// 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 "random_without_cast_overflow.h" #include using Eigen::Tensor; using Eigen::array; template static void test_type_cast() { Tensor ftensor(101, 201); // Generate random values for a valid cast. for (int i = 0; i < 101; ++i) { for (int j = 0; j < 201; ++j) { ftensor(i, j) = internal::random_without_cast_overflow::value(); } } Tensor ttensor(101, 201); ttensor = ftensor.template cast(); for (int i = 0; i < 101; ++i) { for (int j = 0; j < 201; ++j) { const ToType ref = static_cast(ftensor(i, j)); VERIFY_IS_EQUAL(ttensor(i, j), ref); } } } template struct test_cast_runner { static void run() { test_type_cast(); test_type_cast(); test_type_cast(); test_type_cast(); test_type_cast(); test_type_cast(); test_type_cast(); test_type_cast(); test_type_cast(); test_type_cast(); test_type_cast(); test_type_cast(); test_type_cast(); test_type_cast>(); test_type_cast>(); } }; // Only certain types allow cast from std::complex<>. template struct test_cast_runner::IsComplex>> { static void run() { test_type_cast(); test_type_cast(); test_type_cast>(); test_type_cast>(); } }; EIGEN_DECLARE_TEST(cxx11_tensor_casts) { CALL_SUBTEST(test_cast_runner::run()); CALL_SUBTEST(test_cast_runner::run()); CALL_SUBTEST(test_cast_runner::run()); CALL_SUBTEST(test_cast_runner::run()); CALL_SUBTEST(test_cast_runner::run()); CALL_SUBTEST(test_cast_runner::run()); CALL_SUBTEST(test_cast_runner::run()); CALL_SUBTEST(test_cast_runner::run()); CALL_SUBTEST(test_cast_runner::run()); CALL_SUBTEST(test_cast_runner::run()); CALL_SUBTEST(test_cast_runner::run()); CALL_SUBTEST(test_cast_runner::run()); CALL_SUBTEST(test_cast_runner::run()); CALL_SUBTEST(test_cast_runner>::run()); CALL_SUBTEST(test_cast_runner>::run()); }