Skip to content

Commit

Permalink
clear global coords man
Browse files Browse the repository at this point in the history
  • Loading branch information
chrischoy committed Jan 6, 2020
1 parent 2f98396 commit f05500c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
10 changes: 10 additions & 0 deletions MinkowskiEngine/SparseTensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ def sparse_tensor_operation_mode():
return copy.deepcopy(_sparse_tensor_operation_mode)


def clear_global_coords_man():
r"""
When using the operation mode:
`SparseTensorOperationMode.SHARE_COORDS_MANAGER`, you must explicitly clear
the coordinate manager when done using it.
"""
global _global_coords_man
_global_coords_man = None


class SparseTensor():
r"""A sparse tensor class. Can be accessed via
:attr:`MinkowskiEngine.SparseTensor`.
Expand Down
2 changes: 1 addition & 1 deletion MinkowskiEngine/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import torch

from SparseTensor import SparseTensor, SparseTensorOperationMode, \
set_sparse_tensor_operation_mode, sparse_tensor_operation_mode
set_sparse_tensor_operation_mode, sparse_tensor_operation_mode, clear_global_coords_man

from Common import RegionType, convert_to_int_tensor, convert_region_type, \
MinkowskiModuleBase, KernelGenerator, GlobalPoolingMode
Expand Down
20 changes: 12 additions & 8 deletions examples/sparse_tensor_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,19 @@ def operation_mode():
new_coords = torch.IntTensor([[0, 1], [2, 3], [4, 5]])
new_feats = torch.rand(len(new_coords), feats.size(1))

# sparse tensors
A = ME.SparseTensor(coords=coords, feats=feats)
B = ME.SparseTensor(
coords=new_coords,
feats=new_feats,
#coords_manager=A.coords_man, No need to feed the coords_man
force_creation=True)
for _ in range(2):
# sparse tensors
A = ME.SparseTensor(coords=coords, feats=feats)
B = ME.SparseTensor(
coords=new_coords,
feats=new_feats,
# coords_manager=A.coords_man, No need to feed the coords_man
force_creation=True)

C = A + B
C = A + B

# When done using it for forward and backward, you must cleanup the coords man
ME.clear_global_coords_man()


if __name__ == '__main__':
Expand Down

0 comments on commit f05500c

Please sign in to comment.