banded_sym_array

Function banded_sym_array 

Source
pub fn banded_sym_array<T>(
    diagonals: &[Vec<T>],
    n: usize,
    format: &str,
) -> SparseResult<Box<dyn SymSparseArray<T>>>
where T: Float + Debug + Copy + 'static + Add<Output = T> + Sub<Output = T> + Mul<Output = T> + Div<Output = T> + SimdUnifiedOps + Send + Sync,
Expand description

Create a symmetric banded matrix from diagonals

§Arguments

  • diagonals - Vector of diagonals to populate, where index 0 is the main diagonal
  • n - Size of the matrix (n x n)
  • format - Format of the output matrix (“csr” or “coo”)

§Returns

A symmetric banded matrix

§Examples

use scirs2_sparse::construct_sym::banded_sym_array;

// Create a 5x5 symmetric banded matrix with:
// - Main diagonal: [2, 2, 2, 2, 2]
// - First off-diagonal: [1, 1, 1, 1]
// - Second off-diagonal: [0.5, 0.5, 0.5]

let diagonals = vec![
    vec![2.0, 2.0, 2.0, 2.0, 2.0],       // Main diagonal
    vec![1.0, 1.0, 1.0, 1.0],            // First off-diagonal
    vec![0.5, 0.5, 0.5],                 // Second off-diagonal
];

let banded = banded_sym_array(&diagonals, 5, "csr").unwrap();

assert_eq!(banded.shape(), (5, 5));
assert_eq!(banded.get(0, 0), 2.0);  // Main diagonal
assert_eq!(banded.get(0, 1), 1.0);  // First off-diagonal
assert_eq!(banded.get(0, 2), 0.5);  // Second off-diagonal
assert_eq!(banded.get(0, 3), 0.0);  // Outside band