Skip to content

Commit fc5a0ba

Browse files
committed
Merge branch 'fast-mask'
* fast-mask: MAINT: Make setting mask values with scalars faster.
2 parents aeb13af + 0cc113c commit fc5a0ba

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

numpy/ma/core.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3129,6 +3129,11 @@ def __setmask__(self, mask, copy=False):
31293129
if self._hardmask:
31303130
current_mask |= mask
31313131
# Softmask: set everything to False
3132+
# If it's obviously a compatible scalar, use a quick update
3133+
# method...
3134+
elif isinstance(mask, (int, float, np.bool_, np.number)):
3135+
current_mask[...] = mask
3136+
# ...otherwise fall back to the slower, general purpose way.
31323137
else:
31333138
current_mask.flat = mask
31343139
# Named fields w/ ............
@@ -3158,6 +3163,11 @@ def __setmask__(self, mask, copy=False):
31583163
for n in idtype.names:
31593164
current_mask[n] |= mask[n]
31603165
# Softmask: set everything to False
3166+
# If it's obviously a compatible scalar, use a quick update
3167+
# method...
3168+
elif isinstance(mask, (int, float, np.bool_, np.number)):
3169+
current_mask[...] = mask
3170+
# ...otherwise fall back to the slower, general purpose way.
31613171
else:
31623172
current_mask.flat = mask
31633173
# Reshape if needed

0 commit comments

Comments
 (0)