MCPcopy Index your code
hub / github.com/scikit-learn/scikit-learn / device

Function device

sklearn/utils/_array_api.py:207–248  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

205
206
207def 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
251def size(x):

Callers 15

_class_meansFunction · 0.90
_solve_svdMethod · 0.90
_fit_and_scoreFunction · 0.90
cross_val_predictFunction · 0.90
_randomized_range_finderFunction · 0.90
svd_flipFunction · 0.90
_map_to_integerFunction · 0.90
inverse_transformMethod · 0.90
partial_fitMethod · 0.90
transformMethod · 0.90
inverse_transformMethod · 0.90
partial_fitMethod · 0.90

Calls 2

_remove_non_arraysFunction · 0.85
_single_array_deviceFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…