You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
73 lines
1.7 KiB
73 lines
1.7 KiB
7 years ago
|
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserved.
|
||
7 years ago
|
|
||
|
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. */
|
||
7 years ago
|
|
||
|
#include <memory>
|
||
|
|
||
7 years ago
|
#include "glog/logging.h"
|
||
|
#include "gtest/gtest.h"
|
||
7 years ago
|
#include "paddle/fluid/framework/mixed_vector.h"
|
||
7 years ago
|
|
||
|
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);
|
||
|
}
|
||
7 years ago
|
ASSERT_EQ(tmp.size(), 10UL);
|
||
7 years ago
|
vec<int> tmp2;
|
||
|
tmp2 = tmp;
|
||
7 years ago
|
ASSERT_EQ(tmp2.size(), 10UL);
|
||
7 years ago
|
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;
|
||
|
}
|
||
|
}
|
||
|
|
||
7 years ago
|
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);
|
||
|
}
|