Skip to content

Commit

Permalink
Use RandomState
Browse files Browse the repository at this point in the history
  • Loading branch information
RAMitchell committed Jun 4, 2020
1 parent a5722a1 commit df87dc1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
7 changes: 6 additions & 1 deletion tests/python-gpu/test_device_quantile_dmatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import xgboost as xgb
import unittest
import pytest
import cupy as cp
import sys

sys.path.append("tests/python")
import testing as tm


class TestDeviceQuantileDMatrix(unittest.TestCase):
Expand All @@ -12,6 +15,8 @@ def test_dmatrix_numpy_init(self):
with pytest.raises(AssertionError, match='is not supported for DeviceQuantileDMatrix'):
dm = xgb.DeviceQuantileDMatrix(data, np.ones(5, dtype=np.float64))

@pytest.mark.skipif(**tm.no_cupy())
def test_dmatrix_cupy_init(self):
import cupy as cp
data = cp.random.randn(5, 5)
dm = xgb.DeviceQuantileDMatrix(data, cp.ones(5, dtype=np.float64))
1 change: 1 addition & 0 deletions tests/python-gpu/test_gpu_updaters.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def test_gpu_hist_device_dmatrix(self):
device_dmatrix_datasets = ["Boston", "Cancer", "Digits"]
for param in test_param:
param['tree_method'] = 'gpu_hist'

gpu_results_device_dmatrix = run_suite(param, select_datasets=device_dmatrix_datasets,
DMatrixT=xgb.DeviceQuantileDMatrix,
dmatrix_params={'max_bin': param['max_bin']})
Expand Down
10 changes: 5 additions & 5 deletions tests/python/regression_test_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def get_sparse():
n = 2000
sparsity = 0.75
X, y = datasets.make_regression(n, random_state=rng)
flag = np.random.binomial(1, sparsity, X.shape)
flag = rng.binomial(1, sparsity, X.shape)
for i in range(X.shape[0]):
for j in range(X.shape[1]):
if flag[i, j]:
Expand All @@ -85,16 +85,16 @@ def get_small_weights():

@memory.cache
def get_weights_regression(min_weight, max_weight):
np.random.seed(199)
rng = np.random.RandomState(199)
n = 2000
sparsity = 0.25
X, y = datasets.make_regression(n, random_state=199)
flag = np.random.binomial(1, sparsity, X.shape)
X, y = datasets.make_regression(n, random_state=rng)
flag = rng.binomial(1, sparsity, X.shape)
for i in range(X.shape[0]):
for j in range(X.shape[1]):
if flag[i, j]:
X[i, j] = np.nan
w = np.random.uniform(min_weight, max_weight, n)
w = rng.uniform(min_weight, max_weight, n)
return X, y, w


Expand Down

0 comments on commit df87dc1

Please sign in to comment.