diff options
author | rgommers <ralf.gommers@googlemail.com> | 2010-07-31 04:41:08 +0000 |
---|---|---|
committer | rgommers <ralf.gommers@googlemail.com> | 2010-07-31 04:41:08 +0000 |
commit | d1a661df48625ce5544d83dc022c96cf8c5d41c7 (patch) | |
tree | 40d139668649832673e3f1803971183e937e7633 /numpy/lib/tests/test_function_base.py | |
parent | bff8bb580d6e915b9bdadea312482a169f7d1472 (diff) | |
download | numpy-d1a661df48625ce5544d83dc022c96cf8c5d41c7.tar.gz |
ENH: Make trapz work with ndarray subclasses. Thanks to Ryan May. Closes #1438.
Diffstat (limited to 'numpy/lib/tests/test_function_base.py')
-rw-r--r-- | numpy/lib/tests/test_function_base.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py index 037e8043a..1d0d61be3 100644 --- a/numpy/lib/tests/test_function_base.py +++ b/numpy/lib/tests/test_function_base.py @@ -491,6 +491,32 @@ class TestTrapz(TestCase): r = trapz(q, x=z, axis=2) assert_almost_equal(r, qz) + def test_masked(self): + #Testing that masked arrays behave as if the function is 0 where + #masked + x = arange(5) + y = x * x + mask = x == 2 + ym = np.ma.array(y, mask=mask) + r = 13.0 # sum(0.5 * (0 + 1) * 1.0 + 0.5 * (9 + 16)) + assert_almost_equal(trapz(ym, x), r) + + xm = np.ma.array(x, mask=mask) + assert_almost_equal(trapz(ym, xm), r) + + xm = np.ma.array(x, mask=mask) + assert_almost_equal(trapz(y, xm), r) + + def test_matrix(self): + #Test to make sure matrices give the same answer as ndarrays + x = linspace(0, 5) + y = x * x + r = trapz(y, x) + mx = matrix(x) + my = matrix(y) + mr = trapz(my, mx) + assert_almost_equal(mr, r) + class TestSinc(TestCase): def test_simple(self): |