增加环绕侦察场景适配

This commit is contained in:
2026-01-08 15:44:38 +08:00
parent 3eba1f962b
commit 10c5bb5a8a
5441 changed files with 40219 additions and 379695 deletions

View File

@@ -84,10 +84,7 @@ Exceptions
"""
# To get sub-modules
from . import (
_linalg,
linalg, # deprecated in NumPy 2.0
)
from . import _linalg
from ._linalg import *
__all__ = _linalg.__all__.copy() # noqa: PLE0605

View File

@@ -1,6 +1,4 @@
from . import _linalg as _linalg
from . import _umath_linalg as _umath_linalg
from . import linalg as linalg
from . import _linalg as _linalg, _umath_linalg as _umath_linalg
from ._linalg import (
cholesky,
cond,

View File

@@ -35,7 +35,9 @@ from numpy._core import (
cdouble,
complexfloating,
count_nonzero,
cross as _core_cross,
csingle,
diagonal as _core_diagonal,
divide,
dot,
double,
@@ -49,10 +51,13 @@ from numpy._core import (
intp,
isfinite,
isnan,
matmul as _core_matmul,
matrix_transpose as _core_matrix_transpose,
moveaxis,
multiply,
newaxis,
object_,
outer as _core_outer,
overrides,
prod,
reciprocal,
@@ -62,34 +67,11 @@ from numpy._core import (
sqrt,
sum,
swapaxes,
zeros,
)
from numpy._core import (
cross as _core_cross,
)
from numpy._core import (
diagonal as _core_diagonal,
)
from numpy._core import (
matmul as _core_matmul,
)
from numpy._core import (
matrix_transpose as _core_matrix_transpose,
)
from numpy._core import (
outer as _core_outer,
)
from numpy._core import (
tensordot as _core_tensordot,
)
from numpy._core import (
trace as _core_trace,
)
from numpy._core import (
transpose as _core_transpose,
)
from numpy._core import (
vecdot as _core_vecdot,
zeros,
)
from numpy._globals import _NoValue
from numpy._typing import NDArray
@@ -335,8 +317,7 @@ def tensorsolve(a, b, axes=None):
Examples
--------
>>> import numpy as np
>>> a = np.eye(2*3*4)
>>> a.shape = (2*3, 4, 2, 3, 4)
>>> a = np.eye(2*3*4).reshape((2*3, 4, 2, 3, 4))
>>> rng = np.random.default_rng()
>>> b = rng.normal(size=(2*3, 4))
>>> x = np.linalg.tensorsolve(a, b)
@@ -513,8 +494,7 @@ def tensorinv(a, ind=2):
Examples
--------
>>> import numpy as np
>>> a = np.eye(4*6)
>>> a.shape = (4, 6, 8, 3)
>>> a = np.eye(4*6).reshape((4, 6, 8, 3))
>>> ainv = np.linalg.tensorinv(a, ind=2)
>>> ainv.shape
(8, 3, 4, 6)
@@ -523,8 +503,7 @@ def tensorinv(a, ind=2):
>>> np.allclose(np.tensordot(ainv, b), np.linalg.tensorsolve(a, b))
True
>>> a = np.eye(4*6)
>>> a.shape = (24, 8, 3)
>>> a = np.eye(4*6).reshape((24, 8, 3))
>>> ainv = np.linalg.tensorinv(a, ind=1)
>>> ainv.shape
(8, 3, 24)
@@ -1016,9 +995,6 @@ def qr(a, mode='reduced'):
Returns
-------
When mode is 'reduced' or 'complete', the result will be a namedtuple with
the attributes `Q` and `R`.
Q : ndarray of float or complex, optional
A matrix with orthonormal columns. When mode = 'complete' the
result is an orthogonal/unitary matrix depending on whether or not
@@ -1047,6 +1023,9 @@ def qr(a, mode='reduced'):
Notes
-----
When mode is 'reduced' or 'complete', the result will be a namedtuple with
the attributes ``Q`` and ``R``.
This is an interface to the LAPACK routines ``dgeqrf``, ``zgeqrf``,
``dorgqr``, and ``zungqr``.
@@ -1717,9 +1696,6 @@ def svd(a, full_matrices=True, compute_uv=True, hermitian=False):
Returns
-------
When `compute_uv` is True, the result is a namedtuple with the following
attribute names:
U : { (..., M, M), (..., M, K) } array
Unitary array(s). The first ``a.ndim - 2`` dimensions have the same
size as those of the input `a`. The size of the last two dimensions
@@ -1747,6 +1723,9 @@ def svd(a, full_matrices=True, compute_uv=True, hermitian=False):
Notes
-----
When `compute_uv` is True, the result is a namedtuple with the following
attribute names: `U`, `S`, and `Vh`.
The decomposition is performed using LAPACK routine ``_gesdd``.
SVD is usually described for the factorization of a 2D matrix :math:`A`.
@@ -2037,18 +2016,14 @@ def cond(x, p=None):
r = r.astype(result_t, copy=False)
# Convert nans to infs unless the original array had nan entries
r = asarray(r)
nan_mask = isnan(r)
if nan_mask.any():
nan_mask &= ~isnan(x).any(axis=(-2, -1))
if r.ndim > 0:
r[nan_mask] = inf
elif nan_mask:
r[()] = inf
# Convention is to return scalars instead of 0d arrays
if r.ndim == 0:
r = r[()]
# Convention is to return scalars instead of 0d arrays.
r = r.dtype.type(inf)
return r
@@ -2094,9 +2069,9 @@ def matrix_rank(A, tol=None, hermitian=False, *, rtol=None):
The default threshold to detect rank deficiency is a test on the magnitude
of the singular values of `A`. By default, we identify singular values
less than ``S.max() * max(M, N) * eps`` as indicating rank deficiency
(with the symbols defined above). This is the algorithm MATLAB uses [1].
(with the symbols defined above). This is the algorithm MATLAB uses [1]_.
It also appears in *Numerical recipes* in the discussion of SVD solutions
for linear least squares [2].
for linear least squares [2]_.
This default threshold is designed to detect rank deficiency accounting
for the numerical errors of the SVD computation. Imagine that there
@@ -2963,7 +2938,7 @@ def multi_dot(arrays, *, out=None):
return A.shape[0] * A.shape[1] * B.shape[1]
Assume we have three matrices
:math:`A_{10 \times 100}, B_{100 \times 5}, C_{5 \times 50}`.
:math:`A_{10 \\times 100}, B_{100 \\times 5}, C_{5 \\times 50}`.
The costs for the two different parenthesizations are as follows::

View File

@@ -1,6 +1,7 @@
from collections.abc import Iterable
from typing import (
Any,
Literal as L,
NamedTuple,
Never,
SupportsIndex,
@@ -9,25 +10,21 @@ from typing import (
TypeVar,
overload,
)
from typing import Literal as L
import numpy as np
from numpy import (
complex128,
complexfloating,
float64,
# other
floating,
int32,
object_,
signedinteger,
timedelta64,
unsignedinteger,
# re-exports
vecdot,
)
from numpy._core.fromnumeric import matrix_transpose
from numpy._core.numeric import tensordot
from numpy._globals import _NoValueType
from numpy._typing import (
ArrayLike,
@@ -38,9 +35,12 @@ from numpy._typing import (
_ArrayLikeComplex_co,
_ArrayLikeFloat_co,
_ArrayLikeInt_co,
_ArrayLikeNumber_co,
_ArrayLikeObject_co,
_ArrayLikeTD64_co,
_ArrayLikeUInt_co,
_NestedSequence,
_ShapeLike,
)
from numpy.linalg import LinAlgError
@@ -80,6 +80,7 @@ __all__ = [
]
_NumberT = TypeVar("_NumberT", bound=np.number)
_NumericScalarT = TypeVar("_NumericScalarT", bound=np.number | np.timedelta64 | np.object_)
_ModeKind: TypeAlias = L["reduced", "complete", "r", "raw"]
@@ -114,19 +115,19 @@ class SVDResult(NamedTuple):
def tensorsolve(
a: _ArrayLikeInt_co,
b: _ArrayLikeInt_co,
axes: Iterable[int] | None = ...,
axes: Iterable[int] | None = None,
) -> NDArray[float64]: ...
@overload
def tensorsolve(
a: _ArrayLikeFloat_co,
b: _ArrayLikeFloat_co,
axes: Iterable[int] | None = ...,
axes: Iterable[int] | None = None,
) -> NDArray[floating]: ...
@overload
def tensorsolve(
a: _ArrayLikeComplex_co,
b: _ArrayLikeComplex_co,
axes: Iterable[int] | None = ...,
axes: Iterable[int] | None = None,
) -> NDArray[complexfloating]: ...
@overload
@@ -148,17 +149,17 @@ def solve(
@overload
def tensorinv(
a: _ArrayLikeInt_co,
ind: int = ...,
ind: int = 2,
) -> NDArray[float64]: ...
@overload
def tensorinv(
a: _ArrayLikeFloat_co,
ind: int = ...,
ind: int = 2,
) -> NDArray[floating]: ...
@overload
def tensorinv(
a: _ArrayLikeComplex_co,
ind: int = ...,
ind: int = 2,
) -> NDArray[complexfloating]: ...
@overload
@@ -208,11 +209,11 @@ def outer(
) -> NDArray[Any]: ...
@overload
def qr(a: _ArrayLikeInt_co, mode: _ModeKind = ...) -> QRResult: ...
def qr(a: _ArrayLikeInt_co, mode: _ModeKind = "reduced") -> QRResult: ...
@overload
def qr(a: _ArrayLikeFloat_co, mode: _ModeKind = ...) -> QRResult: ...
def qr(a: _ArrayLikeFloat_co, mode: _ModeKind = "reduced") -> QRResult: ...
@overload
def qr(a: _ArrayLikeComplex_co, mode: _ModeKind = ...) -> QRResult: ...
def qr(a: _ArrayLikeComplex_co, mode: _ModeKind = "reduced") -> QRResult: ...
@overload
def eigvals(a: _ArrayLikeInt_co) -> NDArray[float64] | NDArray[complex128]: ...
@@ -222,9 +223,9 @@ def eigvals(a: _ArrayLikeFloat_co) -> NDArray[floating] | NDArray[complexfloatin
def eigvals(a: _ArrayLikeComplex_co) -> NDArray[complexfloating]: ...
@overload
def eigvalsh(a: _ArrayLikeInt_co, UPLO: L["L", "U", "l", "u"] = ...) -> NDArray[float64]: ...
def eigvalsh(a: _ArrayLikeInt_co, UPLO: L["L", "U", "l", "u"] = "L") -> NDArray[float64]: ...
@overload
def eigvalsh(a: _ArrayLikeComplex_co, UPLO: L["L", "U", "l", "u"] = ...) -> NDArray[floating]: ...
def eigvalsh(a: _ArrayLikeComplex_co, UPLO: L["L", "U", "l", "u"] = "L") -> NDArray[floating]: ...
@overload
def eig(a: _ArrayLikeInt_co) -> EigResult: ...
@@ -236,70 +237,92 @@ def eig(a: _ArrayLikeComplex_co) -> EigResult: ...
@overload
def eigh(
a: _ArrayLikeInt_co,
UPLO: L["L", "U", "l", "u"] = ...,
UPLO: L["L", "U", "l", "u"] = "L",
) -> EighResult: ...
@overload
def eigh(
a: _ArrayLikeFloat_co,
UPLO: L["L", "U", "l", "u"] = ...,
UPLO: L["L", "U", "l", "u"] = "L",
) -> EighResult: ...
@overload
def eigh(
a: _ArrayLikeComplex_co,
UPLO: L["L", "U", "l", "u"] = ...,
UPLO: L["L", "U", "l", "u"] = "L",
) -> EighResult: ...
@overload
def svd(
a: _ArrayLikeInt_co,
full_matrices: bool = ...,
compute_uv: L[True] = ...,
hermitian: bool = ...,
full_matrices: bool = True,
compute_uv: L[True] = True,
hermitian: bool = False,
) -> SVDResult: ...
@overload
def svd(
a: _ArrayLikeFloat_co,
full_matrices: bool = ...,
compute_uv: L[True] = ...,
hermitian: bool = ...,
full_matrices: bool = True,
compute_uv: L[True] = True,
hermitian: bool = False,
) -> SVDResult: ...
@overload
def svd(
a: _ArrayLikeComplex_co,
full_matrices: bool = ...,
compute_uv: L[True] = ...,
hermitian: bool = ...,
full_matrices: bool = True,
compute_uv: L[True] = True,
hermitian: bool = False,
) -> SVDResult: ...
@overload
def svd(
a: _ArrayLikeInt_co,
full_matrices: bool = ...,
compute_uv: L[False] = ...,
hermitian: bool = ...,
full_matrices: bool = True,
*,
compute_uv: L[False],
hermitian: bool = False,
) -> NDArray[float64]: ...
@overload
def svd(
a: _ArrayLikeInt_co,
full_matrices: bool,
compute_uv: L[False],
hermitian: bool = False,
) -> NDArray[float64]: ...
@overload
def svd(
a: _ArrayLikeComplex_co,
full_matrices: bool = ...,
compute_uv: L[False] = ...,
hermitian: bool = ...,
full_matrices: bool = True,
*,
compute_uv: L[False],
hermitian: bool = False,
) -> NDArray[floating]: ...
@overload
def svd(
a: _ArrayLikeComplex_co,
full_matrices: bool,
compute_uv: L[False],
hermitian: bool = False,
) -> NDArray[floating]: ...
def svdvals(
x: _ArrayLikeInt_co | _ArrayLikeFloat_co | _ArrayLikeComplex_co
) -> NDArray[floating]: ...
# the ignored `overload-overlap` mypy error below is a false-positive
@overload
def svdvals( # type: ignore[overload-overlap]
x: _ArrayLike[np.float64 | np.complex128 | np.integer | np.bool] | _NestedSequence[complex], /
) -> NDArray[np.float64]: ...
@overload
def svdvals(x: _ArrayLike[np.float32 | np.complex64], /) -> NDArray[np.float32]: ...
@overload
def svdvals(x: _ArrayLikeNumber_co, /) -> NDArray[floating]: ...
# TODO: Returns a scalar for 2D arrays and
# a `(x.ndim - 2)`` dimensionl array otherwise
def cond(x: _ArrayLikeComplex_co, p: float | L["fro", "nuc"] | None = ...) -> Any: ...
def cond(x: _ArrayLikeComplex_co, p: float | L["fro", "nuc"] | None = None) -> Any: ...
# TODO: Returns `int` for <2D arrays and `intp` otherwise
def matrix_rank(
A: _ArrayLikeComplex_co,
tol: _ArrayLikeFloat_co | None = ...,
hermitian: bool = ...,
tol: _ArrayLikeFloat_co | None = None,
hermitian: bool = False,
*,
rtol: _ArrayLikeFloat_co | None = ...,
rtol: _ArrayLikeFloat_co | None = None,
) -> Any: ...
@overload
@@ -336,21 +359,21 @@ def slogdet(a: _ArrayLikeComplex_co) -> SlogdetResult: ...
def det(a: _ArrayLikeComplex_co) -> Any: ...
@overload
def lstsq(a: _ArrayLikeInt_co, b: _ArrayLikeInt_co, rcond: float | None = ...) -> tuple[
def lstsq(a: _ArrayLikeInt_co, b: _ArrayLikeInt_co, rcond: float | None = None) -> tuple[
NDArray[float64],
NDArray[float64],
int32,
NDArray[float64],
]: ...
@overload
def lstsq(a: _ArrayLikeFloat_co, b: _ArrayLikeFloat_co, rcond: float | None = ...) -> tuple[
def lstsq(a: _ArrayLikeFloat_co, b: _ArrayLikeFloat_co, rcond: float | None = None) -> tuple[
NDArray[floating],
NDArray[floating],
int32,
NDArray[floating],
]: ...
@overload
def lstsq(a: _ArrayLikeComplex_co, b: _ArrayLikeComplex_co, rcond: float | None = ...) -> tuple[
def lstsq(a: _ArrayLikeComplex_co, b: _ArrayLikeComplex_co, rcond: float | None = None) -> tuple[
NDArray[complexfloating],
NDArray[floating],
int32,
@@ -360,16 +383,24 @@ def lstsq(a: _ArrayLikeComplex_co, b: _ArrayLikeComplex_co, rcond: float | None
@overload
def norm(
x: ArrayLike,
ord: float | L["fro", "nuc"] | None = ...,
axis: None = ...,
keepdims: bool = ...,
ord: float | L["fro", "nuc"] | None = None,
axis: None = None,
keepdims: L[False] = False,
) -> floating: ...
@overload
def norm(
x: ArrayLike,
ord: float | L["fro", "nuc"] | None = ...,
axis: SupportsInt | SupportsIndex | tuple[int, ...] = ...,
keepdims: bool = ...,
ord: float | L["fro", "nuc"] | None,
axis: SupportsInt | SupportsIndex | tuple[int, ...] | None,
keepdims: bool = False,
) -> Any: ...
@overload
def norm(
x: ArrayLike,
ord: float | L["fro", "nuc"] | None = None,
*,
axis: SupportsInt | SupportsIndex | tuple[int, ...] | None,
keepdims: bool = False,
) -> Any: ...
@overload
@@ -377,16 +408,16 @@ def matrix_norm(
x: ArrayLike,
/,
*,
ord: float | L["fro", "nuc"] | None = ...,
keepdims: bool = ...,
ord: float | L["fro", "nuc"] | None = "fro",
keepdims: L[False] = False,
) -> floating: ...
@overload
def matrix_norm(
x: ArrayLike,
/,
*,
ord: float | L["fro", "nuc"] | None = ...,
keepdims: bool = ...,
ord: float | L["fro", "nuc"] | None = "fro",
keepdims: bool = False,
) -> Any: ...
@overload
@@ -394,40 +425,82 @@ def vector_norm(
x: ArrayLike,
/,
*,
axis: None = ...,
ord: float | None = ...,
keepdims: bool = ...,
axis: None = None,
ord: float | None = 2,
keepdims: L[False] = False,
) -> floating: ...
@overload
def vector_norm(
x: ArrayLike,
/,
*,
axis: SupportsInt | SupportsIndex | tuple[int, ...] = ...,
ord: float | None = ...,
keepdims: bool = ...,
axis: SupportsInt | SupportsIndex | tuple[int, ...],
ord: float | None = 2,
keepdims: bool = False,
) -> Any: ...
# keep in sync with numpy._core.numeric.tensordot (ignoring `/, *`)
@overload
def tensordot(
a: _ArrayLike[_NumericScalarT],
b: _ArrayLike[_NumericScalarT],
/,
*,
axes: int | tuple[_ShapeLike, _ShapeLike] = 2,
) -> NDArray[_NumericScalarT]: ...
@overload
def tensordot(
a: _ArrayLikeBool_co,
b: _ArrayLikeBool_co,
/,
*,
axes: int | tuple[_ShapeLike, _ShapeLike] = 2,
) -> NDArray[np.bool_]: ...
@overload
def tensordot(
a: _ArrayLikeInt_co,
b: _ArrayLikeInt_co,
/,
*,
axes: int | tuple[_ShapeLike, _ShapeLike] = 2,
) -> NDArray[np.int_ | Any]: ...
@overload
def tensordot(
a: _ArrayLikeFloat_co,
b: _ArrayLikeFloat_co,
/,
*,
axes: int | tuple[_ShapeLike, _ShapeLike] = 2,
) -> NDArray[np.float64 | Any]: ...
@overload
def tensordot(
a: _ArrayLikeComplex_co,
b: _ArrayLikeComplex_co,
/,
*,
axes: int | tuple[_ShapeLike, _ShapeLike] = 2,
) -> NDArray[np.complex128 | Any]: ...
# TODO: Returns a scalar or array
def multi_dot(
arrays: Iterable[_ArrayLikeComplex_co | _ArrayLikeObject_co | _ArrayLikeTD64_co],
*,
out: NDArray[Any] | None = ...,
out: NDArray[Any] | None = None,
) -> Any: ...
def diagonal(
x: ArrayLike, # >= 2D array
/,
*,
offset: SupportsIndex = ...,
offset: SupportsIndex = 0,
) -> NDArray[Any]: ...
def trace(
x: ArrayLike, # >= 2D array
/,
*,
offset: SupportsIndex = ...,
dtype: DTypeLike = ...,
offset: SupportsIndex = 0,
dtype: DTypeLike | None = None,
) -> Any: ...
@overload
@@ -436,7 +509,7 @@ def cross(
x2: _ArrayLikeUInt_co,
/,
*,
axis: int = ...,
axis: int = -1,
) -> NDArray[unsignedinteger]: ...
@overload
def cross(
@@ -444,7 +517,7 @@ def cross(
x2: _ArrayLikeInt_co,
/,
*,
axis: int = ...,
axis: int = -1,
) -> NDArray[signedinteger]: ...
@overload
def cross(
@@ -452,7 +525,7 @@ def cross(
x2: _ArrayLikeFloat_co,
/,
*,
axis: int = ...,
axis: int = -1,
) -> NDArray[floating]: ...
@overload
def cross(
@@ -460,16 +533,16 @@ def cross(
x2: _ArrayLikeComplex_co,
/,
*,
axis: int = ...,
axis: int = -1,
) -> NDArray[complexfloating]: ...
@overload
def matmul(x1: _ArrayLike[_NumberT], x2: _ArrayLike[_NumberT], /) -> NDArray[_NumberT]: ...
@overload
def matmul(x1: _ArrayLikeInt_co, x2: _ArrayLikeInt_co, /) -> NDArray[signedinteger]: ...
@overload
def matmul(x1: _ArrayLikeUInt_co, x2: _ArrayLikeUInt_co, /) -> NDArray[unsignedinteger]: ...
@overload
def matmul(x1: _ArrayLikeInt_co, x2: _ArrayLikeInt_co, /) -> NDArray[signedinteger]: ...
@overload
def matmul(x1: _ArrayLikeFloat_co, x2: _ArrayLikeFloat_co, /) -> NDArray[floating]: ...
@overload
def matmul(x1: _ArrayLikeComplex_co, x2: _ArrayLikeComplex_co, /) -> NDArray[complexfloating]: ...

View File

@@ -1,5 +1,4 @@
from typing import Final
from typing import Literal as L
from typing import Final, Literal as L
import numpy as np
from numpy._typing._ufunc import _GUFunc_Nin2_Nout1

View File

@@ -57,6 +57,8 @@ class _ZUNGQR(TypedDict):
_ilp64: Final[bool] = ...
class LapackError(Exception): ...
def dgelsd(
m: int,
n: int,

View File

@@ -1,17 +0,0 @@
def __getattr__(attr_name):
import warnings
from numpy.linalg import _linalg
ret = getattr(_linalg, attr_name, None)
if ret is None:
raise AttributeError(
f"module 'numpy.linalg.linalg' has no attribute {attr_name}")
warnings.warn(
"The numpy.linalg.linalg has been made private and renamed to "
"numpy.linalg._linalg. All public functions exported by it are "
f"available from numpy.linalg. Please use numpy.linalg.{attr_name} "
"instead.",
DeprecationWarning,
stacklevel=3
)
return ret

View File

@@ -1,69 +0,0 @@
from ._linalg import (
LinAlgError,
cholesky,
cond,
cross,
det,
diagonal,
eig,
eigh,
eigvals,
eigvalsh,
inv,
lstsq,
matmul,
matrix_norm,
matrix_power,
matrix_rank,
matrix_transpose,
multi_dot,
norm,
outer,
pinv,
qr,
slogdet,
solve,
svd,
svdvals,
tensordot,
tensorinv,
tensorsolve,
trace,
vecdot,
vector_norm,
)
__all__ = [
"LinAlgError",
"cholesky",
"cond",
"cross",
"det",
"diagonal",
"eig",
"eigh",
"eigvals",
"eigvalsh",
"inv",
"lstsq",
"matmul",
"matrix_norm",
"matrix_power",
"matrix_rank",
"matrix_transpose",
"multi_dot",
"norm",
"outer",
"pinv",
"qr",
"slogdet",
"solve",
"svd",
"svdvals",
"tensordot",
"tensorinv",
"tensorsolve",
"trace",
"vecdot",
"vector_norm",
]

View File

@@ -1,8 +1,9 @@
"""Test deprecation and future warnings.
"""
import pytest
import numpy as np
from numpy.testing import assert_warns
def test_qr_mode_full_future_warning():
@@ -14,7 +15,7 @@ def test_qr_mode_full_future_warning():
"""
a = np.eye(2)
assert_warns(DeprecationWarning, np.linalg.qr, a, mode='full')
assert_warns(DeprecationWarning, np.linalg.qr, a, mode='f')
assert_warns(DeprecationWarning, np.linalg.qr, a, mode='economic')
assert_warns(DeprecationWarning, np.linalg.qr, a, mode='e')
pytest.warns(DeprecationWarning, np.linalg.qr, a, mode='full')
pytest.warns(DeprecationWarning, np.linalg.qr, a, mode='f')
pytest.warns(DeprecationWarning, np.linalg.qr, a, mode='economic')
pytest.warns(DeprecationWarning, np.linalg.qr, a, mode='e')

View File

@@ -8,6 +8,7 @@ import sys
import textwrap
import threading
import traceback
import warnings
import pytest
@@ -42,7 +43,6 @@ from numpy.testing import (
assert_equal,
assert_raises,
assert_raises_regex,
suppress_warnings,
)
try:
@@ -1331,8 +1331,9 @@ class _TestNormGeneral(_TestNormBase):
self.check_dtype(at, an)
assert_almost_equal(an, 0.0)
with suppress_warnings() as sup:
sup.filter(RuntimeWarning, "divide by zero encountered")
with warnings.catch_warnings():
warnings.filterwarnings(
'ignore', "divide by zero encountered", RuntimeWarning)
an = norm(at, -1)
self.check_dtype(at, an)
assert_almost_equal(an, 0.0)
@@ -1494,8 +1495,9 @@ class _TestNorm2D(_TestNormBase):
self.check_dtype(at, an)
assert_almost_equal(an, 2.0)
with suppress_warnings() as sup:
sup.filter(RuntimeWarning, "divide by zero encountered")
with warnings.catch_warnings():
warnings.filterwarnings(
'ignore', "divide by zero encountered", RuntimeWarning)
an = norm(at, -1)
self.check_dtype(at, an)
assert_almost_equal(an, 1.0)
@@ -2216,8 +2218,7 @@ class TestTensorinv:
((24, 8, 3), 1),
])
def test_tensorinv_shape(self, shape, ind):
a = np.eye(24)
a.shape = shape
a = np.eye(24).reshape(shape)
ainv = linalg.tensorinv(a=a, ind=ind)
expected = a.shape[ind:] + a.shape[:ind]
actual = ainv.shape
@@ -2227,15 +2228,13 @@ class TestTensorinv:
0, -2,
])
def test_tensorinv_ind_limit(self, ind):
a = np.eye(24)
a.shape = (4, 6, 8, 3)
a = np.eye(24).reshape((4, 6, 8, 3))
with assert_raises(ValueError):
linalg.tensorinv(a=a, ind=ind)
def test_tensorinv_result(self):
# mimic a docstring example
a = np.eye(24)
a.shape = (24, 8, 3)
a = np.eye(24).reshape((24, 8, 3))
ainv = linalg.tensorinv(a, ind=1)
b = np.ones(24)
assert_allclose(np.tensordot(ainv, b, 1), np.linalg.tensorsolve(a, b))

View File

@@ -33,7 +33,7 @@ class TestRegression:
1.51971555e-15 + 0.j,
-1.51308713e-15 + 0.j])
a = arange(13 * 13, dtype=float64)
a.shape = (13, 13)
a = a.reshape((13, 13))
a = a % 17
va, ve = linalg.eig(a)
va.sort()
@@ -165,6 +165,7 @@ class TestRegression:
res = np.linalg.matrix_rank(x, rtol=rtol)
assert res.shape == (4,)
@pytest.mark.thread_unsafe(reason="test is already testing threads with openblas")
def test_openblas_threading(self):
# gh-27036
# Test whether matrix multiplication involving a large matrix always