pub struct CpuLinAlg;Expand description
CPU linear algebra backend.
Uses Vec<f64> for vectors and Matrix for matrices.
All trait methods delegate to existing implementations in
crate::matrix and crate::activation.
Trait Implementations§
Source§impl LinAlg for CpuLinAlg
impl LinAlg for CpuLinAlg
Source§fn zeros_mat(rows: usize, cols: usize) -> Self::Matrix
fn zeros_mat(rows: usize, cols: usize) -> Self::Matrix
Creates a zero-filled matrix with the given dimensions.
Source§fn xavier_mat(rows: usize, cols: usize, rng: &mut impl Rng) -> Self::Matrix
fn xavier_mat(rows: usize, cols: usize, rng: &mut impl Rng) -> Self::Matrix
Creates a matrix with Xavier-uniform initialization.
Source§fn mat_vec_mul(m: &Self::Matrix, v: &Self::Vector) -> Self::Vector
fn mat_vec_mul(m: &Self::Matrix, v: &Self::Vector) -> Self::Vector
Matrix-vector multiplication:
m * v.Source§fn mat_transpose(m: &Self::Matrix) -> Self::Matrix
fn mat_transpose(m: &Self::Matrix) -> Self::Matrix
Returns the transpose of the matrix.
Source§fn outer_product(a: &Self::Vector, b: &Self::Vector) -> Self::Matrix
fn outer_product(a: &Self::Vector, b: &Self::Vector) -> Self::Matrix
Outer product of two vectors:
a * b^T.Source§fn mat_mul(a: &Self::Matrix, b: &Self::Matrix) -> Self::Matrix
fn mat_mul(a: &Self::Matrix, b: &Self::Matrix) -> Self::Matrix
Matrix-matrix multiplication:
a * b. Read moreSource§fn svd(m: &Self::Matrix) -> SvdResult<Self>
fn svd(m: &Self::Matrix) -> SvdResult<Self>
Singular Value Decomposition:
M = U × diag(S) × V^T. Read moreSource§fn mat_scale_add(m: &mut Self::Matrix, other: &Self::Matrix, scale: f64)
fn mat_scale_add(m: &mut Self::Matrix, other: &Self::Matrix, scale: f64)
Adds
scale * other element-wise to m (in place).Source§fn mat_get(m: &Self::Matrix, row: usize, col: usize) -> f64
fn mat_get(m: &Self::Matrix, row: usize, col: usize) -> f64
Returns the element at
(row, col).Source§fn mat_set(m: &mut Self::Matrix, row: usize, col: usize, val: f64)
fn mat_set(m: &mut Self::Matrix, row: usize, col: usize, val: f64)
Sets the element at
(row, col).Source§fn vec_sub(a: &Self::Vector, b: &Self::Vector) -> Self::Vector
fn vec_sub(a: &Self::Vector, b: &Self::Vector) -> Self::Vector
Element-wise subtraction:
a - b.Source§fn vec_hadamard(a: &Self::Vector, b: &Self::Vector) -> Self::Vector
fn vec_hadamard(a: &Self::Vector, b: &Self::Vector) -> Self::Vector
Element-wise (Hadamard) product:
a[i] * b[i].Source§fn vec_from_slice(s: &[f64]) -> Self::Vector
fn vec_from_slice(s: &[f64]) -> Self::Vector
Creates a vector from a slice of
f64.Source§fn vec_as_slice(v: &Self::Vector) -> &[f64]
fn vec_as_slice(v: &Self::Vector) -> &[f64]
Returns a slice view of the vector data (zero-copy for CPU). Read more
Source§fn clip_vec(v: &mut Self::Vector, max_abs: f64)
fn clip_vec(v: &mut Self::Vector, max_abs: f64)
Clamps each element to
[-max_abs, max_abs] in place.Source§fn clip_mat(m: &mut Self::Matrix, max_abs: f64)
fn clip_mat(m: &mut Self::Matrix, max_abs: f64)
Clamps each matrix element to
[-max_abs, max_abs] in place.Source§fn apply_activation(v: &Self::Vector, act: Activation) -> Self::Vector
fn apply_activation(v: &Self::Vector, act: Activation) -> Self::Vector
Applies an activation function element-wise.
Source§fn apply_derivative(v: &Self::Vector, act: Activation) -> Self::Vector
fn apply_derivative(v: &Self::Vector, act: Activation) -> Self::Vector
Applies an activation derivative element-wise.
Source§fn softmax_masked(logits: &Self::Vector, mask: &[usize]) -> Self::Vector
fn softmax_masked(logits: &Self::Vector, mask: &[usize]) -> Self::Vector
Numerically stable masked softmax.
Source§fn argmax_masked(values: &Self::Vector, mask: &[usize]) -> usize
fn argmax_masked(values: &Self::Vector, mask: &[usize]) -> usize
Returns the index of the maximum value among masked indices.
Auto Trait Implementations§
impl Freeze for CpuLinAlg
impl RefUnwindSafe for CpuLinAlg
impl Send for CpuLinAlg
impl Sync for CpuLinAlg
impl Unpin for CpuLinAlg
impl UnsafeUnpin for CpuLinAlg
impl UnwindSafe for CpuLinAlg
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more