Hardware device where the array data resides on. If the hardware device is not the same for all arrays, an error is raised. Parameters ---------- *array_list : arrays List of array instances from NumPy or an array API compatible library. remove_none : bool, default=Tru
(*array_list, remove_none=True, remove_types=REMOVE_TYPES_DEFAULT)
| 205 | |
| 206 | |
| 207 | def device(*array_list, remove_none=True, remove_types=REMOVE_TYPES_DEFAULT): |
| 208 | """Hardware device where the array data resides on. |
| 209 | |
| 210 | If the hardware device is not the same for all arrays, an error is raised. |
| 211 | |
| 212 | Parameters |
| 213 | ---------- |
| 214 | *array_list : arrays |
| 215 | List of array instances from NumPy or an array API compatible library. |
| 216 | |
| 217 | remove_none : bool, default=True |
| 218 | Whether to ignore None objects passed in array_list. |
| 219 | |
| 220 | remove_types : tuple or list, default=(str, list, tuple) |
| 221 | Types to ignore in array_list. |
| 222 | |
| 223 | Returns |
| 224 | ------- |
| 225 | out : device |
| 226 | `device` object (see the "Device Support" section of the array API spec). |
| 227 | """ |
| 228 | array_list = _remove_non_arrays( |
| 229 | *array_list, remove_none=remove_none, remove_types=remove_types |
| 230 | ) |
| 231 | |
| 232 | if not array_list: |
| 233 | return None |
| 234 | |
| 235 | device_ = _single_array_device(array_list[0]) |
| 236 | |
| 237 | # Note: here we cannot simply use a Python `set` as it requires |
| 238 | # hashable members which is not guaranteed for Array API device |
| 239 | # objects. In particular, CuPy devices are not hashable at the |
| 240 | # time of writing. |
| 241 | for array in array_list[1:]: |
| 242 | device_other = _single_array_device(array) |
| 243 | if device_ != device_other: |
| 244 | raise ValueError( |
| 245 | f"Input arrays use different devices: {device_}, {device_other}" |
| 246 | ) |
| 247 | |
| 248 | return device_ |
| 249 | |
| 250 | |
| 251 | def size(x): |
no test coverage detected
searching dependent graphs…