Expand description
Signed fixed-point Q-format arithmetic, ported from tinymind (C++) cpp/qformat.hpp.
The C++ QValue<FixedBits, FractionalBits, IsSigned, RoundingPolicy, SaturatePolicy>
picks its storage type from FixedBits + FractionalBits at compile time
(QTypeChooser). Stable Rust cannot compute a type from const-generic
arithmetic (that needs the nightly generic_const_exprs feature), so here the
storage type is an explicit parameter: QValue<i32, 16> is Q16.16 and
QValue<i16, 8> is Q8.8. The methods and operators are generated for each
supported storage type by a macro, each with the wider type C++ uses for
products and quotients (i64 for i32, i32 for i16).
Only tinymind (C++)’s default policies are ported: TruncatePolicy (multiplication
drops the low bits) and WrapPolicy (addition and subtraction wrap modulo the
storage width).
The module also defines Scalar, the value-type trait every network is
generic over, implemented for these formats and for f32 and f64 (and the
deprecated Fixed, its name up to 0.1.5).
Structs§
- QValue
- A signed fixed-point value stored in
S(i16ori32) withFRACfractional bits.
Traits§
- Fixed
Deprecated - The name of
Scalarup to 0.1.5, kept so that bounds writtenV: Fixedstill compile. EveryScalaris aFixed; implementScalarinstead.Fixedhas no items of its own, so paths that name them through it (<V as Fixed>::ONE,Fixed::div_int(..)) must nameScalar. - Scalar
- A network’s value type: the arithmetic a network needs from the numbers it computes with. This is the Rust counterpart of the implicit “ValueType concept” that the C++ templates rely on: in C++ a missing operator is a template instantiation error, here it is a trait-bound error at the call site.
- Sqrt
- Square root of a non-negative value (C++
SquareRootApproximation): integer Newton iteration onraw << FRACin the wide type, which gives the floor of the exact root in raw units. Zero and negative values give zero. The Adam and RMSprop optimizers use it.