ublas_interop.hpp 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. typedef typename sparse_vector_element<V>::const_reference ref_type;
  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. typedef boost::multiprecision::number<Backend1, ExpressionTemplates1> number1_t;
  22. typedef boost::multiprecision::number<Backend2, ExpressionTemplates2> number2_t;
  23. typedef typename mpl::if_c<
  24. is_convertible<number1_t, number2_t>::value && !is_convertible<number2_t, number1_t>::value,
  25. number2_t, number1_t
  26. >::type promote_type;
  27. };
  28. template <class Backend1, boost::multiprecision::expression_template_option ExpressionTemplates1, class tag, class Arg1, class Arg2, class Arg3, class Arg4>
  29. struct promote_traits<boost::multiprecision::number<Backend1, ExpressionTemplates1>, boost::multiprecision::detail::expression<tag, Arg1, Arg2, Arg3, Arg4> >
  30. {
  31. typedef boost::multiprecision::number<Backend1, ExpressionTemplates1> number1_t;
  32. typedef boost::multiprecision::detail::expression<tag, Arg1, Arg2, Arg3, Arg4> expression_type;
  33. typedef typename expression_type::result_type number2_t;
  34. typedef typename promote_traits<number1_t, number2_t>::promote_type promote_type;
  35. };
  36. template <class tag, class Arg1, class Arg2, class Arg3, class Arg4, class Backend1, boost::multiprecision::expression_template_option ExpressionTemplates1>
  37. struct promote_traits<boost::multiprecision::detail::expression<tag, Arg1, Arg2, Arg3, Arg4>, boost::multiprecision::number<Backend1, ExpressionTemplates1> >
  38. {
  39. typedef boost::multiprecision::number<Backend1, ExpressionTemplates1> number1_t;
  40. typedef boost::multiprecision::detail::expression<tag, Arg1, Arg2, Arg3, Arg4> expression_type;
  41. typedef typename expression_type::result_type number2_t;
  42. typedef typename promote_traits<number1_t, number2_t>::promote_type promote_type;
  43. };
  44. template <class tag, class Arg1, class Arg2, class Arg3, class Arg4, class tagb, class Arg1b, class Arg2b, class Arg3b, class Arg4b>
  45. struct promote_traits<boost::multiprecision::detail::expression<tag, Arg1, Arg2, Arg3, Arg4>, boost::multiprecision::detail::expression<tagb, Arg1b, Arg2b, Arg3b, Arg4b> >
  46. {
  47. typedef boost::multiprecision::detail::expression<tag, Arg1, Arg2, Arg3, Arg4> expression1_t;
  48. typedef typename expression1_t::result_type number1_t;
  49. typedef boost::multiprecision::detail::expression<tagb, Arg1b, Arg2b, Arg3b, Arg4b> expression2_t;
  50. typedef typename expression2_t::result_type number2_t;
  51. };
  52. }}} // namespace
  53. #endif