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