realroot_doc 0.1.1
/Users/mourrain/Devel/mmx/realroot/include/realroot/tensor_convert.hpp
Go to the documentation of this file.
00001 #ifndef realroot_MPOLDSE_MODULE_H
00002 #define realroot_MPOLDSE_MODULE_H
00003 //====================================================================
00004 #include <realroot/tensor_eenv.hpp> 
00005 #include <realroot/tensor_vctops.hpp>
00006 #include <realroot/binomials.hpp>
00007 //====================================================================
00008 namespace mmx {
00009 
00010 namespace tensor {
00011 
00012   typedef tensor::eenv eenv;
00013   
00014   template<class MPLBASE, class C >
00015   void scadd (MPLBASE & mpl, const C & c)
00016   {
00017     vct::scadd (mpl.begin (), c, mpl.esz (), 1);
00018   };
00019   
00020   template<class MPLBASE, class MPLBASE1, class C >
00021   void scadd ( MPLBASE& r, const MPLBASE1 &a, const C & c)
00022   {
00023     if (r.env != a.env) 
00024       scadd (r = a, c);
00025     else 
00026       vct::scadd (r.begin (), a.begin (), c, r.esz ());
00027   };
00028   
00029   template<class MPLBASE0,class MPLBASE1>
00030     void conv( MPLBASE0 &r, const MPLBASE1 &a );
00031 
00032   template<class MPLBASE0, class MPLBASE1, class MPLBASE2 >
00033   void conv( MPLBASE0& r, const MPLBASE1& a, const MPLBASE2& b )
00034   {
00035     if (&a == &r) { conv (r, b); return; };
00036     if (&b == &r) { conv (r, a); return; };
00037     clear (r, eenv::mul (a.env, b.env));
00038 
00039     unsigned *oa = new unsigned[a.esz () + b.esz ()];
00040     unsigned *ob = oa + a.esz ();
00041 
00042     eenv::oaddress (r.env, oa, a.env);
00043     eenv::oaddress (r.env, ob, b.env);
00044     
00045     typedef typename MPLBASE0::value_type rreal;
00046     typedef typename MPLBASE1::value_type areal;
00047     typedef typename MPLBASE2::value_type breal;
00048     
00049     unsigned *ea;
00050     unsigned *eb;
00051     rreal * pr = r.begin();
00052     const areal * pa;
00053     const breal * pb;
00054     
00055     for (ea = oa, pa = a.begin (); ea != oa + a.esz (); ea++, pa++)
00056       for (eb = ob, pb = b.begin (); eb != ob + b.esz ();
00057            pr[*ea + *eb++] += (*pa) * (*pb++) ) ;
00058     delete[]oa;
00059   };
00060   
00061   template<class MPLBASE0,class MPLBASE1> void 
00062   conv( MPLBASE0 &r, const MPLBASE1 &a ) { 
00063     MPLBASE0 tmp;
00064     r.swap (tmp);
00065     conv (r, tmp, a);
00066   };
00067   
00068  
00072   template<class UPOL,class MPOL>
00073   UPOL convert(const MPOL & p, unsigned v)
00074   {
00075     unsigned N = degree(p,v)+1;
00076     UPOL r(N, AsSize());
00077     for(unsigned i =0; i<N;i++) { slice(r[i].rep(),p.rep(),v,i); }
00078     return r;
00079   }
00080 
00081 } // namespace dense
00082 //======================================================================
00083 } //namespace mmx
00084 #endif