46
46
47
47
def assert_equal (x , y ):
48
48
if x .dtype in dh .float_dtypes :
49
- assert_allclose (x , y )
49
+ # It's too difficult to do an approximately equal test here because
50
+ # different routines can give completely different answers, and even
51
+ # when it does work, the elementwise comparisons are too slow. So for
52
+ # floating-point dtypes only test the shape and dtypes.
53
+
54
+ # assert_allclose(x, y)
55
+
56
+ assert x .shape == y .shape , f"The input arrays do not have the same shapes ({ x .shape } != { y .shape } )"
57
+ assert x .dtype == y .dtype , f"The input arrays do not have the same dtype ({ x .dtype } != { y .dtype } )"
50
58
else :
51
59
assert_exactly_equal (x , y )
52
60
@@ -250,18 +258,17 @@ def test_eigh(x):
250
258
assert eigenvectors .dtype == x .dtype , "eigh().eigenvectors did not return the correct dtype"
251
259
assert eigenvectors .shape == x .shape , "eigh().eigenvectors did not return the correct shape"
252
260
253
- # The order of the eigenvalues is not specified, so make sure the same
254
- # eigenvalues are compared against each other.
261
+ # Note: _test_stacks here is only testing the shape and dtype. The actual
262
+ # eigenvalues and eigenvectors may not be equal at all, since there is not
263
+ # requirements about how eigh computes an eigenbasis, or about the order
264
+ # of the eigenvalues
255
265
_test_stacks (lambda x : linalg .eigh (x ).eigenvalues , x ,
256
- res = eigenvalues , dims = 1 , assert_equal = lambda a , b :
257
- assert_equal (xp .sort (a ), xp .sort (b )))
266
+ res = eigenvalues , dims = 1 )
258
267
259
- # There are equivalent ways of representing eigenvectors, and algorithms
260
- # may not give the same eigenvectors on a stack vs. a matrix.
261
268
# TODO: Test that eigenvectors are orthonormal.
262
269
263
- # _test_stacks(lambda x: linalg.eigh(x).eigenvectors, x,
264
- # res=eigenvectors, dims=2)
270
+ _test_stacks (lambda x : linalg .eigh (x ).eigenvectors , x ,
271
+ res = eigenvectors , dims = 2 )
265
272
266
273
# TODO: Test that res actually corresponds to the eigenvalues and
267
274
# eigenvectors of x
@@ -274,12 +281,14 @@ def test_eigvalsh(x):
274
281
assert res .dtype == x .dtype , "eigvalsh() did not return the correct dtype"
275
282
assert res .shape == x .shape [:- 1 ], "eigvalsh() did not return the correct shape"
276
283
277
- # The order of the eigenvalues is not specified, so make sure the same
278
- # eigenvalues are compared against each other.
279
- _test_stacks (linalg .eigvalsh , x , res = res , dims = 1 , assert_equal = lambda a ,
280
- b : assert_equal (xp .sort (a ), xp .sort (b )))
284
+ # Note: _test_stacks here is only testing the shape and dtype. The actual
285
+ # eigenvalues may not be equal at all, since there is not requirements or
286
+ # about the order of the eigenvalues, and the stacking code may use a
287
+ # different code path.
288
+ _test_stacks (linalg .eigvalsh , x , res = res , dims = 1 )
281
289
282
290
# TODO: Should we test that the result is the same as eigh(x).eigenvalues?
291
+ # (probably no because the spec doesn't actually require that)
283
292
284
293
# TODO: Test that res actually corresponds to the eigenvalues of x
285
294
0 commit comments