Support for all primitive types from array. (#7003)
* Change C API name. * Test for all primitive types from array. * Add native support for CPU 128 float. * Convert boolean and float16 in Python. * Fix dask version for now.
This commit is contained in:
@@ -237,3 +237,51 @@ class TestInplacePredict:
|
||||
dtrain = xgb.DMatrix(self.X, self.y, base_margin=base_margin)
|
||||
from_dmatrix = booster.predict(dtrain)
|
||||
np.testing.assert_allclose(from_dmatrix, from_inplace)
|
||||
|
||||
def test_dtypes(self):
|
||||
orig = self.rng.randint(low=0, high=127, size=self.rows * self.cols).reshape(
|
||||
self.rows, self.cols
|
||||
)
|
||||
predt_orig = self.booster.inplace_predict(orig)
|
||||
# all primitive types in numpy
|
||||
for dtype in [
|
||||
np.signedinteger,
|
||||
np.byte,
|
||||
np.short,
|
||||
np.intc,
|
||||
np.int_,
|
||||
np.longlong,
|
||||
np.unsignedinteger,
|
||||
np.ubyte,
|
||||
np.ushort,
|
||||
np.uintc,
|
||||
np.uint,
|
||||
np.ulonglong,
|
||||
np.floating,
|
||||
np.half,
|
||||
np.single,
|
||||
np.double,
|
||||
]:
|
||||
X = np.array(orig, dtype=dtype)
|
||||
predt = self.booster.inplace_predict(X)
|
||||
np.testing.assert_allclose(predt, predt_orig)
|
||||
|
||||
# boolean
|
||||
orig = self.rng.binomial(1, 0.5, size=self.rows * self.cols).reshape(
|
||||
self.rows, self.cols
|
||||
)
|
||||
predt_orig = self.booster.inplace_predict(orig)
|
||||
for dtype in [np.bool8, np.bool_]:
|
||||
X = np.array(orig, dtype=dtype)
|
||||
predt = self.booster.inplace_predict(X)
|
||||
np.testing.assert_allclose(predt, predt_orig)
|
||||
|
||||
# unsupported types
|
||||
for dtype in [
|
||||
np.string_,
|
||||
np.complex64,
|
||||
np.complex128,
|
||||
]:
|
||||
X = np.array(orig, dtype=dtype)
|
||||
with pytest.raises(ValueError):
|
||||
self.booster.inplace_predict(X)
|
||||
|
||||
Reference in New Issue
Block a user