2020-11-25 00:36:03 +08:00
|
|
|
use crate::convert::serial::*;
|
2021-01-26 00:26:27 +08:00
|
|
|
use crate::coo::CooMatrix;
|
2020-11-25 00:36:03 +08:00
|
|
|
use crate::csc::CscMatrix;
|
2021-01-26 00:26:27 +08:00
|
|
|
use crate::csr::CsrMatrix;
|
|
|
|
use nalgebra::storage::Storage;
|
|
|
|
use nalgebra::{ClosedAdd, DMatrix, Dim, Matrix, Scalar};
|
|
|
|
use num_traits::Zero;
|
2020-11-18 21:14:38 +08:00
|
|
|
|
|
|
|
impl<'a, T, R, C, S> From<&'a Matrix<T, R, C, S>> for CooMatrix<T>
|
|
|
|
where
|
|
|
|
T: Scalar + Zero,
|
|
|
|
R: Dim,
|
|
|
|
C: Dim,
|
2021-01-26 00:26:27 +08:00
|
|
|
S: Storage<T, R, C>,
|
2020-11-18 21:14:38 +08:00
|
|
|
{
|
|
|
|
fn from(matrix: &'a Matrix<T, R, C, S>) -> Self {
|
|
|
|
convert_dense_coo(matrix)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a, T> From<&'a CooMatrix<T>> for DMatrix<T>
|
|
|
|
where
|
|
|
|
T: Scalar + Zero + ClosedAdd,
|
|
|
|
{
|
|
|
|
fn from(coo: &'a CooMatrix<T>) -> Self {
|
|
|
|
convert_coo_dense(coo)
|
|
|
|
}
|
2020-11-25 00:36:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a, T> From<&'a CooMatrix<T>> for CsrMatrix<T>
|
|
|
|
where
|
2021-01-26 00:26:27 +08:00
|
|
|
T: Scalar + Zero + ClosedAdd,
|
2020-11-25 00:36:03 +08:00
|
|
|
{
|
|
|
|
fn from(matrix: &'a CooMatrix<T>) -> Self {
|
|
|
|
convert_coo_csr(matrix)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a, T> From<&'a CsrMatrix<T>> for CooMatrix<T>
|
|
|
|
where
|
2021-01-26 00:26:27 +08:00
|
|
|
T: Scalar + Zero + ClosedAdd,
|
2020-11-25 00:36:03 +08:00
|
|
|
{
|
|
|
|
fn from(matrix: &'a CsrMatrix<T>) -> Self {
|
|
|
|
convert_csr_coo(matrix)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a, T, R, C, S> From<&'a Matrix<T, R, C, S>> for CsrMatrix<T>
|
|
|
|
where
|
|
|
|
T: Scalar + Zero,
|
|
|
|
R: Dim,
|
|
|
|
C: Dim,
|
2021-01-26 00:26:27 +08:00
|
|
|
S: Storage<T, R, C>,
|
2020-11-25 00:36:03 +08:00
|
|
|
{
|
|
|
|
fn from(matrix: &'a Matrix<T, R, C, S>) -> Self {
|
|
|
|
convert_dense_csr(matrix)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a, T> From<&'a CsrMatrix<T>> for DMatrix<T>
|
|
|
|
where
|
2021-01-26 00:26:27 +08:00
|
|
|
T: Scalar + Zero + ClosedAdd,
|
2020-11-25 00:36:03 +08:00
|
|
|
{
|
|
|
|
fn from(matrix: &'a CsrMatrix<T>) -> Self {
|
|
|
|
convert_csr_dense(matrix)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a, T> From<&'a CooMatrix<T>> for CscMatrix<T>
|
|
|
|
where
|
2021-01-26 00:26:27 +08:00
|
|
|
T: Scalar + Zero + ClosedAdd,
|
2020-11-25 00:36:03 +08:00
|
|
|
{
|
|
|
|
fn from(matrix: &'a CooMatrix<T>) -> Self {
|
|
|
|
convert_coo_csc(matrix)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a, T> From<&'a CscMatrix<T>> for CooMatrix<T>
|
|
|
|
where
|
2021-01-26 00:26:27 +08:00
|
|
|
T: Scalar + Zero,
|
2020-11-25 00:36:03 +08:00
|
|
|
{
|
|
|
|
fn from(matrix: &'a CscMatrix<T>) -> Self {
|
|
|
|
convert_csc_coo(matrix)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a, T, R, C, S> From<&'a Matrix<T, R, C, S>> for CscMatrix<T>
|
2021-01-26 00:26:27 +08:00
|
|
|
where
|
|
|
|
T: Scalar + Zero,
|
|
|
|
R: Dim,
|
|
|
|
C: Dim,
|
|
|
|
S: Storage<T, R, C>,
|
2020-11-25 00:36:03 +08:00
|
|
|
{
|
|
|
|
fn from(matrix: &'a Matrix<T, R, C, S>) -> Self {
|
|
|
|
convert_dense_csc(matrix)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a, T> From<&'a CscMatrix<T>> for DMatrix<T>
|
2021-01-26 00:26:27 +08:00
|
|
|
where
|
|
|
|
T: Scalar + Zero + ClosedAdd,
|
2020-11-25 00:36:03 +08:00
|
|
|
{
|
|
|
|
fn from(matrix: &'a CscMatrix<T>) -> Self {
|
|
|
|
convert_csc_dense(matrix)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a, T> From<&'a CscMatrix<T>> for CsrMatrix<T>
|
2021-01-26 00:26:27 +08:00
|
|
|
where
|
|
|
|
T: Scalar,
|
2020-11-25 00:36:03 +08:00
|
|
|
{
|
|
|
|
fn from(matrix: &'a CscMatrix<T>) -> Self {
|
|
|
|
convert_csc_csr(matrix)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a, T> From<&'a CsrMatrix<T>> for CscMatrix<T>
|
|
|
|
where
|
2021-01-26 00:26:27 +08:00
|
|
|
T: Scalar,
|
2020-11-25 00:36:03 +08:00
|
|
|
{
|
|
|
|
fn from(matrix: &'a CsrMatrix<T>) -> Self {
|
|
|
|
convert_csr_csc(matrix)
|
|
|
|
}
|
2021-01-26 00:26:27 +08:00
|
|
|
}
|