pub trait Module<R: Ring>:
AbelianGroup
+ Mul<R, Output = Self>
+ MulAssign<R> {
// Provided methods
fn scale(&self, scalar: R) -> Self { ... }
fn scale_mut(&mut self, scalar: R) { ... }
}Expand description
Represents a Module over a Ring.
A module is a generalization of a vector space, where the scalars are
elements of a Ring R rather than being restricted to a Field.
§Mathematical Definition
A left module M over a ring R consists of an abelian group (M, +) and
an operation R × M → M (scalar multiplication) such that for all
r, s in R and x, y in M, the following axioms hold:
r * (x + y) = r*x + r*y(r + s) * x = r*x + s*x(r * s) * x = r * (s * x)1 * x = x(ifRis a unital ring)
§Structure in this Crate
- The “vectors” (
Self) form anAbelianGroup. - The “scalars” (
R) form aRing. - Scalar multiplication is provided by implementing
Mul<R>andMulAssign<R>.
§Examples
- Any
AbelianGroupGis a module over the ring of integersZ. - A vector space is a module where the ring of scalars is a
Field. Complex<T>is a module over theRealFieldT.
Provided Methods§
Sourcefn scale_mut(&mut self, scalar: R)
fn scale_mut(&mut self, scalar: R)
Scales the module element in-place by a scalar from the ring R.
This is a convenience method that uses the MulAssign (*=) operator
for in-place scalar multiplication. This is often more efficient for
large data structures like tensors as it avoids allocation.
§Arguments
scalar: The scalar value of typeRto multiply by.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.