Skip to content

Add new rounding mechanism

Olivier BICHLER requested to merge round into dev

To be merged after !358 (merged).

Introduces a new rounding mechanism in Aidge: the generic Aidge::round() function, which should always be used. The available rounding modes are the following:

enum class RoundingMode {
    // Directed rounding
    Down, // std::floor
    Up, // std::ceil
    TowardZero, // std::trunc
    AwayFromZero,
    // Round to nearest
    HalfDown, // std::rint or std::nearbyint with FE_DOWNWARD mode
    HalfUp, // std::rint or std::nearbyint with FE_UPWARD mode
    HalfTowardZero, // std::rint or std::nearbyint with FE_TOWARDZERO mode
    HalfAwayFromZero, // std::round and std::rint or std::nearbyint with FE_TONEAREST mode
    HalfToEven, // Python round() and numpy.round()
    HalfToOdd
};

The following operators have now a RoundingMode attribute (that is only meaningful when their output type is integral):

  • AvgPooling;
  • GlobalAveragePooling;
  • ReduceMean;
  • Round (which has the same behavior as ONNX Round when RoundingMode is set to HalfToEven. This is the case when importing an ONNX model).

⚠️ The default rounding mode is HalfAwayFromZero, the same as C++ std::round(), but not the same as the default Python rounding, which is HalfToEven.

Implementations that do not yet support output integral type can ignore this attribute (as with the current implementation of these operators in CUDA).

Edited by Olivier BICHLER

Merge request reports

Loading