1 /** 2 * Copyright 2020-2021 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 17 #ifndef MINDSPORE_CORE_OPS_STRIDED_SLICE_H_ 18 #define MINDSPORE_CORE_OPS_STRIDED_SLICE_H_ 19 #include <map> 20 #include <vector> 21 #include <string> 22 #include <memory> 23 #include "ops/primitive_c.h" 24 #include "abstract/abstract_value.h" 25 #include "utils/check_convert_utils.h" 26 27 namespace mindspore { 28 namespace ops { 29 constexpr auto kNameStridedSlice = prim::kStridedSlice; 30 /// \brief Extracts a strided slice of a tensor. Refer to Python API @ref mindspore.ops.StridedSlice for more details. 31 class MS_CORE_API StridedSlice : public PrimitiveC { 32 public: 33 /// \brief Constructor. StridedSlice()34 StridedSlice() : PrimitiveC(prim::kPrimStridedSlice->name()) { 35 InitIOName({"x", "begin", "end", "strides"}, {"output"}); 36 } 37 /// \brief Destructor. 38 ~StridedSlice() = default; 39 MS_DECLARE_PARENT(StridedSlice, PrimitiveC); 40 /// \brief Init. Refer to the parameters of python API @ref mindspore.ops.StridedSlice for the inputs. 41 void Init(const int64_t begin_mask = 0, const int64_t end_mask = 0, const int64_t ellipsis_mask = 0, 42 const int64_t new_axis_mask = 0, const int64_t shrink_axis_mask = 0); 43 /// \brief Set begin_mask. 44 void set_begin_mask(const int64_t begin_mask); 45 /// \brief Set end_mask. 46 void set_end_mask(const int64_t end_mask); 47 /// \brief Set ellipsis_mask. 48 void set_ellipsis_mask(const int64_t ellipsis_mask); 49 /// \brief Set new_axis_mask. 50 void set_new_axis_mask(const int64_t new_axis_mask); 51 /// \brief Set shrink_axis_mask. 52 void set_shrink_axis_mask(const int64_t shrink_axis_mask); 53 /// \brief Get begin_mask. 54 /// 55 /// \return begin_mask. 56 int64_t get_begin_mask() const; 57 /// \brief Get end_mask. 58 /// 59 /// \return end_mask. 60 int64_t get_end_mask() const; 61 /// \brief Get ellipsis_mask. 62 /// 63 /// \return ellipsis_mask. 64 int64_t get_ellipsis_mask() const; 65 /// \brief Get new_axis_mask. 66 /// 67 /// \return new_axis_mask. 68 int64_t get_new_axis_mask() const; 69 /// \brief Get shrink_axis_mask. 70 /// 71 /// \return shrink_axis_mask. 72 int64_t get_shrink_axis_mask() const; 73 std::vector<int64_t> TenToTwo(int64_t num); 74 int64_t compute_slicing_length(int64_t start_pos, int64_t end_pos, int64_t strides, int64_t x_dim) const; 75 }; 76 struct ComputeHasEllipsis { 77 bool has_ellipsis; 78 }; 79 AbstractBasePtr StridedSliceInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, 80 const std::vector<AbstractBasePtr> &input_args); 81 using PrimStridedSlicePtr = std::shared_ptr<StridedSlice>; 82 } // namespace ops 83 } // namespace mindspore 84 85 #endif // MINDSPORE_CORE_OPS_STRIDED_SLICE_H_ 86