pub trait Scalar:
Copy
+ Default
+ PartialOrd
+ Add<Output = Self>
+ AddAssign
+ Sub<Output = Self>
+ Mul<Output = Self>
+ Div<Output = Self> {
const ZERO: Self;
const ONE: Self;
// Required methods
fn pow2_neg(n: u32) -> Self;
fn div_int(self, n: i32) -> Self;
// Provided methods
fn mul_round_toward_zero(self, rhs: Self) -> Self { ... }
fn mul_round_nearest(self, rhs: Self) -> Self { ... }
}Expand description
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.
Implemented for the QValue formats and for f32 and f64: the networks
run in fixed point or in floating point, as tinymind (C++)’s do when
instantiated with a Q format, float or double. Called Fixed up to
0.1.5; that name remains as a deprecated alias (Fixed).
Required Associated Constants§
Required Methods§
Provided Methods§
Sourcefn mul_round_toward_zero(self, rhs: Self) -> Self
fn mul_round_toward_zero(self, rhs: Self) -> Self
self * rhs rounded toward zero (C++ multiplyRoundTowardZero), used
for SGD’s momentum and acceleration terms so that a delta weight no
gradient refreshes decays to exactly 0. The default is self * rhs,
right for floating point; the Q formats round their product toward
zero instead of flooring it.
Sourcefn mul_round_nearest(self, rhs: Self) -> Self
fn mul_round_nearest(self, rhs: Self) -> Self
self * rhs rounded to nearest, ties away from zero (C++
multiplyRoundNearest), used for SGD’s step learning rate * gradient, so that steps smaller than the format’s resolution do not
all drift one way. The default is self * rhs, right for floating
point; the Q formats round their product to nearest instead of
flooring it.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".