[pythran] Re: mixed complex, integral computations

  • From: Pierrick Brunet <pierrick.brunet@xxxxxxxx>
  • To: pythran@xxxxxxxxxxxxx
  • Date: Wed, 08 Oct 2014 20:40:27 +0200

Hi Neal,

Thanks for your support.
I am not sure but it looks like it would enable correct complex64 bhavior which looks to be not supported for now. I just wonder if the check on argument type is requiered in Python as complex number have float (double or simple) attributs and for the other, we want to have the complex type whatever it is no?

Pierrick

On 07/10/2014 20:55, Neal Becker wrote:
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: