Create a valid region based on tensor shape, border mode and border size * * @param[in] a_shape Shape used as size of the valid region. * @param[in] border_undefined (Optional) Boolean indicating if the border mode is undefined. * @param[in] border_size (Optional) Border size used to specify the region to exclude. * * @return A valid region starting at (0, 0, ...) with size of
| 218 | * return A valid region starting at (@p border_size.left, @p border_size.top, ...) with reduced size of @p shape. |
| 219 | */ |
| 220 | inline ValidRegion |
| 221 | shape_to_valid_region(const TensorShape &a_shape, bool border_undefined = false, BorderSize border_size = BorderSize(0)) |
| 222 | { |
| 223 | ValidRegion valid_region{Coordinates(), a_shape}; |
| 224 | |
| 225 | Coordinates &anchor = valid_region.anchor; |
| 226 | TensorShape &shape = valid_region.shape; |
| 227 | |
| 228 | if (border_undefined) |
| 229 | { |
| 230 | ARM_COMPUTE_ERROR_ON(shape.num_dimensions() < 2); |
| 231 | |
| 232 | anchor.set(0, border_size.left); |
| 233 | anchor.set(1, border_size.top); |
| 234 | |
| 235 | const int valid_shape_x = std::max(0, static_cast<int>(shape.x()) - static_cast<int>(border_size.left) - |
| 236 | static_cast<int>(border_size.right)); |
| 237 | const int valid_shape_y = std::max(0, static_cast<int>(shape.y()) - static_cast<int>(border_size.top) - |
| 238 | static_cast<int>(border_size.bottom)); |
| 239 | |
| 240 | shape.set(0, valid_shape_x); |
| 241 | shape.set(1, valid_shape_y); |
| 242 | } |
| 243 | |
| 244 | return valid_region; |
| 245 | } |
| 246 | |
| 247 | /** Write the value after casting the pointer according to @p data_type. |
| 248 | * |
no test coverage detected