[Numpy-svn] r6526 - in trunk/numpy/linalg: . tests

numpy-svn@scip... numpy-svn@scip...
Mon Mar 2 08:26:56 CST 2009


Author: cdavid
Date: 2009-03-02 08:26:50 -0600 (Mon, 02 Mar 2009)
New Revision: 6526

Modified:
   trunk/numpy/linalg/linalg.py
   trunk/numpy/linalg/tests/test_linalg.py
   trunk/numpy/linalg/tests/test_regression.py
Log:
BUG: fix #786, bad exception for wrong order for linalg.norm.

Modified: trunk/numpy/linalg/linalg.py
===================================================================
--- trunk/numpy/linalg/linalg.py	2009-03-02 14:18:29 UTC (rev 6525)
+++ trunk/numpy/linalg/linalg.py	2009-03-02 14:26:50 UTC (rev 6526)
@@ -1378,6 +1378,10 @@
         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:

Modified: trunk/numpy/linalg/tests/test_linalg.py
===================================================================
--- trunk/numpy/linalg/tests/test_linalg.py	2009-03-02 14:18:29 UTC (rev 6525)
+++ trunk/numpy/linalg/tests/test_linalg.py	2009-03-02 14:26:50 UTC (rev 6526)
@@ -290,12 +290,6 @@
                   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)

Modified: trunk/numpy/linalg/tests/test_regression.py
===================================================================
--- trunk/numpy/linalg/tests/test_regression.py	2009-03-02 14:18:29 UTC (rev 6525)
+++ trunk/numpy/linalg/tests/test_regression.py	2009-03-02 14:26:50 UTC (rev 6526)
@@ -52,6 +52,11 @@
 
         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()



More information about the Numpy-svn mailing list