MCPcopy Create free account
hub / github.com/dmlc/xgboost / CopyTensorInfoImpl

Function CopyTensorInfoImpl

src/data/data.cc:489–517  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

487namespace {
488template <int32_t D, typename T>
489void 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
519void ReshapeInfo(bst_idx_t n_samples, linalg::Matrix<float>* p_info, StringView name) {
520 if (n_samples != 0 && p_info->Shape(0) != n_samples) {

Callers 1

SetInfoFromHostMethod · 0.85

Calls 12

CPUFunction · 0.85
TransformIdxKernelFunction · 0.85
ReshapeMethod · 0.80
ModifyInplaceMethod · 0.80
HostPointerMethod · 0.80
ShapeMethod · 0.80
ThreadsMethod · 0.80
DispatchDTypeFunction · 0.70
CapacityMethod · 0.45
dataMethod · 0.45
ResizeMethod · 0.45
ViewMethod · 0.45

Tested by

no test coverage detected