MCPcopy Create free account
hub / github.com/PaddlePaddle/Paddle / TEST

Function TEST

test/cpp/fluid/save_load_op_test.cc:24–66  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22PD_DECLARE_KERNEL(load_sr, CPU, ALL_LAYOUT);
23
24TEST(SaveLoadOp, CPU) {
25 paddle::framework::Scope scope;
26 phi::CPUPlace place;
27
28 auto var = scope.Var("test_var");
29 auto tensor = var->GetMutable<phi::DenseTensor>();
30 tensor->Resize({3, 10});
31 phi::LegacyLoD expect_lod;
32 expect_lod.resize(1);
33 expect_lod[0].push_back(0);
34 expect_lod[0].push_back(1);
35 expect_lod[0].push_back(2);
36 expect_lod[0].push_back(3);
37
38 tensor->set_lod(expect_lod);
39 int* expect = tensor->mutable_data<int>(place);
40 for (int64_t i = 0; i < tensor->numel(); ++i) {
41 expect[i] = static_cast<int>(i);
42 }
43 paddle::framework::AttributeMap attrs;
44 attrs.insert({"file_path", std::string("tensor.save")});
45
46 auto save_op = paddle::framework::OpRegistry::CreateOp(
47 "save", {{"X", {"test_var"}}}, {}, attrs);
48 save_op->Run(scope, place);
49
50 auto load_var = scope.Var("out_var");
51 auto target = load_var->GetMutable<phi::DenseTensor>();
52 auto load_op = paddle::framework::OpRegistry::CreateOp(
53 "load", {}, {{"Out", {"out_var"}}}, attrs);
54 load_op->Run(scope, place);
55 int* actual = target->data<int>();
56 for (int64_t i = 0; i < tensor->numel(); ++i) {
57 EXPECT_EQ(expect[i], actual[i]);
58 }
59 auto& actual_lod = target->lod();
60 EXPECT_EQ(expect_lod.size(), actual_lod.size());
61 for (size_t i = 0; i < expect_lod.size(); ++i) { // NOLINT
62 for (size_t j = 0; j < expect_lod[i].size(); ++j) {
63 EXPECT_EQ(expect_lod[i][j], actual_lod[i][j]);
64 }
65 }
66}
67
68TEST(SaveLoadOpSelectedRows, CPU) {
69 paddle::framework::Scope scope;

Callers

nothing calls this directly

Calls 15

CreateOpFunction · 0.85
float16Function · 0.50
VarMethod · 0.45
ResizeMethod · 0.45
resizeMethod · 0.45
push_backMethod · 0.45
set_lodMethod · 0.45
numelMethod · 0.45
insertMethod · 0.45
RunMethod · 0.45
lodMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected