23void gather_no_array(
const float *in_data,
const std::array<size_t, 3> &dims,
float *out_data,
24 const std::array<size_t, 3> &out_dims,
25 const int *indices,
const std::array<size_t, 3> &indices_dims)
27 assert(indices_dims[1] == dims.size());
29 for (
int i = 0; i < indices_dims[0]; ++i)
31 for (
int j = 0; j < indices_dims[1]; ++j)
33 const int *index_ptr = indices + i * indices_dims[2] * indices_dims[1] + j * indices_dims[2];
35 size_t in_offset = index_ptr[0] * dims[2] * dims[1] + index_ptr[1] * dims[2];
37 const float *in_ptr = in_data + in_offset;
39 size_t out_offset = i * out_dims[2] * out_dims[1] + j * out_dims[2];
41 float *out_ptr = out_data + out_offset;
43 for (
int k = 0; k < dims[2]; ++k)
45 out_ptr[k] = in_ptr[k];
53 std::array<size_t, 3> in_dims{3, 3, 4};
54 std::vector<float> input(3 * 3 * 4);
55 for (
size_t i = 0; i < 3 * 3 * 4; ++i)
58 std::array<size_t, 3> indices_shape{1, 3, 2};
59 std::vector<int> indices(1 * 3 * 2);
68 std::array<size_t, 3> output_dims{1, 3, 4};
69 std::vector<float> output(1 * 3 * 4);
71 gather_no_array(input.data(), in_dims, output.data(), output_dims, indices.data(), indices_shape);
73 for (
size_t i = 0; i < output_dims[0]; ++i)
75 for (
size_t j = 0; j < output_dims[1]; ++j)
77 auto out_ptr = output.data() + i * output_dims[1] * output_dims[2] + j * output_dims[2];
78 for (
size_t k = 0; k < output_dims[2]; ++k)
80 std::cout << out_ptr[k] <<
", ";
82 std::cout << std::endl;
void gather_no_array(const float *in_data, const std::array< size_t, 3 > &dims, float *out_data, const std::array< size_t, 3 > &out_dims, const int *indices, const std::array< size_t, 3 > &indices_dims)