Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
44a329c
Introduce dpnp.scipy submodule with dpnp.scipy.linalg
vlad-perevezentsev Sep 30, 2025
05e51d7
Lazy import dpnp.scipy submodule
vlad-perevezentsev Oct 1, 2025
9b288c5
Remove lu_factor and lu_solve from dpnp.linalg
vlad-perevezentsev Oct 1, 2025
3fdc5fa
Correct call migrated functions in tests
vlad-perevezentsev Oct 1, 2025
0ef07b2
Update rendered page for scipy submodule
vlad-perevezentsev Oct 1, 2025
13bdcfd
Move dpnp.special to dpnp.scipy.special
vlad-perevezentsev Oct 1, 2025
f6512c5
Update erf tests after migration
vlad-perevezentsev Oct 1, 2025
bf3bdb7
Update rendered page for dpnp.scipy.special
vlad-perevezentsev Oct 1, 2025
c624329
Merge master into scipy_submodule
vlad-perevezentsev Oct 1, 2025
1526a53
Use eager import for dpnp.scipy
vlad-perevezentsev Oct 2, 2025
6f6326b
Use correct call in TestLuFactorBatched::test_strided
vlad-perevezentsev Oct 2, 2025
fb153a6
Remove unused import import_module
vlad-perevezentsev Oct 2, 2025
26fad7e
Apply remarks
vlad-perevezentsev Oct 2, 2025
24e7fa3
Remove extra pylint dasables
vlad-perevezentsev Oct 2, 2025
e4a0488
Disable pylint duplicate code for dpnp_utils_linalg
vlad-perevezentsev Oct 2, 2025
64aefb5
Disable pylint duplicate code for another iface files
vlad-perevezentsev Oct 2, 2025
2d48d68
Merge master into scipy_submodule
vlad-perevezentsev Oct 6, 2025
5907a56
Rename dpnp_iface_scipy_linalg.py to _decomp_lu.py
vlad-perevezentsev Oct 6, 2025
42f4846
Rename dpnp_utils_scipy_linalg.py to _utils.py
vlad-perevezentsev Oct 6, 2025
fad2bfa
Update _call_func_cupy and remove resolve_special_scp
vlad-perevezentsev Oct 6, 2025
047b47c
Raname Routines to Routines (NumPy)
vlad-perevezentsev Oct 6, 2025
1b1f6c4
Apply remarks
vlad-perevezentsev Oct 6, 2025
49576c8
Merge master into scipy_submodule
vlad-perevezentsev Oct 6, 2025
79c5a9f
Remove dublicate code in __init__
vlad-perevezentsev Oct 6, 2025
ecf0367
Update Routines title in docs
vlad-perevezentsev Oct 6, 2025
bf4b145
Update changelog
vlad-perevezentsev Oct 6, 2025
9d008f3
Remove lu_factor and lu_solve from dpnp.linalg submodule
vlad-perevezentsev Oct 6, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ repos:
"--disable=redefined-builtin",
"--disable=unused-wildcard-import"
]
files: '^dpnp/(dpnp_iface.*|fft|linalg|special|dpnp_array)'
files: '^dpnp/(dpnp_iface.*|fft|linalg|scipy|dpnp_array)'
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
rev: v2.15.0
hooks:
Expand Down
14 changes: 14 additions & 0 deletions doc/reference/scipy.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.. currentmodule:: dpnp.scipy

Routines (SciPy) (:mod:`dpnp.scipy`)
=======================================

The following pages describe SciPy-compatible routines.
These functions cover a subset of
`SciPy routines <https://docs.scipy.org/doc/scipy/reference/#api-reference>`_.

.. toctree::
:maxdepth: 2

scipy_linalg
scipy_special
17 changes: 17 additions & 0 deletions doc/reference/scipy_linalg.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.. currentmodule:: dpnp.scipy.linalg

Linear algebra (:mod:`dpnp.scipy.linalg`)
=========================================

.. Hint:: `SciPy API Reference: Linear algebra (scipy.linalg) <https://docs.scipy.org/doc/scipy/reference/linalg.html>`_

Decompositions
--------------

.. autosummary::
:toctree: generated/
:nosignatures:

dpnp.scipy.linalg.lu
dpnp.scipy.linalg.lu_factor
dpnp.scipy.linalg.lu_solve
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.. currentmodule:: dpnp.special
.. currentmodule:: dpnp.scipy.special

Special functions (:mod:`dpnp.special`)
Special functions (:mod:`dpnp.scipy.special`)
=======================================

.. Hint:: `SciPy API Reference: Special functions (scipy.special) <https://docs.scipy.org/doc/scipy/reference/special.html>`_
Expand Down
3 changes: 3 additions & 0 deletions dpnp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import os
import sys
from importlib import import_module

mypath = os.path.dirname(os.path.realpath(__file__))

Expand Down Expand Up @@ -70,9 +71,11 @@
from .dpnp_iface_utils import *
from .dpnp_iface_utils import __all__ as _ifaceutils__all__
from ._version import get_versions
from . import scipy as scipy

__all__ = _iface__all__
__all__ += _ifaceutils__all__
__all__ += ["scipy"]


__version__ = get_versions()["version"]
Expand Down
1 change: 0 additions & 1 deletion dpnp/dpnp_iface.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
from dpnp.linalg import *
from dpnp.memory import *
from dpnp.random import *
from dpnp.special import *

__all__ = [
"are_same_logical_tensors",
Expand Down
147 changes: 0 additions & 147 deletions dpnp/linalg/dpnp_iface_linalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@
dpnp_eigh,
dpnp_inv,
dpnp_lstsq,
dpnp_lu_factor,
dpnp_lu_solve,
dpnp_matrix_power,
dpnp_matrix_rank,
dpnp_multi_dot,
Expand All @@ -81,8 +79,6 @@
"eigvalsh",
"inv",
"lstsq",
"lu_factor",
"lu_solve",
"matmul",
"matrix_norm",
"matrix_power",
Expand Down Expand Up @@ -905,149 +901,6 @@ def lstsq(a, b, rcond=None):
return dpnp_lstsq(a, b, rcond=rcond)


def lu_factor(a, overwrite_a=False, check_finite=True):
"""
Compute the pivoted LU decomposition of `a` matrix.

The decomposition is::

A = P @ L @ U

where `P` is a permutation matrix, `L` is lower triangular with unit
diagonal elements, and `U` is upper triangular.

For full documentation refer to :obj:`scipy.linalg.lu_factor`.

Parameters
----------
a : (..., M, N) {dpnp.ndarray, usm_ndarray}
Input array to decompose.
overwrite_a : {None, bool}, optional
Whether to overwrite data in `a` (may increase performance).

Default: ``False``.
check_finite : {None, bool}, optional
Whether to check that the input matrix contains only finite numbers.
Disabling may give a performance gain, but may result in problems
(crashes, non-termination) if the inputs do contain infinities or NaNs.

Default: ``True``.

Returns
-------
lu : (..., M, N) dpnp.ndarray
Matrix containing `U` in its upper triangle,
and `L` in its lower triangle.
The unit diagonal elements of `L` are not stored.
piv : (..., K) dpnp.ndarray
Pivot indices representing the permutation matrix `P`:
row i of matrix was interchanged with row piv[i].
Where ``K = min(M, N)``.

Warning
-------
This function synchronizes in order to validate array elements
when ``check_finite=True``.

See Also
--------
:obj:`dpnp.linalg.lu_solve` : Solve an equation system using
the LU factorization of `a` matrix.

Examples
--------
>>> import dpnp as np
>>> a = np.array([[4., 3.], [6., 3.]])
>>> lu, piv = np.linalg.lu_factor(a)
>>> lu
array([[6. , 3. ],
[0.66666667, 1. ]])
>>> piv
array([1, 1])

"""

dpnp.check_supported_arrays_type(a)
assert_stacked_2d(a)

return dpnp_lu_factor(a, overwrite_a=overwrite_a, check_finite=check_finite)


def lu_solve(lu_and_piv, b, trans=0, overwrite_b=False, check_finite=True):
"""
Solve a linear system, :math:`a x = b`, given the LU factorization of `a`.

For full documentation refer to :obj:`scipy.linalg.lu_solve`.

Parameters
----------
lu, piv : {tuple of dpnp.ndarrays or usm_ndarrays}
LU factorization of matrix `a` (M, M) together with pivot indices.
b : {(M,), (..., M, K)} {dpnp.ndarray, usm_ndarray}
Right-hand side
trans : {0, 1, 2} , optional
Type of system to solve:

===== =================
trans system
===== =================
0 :math:`a x = b`
1 :math:`a^T x = b`
2 :math:`a^H x = b`
===== =================

Default: ``0``.
overwrite_b : {None, bool}, optional
Whether to overwrite data in `b` (may increase performance).

Default: ``False``.
check_finite : {None, bool}, optional
Whether to check that the input matrix contains only finite numbers.
Disabling may give a performance gain, but may result in problems
(crashes, non-termination) if the inputs do contain infinities or NaNs.

Default: ``True``.

Returns
-------
x : {(M,), (M, K)} dpnp.ndarray
Solution to the system

Warning
-------
This function synchronizes in order to validate array elements
when ``check_finite=True``.

See Also
--------
:obj:`dpnp.linalg.lu_factor` : LU factorize a matrix.

Examples
--------
>>> import dpnp as np
>>> A = np.array([[2, 5, 8, 7], [5, 2, 2, 8], [7, 5, 6, 6], [5, 4, 4, 8]])
>>> b = np.array([1, 1, 1, 1])
>>> lu, piv = np.linalg.lu_factor(A)
>>> x = np.linalg.lu_solve((lu, piv), b)
>>> np.allclose(A @ x - b, np.zeros((4,)))
array(True)

"""

(lu, piv) = lu_and_piv
dpnp.check_supported_arrays_type(lu, piv, b)
assert_stacked_2d(lu)

return dpnp_lu_solve(
lu,
piv,
b,
trans=trans,
overwrite_b=overwrite_b,
check_finite=check_finite,
)


def matmul(x1, x2, /):
"""
Computes the matrix product.
Expand Down
Loading
Loading