Skip to main content

DenseMatrix

Trait DenseMatrix 

Source
pub trait DenseMatrix:
    Matrix
    + for<'b> MatrixOpsByValue<&'b Self, Self>
    + for<'b> MatrixMutOpsByValue<&'b Self>
    + for<'a, 'b> MatrixOpsByValue<&'b Self::View<'a>, Self>
    + for<'a, 'b> MatrixMutOpsByValue<&'b Self::View<'a>> {
    type View<'a>: MatrixView<'a, Owned = Self, T = Self::T, V = Self::V>
       where Self: 'a;
    type ViewMut<'a>: MatrixViewMut<'a, Owned = Self, T = Self::T, V = Self::V, View = Self::View<'a>>
       where Self: 'a;

    // Required methods
    fn gemm(&mut self, alpha: Self::T, a: &Self, b: &Self, beta: Self::T);
    fn column_axpy(&mut self, alpha: Self::T, j: IndexType, i: IndexType);
    fn columns(&self, start: IndexType, end: IndexType) -> Self::View<'_>;
    fn column(&self, i: IndexType) -> <Self::V as Vector>::View<'_>;
    fn columns_mut(
        &mut self,
        start: IndexType,
        end: IndexType,
    ) -> Self::ViewMut<'_>;
    fn column_mut(&mut self, i: IndexType) -> <Self::V as Vector>::ViewMut<'_>;
    fn set_index(&mut self, i: IndexType, j: IndexType, value: Self::T);
    fn get_index(&self, i: IndexType, j: IndexType) -> Self::T;
    fn resize_cols(&mut self, ncols: IndexType);
    fn from_vec(
        nrows: IndexType,
        ncols: IndexType,
        data: Vec<Self::T>,
        ctx: Self::C,
    ) -> Self;

    // Provided method
    fn mat_mul(&self, b: &Self) -> Self { ... }
}
Expand description

A dense column-major matrix with efficient column access operations.

This trait represents matrices stored in column-major order, where accessing matrix columns is efficient. It supports:

  • Matrix views and mutable views
  • Matrix-matrix multiplication (GEMM)
  • Column operations (axpy, access, modification)
  • Element access and modification
  • Matrix resizing

The column-major layout makes operations on individual or ranges of columns very efficient.

Required Associated Types§

Source

type View<'a>: MatrixView<'a, Owned = Self, T = Self::T, V = Self::V> where Self: 'a

A view of the dense matrix type

Source

type ViewMut<'a>: MatrixViewMut<'a, Owned = Self, T = Self::T, V = Self::V, View = Self::View<'a>> where Self: 'a

A mutable view of the dense matrix type

Required Methods§

Source

fn gemm(&mut self, alpha: Self::T, a: &Self, b: &Self, beta: Self::T)

Perform a matrix-matrix multiplication: self = alpha * a * b + beta * self

Source

fn column_axpy(&mut self, alpha: Self::T, j: IndexType, i: IndexType)

Perform a column AXPY operation: column i = alpha * column j + column i

This is equivalent to: self[:, i] += alpha * self[:, j]

Source

fn columns(&self, start: IndexType, end: IndexType) -> Self::View<'_>

Get an immutable view of columns from start (inclusive) to end (exclusive).

Source

fn column(&self, i: IndexType) -> <Self::V as Vector>::View<'_>

Get an immutable vector view of column i.

Source

fn columns_mut(&mut self, start: IndexType, end: IndexType) -> Self::ViewMut<'_>

Get a mutable view of columns from start (inclusive) to end (exclusive).

Source

fn column_mut(&mut self, i: IndexType) -> <Self::V as Vector>::ViewMut<'_>

Get a mutable vector view of column i.

Source

fn set_index(&mut self, i: IndexType, j: IndexType, value: Self::T)

Set the value at the given row and column indices.

Source

fn get_index(&self, i: IndexType, j: IndexType) -> Self::T

Get the value at the given row and column indices.

Source

fn resize_cols(&mut self, ncols: IndexType)

Resize the number of columns in the matrix, preserving existing data.

New elements (if added) are uninitialized. If the number of columns decreases, trailing columns are discarded.

Source

fn from_vec( nrows: IndexType, ncols: IndexType, data: Vec<Self::T>, ctx: Self::C, ) -> Self

Create a new matrix from a vector of values in column-major order.

The values are assumed to be stored in column-major order (first column, then second column, etc.).

Provided Methods§

Source

fn mat_mul(&self, b: &Self) -> Self

Perform matrix-matrix multiplication using GEMM, allocating a new matrix for the result.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§