| 108 | |
| 109 | template <typename T> |
| 110 | void LoadScalarField(dmlc::Stream* strm, const std::string& expected_name, |
| 111 | xgboost::DataType expected_type, T* field) { |
| 112 | const std::string invalid{"MetaInfo: Invalid format for " + expected_name}; |
| 113 | std::string name; |
| 114 | xgboost::DataType type; |
| 115 | bool is_scalar; |
| 116 | CHECK(strm->Read(&name)) << invalid; |
| 117 | CHECK_EQ(name, expected_name) << invalid << " Expected field: " << expected_name |
| 118 | << ", got: " << name; |
| 119 | uint8_t type_val; |
| 120 | CHECK(strm->Read(&type_val)) << invalid; |
| 121 | type = static_cast<xgboost::DataType>(type_val); |
| 122 | CHECK(type == expected_type) << invalid |
| 123 | << "Expected field of type: " << static_cast<int>(expected_type) |
| 124 | << ", " |
| 125 | << "got field type: " << static_cast<int>(type); |
| 126 | CHECK(strm->Read(&is_scalar)) << invalid; |
| 127 | CHECK(is_scalar) << invalid << "Expected field " << expected_name |
| 128 | << " to be a scalar; got a vector"; |
| 129 | CHECK(strm->Read(field)) << invalid; |
| 130 | } |
| 131 | |
| 132 | template <typename T> |
| 133 | void LoadVectorField(dmlc::Stream* strm, const std::string& expected_name, |