Function diagm_csc

Source
pub fn diagm_csc(data: &[f64], offset: isize) -> CscMatrix<f64>
Expand description

Creates a diagonal sparse CSC matrix with the given data placed on a specified diagonal.

This function constructs a matrix where the provided data is placed on a diagonal that can be offset from the main diagonal. The resulting matrix size is determined by the length of the data and the absolute value of the offset.

§Arguments

  • data - A slice of f64 values to be placed on the diagonal
  • offset - The diagonal offset:
    • 0: Main diagonal
    • Positive: above the main diagonal (upper-diagonal)
    • Negative: below the main diagonal (lower-diagonal)

§Returns

A CscMatrix<f64> containing the diagonal matrix. If data is empty, returns a 0×0 matrix.

§Examples

use iterative_solvers::utils::sparse::diagm_csr;

// Main diagonal
let data = vec![1.0, 2.0, 3.0];
let mat = diagm_csr(&data, 0);
// Creates:
// [1.0, 0.0, 0.0]
// [0.0, 2.0, 0.0]
// [0.0, 0.0, 3.0]

// Upper-diagonal (offset = 1)
let mat = diagm_csr(&data, 1);
// Creates:
// [0.0, 1.0, 0.0, 0.0]
// [0.0, 0.0, 2.0, 0.0]
// [0.0, 0.0, 0.0, 3.0]
// [0.0, 0.0, 0.0, 0.0]