pub fn banded_sym_array<T>(
diagonals: &[Vec<T>],
n: usize,
format: &str,
) -> SparseResult<Box<dyn SymSparseArray<T>>>
Expand description
Create a symmetric banded matrix from diagonals
§Arguments
diagonals
- Vector of diagonals to populate, where index 0 is the main diagonaln
- 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