def test_concat(): element_type = Type.f32 A = Parameter(element_type, Shape([1, 2])) B = Parameter(element_type, Shape([1, 2])) C = Parameter(element_type, Shape([1, 2])) parameter_list = [A, B, C] axis = 0 function = Function(NodeVector([Concat(NodeVector([A, B, C]), axis)]), parameter_list, 'test') backend, cf = make_backend_call_frame(function) a = backend.make_primary_tensor_view(element_type, Shape([1, 2])) b = backend.make_primary_tensor_view(element_type, Shape([1, 2])) c = backend.make_primary_tensor_view(element_type, Shape([1, 2])) result = backend.make_primary_tensor_view(element_type, Shape([3, 2])) a.write(util.numpy_to_c(np.array([1, 2], dtype=np.float32)), 0, 8) b.write(util.numpy_to_c(np.array([5, 6], dtype=np.float32)), 0, 8) c.write(util.numpy_to_c(np.array([7, 8], dtype=np.float32)), 0, 8) result_arr = np.zeros(6, dtype=np.float32).reshape(3, 2) result.write(util.numpy_to_c(result_arr), 0, 24) cf.call([result], [a, b, c]) result.read(util.numpy_to_c(result_arr), 0, 24) a_arr = np.array([[1, 2]], dtype=np.float32) b_arr = np.array([[5, 6]], dtype=np.float32) c_arr = np.array([[7, 8]], dtype=np.float32) result_arr_ref = np.concatenate((a_arr, b_arr, c_arr), axis) assert np.allclose(result_arr, result_arr_ref)
def test_concat(): element_type = Type.f32 A = Parameter(element_type, Shape([1, 2])) B = Parameter(element_type, Shape([1, 2])) C = Parameter(element_type, Shape([1, 2])) parameter_list = [A, B, C] axis = 0 function = Function(NodeVector([Concat(NodeVector([A, B, C]), axis)]), parameter_list, 'test') backend = Backend.create(pytest.config.getoption('backend')) a = backend.create_tensor(element_type, Shape([1, 2])) b = backend.create_tensor(element_type, Shape([1, 2])) c = backend.create_tensor(element_type, Shape([1, 2])) result = backend.create_tensor(element_type, Shape([3, 2])) a.write(util.numpy_to_c(np.array([1, 2], dtype=np.float32)), 0, 8) b.write(util.numpy_to_c(np.array([5, 6], dtype=np.float32)), 0, 8) c.write(util.numpy_to_c(np.array([7, 8], dtype=np.float32)), 0, 8) result_arr = np.zeros(6, dtype=np.float32).reshape(3, 2) result.write(util.numpy_to_c(result_arr), 0, 24) backend.call(backend.compile(function), [result], [a, b, c]) result.read(util.numpy_to_c(result_arr), 0, 24) a_arr = np.array([[1, 2]], dtype=np.float32) b_arr = np.array([[5, 6]], dtype=np.float32) c_arr = np.array([[7, 8]], dtype=np.float32) result_arr_ref = np.concatenate((a_arr, b_arr, c_arr), axis) assert np.allclose(result_arr, result_arr_ref)
def concat(nodes, axis): # type: (List[Node], int) -> Node """Concatenate input nodes into single new node along specified axis. :param nodes: The nodes we want concatenate into single new node. :param axis: The axis along which we want to concatenate input nodes. :return: Return new node that is a concatenation of input nodes. """ return Concat(NodeVector(nodes), axis)
def concat(nodes, axis, name=None): # type: (List[Node], int, str) -> Node """Concatenate input nodes into single new node along specified axis. :param nodes: The nodes we want concatenate into single new node. :param axis: The axis along which we want to concatenate input nodes. :param name: The optional new name for output node. :return: Return new node that is a concatenation of input nodes. """ return Concat(nodes, axis)