use tokio::sync::oneshot;
use crate::dtype::{SparseIndex, SparseSupported};
use crate::error::GpuError;
use crate::gpu_ref::GpuRef;
use super::format::SparseMatrix;
use super::spmm::DenseOrder;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ConvertKind {
DenseToSparse,
SparseToDense,
}
pub struct ConvertRequest<T: SparseSupported, I: SparseIndex> {
pub kind: ConvertKind,
pub dense: GpuRef<T>,
pub dense_rows: i64,
pub dense_cols: i64,
pub dense_ld: i64,
pub dense_order: DenseOrder,
pub sparse: SparseMatrix<T, I>,
pub reply: oneshot::Sender<Result<ConvertResult, GpuError>>,
}
#[derive(Debug, Clone, Copy)]
pub struct ConvertResult {
pub nnz: i64,
}
impl<T: SparseSupported, I: SparseIndex> ConvertRequest<T, I> {
#[allow(clippy::too_many_arguments)]
pub fn dense_to_sparse(
dense: GpuRef<T>,
rows: i64,
cols: i64,
ld: i64,
order: DenseOrder,
sparse: SparseMatrix<T, I>,
reply: oneshot::Sender<Result<ConvertResult, GpuError>>,
) -> Self {
Self {
kind: ConvertKind::DenseToSparse,
dense,
dense_rows: rows,
dense_cols: cols,
dense_ld: ld,
dense_order: order,
sparse,
reply,
}
}
#[allow(clippy::too_many_arguments)]
pub fn sparse_to_dense(
sparse: SparseMatrix<T, I>,
dense: GpuRef<T>,
rows: i64,
cols: i64,
ld: i64,
order: DenseOrder,
reply: oneshot::Sender<Result<ConvertResult, GpuError>>,
) -> Self {
Self {
kind: ConvertKind::SparseToDense,
dense,
dense_rows: rows,
dense_cols: cols,
dense_ld: ld,
dense_order: order,
sparse,
reply,
}
}
}