Draft: Feat : Add halfway rounding modes to the Round operator
Description
Solves aidge_quantization#81 (closed) for the aidge_backend_cpu module.
Files modified : RoundImpl.hpp, RoundImpl_kernels.cpp and RoundImpl.cpp.
Note : Pipeline currently fails because aidge_core!419 (closed) is not merged yet !
Merge request reports
Activity
added Feature 🚀 StatusReview Ready labels
requested review from @cmoineau, @pineapple, and @noamzerah
assigned to @bhalimi
30 32 31 for (std::size_t i = 0; i < inputLength; ++i) { 32 //std::round would not work since it doesn't follow the halves rules (See ONNX Round) 33 output[i] = static_cast<O>(std::nearbyint(static_cast<float>(input[i]))); 33 for (std::size_t i = 0; i < inputLength; ++i) 34 { 35 float inputValue = static_cast<float>(input[i]); 36 37 if (mode == Round_Op::HalfwayRounding::NearestEven) { 38 output[i] = static_cast<O>(std::nearbyint(inputValue)); 39 } 40 else if (mode == Round_Op::HalfwayRounding::AwayFromZero) { 41 output[i] = static_cast<O>(std::round(inputValue)); 42 } 43 else if (mode == Round_Op::HalfwayRounding::NextInteger) { 44 output[i] = static_cast<O>(std::round(std::nextafter(inputValue, inputValue + 1))); I don't understand this line. I am not sure this is what you intend. I think it would be much clearer to only rely on the rounding modes described in https://en.cppreference.com/w/cpp/numeric/fenv/feround.
changed this line in version 2 of the diff
Well after some testing it appears that
FE_UPWARDdoes not round only halfways towards the next integer, but any value !So I don't have better solution right now than the
std::nextafter()thing. I revert until we find a better way to address this issue !Edited by Benjamin Halimi
I added a new rounding mechanism in aidge_core!421 (merged), which will superseed this MR.