blob: 54fb66a57311e0d2b22213ef696ce03f2fa9b50f [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
2 * Copyright (c) 2017 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#ifndef __ARM_COMPUTE_SUBTENSORINFO_H__
25#define __ARM_COMPUTE_SUBTENSORINFO_H__
26
27#include "arm_compute/core/ITensorInfo.h"
28
29#include "arm_compute/core/Coordinates.h"
Georgios Pinitas6f669f02017-09-26 12:32:57 +010030#include "arm_compute/core/Helpers.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010031#include "arm_compute/core/Strides.h"
32#include "arm_compute/core/TensorInfo.h"
33#include "arm_compute/core/TensorShape.h"
34#include "arm_compute/core/Validate.h"
35
36#include <cstddef>
37
38namespace arm_compute
39{
40/** Store the sub tensor's metadata */
41class SubTensorInfo final : public ITensorInfo
42{
43public:
44 /** Default constructor */
45 SubTensorInfo();
46 /** Default constructor
47 *
48 * @param[in] parent Metadata of parent tensor.
49 * @param[in] tensor_shape Tensor shape. Shape must fit inside parent's shape.
50 * X and Y dimensions must match the parent's ones.
51 * @param[in] coords Coordinates of starting element inside parent tensor.
52 */
53 SubTensorInfo(ITensorInfo *parent, const TensorShape &tensor_shape, const Coordinates &coords);
54 /** Default destructor */
55 ~SubTensorInfo() = default;
56 /** Allow instances of this class to be copy constructed */
57 SubTensorInfo(const SubTensorInfo &) = default;
58 /** Allow instances of this class to be copied */
59 SubTensorInfo &operator=(const SubTensorInfo &) = default;
60 /** Allow instances of this class to be move constructed */
61 SubTensorInfo(SubTensorInfo &&) = default;
62 /** Allow instances of this class to be moved */
63 SubTensorInfo &operator=(SubTensorInfo &&) = default;
64
65 // Inherited methods overridden:
66 void set_data_type(DataType data_type) override
67 {
68 ARM_COMPUTE_ERROR_ON(_parent == nullptr);
69 _parent->set_data_type(data_type);
70 };
71 void set_num_channels(int num_channels) override
72 {
73 ARM_COMPUTE_ERROR_ON(_parent == nullptr);
74 _parent->set_num_channels(num_channels);
75 };
76 void set_format(Format format) override
77 {
78 ARM_COMPUTE_ERROR_ON(_parent == nullptr);
79 _parent->set_format(format);
80 };
81 void set_fixed_point_position(int fixed_point_position) override
82 {
83 ARM_COMPUTE_ERROR_ON(_parent == nullptr);
84 _parent->set_fixed_point_position(fixed_point_position);
85 };
86 void set_tensor_shape(TensorShape shape) override;
87 bool auto_padding() override
88 {
89 ARM_COMPUTE_ERROR_ON(_parent == nullptr);
90 return _parent->auto_padding();
91 };
92 bool extend_padding(const PaddingSize &padding) override;
93 size_t dimension(size_t index) const override
94 {
95 return _tensor_shape[index];
96 }
97 const Strides &strides_in_bytes() const override
98 {
99 ARM_COMPUTE_ERROR_ON(_parent == nullptr);
100 return _parent->strides_in_bytes();
101 }
102 size_t offset_first_element_in_bytes() const override
103 {
104 ARM_COMPUTE_ERROR_ON(_parent == nullptr);
105 return _parent->offset_element_in_bytes(_coords);
106 }
107 size_t offset_element_in_bytes(const Coordinates &pos) const override;
108 int fixed_point_position() const override
109 {
110 ARM_COMPUTE_ERROR_ON(_parent == nullptr);
111 return _parent->fixed_point_position();
112 }
113 size_t element_size() const override
114 {
115 ARM_COMPUTE_ERROR_ON(_parent == nullptr);
116 return _parent->element_size();
117 }
118 size_t num_dimensions() const override
119 {
120 return _tensor_shape.num_dimensions();
121 }
122 size_t num_channels() const override
123 {
124 ARM_COMPUTE_ERROR_ON(_parent == nullptr);
125 return _parent->num_channels();
126 }
127 const TensorShape &tensor_shape() const override
128 {
129 ARM_COMPUTE_ERROR_ON(_parent == nullptr);
130 return _tensor_shape;
131 }
132 DataType data_type() const override
133 {
134 ARM_COMPUTE_ERROR_ON(_parent == nullptr);
135 return _parent->data_type();
136 }
137 Format format() const override
138 {
139 ARM_COMPUTE_ERROR_ON(_parent == nullptr);
140 return _parent->format();
141 }
142 size_t total_size() const override
143 {
144 ARM_COMPUTE_ERROR_ON(_parent == nullptr);
145 return _parent->total_size();
146 }
147 PaddingSize padding() const override
148 {
149 ARM_COMPUTE_ERROR_ON(_parent == nullptr);
150 return _parent->padding();
151 }
152 bool has_padding() const override
153 {
154 ARM_COMPUTE_ERROR_ON(_parent == nullptr);
155 return _parent->has_padding();
156 }
157 bool is_resizable() const override
158 {
159 ARM_COMPUTE_ERROR_ON(_parent == nullptr);
160 return _parent->is_resizable();
161 }
162 void set_is_resizable(bool is_resizable) override
163 {
164 ARM_COMPUTE_ERROR_ON(_parent == nullptr);
165 _parent->set_is_resizable(is_resizable);
166 }
167 ValidRegion valid_region() const override
168 {
169 return _valid_region;
170 }
171 void set_valid_region(ValidRegion valid_region) override
172 {
173 ARM_COMPUTE_ERROR_ON(_parent == nullptr);
174 ARM_COMPUTE_ERROR_ON_INVALID_SUBTENSOR_VALID_REGION(_parent->valid_region(), valid_region);
175 _valid_region = std::move(valid_region);
176 }
177
178private:
179 ITensorInfo *_parent;
180 TensorShape _tensor_shape;
181 Coordinates _coords;
182 ValidRegion _valid_region;
183};
184}
185#endif /*__ARM_COMPUTE_SUBTENSORINFO_H__ */