Returns a dictionary storing the CUDA array interface.
(data: _CudaArrayLikeArg)
| 94 | |
| 95 | |
| 96 | def cuda_array_interface_dict(data: _CudaArrayLikeArg) -> CudaArrayInf: |
| 97 | """Returns a dictionary storing the CUDA array interface.""" |
| 98 | if array_hasobject(data): |
| 99 | raise ValueError("Input data contains `object` dtype. Expecting numeric data.") |
| 100 | ainf = data.__cuda_array_interface__ |
| 101 | if "mask" in ainf and ainf["mask"] is not None: |
| 102 | mask_ainf = ainf["mask"].__cuda_array_interface__ # type: ignore[union-attr] |
| 103 | # Normalize the validity mask to XGBoost's expected layout (`|t1` bit field of |
| 104 | # length `n_samples`). |
| 105 | typestr = mask_ainf["typestr"] |
| 106 | n_samples = ainf["shape"][0] |
| 107 | if typestr[1] in ("u", "i", "t") and typestr[2:] == "1" and n_samples: |
| 108 | mask_ainf = dict(mask_ainf) |
| 109 | mask_ainf["typestr"] = "|t1" |
| 110 | mask_ainf["shape"] = (n_samples,) |
| 111 | mask_ainf.pop("strides", None) |
| 112 | ainf["mask"] = mask_ainf |
| 113 | return ainf |
| 114 | |
| 115 | |
| 116 | def cuda_array_interface(data: _CudaArrayLikeArg) -> bytes: |
no test coverage detected