MCPcopy Create free account
hub / github.com/numpy/numpy / _new

Method _new

numpy/array_api/_array_object.py:65–85  ·  view source on GitHub ↗

This is a private method for initializing the array API Array object. Functions outside of the array_api submodule should not use this method. Use one of the creation functions instead, such as ``asarray``.

(cls, x, /)

Source from the content-addressed store, hash-verified

63 # this class is not supported API.
64 @classmethod
65 def _new(cls, x, /):
66 """
67 This is a private method for initializing the array API Array
68 object.
69
70 Functions outside of the array_api submodule should not use this
71 method. Use one of the creation functions instead, such as
72 ``asarray``.
73
74 """
75 obj = super().__new__(cls)
76 # Note: The spec does not have array scalars, only 0-D arrays.
77 if isinstance(x, np.generic):
78 # Convert the array scalar to a 0-D array
79 x = np.asarray(x)
80 if x.dtype not in _all_dtypes:
81 raise TypeError(
82 f"The array_api namespace does not support the dtype '{x.dtype}'"
83 )
84 obj._array = x
85 return obj
86
87 # Prevent Array() from working
88 def __new__(cls, *args, **kwargs):

Callers 15

__getitem__Method · 0.95
argsortFunction · 0.80
sortFunction · 0.80
choleskyFunction · 0.80
crossFunction · 0.80
detFunction · 0.80
diagonalFunction · 0.80
eigvalshFunction · 0.80
invFunction · 0.80
matmulFunction · 0.80
matrix_normFunction · 0.80
matrix_powerFunction · 0.80

Calls 1

__new__Method · 0.45

Tested by

no test coverage detected