8000 API: Add a batch of Array API aliases · numpy/numpy@4a1c7e5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4a1c7e5

Browse files
committed
API: Add a batch of Array API aliases
1 parent 29cbb1f commit 4a1c7e5

File tree

8 files changed

+94
-26
lines changed

8 files changed

+94
-26
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Array API compatible functions' aliases
2+
---------------------------------------
3+
4+
13 aliases for existing functions were added to comply with Array API:
5+
6+
* Trigonometry: ``acos``, ``acosh``, ``asin``, ``asinh``, ``atan``, ``atanh``, ``atan2``.
7+
8+
* Bitwise: ``bitwise_left_shift``, ``bitwise_invert``, ``bitwise_right_shift``.
9+
10+
* Misc: ``concat``, ``permute_dims``, ``pow``.

doc/source/reference/routines.array-manipulation.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Transpose-like operations
3232
swapaxes
3333
ndarray.T
3434
transpose
35+
premute_dims
3536

3637
Changing number of dimensions
3738
=============================
@@ -66,6 +67,7 @@ Joining arrays
6667
:toctree: generated/
6768

6869
concatenate
70+
concat
6971
stack
7072
block
7173
vstack

doc/source/reference/routines.bitwise.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@ Elementwise bit operations
1212
bitwise_or
1313
bitwise_xor
1414
invert
15+
bitwise_invert
1516
left_shift
17+
bitwise_left_shift
1618
right_shift
19+
bitwise_right_shift
1720

1821
Bit packing
1922
-----------

doc/source/reference/routines.math.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,14 @@ Trigonometric functions
1212
cos
1313
tan
1414
arcsin
15+
asin
1516
arccos
17+
acos
1618
arctan
19+
atan
1720
hypot
1821
arctan2
22+
atan2
1923
degrees
2024
radians
2125
unwrap
@@ -31,8 +35,11 @@ Hyperbolic functions
3135
cosh
3236
tanh
3337
arcsinh
38+
asinh
3439
arccosh
40+
acosh
3541
arctanh
42+
atanh
3643

3744
Rounding
3845
--------
@@ -120,6 +127,7 @@ Arithmetic operations
120127
multiply
121128
divide
122129
power
130+
pow
123131
subtract
124132
true_divide
125133
floor_divide

numpy/__init__.py

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -121,18 +121,20 @@
121121
from . import _core
122122
from ._core import (
123123
False_, ScalarType, True_, _get_promotion_state, _no_nep50_warning,
124-
_set_promotion_state, abs, absolute, add, all, allclose, alltrue,
125-
amax, amin, any, arange, arccos, arccosh, arcsin, arcsinh, arctan,
126-
arctan2, arctanh, argmax, argmin, argpartition, argsort, argwhere,
127-
around, array, array2string, array_equal, array_equiv, array_repr,
128-
array_str, asanyarray, asarray, ascontiguousarray, asfortranarray,
129-
atleast_1d, atleast_2d, atleast_3d, base_repr, binary_repr,
130-
bitwise_and, bitwise_count, bitwise_not, bitwise_or, bitwise_xor,
131-
block, bool_, broadcast, busday_count, busday_offset, busdaycalendar,
132-
byte, bytes_, can_cast, cbrt, cdouble, ceil, character, choose, clip,
133-
clongdouble, complex128, complex64, complexfloating, compress,
134-
concatenate, conj, conjugate, convolve, copysign, copyto, correlate,
135-
cos, cosh, count_nonzero, cross, csingle, cumprod, cumproduct, cumsum,
124+
_set_promotion_state, abs, absolute, acos, acosh, add, all, allclose,
125+
alltrue, amax, amin, any, arange, arccos, arccosh, arcsin, arcsinh,
126+
arctan, arctan2, arctanh, argmax, argmin, argpartition, argsort,
127+
argwhere, around, array, array2string, array_equal, array_equiv,
128+
array_repr, array_str, asanyarray, asarray, ascontiguousarray,
129+
asfortranarray, asin, asinh, atan, atanh, atan2, atleast_1d,
130+
atleast_2d, atleast_3d, base_repr, binary_repr, bitwise_and,
131+
bitwise_count, bitwise_invert, bitwise_left_shift, bitwise_not,
132+
bitwise_or, bitwise_right_shift, bitwise_xor, block, bool_, broadcast,
133+
busday_count, busday_offset, busdaycalendar, byte, bytes_, can_cast,
134+
cbrt, cdouble, ceil, character, choose, clip, clongdouble, complex128,
135+
complex64, complexfloating, compress, concat, concatenate, conj,
136+
conjugate, convolve, copysign, copyto, correlate, cos, cosh,
137+
count_nonzero, cross, csingle, cumprod, cumproduct, cumsum,
136138
datetime64, datetime_as_string, datetime_data, deg2rad, degrees,
137139
diagonal, divide, divmod, dot, double, dtype, e, einsum, einsum_path,
138140
empty, empty_like, equal, errstate, euler_gamma, exp, exp2, expm1,
@@ -152,18 +154,18 @@
152154
may_share_memory, mean, memmap, min, min_scalar_type, minimum, mod,
153155
modf, moveaxis, multiply, nan, ndarray, ndim, nditer, negative,
154156
nested_iters, newaxis, nextafter, nonzero, not_equal, number, object_,
155-
ones, ones_like, outer, partition, pi, positive, power, printoptions,
156-
prod, product, promote_types, ptp, put, putmask, rad2deg, radians,
157-
ravel, recarray, reciprocal, record, remainder, repeat, require,
158-
reshape, resize, result_type, right_shift, rint, roll, rollaxis,
159-
round, sctypeDict, searchsorted, set_printoptions, setbufsize, seterr,
160-
seterrcall, shape, shares_memory, short, sign, signbit, signedinteger,
161-
sin, single, sinh, size, sometrue, sort, spacing, sqrt, square,
162-
squeeze, stack, std, str_, subtract, sum, swapaxes, take, tan, tanh,
163-
tensordot, timedelta64, trace, transpose, true_divide, trunc,
164-
typecodes, ubyte, ufunc, uint, uint16, uint32, uint64, uint8, uintc,
165-
uintp, ulong, ulonglong, unsignedinteger, ushort, var, vdot, void,
166-
vstack, where, zeros, zeros_like
157+
ones, ones_like, outer, partition, permute_dims, pi, positive, pow,
158+
power, printoptions, prod, product, promote_types, ptp, put, putmask,
159+
rad2deg, radians, ravel, recarray, reciprocal, record, remainder,
160+
repeat, require, reshape, resize, result_type, right_shift, rint,
161+
roll, rollaxis, round, sctypeDict, searchsorted, set_printoptions,
162+
setbufsize, seterr, seterrcall, shape, shares_memory, short, sign,
163+
signbit, signedinteger, sin, single, sinh, size, sometrue, sort,
164+
spacing, sqrt, square, squeeze, stack, std, str_, subtract, sum,
165+
swapaxes, take, tan, tanh, tensordot, timedelta64, trace, transpose,
166+
true_divide, trunc, typecodes, ubyte, ufunc, uint, uint16, uint32,
167+
uint64, uint8, uintc, uintp, ulong, ulonglong, unsignedinteger,
168+
ushort, var, vdot, void, vstack, where, zeros, zeros_like
167169
)
168170

169171
# NOTE: It's still under discussion whether these aliases

numpy/__init__.pyi

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3246,6 +3246,19 @@ true_divide: _UFunc_Nin2_Nout1[L['true_divide'], L[11], None]
32463246
trunc: _UFunc_Nin1_Nout1[L['trunc'], L[7], None]
32473247

32483248
abs = absolute
3249+
acos = arccos
3250+
acosh = arccosh
3251+
asin = arcsin
3252+
asinh = arcsinh
3253+
atan = arctan
3254+
atanh = arctanh
3255+
atan2 = arctan2
3256+
concat = concatenate
3257+
bitwise_left_shift = left_shift
3258+
bitwise_invert = invert
3259+
bitwise_right_shift = right_shift
3260+
permute_dims = transpose
3261+
pow = power
32493262

32503263
class _CopyMode(enum.Enum):
32513264
ALWAYS: L[True]

numpy/_core/__init__.py

Lines changed: 19 additions & 1 deletion
< EED3 tr class="diff-line-row">
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,25 @@
101101
from . import _dtype
102102
from . import _methods
103103

104-
__all__ = ['memmap', 'sctypeDict', 'record', 'recarray', 'abs']
104+
acos = numeric.arccos
105+
acosh = numeric.arccosh
106+
asin = numeric.arcsin
107+
asinh = numeric.arcsinh
108+
atan = numeric.arctan
109+
atanh = numeric.arctanh
110+
atan2 = numeric.arctan2
111+
concat = numeric.concatenate
112+
bitwise_left_shift = numeric.left_shift
113+
bitwise_invert = numeric.invert
114+
bitwise_right_shift = numeric.right_shift
115+
permute_dims = numeric.transpose
116+
pow = numeric.power
117+
118+
__all__ = [
119+
"abs", "acos", "acosh", "asin", "asinh", "atan", "atanh", "atan2",
120+
"bitwise_invert", "bitwise_left_shift", "bitwise_right_shift", "concat",
121+
"pow", "permute_dims", "memmap", "sctypeDict", "record", "recarray"
122+
]
105123
__all__ += numeric.__all__
106124
__all__ += function_base.__all__
107125
__all__ += getlimits.__all__

numpy/tests/test_public_api.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,10 +605,22 @@ def test_functions_single_location():
605605
if (
606606
member.__name__ in [
607607
"absolute", # np.abs
608+
"arccos", # np.acos
609+
"arccosh", # np.acosh
610+
"arcsin", # np.asin
611+
"arcsinh", # np.asinh
612+
"arctan", # np.atan
613+
"arctan2", # np.atan2
614+
"arctanh", # np.atanh
615+
"left_shift", # np.bitwise_left_shift
616+
"right_shift", # np.bitwise_right_shift
608617
"conjugate", # np.conj
609-
"invert", # np.bitwise_not
618+
"invert", # np.bitwise_not & np.bitwise_invert
610619
"remainder", # np.mod
611620
"divide", # np.true_divide
621+
"concatenate", # np.concat
622+
"power", # np.pow
623+
"transpose", # np.premute_dims
612624
] and
613625
module.__name__ == "numpy"
614626
):

0 commit comments

Comments
 (0)
0