use crate::traits::{Integer, Scalar};
use crate::util::axpy;
use crate::{csr_diagonal, csr_matmat, csr_matmat_maxnnz, csr_tocsc};
pub fn csc_matvec<I: Integer, T: Scalar>(
_n_row: usize,
n_col: usize,
a_p: &[I],
a_i: &[I],
a_x: &[T],
x_x: &[T],
y_x: &mut [T],
) {
for j in 0..n_col {
let col_start = a_p[j].to_usize().unwrap();
let col_end = a_p[j + 1].to_usize().unwrap();
for ii in col_start..col_end {
let i = a_i[ii].to_usize().unwrap();
y_x[i] += a_x[ii] * x_x[j];
}
}
}
pub fn csc_matvecs<I: Integer, T: Scalar>(
_n_row: usize,
n_col: usize,
n_vecs: usize,
a_p: &[I],
a_i: &[I],
a_x: &[T],
x_x: &[T],
y_x: &mut [T],
) {
for j in 0..n_col {
let start = a_p[j].to_usize().unwrap();
let end = a_p[j + 1].to_usize().unwrap();
for ii in start..end {
let i = a_i[ii].to_usize().unwrap();
axpy(
n_vecs,
a_x[ii],
&x_x[(n_vecs * j)..],
&mut y_x[(n_vecs * i)..],
);
}
}
}
pub fn csc_diagonal<I: Integer, T: Scalar>(
k: isize,
n_row: usize,
n_col: usize,
a_p: &[I],
a_j: &[I],
a_x: &[T],
y_x: &mut [T],
) {
csr_diagonal(-k, n_col, n_row, a_p, a_j, a_x, y_x);
}
pub fn csc_tocsr<I: Integer, T: Scalar>(
n_row: usize,
n_col: usize,
a_p: &[I],
a_i: &[I],
a_x: &[T],
b_p: &mut [I],
b_j: &mut [I],
b_x: &mut [T],
) {
csr_tocsc(n_col, n_row, a_p, a_i, a_x, b_p, b_j, b_x);
}
pub fn csc_matmat_maxnnz<I: Integer>(
n_row: usize,
n_col: usize,
a_p: &[I],
a_i: &[I],
b_p: &[I],
b_i: &[I],
) -> usize
{
return csr_matmat_maxnnz(n_col, n_row, b_p, b_i, a_p, a_i);
}
pub fn csc_matmat<I: Integer, T: Scalar>(
n_row: usize,
n_col: usize,
a_p: &[I],
a_i: &[I],
a_x: &[T],
b_p: &[I],
b_i: &[I],
b_x: &[T],
c_p: &mut [I],
c_i: &mut [I],
c_x: &mut [T],
) {
csr_matmat(n_col, n_row, b_p, b_i, b_x, a_p, a_i, a_x, c_p, c_i, c_x);
}