![]() |
Blitz Devel : |
From: Andre Krause (post_at_[hidden])
Date: 2005-04-05 10:21:54
Hey - great stuff ! Hope this gets included in blitz++ !!
Here is a link about the "SFINAE principle" http://www.mpi-sb.mpg.de/~kettner/courses/lib_design_03/notes/meta.html#Constraining
> -----Original Message-----
> From: blitz-dev-bounces_at_[hidden]
> [mailto:blitz-dev-bounces_at_[hidden]] On Behalf Of yannick.le-goc
> Sent: Dienstag, 5. April 2005 14:46
> To: blitz-dev
> Subject: [Blitz-dev] TinyMatrix product
>
> hi,
>
> I just began to look at the Blitz++ library which is very
> well programmed! I think the API can be simplified, for
> example for the TinyMatrix products, we can use SFINAE
> technique to provide a more intuitive syntax:
>
> #include <blitz/tinymat.h>
> #include <blitz/vector.h>
> #include <iostream>
>
> using namespace std;
>
> // ProductResult
> ///////////////////////////////////////////////////////////////
>
> template<class A, class B> struct ProductResult;
>
> // TinyMatrix - TinyVector ProductResult
> ///////////////////////////////////////
>
> template<class MT, class VT, int Mm, int Mn> struct
> ProductResult<blitz::TinyMatrix<MT, Mm, Mn>,
> blitz::TinyVector<VT, Mn> > {
> typedef blitz::TinyVector<MT, Mm> type; };
>
> // TinyMatrix - TinyMatrix ProductResult
> ///////////////////////////////////////
>
> template<class MAT, class MBT, int MAm, int MAn, int MBn>
> struct ProductResult<blitz::TinyMatrix<MAT, MAm, MAn>,
> blitz::TinyMatrix<MBT, MAn, MBn> > {
> typedef
> blitz::_bz_tinyMatExpr<blitz::_bz_tinyMatrixMatrixProduct<MAT,
> MBT, MAm, MAn, MBn, MAn, 1, MBn, 1> > type; };
>
> // operator* for blitz types using SFINAE technique
> ////////////////////////////
>
> template<class A, class B>
> inline typename ProductResult<A, B>::type operator* (const A
> &a, const B &b) {
> return product(a, b);
> }
>
> using namespace blitz;
>
> int main()
> {
> // TinyMatrix
>
> TinyMatrix<int, 3, 3> C;
>
> C = 1, 0, 2,
> 2, 4, 1,
> 0, 2, 1;
>
> TinyVector<int, 3> x(1, -3, 2);
> TinyVector<int, 3> y(-2, 1, 3);
>
> TinyMatrix<int, 3, 3> M;
>
> M = product(C, C);
> // is now equivalent to
> M = C*C;
>
> TinyVector<double,3> z;
> z = product(C, x);
> // is now equivalent to
> z = C*x;
>
> return 1;
> }
>
> The two lines are equivalent since the compiler uses inline
> keyword. Furthermore thanks to template partial
> specialization, type coherence is checked!
>
> Accédez au courrier électronique de La Poste : www.laposte.net ;
> 3615 LAPOSTENET (0,34€/mn) ; tél : 08 92 68 13 50 (0,34€/mn)
>
>
>
>
> _______________________________________________
> Blitz-dev mailing list
> Blitz-dev_at_[hidden]
> http://www.oonumerics.org/mailman/listinfo.cgi/blitz-dev
>