diff options
author | Aaron Meurer <asmeurer@gmail.com> | 2021-07-08 17:22:47 -0600 |
---|---|---|
committer | Aaron Meurer <asmeurer@gmail.com> | 2021-07-08 17:22:47 -0600 |
commit | aee3a56d4e150a55c590966c9cc2ae0e201fa936 (patch) | |
tree | cb2519e418f8e7b0ad850c5e8c094a801472d9ef /numpy/_array_api/_elementwise_functions.py | |
parent | fc1ff6fc3045482a72c359689ee7bfa7e3299985 (diff) | |
download | numpy-aee3a56d4e150a55c590966c9cc2ae0e201fa936.tar.gz |
Rename the array class in the array API namespace from ndarray to Array
The actual class name doesn't matter because it isn't part of the namespace
API (arrays should be constructed with the array creation functions like
asarray()). However, it is better to use a name that is different from the
existing NumPy array object to avoid ambiguity.
Diffstat (limited to 'numpy/_array_api/_elementwise_functions.py')
-rw-r--r-- | numpy/_array_api/_elementwise_functions.py | 164 |
1 files changed, 80 insertions, 84 deletions
diff --git a/numpy/_array_api/_elementwise_functions.py b/numpy/_array_api/_elementwise_functions.py index ae265181a..8dedc77fb 100644 --- a/numpy/_array_api/_elementwise_functions.py +++ b/numpy/_array_api/_elementwise_functions.py @@ -3,11 +3,7 @@ from __future__ import annotations from ._dtypes import (_boolean_dtypes, _floating_dtypes, _integer_dtypes, _integer_or_boolean_dtypes, _numeric_dtypes) -from ._array_object import ndarray - -from typing import TYPE_CHECKING -if TYPE_CHECKING: - from ._types import Array +from ._array_object import Array import numpy as np @@ -19,7 +15,7 @@ def abs(x: Array, /) -> Array: """ if x.dtype not in _numeric_dtypes: raise TypeError('Only numeric dtypes are allowed in abs') - return ndarray._new(np.abs(x._array)) + return Array._new(np.abs(x._array)) # Note: the function name is different here @np.errstate(all='ignore') @@ -31,7 +27,7 @@ def acos(x: Array, /) -> Array: """ if x.dtype not in _floating_dtypes: raise TypeError('Only floating-point dtypes are allowed in acos') - return ndarray._new(np.arccos(x._array)) + return Array._new(np.arccos(x._array)) # Note: the function name is different here @np.errstate(all='ignore') @@ -43,7 +39,7 @@ def acosh(x: Array, /) -> Array: """ if x.dtype not in _floating_dtypes: raise TypeError('Only floating-point dtypes are allowed in acosh') - return ndarray._new(np.arccosh(x._array)) + return Array._new(np.arccosh(x._array)) @np.errstate(all='ignore') def add(x1: Array, x2: Array, /) -> Array: @@ -54,8 +50,8 @@ def add(x1: Array, x2: Array, /) -> Array: """ if x1.dtype not in _numeric_dtypes or x2.dtype not in _numeric_dtypes: raise TypeError('Only numeric dtypes are allowed in add') - x1, x2 = ndarray._normalize_two_args(x1, x2) - return ndarray._new(np.add(x1._array, x2._array)) + x1, x2 = Array._normalize_two_args(x1, x2) + return Array._new(np.add(x1._array, x2._array)) # Note: the function name is different here @np.errstate(all='ignore') @@ -67,7 +63,7 @@ def asin(x: Array, /) -> Array: """ if x.dtype not in _floating_dtypes: raise TypeError('Only floating-point dtypes are allowed in asin') - return ndarray._new(np.arcsin(x._array)) + return Array._new(np.arcsin(x._array)) # Note: the function name is different here @np.errstate(all='ignore') @@ -79,7 +75,7 @@ def asinh(x: Array, /) -> Array: """ if x.dtype not in _floating_dtypes: raise TypeError('Only floating-point dtypes are allowed in asinh') - return ndarray._new(np.arcsinh(x._array)) + return Array._new(np.arcsinh(x._array)) # Note: the function name is different here def atan(x: Array, /) -> Array: @@ -90,7 +86,7 @@ def atan(x: Array, /) -> Array: """ if x.dtype not in _floating_dtypes: raise TypeError('Only floating-point dtypes are allowed in atan') - return ndarray._new(np.arctan(x._array)) + return Array._new(np.arctan(x._array)) # Note: the function name is different here def atan2(x1: Array, x2: Array, /) -> Array: @@ -101,8 +97,8 @@ def atan2(x1: Array, x2: Array, /) -> Array: """ if x1.dtype not in _floating_dtypes or x2.dtype not in _floating_dtypes: raise TypeError('Only floating-point dtypes are allowed in atan2') - x1, x2 = ndarray._normalize_two_args(x1, x2) - return ndarray._new(np.arctan2(x1._array, x2._array)) + x1, x2 = Array._normalize_two_args(x1, x2) + return Array._new(np.arctan2(x1._array, x2._array)) # Note: the function name is different here @np.errstate(all='ignore') @@ -114,7 +110,7 @@ def atanh(x: Array, /) -> Array: """ if x.dtype not in _floating_dtypes: raise TypeError('Only floating-point dtypes are allowed in atanh') - return ndarray._new(np.arctanh(x._array)) + return Array._new(np.arctanh(x._array)) def bitwise_and(x1: Array, x2: Array, /) -> Array: """ @@ -124,8 +120,8 @@ def bitwise_and(x1: Array, x2: Array, /) -> Array: """ if x1.dtype not in _integer_or_boolean_dtypes or x2.dtype not in _integer_or_boolean_dtypes: raise TypeError('Only integer_or_boolean dtypes are allowed in bitwise_and') - x1, x2 = ndarray._normalize_two_args(x1, x2) - return ndarray._new(np.bitwise_and(x1._array, x2._array)) + x1, x2 = Array._normalize_two_args(x1, x2) + return Array._new(np.bitwise_and(x1._array, x2._array)) # Note: the function name is different here def bitwise_left_shift(x1: Array, x2: Array, /) -> Array: @@ -136,14 +132,14 @@ def bitwise_left_shift(x1: Array, x2: Array, /) -> Array: """ if x1.dtype not in _integer_dtypes or x2.dtype not in _integer_dtypes: raise TypeError('Only integer dtypes are allowed in bitwise_left_shift') - x1, x2 = ndarray._normalize_two_args(x1, x2) + x1, x2 = Array._normalize_two_args(x1, x2) # Note: bitwise_left_shift is only defined for x2 nonnegative. if np.any(x2._array < 0): raise ValueError('bitwise_left_shift(x1, x2) is only defined for x2 >= 0') # Note: The spec requires the return dtype of bitwise_left_shift to be the # same as the first argument. np.left_shift() returns a type that is the # type promotion of the two input types. - return ndarray._new(np.left_shift(x1._array, x2._array).astype(x1.dtype)) + return Array._new(np.left_shift(x1._array, x2._array).astype(x1.dtype)) # Note: the function name is different here def bitwise_invert(x: Array, /) -> Array: @@ -154,7 +150,7 @@ def bitwise_invert(x: Array, /) -> Array: """ if x.dtype not in _integer_or_boolean_dtypes: raise TypeError('Only integer or boolean dtypes are allowed in bitwise_invert') - return ndarray._new(np.invert(x._array)) + return Array._new(np.invert(x._array)) def bitwise_or(x1: Array, x2: Array, /) -> Array: """ @@ -164,8 +160,8 @@ def bitwise_or(x1: Array, x2: Array, /) -> Array: """ if x1.dtype not in _integer_or_boolean_dtypes or x2.dtype not in _integer_or_boolean_dtypes: raise TypeError('Only integer or boolean dtypes are allowed in bitwise_or') - x1, x2 = ndarray._normalize_two_args(x1, x2) - return ndarray._new(np.bitwise_or(x1._array, x2._array)) + x1, x2 = Array._normalize_two_args(x1, x2) + return Array._new(np.bitwise_or(x1._array, x2._array)) # Note: the function name is different here def bitwise_right_shift(x1: Array, x2: Array, /) -> Array: @@ -176,14 +172,14 @@ def bitwise_right_shift(x1: Array, x2: Array, /) -> Array: """ if x1.dtype not in _integer_dtypes or x2.dtype not in _integer_dtypes: raise TypeError('Only integer dtypes are allowed in bitwise_right_shift') - x1, x2 = ndarray._normalize_two_args(x1, x2) + x1, x2 = Array._normalize_two_args(x1, x2) # Note: bitwise_right_shift is only defined for x2 nonnegative. if np.any(x2._array < 0): raise ValueError('bitwise_right_shift(x1, x2) is only defined for x2 >= 0') # Note: The spec requires the return dtype of bitwise_left_shift to be the # same as the first argument. np.left_shift() returns a type that is the # type promotion of the two input types. - return ndarray._new(np.right_shift(x1._array, x2._array).astype(x1.dtype)) + return Array._new(np.right_shift(x1._array, x2._array).astype(x1.dtype)) def bitwise_xor(x1: Array, x2: Array, /) -> Array: """ @@ -193,8 +189,8 @@ def bitwise_xor(x1: Array, x2: Array, /) -> Array: """ if x1.dtype not in _integer_or_boolean_dtypes or x2.dtype not in _integer_or_boolean_dtypes: raise TypeError('Only integer or boolean dtypes are allowed in bitwise_xor') - x1, x2 = ndarray._normalize_two_args(x1, x2) - return ndarray._new(np.bitwise_xor(x1._array, x2._array)) + x1, x2 = Array._normalize_two_args(x1, x2) + return Array._new(np.bitwise_xor(x1._array, x2._array)) def ceil(x: Array, /) -> Array: """ @@ -207,7 +203,7 @@ def ceil(x: Array, /) -> Array: if x.dtype in _integer_dtypes: # Note: The return dtype of ceil is the same as the input return x - return ndarray._new(np.ceil(x._array)) + return Array._new(np.ceil(x._array)) @np.errstate(all='ignore') def cos(x: Array, /) -> Array: @@ -218,7 +214,7 @@ def cos(x: Array, /) -> Array: """ if x.dtype not in _floating_dtypes: raise TypeError('Only floating-point dtypes are allowed in cos') - return ndarray._new(np.cos(x._array)) + return Array._new(np.cos(x._array)) @np.errstate(all='ignore') def cosh(x: Array, /) -> Array: @@ -229,7 +225,7 @@ def cosh(x: Array, /) -> Array: """ if x.dtype not in _floating_dtypes: raise TypeError('Only floating-point dtypes are allowed in cosh') - return ndarray._new(np.cosh(x._array)) + return Array._new(np.cosh(x._array)) @np.errstate(all='ignore') def divide(x1: Array, x2: Array, /) -> Array: @@ -240,8 +236,8 @@ def divide(x1: Array, x2: Array, /) -> Array: """ if x1.dtype not in _floating_dtypes or x2.dtype not in _floating_dtypes: raise TypeError('Only floating-point dtypes are allowed in divide') - x1, x2 = ndarray._normalize_two_args(x1, x2) - return ndarray._new(np.divide(x1._array, x2._array)) + x1, x2 = Array._normalize_two_args(x1, x2) + return Array._new(np.divide(x1._array, x2._array)) def equal(x1: Array, x2: Array, /) -> Array: """ @@ -249,8 +245,8 @@ def equal(x1: Array, x2: Array, /) -> Array: See its docstring for more information. """ - x1, x2 = ndarray._normalize_two_args(x1, x2) - return ndarray._new(np.equal(x1._array, x2._array)) + x1, x2 = Array._normalize_two_args(x1, x2) + return Array._new(np.equal(x1._array, x2._array)) @np.errstate(all='ignore') def exp(x: Array, /) -> Array: @@ -261,7 +257,7 @@ def exp(x: Array, /) -> Array: """ if x.dtype not in _floating_dtypes: raise TypeError('Only floating-point dtypes are allowed in exp') - return ndarray._new(np.exp(x._array)) + return Array._new(np.exp(x._array)) @np.errstate(all='ignore') def expm1(x: Array, /) -> Array: @@ -272,7 +268,7 @@ def expm1(x: Array, /) -> Array: """ if x.dtype not in _floating_dtypes: raise TypeError('Only floating-point dtypes are allowed in expm1') - return ndarray._new(np.expm1(x._array)) + return Array._new(np.expm1(x._array)) def floor(x: Array, /) -> Array: """ @@ -285,7 +281,7 @@ def floor(x: Array, /) -> Array: if x.dtype in _integer_dtypes: # Note: The return dtype of floor is the same as the input return x - return ndarray._new(np.floor(x._array)) + return Array._new(np.floor(x._array)) @np.errstate(all='ignore') def floor_divide(x1: Array, x2: Array, /) -> Array: @@ -296,8 +292,8 @@ def floor_divide(x1: Array, x2: Array, /) -> Array: """ if x1.dtype not in _numeric_dtypes or x2.dtype not in _numeric_dtypes: raise TypeError('Only numeric dtypes are allowed in floor_divide') - x1, x2 = ndarray._normalize_two_args(x1, x2) - return ndarray._new(np.floor_divide(x1._array, x2._array)) + x1, x2 = Array._normalize_two_args(x1, x2) + return Array._new(np.floor_divide(x1._array, x2._array)) def greater(x1: Array, x2: Array, /) -> Array: """ @@ -307,8 +303,8 @@ def greater(x1: Array, x2: Array, /) -> Array: """ if x1.dtype not in _numeric_dtypes or x2.dtype not in _numeric_dtypes: raise TypeError('Only numeric dtypes are allowed in greater') - x1, x2 = ndarray._normalize_two_args(x1, x2) - return ndarray._new(np.greater(x1._array, x2._array)) + x1, x2 = Array._normalize_two_args(x1, x2) + return Array._new(np.greater(x1._array, x2._array)) def greater_equal(x1: Array, x2: Array, /) -> Array: """ @@ -318,8 +314,8 @@ def greater_equal(x1: Array, x2: Array, /) -> Array: """ if x1.dtype not in _numeric_dtypes or x2.dtype not in _numeric_dtypes: raise TypeError('Only numeric dtypes are allowed in greater_equal') - x1, x2 = ndarray._normalize_two_args(x1, x2) - return ndarray._new(np.greater_equal(x1._array, x2._array)) + x1, x2 = Array._normalize_two_args(x1, x2) + return Array._new(np.greater_equal(x1._array, x2._array)) def isfinite(x: Array, /) -> Array: """ @@ -329,7 +325,7 @@ def isfinite(x: Array, /) -> Array: """ if x.dtype not in _numeric_dtypes: raise TypeError('Only numeric dtypes are allowed in isfinite') - return ndarray._new(np.isfinite(x._array)) + return Array._new(np.isfinite(x._array)) def isinf(x: Array, /) -> Array: """ @@ -339,7 +335,7 @@ def isinf(x: Array, /) -> Array: """ if x.dtype not in _numeric_dtypes: raise TypeError('Only numeric dtypes are allowed in isinf') - return ndarray._new(np.isinf(x._array)) + return Array._new(np.isinf(x._array)) def isnan(x: Array, /) -> Array: """ @@ -349,7 +345,7 @@ def isnan(x: Array, /) -> Array: """ if x.dtype not in _numeric_dtypes: raise TypeError('Only numeric dtypes are allowed in isnan') - return ndarray._new(np.isnan(x._array)) + return Array._new(np.isnan(x._array)) def less(x1: Array, x2: Array, /) -> Array: """ @@ -359,8 +355,8 @@ def less(x1: Array, x2: Array, /) -> Array: """ if x1.dtype not in _numeric_dtypes or x2.dtype not in _numeric_dtypes: raise TypeError('Only numeric dtypes are allowed in less') - x1, x2 = ndarray._normalize_two_args(x1, x2) - return ndarray._new(np.less(x1._array, x2._array)) + x1, x2 = Array._normalize_two_args(x1, x2) + return Array._new(np.less(x1._array, x2._array)) def less_equal(x1: Array, x2: Array, /) -> Array: """ @@ -370,8 +366,8 @@ def less_equal(x1: Array, x2: Array, /) -> Array: """ if x1.dtype not in _numeric_dtypes or x2.dtype not in _numeric_dtypes: raise TypeError('Only numeric dtypes are allowed in less_equal') - x1, x2 = ndarray._normalize_two_args(x1, x2) - return ndarray._new(np.less_equal(x1._array, x2._array)) + x1, x2 = Array._normalize_two_args(x1, x2) + return Array._new(np.less_equal(x1._array, x2._array)) @np.errstate(all='ignore') def log(x: Array, /) -> Array: @@ -382,7 +378,7 @@ def log(x: Array, /) -> Array: """ if x.dtype not in _floating_dtypes: raise TypeError('Only floating-point dtypes are allowed in log') - return ndarray._new(np.log(x._array)) + return Array._new(np.log(x._array)) @np.errstate(all='ignore') def log1p(x: Array, /) -> Array: @@ -393,7 +389,7 @@ def log1p(x: Array, /) -> Array: """ if x.dtype not in _floating_dtypes: raise TypeError('Only floating-point dtypes are allowed in log1p') - return ndarray._new(np.log1p(x._array)) + return Array._new(np.log1p(x._array)) @np.errstate(all='ignore') def log2(x: Array, /) -> Array: @@ -404,7 +400,7 @@ def log2(x: Array, /) -> Array: """ if x.dtype not in _floating_dtypes: raise TypeError('Only floating-point dtypes are allowed in log2') - return ndarray._new(np.log2(x._array)) + return Array._new(np.log2(x._array)) @np.errstate(all='ignore') def log10(x: Array, /) -> Array: @@ -415,7 +411,7 @@ def log10(x: Array, /) -> Array: """ if x.dtype not in _floating_dtypes: raise TypeError('Only floating-point dtypes are allowed in log10') - return ndarray._new(np.log10(x._array)) + return Array._new(np.log10(x._array)) def logaddexp(x1: Array, x2: Array) -> Array: """ @@ -425,8 +421,8 @@ def logaddexp(x1: Array, x2: Array) -> Array: """ if x1.dtype not in _floating_dtypes or x2.dtype not in _floating_dtypes: raise TypeError('Only floating-point dtypes are allowed in logaddexp') - x1, x2 = ndarray._normalize_two_args(x1, x2) - return ndarray._new(np.logaddexp(x1._array, x2._array)) + x1, x2 = Array._normalize_two_args(x1, x2) + return Array._new(np.logaddexp(x1._array, x2._array)) def logical_and(x1: Array, x2: Array, /) -> Array: """ @@ -436,8 +432,8 @@ def logical_and(x1: Array, x2: Array, /) -> Array: """ if x1.dtype not in _boolean_dtypes or x2.dtype not in _boolean_dtypes: raise TypeError('Only boolean dtypes are allowed in logical_and') - x1, x2 = ndarray._normalize_two_args(x1, x2) - return ndarray._new(np.logical_and(x1._array, x2._array)) + x1, x2 = Array._normalize_two_args(x1, x2) + return Array._new(np.logical_and(x1._array, x2._array)) def logical_not(x: Array, /) -> Array: """ @@ -447,7 +443,7 @@ def logical_not(x: Array, /) -> Array: """ if x.dtype not in _boolean_dtypes: raise TypeError('Only boolean dtypes are allowed in logical_not') - return ndarray._new(np.logical_not(x._array)) + return Array._new(np.logical_not(x._array)) def logical_or(x1: Array, x2: Array, /) -> Array: """ @@ -457,8 +453,8 @@ def logical_or(x1: Array, x2: Array, /) -> Array: """ if x1.dtype not in _boolean_dtypes or x2.dtype not in _boolean_dtypes: raise TypeError('Only boolean dtypes are allowed in logical_or') - x1, x2 = ndarray._normalize_two_args(x1, x2) - return ndarray._new(np.logical_or(x1._array, x2._array)) + x1, x2 = Array._normalize_two_args(x1, x2) + return Array._new(np.logical_or(x1._array, x2._array)) def logical_xor(x1: Array, x2: Array, /) -> Array: """ @@ -468,8 +464,8 @@ def logical_xor(x1: Array, x2: Array, /) -> Array: """ if x1.dtype not in _boolean_dtypes or x2.dtype not in _boolean_dtypes: raise TypeError('Only boolean dtypes are allowed in logical_xor') - x1, x2 = ndarray._normalize_two_args(x1, x2) - return ndarray._new(np.logical_xor(x1._array, x2._array)) + x1, x2 = Array._normalize_two_args(x1, x2) + return Array._new(np.logical_xor(x1._array, x2._array)) @np.errstate(all='ignore') def multiply(x1: Array, x2: Array, /) -> Array: @@ -480,8 +476,8 @@ def multiply(x1: Array, x2: Array, /) -> Array: """ if x1.dtype not in _numeric_dtypes or x2.dtype not in _numeric_dtypes: raise TypeError('Only numeric dtypes are allowed in multiply') - x1, x2 = ndarray._normalize_two_args(x1, x2) - return ndarray._new(np.multiply(x1._array, x2._array)) + x1, x2 = Array._normalize_two_args(x1, x2) + return Array._new(np.multiply(x1._array, x2._array)) def negative(x: Array, /) -> Array: """ @@ -491,7 +487,7 @@ def negative(x: Array, /) -> Array: """ if x.dtype not in _numeric_dtypes: raise TypeError('Only numeric dtypes are allowed in negative') - return ndarray._new(np.negative(x._array)) + return Array._new(np.negative(x._array)) def not_equal(x1: Array, x2: Array, /) -> Array: """ @@ -499,8 +495,8 @@ def not_equal(x1: Array, x2: Array, /) -> Array: See its docstring for more information. """ - x1, x2 = ndarray._normalize_two_args(x1, x2) - return ndarray._new(np.not_equal(x1._array, x2._array)) + x1, x2 = Array._normalize_two_args(x1, x2) + return Array._new(np.not_equal(x1._array, x2._array)) def positive(x: Array, /) -> Array: """ @@ -510,7 +506,7 @@ def positive(x: Array, /) -> Array: """ if x.dtype not in _numeric_dtypes: raise TypeError('Only numeric dtypes are allowed in positive') - return ndarray._new(np.positive(x._array)) + return Array._new(np.positive(x._array)) # Note: the function name is different here @np.errstate(all='ignore') @@ -522,8 +518,8 @@ def pow(x1: Array, x2: Array, /) -> Array: """ if x1.dtype not in _floating_dtypes or x2.dtype not in _floating_dtypes: raise TypeError('Only floating-point dtypes are allowed in pow') - x1, x2 = ndarray._normalize_two_args(x1, x2) - return ndarray._new(np.power(x1._array, x2._array)) + x1, x2 = Array._normalize_two_args(x1, x2) + return Array._new(np.power(x1._array, x2._array)) @np.errstate(all='ignore') def remainder(x1: Array, x2: Array, /) -> Array: @@ -534,8 +530,8 @@ def remainder(x1: Array, x2: Array, /) -> Array: """ if x1.dtype not in _numeric_dtypes or x2.dtype not in _numeric_dtypes: raise TypeError('Only numeric dtypes are allowed in remainder') - x1, x2 = ndarray._normalize_two_args(x1, x2) - return ndarray._new(np.remainder(x1._array, x2._array)) + x1, x2 = Array._normalize_two_args(x1, x2) + return Array._new(np.remainder(x1._array, x2._array)) def round(x: Array, /) -> Array: """ @@ -545,7 +541,7 @@ def round(x: Array, /) -> Array: """ if x.dtype not in _numeric_dtypes: raise TypeError('Only numeric dtypes are allowed in round') - return ndarray._new(np.round(x._array)) + return Array._new(np.round(x._array)) def sign(x: Array, /) -> Array: """ @@ -555,7 +551,7 @@ def sign(x: Array, /) -> Array: """ if x.dtype not in _numeric_dtypes: raise TypeError('Only numeric dtypes are allowed in sign') - return ndarray._new(np.sign(x._array)) + return Array._new(np.sign(x._array)) @np.errstate(all='ignore') def sin(x: Array, /) -> Array: @@ -566,7 +562,7 @@ def sin(x: Array, /) -> Array: """ if x.dtype not in _floating_dtypes: raise TypeError('Only floating-point dtypes are allowed in sin') - return ndarray._new(np.sin(x._array)) + return Array._new(np.sin(x._array)) @np.errstate(all='ignore') def sinh(x: Array, /) -> Array: @@ -577,7 +573,7 @@ def sinh(x: Array, /) -> Array: """ if x.dtype not in _floating_dtypes: raise TypeError('Only floating-point dtypes are allowed in sinh') - return ndarray._new(np.sinh(x._array)) + return Array._new(np.sinh(x._array)) @np.errstate(all='ignore') def square(x: Array, /) -> Array: @@ -588,7 +584,7 @@ def square(x: Array, /) -> Array: """ if x.dtype not in _numeric_dtypes: raise TypeError('Only numeric dtypes are allowed in square') - return ndarray._new(np.square(x._array)) + return Array._new(np.square(x._array)) @np.errstate(all='ignore') def sqrt(x: Array, /) -> Array: @@ -599,7 +595,7 @@ def sqrt(x: Array, /) -> Array: """ if x.dtype not in _floating_dtypes: raise TypeError('Only floating-point dtypes are allowed in sqrt') - return ndarray._new(np.sqrt(x._array)) + return Array._new(np.sqrt(x._array)) @np.errstate(all='ignore') def subtract(x1: Array, x2: Array, /) -> Array: @@ -610,8 +606,8 @@ def subtract(x1: Array, x2: Array, /) -> Array: """ if x1.dtype not in _numeric_dtypes or x2.dtype not in _numeric_dtypes: raise TypeError('Only numeric dtypes are allowed in subtract') - x1, x2 = ndarray._normalize_two_args(x1, x2) - return ndarray._new(np.subtract(x1._array, x2._array)) + x1, x2 = Array._normalize_two_args(x1, x2) + return Array._new(np.subtract(x1._array, x2._array)) @np.errstate(all='ignore') def tan(x: Array, /) -> Array: @@ -622,7 +618,7 @@ def tan(x: Array, /) -> Array: """ if x.dtype not in _floating_dtypes: raise TypeError('Only floating-point dtypes are allowed in tan') - return ndarray._new(np.tan(x._array)) + return Array._new(np.tan(x._array)) def tanh(x: Array, /) -> Array: """ @@ -632,7 +628,7 @@ def tanh(x: Array, /) -> Array: """ if x.dtype not in _floating_dtypes: raise TypeError('Only floating-point dtypes are allowed in tanh') - return ndarray._new(np.tanh(x._array)) + return Array._new(np.tanh(x._array)) def trunc(x: Array, /) -> Array: """ @@ -642,4 +638,4 @@ def trunc(x: Array, /) -> Array: """ if x.dtype not in _numeric_dtypes: raise TypeError('Only numeric dtypes are allowed in trunc') - return ndarray._new(np.trunc(x._array)) + return Array._new(np.trunc(x._array)) |