Accept numpy array view. (#4147)

* Accept array view (slice) in metainfo.
This commit is contained in:
Jiaming Yuan
2019-02-18 22:21:34 +08:00
committed by GitHub
parent 0ff84d950e
commit a985a99cf0
6 changed files with 152 additions and 43 deletions

View File

@@ -63,6 +63,12 @@ class TestBasic(unittest.TestCase):
# assert they are the same
assert np.sum(np.abs(preds2 - preds)) == 0
def test_np_view(self):
y = np.array([12, 34, 56], np.float32)[::2]
from_view = xgb.DMatrix([], label=y).get_label()
from_array = xgb.DMatrix([], label=y + 0).get_label()
assert (from_view == from_array).all()
def test_record_results(self):
dtrain = xgb.DMatrix(dpath + 'agaricus.txt.train')
dtest = xgb.DMatrix(dpath + 'agaricus.txt.test')