Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

TST: fix linalg.norm test failure. Thanks to Rudiger Kessel.

The intended output was obviously 0.5 (where numpy.linalg.norm gives 0.0); this
seems to be the case on most but not all systems.  The reason is that snrm
seems to internally use double precision for most BLAS versions, but not all.

Note that test_overflow() for this implementation of norm() passes on all
systems, so even where test_stable() fails the performance of norm() looks
better than for numpy.linalg.norm().
  • Loading branch information...
commit e2fd3dab37173e228db24b6ec4fd57ab6a712823 1 parent 6cc4699
@rgommers rgommers authored
Showing with 8 additions and 1 deletion.
  1. +8 −1 scipy/linalg/tests/test_basic.py
View
9 scipy/linalg/tests/test_basic.py
@@ -582,7 +582,14 @@ def test_overflow(self):
def test_stable(self):
# more stable than numpy's norm
a = array([1e4] + [1]*10000, dtype=float32)
- assert_almost_equal(norm(a) - 1e4, 0.5)
+ try:
+ # snrm in double precision; we obtain the same as for float64
+ assert_almost_equal(norm(a) - 1e4, 0.5)
+ except AssertionError:
+ # snrm implemented in single precision, == np.linalg.norm result
+ msg = ": Result should equal either 0.0 or 0.5 (depending on " \
+ "implementation of snrm2)."
+ assert_almost_equal(norm(a) - 1e4, 0.0, err_msg=msg)
def test_zero_norm(self):
assert_equal(norm([1,0,3], 0), 2)
Please sign in to comment.
Something went wrong with that request. Please try again.