Drop support for loading remote files. (#9504)

This commit is contained in:
Jiaming Yuan
2023-08-21 23:34:05 +08:00
committed by GitHub
parent d779a11af9
commit 044fea1281
12 changed files with 43 additions and 112 deletions

View File

@@ -216,8 +216,8 @@ TEST(CAPI, JsonModelIO) {
std::string buffer;
Json::Dump(Json::Load(l, std::ios::binary), &buffer);
ASSERT_EQ(model_str_0.size() - 1, buffer.size());
ASSERT_EQ(model_str_0.back(), '\0');
ASSERT_EQ(model_str_0.size(), buffer.size());
ASSERT_EQ(model_str_0.back(), '}');
ASSERT_TRUE(std::equal(model_str_0.begin(), model_str_0.end() - 1, buffer.begin()));
ASSERT_EQ(XGBoosterSaveModelToBuffer(handle, R"({})", &len, &data), -1);

View File

@@ -63,31 +63,27 @@ TEST(IO, LoadSequentialFile) {
// Generate a JSON file.
size_t constexpr kRows = 1000, kCols = 100;
std::shared_ptr<DMatrix> p_dmat{
RandomDataGenerator{kRows, kCols, 0}.GenerateDMatrix(true)};
std::unique_ptr<Learner> learner { Learner::Create({p_dmat}) };
std::shared_ptr<DMatrix> p_dmat{RandomDataGenerator{kRows, kCols, 0}.GenerateDMatrix(true)};
std::unique_ptr<Learner> learner{Learner::Create({p_dmat})};
learner->SetParam("tree_method", "hist");
learner->Configure();
for (int32_t iter = 0; iter < 10; ++iter) {
learner->UpdateOneIter(iter, p_dmat);
}
Json out { Object() };
Json out{Object()};
learner->SaveModel(&out);
std::string str;
std::vector<char> str;
Json::Dump(out, &str);
std::string tmpfile = tempdir.path + "/model.json";
{
std::unique_ptr<dmlc::Stream> fo(
dmlc::Stream::Create(tmpfile.c_str(), "w"));
fo->Write(str.c_str(), str.size());
std::unique_ptr<dmlc::Stream> fo(dmlc::Stream::Create(tmpfile.c_str(), "w"));
fo->Write(str.data(), str.size());
}
auto loaded = LoadSequentialFile(tmpfile, true);
auto loaded = LoadSequentialFile(tmpfile);
ASSERT_EQ(loaded, str);
ASSERT_THROW(LoadSequentialFile("non-exist", true), dmlc::Error);
}
TEST(IO, Resource) {

View File

@@ -418,7 +418,7 @@ TEST(Json, AssigningString) {
TEST(Json, LoadDump) {
std::string ori_buffer = GetModelStr();
Json origin {Json::Load(StringView{ori_buffer.c_str(), ori_buffer.size()})};
Json origin{Json::Load(StringView{ori_buffer.c_str(), ori_buffer.size()})};
dmlc::TemporaryDirectory tempdir;
auto const& path = tempdir.path + "test_model_dump";
@@ -430,9 +430,9 @@ TEST(Json, LoadDump) {
ASSERT_TRUE(fout);
fout << out << std::flush;
std::string new_buffer = common::LoadSequentialFile(path);
std::vector<char> new_buffer = common::LoadSequentialFile(path);
Json load_back {Json::Load(StringView(new_buffer.c_str(), new_buffer.size()))};
Json load_back{Json::Load(StringView(new_buffer.data(), new_buffer.size()))};
ASSERT_EQ(load_back, origin);
}
@@ -651,7 +651,7 @@ TEST(UBJson, Basic) {
}
auto data = common::LoadSequentialFile("test.ubj");
UBJReader reader{StringView{data}};
UBJReader reader{StringView{data.data(), data.size()}};
json = reader.Load();
return json;
};

View File

@@ -250,7 +250,7 @@ auto TestSparsePageDMatrixDeterminism(int32_t threads) {
auto cache_name =
data::MakeId(filename, dynamic_cast<data::SparsePageDMatrix *>(sparse.get())) + ".row.page";
std::string cache = common::LoadSequentialFile(cache_name);
auto cache = common::LoadSequentialFile(cache_name);
return cache;
}
@@ -258,7 +258,7 @@ TEST(SparsePageDMatrix, Determinism) {
#if defined(_MSC_VER)
return;
#endif // defined(_MSC_VER)
std::vector<std::string> caches;
std::vector<std::vector<char>> caches;
for (size_t i = 1; i < 18; i += 2) {
caches.emplace_back(TestSparsePageDMatrixDeterminism(i));
}

View File

@@ -184,7 +184,7 @@ TEST(Learner, JsonModelIO) {
fout.close();
auto loaded_str = common::LoadSequentialFile(tmpdir.path + "/model.json");
Json loaded = Json::Load(StringView{loaded_str.c_str(), loaded_str.size()});
Json loaded = Json::Load(StringView{loaded_str.data(), loaded_str.size()});
learner->LoadModel(loaded);
learner->Configure();