|
| 1 | +/* |
| 2 | + * Copyright (c) 2025 Samsung Electronics Co., Ltd. All Rights Reserved |
| 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 | +#ifndef __CIRCLE_RESIZER_SHAPE_H__ |
| 18 | +#define __CIRCLE_RESIZER_SHAPE_H__ |
| 19 | + |
| 20 | +#include "Dim.h" |
| 21 | + |
| 22 | +#include <ostream> |
| 23 | +#include <vector> |
| 24 | + |
| 25 | +namespace circle_resizer |
| 26 | +{ |
| 27 | + |
| 28 | +/** |
| 29 | + * The representation of a single shape. |
| 30 | + */ |
| 31 | +class Shape |
| 32 | +{ |
| 33 | +public: |
| 34 | + /** |
| 35 | + * @brief Initialize shape with initializer list of dims. |
| 36 | + */ |
| 37 | + Shape(const std::initializer_list<Dim> &dims); |
| 38 | + |
| 39 | + /** |
| 40 | + * @brief Initialize shape with vector of dims. |
| 41 | + */ |
| 42 | + Shape(const std::vector<Dim> &shape_vec); |
| 43 | + |
| 44 | + /** |
| 45 | + * @brief Initialize static shape with initializer list of of uint32_t values. |
| 46 | + * |
| 47 | + * Exceptions: |
| 48 | + * - std::out_of_range if some elements in shape_vec exceed int32_t range. |
| 49 | + */ |
| 50 | + Shape(const std::initializer_list<uint32_t> &shape_vec); |
| 51 | + |
| 52 | + /** |
| 53 | + * @brief Create scalar shape. Note, that the same can be achieved with Shape{}. |
| 54 | + */ |
| 55 | + static Shape scalar(); |
| 56 | + |
| 57 | +public: |
| 58 | + /** |
| 59 | + * @brief Returns number of dimensions in the shape. |
| 60 | + */ |
| 61 | + size_t rank() const; |
| 62 | + |
| 63 | + /** |
| 64 | + * @brief Returns dimension of the position determined by axis. |
| 65 | + * |
| 66 | + * Exceptions: |
| 67 | + * - std::invalid_argument if the method is called on a scalar shape. |
| 68 | + * - std::out_of_range if the provided axis is greater than rank. |
| 69 | + */ |
| 70 | + Dim operator[](const size_t &axis) const; |
| 71 | + |
| 72 | + /** |
| 73 | + * @brief Returns true if the shape is a scalar. Otherwise, return false. |
| 74 | + */ |
| 75 | + bool is_scalar() const; |
| 76 | + |
| 77 | + /** |
| 78 | + * @brief Returns true if all dimensions in the shape are static or the shape is a scalar. |
| 79 | + * Otherwise, return false. |
| 80 | + */ |
| 81 | + bool is_dynamic() const; |
| 82 | + |
| 83 | + /** |
| 84 | + * @brief Returns true of the current shape and the provided rhs are equal. |
| 85 | + */ |
| 86 | + bool operator==(const Shape &rhs) const; |
| 87 | + |
| 88 | + /** |
| 89 | + * @brief Print the shape in format [1, 2, 3]. |
| 90 | + */ |
| 91 | + friend std::ostream &operator<<(std::ostream &os, const Shape &shape); |
| 92 | + |
| 93 | +private: |
| 94 | + std::vector<Dim> _dims; |
| 95 | +}; |
| 96 | + |
| 97 | +} // namespace circle_resizer |
| 98 | + |
| 99 | +#endif // __CIRCLE_RESIZER_SHAPE_H__ |
0 commit comments