r"""A sparse tensor class. Can be accessed via :attr:`MinkowskiEngine.SparseTensor`. The :attr:`SparseTensor` class is the basic tensor in MinkowskiEngine. For the definition of a sparse tensor, please visit `the terminology page <https://nvidia.github.io/MinkowskiEngine/terminology
| 46 | |
| 47 | |
| 48 | class SparseTensor(Tensor): |
| 49 | r"""A sparse tensor class. Can be accessed via |
| 50 | :attr:`MinkowskiEngine.SparseTensor`. |
| 51 | |
| 52 | The :attr:`SparseTensor` class is the basic tensor in MinkowskiEngine. For |
| 53 | the definition of a sparse tensor, please visit `the terminology page |
| 54 | <https://nvidia.github.io/MinkowskiEngine/terminology.html#sparse-tensor>`_. |
| 55 | We use the COOrdinate (COO) format to save a sparse tensor `[1] |
| 56 | <http://groups.csail.mit.edu/commit/papers/2016/parker-thesis.pdf>`_. This |
| 57 | representation is simply a concatenation of coordinates in a matrix |
| 58 | :math:`C` and associated features :math:`F`. |
| 59 | |
| 60 | .. math:: |
| 61 | |
| 62 | \mathbf{C} = \begin{bmatrix} |
| 63 | b_1 & x_1^1 & x_1^2 & \cdots & x_1^D \\ |
| 64 | \vdots & \vdots & \vdots & \ddots & \vdots \\ |
| 65 | b_N & x_N^1 & x_N^2 & \cdots & x_N^D |
| 66 | \end{bmatrix}, \; \mathbf{F} = \begin{bmatrix} |
| 67 | \mathbf{f}_1^T\\ |
| 68 | \vdots\\ |
| 69 | \mathbf{f}_N^T |
| 70 | \end{bmatrix} |
| 71 | |
| 72 | where :math:`\mathbf{x}_i \in \mathcal{Z}^D` is a :math:`D`-dimensional |
| 73 | coordinate and :math:`b_i \in \mathcal{Z}_+` denotes the corresponding |
| 74 | batch index. :math:`N` is the number of non-zero elements in the sparse |
| 75 | tensor, each with the coordinate :math:`(b_i, x_i^1, x_i^1, \cdots, |
| 76 | x_i^D)`, and the associated feature :math:`\mathbf{f}_i`. Internally, we |
| 77 | handle the batch index as an additional spatial dimension. |
| 78 | |
| 79 | Example:: |
| 80 | |
| 81 | >>> coords, feats = ME.utils.sparse_collate([coords_batch0, coords_batch1], [feats_batch0, feats_batch1]) |
| 82 | >>> A = ME.SparseTensor(features=feats, coordinates=coords) |
| 83 | >>> B = ME.SparseTensor(features=feats, coordinate_map_key=A.coordiante_map_key, coordinate_manager=A.coordinate_manager) |
| 84 | >>> C = ME.SparseTensor(features=feats, coordinates=coords, quantization_mode=ME.SparseTensorQuantizationMode.UNWEIGHTED_AVERAGE) |
| 85 | >>> D = ME.SparseTensor(features=feats, coordinates=coords, quantization_mode=ME.SparseTensorQuantizationMode.RANDOM_SUBSAMPLE) |
| 86 | >>> E = ME.SparseTensor(features=feats, coordinates=coords, tensor_stride=2) |
| 87 | |
| 88 | .. warning:: |
| 89 | |
| 90 | To use the GPU-backend for coordinate management, the |
| 91 | :attr:`coordinates` must be a torch tensor on GPU. Applying `to(device)` |
| 92 | after :attr:`MinkowskiEngine.SparseTensor` initialization with a CPU |
| 93 | `coordinates` will waste time and computation on creating an unnecessary |
| 94 | CPU CoordinateMap since the GPU CoordinateMap will be created from |
| 95 | scratch as well. |
| 96 | |
| 97 | .. warning:: |
| 98 | |
| 99 | Before MinkowskiEngine version 0.4, we put the batch indices on the last |
| 100 | column. Thus, direct manipulation of coordinates will be incompatible |
| 101 | with the latest versions. Instead, please use |
| 102 | :attr:`MinkowskiEngine.utils.batched_coordinates` or |
| 103 | :attr:`MinkowskiEngine.utils.sparse_collate` to create batched |
| 104 | coordinates. |
| 105 |
no outgoing calls