mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
merge pull request 198
This commit is contained in:
@@ -27,6 +27,8 @@ static void test_parallelism()
|
||||
// Test we never-ever fail to match available tasks with idle threads.
|
||||
const int kThreads = 16; // code below expects that this is a multiple of 4
|
||||
NonBlockingThreadPool tp(kThreads);
|
||||
VERIFY_IS_EQUAL(tp.NumThreads(), kThreads);
|
||||
VERIFY_IS_EQUAL(tp.CurrentThreadId(), -1);
|
||||
for (int iter = 0; iter < 100; ++iter) {
|
||||
std::atomic<int> running(0);
|
||||
std::atomic<int> done(0);
|
||||
@@ -34,6 +36,9 @@ static void test_parallelism()
|
||||
// Schedule kThreads tasks and ensure that they all are running.
|
||||
for (int i = 0; i < kThreads; ++i) {
|
||||
tp.Schedule([&]() {
|
||||
const int thread_id = tp.CurrentThreadId();
|
||||
VERIFY_GE(thread_id, 0);
|
||||
VERIFY_LE(thread_id, kThreads - 1);
|
||||
running++;
|
||||
while (phase < 1) {
|
||||
}
|
||||
|
||||
@@ -13,6 +13,20 @@
|
||||
#include <Eigen/CXX11/Tensor>
|
||||
|
||||
|
||||
template<int DataLayout>
|
||||
static void test_output_0d()
|
||||
{
|
||||
Tensor<int, 0, DataLayout> tensor;
|
||||
tensor() = 123;
|
||||
|
||||
std::stringstream os;
|
||||
os << tensor;
|
||||
|
||||
std::string expected("123");
|
||||
VERIFY_IS_EQUAL(std::string(os.str()), expected);
|
||||
}
|
||||
|
||||
|
||||
template<int DataLayout>
|
||||
static void test_output_1d()
|
||||
{
|
||||
@@ -26,6 +40,12 @@ static void test_output_1d()
|
||||
|
||||
std::string expected("0\n1\n2\n3\n4");
|
||||
VERIFY_IS_EQUAL(std::string(os.str()), expected);
|
||||
|
||||
Eigen::Tensor<double,1,DataLayout> empty_tensor(0);
|
||||
std::stringstream empty_os;
|
||||
empty_os << empty_tensor;
|
||||
std::string empty_string;
|
||||
VERIFY_IS_EQUAL(std::string(empty_os.str()), empty_string);
|
||||
}
|
||||
|
||||
|
||||
@@ -101,6 +121,8 @@ static void test_output_const()
|
||||
|
||||
void test_cxx11_tensor_io()
|
||||
{
|
||||
CALL_SUBTEST(test_output_0d<ColMajor>());
|
||||
CALL_SUBTEST(test_output_0d<RowMajor>());
|
||||
CALL_SUBTEST(test_output_1d<ColMajor>());
|
||||
CALL_SUBTEST(test_output_1d<RowMajor>());
|
||||
CALL_SUBTEST(test_output_2d<ColMajor>());
|
||||
|
||||
@@ -38,6 +38,30 @@ static void test_1d_scan()
|
||||
}
|
||||
}
|
||||
|
||||
template <int DataLayout, typename Type=float>
|
||||
static void test_1d_inclusive_scan()
|
||||
{
|
||||
int size = 50;
|
||||
Tensor<Type, 1, DataLayout> tensor(size);
|
||||
tensor.setRandom();
|
||||
Tensor<Type, 1, DataLayout> result = tensor.cumsum(0, true);
|
||||
|
||||
VERIFY_IS_EQUAL(tensor.dimension(0), result.dimension(0));
|
||||
|
||||
float accum = 0;
|
||||
for (int i = 0; i < size; i++) {
|
||||
VERIFY_IS_EQUAL(result(i), accum);
|
||||
accum += tensor(i);
|
||||
}
|
||||
|
||||
accum = 1;
|
||||
result = tensor.cumprod(0, true);
|
||||
for (int i = 0; i < size; i++) {
|
||||
VERIFY_IS_EQUAL(result(i), accum);
|
||||
accum *= tensor(i);
|
||||
}
|
||||
}
|
||||
|
||||
template <int DataLayout, typename Type=float>
|
||||
static void test_4d_scan()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user