slice_plan.hpp
1 //*****************************************************************************
2 // Copyright 2017-2020 Intel Corporation
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 #pragma once
18 
19 #include <set>
20 
21 #include "ngraph/axis_set.hpp"
22 #include "ngraph/shape.hpp"
23 
24 namespace ngraph
25 {
26  //
27  // In various places, like ConstantFolding and DynElimination, it is
28  // useful to transform DynSlice by converting it to a sequence of ops:
29  //
30  // Slice (to do the basic slicing)
31  // |
32  // v
33  // Reshape (non-transposing, to handle shrinks)
34  // |
35  // v
36  // Reverse (to emulate backwards stride)
37  //
38  // (The Reshape, Reverse, or both may be omitted if they would just be
39  // identities.)
40  //
41  // A SlicePlan is used to collect parameters for these ops.
42  //
43  struct NGRAPH_API SlicePlan
44  {
45  // Parameters for the Slice
46  std::vector<int64_t> begins;
47  std::vector<int64_t> ends;
48  std::vector<int64_t> strides;
49 
50  // Shapes coming into, and going out of, the Reshape.
51  Shape reshape_in_shape;
52  Shape reshape_out_shape;
53 
54  // Parameters for the Reverse
55  AxisSet reverse_axes;
56 
57  bool operator==(const SlicePlan& other) const;
58  bool operator!=(const SlicePlan& other) const;
59  };
60 
61  SlicePlan NGRAPH_API make_slice_plan(const Shape& input_shape,
62  const std::vector<int64_t>& begins,
63  const std::vector<int64_t>& ends,
64  const std::vector<int64_t>& strides,
65  const AxisSet& lower_bounds_mask,
66  const AxisSet& upper_bounds_mask,
67  const AxisSet& new_axis_mask,
68  const AxisSet& shrink_axis_mask,
69  const AxisSet& ellipsis_mask);
70 }
ngraph::SlicePlan
Definition: slice_plan.hpp:44
ngraph::AxisSet
A set of axes.
Definition: axis_set.hpp:31
ngraph::Shape
Shape for a tensor.
Definition: shape.hpp:31
ngraph
The Intel nGraph C++ API.
Definition: attribute_adapter.hpp:28