src.utils.sparse

Functions

bilinear_diag_torch

Bilinear and diagonal in sequence, for diagonal(sparse x dense x sparse) -> dense vector.

dense_to_sparse

Convert a dense tensor to a sparse one.

get_batches

Get batches from a 3d sparse tensor.

recover_ssp

Recover scipy.sparse coo_matrix from a dictionary containing row, col and data tensors. :param t_dict: containing keys ‘row’, ‘col’, ‘data’, each corresponds to a bxn tensor ‘shape’, containing the MxN shape of each tensor :return: list of scipy.sparse matrix. list indices represent batches.

sbmm

Perform bmm (Batch Matrix Matrix) for sparse x dense -> dense.

sbmm_diag

Perform bmm and diagonal for sparse x dense -> dense.

sdd_bmm_diag_torch

Perform bmm and diagonal for sparse x dense -> dense.

sdd_bmm_torch

bmm (Batch Matrix Matrix) for sparse x dense -> dense.

sds_bmm_torch

bmm (Batch Matrix Matrix) for sparse x dense -> sparse.

sdsbmm

Perform bmm for sparse x dense -> sparse.

slicing_torch

A slicing function for torch sparse tensors. :param s_t: input sparse tensor :param slice: tensor containing indices, -1 stands for all. For example, (1, -1) returns the second row of a 2d tensor. :param preserve_dim: If True, the dimension of the original tensor will be preserved, i.e. 1 will be padded for those removed dimensions. :return: sliced sparse tensor.

ssp2torch

Convert scipy.sparse matrix to torch sparse matrix. Since scipy.sparse has a dimension limit of 2, list of matrices is supported for batches. :param M: input scipy.sparse matrix :param batch: the type that represent batches in the output. If batch=’list’, tensors are 2d and stored in list. If batch=’dim’, tensors are 3d ane the first dimension represents batch size. :param dtype: output data type :param device: device :return: output torch sparse matrix.

sss_bmm_diag_spp

bmm (Batch Matrix Matrix) for sparse x sparse -> sparse.

sssbmm_diag

Perform bmm and diagonal for sparse x sparse -> sparse.

to_sparse

converts dense tensor x to sparse format

torch2ssp

Convert torch sparse matrix to scipy.sparse matrix.

Classes

SparseDenseDenseBMM

bmm (Batch Matrix Matrix) for sparse x dense -> dense.