| 210 | |
| 211 | template <typename T> |
| 212 | Json GetArrayInterface(HostDeviceVector<T> const* storage, size_t rows, size_t cols) { |
| 213 | Json array_interface{Object()}; |
| 214 | array_interface["data"] = std::vector<Json>(2); |
| 215 | if (storage->DeviceCanRead()) { |
| 216 | array_interface["data"][0] = Integer{reinterpret_cast<int64_t>(storage->ConstDevicePointer())}; |
| 217 | array_interface["stream"] = nullptr; |
| 218 | } else { |
| 219 | array_interface["data"][0] = Integer{reinterpret_cast<int64_t>(storage->ConstHostPointer())}; |
| 220 | } |
| 221 | array_interface["data"][1] = Boolean(false); |
| 222 | |
| 223 | array_interface["shape"] = std::vector<Json>(2); |
| 224 | array_interface["shape"][0] = rows; |
| 225 | array_interface["shape"][1] = cols; |
| 226 | |
| 227 | char t = linalg::detail::ArrayInterfaceHandler::TypeChar<T>(); |
| 228 | array_interface["typestr"] = String(std::string{"<"} + t + std::to_string(sizeof(T))); |
| 229 | array_interface["version"] = 3; |
| 230 | return array_interface; |
| 231 | } |
| 232 | |
| 233 | // Generate in-memory random data without using DMatrix. |
| 234 | class RandomDataGenerator { |