Check cupy lazily. (#7752)
This commit is contained in:
parent
af0cf88921
commit
b3ba0e8708
@ -17,7 +17,7 @@ from inspect import signature, Parameter
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
import scipy.sparse
|
import scipy.sparse
|
||||||
|
|
||||||
from .compat import STRING_TYPES, DataFrame, py_str, PANDAS_INSTALLED, lazy_isinstance
|
from .compat import STRING_TYPES, DataFrame, py_str, PANDAS_INSTALLED
|
||||||
from .libpath import find_lib_path
|
from .libpath import find_lib_path
|
||||||
from ._typing import (
|
from ._typing import (
|
||||||
CStrPptr,
|
CStrPptr,
|
||||||
@ -2080,8 +2080,13 @@ class Booster:
|
|||||||
f"got {data.shape[1]}"
|
f"got {data.shape[1]}"
|
||||||
)
|
)
|
||||||
|
|
||||||
from .data import _is_pandas_df, _transform_pandas_df, _is_cudf_df
|
from .data import (
|
||||||
from .data import _array_interface
|
_is_pandas_df,
|
||||||
|
_transform_pandas_df,
|
||||||
|
_is_cudf_df,
|
||||||
|
_is_cupy_array,
|
||||||
|
_array_interface,
|
||||||
|
)
|
||||||
enable_categorical = _has_categorical(self, data)
|
enable_categorical = _has_categorical(self, data)
|
||||||
if _is_pandas_df(data):
|
if _is_pandas_df(data):
|
||||||
data, _, _ = _transform_pandas_df(data, enable_categorical)
|
data, _, _ = _transform_pandas_df(data, enable_categorical)
|
||||||
@ -2118,9 +2123,7 @@ class Booster:
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
return _prediction_output(shape, dims, preds, False)
|
return _prediction_output(shape, dims, preds, False)
|
||||||
if lazy_isinstance(data, "cupy.core.core", "ndarray") or lazy_isinstance(
|
if _is_cupy_array(data):
|
||||||
data, "cupy._core.core", "ndarray"
|
|
||||||
):
|
|
||||||
from .data import _transform_cupy_array
|
from .data import _transform_cupy_array
|
||||||
|
|
||||||
data = _transform_cupy_array(data)
|
data = _transform_cupy_array(data)
|
||||||
|
|||||||
@ -688,12 +688,10 @@ def _is_cudf_ser(data):
|
|||||||
return isinstance(data, cudf.Series)
|
return isinstance(data, cudf.Series)
|
||||||
|
|
||||||
|
|
||||||
def _is_cupy_array(data):
|
def _is_cupy_array(data: Any) -> bool:
|
||||||
try:
|
return lazy_isinstance(data, "cupy.core.core", "ndarray") or lazy_isinstance(
|
||||||
import cupy
|
data, "cupy._core.core", "ndarray"
|
||||||
except ImportError:
|
)
|
||||||
return False
|
|
||||||
return isinstance(data, cupy.ndarray)
|
|
||||||
|
|
||||||
|
|
||||||
def _transform_cupy_array(data):
|
def _transform_cupy_array(data):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user