From 1dcf0c96df5e2f7b861c6054ead2ad7ebc77aa79 Mon Sep 17 00:00:00 2001 From: Ralf Gommers Date: Tue, 29 Mar 2011 20:02:13 +0200 Subject: BUG: handle empty inputs in cov and corrcoef. Closes #1773. --- numpy/lib/tests/test_function_base.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'numpy/lib/tests/test_function_base.py') 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): -- cgit v1.2.1