mixed_vector_test.cc 1.7 KB
Newer Older
1
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserved.
D
dzhwinter 已提交
2 3 4 5 6 7 8 9 10 11 12 13

   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. */
14 15 16

#include <memory>

Y
Yu Yang 已提交
17 18
#include "glog/logging.h"
#include "gtest/gtest.h"
Y
Yi Wang 已提交
19
#include "paddle/fluid/framework/mixed_vector.h"
Y
Yu Yang 已提交
20 21 22 23 24 25 26 27 28

template <typename T>
using vec = paddle::framework::Vector<T>;

TEST(mixed_vector, CPU_VECTOR) {
  vec<int> tmp;
  for (int i = 0; i < 10; ++i) {
    tmp.push_back(i);
  }
29
  ASSERT_EQ(tmp.size(), 10UL);
Y
Yu Yang 已提交
30 31
  vec<int> tmp2;
  tmp2 = tmp;
32
  ASSERT_EQ(tmp2.size(), 10UL);
Y
Yu Yang 已提交
33 34 35 36 37 38 39 40 41 42 43
  for (int i = 0; i < 10; ++i) {
    ASSERT_EQ(tmp2[i], i);
    ASSERT_EQ(tmp2[i], tmp[i]);
  }
  int cnt = 0;
  for (auto& t : tmp2) {
    ASSERT_EQ(t, cnt);
    ++cnt;
  }
}

44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
TEST(mixed_vector, InitWithCount) {
  paddle::framework::Vector<int> vec(10, 10);
  for (int i = 0; i < 10; ++i) {
    ASSERT_EQ(vec[i], 10);
  }
}

TEST(mixed_vector, ForEach) {
  vec<int> tmp;
  for (auto& v : tmp) {
    VLOG(3) << v;
  }
}

TEST(mixed_vector, Reserve) {
  paddle::framework::Vector<int> vec;
  vec.reserve(1);
  vec.push_back(0);
  vec.push_back(0);
  vec.push_back(0);
}

TEST(mixed_vector, Resize) {
  paddle::framework::Vector<int> vec;
  vec.resize(1);
  vec.push_back(0);
  vec.push_back(0);
  vec.push_back(0);
}