torch_geometric.transforms.ToSparseTensor
- class ToSparseTensor(attr: Optional[str] = 'edge_weight', remove_edge_index: bool = True, fill_cache: bool = True, layout: Optional[int] = None)[source]
Bases:
BaseTransformConverts the
edge_indexattributes of a homogeneous or heterogeneous data object into a transposedtorch_sparse.SparseTensoror PyTorchtorch.sparse.Tensorobject with keyadj_t(functional name:to_sparse_tensor).Note
In case of composing multiple transforms, it is best to convert the
dataobject viaToSparseTensoras late as possible, since there exist some transforms that are only able to operate ondata.edge_indexfor now.- Parameters
attr (str, optional) – The name of the attribute to add as a value to the
SparseTensorortorch.sparse.Tensorobject (if present). (default:edge_weight)remove_edge_index (bool, optional) – If set to
False, theedge_indextensor will not be removed. (default:True)fill_cache (bool, optional) – If set to
True, will fill the underlyingtorch_sparse.SparseTensorcache (if used). (default:True)layout (torch.layout, optional) – Specifies the layout of the returned sparse tensor (
None,torch.sparse_cooortorch.sparse_csr). If set toNoneand thetorch_sparsedependency is installed, will convertedge_indexinto atorch_sparse.SparseTensorobject. If set toNoneand thetorch_sparsedependency is not installed, will convertedge_indexinto atorch.sparse.Tensorobject with layouttorch.sparse_csr. (default:None)