MCPcopy Create free account
hub / github.com/NVIDIA/MinkowskiEngine / sparse

Method sparse

MinkowskiEngine/MinkowskiSparseTensor.py:344–455  ·  view source on GitHub ↗

r"""Convert the :attr:`MinkowskiEngine.SparseTensor` to a torch sparse tensor. Args: :attr:`min_coords` (torch.IntTensor, optional): The min coordinates of the output sparse tensor. Must be divisible by the current :attr:`tensor_stride`.

(self, min_coords=None, max_coords=None, contract_coords=True)

Source from the content-addressed store, hash-verified

342
343 # Conversion functions
344 def sparse(self, min_coords=None, max_coords=None, contract_coords=True):
345 r"""Convert the :attr:`MinkowskiEngine.SparseTensor` to a torch sparse
346 tensor.
347
348 Args:
349 :attr:`min_coords` (torch.IntTensor, optional): The min
350 coordinates of the output sparse tensor. Must be divisible by the
351 current :attr:`tensor_stride`.
352
353 :attr:`max_coords` (torch.IntTensor, optional): The max coordinates
354 of the output sparse tensor (inclusive). Must be divisible by the
355 current :attr:`tensor_stride`.
356
357 :attr:`contract_coords` (bool, optional): Given True, the output
358 coordinates will be divided by the tensor stride to make features
359 contiguous.
360
361 Returns:
362 :attr:`spare_tensor` (torch.sparse.Tensor): the torch sparse tensor
363 representation of the self in `[Batch Dim, Spatial Dims..., Feature
364 Dim]`. The coordinate of each feature can be accessed via
365 `min_coord + tensor_stride * [the coordinate of the dense tensor]`.
366
367 :attr:`min_coords` (torch.IntTensor): the D-dimensional vector
368 defining the minimum coordinate of the output sparse tensor. If
369 :attr:`contract_coords` is True, the :attr:`min_coords` will also
370 be contracted.
371
372 :attr:`tensor_stride` (torch.IntTensor): the D-dimensional vector
373 defining the stride between tensor elements.
374
375 """
376
377 if min_coords is not None:
378 assert isinstance(min_coords, torch.IntTensor)
379 assert min_coords.numel() == self._D
380 if max_coords is not None:
381 assert isinstance(max_coords, torch.IntTensor)
382 assert min_coords.numel() == self._D
383
384 def torch_sparse_Tensor(coords, feats, size=None):
385 if size is None:
386 if feats.dtype == torch.float64:
387 return torch.sparse.DoubleTensor(coords, feats)
388 elif feats.dtype == torch.float32:
389 return torch.sparse.FloatTensor(coords, feats)
390 else:
391 raise ValueError("Feature type not supported.")
392 else:
393 if feats.dtype == torch.float64:
394 return torch.sparse.DoubleTensor(coords, feats, size)
395 elif feats.dtype == torch.float32:
396 return torch.sparse.FloatTensor(coords, feats, size)
397 else:
398 raise ValueError("Feature type not supported.")
399
400 # Use int tensor for all operations
401 tensor_stride = torch.IntTensor(self.tensor_stride)

Callers

nothing calls this directly

Calls 3

get_batch_indicesMethod · 0.80
minMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected