to_scipy#
- iskra.sparse.to_scipy(x: SparseTensor | Tensor) coo_array | csr_array[SOURCE]#
Converts PyTorch sprase COO/CSR tensors into SciPy sparse arrays.
If the input is on the CPU and does not require gradients, we will return a view into the data. If the data is on the GPU or requires gradients, the tensor will be cloned and a view into that tensor will be returned.
Since SciPy does not perform type erasure when it comes to sparse layouts, this function can only return the type
scipy.sparse.coo_array | scipy.sparse.csr_array, which might make your type checker complain if you call any functions specific to either layout. If this happens, you can always follow this function up with, e.g.,assert isinstance(y, scipy.sparse.csr_array)to silence the type checker.- Parameters:
x (
SparseTensor|Tensor) – COO or CSR tensor to be converted.- Raises:
ValueError – Throws an exception if the input tensor is neither COO nor CSR.
- Returns:
(scipy.sparse.coo_array | scipy.sparse.csr_array) – SciPy array with the same data.