ublas_interop.hpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Copyright 2013 John Maddock. Distributed under the Boost
  3. // Software License, Version 1.0. (See accompanying file
  4. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. #ifndef BOOST_MP_UBLAS_HPP
  6. #define BOOST_MP_UBLAS_HPP
  7. namespace boost { namespace numeric { namespace ublas {
  8. template <class V>
  9. class sparse_vector_element;
  10. template <class V, class Backend, multiprecision::expression_template_option ExpressionTemplates>
  11. inline bool operator==(const sparse_vector_element<V>& a, const ::boost::multiprecision::number<Backend, ExpressionTemplates>& b)
  12. {
  13. using ref_type = typename sparse_vector_element<V>::const_reference;
  14. return static_cast<ref_type>(a) == b;
  15. }
  16. template <class X, class Y>
  17. struct promote_traits;
  18. template <class Backend1, boost::multiprecision::expression_template_option ExpressionTemplates1, class Backend2, boost::multiprecision::expression_template_option ExpressionTemplates2>
  19. struct promote_traits<boost::multiprecision::number<Backend1, ExpressionTemplates1>, boost::multiprecision::number<Backend2, ExpressionTemplates2> >
  20. {
  21. using number1_t = boost::multiprecision::number<Backend1, ExpressionTemplates1>;
  22. using number2_t = boost::multiprecision::number<Backend2, ExpressionTemplates2>;
  23. using promote_type = typename std::conditional<
  24. std::is_convertible<number1_t, number2_t>::value && !std::is_convertible<number2_t, number1_t>::value,
  25. number2_t, number1_t>::type;
  26. };
  27. template <class Backend1, boost::multiprecision::expression_template_option ExpressionTemplates1, class Arithmetic>
  28. struct promote_traits<boost::multiprecision::number<Backend1, ExpressionTemplates1>, Arithmetic>
  29. {
  30. using promote_type = boost::multiprecision::number<Backend1, ExpressionTemplates1>;
  31. };
  32. template <class Arithmetic, class Backend1, boost::multiprecision::expression_template_option ExpressionTemplates1>
  33. struct promote_traits<Arithmetic, boost::multiprecision::number<Backend1, ExpressionTemplates1> >
  34. {
  35. using promote_type = boost::multiprecision::number<Backend1, ExpressionTemplates1>;
  36. };
  37. template <class Backend1, boost::multiprecision::expression_template_option ExpressionTemplates1, class tag, class Arg1, class Arg2, class Arg3, class Arg4>
  38. struct promote_traits<boost::multiprecision::number<Backend1, ExpressionTemplates1>, boost::multiprecision::detail::expression<tag, Arg1, Arg2, Arg3, Arg4> >
  39. {
  40. using number1_t = boost::multiprecision::number<Backend1, ExpressionTemplates1> ;
  41. using expression_type = boost::multiprecision::detail::expression<tag, Arg1, Arg2, Arg3, Arg4>;
  42. using number2_t = typename expression_type::result_type ;
  43. using promote_type = typename promote_traits<number1_t, number2_t>::promote_type ;
  44. };
  45. template <class tag, class Arg1, class Arg2, class Arg3, class Arg4, class Backend1, boost::multiprecision::expression_template_option ExpressionTemplates1>
  46. struct promote_traits<boost::multiprecision::detail::expression<tag, Arg1, Arg2, Arg3, Arg4>, boost::multiprecision::number<Backend1, ExpressionTemplates1> >
  47. {
  48. using number1_t = boost::multiprecision::number<Backend1, ExpressionTemplates1> ;
  49. using expression_type = boost::multiprecision::detail::expression<tag, Arg1, Arg2, Arg3, Arg4>;
  50. using number2_t = typename expression_type::result_type ;
  51. using promote_type = typename promote_traits<number1_t, number2_t>::promote_type ;
  52. };
  53. template <class tag, class Arg1, class Arg2, class Arg3, class Arg4, class tagb, class Arg1b, class Arg2b, class Arg3b, class Arg4b>
  54. struct promote_traits<boost::multiprecision::detail::expression<tag, Arg1, Arg2, Arg3, Arg4>, boost::multiprecision::detail::expression<tagb, Arg1b, Arg2b, Arg3b, Arg4b> >
  55. {
  56. using expression1_t = boost::multiprecision::detail::expression<tag, Arg1, Arg2, Arg3, Arg4> ;
  57. using number1_t = typename expression1_t::result_type ;
  58. using expression2_t = boost::multiprecision::detail::expression<tagb, Arg1b, Arg2b, Arg3b, Arg4b>;
  59. using number2_t = typename expression2_t::result_type ;
  60. };
  61. }}} // namespace boost::numeric::ublas
  62. #endif