Skip to content

Commit a4edd9b

Browse files
authored
Add documentation to LinAlgError exception (#2613)
The PR adds missing docstrings to `dpnp.linalg.LinAlgError` exception.
1 parent c27aae9 commit a4edd9b

File tree

4 files changed

+43
-5
lines changed

4 files changed

+43
-5
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88

99
### Added
1010

11+
* Added the docstrings to `dpnp.linalg.LinAlgError` exception [#2613](https://github.com/IntelPython/dpnp/pull/2613)
12+
1113
### Changed
1214

1315
* Silenced `pybind11` CMake message due to using compatibility mode for Python [#2614](https://github.com/IntelPython/dpnp/pull/2614)

doc/reference/linalg.rst

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,20 @@ Exceptions
107107
:toctree: generated/
108108
:nosignatures:
109109

110-
dpnp.linalg.linAlgError
110+
dpnp.linalg.LinAlgError
111+
112+
Linear algebra on several matrices at once
113+
------------------------------------------
114+
115+
Several of the linear algebra routines listed above are able to compute results
116+
for several matrices at once, if they are stacked into the same array.
117+
118+
This is indicated in the documentation via input parameter specifications such
119+
as ``a : (..., M, M) {dpnp.ndarray, usm_ndarray}``. This means that if for
120+
instance given an input array ``a.shape == (N, M, M)``, it is interpreted as a
121+
"stack" of N matrices, each of size M-by-M. Similar specification applies to
122+
return values, for instance the determinant has ``det : (...)`` and will in
123+
this case return an array of shape ``det(a).shape == (N,)``. This generalizes
124+
to linear algebra operations on higher-dimensional arrays: the last 1 or 2
125+
dimensions of a multidimensional array are interpreted as vectors or matrices,
126+
as appropriate for each operation.

dpnp/backend/extensions/lapack/lapack_py.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,10 @@ PYBIND11_MODULE(_lapack_impl, m)
8383
.value("C", oneapi::mkl::transpose::C)
8484
.export_values(); // Optional, allows access like `Transpose.N`
8585

86-
// Register a LinAlgError exception in the current submodule
87-
py::register_exception<lapack_ext::LinAlgError>(m, "LinAlgError",
88-
PyExc_ValueError);
86+
// Register a LinAlgError exception with local scope, meaning this is a
87+
// module-private exception (only used in that module)
88+
py::register_local_exception<lapack_ext::LinAlgError>(m, "LinAlgError",
89+
PyExc_ValueError);
8990

9091
init_dispatch_vectors();
9192
init_dispatch_tables();

dpnp/linalg/dpnp_iface_linalg.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,27 @@
104104
"vector_norm",
105105
]
106106

107-
# Need to set the module explicitly, since exposed by LAPACK pybind11 extension
107+
# Need to set the module explicitly, because it's initially exposed by LAPACK
108+
# pybind11 extension and to add the docstrings
108109
LinAlgError.__module__ = "dpnp.linalg"
110+
LinAlgError.__doc__ = """
111+
Generic Python-exception-derived object raised by LinAlg functions.
112+
113+
For full documentation refer to :obj:`numpy.linalg.LinAlgError`.
114+
115+
General purpose exception class, derived from Python's ``ValueError`` class,
116+
programmatically raised in LinAlg functions when a Linear Algebra-related
117+
condition would prevent further correct execution of the function.
118+
119+
Examples
120+
--------
121+
>>> import dpnp as np
122+
>>> np.linalg.inv(np.zeros((2, 2)))
123+
Traceback (most recent call last):
124+
...
125+
dpnp.linalg.LinAlgError: The input coefficient matrix is singular.
126+
127+
"""
109128

110129

111130
# pylint:disable=missing-class-docstring

0 commit comments

Comments
 (0)