• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2020 Huawei Technologies Co., Ltd
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 #ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_CORE_TENSOR_HELPERS_H_
17 #define MINDSPORE_CCSRC_MINDDATA_DATASET_CORE_TENSOR_HELPERS_H_
18 
19 #include <memory>
20 #include <vector>
21 
22 #include "minddata/dataset/include/dataset/transforms.h"
23 #include "minddata/dataset/include/dataset/constants.h"
24 
25 namespace mindspore {
26 namespace dataset {
27 /// Recursive helper function to generate indices based on vector of SliceOptions. It recursively iterates through each
28 /// range represented by slice_options to generate a list of indices to be sliced.
29 /// \param[out] matrix Generated nested vector of indices
30 ///       Example: For a 4 x 2 tensor, and with slice_list = {SliceOption({0})} (the first row), matrix will become
31 ///       {{0}}. For slice_list = {SliceOption(all), SliceOption({0})} (the first column), matrix will become
32 ///       {{0, 0}, {1, 0}, {2, 0}, {3, 0}}.
33 ///       For slice_list = {SliceOption({0, 2})}, matrix will become {{0}, {2}}. The size of each nested array is always
34 ///       equal to (slice_list).size().
35 /// \param[in] depth used to keep track of recursion level
36 /// \param[in] numbers vector used to represent current index
37 /// \param[in] matrix 2D vector to be populated with desired indices
38 /// \param[in] slice_options vector of SliceOption objects
39 void IndexGeneratorHelper(int8_t depth, std::vector<dsize_t> *numbers, const std::vector<SliceOption> &slice_list,
40                           std::vector<std::vector<dsize_t>> *matrix);
41 
42 /// Generate indices based on vector of SliceOptions
43 /// Calls the recursive helper function IndexGeneratorHelper
44 /// \param[in] slice_list vector of SliceOption objects. Note: If the user passes
45 ///       {SliceOption(true), SliceOption(true)}, it will return a M x 2 vector, instead of reducing it to
46 ///       {SliceOption(true)} first to only generate a M x 1 vector.
47 /// \return std::vector<std::vector<dsize_t>> 2D vector of generated indices, M x (slice_list).size()
48 std::vector<std::vector<dsize_t>> IndexGenerator(const std::vector<SliceOption> &slice_list);
49 }  // namespace dataset
50 }  // namespace mindspore
51 #endif  // MINDSPORE_CCSRC_MINDDATA_DATASET_CORE_TENSOR_HELPERS_H_
52