| 1 | // |
| 2 | // SPDX-FileCopyrightText: Copyright 2024-2026 Arm Limited and/or its affiliates <open-source-office@arm.com> |
| 3 | // |
| 4 | // SPDX-License-Identifier: Apache-2.0 |
| 5 | // |
| 6 | |
| 7 | #pragma once |
| 8 | |
| 9 | #include <cstddef> |
| 10 | #include <optional> |
| 11 | #include <tuple> |
| 12 | |
| 13 | #include "test/common/buffer.hpp" |
| 14 | #include "test/common/data_type.hpp" |
| 15 | |
| 16 | namespace kai::test { |
| 17 | |
| 18 | /// Finds the clamping parameters to limit the dynamic range. |
| 19 | /// |
| 20 | /// @param[in] src The data buffer. |
| 21 | /// @param[in] len The number of values. |
| 22 | /// @param[in] keep_ratio The ratio of the input dynamic range to keep unclamped. |
| 23 | /// |
| 24 | /// @return The minimum value and the maximum value. |
| 25 | template <typename T> |
| 26 | std::tuple<T, T> find_clamp_range(const void* src, size_t len, std::optional<float> keep_ratio); |
| 27 | |
| 28 | /// Finds the clamping parameters to limit the dynamic range. |
| 29 | /// |
| 30 | /// @param[in] type Array element data type. |
| 31 | /// @param[in] src The data buffer. |
| 32 | /// @param[in] len The number of values. |
| 33 | /// @param[in] keep_ratio The ratio of the input dynamic range to keep unclamped. |
| 34 | /// |
| 35 | /// @return The minimum value and the maximum value. |
| 36 | std::tuple<float, float> find_clamp_range(DataType type, const void* src, size_t len, std::optional<float> keep_ratio); |
| 37 | |
| 38 | /// Clamps the matrix. |
| 39 | /// |
| 40 | /// @param[in] src Data buffer of the source matrix. |
| 41 | /// @param[in] len Number of values in the source matrix. |
| 42 | /// @param[in] min_value Lower bound of clamp. |
| 43 | /// @param[in] width Upper bound of clamp. |
| 44 | template <typename T> |
| 45 | Buffer clamp(const void* src, size_t len, T min_value, T max_value); |
| 46 | |
| 47 | /// Clamps the matrix. |
| 48 | /// |
| 49 | /// @param[in] type Array element data type. |
| 50 | /// @param[in] src Data buffer of the source matrix. |
| 51 | /// @param[in] len Number of values in the source matrix. |
| 52 | /// @param[in] min_value Lower bound of clamp. |
| 53 | /// @param[in] max_value Upper bound of clamp. |
| 54 | Buffer clamp(DataType type, const void* src, size_t len, float min_value, float max_value); |
| 55 | } // namespace kai::test |