From 2195822df64c34eacc411043a197ce701ae6b135 Mon Sep 17 00:00:00 2001 From: Godeffroy Valet Date: Sat, 25 Jul 2015 11:58:36 +0200 Subject: Allowed tensor contraction operation with an empty array of dimension pairs, which performs a tensor product. --- unsupported/test/cxx11_tensor_contraction.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'unsupported/test/cxx11_tensor_contraction.cpp') diff --git a/unsupported/test/cxx11_tensor_contraction.cpp b/unsupported/test/cxx11_tensor_contraction.cpp index f4acdc504..b0d52c6cf 100644 --- a/unsupported/test/cxx11_tensor_contraction.cpp +++ b/unsupported/test/cxx11_tensor_contraction.cpp @@ -448,6 +448,31 @@ static void test_small_blocking_factors() } } +template +static void test_tensor_product() +{ + Tensor mat1(2, 3); + Tensor mat2(4, 1); + mat1.setRandom(); + mat2.setRandom(); + + Tensor result = mat1.contract(mat2, Eigen::array{{}}); + + VERIFY_IS_EQUAL(result.dimension(0), 2); + VERIFY_IS_EQUAL(result.dimension(1), 3); + VERIFY_IS_EQUAL(result.dimension(2), 4); + VERIFY_IS_EQUAL(result.dimension(3), 1); + for (int i = 0; i < result.dimension(0); ++i) { + for (int j = 0; j < result.dimension(1); ++j) { + for (int k = 0; k < result.dimension(2); ++k) { + for (int l = 0; l < result.dimension(3); ++l) { + VERIFY_IS_APPROX(result(i, j, k, l), mat1(i, j) * mat2(k, l) ); + } + } + } + } +} + void test_cxx11_tensor_contraction() { @@ -477,4 +502,6 @@ void test_cxx11_tensor_contraction() CALL_SUBTEST(test_tensor_vector()); CALL_SUBTEST(test_small_blocking_factors()); CALL_SUBTEST(test_small_blocking_factors()); + CALL_SUBTEST(test_tensor_product()); + CALL_SUBTEST(test_tensor_product()); } -- cgit v1.2.3