-
Notifications
You must be signed in to change notification settings - Fork 52
Description
I always wonder how to design a vectorizable function when the sizes of the input and output arrays are different.
In other words, I am always unsure whether to shift the “core dimension” to the back
def polar_coordinates(r, theta):
xp = array_api_compat(r, theta)
return xp.stack([r * xp.cos(theta), r * xp.sin(theta)], axis=-1)
or to the front
def polar_coordinates(r, theta):
xp = array_api_compat(r, theta)
return xp.stack([r * xp.cos(theta), r * xp.sin(theta)], axis=0)
Is there any plans to add recommendations for this to array API? For reference
-
Numpy's gufunc puts "core dimension" to the back https://numpy.org/doc/stable/reference/c-api/generalized-ufuncs.html
-
Recently added
scipy.special.sph_harm_y_all
puts "core dimension" to the front https://docs.scipy.org/doc/scipy/reference/generated/scipy.special.sph_harm_y_all.html -
Since
broadcasting
adjusts shapes to the back, by putting "core dimension" to the back one can more easily interact with newly added feature (dimension), and vice versa. -
In terms of calculation speed, this should be related to C-style and Fortran-style indexing.