Skip to main content

CpuLinAlg

Struct CpuLinAlg 

Source
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 Clone for CpuLinAlg

Source§

fn clone(&self) -> CpuLinAlg

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CpuLinAlg

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl LinAlg for CpuLinAlg

Source§

type Vector = Vec<f64>

1-D vector type.
Source§

type Matrix = Matrix

2-D matrix type.
Source§

fn zeros_vec(size: usize) -> Self::Vector

Creates a zero-filled vector of the given size.
Source§

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

Creates a matrix with Xavier-uniform initialization.
Source§

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

Returns the transpose of the matrix.
Source§

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

Matrix-matrix multiplication: a * b. Read more
Source§

fn svd(m: &Self::Matrix) -> SvdResult<Self>

Singular Value Decomposition: M = U × diag(S) × V^T. Read more
Source§

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_rows(m: &Self::Matrix) -> usize

Returns the number of rows.
Source§

fn mat_cols(m: &Self::Matrix) -> usize

Returns the number of columns.
Source§

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)

Sets the element at (row, col).
Source§

fn vec_add(a: &Self::Vector, b: &Self::Vector) -> Self::Vector

Element-wise addition: a + b.
Source§

fn vec_sub(a: &Self::Vector, b: &Self::Vector) -> Self::Vector

Element-wise subtraction: a - b.
Source§

fn vec_scale(v: &Self::Vector, s: f64) -> Self::Vector

Scalar multiplication: v * s.
Source§

fn vec_hadamard(a: &Self::Vector, b: &Self::Vector) -> Self::Vector

Element-wise (Hadamard) product: a[i] * b[i].
Source§

fn vec_dot(a: &Self::Vector, b: &Self::Vector) -> f64

Dot product: sum(a[i] * b[i]).
Source§

fn vec_len(v: &Self::Vector) -> usize

Returns the number of elements in the vector.
Source§

fn vec_get(v: &Self::Vector, i: usize) -> f64

Returns the element at index i.
Source§

fn vec_set(v: &mut Self::Vector, i: usize, val: f64)

Sets the element at index i.
Source§

fn vec_from_slice(s: &[f64]) -> Self::Vector

Creates a vector from a slice of f64.
Source§

fn vec_to_vec(v: &Self::Vector) -> Vec<f64>

Converts the vector to a Vec<f64> (copies data).
Source§

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)

Clamps each element to [-max_abs, max_abs] in place.
Source§

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

Applies an activation function element-wise.
Source§

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

Numerically stable masked softmax.
Source§

fn argmax_masked(values: &Self::Vector, mask: &[usize]) -> usize

Returns the index of the maximum value among masked indices.
Source§

fn sample_from_probs( probs: &Self::Vector, mask: &[usize], rng: &mut impl Rng, ) -> usize

Samples an action index from a probability distribution over masked indices.
Source§

fn rms_error(error_vecs: &[&Self::Vector]) -> f64

Combined RMS error across multiple error vectors.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V