diff --git a/tfields/core.py b/tfields/core.py index d2f5921979860f7607c099c4146e31a00872e4f0..3f42c52781a9c939bf364f12d17fe51c802bef30 100644 --- a/tfields/core.py +++ b/tfields/core.py @@ -2757,20 +2757,21 @@ class TensorMaps(TensorFields): inst = self.copy() remove_mask = np.full(inst.shape[0], False, dtype=bool) duplicates = tfields.lib.util.duplicates(inst, axis=0) - for tensor_index, duplicate_index in zip(range(inst.shape[0]), duplicates): - if duplicate_index != tensor_index: - # mark duplicate at tensor_index for removal - remove_mask[tensor_index] = True - # redirect maps. Note: work on inst.maps instead of - # self.maps in case stale vertices where removed - for map_dim in inst.maps: - for face_index in range(len(inst.maps[map_dim])): # face index - map_ = np.array(inst.maps[map_dim], dtype=int) - if tensor_index in map_[face_index]: - index = tfields.lib.util.index( - map_[face_index], tensor_index - ) - inst.maps[map_dim][face_index][index] = duplicate_index + tensor_indices = np.arange(inst.shape[0]) + duplicates_mask = duplicates != tensor_indices + if duplicates_mask.any(): + # redirect maps. Note: work on inst.maps instead of + # self.maps in case stale vertices where removed + keys = tensor_indices[duplicates_mask] + values = duplicates[duplicates_mask] + for map_dim in inst.maps: + tfields.lib.sets.remap( + inst.maps[map_dim], keys, values, inplace=True + ) + + # mark duplicates for removal + remove_mask[keys] = True + if remove_mask.any(): # prevent another copy inst = inst.removed(remove_mask)