Exemple #1
0
    def convert_layer_add(self, layer_config: Dict[str, object], inputs: List[Variable]) -> List[Variable]:
        """
        Example:
          {'class_name': 'Add',
    'config': {'name': 'add_1', 'trainable': True},
    'inbound_nodes': [[['conv2d_2', 0, 0, {}], ['conv2d_3', 0, 0, {}]]],
    'name': 'add_1'},
        :param layer_config: 
        :param inputs: 
        :return: 
        """
        name: str = layer_config["name"]

        sum_opr = ElementwiseSum(name)
        y, = sum_opr(*inputs)

        return [y]
def test_general():
    vx1 = np.random.rand(2, 3, 4, 5)
    vx2 = np.random.rand(2, 3, 4, 5)
    vy = vx1 + vx2

    x1 = Variable(vx1.shape, order=OrderNHWC)
    x2 = Variable(vx2.shape, order=OrderNHWC)
    y, = ElementwiseSum(None)(x1, x2)

    generate_kernel_test_case(description=f"ElementwiseSum",
                              backend=["webgpu", "webassembly", "fallback"],
                              graph=Graph([x1, x2], [y]),
                              inputs={
                                  x1: vx1,
                                  x2: vx2
                              },
                              expected={y: vy})
def test_every_order():
    orders = [
        OrderC, OrderNC, OrderCN, OrderNHWC, OrderHWNC, OrderHWCN, OrderNCHW,
        OrderCNHW, OrderCHWN
    ]

    for order1, order2 in itertools.product(orders, orders):
        if set(order1.axes) != set(order2.axes):
            continue

        default_order = {1: OrderC, 2: OrderNC, 4: OrderNHWC}

        op = ElementwiseSum("op")
        x1 = Variable(np.arange(order1.ndim) + 1, default_order[order2.ndim])
        x2 = Variable(np.arange(order2.ndim) + 1, default_order[order2.ndim])

        x1.change_order(order1)
        x2.change_order(order2)

        y, = op(x1, x2)
        for axis in order1.axes:
            assert y.shape_dict[axis] == x1.shape_dict[axis]
def test_invalid_shape2():
    op = ElementwiseSum("op")

    x1 = Variable((2, 3, 4, 5), OrderNCHW)
    x2 = Variable((2, 3, 4, 5), OrderNHWC)
    y, = op(x1, x2)
Exemple #5
0
 def __call__(self, inputs: List[Variable]) -> List[Variable]:
     opr = ElementwiseSum(generate_unique_name(self.cfunc.label))
     return list(opr(*inputs))