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, /)
| 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): |
no test coverage detected