diff options
author | Jaroslaw Rzepecki <jaroslaw.rzepecki@arm.com> | 2017-11-22 17:16:39 +0000 |
---|---|---|
committer | Anthony Barbier <anthony.barbier@arm.com> | 2018-11-02 16:42:17 +0000 |
commit | 0a878ae1bbb13002e50f8287721750d2e4b22680 (patch) | |
tree | b0e18e7df45e01f9440208ecaa06fe6845d02155 /src/core/Utils.cpp | |
parent | 8795ffb03c1bb84a0d93e4ece153ceaa86118594 (diff) | |
download | ComputeLibrary-0a878ae1bbb13002e50f8287721750d2e4b22680.tar.gz |
COMPMID-556: Added a rounding policy to the quantize function
Change-Id: I6272a36636c5d9baff6d35dee0a50dc847f65bfa
Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/110266
Tested-by: BSG Visual Compute Jenkins server to access repositories on http://mpd-gerrit.cambridge.arm.com <bsgcomp@arm.com>
Reviewed-by: Anthony Barbier <anthony.barbier@arm.com>
Diffstat (limited to 'src/core/Utils.cpp')
-rw-r--r-- | src/core/Utils.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/core/Utils.cpp b/src/core/Utils.cpp index af864f57f7..af50bbbaf7 100644 --- a/src/core/Utils.cpp +++ b/src/core/Utils.cpp @@ -21,10 +21,13 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ + #include "arm_compute/core/Utils.h" #include "arm_compute/core/FixedPoint.h" +#include "support/ToolchainSupport.h" + #include <algorithm> #include <cmath> #include <cstdint> @@ -387,3 +390,34 @@ int arm_compute::max_consecutive_elements_display_width(std::ostream &s, DataTyp } return 0; } + +int arm_compute::round(float x, RoundingPolicy rounding_policy) +{ + using namespace std; + int rounded = 0; + switch(rounding_policy) + { + case RoundingPolicy::TO_ZERO: + { + rounded = static_cast<int>(x); + break; + } + case RoundingPolicy::TO_NEAREST_UP: + { + rounded = static_cast<int>(support::cpp11::round(x)); + break; + } + case RoundingPolicy::TO_NEAREST_EVEN: + { + ARM_COMPUTE_ERROR("TO_NEAREST_EVEN rounding policy is not supported."); + break; + } + default: + { + ARM_COMPUTE_ERROR("Unsupported rounding policy."); + break; + } + } + + return rounded; +} |