Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ This release is compatible with NumPy 2.3.3.
* Added implementation of `dpnp.piecewise` [#2550](https://github.com/IntelPython/dpnp/pull/2550)
* Added implementation of `dpnp.linalg.lu_solve` for 2D inputs (SciPy-compatible) [#2575](https://github.com/IntelPython/dpnp/pull/2575)
* Added implementation of `dpnp.special.erfc` [#2588](https://github.com/IntelPython/dpnp/pull/2588)
* Added `dpnp.scipy` submodule to aggregate new SciPy-compatible functions from `linalg` and `special` namespaces [#2603](https://github.com/IntelPython/dpnp/pull/2603)

### Changed

Expand Down
5 changes: 2 additions & 3 deletions doc/reference/routines.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
--------
Routines
--------
Routines (NumPy)
================

The following pages describe NumPy-compatible routines.
These functions cover a subset of
Expand Down
12 changes: 12 additions & 0 deletions doc/reference/scipy.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
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:

lu
lu_factor
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: 2 additions & 1 deletion dpnp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,13 @@
from .dpnp_iface_utils import __all__ as _ifaceutils__all__
from ._version import get_versions
from . import linalg as linalg
from . import scipy as scipy

__all__ = _iface__all__
__all__ += _ifaceutils__all__

# add submodules
__all__ += ["linalg"]
__all__ += ["linalg", "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 @@ -54,7 +54,6 @@
from dpnp.fft import *
from dpnp.memory import *
from dpnp.random import *
from dpnp.special import *

__all__ = [
"are_same_logical_tensors",
Expand Down
2 changes: 2 additions & 0 deletions dpnp/dpnp_iface_arraycreation.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
"""


# pylint: disable=duplicate-code

import operator

import dpctl.tensor as dpt
Expand Down
2 changes: 2 additions & 0 deletions dpnp/dpnp_iface_manipulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
"""


# pylint: disable=duplicate-code

import math
import operator
import warnings
Expand Down
2 changes: 0 additions & 2 deletions dpnp/linalg/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@
eigvalsh,
inv,
lstsq,
lu_factor,
lu_solve,
matmul,
matrix_norm,
matrix_power,
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 @@ -58,8 +58,6 @@
dpnp_eigh,
dpnp_inv,
dpnp_lstsq,
dpnp_lu_factor,
dpnp_lu_solve,
dpnp_matrix_power,
dpnp_matrix_rank,
dpnp_multi_dot,
Expand All @@ -84,8 +82,6 @@
"eigvalsh",
"inv",
"lstsq",
"lu_factor",
"lu_solve",
"matmul",
"matrix_norm",
"matrix_power",
Expand Down Expand Up @@ -911,149 +907,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