Function diags_array

Source
pub fn diags_array<T>(
    diagonals: &[Array1<T>],
    offsets: &[isize],
    shape: (usize, usize),
    format: &str,
) -> SparseResult<Box<dyn SparseArray<T>>>
where T: Float + Add<Output = T> + Sub<Output = T> + Mul<Output = T> + Div<Output = T> + Debug + Copy + 'static,
Expand description

Creates a sparse array from the specified diagonals

§Arguments

  • diagonals - Data for the diagonals
  • offsets - Offset for each diagonal (0 = main, >0 = above main, <0 = below main)
  • shape - Shape of the output array (m, n)
  • format - Format of the output array (“csr” or “coo”)

§Returns

A sparse array with the specified diagonals

§Examples

use scirs2_sparse::construct::diags_array;
use ndarray::Array1;

let diags = vec![
    Array1::from_vec(vec![1.0, 2.0, 3.0]), // main diagonal
    Array1::from_vec(vec![4.0, 5.0])       // superdiagonal
];
let offsets = vec![0, 1];
let shape = (3, 3);

let result = diags_array(&diags, &offsets, shape, "csr").unwrap();
assert_eq!(result.shape(), (3, 3));
assert_eq!(result.get(0, 0), 1.0);
assert_eq!(result.get(1, 1), 2.0);
assert_eq!(result.get(2, 2), 3.0);
assert_eq!(result.get(0, 1), 4.0);
assert_eq!(result.get(1, 2), 5.0);