@@ -19,14 +19,14 @@ def asarray(obj: Union[float, NestedSequence[bool|int|float], SupportsDLPack, Su
19
19
"""
20
20
# _array_object imports in this file are inside the functions to avoid
21
21
# circular imports
22
- from ._array_object import ndarray
22
+ from ._array_object import Array
23
23
if device is not None :
24
- # Note: Device support is not yet implemented on ndarray
24
+ # Note: Device support is not yet implemented on Array
25
25
raise NotImplementedError ("Device support is not yet implemented" )
26
26
if copy is not None :
27
27
# Note: copy is not yet implemented in np.asarray
28
28
raise NotImplementedError ("The copy keyword argument to asarray is not yet implemented" )
29
- if isinstance (obj , ndarray ) and (dtype is None or obj .dtype == dtype ):
29
+ if isinstance (obj , Array ) and (dtype is None or obj .dtype == dtype ):
30
30
return obj
31
31
if dtype is None and isinstance (obj , int ) and (obj > 2 ** 64 or obj < - 2 ** 63 ):
32
32
# Give a better error message in this case. NumPy would convert this
@@ -35,58 +35,58 @@ def asarray(obj: Union[float, NestedSequence[bool|int|float], SupportsDLPack, Su
35
35
res = np .asarray (obj , dtype = dtype )
36
36
if res .dtype not in _all_dtypes :
37
37
raise TypeError (f"The array_api namespace does not support the dtype '{ res .dtype } '" )
38
- return ndarray ._new (res )
38
+ return Array ._new (res )
39
39
40
40
def arange (start : Union [int , float ], / , stop : Optional [Union [int , float ]] = None , step : Union [int , float ] = 1 , * , dtype : Optional [Dtype ] = None , device : Optional [Device ] = None ) -> Array :
41
41
"""
42
42
Array API compatible wrapper for :py:func:`np.arange <numpy.arange>`.
43
43
44
44
See its docstring for more information.
45
45
"""
46
- from ._array_object import ndarray
46
+ from ._array_object import Array
47
47
if device is not None :
48
- # Note: Device support is not yet implemented on ndarray
48
+ # Note: Device support is not yet implemented on Array
49
49
raise NotImplementedError ("Device support is not yet implemented" )
50
- return ndarray ._new (np .arange (start , stop = stop , step = step , dtype = dtype ))
50
+ return Array ._new (np .arange (start , stop = stop , step = step , dtype = dtype ))
51
51
52
52
def empty (shape : Union [int , Tuple [int , ...]], * , dtype : Optional [Dtype ] = None , device : Optional [Device ] = None ) -> Array :
53
53
"""
54
54
Array API compatible wrapper for :py:func:`np.empty <numpy.empty>`.
55
55
56
56
See its docstring for more information.
57
57
"""
58
- from ._array_object import ndarray
58
+ from ._array_object import Array
59
59
if device is not None :
60
- # Note: Device support is not yet implemented on ndarray
60
+ # Note: Device support is not yet implemented on Array
61
61
raise NotImplementedError ("Device support is not yet implemented" )
62
- return ndarray ._new (np .empty (shape , dtype = dtype ))
62
+ return Array ._new (np .empty (shape , dtype = dtype ))
63
63
64
64
def empty_like (x : Array , / , * , dtype : Optional [Dtype ] = None , device : Optional [Device ] = None ) -> Array :
65
65
"""
66
66
Array API compatible wrapper for :py:func:`np.empty_like <numpy.empty_like>`.
67
67
68
68
See its docstring for more information.
69
69
"""
70
- from ._array_object import ndarray
70
+ from ._array_object import Array
71
71
if device is not None :
72
- # Note: Device support is not yet implemented on ndarray
72
+ # Note: Device support is not yet implemented on Array
73
73
raise NotImplementedError ("Device support is not yet implemented" )
74
- return ndarray ._new (np .empty_like (x ._array , dtype = dtype ))
74
+ return Array ._new (np .empty_like (x ._array , dtype = dtype ))
75
75
76
76
def eye (n_rows : int , n_cols : Optional [int ] = None , / , * , k : Optional [int ] = 0 , dtype : Optional [Dtype ] = None , device : Optional [Device ] = None ) -> Array :
77
77
"""
78
78
Array API compatible wrapper for :py:func:`np.eye <numpy.eye>`.
79
79
80
80
See its docstring for more information.
81
81
"""
82
- from ._array_object import ndarray
82
+ from ._array_object import Array
83
83
if device is not None :
84
- # Note: Device support is not yet implemented on ndarray
84
+ # Note: Device support is not yet implemented on Array
85
85
raise NotImplementedError ("Device support is not yet implemented" )
86
- return ndarray ._new (np .eye (n_rows , M = n_cols , k = k , dtype = dtype ))
86
+ return Array ._new (np .eye (n_rows , M = n_cols , k = k , dtype = dtype ))
87
87
88
88
def from_dlpack (x : object , / ) -> Array :
89
- # Note: dlpack support is not yet implemented on ndarray
89
+ # Note: dlpack support is not yet implemented on Array
90
90
raise NotImplementedError ("DLPack support is not yet implemented" )
91
91
92
92
def full (shape : Union [int , Tuple [int , ...]], fill_value : Union [int , float ], * , dtype : Optional [Dtype ] = None , device : Optional [Device ] = None ) -> Array :
@@ -95,101 +95,101 @@ def full(shape: Union[int, Tuple[int, ...]], fill_value: Union[int, float], *, d
95
95
96
96
See its docstring for more information.
97
97
"""
98
- from ._array_object import ndarray
98
+ from ._array_object import Array
99
99
if device is not None :
100
- # Note: Device support is not yet implemented on ndarray
100
+ # Note: Device support is not yet implemented on Array
101
101
raise NotImplementedError ("Device support is not yet implemented" )
102
- if isinstance (fill_value , ndarray ) and fill_value .ndim == 0 :
103
- fill_value = fill_value ._array [...]
102
+ if isinstance (fill_value , Array ) and fill_value .ndim == 0 :
103
+ fill_value = fill_value ._array [...]
104
104
res = np .full (shape , fill_value , dtype = dtype )
105
105
if res .dtype not in _all_dtypes :
106
106
# This will happen if the fill value is not something that NumPy
107
107
# coerces to one of the acceptable dtypes.
108
108
raise TypeError ("Invalid input to full" )
109
- return ndarray ._new (res )
109
+ return Array ._new (res )
110
110
111
111
def full_like (x : Array , / , fill_value : Union [int , float ], * , dtype : Optional [Dtype ] = None , device : Optional [Device ] = None ) -> Array :
112
112
"""
113
113
Array API compatible wrapper for :py:func:`np.full_like <numpy.full_like>`.
114
114
115
115
See its docstring for more information.
116
116
"""
117
- from ._array_object import ndarray
117
+ from ._array_object import Array
118
118
if device is not None :
119
- # Note: Device support is not yet implemented on ndarray
119
+ # Note: Device support is not yet implemented on Array
120
120
raise NotImplementedError ("Device support is not yet implemented" )
121
121
res = np .full_like (x ._array , fill_value , dtype = dtype )
122
122
if res .dtype not in _all_dtypes :
123
123
# This will happen if the fill value is not something that NumPy
124
124
# coerces to one of the acceptable dtypes.
125
125
raise TypeError ("Invalid input to full_like" )
126
- return ndarray ._new (res )
126
+ return Array ._new (res )
127
127
128
128
def linspace (start : Union [int , float ], stop : Union [int , float ], / , num : int , * , dtype : Optional [Dtype ] = None , device : Optional [Device ] = None , endpoint : bool = True ) -> Array :
129
129
"""
130
130
Array API compatible wrapper for :py:func:`np.linspace <numpy.linspace>`.
131
131
132
132
See its docstring for more information.
133
133
"""
134
- from ._array_object import ndarray
134
+ from ._array_object import Array
135
135
if device is not None :
136
- # Note: Device support is not yet implemented on ndarray
136
+ # Note: Device support is not yet implemented on Array
137
137
raise NotImplementedError ("Device support is not yet implemented" )
138
- return ndarray ._new (np .linspace (start , stop , num , dtype = dtype , endpoint = endpoint ))
138
+ return Array ._new (np .linspace (start , stop , num , dtype = dtype , endpoint = endpoint ))
139
139
140
140
def meshgrid (* arrays : Sequence [Array ], indexing : str = 'xy' ) -> List [Array , ...]:
141
141
"""
142
142
Array API compatible wrapper for :py:func:`np.meshgrid <numpy.meshgrid>`.
143
143
144
144
See its docstring for more information.
145
145
"""
146
- from ._array_object import ndarray
147
- return [ndarray ._new (array ) for array in np .meshgrid (* [a ._array for a in arrays ], indexing = indexing )]
146
+ from ._array_object import Array
147
+ return [Array ._new (array ) for array in np .meshgrid (* [a ._array for a in arrays ], indexing = indexing )]
148
148
149
149
def ones (shape : Union [int , Tuple [int , ...]], * , dtype : Optional [Dtype ] = None , device : Optional [Device ] = None ) -> Array :
150
150
"""
151
151
Array API compatible wrapper for :py:func:`np.ones <numpy.ones>`.
152
152
153
153
See its docstring for more information.
154
154
"""
155
- from ._array_object import ndarray
155
+ from ._array_object import Array
156
156
if device is not None :
157
- # Note: Device support is not yet implemented on ndarray
157
+ # Note: Device support is not yet implemented on Array
158
158
raise NotImplementedError ("Device support is not yet implemented" )
159
- return ndarray ._new (np .ones (shape , dtype = dtype ))
159
+ return Array ._new (np .ones (shape , dtype = dtype ))
160
160
161
161
def ones_like (x : Array , / , * , dtype : Optional [Dtype ] = None , device : Optional [Device ] = None ) -> Array :
162
162
"""
163
163
Array API compatible wrapper for :py:func:`np.ones_like <numpy.ones_like>`.
164
164
165
165
See its docstring for more information.
166
166
"""
167
- from ._array_object import ndarray
167
+ from ._array_object import Array
168
168
if device is not None :
169
- # Note: Device support is not yet implemented on ndarray
169
+ # Note: Device support is not yet implemented on Array
170
170
raise NotImplementedError ("Device support is not yet implemented" )
171
- return ndarray ._new (np .ones_like (x ._array , dtype = dtype ))
171
+ return Array ._new (np .ones_like (x ._array , dtype = dtype ))
172
172
173
173
def zeros (shape : Union [int , Tuple [int , ...]], * , dtype : Optional [Dtype ] = None , device : Optional [Device ] = None ) -> Array :
174
174
"""
175
175
Array API compatible wrapper for :py:func:`np.zeros <numpy.zeros>`.
176
176
177
177
See its docstring for more information.
178
178
"""
179
- from ._array_object import ndarray
179
+ from ._array_object import Array
180
180
if device is not None :
181
- # Note: Device support is not yet implemented on ndarray
181
+ # Note: Device support is not yet implemented on Array
182
182
raise NotImplementedError ("Device support is not yet implemented" )
183
- return ndarray ._new (np .zeros (shape , dtype = dtype ))
183
+ return Array ._new (np .zeros (shape , dtype = dtype ))
184
184
185
185
def zeros_like (x : Array , / , * , dtype : Optional [Dtype ] = None , device : Optional [Device ] = None ) -> Array :
186
186
"""
187
187
Array API compatible wrapper for :py:func:`np.zeros_like <numpy.zeros_like>`.
188
188
189
189
See its docstring for more information.
190
190
"""
191
- from ._array_object import ndarray
191
+ from ._array_object import Array
192
192
if device is not None :
193
- # Note: Device support is not yet implemented on ndarray
193
+ # Note: Device support is not yet implemented on Array
194
194
raise NotImplementedError ("Device support is not yet implemented" )
195
- return ndarray ._new (np .zeros_like (x ._array , dtype = dtype ))
195
+ return Array ._new (np .zeros_like (x ._array , dtype = dtype ))
0 commit comments