octave-maintainers
[Top][All Lists]
Advanced

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

Re: convn with real and complex data


From: Søren Hauberg
Subject: Re: convn with real and complex data
Date: Fri, 28 Mar 2008 09:56:25 +0100

fre, 28 03 2008 kl. 00:44 -0400, skrev John W. Eaton:
> 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).
Ahh, that's a nice feature.

> 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.
Seems to me like a lot of extra code to avoid the extra template
parameter. But if you prefer it that way, then I won't object :-)

Søren



reply via email to

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