TensorShapeTest.cpp 1.4 KB
Newer Older
H
hedaoyuan 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/* 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 "TensorShape.h"
#include <gtest/gtest.h>

namespace paddle {

TEST(TensorShape, Constructor) {
  TensorShape t1;
22 23
  EXPECT_EQ(t1.ndims(), 0U);
  EXPECT_EQ(t1.getElements(), 0U);
H
hedaoyuan 已提交
24 25

  TensorShape t2(3);
26 27
  EXPECT_EQ(t2.ndims(), 3U);
  EXPECT_EQ(t2.getElements(), 1U);
H
hedaoyuan 已提交
28 29

  TensorShape t3({8, 10});
30 31
  EXPECT_EQ(t3.ndims(), 2U);
  EXPECT_EQ(t3.getElements(), 80U);
H
hedaoyuan 已提交
32 33 34 35 36 37

  TensorShape t4(t3);
  EXPECT_EQ(t4.ndims(), t3.ndims());
  EXPECT_EQ(t4.getElements(), t3.getElements());

  TensorShape t5({1, 2, 3, 4, 5});
38 39
  EXPECT_EQ(t5.ndims(), 5U);
  EXPECT_EQ(t5.getElements(), 120U);
H
hedaoyuan 已提交
40 41 42 43
}

TEST(TensorShape, GetAndSet) {
  TensorShape t({1, 2, 3});
44 45
  EXPECT_EQ(t.ndims(), 3U);
  EXPECT_EQ(t.getElements(), 6U);
H
hedaoyuan 已提交
46

Y
Yi Wang 已提交
47
  EXPECT_EQ(t[1], 2U);
H
hedaoyuan 已提交
48
  t.setDim(1, 100);
49 50
  EXPECT_EQ(t.getElements(), 300U);
  EXPECT_EQ(t[1], 100U);
H
hedaoyuan 已提交
51 52 53
}

}  // namespace paddle