Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: add support for creating a new array by tiling a provided array #655

Closed
kgryte opened this issue Jul 13, 2023 · 3 comments · Fixed by #692
Closed

RFC: add support for creating a new array by tiling a provided array #655

kgryte opened this issue Jul 13, 2023 · 3 comments · Fixed by #692
Labels
API extension Adds new functions or objects to the API. topic: Manipulation Array manipulation and transformation.
Milestone

Comments

@kgryte
Copy link
Contributor

kgryte commented Jul 13, 2023

This RFC proposes adding support to the array API specification for creating a new array by tiling a provided array.

Overview

Based on array comparison data, the API is available in all array libraries.

Prior art

Proposal

def tile(x: array, repetitions: Union[int, Tuple[int, ...]], /)
  • repetitions: the number of repetitions of x along each axis. Let N = len(repetitions) and let M = len(x.shape).

    • if M < N, then x must be broadcasted to be N dimensional by prepending new axes.
    • if M > N, then repetitions must be broadcasted by prepending new axes.

Questions

  • Neither PyTorch nor TensorFlow support providing an int for repetitions. TensorFlow requires repetitions to be a Tensor. All array libraries apart from TensorFlow allow repetitions to be a tuple. Should repetitions be typed more strictly?

Related

@kgryte kgryte added API extension Adds new functions or objects to the API. topic: Manipulation Array manipulation and transformation. labels Jul 13, 2023
@kgryte kgryte added this to the v2023 milestone Jul 13, 2023
@rgommers
Copy link
Member

  • Neither PyTorch nor TensorFlow support providing an int for repetitions. TensorFlow requires repetitions to be a Tensor. All array libraries apart from TensorFlow allow repetitions to be a tuple. Should repetitions be typed more strictly?

I'd support tuple-only. It can always be loosened in the future, and this function isn't used all that much hence it's not much of a burden to type (3,) instead of 3.

Should repetitions be positional-only perhaps? I noticed that NumPy uses reps rather than repetitions.

@kgryte
Copy link
Contributor Author

kgryte commented Jul 13, 2023

Should repetitions be positional-only perhaps? I noticed that NumPy uses reps rather than repetitions.

The current proposal has repetitions as positional-only. Hence, the reps/repetitions distinction should not matter.

The question then becomes should repetitions be positional or keyword? In which case, settling on a naming convention makes sense. For this, there is divergence in the ecosystem (e.g., PyTorch uses dims, TensorFlow uses multiples).

@kgryte
Copy link
Contributor Author

kgryte commented Jul 13, 2023

Regarding usage, according to usage data for common APIs, tile does seem to be used a fair amount (e.g., more than various element-wise, linalg, and other APIs already included in the specification).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API extension Adds new functions or objects to the API. topic: Manipulation Array manipulation and transformation.
Projects
Status: Stage 2
Development

Successfully merging a pull request may close this issue.

2 participants