Skip to content

Commit

Permalink
Don't use uint for threads. (#5542)
Browse files Browse the repository at this point in the history
  • Loading branch information
trivialfis authored Apr 17, 2020
1 parent bb29ce2 commit cfee9fa
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions python-package/xgboost/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,8 +498,8 @@ def __init__(self, data, label=None, weight=None, base_margin=None,
feature_types : list, optional
Set types for features.
nthread : integer, optional
Number of threads to use for loading data from numpy array. If -1,
uses maximum threads available on the system.
Number of threads to use for loading data when parallelization is
applicable. If -1, uses maximum threads available on the system.
"""
# force into void_p, mac need to pass things in as void_p
Expand All @@ -518,7 +518,8 @@ def __init__(self, data, label=None, weight=None, base_margin=None,
data, feature_names, feature_types = _convert_dataframes(
data, feature_names, feature_types
)
missing = np.nan if missing is None else missing
missing = missing if missing is not None else np.nan
nthread = nthread if nthread is not None else 1

if isinstance(data, (STRING_TYPES, os_PathLike)):
handle = ctypes.c_void_p()
Expand Down Expand Up @@ -609,15 +610,13 @@ def _init_from_npy2d(self, mat, missing, nthread):
# explicitly tell np.array to try and avoid copying)
data = np.array(mat.reshape(mat.size), copy=False, dtype=np.float32)
handle = ctypes.c_void_p()
missing = missing if missing is not None else np.nan
nthread = nthread if nthread is not None else 1
_check_call(_LIB.XGDMatrixCreateFromMat_omp(
data.ctypes.data_as(ctypes.POINTER(ctypes.c_float)),
c_bst_ulong(mat.shape[0]),
c_bst_ulong(mat.shape[1]),
ctypes.c_float(missing),
ctypes.byref(handle),
c_bst_ulong(nthread)))
ctypes.c_int(nthread)))
self.handle = handle

def _init_from_dt(self, data, nthread):
Expand Down Expand Up @@ -648,19 +647,18 @@ def _init_from_dt(self, data, nthread):
c_bst_ulong(data.shape[0]),
c_bst_ulong(data.shape[1]),
ctypes.byref(handle),
nthread))
ctypes.c_int(nthread)))
self.handle = handle

def _init_from_array_interface_columns(self, df, missing, nthread):
"""Initialize DMatrix from columnar memory format."""
interfaces_str = _cudf_array_interfaces(df)
handle = ctypes.c_void_p()
missing = missing if missing is not None else np.nan
nthread = nthread if nthread is not None else 1
_check_call(
_LIB.XGDMatrixCreateFromArrayInterfaceColumns(
interfaces_str,
ctypes.c_float(missing), ctypes.c_int(nthread),
ctypes.c_float(missing),
ctypes.c_int(nthread),
ctypes.byref(handle)))
self.handle = handle

Expand All @@ -672,12 +670,11 @@ def _init_from_array_interface(self, data, missing, nthread):
interface_str = bytes(json.dumps(interface, indent=2), 'utf-8')

handle = ctypes.c_void_p()
missing = missing if missing is not None else np.nan
nthread = nthread if nthread is not None else 1
_check_call(
_LIB.XGDMatrixCreateFromArrayInterface(
interface_str,
ctypes.c_float(missing), ctypes.c_int(nthread),
ctypes.c_float(missing),
ctypes.c_int(nthread),
ctypes.byref(handle)))
self.handle = handle

Expand Down

0 comments on commit cfee9fa

Please sign in to comment.