summaryrefslogtreecommitdiff
path: root/numpy/ma/tests/test_subclassing.py
diff options
context:
space:
mode:
authorpierregm <pierregm@localhost>2009-05-13 22:24:09 +0000
committerpierregm <pierregm@localhost>2009-05-13 22:24:09 +0000
commit673de279532eaf153ac97449b0c81a5c4b239ef3 (patch)
treea59aff8c7f3c78ca260dd2086f2e208dd1e4dbea /numpy/ma/tests/test_subclassing.py
parentfef030ee54c9b2bf4ad510766038fa288dce6014 (diff)
downloadnumpy-673de279532eaf153ac97449b0c81a5c4b239ef3.tar.gz
* getdata : prevent unnecessary copies (thx to Eric Firing)
* _Domained/MaskedUnary/BinaryOperations: optimization by preventing the use of np.where and the calculation of domain. Here's the catch: we're basically cheating. We force np.seterr(divide='ignore',invalid='ignore') before computing the results, then mask the invalid values (if any) and reset the corresponding entries in .data to the input. Finally, we reset the error status. This playing around with the error status may (or may not) fail in multi-thread. It's still faaar faster than computing the domain (especially _DomainSafeDivide) when the inputs are large...
Diffstat (limited to 'numpy/ma/tests/test_subclassing.py')
-rw-r--r--numpy/ma/tests/test_subclassing.py28
1 files changed, 25 insertions, 3 deletions
diff --git a/numpy/ma/tests/test_subclassing.py b/numpy/ma/tests/test_subclassing.py
index 5943ad6c1..b732cf845 100644
--- a/numpy/ma/tests/test_subclassing.py
+++ b/numpy/ma/tests/test_subclassing.py
@@ -70,6 +70,11 @@ mmatrix = MMatrix
class TestSubclassing(TestCase):
"""Test suite for masked subclasses of ndarray."""
+ def setUp(self):
+ x = np.arange(5)
+ mx = mmatrix(x, mask=[0, 1, 0, 0, 0])
+ self.data = (x, mx)
+
def test_data_subclassing(self):
"Tests whether the subclass is kept."
x = np.arange(5)
@@ -82,19 +87,36 @@ class TestSubclassing(TestCase):
def test_maskedarray_subclassing(self):
"Tests subclassing MaskedArray"
- x = np.arange(5)
- mx = mmatrix(x,mask=[0,1,0,0,0])
+ (x, mx) = self.data
self.failUnless(isinstance(mx._data, np.matrix))
+
+ def test_masked_unary_operations(self):
"Tests masked_unary_operation"
+ (x, mx) = self.data
+ self.failUnless(isinstance(log(mx), mmatrix))
+ assert_equal(log(x), np.log(x))
+
+ def test_masked_binary_operations(self):
+ "Tests masked_binary_operation"
+ (x, mx) = self.data
+ # Result should be a mmatrix
self.failUnless(isinstance(add(mx,mx), mmatrix))
self.failUnless(isinstance(add(mx,x), mmatrix))
+ # Result should work
assert_equal(add(mx,x), mx+x)
self.failUnless(isinstance(add(mx,mx)._data, np.matrix))
self.failUnless(isinstance(add.outer(mx,mx), mmatrix))
- "Tests masked_binary_operation"
self.failUnless(isinstance(hypot(mx,mx), mmatrix))
self.failUnless(isinstance(hypot(mx,x), mmatrix))
+ def test_masked_binary_operations(self):
+ "Tests domained_masked_binary_operation"
+ (x, mx) = self.data
+ xmx = masked_array(mx.data.__array__(), mask=mx.mask)
+ self.failUnless(isinstance(divide(mx,mx), mmatrix))
+ self.failUnless(isinstance(divide(mx,x), mmatrix))
+ assert_equal(divide(mx, mx), divide(xmx, xmx))
+
def test_attributepropagation(self):
x = array(arange(5), mask=[0]+[1]*4)
my = masked_array(subarray(x))