Skip to main content

Module

Trait Module 

Source
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:

  1. r * (x + y) = r*x + r*y
  2. (r + s) * x = r*x + s*x
  3. (r * s) * x = r * (s * x)
  4. 1 * x = x (if R is a unital ring)

§Structure in this Crate

  • The “vectors” (Self) form an AbelianGroup.
  • The “scalars” (R) form a Ring.
  • Scalar multiplication is provided by implementing Mul<R> and MulAssign<R>.

§Examples

  • Any AbelianGroup G is a module over the ring of integers Z.
  • A vector space is a module where the ring of scalars is a Field.
  • Complex<T> is a module over the RealField T.

Provided Methods§

Source

fn scale(&self, scalar: R) -> Self

Scales the module element by a scalar from the ring R.

This is a convenience method that clones self and applies the * operator for scalar multiplication.

§Arguments
  • scalar: The scalar value of type R to multiply by.
§Returns

A new element of Self representing the scaled result.

Source

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 type R to 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.

Implementors§

Source§

impl<V, R> Module<R> for V
where V: AbelianGroup + Mul<R, Output = V> + MulAssign<R>, R: Ring,