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)
| 997 | |
| 998 | |
| 999 | def _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 | |
| 1021 | def _estimator_with_converted_arrays(estimator, converter): |
searching dependent graphs…