summaryrefslogtreecommitdiff
path: root/numpy/_array_api
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/_array_api')
-rw-r--r--numpy/_array_api/_creation_functions.py35
-rw-r--r--numpy/_array_api/_elementwise_functions.py167
-rw-r--r--numpy/_array_api/_linear_algebra_functions.py68
-rw-r--r--numpy/_array_api/_manipulation_functions.py23
-rw-r--r--numpy/_array_api/_searching_functions.py14
-rw-r--r--numpy/_array_api/_set_functions.py5
-rw-r--r--numpy/_array_api/_sorting_functions.py14
-rw-r--r--numpy/_array_api/_statistical_functions.py23
-rw-r--r--numpy/_array_api/_utility_functions.py8
9 files changed, 131 insertions, 226 deletions
diff --git a/numpy/_array_api/_creation_functions.py b/numpy/_array_api/_creation_functions.py
index 4e91aa443..b74eca060 100644
--- a/numpy/_array_api/_creation_functions.py
+++ b/numpy/_array_api/_creation_functions.py
@@ -1,76 +1,67 @@
+import numpy as np
+
def arange(start, /, *, stop=None, step=1, dtype=None, device=None):
- from .. import arange
if device is not None:
# Note: Device support is not yet implemented on ndarray
raise NotImplementedError("Device support is not yet implemented")
- return arange(start, stop=stop, step=step, dtype=dtype)
+ return np.arange(start, stop=stop, step=step, dtype=dtype)
def empty(shape, /, *, dtype=None, device=None):
- from .. import empty
if device is not None:
# Note: Device support is not yet implemented on ndarray
raise NotImplementedError("Device support is not yet implemented")
- return empty(shape, dtype=dtype)
+ return np.empty(shape, dtype=dtype)
def empty_like(x, /, *, dtype=None, device=None):
- from .. import empty_like
if device is not None:
# Note: Device support is not yet implemented on ndarray
raise NotImplementedError("Device support is not yet implemented")
- return empty_like(x, dtype=dtype)
+ return np.empty_like(x, dtype=dtype)
def eye(N, /, *, M=None, k=0, dtype=None, device=None):
- from .. import eye
if device is not None:
# Note: Device support is not yet implemented on ndarray
raise NotImplementedError("Device support is not yet implemented")
- return eye(N, M=M, k=k, dtype=dtype)
+ return np.eye(N, M=M, k=k, dtype=dtype)
def full(shape, fill_value, /, *, dtype=None, device=None):
- from .. import full
if device is not None:
# Note: Device support is not yet implemented on ndarray
raise NotImplementedError("Device support is not yet implemented")
- return full(shape, fill_value, dtype=dtype)
+ return np.full(shape, fill_value, dtype=dtype)
def full_like(x, fill_value, /, *, dtype=None, device=None):
- from .. import full_like
if device is not None:
# Note: Device support is not yet implemented on ndarray
raise NotImplementedError("Device support is not yet implemented")
- return full_like(x, fill_value, dtype=dtype)
+ return np.full_like(x, fill_value, dtype=dtype)
def linspace(start, stop, num, /, *, dtype=None, device=None, endpoint=True):
- from .. import linspace
if device is not None:
# Note: Device support is not yet implemented on ndarray
raise NotImplementedError("Device support is not yet implemented")
- return linspace(start, stop, num, dtype=dtype, endpoint=endpoint)
+ return np.linspace(start, stop, num, dtype=dtype, endpoint=endpoint)
def ones(shape, /, *, dtype=None, device=None):
- from .. import ones
if device is not None:
# Note: Device support is not yet implemented on ndarray
raise NotImplementedError("Device support is not yet implemented")
- return ones(shape, dtype=dtype)
+ return np.ones(shape, dtype=dtype)
def ones_like(x, /, *, dtype=None, device=None):
- from .. import ones_like
if device is not None:
# Note: Device support is not yet implemented on ndarray
raise NotImplementedError("Device support is not yet implemented")
- return ones_like(x, dtype=dtype)
+ return np.ones_like(x, dtype=dtype)
def zeros(shape, /, *, dtype=None, device=None):
- from .. import zeros
if device is not None:
# Note: Device support is not yet implemented on ndarray
raise NotImplementedError("Device support is not yet implemented")
- return zeros(shape, dtype=dtype)
+ return np.zeros(shape, dtype=dtype)
def zeros_like(x, /, *, dtype=None, device=None):
- from .. import zeros_like
if device is not None:
# Note: Device support is not yet implemented on ndarray
raise NotImplementedError("Device support is not yet implemented")
- return zeros_like(x, dtype=dtype)
+ return np.zeros_like(x, dtype=dtype)
diff --git a/numpy/_array_api/_elementwise_functions.py b/numpy/_array_api/_elementwise_functions.py
index f9052020e..ef820dd5b 100644
--- a/numpy/_array_api/_elementwise_functions.py
+++ b/numpy/_array_api/_elementwise_functions.py
@@ -1,230 +1,177 @@
+import numpy as np
+
def abs(x, /):
- from .. import abs
- return abs(x)
+ return np.abs(x)
def acos(x, /):
# Note: the function name is different here
- from .. import arccos
- return arccos(x)
+ return np.arccos(x)
def acosh(x, /):
# Note: the function name is different here
- from .. import arccosh
- return arccosh(x)
+ return np.arccosh(x)
def add(x1, x2, /):
- from .. import add
- return add(x1, x2)
+ return np.add(x1, x2)
def asin(x, /):
# Note: the function name is different here
- from .. import arcsin
- return arcsin(x)
+ return np.arcsin(x)
def asinh(x, /):
# Note: the function name is different here
- from .. import arcsinh
- return arcsinh(x)
+ return np.arcsinh(x)
def atan(x, /):
# Note: the function name is different here
- from .. import arctan
- return arctan(x)
+ return np.arctan(x)
def atan2(x1, x2, /):
# Note: the function name is different here
- from .. import arctan2
- return arctan2(x1, x2)
+ return np.arctan2(x1, x2)
def atanh(x, /):
# Note: the function name is different here
- from .. import arctanh
- return arctanh(x)
+ return np.arctanh(x)
def bitwise_and(x1, x2, /):
- from .. import bitwise_and
- return bitwise_and(x1, x2)
+ return np.bitwise_and(x1, x2)
def bitwise_left_shift(x1, x2, /):
# Note: the function name is different here
- from .. import left_shift
- return left_shift(x1, x2)
+ return np.left_shift(x1, x2)
def bitwise_invert(x, /):
# Note: the function name is different here
- from .. import invert
- return invert(x)
+ return np.invert(x)
def bitwise_or(x1, x2, /):
- from .. import bitwise_or
- return bitwise_or(x1, x2)
+ return np.bitwise_or(x1, x2)
def bitwise_right_shift(x1, x2, /):
# Note: the function name is different here
- from .. import right_shift
- return right_shift(x1, x2)
+ return np.right_shift(x1, x2)
def bitwise_xor(x1, x2, /):
- from .. import bitwise_xor
- return bitwise_xor(x1, x2)
+ return np.bitwise_xor(x1, x2)
def ceil(x, /):
- from .. import ceil
- return ceil(x)
+ return np.ceil(x)
def cos(x, /):
- from .. import cos
- return cos(x)
+ return np.cos(x)
def cosh(x, /):
- from .. import cosh
- return cosh(x)
+ return np.cosh(x)
def divide(x1, x2, /):
- from .. import divide
- return divide(x1, x2)
+ return np.divide(x1, x2)
def equal(x1, x2, /):
- from .. import equal
- return equal(x1, x2)
+ return np.equal(x1, x2)
def exp(x, /):
- from .. import exp
- return exp(x)
+ return np.exp(x)
def expm1(x, /):
- from .. import expm1
- return expm1(x)
+ return np.expm1(x)
def floor(x, /):
- from .. import floor
- return floor(x)
+ return np.floor(x)
def floor_divide(x1, x2, /):
- from .. import floor_divide
- return floor_divide(x1, x2)
+ return np.floor_divide(x1, x2)
def greater(x1, x2, /):
- from .. import greater
- return greater(x1, x2)
+ return np.greater(x1, x2)
def greater_equal(x1, x2, /):
- from .. import greater_equal
- return greater_equal(x1, x2)
+ return np.greater_equal(x1, x2)
def isfinite(x, /):
- from .. import isfinite
- return isfinite(x)
+ return np.isfinite(x)
def isinf(x, /):
- from .. import isinf
- return isinf(x)
+ return np.isinf(x)
def isnan(x, /):
- from .. import isnan
- return isnan(x)
+ return np.isnan(x)
def less(x1, x2, /):
- from .. import less
- return less(x1, x2)
+ return np.less(x1, x2)
def less_equal(x1, x2, /):
- from .. import less_equal
- return less_equal(x1, x2)
+ return np.less_equal(x1, x2)
def log(x, /):
- from .. import log
- return log(x)
+ return np.log(x)
def log1p(x, /):
- from .. import log1p
- return log1p(x)
+ return np.log1p(x)
def log2(x, /):
- from .. import log2
- return log2(x)
+ return np.log2(x)
def log10(x, /):
- from .. import log10
- return log10(x)
+ return np.log10(x)
def logical_and(x1, x2, /):
- from .. import logical_and
- return logical_and(x1, x2)
+ return np.logical_and(x1, x2)
def logical_not(x, /):
- from .. import logical_not
- return logical_not(x)
+ return np.logical_not(x)
def logical_or(x1, x2, /):
- from .. import logical_or
- return logical_or(x1, x2)
+ return np.logical_or(x1, x2)
def logical_xor(x1, x2, /):
- from .. import logical_xor
- return logical_xor(x1, x2)
+ return np.logical_xor(x1, x2)
def multiply(x1, x2, /):
- from .. import multiply
- return multiply(x1, x2)
+ return np.multiply(x1, x2)
def negative(x, /):
- from .. import negative
- return negative(x)
+ return np.negative(x)
def not_equal(x1, x2, /):
- from .. import not_equal
- return not_equal(x1, x2)
+ return np.not_equal(x1, x2)
def positive(x, /):
- from .. import positive
- return positive(x)
+ return np.positive(x)
def pow(x1, x2, /):
# Note: the function name is different here
- from .. import power
- return power(x1, x2)
+ return np.power(x1, x2)
def remainder(x1, x2, /):
- from .. import remainder
- return remainder(x1, x2)
+ return np.remainder(x1, x2)
def round(x, /):
- from .. import round
- return round(x)
+ return np.round(x)
def sign(x, /):
- from .. import sign
- return sign(x)
+ return np.sign(x)
def sin(x, /):
- from .. import sin
- return sin(x)
+ return np.sin(x)
def sinh(x, /):
- from .. import sinh
- return sinh(x)
+ return np.sinh(x)
def square(x, /):
- from .. import square
- return square(x)
+ return np.square(x)
def sqrt(x, /):
- from .. import sqrt
- return sqrt(x)
+ return np.sqrt(x)
def subtract(x1, x2, /):
- from .. import subtract
- return subtract(x1, x2)
+ return np.subtract(x1, x2)
def tan(x, /):
- from .. import tan
- return tan(x)
+ return np.tan(x)
def tanh(x, /):
- from .. import tanh
- return tanh(x)
+ return np.tanh(x)
def trunc(x, /):
- from .. import trunc
- return trunc(x)
+ return np.trunc(x)
diff --git a/numpy/_array_api/_linear_algebra_functions.py b/numpy/_array_api/_linear_algebra_functions.py
index 10c81d12c..ffb589c99 100644
--- a/numpy/_array_api/_linear_algebra_functions.py
+++ b/numpy/_array_api/_linear_algebra_functions.py
@@ -1,93 +1,73 @@
+import numpy as np
+
# def cholesky():
-# from .. import cholesky
-# return cholesky()
+# return np.cholesky()
def cross(x1, x2, /, *, axis=-1):
- from .. import cross
- return cross(x1, x2, axis=axis)
+ return np.cross(x1, x2, axis=axis)
def det(x, /):
# Note: this function is being imported from a nondefault namespace
- from ..linalg import det
- return det(x)
+ return np.det(x)
def diagonal(x, /, *, axis1=0, axis2=1, offset=0):
- from .. import diagonal
- return diagonal(x, axis1=axis1, axis2=axis2, offset=offset)
+ return np.diagonal(x, axis1=axis1, axis2=axis2, offset=offset)
# def dot():
-# from .. import dot
-# return dot()
+# return np.dot()
#
# def eig():
-# from .. import eig
-# return eig()
+# return np.eig()
#
# def eigvalsh():
-# from .. import eigvalsh
-# return eigvalsh()
+# return np.eigvalsh()
#
# def einsum():
-# from .. import einsum
-# return einsum()
+# return np.einsum()
def inv(x):
# Note: this function is being imported from a nondefault namespace
- from ..linalg import inv
- return inv(x)
+ return np.inv(x)
# def lstsq():
-# from .. import lstsq
-# return lstsq()
+# return np.lstsq()
#
# def matmul():
-# from .. import matmul
-# return matmul()
+# return np.matmul()
#
# def matrix_power():
-# from .. import matrix_power
-# return matrix_power()
+# return np.matrix_power()
#
# def matrix_rank():
-# from .. import matrix_rank
-# return matrix_rank()
+# return np.matrix_rank()
def norm(x, /, *, axis=None, keepdims=False, ord=None):
# Note: this function is being imported from a nondefault namespace
- from ..linalg import norm
# Note: this is different from the default behavior
if axis == None and x.ndim > 2:
x = x.flatten()
- return norm(x, axis=axis, keepdims=keepdims, ord=ord)
+ return np.norm(x, axis=axis, keepdims=keepdims, ord=ord)
def outer(x1, x2, /):
- from .. import outer
- return outer(x1, x2)
+ return np.outer(x1, x2)
# def pinv():
-# from .. import pinv
-# return pinv()
+# return np.pinv()
#
# def qr():
-# from .. import qr
-# return qr()
+# return np.qr()
#
# def slogdet():
-# from .. import slogdet
-# return slogdet()
+# return np.slogdet()
#
# def solve():
-# from .. import solve
-# return solve()
+# return np.solve()
#
# def svd():
-# from .. import svd
-# return svd()
+# return np.svd()
def trace(x, /, *, axis1=0, axis2=1, offset=0):
- from .. import trace
- return trace(x, axis1=axis1, axis2=axis2, offset=offset)
+ return np.trace(x, axis1=axis1, axis2=axis2, offset=offset)
def transpose(x, /, *, axes=None):
- from .. import transpose
- return transpose(x, axes=axes)
+ return np.transpose(x, axes=axes)
diff --git a/numpy/_array_api/_manipulation_functions.py b/numpy/_array_api/_manipulation_functions.py
index 19e9c1cab..262c712f8 100644
--- a/numpy/_array_api/_manipulation_functions.py
+++ b/numpy/_array_api/_manipulation_functions.py
@@ -1,28 +1,23 @@
+import numpy as np
+
def concat(arrays, /, *, axis=0):
# Note: the function name is different here
- from .. import concatenate
- return concatenate(arrays, axis=axis)
+ return np.concatenate(arrays, axis=axis)
def expand_dims(x, axis, /):
- from .. import expand_dims
- return expand_dims(x, axis)
+ return np.expand_dims(x, axis)
def flip(x, /, *, axis=None):
- from .. import flip
- return flip(x, axis=axis)
+ return np.flip(x, axis=axis)
def reshape(x, shape, /):
- from .. import reshape
- return reshape(x, shape)
+ return np.reshape(x, shape)
def roll(x, shift, /, *, axis=None):
- from .. import roll
- return roll(x, shift, axis=axis)
+ return np.roll(x, shift, axis=axis)
def squeeze(x, /, *, axis=None):
- from .. import squeeze
- return squeeze(x, axis=axis)
+ return np.squeeze(x, axis=axis)
def stack(arrays, /, *, axis=0):
- from .. import stack
- return stack(arrays, axis=axis)
+ return np.stack(arrays, axis=axis)
diff --git a/numpy/_array_api/_searching_functions.py b/numpy/_array_api/_searching_functions.py
index c6035ca77..62763eaca 100644
--- a/numpy/_array_api/_searching_functions.py
+++ b/numpy/_array_api/_searching_functions.py
@@ -1,15 +1,13 @@
+import numpy as np
+
def argmax(x, /, *, axis=None, keepdims=False):
- from .. import argmax
- return argmax(x, axis=axis, keepdims=keepdims)
+ return np.argmax(x, axis=axis, keepdims=keepdims)
def argmin(x, /, *, axis=None, keepdims=False):
- from .. import argmin
- return argmin(x, axis=axis, keepdims=keepdims)
+ return np.argmin(x, axis=axis, keepdims=keepdims)
def nonzero(x, /):
- from .. import nonzero
- return nonzero(x)
+ return np.nonzero(x)
def where(condition, x1, x2, /):
- from .. import where
- return where(condition, x1, x2)
+ return np.where(condition, x1, x2)
diff --git a/numpy/_array_api/_set_functions.py b/numpy/_array_api/_set_functions.py
index b6198765a..7603b6b30 100644
--- a/numpy/_array_api/_set_functions.py
+++ b/numpy/_array_api/_set_functions.py
@@ -1,3 +1,4 @@
+import numpy as np
+
def unique(x, /, *, return_counts=False, return_index=False, return_inverse=False, sorted=True):
- from .. import unique
- return unique(x, return_counts=return_counts, return_index=return_index, return_inverse=return_inverse, sorted=sorted)
+ return np.unique(x, return_counts=return_counts, return_index=return_index, return_inverse=return_inverse, sorted=sorted)
diff --git a/numpy/_array_api/_sorting_functions.py b/numpy/_array_api/_sorting_functions.py
index fb2f819a2..6477029b9 100644
--- a/numpy/_array_api/_sorting_functions.py
+++ b/numpy/_array_api/_sorting_functions.py
@@ -1,19 +1,17 @@
+import numpy as np
+
def argsort(x, /, *, axis=-1, descending=False, stable=True):
- from .. import argsort
- from .. import flip
# Note: this keyword argument is different, and the default is different.
kind = 'stable' if stable else 'quicksort'
- res = argsort(x, axis=axis, kind=kind)
+ res = np.argsort(x, axis=axis, kind=kind)
if descending:
- res = flip(res, axis=axis)
+ res = np.flip(res, axis=axis)
return res
def sort(x, /, *, axis=-1, descending=False, stable=True):
- from .. import sort
- from .. import flip
# Note: this keyword argument is different, and the default is different.
kind = 'stable' if stable else 'quicksort'
- res = sort(x, axis=axis, kind=kind)
+ res = np.sort(x, axis=axis, kind=kind)
if descending:
- res = flip(res, axis=axis)
+ res = np.flip(res, axis=axis)
return res
diff --git a/numpy/_array_api/_statistical_functions.py b/numpy/_array_api/_statistical_functions.py
index 339835095..833c47f66 100644
--- a/numpy/_array_api/_statistical_functions.py
+++ b/numpy/_array_api/_statistical_functions.py
@@ -1,29 +1,24 @@
+import numpy as np
+
def max(x, /, *, axis=None, keepdims=False):
- from .. import max
- return max(x, axis=axis, keepdims=keepdims)
+ return np.max(x, axis=axis, keepdims=keepdims)
def mean(x, /, *, axis=None, keepdims=False):
- from .. import mean
- return mean(x, axis=axis, keepdims=keepdims)
+ return np.mean(x, axis=axis, keepdims=keepdims)
def min(x, /, *, axis=None, keepdims=False):
- from .. import min
- return min(x, axis=axis, keepdims=keepdims)
+ return np.min(x, axis=axis, keepdims=keepdims)
def prod(x, /, *, axis=None, keepdims=False):
- from .. import prod
- return prod(x, axis=axis, keepdims=keepdims)
+ return np.prod(x, axis=axis, keepdims=keepdims)
def std(x, /, *, axis=None, correction=0.0, keepdims=False):
- from .. import std
# Note: the keyword argument correction is different here
- return std(x, axis=axis, ddof=correction, keepdims=keepdims)
+ return np.std(x, axis=axis, ddof=correction, keepdims=keepdims)
def sum(x, /, *, axis=None, keepdims=False):
- from .. import sum
- return sum(x, axis=axis, keepdims=keepdims)
+ return np.sum(x, axis=axis, keepdims=keepdims)
def var(x, /, *, axis=None, correction=0.0, keepdims=False):
- from .. import var
# Note: the keyword argument correction is different here
- return var(x, axis=axis, ddof=correction, keepdims=keepdims)
+ return np.var(x, axis=axis, ddof=correction, keepdims=keepdims)
diff --git a/numpy/_array_api/_utility_functions.py b/numpy/_array_api/_utility_functions.py
index accc43e1e..0bbdef412 100644
--- a/numpy/_array_api/_utility_functions.py
+++ b/numpy/_array_api/_utility_functions.py
@@ -1,7 +1,7 @@
+import numpy as np
+
def all(x, /, *, axis=None, keepdims=False):
- from .. import all
- return all(x, axis=axis, keepdims=keepdims)
+ return np.all(x, axis=axis, keepdims=keepdims)
def any(x, /, *, axis=None, keepdims=False):
- from .. import any
- return any(x, axis=axis, keepdims=keepdims)
+ return np.any(x, axis=axis, keepdims=keepdims)