[pythran] mixed complex, integral computations

  • From: Neal Becker <ndbecker2@xxxxxxxxx>
  • To: pythran@xxxxxxxxxxxxx
  • Date: Tue, 7 Oct 2014 14:55:54 -0400

Glancing at pythran/pythonic/types/complex.hpp, I noticed some code for
mixing
integral and complex in math.

I am reminded I contributed the following to boost/numeric/ublas some time
ago, perhaps you might find it useful:

namespace boost { namespace numeric { namespace ublas {

      template<typename R, typename I>
      typename boost::enable_if<
        mpl::and_<
          boost::is_float<R>,
          boost::is_integral<I>
          >,
        std::complex<R> >::type inline operator+ (I in1, std::complex<R>
const& in2 ) {
        return R (in1) + in2;
      }

      template<typename R, typename I>
      typename boost::enable_if<
        mpl::and_<
          boost::is_float<R>,
          boost::is_integral<I>
          >,
        std::complex<R> >::type inline operator+ (std::complex<R> const&
in1, I in2) {
        return in1 + R (in2);
      }

      template<typename R, typename I>
      typename boost::enable_if<
        mpl::and_<
          boost::is_float<R>,
          boost::is_integral<I>
          >,
        std::complex<R> >::type inline operator- (I in1, std::complex<R>
const& in2) {
        return R (in1) - in2;
      }

      template<typename R, typename I>
      typename boost::enable_if<
        mpl::and_<
          boost::is_float<R>,
          boost::is_integral<I>
          >,
        std::complex<R> >::type inline operator- (std::complex<R> const&
in1, I in2) {
        return in1 - R (in2);
      }

      template<typename R, typename I>
      typename boost::enable_if<
        mpl::and_<
          boost::is_float<R>,
          boost::is_integral<I>
          >,
        std::complex<R> >::type inline operator* (I in1, std::complex<R>
const& in2) {
        return R (in1) * in2;
      }

      template<typename R, typename I>
      typename boost::enable_if<
        mpl::and_<
          boost::is_float<R>,
          boost::is_integral<I>
          >,
        std::complex<R> >::type inline operator* (std::complex<R> const&
in1, I in2) {
        return in1 * R(in2);
      }

      template<typename R, typename I>
      typename boost::enable_if<
        mpl::and_<
          boost::is_float<R>,
          boost::is_integral<I>
          >,
        std::complex<R> >::type inline operator/ (I in1, std::complex<R>
const& in2) {
        return R(in1) / in2;
      }

      template<typename R, typename I>
      typename boost::enable_if<
        mpl::and_<
          boost::is_float<R>,
          boost::is_integral<I>
          >,
        std::complex<R> >::type inline operator/ (std::complex<R> const&
in1, I in2) {
        return in1 / R (in2);
      }


-- 
*Those who don't understand recursion are doomed to repeat it*

Other related posts: