Skip to content

Commit 386bd2f

Browse files
authored
Merge branch 'master' into mute_solve_test
2 parents e8258cf + e8f348b commit 386bd2f

File tree

9 files changed

+139
-48
lines changed

9 files changed

+139
-48
lines changed

.github/workflows/build-sphinx.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,11 @@ jobs:
7676
7777
- name: Install Intel OneAPI
7878
run: |
79-
sudo apt-get install intel-oneapi-mkl \
80-
intel-oneapi-mkl-devel \
81-
intel-oneapi-tbb-devel \
82-
intel-oneapi-libdpstd-devel \
83-
intel-oneapi-compiler-dpcpp-cpp
79+
sudo apt-get install intel-oneapi-mkl-2024.2* \
80+
intel-oneapi-mkl-devel-2024.2* \
81+
intel-oneapi-tbb-devel-2021.13* \
82+
intel-oneapi-libdpstd-devel-2022.6* \
83+
intel-oneapi-compiler-dpcpp-cpp-2024.2*
8484
8585
# required by sphinxcontrib-spelling extension
8686
- name: Install enchant package
@@ -96,7 +96,7 @@ jobs:
9696
sudo apt-get install -y nvidia-cuda-toolkit clinfo
9797
9898
- name: Checkout repo
99-
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
99+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
100100
with:
101101
fetch-depth: 0
102102

@@ -237,7 +237,7 @@ jobs:
237237
runs-on: ubuntu-latest
238238

239239
steps:
240-
- uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
240+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
241241
with:
242242
fetch-depth: 0
243243

.github/workflows/conda-package.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ jobs:
9797
access_token: ${{ github.token }}
9898

9999
- name: Checkout DPNP repo
100-
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
100+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
101101
with:
102102
fetch-depth: 0
103103

@@ -131,7 +131,7 @@ jobs:
131131
run: mamba install conda-build=${{ env.CONDA_BUILD_VERSION}}
132132

133133
- name: Cache conda packages
134-
uses: actions/cache@3624ceb22c1c5a301c8db4169662070a689d9ea8 # v4.1.1
134+
uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4.1.2
135135
env:
136136
CACHE_NUMBER: 1 # Increase to reset cache
137137
with:
@@ -144,6 +144,8 @@ jobs:
144144
145145
- name: Build conda package
146146
run: conda build --no-test --python ${{ matrix.python }} --numpy 2.0 ${{ env.CHANNELS }} conda-recipe
147+
env:
148+
MAX_BUILD_CMPL_MKL_VERSION: '2024.3a0'
147149

148150
- name: Upload artifact
149151
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
@@ -231,7 +233,7 @@ jobs:
231233
TEST_CHANNELS: '-c ${{ env.channel-path }} ${{ env.CHANNELS }}'
232234

233235
- name: Cache conda packages
234-
uses: actions/cache@3624ceb22c1c5a301c8db4169662070a689d9ea8 # v4.1.1
236+
uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4.1.2
235237
env:
236238
CACHE_NUMBER: 1 # Increase to reset cache
237239
with:
@@ -375,7 +377,7 @@ jobs:
375377
run: more lockfile
376378

377379
- name: Cache conda packages
378-
uses: actions/cache@3624ceb22c1c5a301c8db4169662070a689d9ea8 # v4.1.1
380+
uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4.1.2
379381
env:
380382
CACHE_NUMBER: 1 # Increase to reset cache
381383
with:
@@ -516,7 +518,7 @@ jobs:
516518
run: mamba install anaconda-client
517519

518520
- name: Checkout repo
519-
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
521+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
520522
with:
521523
repository: IntelPython/devops-tools
522524
fetch-depth: 0

.github/workflows/generate_coverage.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
access_token: ${{ github.token }}
3434

3535
- name: Checkout repo
36-
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
36+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
3737
with:
3838
fetch-depth: 0
3939

@@ -49,11 +49,11 @@ jobs:
4949
- name: Install latest Intel OneAPI
5050
if: env.INSTALL_ONE_API == 'yes'
5151
run: |
52-
sudo apt-get install intel-oneapi-mkl \
53-
intel-oneapi-mkl-devel \
54-
intel-oneapi-tbb-devel \
55-
intel-oneapi-libdpstd-devel \
56-
intel-oneapi-compiler-dpcpp-cpp
52+
sudo apt-get install intel-oneapi-mkl-2024.2* \
53+
intel-oneapi-mkl-devel-2024.2* \
54+
intel-oneapi-tbb-devel-2021.13* \
55+
intel-oneapi-libdpstd-devel-2022.6* \
56+
intel-oneapi-compiler-dpcpp-cpp-2024.2*
5757
5858
- name: Install Lcov
5959
run: |

.github/workflows/openssf-scorecard.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333

3434
steps:
3535
- name: "Checkout code"
36-
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
36+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
3737
with:
3838
persist-credentials: false
3939

@@ -68,6 +68,6 @@ jobs:
6868

6969
# Upload the results to GitHub's code scanning dashboard.
7070
- name: "Upload to code-scanning"
71-
uses: github/codeql-action/upload-sarif@f779452ac5af1c261dce0346a8f964149f49322b # v3.26.13
71+
uses: github/codeql-action/upload-sarif@662472033e021d55d94146f66f6058822b0b39fd # v3.27.0
7272
with:
7373
sarif_file: results.sarif

.github/workflows/pre-commit.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ jobs:
2626
pylint
2727
2828
- name: Checkout DPNP repo
29-
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
29+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
3030

3131
- name: Set up python
32-
uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3 # v5.2.0
32+
uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0
3333
with:
3434
python-version: '3.12'
3535

conda-recipe/meta.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
{% set max_compiler_and_mkl_version = environ.get("MAX_BUILD_CMPL_MKL_VERSION", "2026.0a0") %}
12
{% set required_compiler_and_mkl_version = "2024.2" %}
2-
{% set required_dpctl_version = "0.18.0*" %}
3+
{% set required_dpctl_version = "0.18.1" %}
34

45
package:
56
name: dpnp
@@ -17,14 +18,14 @@ requirements:
1718
- ninja
1819
- git
1920
- dpctl >={{ required_dpctl_version }}
20-
- mkl-devel-dpcpp >={{ required_compiler_and_mkl_version }}
21+
- mkl-devel-dpcpp >={{ required_compiler_and_mkl_version }},<{{ max_compiler_and_mkl_version }}
2122
- onedpl-devel
2223
- tbb-devel
2324
- wheel
2425
- scikit-build
2526
build:
2627
- {{ compiler('cxx') }}
27-
- {{ compiler('dpcpp') }} >={{ required_compiler_and_mkl_version }}
28+
- {{ compiler('dpcpp') }} >={{ required_compiler_and_mkl_version }},<{{ max_compiler_and_mkl_version }}
2829
- sysroot_linux-64 >=2.28 # [linux]
2930
run:
3031
- python

dpnp/linalg/dpnp_iface_linalg.py

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
]
100100

101101

102-
def cholesky(a, upper=False):
102+
def cholesky(a, /, *, upper=False):
103103
"""
104104
Cholesky decomposition.
105105
@@ -1062,7 +1062,7 @@ def matrix_power(a, n):
10621062
return dpnp_matrix_power(a, n)
10631063

10641064

1065-
def matrix_rank(A, tol=None, hermitian=False):
1065+
def matrix_rank(A, tol=None, hermitian=False, *, rtol=None):
10661066
"""
10671067
Return matrix rank of array using SVD method.
10681068
@@ -1073,21 +1073,27 @@ def matrix_rank(A, tol=None, hermitian=False):
10731073
----------
10741074
A : {(M,), (..., M, N)} {dpnp.ndarray, usm_ndarray}
10751075
Input vector or stack of matrices.
1076-
tol : (...) {float, dpnp.ndarray, usm_ndarray}, optional
1077-
Threshold below which SVD values are considered zero. If `tol` is
1078-
``None``, and ``S`` is an array with singular values for `M`, and
1079-
``eps`` is the epsilon value for datatype of ``S``, then `tol` is
1080-
set to ``S.max() * max(M.shape) * eps``.
1076+
tol : (...) {None, float, dpnp.ndarray, usm_ndarray}, optional
1077+
Threshold below which SVD values are considered zero. Only `tol` or
1078+
`rtol` can be set at a time. If none of them are provided, defaults
1079+
to ``S.max() * max(M, N) * eps`` where `S` is an array with singular
1080+
values for `A`, and `eps` is the epsilon value for datatype of `S`.
10811081
Default: ``None``.
10821082
hermitian : bool, optional
10831083
If ``True``, `A` is assumed to be Hermitian (symmetric if real-valued),
10841084
enabling a more efficient method for finding singular values.
10851085
Default: ``False``.
1086+
rtol : (...) {None, float, dpnp.ndarray, usm_ndarray}, optional
1087+
Parameter for the relative tolerance component. Only `tol` or `rtol`
1088+
can be set at a time. If none of them are provided, defaults to
1089+
``max(M, N) * eps`` where `eps` is the epsilon value for datatype
1090+
of `S` (an array with singular values for `A`).
1091+
Default: ``None``.
10861092
10871093
Returns
10881094
-------
10891095
rank : (...) dpnp.ndarray
1090-
Rank of A.
1096+
Rank of `A`.
10911097
10921098
See Also
10931099
--------
@@ -1114,8 +1120,12 @@ def matrix_rank(A, tol=None, hermitian=False):
11141120
dpnp.check_supported_arrays_type(
11151121
tol, scalar_type=True, all_scalars=True
11161122
)
1123+
if rtol is not None:
1124+
dpnp.check_supported_arrays_type(
1125+
rtol, scalar_type=True, all_scalars=True
1126+
)
11171127

1118-
return dpnp_matrix_rank(A, tol=tol, hermitian=hermitian)
1128+
return dpnp_matrix_rank(A, tol=tol, hermitian=hermitian, rtol=rtol)
11191129

11201130

11211131
def matrix_transpose(x, /):
@@ -1456,7 +1466,7 @@ def outer(x1, x2, /):
14561466
return dpnp.outer(x1, x2)
14571467

14581468

1459-
def pinv(a, rcond=1e-15, hermitian=False):
1469+
def pinv(a, rcond=None, hermitian=False, *, rtol=None):
14601470
"""
14611471
Compute the (Moore-Penrose) pseudo-inverse of a matrix.
14621472
@@ -1469,20 +1479,27 @@ def pinv(a, rcond=1e-15, hermitian=False):
14691479
----------
14701480
a : (..., M, N) {dpnp.ndarray, usm_ndarray}
14711481
Matrix or stack of matrices to be pseudo-inverted.
1472-
rcond : {float, dpnp.ndarray, usm_ndarray}, optional
1482+
rcond : (...) {None, float, dpnp.ndarray, usm_ndarray}, optional
14731483
Cutoff for small singular values.
14741484
Singular values less than or equal to ``rcond * largest_singular_value``
14751485
are set to zero. Broadcasts against the stack of matrices.
1476-
Default: ``1e-15``.
1486+
Only `rcond` or `rtol` can be set at a time. If none of them are
1487+
provided, defaults to ``max(M, N) * dpnp.finfo(a.dtype).eps``.
1488+
Default: ``None``.
14771489
hermitian : bool, optional
14781490
If ``True``, a is assumed to be Hermitian (symmetric if real-valued),
14791491
enabling a more efficient method for finding singular values.
14801492
Default: ``False``.
1493+
rtol : (...) {None, float, dpnp.ndarray, usm_ndarray}, optional
1494+
Same as `rcond`, but it's an Array API compatible parameter name.
1495+
Only `rcond` or `rtol` can be set at a time. If none of them are
1496+
provided, defaults to ``max(M, N) * dpnp.finfo(a.dtype).eps``.
1497+
Default: ``None``.
14811498
14821499
Returns
14831500
-------
14841501
out : (..., N, M) dpnp.ndarray
1485-
The pseudo-inverse of a.
1502+
The pseudo-inverse of `a`.
14861503
14871504
Examples
14881505
--------
@@ -1493,17 +1510,24 @@ def pinv(a, rcond=1e-15, hermitian=False):
14931510
>>> a = np.random.randn(9, 6)
14941511
>>> B = np.linalg.pinv(a)
14951512
>>> np.allclose(a, np.dot(a, np.dot(B, a)))
1496-
array([ True])
1513+
array(True)
14971514
>>> np.allclose(B, np.dot(B, np.dot(a, B)))
1498-
array([ True])
1515+
array(True)
14991516
15001517
"""
15011518

15021519
dpnp.check_supported_arrays_type(a)
1503-
dpnp.check_supported_arrays_type(rcond, scalar_type=True, all_scalars=True)
1520+
if rcond is not None:
1521+
dpnp.check_supported_arrays_type(
1522+
rcond, scalar_type=True, all_scalars=True
1523+
)
1524+
if rtol is not None:
1525+
dpnp.check_supported_arrays_type(
1526+
rtol, scalar_type=True, all_scalars=True
1527+
)
15041528
assert_stacked_2d(a)
15051529

1506-
return dpnp_pinv(a, rcond=rcond, hermitian=hermitian)
1530+
return dpnp_pinv(a, rcond=rcond, hermitian=hermitian, rtol=rtol)
15071531

15081532

15091533
def qr(a, mode="reduced"):

dpnp/linalg/dpnp_utils_linalg.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2214,24 +2214,33 @@ def dpnp_matrix_power(a, n):
22142214
return result
22152215

22162216

2217-
def dpnp_matrix_rank(A, tol=None, hermitian=False):
2217+
def dpnp_matrix_rank(A, tol=None, hermitian=False, rtol=None):
22182218
"""
2219-
dpnp_matrix_rank(A, tol=None, hermitian=False)
2219+
dpnp_matrix_rank(A, tol=None, hermitian=False, rtol=None)
22202220
22212221
Return matrix rank of array using SVD method.
22222222
22232223
"""
22242224

2225+
if rtol is not None and tol is not None:
2226+
raise ValueError("`tol` and `rtol` can't be both set.")
2227+
22252228
if A.ndim < 2:
22262229
return (A != 0).any().astype(int)
22272230

22282231
S = dpnp_svd(A, compute_uv=False, hermitian=hermitian)
22292232

22302233
if tol is None:
2231-
rtol = max(A.shape[-2:]) * dpnp.finfo(S.dtype).eps
2234+
if rtol is None:
2235+
rtol = max(A.shape[-2:]) * dpnp.finfo(S.dtype).eps
2236+
elif not dpnp.isscalar(rtol):
2237+
# Add a new axis to make it broadcastable against S
2238+
# needed for S > tol comparison below
2239+
rtol = rtol[..., None]
22322240
tol = S.max(axis=-1, keepdims=True) * rtol
22332241
elif not dpnp.isscalar(tol):
2234-
# Add a new axis to match NumPy's output
2242+
# Add a new axis to make it broadcastable against S,
2243+
# needed for S > tol comparison below
22352244
tol = tol[..., None]
22362245

22372246
return dpnp.count_nonzero(S > tol, axis=-1)
@@ -2320,9 +2329,9 @@ def dpnp_norm(x, ord=None, axis=None, keepdims=False):
23202329
raise ValueError("Improper number of dimensions to norm.")
23212330

23222331

2323-
def dpnp_pinv(a, rcond=1e-15, hermitian=False):
2332+
def dpnp_pinv(a, rcond=None, hermitian=False, rtol=None):
23242333
"""
2325-
dpnp_pinv(a, rcond=1e-15, hermitian=False):
2334+
dpnp_pinv(a, rcond=None, hermitian=False, rtol=None)
23262335
23272336
Compute the Moore-Penrose pseudoinverse of `a` matrix.
23282337
@@ -2331,6 +2340,15 @@ def dpnp_pinv(a, rcond=1e-15, hermitian=False):
23312340
23322341
"""
23332342

2343+
if rcond is None:
2344+
if rtol is None:
2345+
dtype = dpnp.result_type(a.dtype, dpnp.default_float_type(a.device))
2346+
rcond = max(a.shape[-2:]) * dpnp.finfo(dtype).eps
2347+
else:
2348+
rcond = rtol
2349+
elif rtol is not None:
2350+
raise ValueError("`rtol` and `rcond` can't be both set.")
2351+
23342352
if _is_empty_2d(a):
23352353
m, n = a.shape[-2:]
23362354
sh = a.shape[:-2] + (n, m)

0 commit comments

Comments
 (0)