summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2013-08-17 12:40:51 -0600
committerCharles Harris <charlesr.harris@gmail.com>2013-08-17 12:40:51 -0600
commitfc5a0ba32e0df4ddcee1f253be4f77a494db0af2 (patch)
tree757c505a424905d379a92bc7077356664efd6f8b /numpy
parentaeb13affe23abaa9550521531b61f03850551106 (diff)
parent0cc113c7574e40172fe4a48e9c0d90477d736ce3 (diff)
downloadnumpy-fc5a0ba32e0df4ddcee1f253be4f77a494db0af2.tar.gz
Merge branch 'fast-mask'
* fast-mask: MAINT: Make setting mask values with scalars faster.
Diffstat (limited to 'numpy')
-rw-r--r--numpy/ma/core.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/numpy/ma/core.py b/numpy/ma/core.py
index ccf62bdcf..8f2dbedeb 100644
--- a/numpy/ma/core.py
+++ b/numpy/ma/core.py
@@ -3129,6 +3129,11 @@ class MaskedArray(ndarray):
if self._hardmask:
current_mask |= mask
# Softmask: set everything to False
+ # If it's obviously a compatible scalar, use a quick update
+ # method...
+ elif isinstance(mask, (int, float, np.bool_, np.number)):
+ current_mask[...] = mask
+ # ...otherwise fall back to the slower, general purpose way.
else:
current_mask.flat = mask
# Named fields w/ ............
@@ -3158,6 +3163,11 @@ class MaskedArray(ndarray):
for n in idtype.names:
current_mask[n] |= mask[n]
# Softmask: set everything to False
+ # If it's obviously a compatible scalar, use a quick update
+ # method...
+ elif isinstance(mask, (int, float, np.bool_, np.number)):
+ current_mask[...] = mask
+ # ...otherwise fall back to the slower, general purpose way.
else:
current_mask.flat = mask
# Reshape if needed