/////////////////////////////////////////////////////////////////////////////// // Copyright 2018 John Maddock. Distributed under the Boost // Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #ifndef BOOST_MP_EIGEN_HPP #define BOOST_MP_EIGEN_HPP #include #include // // Generic Eigen support code: // namespace Eigen { template struct NumTraits > { using self_type = boost::multiprecision::number ; using Real = typename boost::multiprecision::scalar_result_from_possible_complex::type; using NonInteger = self_type ; // Not correct but we can't do much better?? using Literal = double ; using Nested = self_type ; enum { IsComplex = boost::multiprecision::number_category::value == boost::multiprecision::number_kind_complex, IsInteger = boost::multiprecision::number_category::value == boost::multiprecision::number_kind_integer, ReadCost = 1, AddCost = 4, MulCost = 8, IsSigned = std::numeric_limits::is_specialized ? std::numeric_limits::is_signed : true, RequireInitialization = 1, }; static Real epsilon() { return std::numeric_limits::epsilon(); } static Real dummy_precision() { return 1000 * epsilon(); } static Real highest() { return (std::numeric_limits::max)(); } static Real lowest() { return (std::numeric_limits::min)(); } static int digits10_imp(const std::integral_constant&) { return std::numeric_limits::digits10; } template static int digits10_imp(const std::integral_constant&) { return Real::thread_default_precision(); } static int digits10() { return digits10_imp(std::integral_constant::digits10 && (std::numeric_limits::digits10 != INT_MAX) ? true : false > ()); } }; template struct NumTraits > : public NumTraits::result_type> { }; #define BOOST_MP_EIGEN_SCALAR_TRAITS_DECL(A) \ template \ struct ScalarBinaryOpTraits, A, BinaryOp> \ { \ /*static_assert(boost::multiprecision::is_compatible_arithmetic_type >::value, "Interoperability with this arithmetic type is not supported.");*/ \ using ReturnType = boost::multiprecision::number; \ }; \ template \ struct ScalarBinaryOpTraits, BinaryOp> \ { \ /*static_assert(boost::multiprecision::is_compatible_arithmetic_type >::value, "Interoperability with this arithmetic type is not supported.");*/ \ using ReturnType = boost::multiprecision::number; \ }; BOOST_MP_EIGEN_SCALAR_TRAITS_DECL(float) BOOST_MP_EIGEN_SCALAR_TRAITS_DECL(double) BOOST_MP_EIGEN_SCALAR_TRAITS_DECL(long double) BOOST_MP_EIGEN_SCALAR_TRAITS_DECL(char) BOOST_MP_EIGEN_SCALAR_TRAITS_DECL(unsigned char) BOOST_MP_EIGEN_SCALAR_TRAITS_DECL(signed char) BOOST_MP_EIGEN_SCALAR_TRAITS_DECL(short) BOOST_MP_EIGEN_SCALAR_TRAITS_DECL(unsigned short) BOOST_MP_EIGEN_SCALAR_TRAITS_DECL(int) BOOST_MP_EIGEN_SCALAR_TRAITS_DECL(unsigned int) BOOST_MP_EIGEN_SCALAR_TRAITS_DECL(long) BOOST_MP_EIGEN_SCALAR_TRAITS_DECL(unsigned long) #if 0 template struct ScalarBinaryOpTraits, boost::multiprecision::number, BinaryOp> { static_assert( boost::multiprecision::is_compatible_arithmetic_type, boost::multiprecision::number >::value || boost::multiprecision::is_compatible_arithmetic_type, boost::multiprecision::number >::value, "Interoperability with this arithmetic type is not supported."); using ReturnType = typename std::conditional, boost::multiprecision::number >::value, boost::multiprecision::number, boost::multiprecision::number >::type; }; template struct ScalarBinaryOpTraits, boost::multiprecision::et_on>, boost::multiprecision::mpfr_float, BinaryOp> { using ReturnType = boost::multiprecision::number, boost::multiprecision::et_on>; }; template struct ScalarBinaryOpTraits { using ReturnType = boost::multiprecision::number, boost::multiprecision::et_on>; }; template struct ScalarBinaryOpTraits, boost::multiprecision::number, BinaryOp> { using ReturnType = boost::multiprecision::number; }; #endif template struct ScalarBinaryOpTraits, boost::multiprecision::detail::expression, BinaryOp> { static_assert(std::is_convertible::result_type, boost::multiprecision::number >::value, "Interoperability with this arithmetic type is not supported."); using ReturnType = boost::multiprecision::number; }; template struct ScalarBinaryOpTraits, boost::multiprecision::number, BinaryOp> { static_assert(std::is_convertible::result_type, boost::multiprecision::number >::value, "Interoperability with this arithmetic type is not supported."); using ReturnType = boost::multiprecision::number; }; namespace internal { template struct conj_retval; template struct conj_impl; template struct conj_retval > { using type = typename boost::multiprecision::detail::expression::result_type; }; template struct conj_impl, true> { EIGEN_DEVICE_FUNC static inline typename boost::multiprecision::detail::expression::result_type run(const typename boost::multiprecision::detail::expression& x) { return conj(x); } }; } // namespace internal } // namespace Eigen #endif