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

Method sparse

MinkowskiEngine/MinkowskiTensorField.py:286–379  ·  view source on GitHub ↗

r"""Converts the current sparse tensor field to a sparse tensor.

(
        self,
        tensor_stride: Union[int, Sequence, np.array] = 1,
        coordinate_map_key: CoordinateMapKey = None,
        quantization_mode: SparseTensorQuantizationMode = None,
    )

Source from the content-addressed store, hash-verified

284 return self._manager.get_coordinate_field(self.coordinate_field_map_key)
285
286 def sparse(
287 self,
288 tensor_stride: Union[int, Sequence, np.array] = 1,
289 coordinate_map_key: CoordinateMapKey = None,
290 quantization_mode: SparseTensorQuantizationMode = None,
291 ):
292 r"""Converts the current sparse tensor field to a sparse tensor."""
293 if quantization_mode is None:
294 quantization_mode = self.quantization_mode
295 assert (
296 quantization_mode != SparseTensorQuantizationMode.SPLAT_LINEAR_INTERPOLATION
297 ), "Please use .splat() for splat quantization."
298
299 if coordinate_map_key is None:
300 tensor_stride = convert_to_int_list(tensor_stride, self.D)
301
302 coordinate_map_key, (
303 unique_index,
304 inverse_mapping,
305 ) = self._manager.field_to_sparse_insert_and_map(
306 self.coordinate_field_map_key,
307 tensor_stride,
308 )
309 N_rows = len(unique_index)
310 else:
311 # sparse index, field index
312 inverse_mapping, unique_index = self._manager.field_to_sparse_map(
313 self.coordinate_field_map_key,
314 coordinate_map_key,
315 )
316 N_rows = self._manager.size(coordinate_map_key)
317
318 assert N_rows > 0, f"Invalid out coordinate map key. Found {N_row} elements."
319
320 if len(inverse_mapping) == 0:
321 # When the input has the same shape as the output
322 self._inverse_mapping[coordinate_map_key] = torch.arange(
323 len(self._F),
324 dtype=inverse_mapping.dtype,
325 device=inverse_mapping.device,
326 )
327 return SparseTensor(
328 self._F,
329 coordinate_map_key=coordinate_map_key,
330 coordinate_manager=self._manager,
331 )
332
333 # Create features
334 if quantization_mode == SparseTensorQuantizationMode.UNWEIGHTED_SUM:
335 N = len(self._F)
336 cols = torch.arange(
337 N,
338 dtype=inverse_mapping.dtype,
339 device=inverse_mapping.device,
340 )
341 vals = torch.ones(N, dtype=self._F.dtype, device=self._F.device)
342 size = torch.Size([N_rows, len(inverse_mapping)])
343 features = MinkowskiSPMMFunction().apply(

Callers 8

testMethod · 0.95
test_maxpoolMethod · 0.95
test_pcdMethod · 0.95
field_to_sparseMethod · 0.95
forwardMethod · 0.45
forwardMethod · 0.45
forwardMethod · 0.45
indoor.pyFile · 0.45

Calls 8

convert_to_int_listFunction · 0.90
SparseTensorClass · 0.90
field_to_sparse_mapMethod · 0.80
sizeMethod · 0.45

Tested by 2

test_maxpoolMethod · 0.76
test_pcdMethod · 0.76