Skip to main content

DenseMatrix

Trait DenseMatrix 

Source
pub trait DenseMatrix:
    Matrix
    + for<'b> MatrixOpsByValue<&'b Self, Self>
    + for<'b> MatrixMutOpsByValue<&'b Self> {
    // Required methods
    fn update_backward_diff(&mut self, order: IndexType, d: &Self::V);
    fn mul_cols_by(&mut self, ncols: IndexType, rhs: &[Self::T]);
    fn gemv_cols(
        &self,
        start: IndexType,
        end: IndexType,
        alpha: Self::T,
        x: &[Self::T],
        beta: Self::T,
        y: &mut Self::V,
    );
    fn column(&self, i: IndexType) -> <Self::V as Vector>::View<'_>;
    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 set_index_batch(
        &mut self,
        batch: IndexType,
        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;
}
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:

  • Column operations (access, modification, and the fused column kernels below)
  • Element access and modification
  • Matrix resizing

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

Required Methods§

Source

fn update_backward_diff(&mut self, order: IndexType, d: &Self::V)

Update a table of backward differences held in columns 0..=order+2 of this matrix, given the newly computed highest-order correction d.

Equivalent to:

self[:, order+2] = d - self[:, order+1]
for i in (0..=order+1).rev() { self[:, i] += self[:, i+1] }

where each addition uses the just-updated value of column i+1 (a right-to-left cumulative scan).

Source

fn mul_cols_by(&mut self, ncols: IndexType, rhs: &[Self::T])

Right-multiply a range of columns by a small matrix, in place:

self[:, 0..ncols] = self[:, 0..ncols] * rhs

rhs is an ncols x ncols block held column-major in a host slice of exactly ncols * ncols values — it is small (the BDF step-size update uses at most 6 x 6).

Panics if ncols exceeds MAX_SMALL_COLS, since the serial backends stage the old column values in a fixed-size buffer rather than allocating.

Source

fn gemv_cols( &self, start: IndexType, end: IndexType, alpha: Self::T, x: &[Self::T], beta: Self::T, y: &mut Self::V, )

Matrix-vector multiply over a range of columns, with host-side coefficients:

y = alpha * self[:, start..end] * x + beta * y

x is a host slice, not a vector, because x.len() is the width of the column range rather than a dimension of the problem: every caller in the solvers passes a short coefficient list computed from host scalars — a Runge-Kutta tableau row, the b/d vectors, interpolation weights, BDF’s psi weights. Keeping them on the host is what lets those callers build them in a stack array instead of allocating a vector per call.

Use Matrix::gemv instead when x is a genuine operand of length ncols — a Jacobian- or mass-times-vector product.

Only the leading end - start columns take part; the rest of the matrix is not read. x.len() must be at least end - start; only its leading end - start entries are read, as with a BLAS gemv given a longer vector and incx = 1. beta == 0 means y is not read, so it may hold uninitialised values. An empty range contributes nothing, leaving y = beta * y.

The coefficients are shared by every batch — unlike Matrix::gemv, this cannot apply a different x per batch. Panics if end - start exceeds MAX_SMALL_COLS.

Source

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

Get an immutable vector view of column i.

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.

Scalar access is single-system, as it is for Vector::set_index: panics unless nbatch == 1. So does IndexMut.

Source

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

Set the value at the given row and column indices, in a single batch.

The batch-aware counterpart to Self::set_index: (i, j) alone is ambiguous once nbatch > 1, so the batch is named explicitly. Mirrors Vector::get_batch_mut.

Source

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

Get the value at the given row and column indices.

Scalar access is single-system, as it is for Vector::get_index: panics unless nbatch == 1. So does Index.

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.).

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§