31 const NdArrayDesc<N> &output_desc, uint8_t *output_data,
int indexes[N],
int dim,
32 const int last_broadcasting_dim,
const uint32_t type_size)
35 if (dim == last_broadcasting_dim)
37 int copy_size = output_desc.
strides[dim] * type_size;
38 const uint8_t *data_src = input_data +
subscriptToIndex(input_desc, indexes) * type_size;
39 uint8_t *data_dst = output_data +
subscriptToIndex(output_desc, indexes) * type_size;
40 for (
int i = 0; i < output_desc.
extents[dim]; ++i, data_dst += copy_size)
42 memcpy(data_dst, data_src, copy_size);
48 for (indexes[dim] = 0; indexes[dim] < input_desc.
extents[dim]; ++indexes[dim])
50 BroadcastImpl<N>(input_desc, input_data, output_desc, output_data, indexes, dim + 1,
51 last_broadcasting_dim, type_size);
58 int copy_size = output_desc.
strides[dim] * type_size;
59 uint8_t *data_src = output_data +
subscriptToIndex(output_desc, indexes) * type_size;
60 uint8_t *data_dst = data_src + copy_size;
61 for (
int i = 1; i < output_desc.
extents[dim]; ++i, data_dst += copy_size)
63 memcpy(data_dst, data_src, copy_size);
70 const uint8_t *input_data,
83 int last_broadcast_dim = -1;
84 for (
int i = N - 1; i >= 0; --i)
88 last_broadcast_dim = i;
94 if (last_broadcast_dim == -1)
96 memcpy(output_data, input_data, unextended_input_shape.
flatSize() *
sizeof(data_type));
101 int indexes[N] = {0};
102 BroadcastImpl<N>(input_desc, input_data, output_desc, output_data, indexes, 0, last_broadcast_dim,
void BroadcastImpl(const NdArrayDesc< N > &input_desc, const uint8_t *input_data, const NdArrayDesc< N > &output_desc, uint8_t *output_data, int indexes[N], int dim, const int last_broadcasting_dim, const uint32_t type_size)