| 10 | |
| 11 | namespace xgboost { |
| 12 | TEST(ArrayInterface, Initialize) { |
| 13 | size_t constexpr kRows = 10, kCols = 10; |
| 14 | HostDeviceVector<float> storage; |
| 15 | auto array = RandomDataGenerator{kRows, kCols, 0}.GenerateArrayInterface(&storage); |
| 16 | auto arr_interface = ArrayInterface<2>(StringView{array}); |
| 17 | ASSERT_EQ(arr_interface.Shape<0>(), kRows); |
| 18 | ASSERT_EQ(arr_interface.Shape<1>(), kCols); |
| 19 | ASSERT_EQ(arr_interface.data, storage.ConstHostPointer()); |
| 20 | ASSERT_EQ(arr_interface.ElementSize(), 4); |
| 21 | ASSERT_EQ(arr_interface.type, ArrayInterfaceHandler::kF4); |
| 22 | |
| 23 | HostDeviceVector<size_t> u64_storage(storage.Size()); |
| 24 | std::string u64_arr_str{ArrayInterfaceStr(linalg::TensorView<size_t const, 2>{ |
| 25 | u64_storage.ConstHostSpan(), {kRows, kCols}, DeviceOrd::CPU()})}; |
| 26 | std::copy(storage.ConstHostVector().cbegin(), storage.ConstHostVector().cend(), |
| 27 | u64_storage.HostSpan().begin()); |
| 28 | auto u64_arr = ArrayInterface<2>{u64_arr_str}; |
| 29 | ASSERT_EQ(u64_arr.ElementSize(), 8); |
| 30 | ASSERT_EQ(u64_arr.type, ArrayInterfaceHandler::kU8); |
| 31 | } |
| 32 | |
| 33 | TEST(ArrayInterface, Error) { |
| 34 | constexpr size_t kRows = 16, kCols = 10; |
nothing calls this directly
no test coverage detected