| 18 | |
| 19 | namespace xgboost { |
| 20 | std::string TypedArrayRef::ArrayInterfaceStr() const { |
| 21 | return data::DispatchDType(this->dtype, [this](auto dtype) { |
| 22 | using DType = decltype(dtype); |
| 23 | auto ptr = static_cast<std::add_pointer_t<std::add_const_t<DType>>>(this->data); |
| 24 | if (this->ndim == 1) { |
| 25 | auto vec = linalg::MakeVec(ptr, this->shape.front()); |
| 26 | return linalg::ArrayInterfaceStr(vec); |
| 27 | } else { |
| 28 | auto n = this->Size(); |
| 29 | if (ptr) { |
| 30 | CHECK_GT(n, 0); |
| 31 | } |
| 32 | if (n > 0) { |
| 33 | CHECK(ptr); |
| 34 | } |
| 35 | auto mat = linalg::MakeTensorView(DeviceOrd::CPU(), common::Span{ptr, n}, this->shape[0], |
| 36 | this->shape[1]); |
| 37 | return linalg::ArrayInterfaceStr(mat); |
| 38 | } |
| 39 | }); |
| 40 | } |
| 41 | } // namespace xgboost |
| 42 | |
| 43 | namespace xgboost::data { |
no test coverage detected