serialization_test.cpp 498 字节
Newer Older
D
dzhwinter 已提交
1 2 3 4 5 6 7 8 9 10 11 12
#include "serialization.h"
#include "gtest/gtest.h"

using namespace paddle;
using namespace paddle::optimizer;

TEST(TensorToProto, Case1) {
  Tensor t(3), t1(3);
  for (size_t i = 0; i < t.size(); ++i) {
    t[i] = i;
    t1[i] = 0;
  }
D
dzhwinter 已提交
13

D
dzhwinter 已提交
14 15 16 17 18 19 20 21 22 23 24 25
  TensorProto proto;
  TensorToProto(t, &proto);
  ProtoToTensor(proto, &t1);
  for (size_t i = 0; i < t1.size(); ++i) {
    EXPECT_EQ(t1[i], t[i]);
  }
}

int main(int argc, char** argv) {
  testing::InitGoogleTest(&argc, argv);
  return RUN_ALL_TESTS();
}