def template(x_order=OrderNHWC, x_shape=(2, 3, 4, 5), actual_x_order=OrderNHWC, y_order=OrderNHWC, y_shape=(1, 12, 2, 5), actual_y_order=OrderNHWC, description: str = ""): vx = np.arange(np.product(x_shape)).reshape(x_shape) vy = vx.reshape(y_shape) x = Variable(vx.shape, order=x_order) y = x.reshape(shape=y_shape, order=y_order) x.change_order(actual_x_order) y.change_order(actual_y_order) generate_kernel_test_case( description=f"Reshape {description}", backend=["webgpu", "webgl", "webassembly"], graph=Graph([x], [y]), inputs={ x: vx.transpose([x_order.axes_dict[a] for a in actual_x_order.axes]) }, expected={ y: vy.transpose([y_order.axes_dict[a] for a in actual_y_order.axes]) }, )
def test_reshape(): v1 = Variable([2, 3, 4, 5], OrderNHWC) v2 = v1.reshape(shape=[1, 6, 4, 5], order=OrderNCHW) assert v2.shape_dict[Axis.N] == 1 assert v2.shape_dict[Axis.C] == 6 assert v2.shape_dict[Axis.H] == 4 assert v2.shape_dict[Axis.W] == 5 assert isinstance(v2.output_from, Reshape) assert v2.output_from.inputs["x"] == v1