Voice et bot modif
This commit is contained in:
parent
189d56026b
commit
7333a22bcd
10774 changed files with 634644 additions and 933308 deletions
Binary file not shown.
Binary file not shown.
|
|
@ -61,7 +61,6 @@ from numpy._core import (
|
|||
overrides,
|
||||
prod,
|
||||
reciprocal,
|
||||
sign,
|
||||
single,
|
||||
sort,
|
||||
sqrt,
|
||||
|
|
@ -1810,7 +1809,8 @@ def svd(a, full_matrices=True, compute_uv=True, hermitian=False):
|
|||
# and related arrays to have the correct order
|
||||
if compute_uv:
|
||||
s, u = eigh(a)
|
||||
sgn = sign(s)
|
||||
# avoid zero sign
|
||||
sgn = np.copysign(1.0, s)
|
||||
s = abs(s)
|
||||
sidx = argsort(s)[..., ::-1]
|
||||
sgn = np.take_along_axis(sgn, sidx, axis=-1)
|
||||
|
|
@ -2130,6 +2130,7 @@ def matrix_rank(A, tol=None, hermitian=False, *, rtol=None):
|
|||
A = asarray(A)
|
||||
if A.ndim < 2:
|
||||
return int(not all(A == 0))
|
||||
|
||||
S = svd(A, compute_uv=False, hermitian=hermitian)
|
||||
|
||||
if tol is None:
|
||||
|
|
@ -2137,7 +2138,7 @@ def matrix_rank(A, tol=None, hermitian=False, *, rtol=None):
|
|||
rtol = max(A.shape[-2:]) * finfo(S.dtype).eps
|
||||
else:
|
||||
rtol = asarray(rtol)[..., newaxis]
|
||||
tol = S.max(axis=-1, keepdims=True) * rtol
|
||||
tol = S.max(axis=-1, keepdims=True, initial=0) * rtol
|
||||
else:
|
||||
tol = asarray(tol)[..., newaxis]
|
||||
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -745,6 +745,12 @@ class SVDHermitianCases(HermitianTestCase, HermitianGeneralizedTestCase):
|
|||
class TestSVDHermitian(SVDHermitianCases, SVDBaseTests):
|
||||
hermitian = True
|
||||
|
||||
def test_singular(self):
|
||||
x = np.array([[1, 0], [0, 0]])
|
||||
u, _, vh = linalg.svd(x, hermitian=self.hermitian)
|
||||
assert_allclose(u @ u.T.conj(), np.eye(2), rtol=1e-14)
|
||||
assert_allclose(vh @ vh.T.conj(), np.eye(2), rtol=1e-14)
|
||||
|
||||
|
||||
class CondCases(LinalgSquareTestCase, LinalgGeneralizedSquareTestCase):
|
||||
# cond(x, p) for p in (None, 2, -2)
|
||||
|
|
@ -2440,3 +2446,22 @@ def test_vector_norm_empty():
|
|||
assert_equal(np.linalg.vector_norm(x, ord=1), 0)
|
||||
assert_equal(np.linalg.vector_norm(x, ord=2), 0)
|
||||
assert_equal(np.linalg.vector_norm(x, ord=np.inf), 0)
|
||||
|
||||
def test_empty_matrix_rank():
|
||||
assert_equal(matrix_rank(np.zeros((0, 0))), 0)
|
||||
assert_equal(matrix_rank(np.zeros((0, 5))), 0)
|
||||
assert_equal(matrix_rank(np.zeros((5, 0))), 0)
|
||||
|
||||
result = matrix_rank(np.zeros((0, 5, 5)))
|
||||
assert_equal(result.shape, (0,))
|
||||
assert_equal(result.dtype, np.intp)
|
||||
|
||||
result = matrix_rank(np.zeros((3, 0, 5)))
|
||||
assert_equal(result, np.array([0, 0, 0]))
|
||||
|
||||
result = matrix_rank(np.zeros((2, 5, 0)))
|
||||
assert_equal(result, np.array([0, 0]))
|
||||
|
||||
result = matrix_rank(np.zeros((2, 3, 0, 4)))
|
||||
assert_equal(result.shape, (2, 3))
|
||||
assert_equal(result, np.zeros((2, 3), dtype=np.intp))
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import numpy as np
|
|||
from numpy import arange, array, dot, float64, linalg, transpose
|
||||
from numpy.testing import (
|
||||
assert_,
|
||||
assert_almost_equal,
|
||||
assert_array_almost_equal,
|
||||
assert_array_equal,
|
||||
assert_array_less,
|
||||
|
|
@ -180,3 +181,10 @@ class TestRegression:
|
|||
if mismatches != 0:
|
||||
assert False, ("unexpected result from matmul, "
|
||||
"probably due to OpenBLAS threading issues")
|
||||
|
||||
def test_norm_linux_arm(self):
|
||||
# gh-30816
|
||||
a = np.arange(20000) / 50000
|
||||
b = a + 1j * np.roll(np.flip(a), 12345)
|
||||
norm = np.linalg.norm(b)
|
||||
assert_almost_equal(norm, 46.18628948075393)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue