eigen_test.cc 1.3 KB
Newer Older
Y
Yi Wang 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/*
  Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve.
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at
  http://www.apache.org/licenses/LICENSE-2.0
  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
*/

#include "paddle/framework/eigen.h"
#include <gtest/gtest.h>

Y
Yi Wang 已提交
17 18
namespace paddle {
namespace framework {
Y
Yi Wang 已提交
19

Y
Yi Wang 已提交
20 21 22 23 24 25
TEST(EigenDim, From) {
  EigenDim<3>::Type ed = EigenDim<3>::From(make_ddim({1, 2, 3}));
  EXPECT_EQ(1, ed[0]);
  EXPECT_EQ(2, ed[1]);
  EXPECT_EQ(3, ed[2]);
}
Y
Yi Wang 已提交
26

Y
Yi Wang 已提交
27
TEST(Eigen, Tensor) {
Y
Yi Wang 已提交
28
  Tensor t;
Y
Yi Wang 已提交
29
  float* p = t.mutable_data<float>(make_ddim({1, 2, 3}), platform::CPUPlace());
Y
Yi Wang 已提交
30 31 32 33
  for (int i = 0; i < 1 * 2 * 3; i++) {
    p[i] = static_cast<float>(i);
  }

Y
Yi Wang 已提交
34
  EigenTensor<float, 3>::Type et = EigenTensor<float, 3>::From(t);
Q
qijun 已提交
35 36 37 38

  for (int i = 0; i < 1 * 2 * 3; i++) {
    EXPECT_EQ(et(i), i);
  }
Y
Yi Wang 已提交
39 40 41 42 43 44
  // TODO: check the content of et.
}

TEST(Eigen, Vector) {}

TEST(Eigen, Matrix) {}
Y
Yi Wang 已提交
45

Q
qijun 已提交
46
}  // namespace framework
Y
Yi Wang 已提交
47
}  // namespace paddle