summaryrefslogtreecommitdiff
path: root/numpy/linalg
diff options
context:
space:
mode:
authorGagandeep Singh <gdp.1807@gmail.com>2021-11-02 11:28:17 +0530
committerGagandeep Singh <gdp.1807@gmail.com>2021-11-02 11:28:17 +0530
commitc04509e86e97a69a0b5fcbeebdbec66faad3dbe0 (patch)
treeb5940db3ad46e55b88d566ec058007dc3c6b7e72 /numpy/linalg
parent56647dd47345a7fd24b4ee8d9d52025fcdc3b9ae (diff)
parentfae6fa47a3cf9b9c64af2f5bd11a3b644b1763d2 (diff)
downloadnumpy-c04509e86e97a69a0b5fcbeebdbec66faad3dbe0.tar.gz
resolved conflicts
Diffstat (limited to 'numpy/linalg')
-rw-r--r--numpy/linalg/__init__.pyi44
-rw-r--r--numpy/linalg/lapack_lite/README.rst7
-rw-r--r--numpy/linalg/lapack_lite/clapack_scrub.py45
-rw-r--r--numpy/linalg/lapack_lite/fortran.py5
-rwxr-xr-xnumpy/linalg/lapack_lite/make_lite.py40
-rw-r--r--numpy/linalg/lapack_lite/python_xerbla.c4
-rw-r--r--numpy/linalg/lapack_litemodule.c5
-rw-r--r--numpy/linalg/linalg.py10
-rw-r--r--numpy/linalg/linalg.pyi284
-rw-r--r--numpy/linalg/setup.py3
-rw-r--r--numpy/linalg/tests/test_linalg.py11
-rw-r--r--numpy/linalg/umath_linalg.c.src5
12 files changed, 383 insertions, 80 deletions
diff --git a/numpy/linalg/__init__.pyi b/numpy/linalg/__init__.pyi
index 7237d865d..d457f153a 100644
--- a/numpy/linalg/__init__.pyi
+++ b/numpy/linalg/__init__.pyi
@@ -1,5 +1,28 @@
from typing import Any, List
+from numpy.linalg.linalg import (
+ matrix_power as matrix_power,
+ solve as solve,
+ tensorsolve as tensorsolve,
+ tensorinv as tensorinv,
+ inv as inv,
+ cholesky as cholesky,
+ eigvals as eigvals,
+ eigvalsh as eigvalsh,
+ pinv as pinv,
+ slogdet as slogdet,
+ det as det,
+ svd as svd,
+ eig as eig,
+ eigh as eigh,
+ lstsq as lstsq,
+ norm as norm,
+ qr as qr,
+ cond as cond,
+ matrix_rank as matrix_rank,
+ multi_dot as multi_dot,
+)
+
from numpy._pytesttester import PytestTester
__all__: List[str]
@@ -7,24 +30,3 @@ __path__: List[str]
test: PytestTester
class LinAlgError(Exception): ...
-
-def tensorsolve(a, b, axes=...): ...
-def solve(a, b): ...
-def tensorinv(a, ind=...): ...
-def inv(a): ...
-def matrix_power(a, n): ...
-def cholesky(a): ...
-def qr(a, mode=...): ...
-def eigvals(a): ...
-def eigvalsh(a, UPLO=...): ...
-def eig(a): ...
-def eigh(a, UPLO=...): ...
-def svd(a, full_matrices=..., compute_uv=..., hermitian=...): ...
-def cond(x, p=...): ...
-def matrix_rank(A, tol=..., hermitian=...): ...
-def pinv(a, rcond=..., hermitian=...): ...
-def slogdet(a): ...
-def det(a): ...
-def lstsq(a, b, rcond=...): ...
-def norm(x, ord=..., axis=..., keepdims=...): ...
-def multi_dot(arrays, *, out=...): ...
diff --git a/numpy/linalg/lapack_lite/README.rst b/numpy/linalg/lapack_lite/README.rst
index ed738ab86..8baa1d8ff 100644
--- a/numpy/linalg/lapack_lite/README.rst
+++ b/numpy/linalg/lapack_lite/README.rst
@@ -12,15 +12,18 @@ automatically from a directory of LAPACK source files.
You'll need `plex 2.0.0dev`_, available from PyPI, installed to do the
appropriate scrubbing. As of writing, **this is only available for python 2.7**,
and is unlikely to ever be ported to python 3.
+As a result, all the Python scripts in this directory must remain compatible
+with Python 2.7, even though NumPy itself no longer supports this version,
+until these scripts are rewritten to use something other than ``plex``.
.. _plex 2.0.0dev: https://pypi.python.org/pypi/plex/
The routines that ``lapack_litemodule.c`` wraps are listed in
``wrapped_routines``, along with a few exceptions that aren't picked up
properly. Assuming that you have an unpacked LAPACK source tree in
-``~/LAPACK``, you generate the new routines in this directory with::
+``/tmp/lapack-3.x.x``, you generate the new routines in this directory with::
-$ python ./make_lite.py wrapped_routines ~/LAPACK
+$ ./make_lite.py wrapped_routines /tmp/lapack-3.x.x
This will grab the right routines, with dependencies, put them into the
appropriate ``f2c_*.f`` files, run ``f2c`` over them, then do some scrubbing
diff --git a/numpy/linalg/lapack_lite/clapack_scrub.py b/numpy/linalg/lapack_lite/clapack_scrub.py
index 738fad7fe..fffd70910 100644
--- a/numpy/linalg/lapack_lite/clapack_scrub.py
+++ b/numpy/linalg/lapack_lite/clapack_scrub.py
@@ -1,12 +1,17 @@
-#!/usr/bin/env python3
+#!/usr/bin/env python2.7
+# WARNING! This a Python 2 script. Read README.rst for rationale.
import os
import re
import sys
-from io import StringIO
from plex import Scanner, Str, Lexicon, Opt, Bol, State, AnyChar, TEXT, IGNORE
from plex.traditional import re as Re
+try:
+ from io import BytesIO as UStringIO # Python 2
+except ImportError:
+ from io import StringIO as UStringIO # Python 3
+
class MyScanner(Scanner):
def __init__(self, info, name='<default>'):
@@ -22,8 +27,8 @@ def sep_seq(sequence, sep):
return pat
def runScanner(data, scanner_class, lexicon=None):
- info = StringIO(data)
- outfo = StringIO()
+ info = UStringIO(data)
+ outfo = UStringIO()
if lexicon is not None:
scanner = scanner_class(lexicon, info)
else:
@@ -190,7 +195,7 @@ def cleanComments(source):
return SourceLines
state = SourceLines
- for line in StringIO(source):
+ for line in UStringIO(source):
state = state(line)
comments.flushTo(lines)
return lines.getValue()
@@ -218,20 +223,23 @@ def removeHeader(source):
return OutOfHeader
state = LookingForHeader
- for line in StringIO(source):
+ for line in UStringIO(source):
state = state(line)
return lines.getValue()
def removeSubroutinePrototypes(source):
- expression = re.compile(
- r'/\* Subroutine \*/^\s*(?:(?:inline|static)\s+){0,2}(?!else|typedef|return)\w+\s+\*?\s*(\w+)\s*\([^0]+\)\s*;?'
- )
- lines = LineQueue()
- for line in StringIO(source):
- if not expression.match(line):
- lines.add(line)
-
- return lines.getValue()
+ # This function has never worked as advertised by its name:
+ # - "/* Subroutine */" declarations may span multiple lines and
+ # cannot be matched by a line by line approach.
+ # - The caret in the initial regex would prevent any match, even
+ # of single line "/* Subroutine */" declarations.
+ #
+ # While we could "fix" this function to do what the name implies
+ # it should do, we have no hint of what it should really do.
+ #
+ # Therefore we keep the existing (non-)functionaity, documenting
+ # this function as doing nothing at all.
+ return source
def removeBuiltinFunctions(source):
lines = LineQueue()
@@ -249,7 +257,7 @@ def removeBuiltinFunctions(source):
return InBuiltInFunctions
state = LookingForBuiltinFunctions
- for line in StringIO(source):
+ for line in UStringIO(source):
state = state(line)
return lines.getValue()
@@ -299,6 +307,5 @@ if __name__ == '__main__':
source = scrub_source(source, nsteps, verbose=True)
- writefo = open(outfilename, 'w')
- writefo.write(source)
- writefo.close()
+ with open(outfilename, 'w') as writefo:
+ writefo.write(source)
diff --git a/numpy/linalg/lapack_lite/fortran.py b/numpy/linalg/lapack_lite/fortran.py
index fc09f0808..2a5c9c05e 100644
--- a/numpy/linalg/lapack_lite/fortran.py
+++ b/numpy/linalg/lapack_lite/fortran.py
@@ -1,3 +1,4 @@
+# WARNING! This a Python 2 script. Read README.rst for rationale.
import re
import itertools
@@ -44,6 +45,8 @@ class LineIterator:
line = line.rstrip()
return line
+ next = __next__
+
class PushbackIterator:
"""PushbackIterator(iterable)
@@ -69,6 +72,8 @@ class PushbackIterator:
def pushback(self, item):
self.buffer.append(item)
+ next = __next__
+
def fortranSourceLines(fo):
"""Return an iterator over statement lines of a Fortran source file.
diff --git a/numpy/linalg/lapack_lite/make_lite.py b/numpy/linalg/lapack_lite/make_lite.py
index 09ffaf840..ca8d4c62c 100755
--- a/numpy/linalg/lapack_lite/make_lite.py
+++ b/numpy/linalg/lapack_lite/make_lite.py
@@ -1,4 +1,5 @@
-#!/usr/bin/env python3
+#!/usr/bin/env python2.7
+# WARNING! This a Python 2 script. Read README.rst for rationale.
"""
Usage: make_lite.py <wrapped_routines_file> <lapack_dir>
@@ -20,7 +21,10 @@ import shutil
import fortran
import clapack_scrub
-from shutil import which
+try:
+ from distutils.spawn import find_executable as which # Python 2
+except ImportError:
+ from shutil import which # Python 3
# Arguments to pass to f2c. You'll always want -A for ANSI C prototypes
# Others of interest: -a to not make variables static by default
@@ -81,7 +85,8 @@ class FortranRoutine:
return self._dependencies
def __repr__(self):
- return f'FortranRoutine({self.name!r}, filename={self.filename!r})'
+ return "FortranRoutine({!r}, filename={!r})".format(self.name,
+ self.filename)
class UnknownFortranRoutine(FortranRoutine):
"""Wrapper for a Fortran routine for which the corresponding file
@@ -193,7 +198,7 @@ class LapackLibrary(FortranLibrary):
def printRoutineNames(desc, routines):
print(desc)
for r in routines:
- print(f'\t{r.name}')
+ print('\t%s' % r.name)
def getLapackRoutines(wrapped_routines, ignores, lapack_dir):
blas_src_dir = os.path.join(lapack_dir, 'BLAS', 'SRC')
@@ -243,7 +248,7 @@ def dumpRoutineNames(library, output_dir):
with open(filename, 'w') as fo:
for r in routines:
deps = r.dependencies()
- fo.write(f"{r.name}: {' '.join(deps)}\n")
+ fo.write('%s: %s\n' % (r.name, ' '.join(deps)))
def concatenateRoutines(routines, output_file):
with open(output_file, 'w') as output_fo:
@@ -261,8 +266,8 @@ def runF2C(fortran_filename, output_dir):
subprocess.check_call(
["f2c"] + F2C_ARGS + ['-d', output_dir, fortran_filename]
)
- except subprocess.CalledProcessError as e:
- raise F2CError from e
+ except subprocess.CalledProcessError:
+ raise F2CError
def scrubF2CSource(c_file):
with open(c_file) as fo:
@@ -275,8 +280,8 @@ def scrubF2CSource(c_file):
def ensure_executable(name):
try:
which(name)
- except Exception as ex:
- raise SystemExit(name + ' not found') from ex
+ except Exception:
+ raise SystemExit(name + ' not found')
def create_name_header(output_dir):
routine_re = re.compile(r'^ (subroutine|.* function)\s+(\w+)\(.*$',
@@ -316,13 +321,13 @@ def create_name_header(output_dir):
# Rename BLAS/LAPACK symbols
for name in sorted(symbols):
- f.write(f'#define {name}_ BLAS_FUNC({name})\n')
+ f.write("#define %s_ BLAS_FUNC(%s)\n" % (name, name))
# Rename also symbols that f2c exports itself
f.write("\n"
"/* Symbols exported by f2c.c */\n")
for name in sorted(f2c_symbols):
- f.write(f'#define {name} numpy_lapack_lite_{name}\n')
+ f.write("#define %s numpy_lapack_lite_%s\n" % (name, name))
def main():
if len(sys.argv) != 3:
@@ -336,10 +341,7 @@ def main():
lapack_src_dir = sys.argv[2]
output_dir = os.path.join(os.path.dirname(__file__), 'build')
- try:
- shutil.rmtree(output_dir)
- except:
- pass
+ shutil.rmtree(output_dir, ignore_errors=True)
os.makedirs(output_dir)
wrapped_routines, ignores = getWrappedRoutineNames(wrapped_routines_file)
@@ -348,9 +350,9 @@ def main():
dumpRoutineNames(library, output_dir)
for typename in types:
- fortran_file = os.path.join(output_dir, f'f2c_{typename}.f')
+ fortran_file = os.path.join(output_dir, 'f2c_%s.f' % typename)
c_file = fortran_file[:-2] + '.c'
- print(f'creating {c_file} ...')
+ print('creating %s ...' % c_file)
routines = library.allRoutinesByType(typename)
concatenateRoutines(routines, fortran_file)
@@ -358,11 +360,11 @@ def main():
patch_file = os.path.basename(fortran_file) + '.patch'
if os.path.exists(patch_file):
subprocess.check_call(['patch', '-u', fortran_file, patch_file])
- print(f'Patched {fortran_file}')
+ print("Patched {}".format(fortran_file))
try:
runF2C(fortran_file, output_dir)
except F2CError:
- print(f'f2c failed on {fortran_file}')
+ print('f2c failed on %s' % fortran_file)
break
scrubF2CSource(c_file)
diff --git a/numpy/linalg/lapack_lite/python_xerbla.c b/numpy/linalg/lapack_lite/python_xerbla.c
index fe2f718b2..37a41408b 100644
--- a/numpy/linalg/lapack_lite/python_xerbla.c
+++ b/numpy/linalg/lapack_lite/python_xerbla.c
@@ -1,4 +1,6 @@
-#include "Python.h"
+#define PY_SSIZE_T_CLEAN
+#include <Python.h>
+
#include "numpy/npy_common.h"
#include "npy_cblas.h"
diff --git a/numpy/linalg/lapack_litemodule.c b/numpy/linalg/lapack_litemodule.c
index 362a593a6..2fed0f2b0 100644
--- a/numpy/linalg/lapack_litemodule.c
+++ b/numpy/linalg/lapack_litemodule.c
@@ -4,11 +4,12 @@ More modifications by Jeff Whitaker
*/
#define NPY_NO_DEPRECATED_API NPY_API_VERSION
-#include "Python.h"
+#define PY_SSIZE_T_CLEAN
+#include <Python.h>
+
#include "numpy/arrayobject.h"
#include "npy_cblas.h"
-
#define FNAME(name) BLAS_FUNC(name)
typedef CBLAS_INT fortran_int;
diff --git a/numpy/linalg/linalg.py b/numpy/linalg/linalg.py
index 2b686839a..0c27e0631 100644
--- a/numpy/linalg/linalg.py
+++ b/numpy/linalg/linalg.py
@@ -30,7 +30,7 @@ from numpy.core.multiarray import normalize_axis_index
from numpy.core.overrides import set_module
from numpy.core import overrides
from numpy.lib.twodim_base import triu, eye
-from numpy.linalg import lapack_lite, _umath_linalg
+from numpy.linalg import _umath_linalg
array_function_dispatch = functools.partial(
@@ -1680,7 +1680,7 @@ def cond(x, p=None):
x : (..., M, N) array_like
The matrix whose condition number is sought.
p : {None, 1, -1, 2, -2, inf, -inf, 'fro'}, optional
- Order of the norm:
+ Order of the norm used in the condition number computation:
===== ============================
p norm for matrices
@@ -1695,7 +1695,7 @@ def cond(x, p=None):
-2 smallest singular value
===== ============================
- inf means the numpy.inf object, and the Frobenius norm is
+ inf means the `numpy.inf` object, and the Frobenius norm is
the root-of-sum-of-squares norm.
Returns
@@ -1864,7 +1864,7 @@ def matrix_rank(A, tol=None, hermitian=False):
References
----------
- .. [1] MATLAB reference documention, "Rank"
+ .. [1] MATLAB reference documentation, "Rank"
https://www.mathworks.com/help/techdoc/ref/rank.html
.. [2] W. H. Press, S. A. Teukolsky, W. T. Vetterling and B. P. Flannery,
"Numerical Recipes (3rd edition)", Cambridge University Press, 2007,
@@ -2159,7 +2159,7 @@ def lstsq(a, b, rcond="warn"):
r"""
Return the least-squares solution to a linear matrix equation.
- Computes the vector `x` that approximatively solves the equation
+ Computes the vector `x` that approximately solves the equation
``a @ x = b``. The equation may be under-, well-, or over-determined
(i.e., the number of linearly independent rows of `a` can be less than,
equal to, or greater than its number of linearly independent columns).
diff --git a/numpy/linalg/linalg.pyi b/numpy/linalg/linalg.pyi
new file mode 100644
index 000000000..a60b9539e
--- /dev/null
+++ b/numpy/linalg/linalg.pyi
@@ -0,0 +1,284 @@
+from typing import (
+ Literal as L,
+ List,
+ Iterable,
+ overload,
+ TypeVar,
+ Any,
+ SupportsIndex,
+ SupportsInt,
+ Tuple,
+)
+
+from numpy import (
+ generic,
+ floating,
+ complexfloating,
+ int32,
+ float64,
+ complex128,
+)
+
+from numpy.linalg import LinAlgError as LinAlgError
+
+from numpy.typing import (
+ NDArray,
+ ArrayLike,
+ _ArrayLikeInt_co,
+ _ArrayLikeFloat_co,
+ _ArrayLikeComplex_co,
+ _ArrayLikeTD64_co,
+ _ArrayLikeObject_co,
+)
+
+_T = TypeVar("_T")
+_ArrayType = TypeVar("_ArrayType", bound=NDArray[Any])
+
+_2Tuple = Tuple[_T, _T]
+_ModeKind = L["reduced", "complete", "r", "raw"]
+
+__all__: List[str]
+
+@overload
+def tensorsolve(
+ a: _ArrayLikeInt_co,
+ b: _ArrayLikeInt_co,
+ axes: None | Iterable[int] =...,
+) -> NDArray[float64]: ...
+@overload
+def tensorsolve(
+ a: _ArrayLikeFloat_co,
+ b: _ArrayLikeFloat_co,
+ axes: None | Iterable[int] =...,
+) -> NDArray[floating[Any]]: ...
+@overload
+def tensorsolve(
+ a: _ArrayLikeComplex_co,
+ b: _ArrayLikeComplex_co,
+ axes: None | Iterable[int] =...,
+) -> NDArray[complexfloating[Any, Any]]: ...
+
+@overload
+def solve(
+ a: _ArrayLikeInt_co,
+ b: _ArrayLikeInt_co,
+) -> NDArray[float64]: ...
+@overload
+def solve(
+ a: _ArrayLikeFloat_co,
+ b: _ArrayLikeFloat_co,
+) -> NDArray[floating[Any]]: ...
+@overload
+def solve(
+ a: _ArrayLikeComplex_co,
+ b: _ArrayLikeComplex_co,
+) -> NDArray[complexfloating[Any, Any]]: ...
+
+@overload
+def tensorinv(
+ a: _ArrayLikeInt_co,
+ ind: int = ...,
+) -> NDArray[float64]: ...
+@overload
+def tensorinv(
+ a: _ArrayLikeFloat_co,
+ ind: int = ...,
+) -> NDArray[floating[Any]]: ...
+@overload
+def tensorinv(
+ a: _ArrayLikeComplex_co,
+ ind: int = ...,
+) -> NDArray[complexfloating[Any, Any]]: ...
+
+@overload
+def inv(a: _ArrayLikeInt_co) -> NDArray[float64]: ...
+@overload
+def inv(a: _ArrayLikeFloat_co) -> NDArray[floating[Any]]: ...
+@overload
+def inv(a: _ArrayLikeComplex_co) -> NDArray[complexfloating[Any, Any]]: ...
+
+# TODO: The supported input and output dtypes are dependent on the value of `n`.
+# For example: `n < 0` always casts integer types to float64
+def matrix_power(
+ a: _ArrayLikeComplex_co | _ArrayLikeObject_co,
+ n: SupportsIndex,
+) -> NDArray[Any]: ...
+
+@overload
+def cholesky(a: _ArrayLikeInt_co) -> NDArray[float64]: ...
+@overload
+def cholesky(a: _ArrayLikeFloat_co) -> NDArray[floating[Any]]: ...
+@overload
+def cholesky(a: _ArrayLikeComplex_co) -> NDArray[complexfloating[Any, Any]]: ...
+
+@overload
+def qr(a: _ArrayLikeInt_co, mode: _ModeKind = ...) -> _2Tuple[NDArray[float64]]: ...
+@overload
+def qr(a: _ArrayLikeFloat_co, mode: _ModeKind = ...) -> _2Tuple[NDArray[floating[Any]]]: ...
+@overload
+def qr(a: _ArrayLikeComplex_co, mode: _ModeKind = ...) -> _2Tuple[NDArray[complexfloating[Any, Any]]]: ...
+
+@overload
+def eigvals(a: _ArrayLikeInt_co) -> NDArray[float64] | NDArray[complex128]: ...
+@overload
+def eigvals(a: _ArrayLikeFloat_co) -> NDArray[floating[Any]] | NDArray[complexfloating[Any, Any]]: ...
+@overload
+def eigvals(a: _ArrayLikeComplex_co) -> NDArray[complexfloating[Any, Any]]: ...
+
+@overload
+def eigvalsh(a: _ArrayLikeInt_co, UPLO: L["L", "U", "l", "u"] = ...) -> NDArray[float64]: ...
+@overload
+def eigvalsh(a: _ArrayLikeComplex_co, UPLO: L["L", "U", "l", "u"] = ...) -> NDArray[floating[Any]]: ...
+
+@overload
+def eig(a: _ArrayLikeInt_co) -> _2Tuple[NDArray[float64]] | _2Tuple[NDArray[complex128]]: ...
+@overload
+def eig(a: _ArrayLikeFloat_co) -> _2Tuple[NDArray[floating[Any]]] | _2Tuple[NDArray[complexfloating[Any, Any]]]: ...
+@overload
+def eig(a: _ArrayLikeComplex_co) -> _2Tuple[NDArray[complexfloating[Any, Any]]]: ...
+
+@overload
+def eigh(
+ a: _ArrayLikeInt_co,
+ UPLO: L["L", "U", "l", "u"] = ...,
+) -> Tuple[NDArray[float64], NDArray[float64]]: ...
+@overload
+def eigh(
+ a: _ArrayLikeFloat_co,
+ UPLO: L["L", "U", "l", "u"] = ...,
+) -> Tuple[NDArray[floating[Any]], NDArray[floating[Any]]]: ...
+@overload
+def eigh(
+ a: _ArrayLikeComplex_co,
+ UPLO: L["L", "U", "l", "u"] = ...,
+) -> Tuple[NDArray[floating[Any]], NDArray[complexfloating[Any, Any]]]: ...
+
+@overload
+def svd(
+ a: _ArrayLikeInt_co,
+ full_matrices: bool = ...,
+ compute_uv: L[True] = ...,
+ hermitian: bool = ...,
+) -> Tuple[
+ NDArray[float64],
+ NDArray[float64],
+ NDArray[float64],
+]: ...
+@overload
+def svd(
+ a: _ArrayLikeFloat_co,
+ full_matrices: bool = ...,
+ compute_uv: L[True] = ...,
+ hermitian: bool = ...,
+) -> Tuple[
+ NDArray[floating[Any]],
+ NDArray[floating[Any]],
+ NDArray[floating[Any]],
+]: ...
+@overload
+def svd(
+ a: _ArrayLikeComplex_co,
+ full_matrices: bool = ...,
+ compute_uv: L[True] = ...,
+ hermitian: bool = ...,
+) -> Tuple[
+ NDArray[complexfloating[Any, Any]],
+ NDArray[floating[Any]],
+ NDArray[complexfloating[Any, Any]],
+]: ...
+@overload
+def svd(
+ a: _ArrayLikeInt_co,
+ full_matrices: bool = ...,
+ compute_uv: L[False] = ...,
+ hermitian: bool = ...,
+) -> NDArray[float64]: ...
+@overload
+def svd(
+ a: _ArrayLikeComplex_co,
+ full_matrices: bool = ...,
+ compute_uv: L[False] = ...,
+ hermitian: bool = ...,
+) -> NDArray[floating[Any]]: ...
+
+# TODO: Returns a scalar for 2D arrays and
+# a `(x.ndim - 2)`` dimensionl array otherwise
+def cond(x: _ArrayLikeComplex_co, p: None | float | L["fro", "nuc"] = ...) -> Any: ...
+
+# TODO: Returns `int` for <2D arrays and `intp` otherwise
+def matrix_rank(
+ A: _ArrayLikeComplex_co,
+ tol: None | _ArrayLikeFloat_co = ...,
+ hermitian: bool = ...,
+) -> Any: ...
+
+@overload
+def pinv(
+ a: _ArrayLikeInt_co,
+ rcond: _ArrayLikeFloat_co = ...,
+ hermitian: bool = ...,
+) -> NDArray[float64]: ...
+@overload
+def pinv(
+ a: _ArrayLikeFloat_co,
+ rcond: _ArrayLikeFloat_co = ...,
+ hermitian: bool = ...,
+) -> NDArray[floating[Any]]: ...
+@overload
+def pinv(
+ a: _ArrayLikeComplex_co,
+ rcond: _ArrayLikeFloat_co = ...,
+ hermitian: bool = ...,
+) -> NDArray[complexfloating[Any, Any]]: ...
+
+# TODO: Returns a 2-tuple of scalars for 2D arrays and
+# a 2-tuple of `(a.ndim - 2)`` dimensionl arrays otherwise
+def slogdet(a: _ArrayLikeComplex_co) -> _2Tuple[Any]: ...
+
+# TODO: Returns a 2-tuple of scalars for 2D arrays and
+# a 2-tuple of `(a.ndim - 2)`` dimensionl arrays otherwise
+def det(a: _ArrayLikeComplex_co) -> Any: ...
+
+@overload
+def lstsq(a: _ArrayLikeInt_co, b: _ArrayLikeInt_co, rcond: None | float = ...) -> Tuple[
+ NDArray[float64],
+ NDArray[float64],
+ int32,
+ NDArray[float64],
+]: ...
+@overload
+def lstsq(a: _ArrayLikeFloat_co, b: _ArrayLikeFloat_co, rcond: None | float = ...) -> Tuple[
+ NDArray[floating[Any]],
+ NDArray[floating[Any]],
+ int32,
+ NDArray[floating[Any]],
+]: ...
+@overload
+def lstsq(a: _ArrayLikeComplex_co, b: _ArrayLikeComplex_co, rcond: None | float = ...) -> Tuple[
+ NDArray[complexfloating[Any, Any]],
+ NDArray[floating[Any]],
+ int32,
+ NDArray[floating[Any]],
+]: ...
+
+@overload
+def norm(
+ x: ArrayLike,
+ ord: None | float | L["fro", "nuc"] = ...,
+ axis: None = ...,
+ keepdims: bool = ...,
+) -> floating[Any]: ...
+@overload
+def norm(
+ x: ArrayLike,
+ ord: None | float | L["fro", "nuc"] = ...,
+ axis: SupportsInt | SupportsIndex | Tuple[int, ...] = ...,
+ keepdims: bool = ...,
+) -> Any: ...
+
+# TODO: Returns a scalar or array
+def multi_dot(
+ arrays: Iterable[_ArrayLikeComplex_co | _ArrayLikeObject_co | _ArrayLikeTD64_co],
+ *,
+ out: None | NDArray[Any] = ...,
+) -> Any: ...
diff --git a/numpy/linalg/setup.py b/numpy/linalg/setup.py
index e2944f38c..94536bb2c 100644
--- a/numpy/linalg/setup.py
+++ b/numpy/linalg/setup.py
@@ -3,8 +3,7 @@ import sys
def configuration(parent_package='', top_path=None):
from numpy.distutils.misc_util import Configuration
- from numpy.distutils.system_info import (
- get_info, system_info, lapack_opt_info, blas_opt_info)
+ from numpy.distutils.system_info import get_info, system_info
config = Configuration('linalg', parent_package, top_path)
config.add_subpackage('tests')
diff --git a/numpy/linalg/tests/test_linalg.py b/numpy/linalg/tests/test_linalg.py
index dd059fb63..c1ba84a8e 100644
--- a/numpy/linalg/tests/test_linalg.py
+++ b/numpy/linalg/tests/test_linalg.py
@@ -1,7 +1,6 @@
""" Test functions for linalg module
"""
-from numpy.core.fromnumeric import shape
import os
import sys
import itertools
@@ -22,7 +21,6 @@ from numpy.testing import (
assert_almost_equal, assert_allclose, suppress_warnings,
assert_raises_regex, HAS_LAPACK64,
)
-from numpy.testing._private.utils import requires_memory
def consistent_subclass(out, in_):
@@ -1072,7 +1070,6 @@ class TestMatrixPower:
assert_raises(LinAlgError, matrix_power, mat, -1)
-
class TestEigvalshCases(HermitianTestCase, HermitianGeneralizedTestCase):
def do(self, a, b, tags):
@@ -1956,8 +1953,8 @@ class TestMultiDot:
assert_almost_equal(multi_dot([A, B]), A.dot(B))
assert_almost_equal(multi_dot([A, B]), np.dot(A, B))
- def test_basic_function_with_dynamic_programing_optimization(self):
- # multi_dot with four or more arguments uses the dynamic programing
+ def test_basic_function_with_dynamic_programming_optimization(self):
+ # multi_dot with four or more arguments uses the dynamic programming
# optimization and therefore deserve a separate
A = np.random.random((6, 2))
B = np.random.random((2, 6))
@@ -2018,8 +2015,8 @@ class TestMultiDot:
assert_almost_equal(out, A.dot(B))
assert_almost_equal(out, np.dot(A, B))
- def test_dynamic_programing_optimization_and_out(self):
- # multi_dot with four or more arguments uses the dynamic programing
+ def test_dynamic_programming_optimization_and_out(self):
+ # multi_dot with four or more arguments uses the dynamic programming
# optimization and therefore deserve a separate test
A = np.random.random((6, 2))
B = np.random.random((2, 6))
diff --git a/numpy/linalg/umath_linalg.c.src b/numpy/linalg/umath_linalg.c.src
index a486e9e5b..ff63ea218 100644
--- a/numpy/linalg/umath_linalg.c.src
+++ b/numpy/linalg/umath_linalg.c.src
@@ -5,9 +5,10 @@
** INCLUDES **
*****************************************************************************
*/
-#define NPY_NO_DEPRECATED_API NPY_API_VERSION
+#define PY_SSIZE_T_CLEAN
+#include <Python.h>
-#include "Python.h"
+#define NPY_NO_DEPRECATED_API NPY_API_VERSION
#include "numpy/arrayobject.h"
#include "numpy/ufuncobject.h"