@@ -34,7 +34,7 @@ class __array_namespace_info__:
34
34
35
35
Examples
36
36
--------
37
- >>> info = np .__array_namespace_info__()
37
+ >>> info = xp .__array_namespace_info__()
38
38
>>> info.default_dtypes()
39
39
{'real floating': numpy.float64,
40
40
'complex floating': numpy.complex128,
@@ -76,16 +76,16 @@ def capabilities(self):
76
76
77
77
Examples
78
78
--------
79
- >>> info = np .__array_namespace_info__()
79
+ >>> info = xp .__array_namespace_info__()
80
80
>>> info.capabilities()
81
81
{'boolean indexing': True,
82
- 'data-dependent shapes': True}
82
+ 'data-dependent shapes': True,
83
+ 'max dimensions': 64}
83
84
84
85
"""
85
86
return {
86
87
"boolean indexing" : True ,
87
88
"data-dependent shapes" : True ,
88
- # 'max rank' will be part of the 2024.12 standard
89
89
"max dimensions" : 64 ,
90
90
}
91
91
@@ -102,15 +102,24 @@ def default_device(self):
102
102
103
103
Returns
104
104
-------
105
- device : str
105
+ device : Device
106
106
The default device used for new PyTorch arrays.
107
107
108
108
Examples
109
109
--------
110
- >>> info = np .__array_namespace_info__()
110
+ >>> info = xp .__array_namespace_info__()
111
111
>>> info.default_device()
112
- 'cpu'
112
+ device(type= 'cpu')
113
113
114
+ Notes
115
+ -----
116
+ This method returns the static default device when PyTorch is initialized.
117
+ However, the *current* device used by creation functions (``empty`` etc.)
118
+ can be changed at runtime.
119
+
120
+ See Also
121
+ --------
122
+ https://github.com/data-apis/array-api/issues/835
114
123
"""
115
124
return torch .device ("cpu" )
116
125
@@ -120,9 +129,9 @@ def default_dtypes(self, *, device=None):
120
129
121
130
Parameters
122
131
----------
123
- device : str , optional
124
- The device to get the default data types for. For PyTorch, only
125
- ``'cpu'`` is allowed .
132
+ device : Device , optional
133
+ The device to get the default data types for.
134
+ Unused for PyTorch, as all devices use the same default dtypes .
126
135
127
136
Returns
128
137
-------
@@ -139,7 +148,7 @@ def default_dtypes(self, *, device=None):
139
148
140
149
Examples
141
150
--------
142
- >>> info = np .__array_namespace_info__()
151
+ >>> info = xp .__array_namespace_info__()
143
152
>>> info.default_dtypes()
144
153
{'real floating': torch.float32,
145
154
'complex floating': torch.complex64,
@@ -250,8 +259,9 @@ def dtypes(self, *, device=None, kind=None):
250
259
251
260
Parameters
252
261
----------
253
- device : str , optional
262
+ device : Device , optional
254
263
The device to get the data types for.
264
+ Unused for PyTorch, as all devices use the same dtypes.
255
265
kind : str or tuple of str, optional
256
266
The kind of data types to return. If ``None``, all data types are
257
267
returned. If a string, only data types of that kind are returned.
@@ -287,7 +297,7 @@ def dtypes(self, *, device=None, kind=None):
287
297
288
298
Examples
289
299
--------
290
- >>> info = np .__array_namespace_info__()
300
+ >>> info = xp .__array_namespace_info__()
291
301
>>> info.dtypes(kind='signed integer')
292
302
{'int8': numpy.int8,
293
303
'int16': numpy.int16,
@@ -310,7 +320,7 @@ def devices(self):
310
320
311
321
Returns
312
322
-------
313
- devices : list of str
323
+ devices : list[Device]
314
324
The devices supported by PyTorch.
315
325
316
326
See Also
@@ -322,7 +332,7 @@ def devices(self):
322
332
323
333
Examples
324
334
--------
325
- >>> info = np .__array_namespace_info__()
335
+ >>> info = xp .__array_namespace_info__()
326
336
>>> info.devices()
327
337
[device(type='cpu'), device(type='mps', index=0), device(type='meta')]
328
338
@@ -333,6 +343,7 @@ def devices(self):
333
343
# device:
334
344
try :
335
345
torch .device ('notadevice' )
346
+ raise AssertionError ("unreachable" ) # pragma: nocover
336
347
except RuntimeError as e :
337
348
# The error message is something like:
338
349
# "Expected one of cpu, cuda, ipu, xpu, mkldnn, opengl, opencl, ideep, hip, ve, fpga, ort, xla, lazy, vulkan, mps, meta, hpu, mtia, privateuseone device type at start of device string: notadevice"
0 commit comments