Skip to content

Commit 2514c93

Browse files
authored
Merge branch 'main' into add-cov-delegation
2 parents e5bd40a + 8928fa1 commit 2514c93

File tree

9 files changed

+115
-71
lines changed

9 files changed

+115
-71
lines changed

.all-contributorsrc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,16 @@
270270
"contributions": [
271271
"ideas"
272272
]
273+
},
274+
{
275+
"login": "Enderdead",
276+
"name": "Gauthier-Clerc François",
277+
"avatar_url": "https://avatars.githubusercontent.com/u/22777836?v=4",
278+
"profile": "https://github.com/Enderdead",
279+
"contributions": [
280+
"code",
281+
"test"
282+
]
273283
}
274284
]
275285
}

CONTRIBUTORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ This project exists thanks to the following contributors
4040
<td align="center" valign="top" width="14.28%"><a href="https://github.com/pearu"><img src="https://avatars.githubusercontent.com/u/402156?v=4?s=100" width="100px;" alt="Pearu Peterson"/><br /><sub><b>Pearu Peterson</b></sub></a><br /><a href="https://github.com/data-apis/array-api-extra/pulls?q=is%3Apr+reviewed-by%3Apearu" title="Reviewed Pull Requests">👀</a></td>
4141
<td align="center" valign="top" width="14.28%"><a href="https://paddyroddy.github.io/"><img src="https://avatars.githubusercontent.com/u/15052188?v=4?s=100" width="100px;" alt="Patrick J. Roddy"/><br /><sub><b>Patrick J. Roddy</b></sub></a><br /><a href="https://github.com/data-apis/array-api-extra/commits?author=paddyroddy" title="Code">💻</a> <a href="https://github.com/data-apis/array-api-extra/commits?author=paddyroddy" title="Documentation">📖</a> <a href="#example-paddyroddy" title="Examples">💡</a> <a href="https://github.com/data-apis/array-api-extra/commits?author=paddyroddy" title="Tests">⚠️</a></td>
4242
<td align="center" valign="top" width="14.28%"><a href="https://amacati.github.io/"><img src="https://avatars.githubusercontent.com/u/57562633?v=4?s=100" width="100px;" alt="Martin Schuck"/><br /><sub><b>Martin Schuck</b></sub></a><br /><a href="#ideas-amacati" title="Ideas, Planning, & Feedback">🤔</a></td>
43+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/Enderdead"><img src="https://avatars.githubusercontent.com/u/22777836?v=4?s=100" width="100px;" alt="Gauthier-Clerc François"/><br /><sub><b>Gauthier-Clerc François</b></sub></a><br /><a href="https://github.com/data-apis/array-api-extra/commits?author=Enderdead" title="Code">💻</a> <a href="https://github.com/data-apis/array-api-extra/commits?author=Enderdead" title="Tests">⚠️</a></td>
4344
</tr>
4445
</tbody>
4546
</table>

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ This project exists thanks to the following contributors
9595
<td align="center" valign="top" width="14.28%"><a href="https://github.com/pearu"><img src="https://avatars.githubusercontent.com/u/402156?v=4?s=100" width="100px;" alt="Pearu Peterson"/><br /><sub><b>Pearu Peterson</b></sub></a><br /><a href="https://github.com/data-apis/array-api-extra/pulls?q=is%3Apr+reviewed-by%3Apearu" title="Reviewed Pull Requests">👀</a></td>
9696
<td align="center" valign="top" width="14.28%"><a href="https://paddyroddy.github.io/"><img src="https://avatars.githubusercontent.com/u/15052188?v=4?s=100" width="100px;" alt="Patrick J. Roddy"/><br /><sub><b>Patrick J. Roddy</b></sub></a><br /><a href="https://github.com/data-apis/array-api-extra/commits?author=paddyroddy" title="Code">💻</a> <a href="https://github.com/data-apis/array-api-extra/commits?author=paddyroddy" title="Documentation">📖</a> <a href="#example-paddyroddy" title="Examples">💡</a> <a href="https://github.com/data-apis/array-api-extra/commits?author=paddyroddy" title="Tests">⚠️</a></td>
9797
<td align="center" valign="top" width="14.28%"><a href="https://amacati.github.io/"><img src="https://avatars.githubusercontent.com/u/57562633?v=4?s=100" width="100px;" alt="Martin Schuck"/><br /><sub><b>Martin Schuck</b></sub></a><br /><a href="#ideas-amacati" title="Ideas, Planning, & Feedback">🤔</a></td>
98+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/Enderdead"><img src="https://avatars.githubusercontent.com/u/22777836?v=4?s=100" width="100px;" alt="Gauthier-Clerc François"/><br /><sub><b>Gauthier-Clerc François</b></sub></a><br /><a href="https://github.com/data-apis/array-api-extra/commits?author=Enderdead" title="Code">💻</a> <a href="https://github.com/data-apis/array-api-extra/commits?author=Enderdead" title="Tests">⚠️</a></td>
9899
</tr>
99100
</tbody>
100101
</table>

pixi.lock

Lines changed: 34 additions & 33 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ hypothesis = ">=6.138.3"
6767
dask-core = ">=2025.9.1" # No distributed, tornado, etc.
6868
dprint = ">=0.50.0,<0.51"
6969
lefthook = ">=1.13.1,<2"
70-
ruff = ">=0.12.12,<0.13"
70+
ruff = ">=0.13.1,<0.14"
7171
typos = ">=1.36.3,<2"
7272
actionlint = ">=1.7.7,<2"
7373
blacken-docs = ">=1.20.0,<2"

src/array_api_extra/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Extra array functions built on top of the array API standard."""
22

33
from ._delegation import (
4+
atleast_nd,
45
cov,
56
expand_dims,
67
isclose,
@@ -12,7 +13,6 @@
1213
from ._lib._at import at
1314
from ._lib._funcs import (
1415
apply_where,
15-
atleast_nd,
1616
broadcast_shapes,
1717
create_diagonal,
1818
default_dtype,

src/array_api_extra/_delegation.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,55 @@ def expand_dims(
197197
return _funcs.expand_dims(a, axis=axis, xp=xp)
198198

199199

200+
def atleast_nd(x: Array, /, *, ndim: int, xp: ModuleType | None = None) -> Array:
201+
"""
202+
Recursively expand the dimension of an array to at least `ndim`.
203+
204+
Parameters
205+
----------
206+
x : array
207+
Input array.
208+
ndim : int
209+
The minimum number of dimensions for the result.
210+
xp : array_namespace, optional
211+
The standard-compatible namespace for `x`. Default: infer.
212+
213+
Returns
214+
-------
215+
array
216+
An array with ``res.ndim`` >= `ndim`.
217+
If ``x.ndim`` >= `ndim`, `x` is returned.
218+
If ``x.ndim`` < `ndim`, `x` is expanded by prepending new axes
219+
until ``res.ndim`` equals `ndim`.
220+
221+
Examples
222+
--------
223+
>>> import array_api_strict as xp
224+
>>> import array_api_extra as xpx
225+
>>> x = xp.asarray([1])
226+
>>> xpx.atleast_nd(x, ndim=3, xp=xp)
227+
Array([[[1]]], dtype=array_api_strict.int64)
228+
229+
>>> x = xp.asarray([[[1, 2],
230+
... [3, 4]]])
231+
>>> xpx.atleast_nd(x, ndim=1, xp=xp) is x
232+
True
233+
"""
234+
if xp is None:
235+
xp = array_namespace(x)
236+
237+
if 1 <= ndim <= 3 and (
238+
is_numpy_namespace(xp)
239+
or is_jax_namespace(xp)
240+
or is_dask_namespace(xp)
241+
or is_cupy_namespace(xp)
242+
or is_torch_namespace(xp)
243+
):
244+
return getattr(xp, f"atleast_{ndim}d")(x)
245+
246+
return _funcs.atleast_nd(x, ndim=ndim, xp=xp)
247+
248+
200249
def isclose(
201250
a: Array | complex,
202251
b: Array | complex,

src/array_api_extra/_lib/_funcs.py

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -175,42 +175,9 @@ def _apply_where( # numpydoc ignore=PR01,RT01
175175
return at(out, cond).set(temp1)
176176

177177

178-
def atleast_nd(x: Array, /, *, ndim: int, xp: ModuleType | None = None) -> Array:
179-
"""
180-
Recursively expand the dimension of an array to at least `ndim`.
181-
182-
Parameters
183-
----------
184-
x : array
185-
Input array.
186-
ndim : int
187-
The minimum number of dimensions for the result.
188-
xp : array_namespace, optional
189-
The standard-compatible namespace for `x`. Default: infer.
190-
191-
Returns
192-
-------
193-
array
194-
An array with ``res.ndim`` >= `ndim`.
195-
If ``x.ndim`` >= `ndim`, `x` is returned.
196-
If ``x.ndim`` < `ndim`, `x` is expanded by prepending new axes
197-
until ``res.ndim`` equals `ndim`.
198-
199-
Examples
200-
--------
201-
>>> import array_api_strict as xp
202-
>>> import array_api_extra as xpx
203-
>>> x = xp.asarray([1])
204-
>>> xpx.atleast_nd(x, ndim=3, xp=xp)
205-
Array([[[1]]], dtype=array_api_strict.int64)
206-
207-
>>> x = xp.asarray([[[1, 2],
208-
... [3, 4]]])
209-
>>> xpx.atleast_nd(x, ndim=1, xp=xp) is x
210-
True
211-
"""
212-
if xp is None:
213-
xp = array_namespace(x)
178+
def atleast_nd(x: Array, /, *, ndim: int, xp: ModuleType) -> Array:
179+
# numpydoc ignore=PR01,RT01
180+
"""See docstring in array_api_extra._delegation."""
214181

215182
if x.ndim < ndim:
216183
x = xp.expand_dims(x, axis=0)

0 commit comments

Comments
 (0)