Skip to content

Commit

Permalink
some better imports and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
McArthur-Alford committed Jul 11, 2024
1 parent 24daafd commit 790ed5f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion crates/burn-core/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ pub use burn_tch as libtorch;
pub use burn_tch::LibTorch;

#[cfg(feature = "sparse")]
pub use burn_sparse as sparse;
pub use burn_sparse::decorator as sparse;
5 changes: 5 additions & 0 deletions crates/burn-core/src/tensor.rs
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
pub use burn_tensor::*;

#[cfg(feature = "sparse")]
pub mod sparse {
pub use burn_sparse::backend::*;
}
20 changes: 18 additions & 2 deletions crates/burn-sparse/src/backend/api.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
use crate::backend::{Sparse, SparseBackend};
use burn_tensor::{Int, Tensor, TensorPrimitive};

pub trait SparseTensor<const D: usize, B>
pub trait ToSparse<const D: usize, B>
where
B: SparseBackend,
{
fn into_sparse(self) -> Tensor<B, D, Sparse>;
}

pub trait SparseTensorApi<const D: usize, B>
where
B: SparseBackend,
{
Expand All @@ -10,7 +17,16 @@ where
fn dense(self) -> Tensor<B, D>;
}

impl<const D: usize, B> SparseTensor<D, B> for Tensor<B, D, Sparse>
impl<const D: usize, B> ToSparse<D, B> for Tensor<B, D>
where
B: SparseBackend,
{
fn into_sparse(self) -> Tensor<B, D, Sparse> {
Tensor::new(B::sparse_to_sparse(self.into_primitive().tensor()))
}
}

impl<const D: usize, B> SparseTensorApi<D, B> for Tensor<B, D, Sparse>
where
B: SparseBackend,
{
Expand Down
1 change: 1 addition & 0 deletions crates/burn-sparse/src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ mod kind;
mod sparse_backend;

pub use alias::*;
pub use api::*;
pub use kind::*;
pub use sparse_backend::*;

0 comments on commit 790ed5f

Please sign in to comment.