| 487 | namespace { |
| 488 | template <int32_t D, typename T> |
| 489 | void CopyTensorInfoImpl(Context const* ctx, Json arr_interface, linalg::Tensor<T, D>* p_out) { |
| 490 | ArrayInterface<D> array{arr_interface}; |
| 491 | if (array.n == 0) { |
| 492 | p_out->Reshape(array.shape); |
| 493 | return; |
| 494 | } |
| 495 | CHECK_EQ(array.valid.Capacity(), 0) |
| 496 | << "Meta info like label or weight can not have missing value."; |
| 497 | if (array.is_contiguous && array.type == ToDType<T>::kType) { |
| 498 | // Handle contigious |
| 499 | p_out->ModifyInplace([&](HostDeviceVector<T>* data, common::Span<size_t, D> shape) { |
| 500 | // set shape |
| 501 | std::copy(array.shape, array.shape + D, shape.data()); |
| 502 | // set data |
| 503 | data->Resize(array.n); |
| 504 | std::memcpy(data->HostPointer(), array.data, array.n * sizeof(T)); |
| 505 | }); |
| 506 | return; |
| 507 | } |
| 508 | p_out->Reshape(array.shape); |
| 509 | auto t_out = p_out->View(DeviceOrd::CPU()); |
| 510 | CHECK(t_out.CContiguous()); |
| 511 | auto const shape = t_out.Shape(); |
| 512 | DispatchDType(array, DeviceOrd::CPU(), [&](auto&& in) { |
| 513 | linalg::cpu_impl::TransformIdxKernel(t_out, ctx->Threads(), [&](auto i, auto) { |
| 514 | return std::apply(in, linalg::UnravelIndex<D>(i, shape)); |
| 515 | }); |
| 516 | }); |
| 517 | } |
| 518 | |
| 519 | void ReshapeInfo(bst_idx_t n_samples, linalg::Matrix<float>* p_info, StringView name) { |
| 520 | if (n_samples != 0 && p_info->Shape(0) != n_samples) { |
no test coverage detected