Skip to content

Commit b27a7ca

Browse files
authored
Clarify order of indices returned in dpnp.tril_indices and dpnp.triu_indices (#2586)
The PR updates docstrings to clarify the order of indices returned by the functions.
1 parent 66b9b3b commit b27a7ca

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4343
* Extended `dpnp.pad` to support `pad_width` keyword as a dictionary [#2535](https://github.com/IntelPython/dpnp/pull/2535)
4444
* Redesigned `dpnp.erf` function through pybind11 extension of OneMKL call or dedicated kernel in `ufunc` namespace [#2551](https://github.com/IntelPython/dpnp/pull/2551)
4545
* Improved performance of batched implementation of `dpnp.linalg.det` and `dpnp.linalg.slogdet` [#2572](https://github.com/IntelPython/dpnp/pull/2572)
46+
* Improved documentations of `dpnp.tril_indices` and `dpnp.triu_indices` to clarify the returned order of indices [#2586](https://github.com/IntelPython/dpnp/pull/2586)
4647

4748
### Deprecated
4849

dpnp/dpnp_iface_indexing.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2375,8 +2375,9 @@ def tril_indices(
23752375
Returns
23762376
-------
23772377
inds : tuple of dpnp.ndarray
2378-
The indices for the triangle. The returned tuple contains two arrays,
2379-
each with the indices along one dimension of the array.
2378+
The row and column indices, respectively. The row indices are sorted in
2379+
non-decreasing order, and the corresponding column indices are strictly
2380+
increasing for each row.
23802381
23812382
See Also
23822383
--------
@@ -2394,7 +2395,13 @@ def tril_indices(
23942395
23952396
>>> import dpnp as np
23962397
>>> il1 = np.tril_indices(4)
2397-
>>> il2 = np.tril_indices(4, 2)
2398+
>>> il1
2399+
(array([0, 1, 1, 2, 2, 2, 3, 3, 3, 3]),
2400+
array([0, 0, 1, 0, 1, 2, 0, 1, 2, 3]))
2401+
2402+
Note that row indices (first array) are non-decreasing, and the
2403+
corresponding column indices (second array) are strictly increasing for
2404+
each row.
23982405
23992406
Here is how they can be used with a sample array:
24002407
@@ -2421,6 +2428,7 @@ def tril_indices(
24212428
24222429
These cover almost the whole array (two diagonals right of the main one):
24232430
2431+
>>> il2 = np.tril_indices(4, 2)
24242432
>>> a[il2] = -10
24252433
>>> a
24262434
array([[-10, -10, -10, 3],
@@ -2584,9 +2592,9 @@ def triu_indices(
25842592
Returns
25852593
-------
25862594
inds : tuple of dpnp.ndarray
2587-
The indices for the triangle. The returned tuple contains two arrays,
2588-
each with the indices along one dimension of the array. Can be used
2589-
to slice a ndarray of shape(`n`, `n`).
2595+
The row and column indices, respectively. The row indices are sorted in
2596+
non-decreasing order, and the corresponding column indices are strictly
2597+
increasing for each row.
25902598
25912599
See Also
25922600
--------
@@ -2604,7 +2612,13 @@ def triu_indices(
26042612
26052613
>>> import dpnp as np
26062614
>>> iu1 = np.triu_indices(4)
2607-
>>> iu2 = np.triu_indices(4, 2)
2615+
>>> iu1
2616+
(array([0, 0, 0, 0, 1, 1, 1, 2, 2, 3]),
2617+
array([0, 1, 2, 3, 1, 2, 3, 2, 3, 3]))
2618+
2619+
Note that row indices (first array) are non-decreasing, and the
2620+
corresponding column indices (second array) are strictly increasing for
2621+
each row.
26082622
26092623
Here is how they can be used with a sample array:
26102624
@@ -2632,6 +2646,7 @@ def triu_indices(
26322646
These cover only a small part of the whole array (two diagonals right
26332647
of the main one):
26342648
2649+
>>> iu2 = np.triu_indices(4, 2)
26352650
>>> a[iu2] = -10
26362651
>>> a
26372652
array([[ -1, -1, -10, -10],

0 commit comments

Comments
 (0)