MCPcopy
hub / github.com/scikit-learn/scikit-learn / _convert_to_numpy

Function _convert_to_numpy

sklearn/utils/_array_api.py:999–1018  ·  view source on GitHub ↗

Convert X into a NumPy ndarray on the CPU. This function uses library-specific methods to convert the array to a NumPy ndarray on the CPU. It is only meant as a fallback when move_to fails to use the DLPACK protocol. This function is not meant to be called directly and `move_to

(array, xp)

Source from the content-addressed store, hash-verified

997
998
999def _convert_to_numpy(array, xp):
1000 """Convert X into a NumPy ndarray on the CPU.
1001
1002 This function uses library-specific methods to convert the array to a NumPy
1003 ndarray on the CPU. It is only meant as a fallback when move_to fails to use the
1004 DLPACK protocol.
1005
1006 This function is not meant to be called directly and
1007 `move_to(array, xp=np, device="cpu")` should be used instead.
1008 """
1009 if _is_xp_namespace(xp, "torch"):
1010 return array.cpu().numpy()
1011 elif _is_xp_namespace(xp, "cupy"): # pragma: nocover
1012 return array.get()
1013 elif _is_xp_namespace(xp, "array_api_strict"):
1014 return numpy.asarray(xp.asarray(array, device=xp.Device("CPU_DEVICE")))
1015 elif _is_xp_namespace(xp, "dpnp"): # pragma: nocover
1016 return array.asnumpy()
1017
1018 return numpy.asarray(array)
1019
1020
1021def _estimator_with_converted_arrays(estimator, converter):

Callers 4

move_toFunction · 0.85

Calls 2

_is_xp_namespaceFunction · 0.85
getMethod · 0.80

Used in the wild real call sites across dependent graphs

searching dependent graphs…