blob: 6a1a724bb34eabe8753a987d9fd91955c4a43f02 [file] [log] [blame]
thecha012bfadd92020-08-12 17:25:51 +01001/*
2 * Copyright (c) 2020 Arm Limited.
3 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24#include "arm_compute/graph/nodes/StridedSliceLayerNode.h"
25
26#include "arm_compute/core/Utils.h"
27#include "arm_compute/core/utils/misc/ShapeCalculator.h"
28#include "arm_compute/graph/Graph.h"
29#include "arm_compute/graph/INodeVisitor.h"
30
31namespace arm_compute
32{
33namespace graph
34{
35StridedSliceLayerNode::StridedSliceLayerNode(const Coordinates &starts,
36 const Coordinates &ends,
37 const BiStrides &strides,
38 StridedSliceLayerInfo info)
39 : _starts(starts), _ends(ends), _strides(strides), _info(std::move(info))
40{
41 _input_edges.resize(1, EmptyEdgeID);
42 _outputs.resize(1, NullTensorID);
43}
44
45Coordinates StridedSliceLayerNode::starts() const
46{
47 return _starts;
48}
49
50Coordinates StridedSliceLayerNode::ends() const
51{
52 return _ends;
53}
54
55BiStrides StridedSliceLayerNode::strides() const
56{
57 return _strides;
58}
59
60StridedSliceLayerInfo StridedSliceLayerNode::strided_slice_info() const
61{
62 return _info;
63}
64
65TensorDescriptor StridedSliceLayerNode::compute_output_descriptor(const TensorDescriptor &input_descriptor,
66 const Coordinates &starts,
67 const Coordinates &ends,
68 const BiStrides &strides,
69 StridedSliceLayerInfo info)
70{
71 using namespace arm_compute::helpers::tensor_transform;
72
73 TensorDescriptor output_desc = input_descriptor;
74 output_desc.shape = compute_strided_slice_output_shape(input_descriptor.shape, starts, ends, strides,
75 info.begin_mask(), info.end_mask(), info.shrink_axis_mask());
76
77 return output_desc;
78}
79
80bool StridedSliceLayerNode::forward_descriptors()
81{
82 if((input_id(0) != NullTensorID) && (output_id(0) != NullTensorID))
83 {
84 Tensor *dst = output(0);
85 ARM_COMPUTE_ERROR_ON(dst == nullptr);
86 dst->desc() = configure_output(0);
87 return true;
88 }
89 return false;
90}
91
92TensorDescriptor StridedSliceLayerNode::configure_output(size_t idx) const
93{
94 ARM_COMPUTE_UNUSED(idx);
95 ARM_COMPUTE_ERROR_ON(idx >= _outputs.size());
96
97 const Tensor *src = input(0);
98 ARM_COMPUTE_ERROR_ON(src == nullptr);
99
100 return compute_output_descriptor(src->desc(), _starts, _ends, _strides, _info);
101}
102
103NodeType StridedSliceLayerNode::type() const
104{
105 return NodeType::StridedSliceLayer;
106}
107
108void StridedSliceLayerNode::accept(INodeVisitor &v)
109{
110 v.visit(*this);
111}
112} // namespace graph
113} // namespace arm_compute