torch_geometric.transforms.ToSparseTensor
- class ToSparseTensor(attr: Optional[str] = 'edge_weight', remove_edge_index: bool = True, fill_cache: bool = True)[source]
Bases:
BaseTransform
Converts the
edge_index
attributes of a homogeneous or heterogeneous data object into a (transposed)torch_sparse.SparseTensor
object with keyadj_t
(functional name:to_sparse_tensor
).Note
In case of composing multiple transforms, it is best to convert the
data
object to aSparseTensor
as late as possible, since there exist some transforms that are only able to operate ondata.edge_index
for now.- Parameters
attr (str, optional) – The name of the attribute to add as a value to the
SparseTensor
object (if present). (default:edge_weight
)remove_edge_index (bool, optional) – If set to
False
, theedge_index
tensor will not be removed. (default:True
)fill_cache (bool, optional) – If set to
False
, will not fill the underlyingSparseTensor
cache. (default:True
)