diff options
author | David Cournapeau <cournape@gmail.com> | 2009-03-02 14:26:50 +0000 |
---|---|---|
committer | David Cournapeau <cournape@gmail.com> | 2009-03-02 14:26:50 +0000 |
commit | 9505ef3f9bbdc13d6c4e76c66dbc273650f80297 (patch) | |
tree | 0e89d6309cd2520d0f692ca0ba08b94629834ddd | |
parent | 1cf5461fb0867179846c5f89bc5e91aba57fb242 (diff) | |
download | numpy-9505ef3f9bbdc13d6c4e76c66dbc273650f80297.tar.gz |
BUG: fix #786, bad exception for wrong order for linalg.norm.
-rw-r--r-- | numpy/linalg/linalg.py | 4 | ||||
-rw-r--r-- | numpy/linalg/tests/test_linalg.py | 6 | ||||
-rw-r--r-- | numpy/linalg/tests/test_regression.py | 5 |
3 files changed, 9 insertions, 6 deletions
diff --git a/numpy/linalg/linalg.py b/numpy/linalg/linalg.py index 583ab2f71..1570407ff 100644 --- a/numpy/linalg/linalg.py +++ b/numpy/linalg/linalg.py @@ -1378,6 +1378,10 @@ def norm(x, ord=None): elif ord == 2: return sqrt(((x.conj()*x).real).sum()) # special case for speedup else: + try: + ord + 1 + except TypeError: + raise ValueError, "Invalid norm order for vectors." return ((abs(x)**ord).sum())**(1.0/ord) elif nd == 2: if ord == 2: diff --git a/numpy/linalg/tests/test_linalg.py b/numpy/linalg/tests/test_linalg.py index 1a5edc5bc..3330db2a3 100644 --- a/numpy/linalg/tests/test_linalg.py +++ b/numpy/linalg/tests/test_linalg.py @@ -290,12 +290,6 @@ class _TestNorm(TestCase): array(c, dtype=self.dt)): _test(v) - @np.testing.dec.knownfailureif(True, "#786: FIXME") - def test_vector_badarg(self): - """Regression for #786: Froebenius norm for vectors raises - TypeError.""" - self.assertRaises(ValueError, norm, array([1., 2., 3.]), 'fro') - def test_matrix(self): A = matrix([[1.,3.],[5.,7.]], dtype=self.dt) A = matrix([[1.,3.],[5.,7.]], dtype=self.dt) diff --git a/numpy/linalg/tests/test_regression.py b/numpy/linalg/tests/test_regression.py index ab101b7d0..ab31d9960 100644 --- a/numpy/linalg/tests/test_regression.py +++ b/numpy/linalg/tests/test_regression.py @@ -52,6 +52,11 @@ class TestRegression(TestCase): assert_array_almost_equal(b, np.zeros((2, 2))) + def test_norm_vector_badarg(self): + """Regression for #786: Froebenius norm for vectors raises + TypeError.""" + self.assertRaises(ValueError, linalg.norm, array([1., 2., 3.]), 'fro') + if __name__ == '__main__': run_module_suite() |