mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-01-24 14:45:14 +08:00
Made the contraction test more portable
This commit is contained in:
parent
2c50fc878e
commit
174edf976b
@ -29,7 +29,7 @@ static void test_evals()
|
||||
|
||||
Tensor<float, 2, DataLayout> mat4(3,3);
|
||||
mat4.setZero();
|
||||
Eigen::array<DimPair, 1> dims3({{DimPair(0, 0)}});
|
||||
Eigen::array<DimPair, 1> dims3 = {{DimPair(0, 0)}};
|
||||
typedef TensorEvaluator<decltype(mat1.contract(mat2, dims3)), DefaultDevice> Evaluator;
|
||||
Evaluator eval(mat1.contract(mat2, dims3), DefaultDevice());
|
||||
eval.evalTo(mat4.data());
|
||||
@ -49,7 +49,7 @@ static void test_evals()
|
||||
|
||||
Tensor<float, 2, DataLayout> mat5(2,2);
|
||||
mat5.setZero();
|
||||
Eigen::array<DimPair, 1> dims4({{DimPair(1, 1)}});
|
||||
Eigen::array<DimPair, 1> dims4 = {{DimPair(1, 1)}};
|
||||
typedef TensorEvaluator<decltype(mat1.contract(mat2, dims4)), DefaultDevice> Evaluator2;
|
||||
Evaluator2 eval2(mat1.contract(mat2, dims4), DefaultDevice());
|
||||
eval2.evalTo(mat5.data());
|
||||
@ -64,7 +64,7 @@ static void test_evals()
|
||||
|
||||
Tensor<float, 2, DataLayout> mat6(2,2);
|
||||
mat6.setZero();
|
||||
Eigen::array<DimPair, 1> dims6({{DimPair(1, 0)}});
|
||||
Eigen::array<DimPair, 1> dims6 = {{DimPair(1, 0)}};
|
||||
typedef TensorEvaluator<decltype(mat1.contract(mat3, dims6)), DefaultDevice> Evaluator3;
|
||||
Evaluator3 eval3(mat1.contract(mat3, dims6), DefaultDevice());
|
||||
eval3.evalTo(mat6.data());
|
||||
@ -89,7 +89,7 @@ static void test_scalar()
|
||||
|
||||
Tensor<float, 1, DataLayout> scalar(1);
|
||||
scalar.setZero();
|
||||
Eigen::array<DimPair, 1> dims({{DimPair(0, 0)}});
|
||||
Eigen::array<DimPair, 1> dims = {{DimPair(0, 0)}};
|
||||
typedef TensorEvaluator<decltype(vec1.contract(vec2, dims)), DefaultDevice> Evaluator;
|
||||
Evaluator eval(vec1.contract(vec2, dims), DefaultDevice());
|
||||
eval.evalTo(scalar.data());
|
||||
@ -113,7 +113,7 @@ static void test_multidims()
|
||||
|
||||
Tensor<float, 3, DataLayout> mat3(2, 2, 2);
|
||||
mat3.setZero();
|
||||
Eigen::array<DimPair, 2> dims({{DimPair(1, 2), DimPair(2, 3)}});
|
||||
Eigen::array<DimPair, 2> dims = {{DimPair(1, 2), DimPair(2, 3)}};
|
||||
typedef TensorEvaluator<decltype(mat1.contract(mat2, dims)), DefaultDevice> Evaluator;
|
||||
Evaluator eval(mat1.contract(mat2, dims), DefaultDevice());
|
||||
eval.evalTo(mat3.data());
|
||||
@ -147,7 +147,7 @@ static void test_holes() {
|
||||
t1.setRandom();
|
||||
t2.setRandom();
|
||||
|
||||
Eigen::array<DimPair, 2> dims({{DimPair(0, 0), DimPair(3, 4)}});
|
||||
Eigen::array<DimPair, 2> dims = {{DimPair(0, 0), DimPair(3, 4)}};
|
||||
Tensor<float, 5, DataLayout> result = t1.contract(t2, dims);
|
||||
VERIFY_IS_EQUAL(result.dimension(0), 5);
|
||||
VERIFY_IS_EQUAL(result.dimension(1), 7);
|
||||
@ -182,7 +182,7 @@ static void test_full_redux()
|
||||
t1.setRandom();
|
||||
t2.setRandom();
|
||||
|
||||
Eigen::array<DimPair, 2> dims({{DimPair(0, 0), DimPair(1, 1)}});
|
||||
Eigen::array<DimPair, 2> dims = {{DimPair(0, 0), DimPair(1, 1)}};
|
||||
Tensor<float, 1, DataLayout> result = t1.contract(t2, dims);
|
||||
VERIFY_IS_EQUAL(result.dimension(0), 2);
|
||||
VERIFY_IS_APPROX(result(0), t1(0, 0) * t2(0, 0, 0) + t1(1, 0) * t2(1, 0, 0)
|
||||
@ -212,7 +212,7 @@ static void test_contraction_of_contraction()
|
||||
t3.setRandom();
|
||||
t4.setRandom();
|
||||
|
||||
Eigen::array<DimPair, 1> dims({{DimPair(1, 0)}});
|
||||
Eigen::array<DimPair, 1> dims = {{DimPair(1, 0)}};
|
||||
auto contract1 = t1.contract(t2, dims);
|
||||
auto diff = t3 - contract1;
|
||||
auto contract2 = t1.contract(t4, dims);
|
||||
@ -243,7 +243,7 @@ static void test_expr()
|
||||
|
||||
Tensor<float, 2, DataLayout> mat3(2,2);
|
||||
|
||||
Eigen::array<DimPair, 1> dims({{DimPair(1, 0)}});
|
||||
Eigen::array<DimPair, 1> dims = {{DimPair(1, 0)}};
|
||||
mat3 = mat1.contract(mat2, dims);
|
||||
|
||||
VERIFY_IS_APPROX(mat3(0,0), mat1(0,0)*mat2(0,0) + mat1(0,1)*mat2(1,0) + mat1(0,2)*mat2(2,0));
|
||||
@ -263,7 +263,7 @@ static void test_out_of_order_contraction()
|
||||
|
||||
Tensor<float, 2, DataLayout> mat3(2, 2);
|
||||
|
||||
Eigen::array<DimPair, 2> dims({{DimPair(2, 0), DimPair(0, 2)}});
|
||||
Eigen::array<DimPair, 2> dims = {{DimPair(2, 0), DimPair(0, 2)}};
|
||||
mat3 = mat1.contract(mat2, dims);
|
||||
|
||||
VERIFY_IS_APPROX(mat3(0, 0),
|
||||
@ -279,7 +279,7 @@ static void test_out_of_order_contraction()
|
||||
mat1(0,1,0)*mat2(0,1,0) + mat1(1,1,0)*mat2(0,1,1) +
|
||||
mat1(0,1,1)*mat2(1,1,0) + mat1(1,1,1)*mat2(1,1,1));
|
||||
|
||||
Eigen::array<DimPair, 2> dims2({{DimPair(0, 2), DimPair(2, 0)}});
|
||||
Eigen::array<DimPair, 2> dims2 = {{DimPair(0, 2), DimPair(2, 0)}};
|
||||
mat3 = mat1.contract(mat2, dims2);
|
||||
|
||||
VERIFY_IS_APPROX(mat3(0, 0),
|
||||
@ -311,8 +311,8 @@ static void test_consistency()
|
||||
Tensor<float, 4, DataLayout> mat4(2, 1, 5, 5);
|
||||
|
||||
// contract on dimensions of size 4 and 3
|
||||
Eigen::array<DimPair, 2> dims1({{DimPair(0, 4), DimPair(1, 0)}});
|
||||
Eigen::array<DimPair, 2> dims2({{DimPair(4, 0), DimPair(0, 1)}});
|
||||
Eigen::array<DimPair, 2> dims1 = {{DimPair(0, 4), DimPair(1, 0)}};
|
||||
Eigen::array<DimPair, 2> dims2 = {{DimPair(4, 0), DimPair(0, 1)}};
|
||||
|
||||
mat3 = mat1.contract(mat2, dims1);
|
||||
mat4 = mat2.contract(mat1, dims2);
|
||||
@ -354,7 +354,7 @@ static void test_large_contraction()
|
||||
Eigen::Matrix<float, Dynamic, Dynamic, DataLayout> m_result(1500, 1400);
|
||||
|
||||
// this contraction should be equivalent to a single matrix multiplication
|
||||
Eigen::array<DimPair, 2> dims({{DimPair(2, 0), DimPair(3, 1)}});
|
||||
Eigen::array<DimPair, 2> dims = {{DimPair(2, 0), DimPair(3, 1)}};
|
||||
|
||||
// compute results by separate methods
|
||||
t_result = t_left.contract(t_right, dims);
|
||||
@ -399,10 +399,10 @@ static void test_tensor_vector()
|
||||
{
|
||||
Tensor<float, 3, DataLayout> t_left(7, 13, 17);
|
||||
Tensor<float, 2, DataLayout> t_right(1, 7);
|
||||
|
||||
|
||||
t_left.setRandom();
|
||||
t_right.setRandom();
|
||||
|
||||
|
||||
typedef typename Tensor<float, 1, DataLayout>::DimensionPair DimensionPair;
|
||||
Eigen::array<DimensionPair, 1> dim_pair01{{{0, 1}}};
|
||||
Tensor<float, 3, DataLayout> t_result = t_left.contract(t_right, dim_pair01);
|
||||
@ -434,7 +434,7 @@ static void test_small_blocking_factors()
|
||||
Eigen::setCpuCacheSizes(896, 1920, 2944);
|
||||
|
||||
// this contraction should be equivalent to a single matrix multiplication
|
||||
Eigen::array<DimPair, 2> dims({{DimPair(2, 0), DimPair(3, 1)}});
|
||||
Eigen::array<DimPair, 2> dims = {{DimPair(2, 0), DimPair(3, 1)}};
|
||||
Tensor<float, 5, DataLayout> t_result;
|
||||
t_result = t_left.contract(t_right, dims);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user