blob: 48eba70adf719fa1cf2992d08e1ac7d7226b7752 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
2 * Copyright (c) 2016, 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_VALIDATE_H__
25#define __ARM_COMPUTE_VALIDATE_H__
26
27#include "arm_compute/core/Error.h"
28#include "arm_compute/core/HOGInfo.h"
29#include "arm_compute/core/IKernel.h"
30#include "arm_compute/core/IMultiHOG.h"
31#include "arm_compute/core/IMultiImage.h"
32#include "arm_compute/core/ITensor.h"
33#include "arm_compute/core/MultiImageInfo.h"
34#include "arm_compute/core/Window.h"
35
36#include <algorithm>
37
38namespace arm_compute
39{
40namespace detail
41{
42/* Check whether two dimension objects differ.
43 *
44 * @param[in] dim1 First object to be compared.
45 * @param[in] dim2 Second object to be compared.
46 * @param[in] upper_dim The dimension from which to check.
47 *
48 * @return Return true if the two objects are different.
49 */
50template <typename T>
51inline bool have_different_dimensions(const Dimensions<T> &dim1, const Dimensions<T> &dim2, unsigned int upper_dim)
52{
53 for(unsigned int i = upper_dim; i < arm_compute::Dimensions<T>::num_max_dimensions; ++i)
54 {
55 if(dim1[i] != dim2[i])
56 {
57 return true;
58 }
59 }
60
61 return false;
62}
63
64/** Functor to compare two @ref Dimensions objects and throw an error on mismatch.
65 *
66 * @param[in] dim Object to compare against.
67 * @param[in] function Function in which the error occured.
68 * @param[in] file File in which the error occured.
69 * @param[in] line Line in which the error occured.
70 */
71template <typename T>
72class compare_dimension
73{
74public:
75 compare_dimension(const Dimensions<T> &dim, const char *function, const char *file, int line)
76 : _dim{ dim }, _function{ function }, _file{ file }, _line{ line }
77 {
78 }
79
80 /** Compare the given object against the stored one.
81 *
82 * @param[in] dim To be compared object.
83 */
84 void operator()(const Dimensions<T> &dim)
85 {
86 ARM_COMPUTE_ERROR_ON_LOC_MSG(have_different_dimensions(_dim, dim, 0), _function, _file, _line,
87 "Objects have different dimensions");
88 }
89
90private:
91 const Dimensions<T> &_dim;
92 const char *const _function;
93 const char *const _file;
94 const int _line;
95};
96} // namespace detail
97/** Throw an error if one of the pointers is a nullptr.
98 *
99 * @param[in] function Function in which the error occurred.
100 * @param[in] file Name of the file where the error occurred.
101 * @param[in] line Line on which the error occurred.
102 * @param[in] pointers Pointers to check against nullptr.
103 */
104template <typename... Ts>
105void error_on_nullptr(const char *function, const char *file, const int line, Ts &&... pointers)
106{
107 auto is_nullptr = [&](const void *ptr)
108 {
109 ARM_COMPUTE_ERROR_ON_LOC(ptr == nullptr, function, file, line);
110 };
111
112 for_each(is_nullptr, std::forward<Ts>(pointers)...);
113}
114#define ARM_COMPUTE_ERROR_ON_NULLPTR(...) ::arm_compute::error_on_nullptr(__func__, __FILE__, __LINE__, __VA_ARGS__)
115
116/** Throw an error if the passed window is invalid.
117 *
118 * The subwindow is invalid if:
119 * - It is not a valid window.
120 * - Its dimensions don't match the full window's ones
121 * - The step for each of its dimension is not identical to the corresponding one of the full window.
122 *
123 * @param[in] function Function in which the error occurred.
124 * @param[in] file Name of the file where the error occurred.
125 * @param[in] line Line on which the error occurred.
126 * @param[in] full Full size window
127 * @param[in] win Window to validate.
128 */
129void error_on_mismatching_windows(const char *function, const char *file, const int line,
130 const Window &full, const Window &win);
131#define ARM_COMPUTE_ERROR_ON_MISMATCHING_WINDOWS(f, w) ::arm_compute::error_on_mismatching_windows(__func__, __FILE__, __LINE__, f, w)
132
133/** Throw an error if the passed subwindow is invalid.
134 *
135 * The subwindow is invalid if:
136 * - It is not a valid window.
137 * - It is not fully contained inside the full window
138 * - The step for each of its dimension is not identical to the corresponding one of the full window.
139 *
140 * @param[in] function Function in which the error occurred.
141 * @param[in] file Name of the file where the error occurred.
142 * @param[in] line Line on which the error occurred.
143 * @param[in] full Full size window
144 * @param[in] sub Sub-window to validate.
145 */
146void error_on_invalid_subwindow(const char *function, const char *file, const int line,
147 const Window &full, const Window &sub);
148#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s) ::arm_compute::error_on_invalid_subwindow(__func__, __FILE__, __LINE__, f, s)
149
150/** Throw an error if the passed coordinates have too many dimensions.
151 *
152 * The coordinates have too many dimensions if any of the dimensions greater or equal to max_dim is different from 0.
153 *
154 * @param[in] function Function in which the error occurred.
155 * @param[in] file Name of the file where the error occurred.
156 * @param[in] line Line on which the error occurred.
157 * @param[in] pos Coordinates to validate
158 * @param[in] max_dim Maximum number of dimensions allowed.
159 */
160void error_on_coordinates_dimensions_gte(const char *function, const char *file, const int line,
161 const Coordinates &pos, unsigned int max_dim);
162#define ARM_COMPUTE_ERROR_ON_COORDINATES_DIMENSIONS_GTE(p, md) ::arm_compute::error_on_coordinates_dimensions_gte(__func__, __FILE__, __LINE__, p, md)
163
164/** Throw an error if the passed window has too many dimensions.
165 *
166 * The window has too many dimensions if any of the dimension greater or equal to max_dim is different from 0.
167 *
168 * @param[in] function Function in which the error occurred.
169 * @param[in] file Name of the file where the error occurred.
170 * @param[in] line Line on which the error occurred.
171 * @param[in] win Window to validate
172 * @param[in] max_dim Maximum number of dimensions allowed.
173 */
174void error_on_window_dimensions_gte(const char *function, const char *file, const int line,
175 const Window &win, unsigned int max_dim);
176#define ARM_COMPUTE_ERROR_ON_WINDOW_DIMENSIONS_GTE(w, md) ::arm_compute::error_on_window_dimensions_gte(__func__, __FILE__, __LINE__, w, md)
177
178/** Throw an error if the passed dimension objects differ.
179 *
180 * @param[in] function Function in which the error occurred.
181 * @param[in] file Name of the file where the error occurred.
182 * @param[in] line Line on which the error occurred.
183 * @param[in] dim1 The first object to be compared.
184 * @param[in] dim2 The second object to be compared.
185 * @param[in] dims (Optional) Further allowed objects.
186 */
187template <typename T, typename... Ts>
188void error_on_mismatching_dimensions(const char *function, const char *file, int line,
189 const Dimensions<T> &dim1, const Dimensions<T> &dim2, Ts &&... dims)
190{
191 ARM_COMPUTE_UNUSED(function);
192 ARM_COMPUTE_UNUSED(file);
193 ARM_COMPUTE_UNUSED(line);
194
195 for_each(detail::compare_dimension<T>(dim1, function, file, line), dim2, std::forward<Ts>(dims)...);
196}
197#define ARM_COMPUTE_ERROR_ON_MISMATCHING_DIMENSIONS(...) ::arm_compute::error_on_mismatching_dimensions(__func__, __FILE__, __LINE__, __VA_ARGS__)
198
199/** Throw an error if the passed two tensors have different shapes from the given dimension
200 *
201 * @param[in] function Function in which the error occurred.
202 * @param[in] file Name of the file where the error occurred.
203 * @param[in] line Line on which the error occurred.
204 * @param[in] tensor_1 The first tensor to be compared.
205 * @param[in] tensor_2 The second tensor to be compared.
206 * @param[in] tensors (Optional) Further allowed tensors.
207 */
208template <typename... Ts>
209void error_on_mismatching_shapes(const char *function, const char *file, const int line,
210 const ITensor *tensor_1, const ITensor *tensor_2, Ts... tensors)
211{
212 error_on_mismatching_shapes(function, file, line, 0U, tensor_1, tensor_2, std::forward<Ts>(tensors)...);
213}
214
215/** Throw an error if the passed two tensors have different shapes from the given dimension
216 *
217 * @param[in] function Function in which the error occurred.
218 * @param[in] file Name of the file where the error occurred.
219 * @param[in] line Line on which the error occurred.
220 * @param[in] upper_dim The dimension from which to check.
221 * @param[in] tensor_1 The first tensor to be compared.
222 * @param[in] tensor_2 The second tensor to be compared.
223 * @param[in] tensors (Optional) Further allowed tensors.
224 */
225template <typename... Ts>
226void error_on_mismatching_shapes(const char *function, const char *file, const int line,
227 unsigned int upper_dim, const ITensor *tensor_1, const ITensor *tensor_2, Ts... tensors)
228{
229 ARM_COMPUTE_UNUSED(function);
230 ARM_COMPUTE_UNUSED(file);
231 ARM_COMPUTE_UNUSED(line);
232
233 const std::array < const ITensor *, 2 + sizeof...(Ts) > tensors_array{ { tensor_1, tensor_2, std::forward<Ts>(tensors)... } };
234 ARM_COMPUTE_UNUSED(tensors_array);
235
236 ARM_COMPUTE_ERROR_ON_LOC(tensors_array.cbegin() == nullptr, function, file, line);
237
238 ARM_COMPUTE_ERROR_ON_LOC_MSG(std::any_of(std::next(tensors_array.cbegin()), tensors_array.cend(), [&](const ITensor * tensor)
239 {
240 ARM_COMPUTE_ERROR_ON_LOC(tensor == nullptr, function, file, line);
241 return detail::have_different_dimensions((*tensors_array.cbegin())->info()->tensor_shape(), tensor->info()->tensor_shape(), upper_dim);
242 }),
243 function, file, line, "Tensors have different shapes");
244}
245#define ARM_COMPUTE_ERROR_ON_MISMATCHING_SHAPES(...) ::arm_compute::error_on_mismatching_shapes(__func__, __FILE__, __LINE__, __VA_ARGS__)
246
247/** Throw an error if the passed two tensors have different data types
248 *
249 * @param[in] function Function in which the error occurred.
250 * @param[in] file Name of the file where the error occurred.
251 * @param[in] line Line on which the error occurred.
252 * @param[in] tensor_1 The first tensor to be compared.
253 * @param[in] tensor_2 The second tensor to be compared.
254 * @param[in] tensors (Optional) Further allowed tensors.
255 */
256template <typename... Ts>
257void error_on_mismatching_data_types(const char *function, const char *file, const int line,
258 const ITensor *tensor_1, const ITensor *tensor_2, Ts... tensors)
259{
260 ARM_COMPUTE_UNUSED(function);
261 ARM_COMPUTE_UNUSED(file);
262 ARM_COMPUTE_UNUSED(line);
263 ARM_COMPUTE_UNUSED(tensor_1);
264 ARM_COMPUTE_UNUSED(tensor_2);
265
266 DataType &&first_data_type = tensor_1->info()->data_type();
267 ARM_COMPUTE_UNUSED(first_data_type);
268
269 const std::array<const ITensor *, sizeof...(Ts)> tensors_array{ { std::forward<Ts>(tensors)... } };
270 ARM_COMPUTE_UNUSED(tensors_array);
271
272 ARM_COMPUTE_ERROR_ON_LOC_MSG(tensor_2->info()->data_type() != first_data_type || std::any_of(tensors_array.begin(), tensors_array.end(), [&](const ITensor * tensor)
273 {
274 return tensor->info()->data_type() != first_data_type;
275 }),
276 function, file, line, "Tensors have different data types");
277}
278
279#define ARM_COMPUTE_ERROR_ON_MISMATCHING_DATA_TYPES(...) ::arm_compute::error_on_mismatching_data_types(__func__, __FILE__, __LINE__, __VA_ARGS__)
280
281/** Throw an error if the passed tensors have different fixed point data types or different fixed point positions
282 *
283 * @note: If the first tensor doesn't have fixed point data type, the function returns without throwing an error
284 *
285 * @param[in] function Function in which the error occurred.
286 * @param[in] file Name of the file where the error occurred.
287 * @param[in] line Line on which the error occurred.
288 * @param[in] tensor_1 The first tensor to be compared.
289 * @param[in] tensor_2 The second tensor to be compared.
290 * @param[in] tensors (Optional) Further allowed tensors.
291 */
292template <typename... Ts>
293void error_on_mismatching_fixed_point(const char *function, const char *file, const int line,
294 const ITensor *tensor_1, const ITensor *tensor_2, Ts... tensors)
295{
296 ARM_COMPUTE_UNUSED(function);
297 ARM_COMPUTE_UNUSED(file);
298 ARM_COMPUTE_UNUSED(line);
299 ARM_COMPUTE_UNUSED(tensor_1);
300 ARM_COMPUTE_UNUSED(tensor_2);
301
302 DataType &&first_data_type = tensor_1->info()->data_type();
303 const int first_fixed_point_position = tensor_1->info()->fixed_point_position();
304 ARM_COMPUTE_UNUSED(first_data_type);
305 ARM_COMPUTE_UNUSED(first_fixed_point_position);
306
307 if((first_data_type != DataType::QS8) && (first_data_type != DataType::QS16))
308 {
309 return;
310 }
311
312 const std::array < const ITensor *, 1 + sizeof...(Ts) > tensors_array{ { tensor_2, std::forward<Ts>(tensors)... } };
313 ARM_COMPUTE_UNUSED(tensors_array);
314
315 ARM_COMPUTE_ERROR_ON_LOC_MSG(std::any_of(tensors_array.begin(), tensors_array.end(), [&](const ITensor * tensor)
316 {
317 return tensor->info()->data_type() != first_data_type;
318 }),
319 function, file, line, "Tensors have different fixed point data types");
320
321 ARM_COMPUTE_ERROR_ON_LOC_MSG(std::any_of(tensors_array.begin(), tensors_array.end(), [&](const ITensor * tensor)
322 {
323 return tensor->info()->fixed_point_position() != first_fixed_point_position;
324 }),
325 function, file, line, "Tensors have different fixed point positions");
326}
327
328#define ARM_COMPUTE_ERROR_ON_MISMATCHING_FIXED_POINT(...) ::arm_compute::error_on_mismatching_fixed_point(__func__, __FILE__, __LINE__, __VA_ARGS__)
329
330/** Throw an error if the format of the passed tensor/multi-image does not match any of the formats provided.
331 *
332 * @param[in] function Function in which the error occurred.
333 * @param[in] file Name of the file where the error occurred.
334 * @param[in] line Line on which the error occurred.
335 * @param[in] object Tensor/multi-image to validate.
336 * @param[in] format First format allowed.
337 * @param[in] formats (Optional) Further allowed formats.
338 */
339template <typename T, typename F, typename... Fs>
340void error_on_format_not_in(const char *function, const char *file, const int line,
341 const T *object, F &&format, Fs &&... formats)
342{
343 ARM_COMPUTE_ERROR_ON_LOC(object == nullptr, function, file, line);
344
345 Format &&object_format = object->info()->format();
346 ARM_COMPUTE_UNUSED(object_format);
347
348 ARM_COMPUTE_ERROR_ON_LOC(object_format == Format::UNKNOWN, function, file, line);
349
350 const std::array<F, sizeof...(Fs)> formats_array{ { std::forward<Fs>(formats)... } };
351 ARM_COMPUTE_UNUSED(formats_array);
352
353 ARM_COMPUTE_ERROR_ON_LOC_MSG(object_format != format && std::none_of(formats_array.begin(), formats_array.end(), [&](const F & f)
354 {
355 return f == object_format;
356 }),
357 function, file, line, "Format %s not supported by this kernel", string_from_format(object_format).c_str());
358}
359#define ARM_COMPUTE_ERROR_ON_FORMAT_NOT_IN(t, ...) ::arm_compute::error_on_format_not_in(__func__, __FILE__, __LINE__, t, __VA_ARGS__)
360
361/** Throw an error if the data type of the passed tensor does not match any of the data types provided.
362 *
363 * @param[in] function Function in which the error occurred.
364 * @param[in] file Name of the file where the error occurred.
365 * @param[in] line Line on which the error occurred.
366 * @param[in] tensor Tensor to validate.
367 * @param[in] dt First data type allowed.
368 * @param[in] dts (Optional) Further allowed data types.
369 */
370template <typename T, typename... Ts>
371void error_on_data_type_not_in(const char *function, const char *file, const int line,
372 const ITensor *tensor, T &&dt, Ts &&... dts)
373{
374 ARM_COMPUTE_ERROR_ON_LOC(tensor == nullptr, function, file, line);
375
376 const DataType &tensor_dt = tensor->info()->data_type(); //NOLINT
377 ARM_COMPUTE_UNUSED(tensor_dt);
378
379 ARM_COMPUTE_ERROR_ON_LOC(tensor_dt == DataType::UNKNOWN, function, file, line);
380
381 const std::array<T, sizeof...(Ts)> dts_array{ { std::forward<Ts>(dts)... } };
382 ARM_COMPUTE_UNUSED(dts_array);
383
384 ARM_COMPUTE_ERROR_ON_LOC_MSG(tensor_dt != dt && std::none_of(dts_array.begin(), dts_array.end(), [&](const T & d)
385 {
386 return d == tensor_dt;
387 }),
388 function, file, line, "ITensor data type %s not supported by this kernel", string_from_data_type(tensor_dt).c_str());
389}
390#define ARM_COMPUTE_ERROR_ON_DATA_TYPE_NOT_IN(t, ...) ::arm_compute::error_on_data_type_not_in(__func__, __FILE__, __LINE__, t, __VA_ARGS__)
391
392/** Throw an error if the data type or the number of channels of the passed tensor does not match any of the data types and number of channels provided.
393 *
394 * @param[in] function Function in which the error occurred.
395 * @param[in] file Name of the file where the error occurred.
396 * @param[in] line Line on which the error occurred.
397 * @param[in] tensor Tensor to validate.
398 * @param[in] num_channels Number of channels to check
399 * @param[in] dt First data type allowed.
400 * @param[in] dts (Optional) Further allowed data types.
401 */
402template <typename T, typename... Ts>
403void error_on_data_type_channel_not_in(const char *function, const char *file, const int line,
404 const ITensor *tensor, size_t num_channels, T &&dt, Ts &&... dts)
405{
406 error_on_data_type_not_in(function, file, line, tensor, std::forward<T>(dt), std::forward<Ts>(dts)...);
407
408 const size_t tensor_nc = tensor->info()->num_channels();
409 ARM_COMPUTE_UNUSED(tensor_nc);
410
411 ARM_COMPUTE_ERROR_ON_LOC_MSG(tensor_nc != num_channels, function, file, line, "Number of channels %d. Required number of channels %d", tensor_nc, num_channels);
412}
413#define ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c, ...) ::arm_compute::error_on_data_type_channel_not_in(__func__, __FILE__, __LINE__, t, c, __VA_ARGS__)
414
415/** Throw an error if the tensor is not 2D.
416 *
417 * @param[in] function Function in which the error occurred.
418 * @param[in] file Name of the file where the error occurred.
419 * @param[in] line Line on which the error occurred.
420 * @param[in] tensor Tensor to validate.
421 */
422void error_on_tensor_not_2d(const char *function, const char *file, const int line,
423 const ITensor *tensor);
424#define ARM_COMPUTE_ERROR_ON_TENSOR_NOT_2D(t) ::arm_compute::error_on_tensor_not_2d(__func__, __FILE__, __LINE__, t)
425
426/** Throw an error if the channel is not in channels.
427 *
428 * @param[in] function Function in which the error occurred.
429 * @param[in] file Name of the file where the error occurred.
430 * @param[in] line Line on which the error occurred.
431 * @param[in] cn Input channel
432 * @param[in] channel First channel allowed.
433 * @param[in] channels (Optional) Further allowed channels.
434 */
435template <typename T, typename... Ts>
436void error_on_channel_not_in(const char *function, const char *file, const int line,
437 T cn, T &&channel, Ts &&... channels)
438{
439 ARM_COMPUTE_ERROR_ON_LOC(cn == Channel::UNKNOWN, function, file, line);
440
441 const std::array<T, sizeof...(Ts)> channels_array{ { std::forward<Ts>(channels)... } };
442 ARM_COMPUTE_UNUSED(channels_array);
443 ARM_COMPUTE_ERROR_ON_LOC(channel != cn && std::none_of(channels_array.begin(), channels_array.end(), [&](const T & f)
444 {
445 return f == cn;
446 }),
447 function, file, line);
448}
449#define ARM_COMPUTE_ERROR_ON_CHANNEL_NOT_IN(c, ...) ::arm_compute::error_on_channel_not_in(__func__, __FILE__, __LINE__, c, __VA_ARGS__)
450
451/** Throw an error if the channel is not in format.
452 *
453 * @param[in] function Function in which the error occurred.
454 * @param[in] file Name of the file where the error occurred.
455 * @param[in] line Line on which the error occurred.
456 * @param[in] fmt Input channel
457 * @param[in] cn First channel allowed.
458 */
459void error_on_channel_not_in_known_format(const char *function, const char *file, const int line,
460 Format fmt, Channel cn);
461#define ARM_COMPUTE_ERROR_ON_CHANNEL_NOT_IN_KNOWN_FORMAT(f, c) ::arm_compute::error_on_channel_not_in_known_format(__func__, __FILE__, __LINE__, f, c)
462
463/** Throw an error if the @ref IMultiHOG container is invalid
464 *
465 * An @ref IMultiHOG container is invalid if:
466 *
467 * -# it is a nullptr
468 * -# it doesn't contain models
469 * -# it doesn't have the HOG data objects with the same phase_type, normalization_type and l2_hyst_threshold (if normalization_type == L2HYS_NORM)
470 *
471 * @param[in] function Function in which the error occurred.
472 * @param[in] file Name of the file where the error occurred.
473 * @param[in] line Line on which the error occurred.
474 * @param[in] multi_hog IMultiHOG container to validate
475 */
476void error_on_invalid_multi_hog(const char *function, const char *file, const int line,
477 const IMultiHOG *multi_hog);
478#define ARM_COMPUTE_ERROR_ON_INVALID_MULTI_HOG(m) ::arm_compute::error_on_invalid_multi_hog(__func__, __FILE__, __LINE__, m)
479
480/** Throw an error if the kernel is not configured.
481 *
482 * @param[in] function Function in which the error occurred.
483 * @param[in] file Name of the file where the error occurred.
484 * @param[in] line Line on which the error occurred.
485 * @param[in] kernel Kernel to validate.
486 */
487void error_on_unconfigured_kernel(const char *function, const char *file, const int line,
488 const IKernel *kernel);
489#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k) ::arm_compute::error_on_unconfigured_kernel(__func__, __FILE__, __LINE__, k)
490
491/** Throw an error if if the coordinates and shape of the subtensor are within the parent tensor.
492 *
493 * @param[in] function Function in which the error occurred.
494 * @param[in] file Name of the file where the error occurred.
495 * @param[in] line Line on which the error occurred.
496 * @param[in] parent_shape Parent tensor shape
497 * @param[in] coords Coordinates inside the parent tensor where the first element of the subtensor is
498 * @param[in] shape Shape of the subtensor
499 */
500void error_on_invalid_subtensor(const char *function, const char *file, const int line,
501 const TensorShape &parent_shape, const Coordinates &coords, const TensorShape &shape);
502#define ARM_COMPUTE_ERROR_ON_INVALID_SUBTENSOR(p, c, s) ::arm_compute::error_on_invalid_subtensor(__func__, __FILE__, __LINE__, p, c, s)
503
504/** Throw an error if the valid region of a subtensor is not inside the valid region of the parent tensor.
505 *
506 * @param[in] function Function in which the error occurred.
507 * @param[in] file Name of the file where the error occurred.
508 * @param[in] line Line on which the error occurred.
509 * @param[in] parent_valid_region Parent valid region.
510 * @param[in] valid_region Valid region of subtensor.
511 */
512void error_on_invalid_subtensor_valid_region(const char *function, const char *file, const int line,
513 const ValidRegion &parent_valid_region, const ValidRegion &valid_region);
514#define ARM_COMPUTE_ERROR_ON_INVALID_SUBTENSOR_VALID_REGION(pv, sv) ::arm_compute::error_on_invalid_subtensor_valid_region(__func__, __FILE__, __LINE__, pv, sv)
515
516/** Throw an error if the input fixed-point positions are different.
517 *
518 * @param[in] function Function in which the error occurred.
519 * @param[in] file Name of the file where the error occurred.
520 * @param[in] line Line on which the error occurred.
521 * @param[in] tensor_1 The first tensor to be compared.
522 * @param[in] tensor_2 The second tensor to be compared.
523 * @param[in] tensors (Optional) Further allowed tensors.
524 */
525template <typename... Ts>
526void error_on_mismatching_fixed_point_position(const char *function, const char *file, const int line,
527 const ITensor *tensor_1, const ITensor *tensor_2, Ts... tensors)
528{
529 const std::array < const ITensor *, 1 + sizeof...(Ts) > tensors_array{ { tensor_2, std::forward<Ts>(tensors)... } };
530 ARM_COMPUTE_UNUSED(tensors_array);
531
532 ARM_COMPUTE_ERROR_ON_LOC_MSG(std::any_of(tensors_array.begin(), tensors_array.end(), [&](const ITensor * tensor)
533 {
534 return tensor->info()->fixed_point_position() != tensor_1->info()->fixed_point_position();
535 }),
536 function, file, line, "Tensors have different fixed-point positions");
537}
538#define ARM_COMPUTE_ERROR_ON_MISMATCHING_FIXED_POINT_POSITION(...) ::arm_compute::error_on_mismatching_fixed_point_position(__func__, __FILE__, __LINE__, __VA_ARGS__)
539
540/** Throw an error if the fixed-point value is not representable in the specified Q format.
541 *
542 * @param[in] function Function in which the error occurred.
543 * @param[in] file Name of the file where the error occurred.
544 * @param[in] line Line on which the error occurred.
545 * @param[in] value The floating point value to be checked.
546 * @param[in] tensor Input tensor that has information on data type and fixed-point position.
547 */
548template <typename... Ts>
549void error_on_value_not_representable_in_fixed_point(const char *function, const char *file, int line,
550 float value, const ITensor *tensor)
551{
552 const int fixed_point_position = tensor->info()->fixed_point_position();
553 const DataType dt = tensor->info()->data_type();
554 const unsigned int q_max_range = 0xFFFFFFFFu >> (((sizeof(unsigned int) - element_size_from_data_type(dt)) * 8) + 1);
555 const float max_range = q_max_range / (static_cast<float>(1 << fixed_point_position));
556 ARM_COMPUTE_UNUSED(max_range);
557
558 ARM_COMPUTE_ERROR_ON_LOC_MSG(value > max_range, function, file, line,
559 "Value %f is not representable in %s with fixed-point position %d", value, string_from_data_type(dt).c_str(), fixed_point_position);
560}
561#define ARM_COMPUTE_ERROR_ON_VALUE_NOT_REPRESENTABLE_IN_FIXED_POINT(...) ::arm_compute::error_on_value_not_representable_in_fixed_point(__func__, __FILE__, __LINE__, __VA_ARGS__)
562}
563#endif /* __ARM_COMPUTE_VALIDATE_H__*/