[backport] Make sure input numpy array is aligned. (#8690) (#8696) (#8734)

* [backport] Make sure input numpy array is aligned. (#8690)

- use `np.require` to specify that the alignment is required.
- scipy csr as well.
- validate input pointer in `ArrayInterface`.

* Workaround CUDA warning. (#8696)

* backport from half type support for alignment.

* fix import.
This commit is contained in:
Jiaming Yuan
2023-02-06 16:58:15 +08:00
committed by GitHub
parent 68d86336d7
commit 2f22f8d49b
5 changed files with 66 additions and 25 deletions

View File

@@ -326,7 +326,7 @@ class TestDMatrix:
nrow = 100
ncol = 1000
x = rand(nrow, ncol, density=0.0005, format='csr', random_state=rng)
assert x.indices.max() < ncol - 1
assert x.indices.max() < ncol
x.data[:] = 1
dtrain = xgb.DMatrix(x, label=rng.binomial(1, 0.3, nrow))
assert (dtrain.num_row(), dtrain.num_col()) == (nrow, ncol)