octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

convn with real and complex data


From: John W. Eaton
Subject: convn with real and complex data
Date: Fri, 28 Mar 2008 00:44:10 -0400

On 27-Mar-2008, Søren Hauberg wrote:

|   It seems that 'convn' should also support when one input is real and
| the other is complex (which makes sense). The attached ChangeSet
| implements this.

I applied this patch but made a few changes.

First, I eliminated the ST type from the list of template parameters
by using

  typename MTout::element_type sum = 0;

(element_type is a typedef in the Array<T> class).

Next I defined a traits class and specializations of it so that the
MTout type can be computed from the MTa and MTb types:

  template <class T1, class T2>
  class
  octave_convn_traits
  {
  public:
    // The return type for a T1 by T2 convn operation.
    typedef T1 TR;
  };

  #define OCTAVE_CONVN_TRAIT(T1, T2, T3) \
    template<> \
    class octave_convn_traits <T1, T2> \
    { \
    public: \
      typedef T3 TR; \
    }

  OCTAVE_CONVN_TRAIT (NDArray, NDArray, NDArray);
  OCTAVE_CONVN_TRAIT (ComplexNDArray, NDArray, ComplexNDArray);
  OCTAVE_CONVN_TRAIT (NDArray, ComplexNDArray, ComplexNDArray);
  OCTAVE_CONVN_TRAIT (ComplexNDArray, ComplexNDArray, ComplexNDArray);

With this, the declaration of MTout can be written like this:

  typedef typename octave_convn_traits<MTa, MTb>::TR MTout;

  MTout out (out_size);

inside the convn function, so MTout no longer needs to be a template
parameter.

Finally, I also modified the if/else if structure to be

      if (args(0).is_real_type ())
        {
          if (args(1).is_real_type ())
            ...
          else if (args(1).is_complex_type ())
            ...
          else
            error
        }
      else if (args(0).is_complex_type ())
        {
          if (args(1).is_real_type ())
            ...
          else if (args(1).is_complex_type ())
            ...
          else
            error
        }
      else
        error

as I think that makes it easier to see what is happening.

jwe



reply via email to

[Prev in Thread] Current Thread [Next in Thread]