Skip to content

Commit 06f7fc7

Browse files
authored
Merge branch 'master' into impl_histogram
2 parents b6312e3 + f6f660c commit 06f7fc7

15 files changed

+656
-318
lines changed

.github/workflows/build-sphinx.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,13 @@ jobs:
8686
sudo apt-get install -y nvidia-cuda-toolkit clinfo
8787
8888
- name: Checkout repo
89-
uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4.1.3
89+
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
9090
with:
9191
fetch-depth: 0
9292

9393
# https://github.com/marketplace/actions/setup-miniconda
9494
- name: Setup miniconda
95-
uses: conda-incubator/setup-miniconda@030178870c779d9e5e1b4e563269f3aa69b04081 # v3.0.3
95+
uses: conda-incubator/setup-miniconda@a4260408e20b96e80095f42ff7f1a15b27dd94ca # v3.0.4
9696
with:
9797
auto-update-conda: true
9898
python-version: ${{ env.python-ver }}
@@ -199,7 +199,7 @@ jobs:
199199
runs-on: ubuntu-20.04
200200

201201
steps:
202-
- uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4.1.3
202+
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
203203
with:
204204
fetch-depth: 0
205205

.github/workflows/conda-package.yml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,12 @@ jobs:
8484
access_token: ${{ github.token }}
8585

8686
- name: Checkout DPNP repo
87-
uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4.1.3
87+
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
8888
with:
8989
fetch-depth: 0
9090

9191
- name: Setup miniconda
92-
uses: conda-incubator/setup-miniconda@030178870c779d9e5e1b4e563269f3aa69b04081 # v3.0.3
92+
uses: conda-incubator/setup-miniconda@a4260408e20b96e80095f42ff7f1a15b27dd94ca # v3.0.4
9393
with:
9494
auto-update-conda: true
9595
python-version: ${{ matrix.python }}
@@ -125,7 +125,7 @@ jobs:
125125
run: conda build --no-test --python ${{ matrix.python }} --numpy 1.23 ${{ env.CHANNELS }} conda-recipe
126126

127127
- name: Upload artifact
128-
uses: actions/upload-artifact@1746f4ab65b179e0ea60a494b83293b640dd5bba # v4.3.2
128+
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3
129129
with:
130130
name: ${{ env.PACKAGE_NAME }} ${{ runner.os }} Python ${{ matrix.python }}
131131
path: ${{ env.CONDA_BLD }}${{ env.PACKAGE_NAME }}-*.tar.bz2
@@ -158,7 +158,7 @@ jobs:
158158

159159
steps:
160160
- name: Download artifact
161-
uses: actions/download-artifact@8caf195ad4b1dee92908e23f56eeb0696f1dd42d # v4.1.5
161+
uses: actions/download-artifact@65a9edc5881444af0b9093a5e628f2fe47ea3b2e # v4.1.7
162162
with:
163163
name: ${{ env.PACKAGE_NAME }} ${{ runner.os }} Python ${{ matrix.python }}
164164
path: ${{ env.pkg-path-in-channel }}
@@ -169,7 +169,7 @@ jobs:
169169
tar -xvf ${{ env.pkg-path-in-channel }}/${{ env.PACKAGE_NAME }}-*.tar.bz2 -C ${{ env.extracted-pkg-path }}
170170
171171
- name: Setup miniconda
172-
uses: conda-incubator/setup-miniconda@030178870c779d9e5e1b4e563269f3aa69b04081 # v3.0.3
172+
uses: conda-incubator/setup-miniconda@a4260408e20b96e80095f42ff7f1a15b27dd94ca # v3.0.4
173173
with:
174174
auto-update-conda: true
175175
python-version: ${{ matrix.python }}
@@ -273,7 +273,7 @@ jobs:
273273

274274
steps:
275275
- name: Download artifact
276-
uses: actions/download-artifact@8caf195ad4b1dee92908e23f56eeb0696f1dd42d # v4.1.5
276+
uses: actions/download-artifact@65a9edc5881444af0b9093a5e628f2fe47ea3b2e # v4.1.7
277277
with:
278278
name: ${{ env.PACKAGE_NAME }} ${{ runner.os }} Python ${{ matrix.python }}
279279
path: ${{ env.pkg-path-in-channel }}
@@ -293,7 +293,7 @@ jobs:
293293
dir ${{ env.extracted-pkg-path }}
294294
295295
- name: Setup miniconda
296-
uses: conda-incubator/setup-miniconda@030178870c779d9e5e1b4e563269f3aa69b04081 # v3.0.3
296+
uses: conda-incubator/setup-miniconda@a4260408e20b96e80095f42ff7f1a15b27dd94ca # v3.0.4
297297
with:
298298
auto-update-conda: true
299299
python-version: ${{ matrix.python }}
@@ -419,12 +419,12 @@ jobs:
419419
420420
steps:
421421
- name: Download artifact
422-
uses: actions/download-artifact@8caf195ad4b1dee92908e23f56eeb0696f1dd42d # v4.1.5
422+
uses: actions/download-artifact@65a9edc5881444af0b9093a5e628f2fe47ea3b2e # v4.1.7
423423
with:
424424
name: ${{ env.PACKAGE_NAME }} ${{ runner.os }} Python ${{ matrix.python }}
425425

426426
- name: Setup miniconda
427-
uses: conda-incubator/setup-miniconda@030178870c779d9e5e1b4e563269f3aa69b04081 # v3.0.3
427+
uses: conda-incubator/setup-miniconda@a4260408e20b96e80095f42ff7f1a15b27dd94ca # v3.0.4
428428
with:
429429
auto-update-conda: true
430430
python-version: ${{ matrix.python }}
@@ -447,7 +447,7 @@ jobs:
447447
run:
448448
shell: bash -el {0}
449449
steps:
450-
- uses: conda-incubator/setup-miniconda@030178870c779d9e5e1b4e563269f3aa69b04081 # v3.0.3
450+
- uses: conda-incubator/setup-miniconda@a4260408e20b96e80095f42ff7f1a15b27dd94ca # v3.0.4
451451
with:
452452
run-post: false
453453
channel-priority: "disabled"
@@ -458,7 +458,7 @@ jobs:
458458
run: conda install anaconda-client
459459

460460
- name: Checkout repo
461-
uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4.1.3
461+
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
462462
with:
463463
repository: IntelPython/devops-tools
464464
fetch-depth: 0

.github/workflows/generate_coverage.yaml

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

3434
- name: Checkout repo
35-
uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4.1.3
35+
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
3636
with:
3737
fetch-depth: 0
3838

@@ -57,7 +57,7 @@ jobs:
5757
sudo apt-get install lcov
5858
5959
- name: Setup miniconda
60-
uses: conda-incubator/setup-miniconda@030178870c779d9e5e1b4e563269f3aa69b04081 # v3.0.3
60+
uses: conda-incubator/setup-miniconda@a4260408e20b96e80095f42ff7f1a15b27dd94ca # v3.0.4
6161
with:
6262
auto-update-conda: true
6363
python-version: ${{ env.python-ver }}

.github/workflows/openssf-scorecard.yml

Lines changed: 3 additions & 3 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@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4.1.3
36+
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
3737
with:
3838
persist-credentials: false
3939

@@ -60,14 +60,14 @@ jobs:
6060
# Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF
6161
# format to the repository Actions tab.
6262
- name: "Upload artifact"
63-
uses: actions/upload-artifact@1746f4ab65b179e0ea60a494b83293b640dd5bba # v4.3.2
63+
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3
6464
with:
6565
name: SARIF file
6666
path: results.sarif
6767
retention-days: 14
6868

6969
# Upload the results to GitHub's code scanning dashboard.
7070
- name: "Upload to code-scanning"
71-
uses: github/codeql-action/upload-sarif@c7f9125735019aa87cfc361530512d50ea439c71 # v3.25.1
71+
uses: github/codeql-action/upload-sarif@d39d31e687223d841ef683f52467bd88e9b21c14 # v3.25.3
7272
with:
7373
sarif_file: results.sarif

.github/workflows/pre-commit.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
pylint
2727
2828
- name: Checkout DPNP repo
29-
uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4.1.3
29+
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
3030

3131
- name: Set up python
3232
uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # v5.1.0

dpnp/linalg/dpnp_iface_linalg.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,15 @@
4242
import dpnp
4343

4444
from .dpnp_utils_linalg import (
45+
check_2d,
4546
check_stacked_2d,
4647
check_stacked_square,
4748
dpnp_cholesky,
4849
dpnp_cond,
4950
dpnp_det,
5051
dpnp_eigh,
5152
dpnp_inv,
53+
dpnp_lstsq,
5254
dpnp_matrix_power,
5355
dpnp_matrix_rank,
5456
dpnp_multi_dot,
@@ -69,6 +71,7 @@
6971
"eigvals",
7072
"eigvalsh",
7173
"inv",
74+
"lstsq",
7275
"matrix_power",
7376
"matrix_rank",
7477
"multi_dot",
@@ -594,6 +597,79 @@ def inv(a):
594597
return dpnp_inv(a)
595598

596599

600+
def lstsq(a, b, rcond=None):
601+
"""
602+
Return the least-squares solution to a linear matrix equation.
603+
604+
For full documentation refer to :obj:`numpy.linalg.lstsq`.
605+
606+
Parameters
607+
----------
608+
a : (M, N) {dpnp.ndarray, usm_ndarray}
609+
"Coefficient" matrix.
610+
b : {(M,), (M, K)} {dpnp.ndarray, usm_ndarray}
611+
Ordinate or "dependent variable" values.
612+
If `b` is two-dimensional, the least-squares solution
613+
is calculated for each of the `K` columns of `b`.
614+
rcond : {int, float, None}, optional
615+
Cut-off ratio for small singular values of `a`.
616+
For the purposes of rank determination, singular values are treated
617+
as zero if they are smaller than `rcond` times the largest singular
618+
value of `a`.
619+
The default uses the machine precision times ``max(M, N)``. Passing
620+
``-1`` will use machine precision.
621+
622+
Returns
623+
-------
624+
x : {(N,), (N, K)} dpnp.ndarray
625+
Least-squares solution. If `b` is two-dimensional,
626+
the solutions are in the `K` columns of `x`.
627+
residuals : {(1,), (K,), (0,)} dpnp.ndarray
628+
Sums of squared residuals: Squared Euclidean 2-norm for each column in
629+
``b - a @ x``.
630+
If the rank of `a` is < N or M <= N, this is an empty array.
631+
If `b` is 1-dimensional, this is a (1,) shape array.
632+
Otherwise the shape is (K,).
633+
rank : int
634+
Rank of matrix `a`.
635+
s : (min(M, N),) dpnp.ndarray
636+
Singular values of `a`.
637+
638+
Examples
639+
--------
640+
Fit a line, ``y = mx + c``, through some noisy data-points:
641+
642+
>>> import dpnp as np
643+
>>> x = np.array([0, 1, 2, 3])
644+
>>> y = np.array([-1, 0.2, 0.9, 2.1])
645+
646+
By examining the coefficients, we see that the line should have a
647+
gradient of roughly 1 and cut the y-axis at, more or less, -1.
648+
649+
We can rewrite the line equation as ``y = Ap``, where ``A = [[x 1]]``
650+
and ``p = [[m], [c]]``. Now use `lstsq` to solve for `p`:
651+
652+
>>> A = np.vstack([x, np.ones(len(x))]).T
653+
>>> A
654+
array([[0., 1.],
655+
[1., 1.],
656+
[2., 1.],
657+
[3., 1.]])
658+
659+
>>> m, c = np.linalg.lstsq(A, y, rcond=None)[0]
660+
>>> m, c
661+
(array(1.), array(-0.95)) # may vary
662+
663+
"""
664+
665+
dpnp.check_supported_arrays_type(a, b)
666+
check_2d(a)
667+
if rcond is not None and not isinstance(rcond, (int, float)):
668+
raise TypeError("rcond must be integer, floating type, or None")
669+
670+
return dpnp_lstsq(a, b, rcond=rcond)
671+
672+
597673
def matrix_power(a, n):
598674
"""
599675
Raise a square matrix to the (integer) power `n`.

0 commit comments

Comments
 (0)