Skip to content

Commit eaa451d

Browse files
authored
Merge branch 'master' into add-docstring-to-DLPackCreationError
2 parents b9a6871 + a4edd9b commit eaa451d

File tree

5 files changed

+47
-7
lines changed

5 files changed

+47
-7
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@ 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)
1112
* Added `dpnp.exceptions` submodule to aggregate the generic exceptions used by dpnp [#2616](https://github.com/IntelPython/dpnp/pull/2616)
1213

1314
### Changed
1415

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

1720
### Removed

CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ endif()
4949

5050
include(GNUInstallDirs)
5151

52+
# find Python before enabling pybind11
53+
find_package(Python REQUIRED COMPONENTS Development.Module NumPy)
54+
5255
# Fetch pybind11
5356
include(FetchContent)
5457
FetchContent_Declare(
@@ -59,8 +62,6 @@ FetchContent_Declare(
5962
)
6063
FetchContent_MakeAvailable(pybind11)
6164

62-
find_package(Python REQUIRED COMPONENTS Development.Module NumPy)
63-
6465
set(CYTHON_FLAGS "-t -w \"${CMAKE_SOURCE_DIR}\"")
6566
find_package(Cython REQUIRED)
6667

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)