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

Function LoadTensorField

src/data/data.cc:169–195  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

167
168template <typename T, int32_t D>
169void LoadTensorField(dmlc::Stream* strm, std::string const& expected_name,
170 xgboost::DataType expected_type, xgboost::linalg::Tensor<T, D>* p_out) {
171 const std::string invalid{"MetaInfo: Invalid format for " + expected_name};
172 std::string name;
173 xgboost::DataType type;
174 bool is_scalar;
175 CHECK(strm->Read(&name)) << invalid;
176 CHECK_EQ(name, expected_name) << invalid << " Expected field: " << expected_name
177 << ", got: " << name;
178 uint8_t type_val;
179 CHECK(strm->Read(&type_val)) << invalid;
180 type = static_cast<xgboost::DataType>(type_val);
181 CHECK(type == expected_type) << invalid
182 << "Expected field of type: " << static_cast<int>(expected_type)
183 << ", "
184 << "got field type: " << static_cast<int>(type);
185 CHECK(strm->Read(&is_scalar)) << invalid;
186 CHECK(!is_scalar) << invalid << "Expected field " << expected_name
187 << " to be a tensor; got a scalar";
188 size_t shape[D];
189 for (size_t i = 0; i < D; ++i) {
190 CHECK(strm->Read(&(shape[i])));
191 }
192 p_out->Reshape(shape);
193 auto& field = p_out->Data()->HostVector();
194 CHECK(strm->Read(&field)) << invalid;
195}
196} // anonymous namespace
197
198namespace xgboost {

Callers 1

LoadBinaryMethod · 0.85

Calls 3

ReshapeMethod · 0.80
ReadMethod · 0.45
DataMethod · 0.45

Tested by

no test coverage detected