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

Skip to content

Commit 7f9549b

Browse files
mtsokolngoldbaum
andcommitted
API: Add a batch of Array API aliases
Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com> Co-authored-by: Nathan Goldbaum <nathan.goldbaum@gmail.com>
1 parent 35b14fe commit 7f9549b

File tree

9 files changed

+99
-76
lines changed

9 files changed

+99
-76
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 improve compatibility with the Array API standard:
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/array_api.rst

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -71,54 +71,10 @@ The following functions are named differently in the array API
7171
* - Array API name
7272
- NumPy namespace name
7373
- Notes
74-
* - ``acos``
75-
- ``arccos``
76-
-
77-
* - ``acosh``
78-
- ``arccosh``
79-
-
80-
* - ``asin``
81-
- ``arcsin``
82-
-
83-
* - ``asinh``
84-
- ``arcsinh``
85-
-
86-
* - ``atan``
87-
- ``arctan``
88-
-
89-
* - ``atan2``
90-
- ``arctan2``
91-
-
92-
* - ``atanh``
93-
- ``arctanh``
94-
-
95-
* - ``bitwise_left_shift``
96-
- ``left_shift``
97-
-
98-
* - ``bitwise_invert``
99-
- ``invert``
100-
-
101-
* - ``bitwise_right_shift``
102-
- ``right_shift``
103-
-
104-
* - ``bool``
105-
- ``bool_``
106-
- This is **breaking** because ``np.bool`` is currently a deprecated
107-
alias for the built-in ``bool``.
108-
* - ``concat``
109-
- ``concatenate``
110-
-
11174
* - ``matrix_norm`` and ``vector_norm``
11275
- ``norm``
11376
- ``matrix_norm`` and ``vector_norm`` each do a limited subset of what
11477
``np.norm`` does.
115-
* - ``permute_dims``
116-
- ``transpose``
117-
- Unlike ``np.transpose``, the ``axis`` keyword-argument to
118-
``permute_dims`` is required.
119-
* - ``pow``
120-
- ``power``
121-
-
12278

12379

12480
``linalg`` Namespace Differences

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+
permute_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: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -121,24 +121,25 @@
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-
astype, atleast_1d, atleast_2d, atleast_3d, base_repr, binary_repr,
130-
bitwise_and, bitwise_count, bitwise_not, bitwise_or, bitwise_xor,
131-
block, bool, bool_, broadcast, busday_count, busday_offset,
132-
busdaycalendar, byte, bytes_, can_cast, cbrt, cdouble, ceil,
133-
character, choose, clip, clongdouble, complex128, complex64,
134-
complexfloating, compress, concatenate, conj, conjugate, convolve,
135-
copysign, copyto, correlate, cos, cosh, count_nonzero, cross, csingle,
136-
cumprod, cumproduct, cumsum, datetime64, datetime_as_string,
137-
datetime_data, deg2rad, degrees, diagonal, divide, divmod, dot,
138-
double, dtype, e, einsum, einsum_path, empty, empty_like, equal,
139-
errstate, euler_gamma, exp, exp2, expm1, fabs, finfo, flatiter,
140-
flatnonzero, flexible, float16, float32, float64, float_power,
141-
floating, floor, floor_divide, fmax, fmin, fmod,
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, astype, 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, bool_,
133+
broadcast, busday_count, busday_offset, busdaycalendar, byte, bytes_,
134+
can_cast, cbrt, cdouble, ceil, character, choose, clip, clongdouble,
135+
complex128, complex64, complexfloating, compress, concat, concatenate,
136+
conj, conjugate, convolve, copysign, copyto, correlate, cos, cosh,
137+
count_nonzero, cross, csingle, cumprod, cumproduct, cumsum,
138+
datetime64, datetime_as_string, datetime_data, deg2rad, degrees,
139+
diagonal, divide, divmod, dot, double, dtype, e, einsum, einsum_path,
140+
empty, empty_like, equal, errstate, euler_gamma, exp, exp2, expm1,
141+
fabs, finfo, flatiter, flatnonzero, flexible, float16, float32,
142+
float64, float_power, floating, floor, floor_divide, fmax, fmin, fmod,
142143
format_float_positional, format_float_scientific, frexp, from_dlpack,
143144
frombuffer, fromfile, fromfunction, fromiter, frompyfunc, fromstring,
144145
full, full_like, gcd, generic, geomspace, get_printoptions,
@@ -153,18 +154,18 @@
153154
may_share_memory, mean, memmap, min, min_scalar_type, minimum, mod,
154155
modf, moveaxis, multiply, nan, ndarray, ndim, nditer, negative,
155156
nested_iters, newaxis, nextafter, nonzero, not_equal, number, object_,
156-
ones, ones_like, outer, partition, pi, positive, power, printoptions,
157-
prod, product, promote_types, ptp, put, putmask, rad2deg, radians,
158-
ravel, recarray, reciprocal, record, remainder, repeat, require,
159-
reshape, resize, result_type, right_shift, rint, roll, rollaxis,
160-
round, sctypeDict, searchsorted, set_printoptions, setbufsize, seterr,
161-
seterrcall, shape, shares_memory, short, sign, signbit, signedinteger,
162-
sin, single, sinh, size, sometrue, sort, spacing, sqrt, square,
163-
squeeze, stack, std, str_, subtract, sum, swapaxes, take, tan, tanh,
164-
tensordot, timedelta64, trace, transpose, true_divide, trunc,
165-
typecodes, ubyte, ufunc, uint, uint16, uint32, uint64, uint8, uintc,
166-
uintp, ulong, ulonglong, unsignedinteger, ushort, var, vdot, void,
167-
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
168169
)
169170

170171
# 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
@@ -3248,6 +3248,19 @@ true_divide: _UFunc_Nin2_Nout1[L['true_divide'], L[11], None]
32483248
trunc: _UFunc_Nin1_Nout1[L['trunc'], L[7], None]
32493249

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

32523265
class _CopyMode(enum.Enum):
32533266
ALWAYS: L[True]

numpy/_core/__init__.py

Lines changed: 19 additions & 1 deletion
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
@@ -613,10 +613,22 @@ def test_functions_single_location():
613613
if (
614614
member.__name__ in [
615615
"absolute", # np.abs
616+
"arccos", # np.acos
617+
"arccosh", # np.acosh
618+
"arcsin", # np.asin
619+
"arcsinh", # np.asinh
620+
"arctan", # np.atan
621+
"arctan2", # np.atan2
622+
"arctanh", # np.atanh
623+
"left_shift", # np.bitwise_left_shift
624+
"right_shift", # np.bitwise_right_shift
616625
"conjugate", # np.conj
617-
"invert", # np.bitwise_not
626+
"invert", # np.bitwise_not & np.bitwise_invert
618627
"remainder", # np.mod
619628
"divide", # np.true_divide
629+
"concatenate", # np.concat
630+
"power", # np.pow
631+
"transpose", # np.permute_dims
620632
] and
621633
module.__name__ == "numpy"
622634
):

0 commit comments

Comments
 (0)
0