torch.sparse_coo_tensor
- torch.sparse_coo_tensor(indices, values, size=None, *, dtype=None, device=None, pin_memory=False, , ,
Constructs a sparse tensor in COO(rdinate) format with specified values at the given
indices.
indices (array_like) – Initial data for the tensor. Can be a list, tuple,
NumPy ndarray, scalar, and other types. Will be cast to a torch.LongTensor
internally. The indices are the coordinates of the non-zero values in the matrix, and thus
should be two-dimensional where the first dimension is the number of tensor dimensions and
the second dimension is the number of non-zero values.
values (array_like) – Initial values for the tensor. Can be a list, tuple,
NumPy ndarray, scalar, and other types.
size (list, tuple, or torch.Size, optional) – Size of the sparse tensor. If not
provided the size will be inferred as the minimum size big enough to hold all non-zero
elements.
Example:
>>> i = torch.tensor([[0, 1, 1],
... [2, 0, 2]])
>>> v = torch.tensor([3, 4, 5], dtype=
dtype (torch.dtype, optional) – the desired data type of returned tensor.
Default: if None, infers data type from values.
device (torch.device, optional) – the desired device of returned tensor.
Default: if None, uses the current device for the default tensor type
(see torch.set_default_device()). device will be the CPU
for CPU tensor types and the current CUDA device for CUDA tensor types.
pin_memory (bool, optional) – If set, returned tensor would be allocated in
the pinned memory. Works only for CPU tensors. Default: False.
requires_grad (bool, optional) – If autograd should record operations on the
returned tensor. Default: False.
check_invariants (bool, optional) – If sparse tensor invariants are checked.
Default: as returned by torch.sparse.check_sparse_tensor_invariants.is_enabled(),
initially False.
is_coalesced (bool, optional) – When``True``, the caller is
responsible for providing tensor indices that correspond to a
coalesced tensor. If the check_invariants flag is
False, no error will be raised if the prerequisites are not
met and this will lead to silently incorrect results. To force
coalescing please use coalesce() on the resulting
Tensor.
Default: None: except for trivial cases (e.g. nnz < 2) the
resulting Tensor has is_coalesced set to False`.