summaryrefslogtreecommitdiff
path: root/numpy/lib/tests/test_function_base.py
diff options
context:
space:
mode:
authorRalf Gommers <ralf.gommers@googlemail.com>2011-03-29 20:02:13 +0200
committerRalf Gommers <ralf.gommers@googlemail.com>2011-04-02 12:03:41 +0200
commit1dcf0c96df5e2f7b861c6054ead2ad7ebc77aa79 (patch)
tree3867e9a942752a1047c49ffe6111663f87f9ebc5 /numpy/lib/tests/test_function_base.py
parent89db53b1f437d846829a3c387ea61001b3b66383 (diff)
downloadnumpy-1dcf0c96df5e2f7b861c6054ead2ad7ebc77aa79.tar.gz
BUG: handle empty inputs in cov and corrcoef. Closes #1773.
Diffstat (limited to 'numpy/lib/tests/test_function_base.py')
-rw-r--r--numpy/lib/tests/test_function_base.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py
index 353bf23e9..e65c84158 100644
--- a/numpy/lib/tests/test_function_base.py
+++ b/numpy/lib/tests/test_function_base.py
@@ -944,6 +944,20 @@ class TestCorrCoef(TestCase):
assert_almost_equal(corrcoef(self.A, ddof=-1), self.res1)
assert_almost_equal(corrcoef(self.A, self.B, ddof=-1), self.res2)
+ def test_empty(self):
+ assert_equal(corrcoef(np.array([])).size, 0)
+ assert_equal(corrcoef(np.array([]).reshape(0, 2)).shape, (0, 2))
+
+
+class TestCov(TestCase):
+ def test_basic(self):
+ x = np.array([[0, 2], [1, 1], [2, 0]]).T
+ assert_allclose(np.cov(x), np.array([[ 1.,-1.], [-1.,1.]]))
+
+ def test_empty(self):
+ assert_equal(cov(np.array([])).size, 0)
+ assert_equal(cov(np.array([]).reshape(0, 2)).shape, (0, 2))
+
class Test_i0(TestCase):
def test_simple(self):