2 * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
23 void 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, //[nselections,
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;