mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Clang-format tests, examples, libraries, benchmarks, etc.
This commit is contained in:
committed by
Rasmus Munk Larsen
parent
3252ecc7a4
commit
46e9cdb7fe
@@ -13,10 +13,9 @@
|
||||
|
||||
using Eigen::Tensor;
|
||||
|
||||
template<int DataLayout>
|
||||
static void test_simple_chip()
|
||||
{
|
||||
Tensor<float, 5, DataLayout> tensor(2,3,5,7,11);
|
||||
template <int DataLayout>
|
||||
static void test_simple_chip() {
|
||||
Tensor<float, 5, DataLayout> tensor(2, 3, 5, 7, 11);
|
||||
tensor.setRandom();
|
||||
|
||||
Tensor<float, 4, DataLayout> chip1;
|
||||
@@ -31,7 +30,7 @@ static void test_simple_chip()
|
||||
for (int j = 0; j < 5; ++j) {
|
||||
for (int k = 0; k < 7; ++k) {
|
||||
for (int l = 0; l < 11; ++l) {
|
||||
VERIFY_IS_EQUAL(chip1(i,j,k,l), tensor(1,i,j,k,l));
|
||||
VERIFY_IS_EQUAL(chip1(i, j, k, l), tensor(1, i, j, k, l));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -46,7 +45,7 @@ static void test_simple_chip()
|
||||
for (int j = 0; j < 5; ++j) {
|
||||
for (int k = 0; k < 7; ++k) {
|
||||
for (int l = 0; l < 11; ++l) {
|
||||
VERIFY_IS_EQUAL(chip2(i,j,k,l), tensor(i,1,j,k,l));
|
||||
VERIFY_IS_EQUAL(chip2(i, j, k, l), tensor(i, 1, j, k, l));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -61,7 +60,7 @@ static void test_simple_chip()
|
||||
for (int j = 0; j < 3; ++j) {
|
||||
for (int k = 0; k < 7; ++k) {
|
||||
for (int l = 0; l < 11; ++l) {
|
||||
VERIFY_IS_EQUAL(chip3(i,j,k,l), tensor(i,j,2,k,l));
|
||||
VERIFY_IS_EQUAL(chip3(i, j, k, l), tensor(i, j, 2, k, l));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -76,7 +75,7 @@ static void test_simple_chip()
|
||||
for (int j = 0; j < 3; ++j) {
|
||||
for (int k = 0; k < 5; ++k) {
|
||||
for (int l = 0; l < 11; ++l) {
|
||||
VERIFY_IS_EQUAL(chip4(i,j,k,l), tensor(i,j,k,5,l));
|
||||
VERIFY_IS_EQUAL(chip4(i, j, k, l), tensor(i, j, k, 5, l));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -91,17 +90,16 @@ static void test_simple_chip()
|
||||
for (int j = 0; j < 3; ++j) {
|
||||
for (int k = 0; k < 5; ++k) {
|
||||
for (int l = 0; l < 7; ++l) {
|
||||
VERIFY_IS_EQUAL(chip5(i,j,k,l), tensor(i,j,k,l,7));
|
||||
VERIFY_IS_EQUAL(chip5(i, j, k, l), tensor(i, j, k, l, 7));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<int DataLayout>
|
||||
static void test_dynamic_chip()
|
||||
{
|
||||
Tensor<float, 5, DataLayout> tensor(2,3,5,7,11);
|
||||
template <int DataLayout>
|
||||
static void test_dynamic_chip() {
|
||||
Tensor<float, 5, DataLayout> tensor(2, 3, 5, 7, 11);
|
||||
tensor.setRandom();
|
||||
|
||||
Tensor<float, 4, DataLayout> chip1;
|
||||
@@ -114,7 +112,7 @@ static void test_dynamic_chip()
|
||||
for (int j = 0; j < 5; ++j) {
|
||||
for (int k = 0; k < 7; ++k) {
|
||||
for (int l = 0; l < 11; ++l) {
|
||||
VERIFY_IS_EQUAL(chip1(i,j,k,l), tensor(1,i,j,k,l));
|
||||
VERIFY_IS_EQUAL(chip1(i, j, k, l), tensor(1, i, j, k, l));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -129,7 +127,7 @@ static void test_dynamic_chip()
|
||||
for (int j = 0; j < 5; ++j) {
|
||||
for (int k = 0; k < 7; ++k) {
|
||||
for (int l = 0; l < 11; ++l) {
|
||||
VERIFY_IS_EQUAL(chip2(i,j,k,l), tensor(i,1,j,k,l));
|
||||
VERIFY_IS_EQUAL(chip2(i, j, k, l), tensor(i, 1, j, k, l));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -144,7 +142,7 @@ static void test_dynamic_chip()
|
||||
for (int j = 0; j < 3; ++j) {
|
||||
for (int k = 0; k < 7; ++k) {
|
||||
for (int l = 0; l < 11; ++l) {
|
||||
VERIFY_IS_EQUAL(chip3(i,j,k,l), tensor(i,j,2,k,l));
|
||||
VERIFY_IS_EQUAL(chip3(i, j, k, l), tensor(i, j, 2, k, l));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -159,7 +157,7 @@ static void test_dynamic_chip()
|
||||
for (int j = 0; j < 3; ++j) {
|
||||
for (int k = 0; k < 5; ++k) {
|
||||
for (int l = 0; l < 11; ++l) {
|
||||
VERIFY_IS_EQUAL(chip4(i,j,k,l), tensor(i,j,k,5,l));
|
||||
VERIFY_IS_EQUAL(chip4(i, j, k, l), tensor(i, j, k, 5, l));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -174,18 +172,18 @@ static void test_dynamic_chip()
|
||||
for (int j = 0; j < 3; ++j) {
|
||||
for (int k = 0; k < 5; ++k) {
|
||||
for (int l = 0; l < 7; ++l) {
|
||||
VERIFY_IS_EQUAL(chip5(i,j,k,l), tensor(i,j,k,l,7));
|
||||
VERIFY_IS_EQUAL(chip5(i, j, k, l), tensor(i, j, k, l, 7));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<int DataLayout>
|
||||
template <int DataLayout>
|
||||
static void test_chip_in_expr() {
|
||||
Tensor<float, 5, DataLayout> input1(2,3,5,7,11);
|
||||
Tensor<float, 5, DataLayout> input1(2, 3, 5, 7, 11);
|
||||
input1.setRandom();
|
||||
Tensor<float, 4, DataLayout> input2(3,5,7,11);
|
||||
Tensor<float, 4, DataLayout> input2(3, 5, 7, 11);
|
||||
input2.setRandom();
|
||||
|
||||
Tensor<float, 4, DataLayout> result = input1.template chip<0>(0) + input2;
|
||||
@@ -193,33 +191,32 @@ static void test_chip_in_expr() {
|
||||
for (int j = 0; j < 5; ++j) {
|
||||
for (int k = 0; k < 7; ++k) {
|
||||
for (int l = 0; l < 11; ++l) {
|
||||
float expected = input1(0,i,j,k,l) + input2(i,j,k,l);
|
||||
VERIFY_IS_EQUAL(result(i,j,k,l), expected);
|
||||
float expected = input1(0, i, j, k, l) + input2(i, j, k, l);
|
||||
VERIFY_IS_EQUAL(result(i, j, k, l), expected);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Tensor<float, 3, DataLayout> input3(3,7,11);
|
||||
Tensor<float, 3, DataLayout> input3(3, 7, 11);
|
||||
input3.setRandom();
|
||||
Tensor<float, 3, DataLayout> result2 = input1.template chip<0>(0).template chip<1>(2) + input3;
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
for (int j = 0; j < 7; ++j) {
|
||||
for (int k = 0; k < 11; ++k) {
|
||||
float expected = input1(0,i,2,j,k) + input3(i,j,k);
|
||||
VERIFY_IS_EQUAL(result2(i,j,k), expected);
|
||||
float expected = input1(0, i, 2, j, k) + input3(i, j, k);
|
||||
VERIFY_IS_EQUAL(result2(i, j, k), expected);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<int DataLayout>
|
||||
static void test_chip_as_lvalue()
|
||||
{
|
||||
Tensor<float, 5, DataLayout> input1(2,3,5,7,11);
|
||||
template <int DataLayout>
|
||||
static void test_chip_as_lvalue() {
|
||||
Tensor<float, 5, DataLayout> input1(2, 3, 5, 7, 11);
|
||||
input1.setRandom();
|
||||
|
||||
Tensor<float, 4, DataLayout> input2(3,5,7,11);
|
||||
Tensor<float, 4, DataLayout> input2(3, 5, 7, 11);
|
||||
input2.setRandom();
|
||||
Tensor<float, 5, DataLayout> tensor = input1;
|
||||
tensor.template chip<0>(1) = input2;
|
||||
@@ -229,9 +226,9 @@ static void test_chip_as_lvalue()
|
||||
for (int l = 0; l < 7; ++l) {
|
||||
for (int m = 0; m < 11; ++m) {
|
||||
if (i != 1) {
|
||||
VERIFY_IS_EQUAL(tensor(i,j,k,l,m), input1(i,j,k,l,m));
|
||||
VERIFY_IS_EQUAL(tensor(i, j, k, l, m), input1(i, j, k, l, m));
|
||||
} else {
|
||||
VERIFY_IS_EQUAL(tensor(i,j,k,l,m), input2(j,k,l,m));
|
||||
VERIFY_IS_EQUAL(tensor(i, j, k, l, m), input2(j, k, l, m));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -239,7 +236,7 @@ static void test_chip_as_lvalue()
|
||||
}
|
||||
}
|
||||
|
||||
Tensor<float, 4, DataLayout> input3(2,5,7,11);
|
||||
Tensor<float, 4, DataLayout> input3(2, 5, 7, 11);
|
||||
input3.setRandom();
|
||||
tensor = input1;
|
||||
tensor.template chip<1>(1) = input3;
|
||||
@@ -249,9 +246,9 @@ static void test_chip_as_lvalue()
|
||||
for (int l = 0; l < 7; ++l) {
|
||||
for (int m = 0; m < 11; ++m) {
|
||||
if (j != 1) {
|
||||
VERIFY_IS_EQUAL(tensor(i,j,k,l,m), input1(i,j,k,l,m));
|
||||
VERIFY_IS_EQUAL(tensor(i, j, k, l, m), input1(i, j, k, l, m));
|
||||
} else {
|
||||
VERIFY_IS_EQUAL(tensor(i,j,k,l,m), input3(i,k,l,m));
|
||||
VERIFY_IS_EQUAL(tensor(i, j, k, l, m), input3(i, k, l, m));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -259,7 +256,7 @@ static void test_chip_as_lvalue()
|
||||
}
|
||||
}
|
||||
|
||||
Tensor<float, 4, DataLayout> input4(2,3,7,11);
|
||||
Tensor<float, 4, DataLayout> input4(2, 3, 7, 11);
|
||||
input4.setRandom();
|
||||
tensor = input1;
|
||||
tensor.template chip<2>(3) = input4;
|
||||
@@ -269,9 +266,9 @@ static void test_chip_as_lvalue()
|
||||
for (int l = 0; l < 7; ++l) {
|
||||
for (int m = 0; m < 11; ++m) {
|
||||
if (k != 3) {
|
||||
VERIFY_IS_EQUAL(tensor(i,j,k,l,m), input1(i,j,k,l,m));
|
||||
VERIFY_IS_EQUAL(tensor(i, j, k, l, m), input1(i, j, k, l, m));
|
||||
} else {
|
||||
VERIFY_IS_EQUAL(tensor(i,j,k,l,m), input4(i,j,l,m));
|
||||
VERIFY_IS_EQUAL(tensor(i, j, k, l, m), input4(i, j, l, m));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -279,7 +276,7 @@ static void test_chip_as_lvalue()
|
||||
}
|
||||
}
|
||||
|
||||
Tensor<float, 4, DataLayout> input5(2,3,5,11);
|
||||
Tensor<float, 4, DataLayout> input5(2, 3, 5, 11);
|
||||
input5.setRandom();
|
||||
tensor = input1;
|
||||
tensor.template chip<3>(4) = input5;
|
||||
@@ -289,9 +286,9 @@ static void test_chip_as_lvalue()
|
||||
for (int l = 0; l < 7; ++l) {
|
||||
for (int m = 0; m < 11; ++m) {
|
||||
if (l != 4) {
|
||||
VERIFY_IS_EQUAL(tensor(i,j,k,l,m), input1(i,j,k,l,m));
|
||||
VERIFY_IS_EQUAL(tensor(i, j, k, l, m), input1(i, j, k, l, m));
|
||||
} else {
|
||||
VERIFY_IS_EQUAL(tensor(i,j,k,l,m), input5(i,j,k,m));
|
||||
VERIFY_IS_EQUAL(tensor(i, j, k, l, m), input5(i, j, k, m));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -299,7 +296,7 @@ static void test_chip_as_lvalue()
|
||||
}
|
||||
}
|
||||
|
||||
Tensor<float, 4, DataLayout> input6(2,3,5,7);
|
||||
Tensor<float, 4, DataLayout> input6(2, 3, 5, 7);
|
||||
input6.setRandom();
|
||||
tensor = input1;
|
||||
tensor.template chip<4>(5) = input6;
|
||||
@@ -309,9 +306,9 @@ static void test_chip_as_lvalue()
|
||||
for (int l = 0; l < 7; ++l) {
|
||||
for (int m = 0; m < 11; ++m) {
|
||||
if (m != 5) {
|
||||
VERIFY_IS_EQUAL(tensor(i,j,k,l,m), input1(i,j,k,l,m));
|
||||
VERIFY_IS_EQUAL(tensor(i, j, k, l, m), input1(i, j, k, l, m));
|
||||
} else {
|
||||
VERIFY_IS_EQUAL(tensor(i,j,k,l,m), input6(i,j,k,l));
|
||||
VERIFY_IS_EQUAL(tensor(i, j, k, l, m), input6(i, j, k, l));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -319,7 +316,7 @@ static void test_chip_as_lvalue()
|
||||
}
|
||||
}
|
||||
|
||||
Tensor<float, 5, DataLayout> input7(2,3,5,7,11);
|
||||
Tensor<float, 5, DataLayout> input7(2, 3, 5, 7, 11);
|
||||
input7.setRandom();
|
||||
tensor = input1;
|
||||
tensor.chip(0, 0) = input7.chip(0, 0);
|
||||
@@ -329,9 +326,9 @@ static void test_chip_as_lvalue()
|
||||
for (int l = 0; l < 7; ++l) {
|
||||
for (int m = 0; m < 11; ++m) {
|
||||
if (i != 0) {
|
||||
VERIFY_IS_EQUAL(tensor(i,j,k,l,m), input1(i,j,k,l,m));
|
||||
VERIFY_IS_EQUAL(tensor(i, j, k, l, m), input1(i, j, k, l, m));
|
||||
} else {
|
||||
VERIFY_IS_EQUAL(tensor(i,j,k,l,m), input7(i,j,k,l,m));
|
||||
VERIFY_IS_EQUAL(tensor(i, j, k, l, m), input7(i, j, k, l, m));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -340,9 +337,8 @@ static void test_chip_as_lvalue()
|
||||
}
|
||||
}
|
||||
|
||||
static void test_chip_raw_data_col_major()
|
||||
{
|
||||
Tensor<float, 5, ColMajor> tensor(2,3,5,7,11);
|
||||
static void test_chip_raw_data_col_major() {
|
||||
Tensor<float, 5, ColMajor> tensor(2, 3, 5, 7, 11);
|
||||
tensor.setRandom();
|
||||
|
||||
typedef TensorEvaluator<decltype(tensor.chip<4>(3)), DefaultDevice> Evaluator4;
|
||||
@@ -352,7 +348,7 @@ static void test_chip_raw_data_col_major()
|
||||
for (int k = 0; k < 5; ++k) {
|
||||
for (int l = 0; l < 7; ++l) {
|
||||
int chip_index = i + 2 * (j + 3 * (k + 5 * l));
|
||||
VERIFY_IS_EQUAL(chip.data()[chip_index], tensor(i,j,k,l,3));
|
||||
VERIFY_IS_EQUAL(chip.data()[chip_index], tensor(i, j, k, l, 3));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -375,9 +371,8 @@ static void test_chip_raw_data_col_major()
|
||||
VERIFY_IS_EQUAL(chip3.data(), static_cast<float*>(0));
|
||||
}
|
||||
|
||||
static void test_chip_raw_data_row_major()
|
||||
{
|
||||
Tensor<float, 5, RowMajor> tensor(11,7,5,3,2);
|
||||
static void test_chip_raw_data_row_major() {
|
||||
Tensor<float, 5, RowMajor> tensor(11, 7, 5, 3, 2);
|
||||
tensor.setRandom();
|
||||
|
||||
typedef TensorEvaluator<decltype(tensor.chip<0>(3)), DefaultDevice> Evaluator0;
|
||||
@@ -387,7 +382,7 @@ static void test_chip_raw_data_row_major()
|
||||
for (int k = 0; k < 3; ++k) {
|
||||
for (int l = 0; l < 2; ++l) {
|
||||
int chip_index = l + 2 * (k + 3 * (j + 5 * i));
|
||||
VERIFY_IS_EQUAL(chip.data()[chip_index], tensor(3,i,j,k,l));
|
||||
VERIFY_IS_EQUAL(chip.data()[chip_index], tensor(3, i, j, k, l));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -410,8 +405,7 @@ static void test_chip_raw_data_row_major()
|
||||
VERIFY_IS_EQUAL(chip4.data(), static_cast<float*>(0));
|
||||
}
|
||||
|
||||
EIGEN_DECLARE_TEST(cxx11_tensor_chipping)
|
||||
{
|
||||
EIGEN_DECLARE_TEST(cxx11_tensor_chipping) {
|
||||
CALL_SUBTEST(test_simple_chip<ColMajor>());
|
||||
CALL_SUBTEST(test_simple_chip<RowMajor>());
|
||||
CALL_SUBTEST(test_dynamic_chip<ColMajor>());
|
||||
|
||||
Reference in New Issue
Block a user