diff --git a/Eigen/ThreadPool b/Eigen/ThreadPool new file mode 100644 index 000000000..c9ea3d416 --- /dev/null +++ b/Eigen/ThreadPool @@ -0,0 +1,68 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2016 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/. + +#ifndef EIGEN_THREADPOOL_MODULE_H +#define EIGEN_THREADPOOL_MODULE_H + +#include "Core" + +#include "src/Core/util/DisableStupidWarnings.h" + +/** \defgroup ThreadPool_Module ThreadPool Module + * + * This module provides 2 threadpool implementations + * - a simple reference implementation + * - a faster non blocking implementation + * + * \code + * #include + * \endcode + */ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// There are non-parenthesized calls to "max" in the header, +// which trigger a check in test/main.h causing compilation to fail. +// We work around the check here by removing the check for max in +// the case where we have to emulate thread_local. +#ifdef max +#undef max +#endif +#include + +#include "src/Core/util/Meta.h" +#include "src/Core/util/MaxSizeVector.h" + +// IWYU pragma: begin_exports +#include "src/ThreadPool/ThreadLocal.h" +#include "src/ThreadPool/ThreadYield.h" +#include "src/ThreadPool/ThreadCancel.h" +#include "src/ThreadPool/EventCount.h" +#include "src/ThreadPool/RunQueue.h" +#include "src/ThreadPool/ThreadPoolInterface.h" +#include "src/ThreadPool/ThreadEnvironment.h" +#include "src/ThreadPool/Barrier.h" +#include "src/ThreadPool/NonBlockingThreadPool.h" +// IWYU pragma: end_exports + +#include "src/Core/util/ReenableStupidWarnings.h" + +#endif // EIGEN_CXX11_THREADPOOL_MODULE_H diff --git a/unsupported/Eigen/CXX11/src/util/EmulateArray.h b/Eigen/src/Core/util/EmulateArray.h similarity index 100% rename from unsupported/Eigen/CXX11/src/util/EmulateArray.h rename to Eigen/src/Core/util/EmulateArray.h diff --git a/unsupported/Eigen/CXX11/src/util/MaxSizeVector.h b/Eigen/src/Core/util/MaxSizeVector.h similarity index 100% rename from unsupported/Eigen/CXX11/src/util/MaxSizeVector.h rename to Eigen/src/Core/util/MaxSizeVector.h diff --git a/Eigen/src/Core/util/Meta.h b/Eigen/src/Core/util/Meta.h index a192aac87..c8eed35da 100644 --- a/Eigen/src/Core/util/Meta.h +++ b/Eigen/src/Core/util/Meta.h @@ -27,6 +27,8 @@ #endif +#include "EmulateArray.h" + // Define portable (u)int{32,64} types #include @@ -563,6 +565,513 @@ using std::is_constant_evaluated; constexpr bool is_constant_evaluated() { return false; } #endif +template +struct type_list { constexpr static int count = sizeof...(tt); }; + +template +struct type_list { constexpr static int count = sizeof...(tt) + 1; typedef t first_type; }; + +template +struct numeric_list { constexpr static std::size_t count = sizeof...(nn); }; + +template +struct numeric_list { static constexpr std::size_t count = sizeof...(nn) + 1; + static constexpr T first_value = n; }; + +#ifndef EIGEN_PARSED_BY_DOXYGEN +/* numeric list constructors + * + * equivalencies: + * constructor result + * typename gen_numeric_list::type numeric_list + * typename gen_numeric_list_reversed::type numeric_list + * typename gen_numeric_list_swapped_pair::type numeric_list + * typename gen_numeric_list_repeated::type numeric_list + */ + +template struct gen_numeric_list : gen_numeric_list {}; +template struct gen_numeric_list { typedef numeric_list type; }; + +template struct gen_numeric_list_reversed : gen_numeric_list_reversed {}; +template struct gen_numeric_list_reversed { typedef numeric_list type; }; + +template struct gen_numeric_list_swapped_pair : gen_numeric_list_swapped_pair {}; +template struct gen_numeric_list_swapped_pair { typedef numeric_list type; }; + +template struct gen_numeric_list_repeated : gen_numeric_list_repeated {}; +template struct gen_numeric_list_repeated { typedef numeric_list type; }; + +/* list manipulation: concatenate */ + +template struct concat; + +template struct concat, type_list> { typedef type_list type; }; +template struct concat, numeric_list > { typedef numeric_list type; }; + +template struct mconcat; +template struct mconcat { typedef a type; }; +template struct mconcat : concat {}; +template struct mconcat : concat::type> {}; + +/* list manipulation: extract slices */ + +template struct take; +template struct take> : concat, typename take>::type> {}; +template struct take> { typedef type_list<> type; }; +template struct take<0, type_list> { typedef type_list<> type; }; +template<> struct take<0, type_list<>> { typedef type_list<> type; }; + +template struct take> : concat, typename take>::type> {}; +// XXX The following breaks in gcc-11, and is invalid anyways. +// template struct take> { typedef numeric_list type; }; +template struct take<0, numeric_list> { typedef numeric_list type; }; +template struct take<0, numeric_list> { typedef numeric_list type; }; + +template struct h_skip_helper_numeric; +template struct h_skip_helper_numeric : h_skip_helper_numeric {}; +template struct h_skip_helper_numeric { typedef numeric_list type; }; +template struct h_skip_helper_numeric { typedef numeric_list type; }; +template struct h_skip_helper_numeric { typedef numeric_list type; }; + +template struct h_skip_helper_type; +template struct h_skip_helper_type : h_skip_helper_type {}; +template struct h_skip_helper_type<0, t, tt...> { typedef type_list type; }; +template struct h_skip_helper_type { typedef type_list<> type; }; +template<> struct h_skip_helper_type<0> { typedef type_list<> type; }; +#endif //not EIGEN_PARSED_BY_DOXYGEN + +template +struct h_skip { + template + constexpr static EIGEN_STRONG_INLINE typename h_skip_helper_numeric::type helper(numeric_list) { return typename h_skip_helper_numeric::type(); } + template + constexpr static EIGEN_STRONG_INLINE typename h_skip_helper_type::type helper(type_list) { return typename h_skip_helper_type::type(); } +}; + +template struct skip { typedef decltype(h_skip::helper(a())) type; }; + +template struct slice : take::type> {}; + +/* list manipulation: retrieve single element from list */ + +template struct get; + +template struct get> : get> {}; +template struct get<0, type_list> { typedef a type; }; + +template struct get> : get> {}; +template struct get<0, numeric_list> { constexpr static T value = a; }; + +template constexpr T array_get(const numeric_list&) { + return get<(int)n, numeric_list>::value; +} + +/* always get type, regardless of dummy; good for parameter pack expansion */ + +template struct id_numeric { typedef t type; }; +template struct id_type { typedef t type; }; + +/* equality checking, flagged version */ + +template struct is_same_gf : is_same { constexpr static int global_flags = 0; }; + +/* apply_op to list */ + +template< + bool from_left, // false + template class op, + typename additional_param, + typename... values +> +struct h_apply_op_helper { typedef type_list::type...> type; }; +template< + template class op, + typename additional_param, + typename... values +> +struct h_apply_op_helper { typedef type_list::type...> type; }; + +template< + bool from_left, + template class op, + typename additional_param +> +struct h_apply_op +{ + template + constexpr static typename h_apply_op_helper::type helper(type_list) + { return typename h_apply_op_helper::type(); } +}; + +template< + template class op, + typename additional_param, + typename a +> +struct apply_op_from_left { typedef decltype(h_apply_op::helper(a())) type; }; + +template< + template class op, + typename additional_param, + typename a +> +struct apply_op_from_right { typedef decltype(h_apply_op::helper(a())) type; }; + +/* see if an element is in a list */ + +template< + template class test, + typename check_against, + typename h_list, + bool last_check_positive = false +> +struct contained_in_list; + +template< + template class test, + typename check_against, + typename h_list +> +struct contained_in_list +{ + constexpr static bool value = true; +}; + +template< + template class test, + typename check_against, + typename a, + typename... as +> +struct contained_in_list, false> : contained_in_list, test::value> {}; + +template< + template class test, + typename check_against, + typename... empty +> +struct contained_in_list, false> { constexpr static bool value = false; }; + +/* see if an element is in a list and check for global flags */ + +template< + template class test, + typename check_against, + typename h_list, + int default_flags = 0, + bool last_check_positive = false, + int last_check_flags = default_flags +> +struct contained_in_list_gf; + +template< + template class test, + typename check_against, + typename h_list, + int default_flags, + int last_check_flags +> +struct contained_in_list_gf +{ + constexpr static bool value = true; + constexpr static int global_flags = last_check_flags; +}; + +template< + template class test, + typename check_against, + typename a, + typename... as, + int default_flags, + int last_check_flags +> +struct contained_in_list_gf, default_flags, false, last_check_flags> : contained_in_list_gf, default_flags, test::value, test::global_flags> {}; + +template< + template class test, + typename check_against, + typename... empty, + int default_flags, + int last_check_flags +> +struct contained_in_list_gf, default_flags, false, last_check_flags> { constexpr static bool value = false; constexpr static int global_flags = default_flags; }; + +/* generic reductions */ + +template< + typename Reducer, + typename... Ts +> struct reduce; + +template< + typename Reducer +> struct reduce +{ + EIGEN_DEVICE_FUNC constexpr static EIGEN_STRONG_INLINE int run() { return Reducer::Identity; } +}; + +template< + typename Reducer, + typename A +> struct reduce +{ + EIGEN_DEVICE_FUNC constexpr static EIGEN_STRONG_INLINE A run(A a) { return a; } +}; + +template< + typename Reducer, + typename A, + typename... Ts +> struct reduce +{ + EIGEN_DEVICE_FUNC constexpr static EIGEN_STRONG_INLINE auto run(A a, Ts... ts) -> decltype(Reducer::run(a, reduce::run(ts...))) { + return Reducer::run(a, reduce::run(ts...)); + } +}; + +/* generic binary operations */ + +struct sum_op { + template EIGEN_DEVICE_FUNC constexpr static EIGEN_STRONG_INLINE auto run(A a, B b) -> decltype(a + b) { return a + b; } + static constexpr int Identity = 0; +}; +struct product_op { + template EIGEN_DEVICE_FUNC constexpr static EIGEN_STRONG_INLINE auto run(A a, B b) -> decltype(a * b) { return a * b; } + static constexpr int Identity = 1; +}; + +struct logical_and_op { template constexpr static EIGEN_STRONG_INLINE auto run(A a, B b) -> decltype(a && b) { return a && b; } }; +struct logical_or_op { template constexpr static EIGEN_STRONG_INLINE auto run(A a, B b) -> decltype(a || b) { return a || b; } }; + +struct equal_op { template constexpr static EIGEN_STRONG_INLINE auto run(A a, B b) -> decltype(a == b) { return a == b; } }; +struct not_equal_op { template constexpr static EIGEN_STRONG_INLINE auto run(A a, B b) -> decltype(a != b) { return a != b; } }; +struct lesser_op { template constexpr static EIGEN_STRONG_INLINE auto run(A a, B b) -> decltype(a < b) { return a < b; } }; +struct lesser_equal_op { template constexpr static EIGEN_STRONG_INLINE auto run(A a, B b) -> decltype(a <= b) { return a <= b; } }; +struct greater_op { template constexpr static EIGEN_STRONG_INLINE auto run(A a, B b) -> decltype(a > b) { return a > b; } }; +struct greater_equal_op { template constexpr static EIGEN_STRONG_INLINE auto run(A a, B b) -> decltype(a >= b) { return a >= b; } }; + +/* generic unary operations */ + +struct not_op { template constexpr static EIGEN_STRONG_INLINE auto run(A a) -> decltype(!a) { return !a; } }; +struct negation_op { template constexpr static EIGEN_STRONG_INLINE auto run(A a) -> decltype(-a) { return -a; } }; +struct greater_equal_zero_op { template constexpr static EIGEN_STRONG_INLINE auto run(A a) -> decltype(a >= 0) { return a >= 0; } }; + + +/* reductions for lists */ + +// using auto -> return value spec makes ICC 13.0 and 13.1 crash here, so we have to hack it +// together in front... (13.0 doesn't work with array_prod/array_reduce/... anyway, but 13.1 +// does... +template +EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE decltype(reduce::run((*((Ts*)0))...)) arg_prod(Ts... ts) +{ + return reduce::run(ts...); +} + +template +constexpr EIGEN_STRONG_INLINE decltype(reduce::run((*((Ts*)0))...)) arg_sum(Ts... ts) +{ + return reduce::run(ts...); +} + +/* reverse arrays */ + +template +constexpr EIGEN_STRONG_INLINE Array h_array_reverse(Array arr, numeric_list) +{ + return {{array_get(arr)...}}; +} + +template +constexpr EIGEN_STRONG_INLINE array array_reverse(array arr) +{ + return h_array_reverse(arr, typename gen_numeric_list::type()); +} + + +/* generic array reductions */ + +// can't reuse standard reduce() interface above because Intel's Compiler +// *really* doesn't like it, so we just reimplement the stuff +// (start from N - 1 and work down to 0 because specialization for +// n == N - 1 also doesn't work in Intel's compiler, so it goes into +// an infinite loop) +template +struct h_array_reduce { + EIGEN_DEVICE_FUNC constexpr static EIGEN_STRONG_INLINE auto run(array arr, T identity) -> decltype(Reducer::run(h_array_reduce::run(arr, identity), array_get(arr))) + { + return Reducer::run(h_array_reduce::run(arr, identity), array_get(arr)); + } +}; + +template +struct h_array_reduce +{ + EIGEN_DEVICE_FUNC constexpr static EIGEN_STRONG_INLINE T run(const array& arr, T) + { + return array_get<0>(arr); + } +}; + +template +struct h_array_reduce +{ + EIGEN_DEVICE_FUNC constexpr static EIGEN_STRONG_INLINE T run(const array&, T identity) + { + return identity; + } +}; + +template +EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE auto array_reduce(const array& arr, T identity) -> decltype(h_array_reduce::run(arr, identity)) +{ + return h_array_reduce::run(arr, identity); +} + +/* standard array reductions */ + +template +EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE auto array_sum(const array& arr) -> decltype(array_reduce(arr, static_cast(0))) +{ + return array_reduce(arr, static_cast(0)); +} + +template +EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE auto array_prod(const array& arr) -> decltype(array_reduce(arr, static_cast(1))) +{ + return array_reduce(arr, static_cast(1)); +} + +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE t array_prod(const std::vector& a) { + eigen_assert(a.size() > 0); + t prod = 1; + for (size_t i = 0; i < a.size(); ++i) { prod *= a[i]; } + return prod; +} + +/* zip an array */ + +template +constexpr EIGEN_STRONG_INLINE array h_array_zip(array a, array b, numeric_list) +{ + return array{{ Op::run(array_get(a), array_get(b))... }}; +} + +template +constexpr EIGEN_STRONG_INLINE array array_zip(array a, array b) +{ + return h_array_zip(a, b, typename gen_numeric_list::type()); +} + +/* zip an array and reduce the result */ + +template +constexpr EIGEN_STRONG_INLINE auto h_array_zip_and_reduce(array a, array b, numeric_list) -> decltype(reduce::type...>::run(Op::run(array_get(a), array_get(b))...)) +{ + return reduce::type...>::run(Op::run(array_get(a), array_get(b))...); +} + +template +constexpr EIGEN_STRONG_INLINE auto array_zip_and_reduce(array a, array b) -> decltype(h_array_zip_and_reduce(a, b, typename gen_numeric_list::type())) +{ + return h_array_zip_and_reduce(a, b, typename gen_numeric_list::type()); +} + +/* apply stuff to an array */ + +template +constexpr EIGEN_STRONG_INLINE array h_array_apply(array a, numeric_list) +{ + return array{{ Op::run(array_get(a))... }}; +} + +template +constexpr EIGEN_STRONG_INLINE array array_apply(array a) +{ + return h_array_apply(a, typename gen_numeric_list::type()); +} + +/* apply stuff to an array and reduce */ + +template +constexpr EIGEN_STRONG_INLINE auto h_array_apply_and_reduce(array arr, numeric_list) -> decltype(reduce::type...>::run(Op::run(array_get(arr))...)) +{ + return reduce::type...>::run(Op::run(array_get(arr))...); +} + +template +constexpr EIGEN_STRONG_INLINE auto array_apply_and_reduce(array a) -> decltype(h_array_apply_and_reduce(a, typename gen_numeric_list::type())) +{ + return h_array_apply_and_reduce(a, typename gen_numeric_list::type()); +} + +/* repeat a value n times (and make an array out of it + * usage: + * array = repeat<16>(42); + */ + +template +struct h_repeat +{ + template + constexpr static EIGEN_STRONG_INLINE array run(t v, numeric_list) + { + return {{ typename id_numeric::type(v)... }}; + } +}; + +template +constexpr array repeat(t v) { return h_repeat::run(v, typename gen_numeric_list::type()); } + +/* instantiate a class by a C-style array */ +template +struct h_instantiate_by_c_array; + +template +struct h_instantiate_by_c_array +{ + static InstType run(ArrType* arr, Ps... args) + { + return h_instantiate_by_c_array::run(arr + 1, args..., arr[0]); + } +}; + +template +struct h_instantiate_by_c_array +{ + static InstType run(ArrType* arr, Ps... args) + { + return h_instantiate_by_c_array::run(arr + 1, arr[0], args...); + } +}; + +template +struct h_instantiate_by_c_array +{ + static InstType run(ArrType* arr, Ps... args) + { + (void)arr; + return InstType(args...); + } +}; + +template +struct h_instantiate_by_c_array +{ + static InstType run(ArrType* arr, Ps... args) + { + (void)arr; + return InstType(args...); + } +}; + +template +InstType instantiate_by_c_array(ArrType* arr) +{ + return h_instantiate_by_c_array::run(arr); +} + } // end namespace internal } // end namespace Eigen diff --git a/unsupported/Eigen/CXX11/src/ThreadPool/Barrier.h b/Eigen/src/ThreadPool/Barrier.h similarity index 100% rename from unsupported/Eigen/CXX11/src/ThreadPool/Barrier.h rename to Eigen/src/ThreadPool/Barrier.h diff --git a/unsupported/Eigen/CXX11/src/ThreadPool/EventCount.h b/Eigen/src/ThreadPool/EventCount.h similarity index 100% rename from unsupported/Eigen/CXX11/src/ThreadPool/EventCount.h rename to Eigen/src/ThreadPool/EventCount.h diff --git a/unsupported/Eigen/CXX11/src/ThreadPool/InternalHeaderCheck.h b/Eigen/src/ThreadPool/InternalHeaderCheck.h similarity index 76% rename from unsupported/Eigen/CXX11/src/ThreadPool/InternalHeaderCheck.h rename to Eigen/src/ThreadPool/InternalHeaderCheck.h index 82a89a9d0..44c0fca20 100644 --- a/unsupported/Eigen/CXX11/src/ThreadPool/InternalHeaderCheck.h +++ b/Eigen/src/ThreadPool/InternalHeaderCheck.h @@ -1,3 +1,3 @@ -#ifndef EIGEN_CXX11_THREADPOOL_MODULE_H +#ifndef EIGEN_THREADPOOL_MODULE_H #error "Please include unsupported/Eigen/CXX11/ThreadPool instead of including headers inside the src directory directly." #endif diff --git a/unsupported/Eigen/CXX11/src/ThreadPool/NonBlockingThreadPool.h b/Eigen/src/ThreadPool/NonBlockingThreadPool.h similarity index 100% rename from unsupported/Eigen/CXX11/src/ThreadPool/NonBlockingThreadPool.h rename to Eigen/src/ThreadPool/NonBlockingThreadPool.h diff --git a/unsupported/Eigen/CXX11/src/ThreadPool/RunQueue.h b/Eigen/src/ThreadPool/RunQueue.h similarity index 100% rename from unsupported/Eigen/CXX11/src/ThreadPool/RunQueue.h rename to Eigen/src/ThreadPool/RunQueue.h diff --git a/unsupported/Eigen/CXX11/src/ThreadPool/ThreadCancel.h b/Eigen/src/ThreadPool/ThreadCancel.h similarity index 100% rename from unsupported/Eigen/CXX11/src/ThreadPool/ThreadCancel.h rename to Eigen/src/ThreadPool/ThreadCancel.h diff --git a/unsupported/Eigen/CXX11/src/ThreadPool/ThreadEnvironment.h b/Eigen/src/ThreadPool/ThreadEnvironment.h similarity index 100% rename from unsupported/Eigen/CXX11/src/ThreadPool/ThreadEnvironment.h rename to Eigen/src/ThreadPool/ThreadEnvironment.h diff --git a/unsupported/Eigen/CXX11/src/ThreadPool/ThreadLocal.h b/Eigen/src/ThreadPool/ThreadLocal.h similarity index 100% rename from unsupported/Eigen/CXX11/src/ThreadPool/ThreadLocal.h rename to Eigen/src/ThreadPool/ThreadLocal.h diff --git a/unsupported/Eigen/CXX11/src/ThreadPool/ThreadPoolInterface.h b/Eigen/src/ThreadPool/ThreadPoolInterface.h similarity index 100% rename from unsupported/Eigen/CXX11/src/ThreadPool/ThreadPoolInterface.h rename to Eigen/src/ThreadPool/ThreadPoolInterface.h diff --git a/unsupported/Eigen/CXX11/src/ThreadPool/ThreadYield.h b/Eigen/src/ThreadPool/ThreadYield.h similarity index 100% rename from unsupported/Eigen/CXX11/src/ThreadPool/ThreadYield.h rename to Eigen/src/ThreadPool/ThreadYield.h diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index f402ab34a..98d1bad90 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -173,6 +173,7 @@ add_custom_target(BuildOfficial) ei_add_test(rand) ei_add_test(meta) +ei_add_test(maxsizevector) ei_add_test(numext) ei_add_test(sizeof) ei_add_test(dynalloc) @@ -311,7 +312,9 @@ ei_add_test(initializer_list_construction) ei_add_test(diagonal_matrix_variadic_ctor) ei_add_test(serializer) ei_add_test(tuple_test) - +ei_add_test(threads_eventcount "-pthread" "${CMAKE_THREAD_LIBS_INIT}") +ei_add_test(threads_runqueue "-pthread" "${CMAKE_THREAD_LIBS_INIT}") +ei_add_test(threads_non_blocking_thread_pool "-pthread" "${CMAKE_THREAD_LIBS_INIT}") add_executable(bug1213 bug1213.cpp bug1213_main.cpp) check_cxx_compiler_flag("-ffast-math" COMPILER_SUPPORT_FASTMATH) diff --git a/unsupported/test/cxx11_maxsizevector.cpp b/test/maxsizevector.cpp similarity index 97% rename from unsupported/test/cxx11_maxsizevector.cpp rename to test/maxsizevector.cpp index 22b51ba6a..084ea13f3 100644 --- a/unsupported/test/cxx11_maxsizevector.cpp +++ b/test/maxsizevector.cpp @@ -2,7 +2,7 @@ #include // std::exception -#include +#include struct Foo { diff --git a/test/meta.cpp b/test/meta.cpp index 97ebdd7a8..7e73706fc 100644 --- a/test/meta.cpp +++ b/test/meta.cpp @@ -9,6 +9,9 @@ #include "main.h" +#include +#include + template bool check_is_convertible(const From&, const To&) { @@ -131,3 +134,347 @@ EIGEN_DECLARE_TEST(meta) VERIFY_META_SQRT(1024); VERIFY_META_SQRT(1025); } + +using Eigen::internal::is_same; +using Eigen::internal::type_list; +using Eigen::internal::numeric_list; +using Eigen::internal::gen_numeric_list; +using Eigen::internal::gen_numeric_list_reversed; +using Eigen::internal::gen_numeric_list_swapped_pair; +using Eigen::internal::gen_numeric_list_repeated; +using Eigen::internal::concat; +using Eigen::internal::mconcat; +using Eigen::internal::take; +using Eigen::internal::skip; +using Eigen::internal::slice; +using Eigen::internal::get; +using Eigen::internal::id_numeric; +using Eigen::internal::id_type; +using Eigen::internal::is_same_gf; +using Eigen::internal::apply_op_from_left; +using Eigen::internal::apply_op_from_right; +using Eigen::internal::contained_in_list; +using Eigen::internal::contained_in_list_gf; +using Eigen::internal::arg_prod; +using Eigen::internal::arg_sum; +using Eigen::internal::sum_op; +using Eigen::internal::product_op; +using Eigen::internal::array_reverse; +using Eigen::internal::array_sum; +using Eigen::internal::array_prod; +using Eigen::internal::array_reduce; +using Eigen::internal::array_zip; +using Eigen::internal::array_zip_and_reduce; +using Eigen::internal::array_apply; +using Eigen::internal::array_apply_and_reduce; +using Eigen::internal::repeat; +using Eigen::internal::instantiate_by_c_array; + +struct dummy_a {}; +struct dummy_b {}; +struct dummy_c {}; +struct dummy_d {}; +struct dummy_e {}; + +// dummy operation for testing apply +template struct dummy_op; +template<> struct dummy_op { typedef dummy_c type; }; +template<> struct dummy_op { typedef dummy_d type; }; +template<> struct dummy_op { typedef dummy_a type; }; +template<> struct dummy_op { typedef dummy_d type; }; +template<> struct dummy_op { typedef dummy_b type; }; +template<> struct dummy_op { typedef dummy_d type; }; +template<> struct dummy_op { typedef dummy_e type; }; +template<> struct dummy_op { typedef dummy_e type; }; +template<> struct dummy_op { typedef dummy_e type; }; + +template struct dummy_test { constexpr static bool value = false; constexpr static int global_flags = 0; }; +template<> struct dummy_test { constexpr static bool value = true; constexpr static int global_flags = 1; }; +template<> struct dummy_test { constexpr static bool value = true; constexpr static int global_flags = 2; }; +template<> struct dummy_test { constexpr static bool value = true; constexpr static int global_flags = 4; }; + +struct times2_op { template static A run(A v) { return v * 2; } }; + +struct dummy_inst +{ + int c; + + dummy_inst() : c(0) {} + explicit dummy_inst(int) : c(1) {} + dummy_inst(int, int) : c(2) {} + dummy_inst(int, int, int) : c(3) {} + dummy_inst(int, int, int, int) : c(4) {} + dummy_inst(int, int, int, int, int) : c(5) {} +}; + +static void test_gen_numeric_list() +{ + VERIFY((is_same::type, numeric_list>::value)); + VERIFY((is_same::type, numeric_list>::value)); + VERIFY((is_same::type, numeric_list>::value)); + VERIFY((is_same::type, numeric_list>::value)); + VERIFY((is_same::type, numeric_list>::value)); + + VERIFY((is_same::type, numeric_list>::value)); + VERIFY((is_same::type, numeric_list>::value)); + VERIFY((is_same::type, numeric_list>::value)); + VERIFY((is_same::type, numeric_list>::value)); + VERIFY((is_same::type, numeric_list>::value)); + + VERIFY((is_same::type, numeric_list>::value)); + VERIFY((is_same::type, numeric_list>::value)); + VERIFY((is_same::type, numeric_list>::value)); + VERIFY((is_same::type, numeric_list>::value)); + VERIFY((is_same::type, numeric_list>::value)); + + VERIFY((is_same::type, numeric_list>::value)); + VERIFY((is_same::type, numeric_list>::value)); + VERIFY((is_same::type, numeric_list>::value)); + VERIFY((is_same::type, numeric_list>::value)); + VERIFY((is_same::type, numeric_list>::value)); + + VERIFY((is_same::type, numeric_list>::value)); + VERIFY((is_same::type, numeric_list>::value)); + VERIFY((is_same::type, numeric_list>::value)); + VERIFY((is_same::type, numeric_list>::value)); + VERIFY((is_same::type, numeric_list>::value)); + + VERIFY((is_same::type, numeric_list>::value)); + VERIFY((is_same::type, numeric_list>::value)); + VERIFY((is_same::type, numeric_list>::value)); + VERIFY((is_same::type, numeric_list>::value)); + VERIFY((is_same::type, numeric_list>::value)); + + VERIFY((is_same::type, numeric_list>::value)); + VERIFY((is_same::type, numeric_list>::value)); + VERIFY((is_same::type, numeric_list>::value)); + VERIFY((is_same::type, numeric_list>::value)); + VERIFY((is_same::type, numeric_list>::value)); +} + +static void test_concat() +{ + VERIFY((is_same, type_list<>>::type, type_list>::value)); + VERIFY((is_same, type_list>::type, type_list>::value)); + VERIFY((is_same, type_list>::type, type_list>::value)); + VERIFY((is_same, type_list>::type, type_list>::value)); + VERIFY((is_same, type_list>::type, type_list>::value)); + + VERIFY((is_same, numeric_list>::type, numeric_list>::value)); + VERIFY((is_same, numeric_list>::type, numeric_list>::value)); + VERIFY((is_same, numeric_list>::type, numeric_list>::value)); + VERIFY((is_same, numeric_list>::type, numeric_list>::value)); + VERIFY((is_same, numeric_list>::type, numeric_list>::value)); + + VERIFY((is_same>::type, type_list>::value)); + VERIFY((is_same, type_list>::type, type_list>::value)); + VERIFY((is_same, type_list, type_list>::type, type_list>::value)); + VERIFY((is_same, type_list>::type, type_list>::value)); + VERIFY((is_same, type_list>::type, type_list>::value)); + + VERIFY((is_same>::type, numeric_list>::value)); + VERIFY((is_same, numeric_list>::type, numeric_list>::value)); + VERIFY((is_same, numeric_list, numeric_list>::type, numeric_list>::value)); + VERIFY((is_same, numeric_list>::type, numeric_list>::value)); + VERIFY((is_same, numeric_list>::type, numeric_list>::value)); +} + +static void test_slice() +{ + typedef type_list tl; + typedef numeric_list il; + + VERIFY((is_same::type, type_list<>>::value)); + VERIFY((is_same::type, type_list>::value)); + VERIFY((is_same::type, type_list>::value)); + VERIFY((is_same::type, type_list>::value)); + VERIFY((is_same::type, type_list>::value)); + VERIFY((is_same::type, type_list>::value)); + VERIFY((is_same::type, type_list>::value)); + + VERIFY((is_same::type, numeric_list>::value)); + VERIFY((is_same::type, numeric_list>::value)); + VERIFY((is_same::type, numeric_list>::value)); + VERIFY((is_same::type, numeric_list>::value)); + VERIFY((is_same::type, numeric_list>::value)); + VERIFY((is_same::type, numeric_list>::value)); + VERIFY((is_same::type, numeric_list>::value)); + + VERIFY((is_same::type, type_list>::value)); + VERIFY((is_same::type, type_list>::value)); + VERIFY((is_same::type, type_list>::value)); + VERIFY((is_same::type, type_list>::value)); + VERIFY((is_same::type, type_list>::value)); + VERIFY((is_same::type, type_list>::value)); + VERIFY((is_same::type, type_list<>>::value)); + + VERIFY((is_same::type, numeric_list>::value)); + VERIFY((is_same::type, numeric_list>::value)); + VERIFY((is_same::type, numeric_list>::value)); + VERIFY((is_same::type, numeric_list>::value)); + VERIFY((is_same::type, numeric_list>::value)); + VERIFY((is_same::type, numeric_list>::value)); + VERIFY((is_same::type, numeric_list>::value)); + + VERIFY((is_same::type, typename take<3, tl>::type>::value)); + VERIFY((is_same::type, typename take<3, il>::type>::value)); + VERIFY((is_same::type, type_list>::value)); + VERIFY((is_same::type, numeric_list>::value)); +} + +static void test_get() +{ + typedef type_list tl; + typedef numeric_list il; + + VERIFY((is_same::type, dummy_a>::value)); + VERIFY((is_same::type, dummy_a>::value)); + VERIFY((is_same::type, dummy_b>::value)); + VERIFY((is_same::type, dummy_b>::value)); + VERIFY((is_same::type, dummy_c>::value)); + VERIFY((is_same::type, dummy_c>::value)); + + VERIFY_IS_EQUAL(((int)get<0, il>::value), 4); + VERIFY_IS_EQUAL(((int)get<1, il>::value), 8); + VERIFY_IS_EQUAL(((int)get<2, il>::value), 15); + VERIFY_IS_EQUAL(((int)get<3, il>::value), 16); + VERIFY_IS_EQUAL(((int)get<4, il>::value), 23); + VERIFY_IS_EQUAL(((int)get<5, il>::value), 42); +} + +static void test_id_helper(dummy_a a, dummy_a b, dummy_a c) +{ + (void)a; + (void)b; + (void)c; +} + +template +static void test_id_numeric() +{ + test_id_helper(typename id_numeric::type()...); +} + +template +static void test_id_type() +{ + test_id_helper(typename id_type::type()...); +} + +static void test_id() +{ + // don't call VERIFY here, just assume it works if it compiles + // (otherwise it will complain that it can't find the function) + test_id_numeric<1, 4, 6>(); + test_id_type(); +} + +static void test_is_same_gf() +{ + VERIFY((!is_same_gf::value)); + VERIFY((!!is_same_gf::value)); + VERIFY_IS_EQUAL((!!is_same_gf::global_flags), false); + VERIFY_IS_EQUAL((!!is_same_gf::global_flags), false); +} + +static void test_apply_op() +{ + typedef type_list tl; + VERIFY((!!is_same::type, type_list>::value)); + VERIFY((!!is_same::type, type_list>::value)); +} + +static void test_contained_in_list() +{ + typedef type_list tl; + + VERIFY((!!contained_in_list::value)); + VERIFY((!!contained_in_list::value)); + VERIFY((!!contained_in_list::value)); + VERIFY((!contained_in_list::value)); + VERIFY((!contained_in_list::value)); + + VERIFY((!!contained_in_list_gf::value)); + VERIFY((!!contained_in_list_gf::value)); + VERIFY((!!contained_in_list_gf::value)); + VERIFY((!contained_in_list_gf::value)); + VERIFY((!contained_in_list_gf::value)); + + VERIFY_IS_EQUAL(((int)contained_in_list_gf::global_flags), 1); + VERIFY_IS_EQUAL(((int)contained_in_list_gf::global_flags), 2); + VERIFY_IS_EQUAL(((int)contained_in_list_gf::global_flags), 4); + VERIFY_IS_EQUAL(((int)contained_in_list_gf::global_flags), 0); + VERIFY_IS_EQUAL(((int)contained_in_list_gf::global_flags), 0); +} + +static void test_arg_reductions() +{ + VERIFY_IS_EQUAL(arg_sum(1,2,3,4), 10); + VERIFY_IS_EQUAL(arg_prod(1,2,3,4), 24); + VERIFY_IS_APPROX(arg_sum(0.5, 2, 5), 7.5); + VERIFY_IS_APPROX(arg_prod(0.5, 2, 5), 5.0); +} + +static void test_array_reverse_and_reduce() +{ + array a{{4, 8, 15, 16, 23, 42}}; + array b{{42, 23, 16, 15, 8, 4}}; + + // there is no operator<< for std::array, so VERIFY_IS_EQUAL will + // not compile + VERIFY((array_reverse(a) == b)); + VERIFY((array_reverse(b) == a)); + VERIFY_IS_EQUAL((array_sum(a)), 108); + VERIFY_IS_EQUAL((array_sum(b)), 108); + VERIFY_IS_EQUAL((array_prod(a)), 7418880); + VERIFY_IS_EQUAL((array_prod(b)), 7418880); +} + +static void test_array_zip_and_apply() +{ + array a{{4, 8, 15, 16, 23, 42}}; + array b{{0, 1, 2, 3, 4, 5}}; + array c{{4, 9, 17, 19, 27, 47}}; + array d{{0, 8, 30, 48, 92, 210}}; + array e{{0, 2, 4, 6, 8, 10}}; + + VERIFY((array_zip(a, b) == c)); + VERIFY((array_zip(a, b) == d)); + VERIFY((array_apply(b) == e)); + VERIFY_IS_EQUAL((array_apply_and_reduce(a)), 216); + VERIFY_IS_EQUAL((array_apply_and_reduce(b)), 30); + VERIFY_IS_EQUAL((array_zip_and_reduce(a, b)), 14755932); + VERIFY_IS_EQUAL((array_zip_and_reduce(a, b)), 388); +} + +static void test_array_misc() +{ + array a3{{1, 1, 1}}; + array a6{{2, 2, 2, 2, 2, 2}}; + VERIFY((repeat<3, int>(1) == a3)); + VERIFY((repeat<6, int>(2) == a6)); + + int data[5] = { 0, 1, 2, 3, 4 }; + VERIFY_IS_EQUAL((instantiate_by_c_array(data).c), 0); + VERIFY_IS_EQUAL((instantiate_by_c_array(data).c), 1); + VERIFY_IS_EQUAL((instantiate_by_c_array(data).c), 2); + VERIFY_IS_EQUAL((instantiate_by_c_array(data).c), 3); + VERIFY_IS_EQUAL((instantiate_by_c_array(data).c), 4); + VERIFY_IS_EQUAL((instantiate_by_c_array(data).c), 5); +} + +EIGEN_DECLARE_TEST(cxx11_meta) +{ + CALL_SUBTEST(test_gen_numeric_list()); + CALL_SUBTEST(test_concat()); + CALL_SUBTEST(test_slice()); + CALL_SUBTEST(test_get()); + CALL_SUBTEST(test_id()); + CALL_SUBTEST(test_is_same_gf()); + CALL_SUBTEST(test_apply_op()); + CALL_SUBTEST(test_contained_in_list()); + CALL_SUBTEST(test_arg_reductions()); + CALL_SUBTEST(test_array_reverse_and_reduce()); + CALL_SUBTEST(test_array_zip_and_apply()); + CALL_SUBTEST(test_array_misc()); +} diff --git a/unsupported/test/cxx11_eventcount.cpp b/test/threads_eventcount.cpp similarity index 99% rename from unsupported/test/cxx11_eventcount.cpp rename to test/threads_eventcount.cpp index 714540e49..76fab319e 100644 --- a/unsupported/test/cxx11_eventcount.cpp +++ b/test/threads_eventcount.cpp @@ -10,7 +10,7 @@ #define EIGEN_USE_THREADS #include "main.h" -#include +#include // Visual studio doesn't implement a rand_r() function since its // implementation of rand() is already thread safe diff --git a/unsupported/test/cxx11_non_blocking_thread_pool.cpp b/test/threads_non_blocking_thread_pool.cpp similarity index 98% rename from unsupported/test/cxx11_non_blocking_thread_pool.cpp rename to test/threads_non_blocking_thread_pool.cpp index 993ee1789..25ba96c63 100644 --- a/unsupported/test/cxx11_non_blocking_thread_pool.cpp +++ b/test/threads_non_blocking_thread_pool.cpp @@ -10,8 +10,7 @@ #define EIGEN_USE_THREADS #include "main.h" -#include "Eigen/CXX11/ThreadPool" -#include "Eigen/CXX11/Tensor" +#include "Eigen/ThreadPool" static void test_create_destroy_empty_pool() { diff --git a/unsupported/test/cxx11_runqueue.cpp b/test/threads_runqueue.cpp similarity index 99% rename from unsupported/test/cxx11_runqueue.cpp rename to test/threads_runqueue.cpp index 0f7f13bd1..99668e773 100644 --- a/unsupported/test/cxx11_runqueue.cpp +++ b/test/threads_runqueue.cpp @@ -11,7 +11,7 @@ #define EIGEN_USE_THREADS #include #include "main.h" -#include +#include // Visual studio doesn't implement a rand_r() function since its diff --git a/unsupported/Eigen/CXX11/Tensor b/unsupported/Eigen/CXX11/Tensor index 98e0918c5..5b1c48e7e 100644 --- a/unsupported/Eigen/CXX11/Tensor +++ b/unsupported/Eigen/CXX11/Tensor @@ -18,8 +18,8 @@ #include "../../../Eigen/src/Core/util/DisableStupidWarnings.h" // IWYU pragma: begin_exports -#include "src/util/CXX11Meta.h" -#include "src/util/MaxSizeVector.h" +#include "src/Core/util/Meta.h" +#include "src/Core/util/MaxSizeVector.h" // IWYU pragma: end_exports /** \defgroup CXX11_Tensor_Module Tensor Module diff --git a/unsupported/Eigen/CXX11/ThreadPool b/unsupported/Eigen/CXX11/ThreadPool index 041ba07b2..9cdf2c043 100644 --- a/unsupported/Eigen/CXX11/ThreadPool +++ b/unsupported/Eigen/CXX11/ThreadPool @@ -1,73 +1 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2016 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/. - -#ifndef EIGEN_CXX11_THREADPOOL_MODULE_H -#define EIGEN_CXX11_THREADPOOL_MODULE_H - -#include "../../../Eigen/Core" - -#include "../../../Eigen/src/Core/util/DisableStupidWarnings.h" - -/** \defgroup CXX11_ThreadPool_Module C++11 ThreadPool Module - * - * This module provides 2 threadpool implementations - * - a simple reference implementation - * - a faster non blocking implementation - * - * This module requires C++11. - * - * \code - * #include - * \endcode - */ - - -// The code depends on CXX11, so only include the module if the -// compiler supports it. -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -// There are non-parenthesized calls to "max" in the header, -// which trigger a check in test/main.h causing compilation to fail. -// We work around the check here by removing the check for max in -// the case where we have to emulate thread_local. -#ifdef max -#undef max -#endif -#include - -#include "src/util/CXX11Meta.h" -#include "src/util/MaxSizeVector.h" - -// IWYU pragma: begin_exports -#include "src/ThreadPool/ThreadLocal.h" -#include "src/ThreadPool/ThreadYield.h" -#include "src/ThreadPool/ThreadCancel.h" -#include "src/ThreadPool/EventCount.h" -#include "src/ThreadPool/RunQueue.h" -#include "src/ThreadPool/ThreadPoolInterface.h" -#include "src/ThreadPool/ThreadEnvironment.h" -#include "src/ThreadPool/Barrier.h" -#include "src/ThreadPool/NonBlockingThreadPool.h" -// IWYU pragma: end_exports - -#include "../../../Eigen/src/Core/util/ReenableStupidWarnings.h" - -#endif // EIGEN_CXX11_THREADPOOL_MODULE_H +#include "../../../Eigen/ThreadPool" \ No newline at end of file diff --git a/unsupported/test/CMakeLists.txt b/unsupported/test/CMakeLists.txt index 45cc4a3d6..cd9775699 100644 --- a/unsupported/test/CMakeLists.txt +++ b/unsupported/test/CMakeLists.txt @@ -223,12 +223,6 @@ if(EIGEN_TEST_SYCL) set(EIGEN_SYCL OFF) endif() -ei_add_test(cxx11_eventcount "-pthread" "${CMAKE_THREAD_LIBS_INIT}") -ei_add_test(cxx11_runqueue "-pthread" "${CMAKE_THREAD_LIBS_INIT}") -ei_add_test(cxx11_non_blocking_thread_pool "-pthread" "${CMAKE_THREAD_LIBS_INIT}") - -ei_add_test(cxx11_meta) -ei_add_test(cxx11_maxsizevector) ei_add_test(cxx11_tensor_argmax) ei_add_test(cxx11_tensor_assign) ei_add_test(cxx11_tensor_block_access) diff --git a/unsupported/test/cxx11_meta.cpp b/unsupported/test/cxx11_meta.cpp deleted file mode 100644 index 510e11032..000000000 --- a/unsupported/test/cxx11_meta.cpp +++ /dev/null @@ -1,357 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2013 Christian Seiler -// -// 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::internal::is_same; -using Eigen::internal::type_list; -using Eigen::internal::numeric_list; -using Eigen::internal::gen_numeric_list; -using Eigen::internal::gen_numeric_list_reversed; -using Eigen::internal::gen_numeric_list_swapped_pair; -using Eigen::internal::gen_numeric_list_repeated; -using Eigen::internal::concat; -using Eigen::internal::mconcat; -using Eigen::internal::take; -using Eigen::internal::skip; -using Eigen::internal::slice; -using Eigen::internal::get; -using Eigen::internal::id_numeric; -using Eigen::internal::id_type; -using Eigen::internal::is_same_gf; -using Eigen::internal::apply_op_from_left; -using Eigen::internal::apply_op_from_right; -using Eigen::internal::contained_in_list; -using Eigen::internal::contained_in_list_gf; -using Eigen::internal::arg_prod; -using Eigen::internal::arg_sum; -using Eigen::internal::sum_op; -using Eigen::internal::product_op; -using Eigen::internal::array_reverse; -using Eigen::internal::array_sum; -using Eigen::internal::array_prod; -using Eigen::internal::array_reduce; -using Eigen::internal::array_zip; -using Eigen::internal::array_zip_and_reduce; -using Eigen::internal::array_apply; -using Eigen::internal::array_apply_and_reduce; -using Eigen::internal::repeat; -using Eigen::internal::instantiate_by_c_array; - -struct dummy_a {}; -struct dummy_b {}; -struct dummy_c {}; -struct dummy_d {}; -struct dummy_e {}; - -// dummy operation for testing apply -template struct dummy_op; -template<> struct dummy_op { typedef dummy_c type; }; -template<> struct dummy_op { typedef dummy_d type; }; -template<> struct dummy_op { typedef dummy_a type; }; -template<> struct dummy_op { typedef dummy_d type; }; -template<> struct dummy_op { typedef dummy_b type; }; -template<> struct dummy_op { typedef dummy_d type; }; -template<> struct dummy_op { typedef dummy_e type; }; -template<> struct dummy_op { typedef dummy_e type; }; -template<> struct dummy_op { typedef dummy_e type; }; - -template struct dummy_test { constexpr static bool value = false; constexpr static int global_flags = 0; }; -template<> struct dummy_test { constexpr static bool value = true; constexpr static int global_flags = 1; }; -template<> struct dummy_test { constexpr static bool value = true; constexpr static int global_flags = 2; }; -template<> struct dummy_test { constexpr static bool value = true; constexpr static int global_flags = 4; }; - -struct times2_op { template static A run(A v) { return v * 2; } }; - -struct dummy_inst -{ - int c; - - dummy_inst() : c(0) {} - explicit dummy_inst(int) : c(1) {} - dummy_inst(int, int) : c(2) {} - dummy_inst(int, int, int) : c(3) {} - dummy_inst(int, int, int, int) : c(4) {} - dummy_inst(int, int, int, int, int) : c(5) {} -}; - -static void test_gen_numeric_list() -{ - VERIFY((is_same::type, numeric_list>::value)); - VERIFY((is_same::type, numeric_list>::value)); - VERIFY((is_same::type, numeric_list>::value)); - VERIFY((is_same::type, numeric_list>::value)); - VERIFY((is_same::type, numeric_list>::value)); - - VERIFY((is_same::type, numeric_list>::value)); - VERIFY((is_same::type, numeric_list>::value)); - VERIFY((is_same::type, numeric_list>::value)); - VERIFY((is_same::type, numeric_list>::value)); - VERIFY((is_same::type, numeric_list>::value)); - - VERIFY((is_same::type, numeric_list>::value)); - VERIFY((is_same::type, numeric_list>::value)); - VERIFY((is_same::type, numeric_list>::value)); - VERIFY((is_same::type, numeric_list>::value)); - VERIFY((is_same::type, numeric_list>::value)); - - VERIFY((is_same::type, numeric_list>::value)); - VERIFY((is_same::type, numeric_list>::value)); - VERIFY((is_same::type, numeric_list>::value)); - VERIFY((is_same::type, numeric_list>::value)); - VERIFY((is_same::type, numeric_list>::value)); - - VERIFY((is_same::type, numeric_list>::value)); - VERIFY((is_same::type, numeric_list>::value)); - VERIFY((is_same::type, numeric_list>::value)); - VERIFY((is_same::type, numeric_list>::value)); - VERIFY((is_same::type, numeric_list>::value)); - - VERIFY((is_same::type, numeric_list>::value)); - VERIFY((is_same::type, numeric_list>::value)); - VERIFY((is_same::type, numeric_list>::value)); - VERIFY((is_same::type, numeric_list>::value)); - VERIFY((is_same::type, numeric_list>::value)); - - VERIFY((is_same::type, numeric_list>::value)); - VERIFY((is_same::type, numeric_list>::value)); - VERIFY((is_same::type, numeric_list>::value)); - VERIFY((is_same::type, numeric_list>::value)); - VERIFY((is_same::type, numeric_list>::value)); -} - -static void test_concat() -{ - VERIFY((is_same, type_list<>>::type, type_list>::value)); - VERIFY((is_same, type_list>::type, type_list>::value)); - VERIFY((is_same, type_list>::type, type_list>::value)); - VERIFY((is_same, type_list>::type, type_list>::value)); - VERIFY((is_same, type_list>::type, type_list>::value)); - - VERIFY((is_same, numeric_list>::type, numeric_list>::value)); - VERIFY((is_same, numeric_list>::type, numeric_list>::value)); - VERIFY((is_same, numeric_list>::type, numeric_list>::value)); - VERIFY((is_same, numeric_list>::type, numeric_list>::value)); - VERIFY((is_same, numeric_list>::type, numeric_list>::value)); - - VERIFY((is_same>::type, type_list>::value)); - VERIFY((is_same, type_list>::type, type_list>::value)); - VERIFY((is_same, type_list, type_list>::type, type_list>::value)); - VERIFY((is_same, type_list>::type, type_list>::value)); - VERIFY((is_same, type_list>::type, type_list>::value)); - - VERIFY((is_same>::type, numeric_list>::value)); - VERIFY((is_same, numeric_list>::type, numeric_list>::value)); - VERIFY((is_same, numeric_list, numeric_list>::type, numeric_list>::value)); - VERIFY((is_same, numeric_list>::type, numeric_list>::value)); - VERIFY((is_same, numeric_list>::type, numeric_list>::value)); -} - -static void test_slice() -{ - typedef type_list tl; - typedef numeric_list il; - - VERIFY((is_same::type, type_list<>>::value)); - VERIFY((is_same::type, type_list>::value)); - VERIFY((is_same::type, type_list>::value)); - VERIFY((is_same::type, type_list>::value)); - VERIFY((is_same::type, type_list>::value)); - VERIFY((is_same::type, type_list>::value)); - VERIFY((is_same::type, type_list>::value)); - - VERIFY((is_same::type, numeric_list>::value)); - VERIFY((is_same::type, numeric_list>::value)); - VERIFY((is_same::type, numeric_list>::value)); - VERIFY((is_same::type, numeric_list>::value)); - VERIFY((is_same::type, numeric_list>::value)); - VERIFY((is_same::type, numeric_list>::value)); - VERIFY((is_same::type, numeric_list>::value)); - - VERIFY((is_same::type, type_list>::value)); - VERIFY((is_same::type, type_list>::value)); - VERIFY((is_same::type, type_list>::value)); - VERIFY((is_same::type, type_list>::value)); - VERIFY((is_same::type, type_list>::value)); - VERIFY((is_same::type, type_list>::value)); - VERIFY((is_same::type, type_list<>>::value)); - - VERIFY((is_same::type, numeric_list>::value)); - VERIFY((is_same::type, numeric_list>::value)); - VERIFY((is_same::type, numeric_list>::value)); - VERIFY((is_same::type, numeric_list>::value)); - VERIFY((is_same::type, numeric_list>::value)); - VERIFY((is_same::type, numeric_list>::value)); - VERIFY((is_same::type, numeric_list>::value)); - - VERIFY((is_same::type, typename take<3, tl>::type>::value)); - VERIFY((is_same::type, typename take<3, il>::type>::value)); - VERIFY((is_same::type, type_list>::value)); - VERIFY((is_same::type, numeric_list>::value)); -} - -static void test_get() -{ - typedef type_list tl; - typedef numeric_list il; - - VERIFY((is_same::type, dummy_a>::value)); - VERIFY((is_same::type, dummy_a>::value)); - VERIFY((is_same::type, dummy_b>::value)); - VERIFY((is_same::type, dummy_b>::value)); - VERIFY((is_same::type, dummy_c>::value)); - VERIFY((is_same::type, dummy_c>::value)); - - VERIFY_IS_EQUAL(((int)get<0, il>::value), 4); - VERIFY_IS_EQUAL(((int)get<1, il>::value), 8); - VERIFY_IS_EQUAL(((int)get<2, il>::value), 15); - VERIFY_IS_EQUAL(((int)get<3, il>::value), 16); - VERIFY_IS_EQUAL(((int)get<4, il>::value), 23); - VERIFY_IS_EQUAL(((int)get<5, il>::value), 42); -} - -static void test_id_helper(dummy_a a, dummy_a b, dummy_a c) -{ - (void)a; - (void)b; - (void)c; -} - -template -static void test_id_numeric() -{ - test_id_helper(typename id_numeric::type()...); -} - -template -static void test_id_type() -{ - test_id_helper(typename id_type::type()...); -} - -static void test_id() -{ - // don't call VERIFY here, just assume it works if it compiles - // (otherwise it will complain that it can't find the function) - test_id_numeric<1, 4, 6>(); - test_id_type(); -} - -static void test_is_same_gf() -{ - VERIFY((!is_same_gf::value)); - VERIFY((!!is_same_gf::value)); - VERIFY_IS_EQUAL((!!is_same_gf::global_flags), false); - VERIFY_IS_EQUAL((!!is_same_gf::global_flags), false); -} - -static void test_apply_op() -{ - typedef type_list tl; - VERIFY((!!is_same::type, type_list>::value)); - VERIFY((!!is_same::type, type_list>::value)); -} - -static void test_contained_in_list() -{ - typedef type_list tl; - - VERIFY((!!contained_in_list::value)); - VERIFY((!!contained_in_list::value)); - VERIFY((!!contained_in_list::value)); - VERIFY((!contained_in_list::value)); - VERIFY((!contained_in_list::value)); - - VERIFY((!!contained_in_list_gf::value)); - VERIFY((!!contained_in_list_gf::value)); - VERIFY((!!contained_in_list_gf::value)); - VERIFY((!contained_in_list_gf::value)); - VERIFY((!contained_in_list_gf::value)); - - VERIFY_IS_EQUAL(((int)contained_in_list_gf::global_flags), 1); - VERIFY_IS_EQUAL(((int)contained_in_list_gf::global_flags), 2); - VERIFY_IS_EQUAL(((int)contained_in_list_gf::global_flags), 4); - VERIFY_IS_EQUAL(((int)contained_in_list_gf::global_flags), 0); - VERIFY_IS_EQUAL(((int)contained_in_list_gf::global_flags), 0); -} - -static void test_arg_reductions() -{ - VERIFY_IS_EQUAL(arg_sum(1,2,3,4), 10); - VERIFY_IS_EQUAL(arg_prod(1,2,3,4), 24); - VERIFY_IS_APPROX(arg_sum(0.5, 2, 5), 7.5); - VERIFY_IS_APPROX(arg_prod(0.5, 2, 5), 5.0); -} - -static void test_array_reverse_and_reduce() -{ - array a{{4, 8, 15, 16, 23, 42}}; - array b{{42, 23, 16, 15, 8, 4}}; - - // there is no operator<< for std::array, so VERIFY_IS_EQUAL will - // not compile - VERIFY((array_reverse(a) == b)); - VERIFY((array_reverse(b) == a)); - VERIFY_IS_EQUAL((array_sum(a)), 108); - VERIFY_IS_EQUAL((array_sum(b)), 108); - VERIFY_IS_EQUAL((array_prod(a)), 7418880); - VERIFY_IS_EQUAL((array_prod(b)), 7418880); -} - -static void test_array_zip_and_apply() -{ - array a{{4, 8, 15, 16, 23, 42}}; - array b{{0, 1, 2, 3, 4, 5}}; - array c{{4, 9, 17, 19, 27, 47}}; - array d{{0, 8, 30, 48, 92, 210}}; - array e{{0, 2, 4, 6, 8, 10}}; - - VERIFY((array_zip(a, b) == c)); - VERIFY((array_zip(a, b) == d)); - VERIFY((array_apply(b) == e)); - VERIFY_IS_EQUAL((array_apply_and_reduce(a)), 216); - VERIFY_IS_EQUAL((array_apply_and_reduce(b)), 30); - VERIFY_IS_EQUAL((array_zip_and_reduce(a, b)), 14755932); - VERIFY_IS_EQUAL((array_zip_and_reduce(a, b)), 388); -} - -static void test_array_misc() -{ - array a3{{1, 1, 1}}; - array a6{{2, 2, 2, 2, 2, 2}}; - VERIFY((repeat<3, int>(1) == a3)); - VERIFY((repeat<6, int>(2) == a6)); - - int data[5] = { 0, 1, 2, 3, 4 }; - VERIFY_IS_EQUAL((instantiate_by_c_array(data).c), 0); - VERIFY_IS_EQUAL((instantiate_by_c_array(data).c), 1); - VERIFY_IS_EQUAL((instantiate_by_c_array(data).c), 2); - VERIFY_IS_EQUAL((instantiate_by_c_array(data).c), 3); - VERIFY_IS_EQUAL((instantiate_by_c_array(data).c), 4); - VERIFY_IS_EQUAL((instantiate_by_c_array(data).c), 5); -} - -EIGEN_DECLARE_TEST(cxx11_meta) -{ - CALL_SUBTEST(test_gen_numeric_list()); - CALL_SUBTEST(test_concat()); - CALL_SUBTEST(test_slice()); - CALL_SUBTEST(test_get()); - CALL_SUBTEST(test_id()); - CALL_SUBTEST(test_is_same_gf()); - CALL_SUBTEST(test_apply_op()); - CALL_SUBTEST(test_contained_in_list()); - CALL_SUBTEST(test_arg_reductions()); - CALL_SUBTEST(test_array_reverse_and_reduce()); - CALL_SUBTEST(test_array_zip_and_apply()); - CALL_SUBTEST(test_array_misc()); -} diff --git a/unsupported/test/cxx11_tensor_thread_local.cpp b/unsupported/test/cxx11_tensor_thread_local.cpp index 7e866f6d1..ec9d9ca4e 100644 --- a/unsupported/test/cxx11_tensor_thread_local.cpp +++ b/unsupported/test/cxx11_tensor_thread_local.cpp @@ -11,7 +11,7 @@ #include #include "main.h" -#include +#include struct Counter { Counter() = default;