Skip to content

Commit 2bcf7c0

Browse files
Add support for tiling an array to the specification
PR-URL: #692 Co-authored-by: Oleksandr Pavlyk <[email protected]>
1 parent 03886d6 commit 2bcf7c0

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

Diff for: spec/draft/API_specification/manipulation_functions.rst

+1
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@ Objects in API
2929
roll
3030
squeeze
3131
stack
32+
tile
3233
unstack

Diff for: src/array_api_stubs/_draft/manipulation_functions.py

+25
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"roll",
1111
"squeeze",
1212
"stack",
13+
"tile",
1314
"unstack",
1415
]
1516

@@ -257,6 +258,30 @@ def stack(arrays: Union[Tuple[array, ...], List[array]], /, *, axis: int = 0) ->
257258
"""
258259

259260

261+
def tile(x: array, repetitions: Tuple[int, ...], /):
262+
"""
263+
Constructs an array by tiling an input array.
264+
265+
Parameters
266+
----------
267+
x: array
268+
input array.
269+
repetitions: Tuple[int, ...]
270+
number of repetitions along each axis (dimension).
271+
272+
Let ``N = len(x.shape)`` and ``M = len(repetitions)``.
273+
274+
If ``N > M``, the function must prepend ones until all axes (dimensions) are specified (e.g., if ``x`` has shape ``(8,6,4,2)`` and ``repetitions`` is the tuple ``(3,3)``, then ``repetitions`` must be treated as ``(1,1,3,3)``).
275+
276+
If ``N < M``, the function must prepend singleton axes (dimensions) to ``x`` until ``x`` has as many axes (dimensions) as ``repetitions`` specifies (e.g., if ``x`` has shape ``(4,2)`` and ``repetitions`` is the tuple ``(3,3,3,3)``, then ``x`` must be treated as if it has shape ``(1,1,4,2)``).
277+
278+
Returns
279+
-------
280+
out: array
281+
a tiled output array. The returned array must have the same data type as ``x`` and must have a rank (i.e., number of dimensions) equal to ``max(N, M)``. If ``S`` is the shape of the tiled array after prepending singleton dimensions (if necessary) and ``r`` is the tuple of repetitions after prepending ones (if necessary), then the number of elements along each axis (dimension) must satisfy ``S[i]*r[i]``, where ``i`` refers to the ``i`` th axis (dimension).
282+
"""
283+
284+
260285
def unstack(x: array, /, *, axis: int = 0) -> Tuple[array, ...]:
261286
"""
262287
Splits an array in a sequence of arrays along the given axis.

0 commit comments

Comments
 (0)