From 8b2afe33a165ff0cc5a7afd14fcfb06cdf703235 Mon Sep 17 00:00:00 2001 From: Benoit Steiner Date: Thu, 2 Oct 2014 10:39:36 -0700 Subject: Fixes for the forced evaluation of tensor expressions More tests --- unsupported/test/cxx11_tensor_forced_eval.cpp | 51 +++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 unsupported/test/cxx11_tensor_forced_eval.cpp (limited to 'unsupported/test/cxx11_tensor_forced_eval.cpp') diff --git a/unsupported/test/cxx11_tensor_forced_eval.cpp b/unsupported/test/cxx11_tensor_forced_eval.cpp new file mode 100644 index 000000000..529584a7b --- /dev/null +++ b/unsupported/test/cxx11_tensor_forced_eval.cpp @@ -0,0 +1,51 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2014 Benoit Steiner +// +// This Source Code Form is subject to the terms of the Mozilla +// Public License v. 2.0. If a copy of the MPL was not distributed +// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#include "main.h" + +#include +#include + +using Eigen::MatrixXf; +using Eigen::Tensor; + +static void test_simple() +{ + MatrixXf m1(3,3); + MatrixXf m2(3,3); + m1.setRandom(); + m2.setRandom(); + + TensorMap> mat1(m1.data(), 3,3); + TensorMap> mat2(m2.data(), 3,3); + + Tensor mat3(3,3); + mat3 = mat1; + + typedef Tensor::DimensionPair DimPair; + Eigen::array dims({{DimPair(1, 0)}}); + + mat3 = mat3.contract(mat2, dims).eval(); + + VERIFY_IS_APPROX(mat3(0, 0), (m1*m2).eval()(0,0)); + VERIFY_IS_APPROX(mat3(0, 1), (m1*m2).eval()(0,1)); + VERIFY_IS_APPROX(mat3(0, 2), (m1*m2).eval()(0,2)); + VERIFY_IS_APPROX(mat3(1, 0), (m1*m2).eval()(1,0)); + VERIFY_IS_APPROX(mat3(1, 1), (m1*m2).eval()(1,1)); + VERIFY_IS_APPROX(mat3(1, 2), (m1*m2).eval()(1,2)); + VERIFY_IS_APPROX(mat3(2, 0), (m1*m2).eval()(2,0)); + VERIFY_IS_APPROX(mat3(2, 1), (m1*m2).eval()(2,1)); + VERIFY_IS_APPROX(mat3(2, 2), (m1*m2).eval()(2,2)); +} + + +void test_cxx11_tensor_forced_eval() +{ + CALL_SUBTEST(test_simple()); +} -- cgit v1.2.3