pub fn csr_mul_csr_impl<N, I>(lhs: CsMatViewI<N, I>,
                              rhs: CsMatViewI<N, I>,
                              workspace: &mut[N]
                             ) -> CsMatI<N, I>
where N: Num + Copy,
      I: SpIndex
{
    let res_rows = lhs.rows();
    let res_cols = rhs.cols();
    if lhs.cols() != rhs.rows() {
        panic!("Dimension mismatch");
    }
    if res_cols !=  workspace.len() {
        panic!("Bad storage dimension");
    }
    if lhs.storage() != rhs.storage() || !rhs.is_csr() {
        panic!("Storage mismatch");
    }

    let mut res = CsMatI::empty(lhs.storage(), res_cols);
    res.reserve_nnz_exact(lhs.nnz() + rhs.nnz());
    for lvec in lhs.outer_iterator() {
        // reset the accumulators
        for wval in workspace.iter_mut() {
            *wval = N::zero();
        }
        // accumulate the resulting row
        for (lcol, &lval) in lvec.iter() {
            // we can't be out of bounds thanks to the checks of dimension
            // compatibility and the structure check of CsMat. Therefore it
            // should be safe to call into an unsafe version of outer_view
            let rvec = rhs.outer_view(lcol).unwrap();
            for (rcol, &rval) in rvec.iter() {
                let wval = &mut workspace[rcol];
                let prod = lval * rval;
                *wval = *wval + prod;
            }
        }
        // compress the row into the resulting matrix
        res = res.append_outer(&workspace);
    }
    // TODO: shrink res storage? would need methods on CsMat
    assert_eq!(res_rows, res.rows());
    res
}
/// Actual implementation of CSR-CSR multiplication
/// All other matrix products are implemented in terms of this one.
Actual implementation of CSR-CSR multiplication
All other matrix products are implemented in terms of this one.
Actual implementation of CSR - CSR multiplication All other matrix products are implemented in terms of this one .
pub fn csr_mul_csr_impl<N, I>(lhs: CsMatViewI<N, I>,
                              rhs: CsMatViewI<N, I>,
                              workspace: &mut[N]
                             ) -> CsMatI<N, I>
where N: Num + Copy,
      I: SpIndex
{
    let res_rows = lhs.rows();
    let res_cols = rhs.cols();
    if lhs.cols() != rhs.rows() {
        panic!("Dimension mismatch");
    }
    if res_cols !=  workspace.len() {
        panic!("Bad storage dimension");
    }
    if lhs.storage() != rhs.storage() || !rhs.is_csr() {
        panic!("Storage mismatch");
    }
    let mut res = CsMatI::empty(lhs.storage(), res_cols);
    res.reserve_nnz_exact(lhs.nnz() + rhs.nnz());
    for lvec in lhs.outer_iterator() {
        // reset the accumulators
        for wval in workspace.iter_mut() {
            *wval = N::zero();
        }
        // accumulate the resulting row
        for (lcol, &lval) in lvec.iter() {
            // we can't be out of bounds thanks to the checks of dimension
            // compatibility and the structure check of CsMat. Therefore it
            // should be safe to call into an unsafe version of outer_view
            let rvec = rhs.outer_view(lcol).unwrap();
            for (rcol, &rval) in rvec.iter() {
                let wval = &mut workspace[rcol];
                let prod = lval * rval;
                *wval = *wval + prod;
            }
        }
        // compress the row into the resulting matrix
        res = res.append_outer(&workspace);
    }
    // TODO: shrink res storage? would need methods on CsMat
    assert_eq!(res_rows, res.rows());
    res
}
pub fn csr_mul_csr_impl < N , I > ( lhs : CsMatViewI < N , I > , rhs : CsMatViewI < N , I > , workspace : & mut [ N ] ) -> CsMatI < N , I > where N : Num + Copy , I : SpIndex { let res_rows = lhs . rows ( ) ; let res_cols = rhs . cols ( ) ; if lhs . cols ( ) != rhs . rows ( ) { panic ! ( " " ) ; } if res_cols != workspace . len ( ) { panic ! ( " " ) ; } if lhs . storage ( ) != rhs . storage ( ) || ! rhs . is_csr ( ) { panic ! ( " " ) ; } let mut res = CsMatI :: empty ( lhs . storage ( ) , res_cols ) ; res . reserve_nnz_exact ( lhs . nnz ( ) + rhs . nnz ( ) ) ; for lvec in lhs . outer_iterator ( ) { // reset the accumulators for wval in workspace . iter_mut ( ) { * wval = N :: zero ( ) ; } // accumulate the resulting row for ( lcol , & lval ) in lvec . iter ( ) { // we can't be out of bounds thanks to the checks of dimension // compatibility and the structure check of CsMat. Therefore it // should be safe to call into an unsafe version of outer_view let rvec = rhs . outer_view ( lcol ) . unwrap ( ) ; for ( rcol , & rval ) in rvec . iter ( ) { let wval = & mut workspace [ rcol ] ; let prod = lval * rval ; * wval = * wval + prod ; } } // compress the row into the resulting matrix res = res . append_outer ( & workspace ) ; } // TODO: shrink res storage? would need methods on CsMat assert_eq ! ( res_rows res rows ( ) ) ; res }
Actual implementation of CSR-CSR multiplication
All other matrix products are implemented in terms of this one.
Actual implementation of CSR - CSR multiplication All other matrix products are implemented in terms of this one .
lhs
CsMatViewI<N, I>
rhs
CsMatViewI<N, I>
workspace
&mut[N]
lhs
CsMatViewI<N, I>
rhs
CsMatViewI<N, I>
workspace
&mut[N]