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

Function ArrayInterface

include/xgboost/linalg.h:690–717  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

688 */
689template <typename T, std::int32_t D>
690Json ArrayInterface(TensorView<T const, D> const &t) {
691 Json array_interface{Object{}};
692 array_interface["data"] = std::vector<Json>(2);
693 array_interface["data"][0] = Integer{reinterpret_cast<int64_t>(t.Values().data())};
694 array_interface["data"][1] = Boolean{true};
695 if (t.Device().IsCUDA()) {
696 // Change this once we have different CUDA stream.
697 array_interface["stream"] = Integer{2};
698 }
699 std::vector<Json> shape(t.Shape().size());
700 std::vector<Json> stride(t.Stride().size());
701 for (size_t i = 0; i < t.Shape().size(); ++i) {
702 shape[i] = Integer(t.Shape(i));
703 stride[i] = Integer(t.Stride(i) * sizeof(T));
704 }
705 array_interface["shape"] = Array{shape};
706 array_interface["strides"] = Array{stride};
707 array_interface["version"] = 3;
708
709 char constexpr kT = detail::ArrayInterfaceHandler::TypeChar<T>();
710 static_assert(kT != '\0');
711 if (DMLC_LITTLE_ENDIAN) {
712 array_interface["typestr"] = String{"<" + (kT + std::to_string(sizeof(T)))};
713 } else {
714 array_interface["typestr"] = String{">" + (kT + std::to_string(sizeof(T)))};
715 }
716 return array_interface;
717}
718
719/**
720 * \brief Same as const version, but returns non-readonly data pointer.

Callers 3

ArrayInterfaceStrFunction · 0.70
TESTFunction · 0.50

Calls 6

ValuesMethod · 0.80
ShapeMethod · 0.80
dataMethod · 0.45
IsCUDAMethod · 0.45
DeviceMethod · 0.45
sizeMethod · 0.45

Tested by 1

TESTFunction · 0.40