numfixarray.h

Go to the documentation of this file.
00001 #ifndef __numfixarray_h
00002 #define __numfixarray_h
00003 
00004 #include  "fixarray.h"
00005 #include  "gascoignemath.h"
00006 #include  "nvector.h"
00007 
00008 /*-------------------------------------------------*/
00009 
00010 namespace Gascoigne
00011 {
00012 template<int N, class T>
00013 class numfixarray  : public fixarray<N,T>
00014 {
00015     typedef typename fixarray<N,T>::iterator         nvp;
00016     typedef typename fixarray<N,T>::const_iterator   cnvp;
00017 
00018   public:
00019     ~numfixarray()    {}
00020     numfixarray()                    : fixarray<N,T>(0.)    {}
00021 /*   numfixarray(size_t n)               : fixarray<N,T>(n)   {} */
00022     numfixarray(const T& d)   : fixarray<N,T>(d) {}
00023     numfixarray(const numfixarray<N,T>& v) : fixarray<N,T>(v)   {}
00024 
00025     double operator*(const numfixarray& v) const;
00026     double operator*(const nvector<T>& v) const;
00027     numfixarray<N,T>&   operator=(const T&);
00028     numfixarray<N,T>&   operator=(const numfixarray&);
00029     numfixarray<N,T>&   operator*=(const numfixarray&);
00030     numfixarray<N,T>&   operator*=(double d);
00031     numfixarray<N,T>&   operator/=(double d);
00032     numfixarray<N,T>&   operator+=(double d) { add(d); return *this; }
00033     numfixarray<N,T>&   operator+=(const numfixarray& v) { add(1.,v); return *this; }
00034     numfixarray<N,T>&   operator-=(const numfixarray& v) { add(-1.,v); return *this; }
00035     numfixarray<N,T>    operator-(numfixarray v1) const
00036       { v1.add(-1.,*this);
00037         v1*=(-1);
00038         return v1;
00039       }
00040     
00041     int     n    () const { return fixarray<N,T>::size(); }
00042     void    zero ();
00043     void    equ  (const T&);
00044     void    equ  (double, const numfixarray&);
00045     void    equ  (double, const numfixarray&, double, const numfixarray&);
00046     void    equ  (double, const numfixarray&, double, const numfixarray&, 
00047                   double, const numfixarray&);
00048     void    equ  (double, const numfixarray&, double, const numfixarray&, 
00049                   double, const numfixarray&, double, const numfixarray&);
00050     void    equ  (double, const numfixarray&, double, const numfixarray&, 
00051                   double, const numfixarray&, double, const numfixarray&,
00052                   double, const numfixarray&, double, const numfixarray&);
00053     void    sequ (double, double, const numfixarray&);
00054     void    add  (double);
00055     void    add  (T, const numfixarray&);
00056     void    add  (double, const numfixarray&, double, const numfixarray&);
00057     void    add  (double, const numfixarray&, double, const numfixarray&, 
00058                   double, const numfixarray&);
00059     void    sadd (double, double, const numfixarray&);
00060     double  max  ()     const;
00061     double  norm ()     const;
00062     double  norm_l8 ()     const;
00063     double  norm_l1()     const;
00064     double  norm_l2()     const {return norm();}
00065 
00066     void normalise()
00067       {
00068         T d=0.;
00069         for(int i=0;i<n();i++)
00070           {
00071             d += (*this)[i]*(*this)[i];
00072           }
00073         d = 1./sqrt(d);
00074         for(int i=0;i<n();i++)
00075           {
00076             (*this)[i] *= d;
00077           }
00078       }
00079 
00080 };
00081 
00082 
00083 /**************************************************/
00084 
00085 template<int N,class T>
00086 inline double numfixarray<N,T>::norm_l8() const
00087 {
00088   cnvp first  = fixarray<N,T>::begin();
00089   cnvp last   = fixarray<N,T>::end();
00090 
00091   double d=0.;
00092   while( first != last)
00093     {
00094       d = Gascoigne::max(d,fabs(*first));
00095       first++;
00096     }
00097   return d;
00098 }
00099 
00100 /**************************************************/
00101 
00102 template<int N,class T>
00103 inline double numfixarray<N,T>::norm() const
00104 {
00105   cnvp first  = fixarray<N,T>::begin();
00106   cnvp last   = fixarray<N,T>::end();
00107 
00108   double n=0.;
00109   while( first != last)
00110     {
00111       n += ((*first)) * ((*first));
00112       first++;
00113     }
00114   return sqrt(n);
00115 }
00116 
00117 /**************************************************/
00118 
00119 template<int N,class T>
00120 inline double numfixarray<N,T>::norm_l1() const
00121 {
00122   cnvp first  = fixarray<N,T>::begin();
00123   cnvp last   = fixarray<N,T>::end();
00124 
00125   double n=0.;
00126   while( first != last)
00127     {
00128       n += fabs((*first++));
00129     }
00130   return n;
00131 }
00132 
00133 /**************************************************/
00134 
00135 template<int N,class T>
00136 inline numfixarray<N,T>& numfixarray<N,T>::operator=(const T& d)
00137 {
00138   nvp  first  = fixarray<N,T>::begin();
00139   cnvp last   = fixarray<N,T>::end();
00140 
00141   while( first != last)
00142     {
00143       *first++ = d;
00144     }
00145   return *this;
00146 }
00147 
00148 /**************************************************/
00149 
00150 template<int N,class T>
00151 inline numfixarray<N,T>& numfixarray<N,T>::operator=(const numfixarray<N,T>& v)
00152 {
00153   nvp  first  = fixarray<N,T>::begin();
00154   cnvp last   = fixarray<N,T>::end();
00155   cnvp vfirst = v.fixarray<N,T>::begin();
00156 
00157   while( first != last)
00158     {
00159       *first++ = *vfirst++;
00160     }
00161   return *this;
00162 }
00163 
00164 /**************************************************/
00165 
00166 template<int N,class T>
00167 inline numfixarray<N,T>& numfixarray<N,T>::operator*=(const numfixarray<N,T>& d)
00168 {
00169   nvp  first  = fixarray<N,T>::begin();
00170   cnvp last   = fixarray<N,T>::end();
00171   cnvp fd     = d.fixarray<N,T>::begin();
00172 
00173   while(first != last)
00174     {
00175       (*first++) *= (*fd++);
00176     }
00177   return *this;
00178 }
00179 
00180 /**************************************************/
00181 
00182 template<int N,class T>
00183 inline numfixarray<N,T>& numfixarray<N,T>::operator*=(double d)
00184 {
00185   nvp  first  = fixarray<N,T>::begin();
00186   cnvp last   = fixarray<N,T>::end();
00187 
00188   while(first != last)
00189     {
00190       (*first++) *= d;
00191     }
00192   return *this;
00193 }
00194 
00195 /**************************************************/
00196 
00197 template<int N,class T>
00198 inline numfixarray<N,T>& numfixarray<N,T>::operator/=(double d)
00199 {
00200   nvp  first  = fixarray<N,T>::begin();
00201   cnvp last   = fixarray<N,T>::end();
00202 
00203   while(first != last)
00204     {
00205       (*first++) /= d;
00206     }
00207   return *this;
00208 }
00209 
00210 /**************************************************/
00211 
00212 template<int N,class T>
00213 inline void numfixarray<N,T>::zero()
00214 {
00215   nvp  first  = fixarray<N,T>::begin();
00216   cnvp last   = fixarray<N,T>::end();
00217 
00218   while( first != last)
00219     {
00220       *first++ = 0.;
00221     }
00222 }
00223 
00224 /**************************************************/
00225 
00226 template<int N,class T>
00227 inline double numfixarray<N,T>::max() const
00228 {
00229   double d = -1.;
00230   cnvp first  = fixarray<N,T>::begin();
00231   cnvp last   = fixarray<N,T>::end();
00232 
00233   while( first != last)
00234     {
00235       d = MAX( d, fabs((*first)));
00236       first++;
00237     }
00238   return d;
00239 }
00240 
00241 /**************************************************/
00242 
00243 template<int N,class T>
00244 inline double numfixarray<N,T>::operator* (const numfixarray<N,T>& v) const
00245 {
00246   cnvp first  = fixarray<N,T>::begin();
00247   cnvp last   = fixarray<N,T>::end();
00248   cnvp first2 = v.fixarray<N,T>::begin();
00249 
00250   double d = 0.;
00251   while(first != last)
00252     {
00253       d += (*first++) * (*first2++);
00254     }
00255   return d;
00256 }
00257 
00258 /**************************************************/
00259 
00260 template<int N,class T>
00261 inline double numfixarray<N,T>::operator* (const nvector<T>& v) const
00262 {
00263   cnvp first  = fixarray<N,T>::begin();
00264   cnvp last   = fixarray<N,T>::end();
00265   cnvp first2 = v.fixarray<N,T>::begin();
00266 
00267   double d = 0.;
00268   while(first != last)
00269     {
00270       d += (*first++) * (*first2++);
00271     }
00272   return d;
00273 }
00274 
00275 /**************************************************/
00276 
00277 template<int N,class T>
00278 inline void numfixarray<N,T>::equ (const T& d)
00279 {
00280   nvp  first  = fixarray<N,T>::begin();
00281   cnvp last   = fixarray<N,T>::end();
00282 
00283   while(first != last)
00284     {
00285       (*first++) = d;
00286     }
00287 }
00288 
00289 /**************************************************/
00290 
00291 template<int N,class T>
00292 inline void numfixarray<N,T>::equ (double d, const numfixarray<N,T>& v)
00293 {
00294   nvp  first  = fixarray<N,T>::begin();
00295   cnvp last   = fixarray<N,T>::end();
00296   cnvp first2 = v.fixarray<N,T>::begin();
00297 
00298   while(first != last)
00299     {
00300       (*first++) = d*(*first2++);
00301     }
00302 }
00303 
00304 /**************************************************/
00305 
00306 template<int N,class T>
00307 inline void numfixarray<N,T>::equ (double d, const numfixarray<N,T>& v, 
00308                                    double e, const numfixarray<N,T>& w)
00309 {
00310   nvp  first  = fixarray<N,T>::begin();
00311   cnvp last   = fixarray<N,T>::end();
00312   cnvp first2 = v.fixarray<N,T>::begin();
00313   cnvp first3 = w.fixarray<N,T>::begin();
00314 
00315   while(first != last)
00316     {
00317       (*first++) = d*(*first2++) + e*(*first3++);
00318     }
00319 }
00320 
00321 /**************************************************/
00322 
00323 template<int N,class T>
00324 inline void numfixarray<N,T>::equ (double d, const numfixarray<N,T>& v, 
00325                                    double e, const numfixarray<N,T>& w,
00326                                    double f, const numfixarray<N,T>& x)
00327 {
00328   nvp  first  = fixarray<N,T>::begin();
00329   cnvp last   = fixarray<N,T>::end();
00330   cnvp first2 = v.fixarray<N,T>::begin();
00331   cnvp first3 = w.fixarray<N,T>::begin();
00332   cnvp first4 = x.fixarray<N,T>::begin();
00333 
00334   while(first != last)
00335     {
00336       (*first++) = d*(*first2++) + e*(*first3++) + f*(*first4++);
00337     }
00338 }
00339 
00340 /**************************************************/
00341 
00342 template<int N,class T>
00343 inline void numfixarray<N,T>::equ (double d, const numfixarray<N,T>& v, 
00344                                    double e, const numfixarray<N,T>& w,
00345                                    double f, const numfixarray<N,T>& x,
00346                                    double g, const numfixarray<N,T>& y     )
00347 {
00348   nvp  first  = fixarray<N,T>::begin();
00349   cnvp last   = fixarray<N,T>::end();
00350   cnvp first2 = v.fixarray<N,T>::begin();
00351   cnvp first3 = w.fixarray<N,T>::begin();
00352   cnvp first4 = x.fixarray<N,T>::begin();
00353   cnvp first5 = y.fixarray<N,T>::begin();
00354 
00355   while(first != last)
00356     {
00357       (*first++) = d*(*first2++) + e*(*first3++) + f*(*first4++) + g*(*first5++);
00358     }
00359 }
00360 
00361 /**************************************************/
00362 
00363 template<int N,class T>
00364 inline void numfixarray<N,T>::equ (double d, const numfixarray<N,T>& v, 
00365                                    double e, const numfixarray<N,T>& w,
00366                                    double f, const numfixarray<N,T>& x,
00367                                    double g, const numfixarray<N,T>& y,
00368                                    double h, const numfixarray<N,T>& z,
00369                                    double i, const numfixarray<N,T>& zz)
00370 {
00371   nvp  first  = fixarray<N,T>::begin();
00372   cnvp last   = fixarray<N,T>::end();
00373   cnvp first2 = v.fixarray<N,T>::begin();
00374   cnvp first3 = w.fixarray<N,T>::begin();
00375   cnvp first4 = x.fixarray<N,T>::begin();
00376   cnvp first5 = y.fixarray<N,T>::begin();
00377   cnvp first6 = z.fixarray<N,T>::begin();
00378   cnvp first7 = zz.fixarray<N,T>::begin();
00379 
00380   while(first != last)
00381     {
00382       (*first++) = d*(*first2++) + e*(*first3++) + f*(*first4++) + g*(*first5++) 
00383                    + h*(*first6++) + i*(*first7++);
00384     }
00385 }
00386 
00387 /**************************************************/
00388 
00389 template<int N,class T>
00390 inline void numfixarray<N,T>::sequ (double s, double d, const numfixarray<N,T>& v)
00391 {
00392   equ(s,*this);
00393   add(d,v);
00394   return;
00395 
00396   nvp  first  = fixarray<N,T>::begin();
00397   cnvp last   = fixarray<N,T>::end();
00398   cnvp first2 = v.fixarray<N,T>::begin();
00399 
00400   while(first != last)
00401     {
00402       (*first) = s*(*first) + d*(*first2++);
00403       first++;
00404     }
00405 }
00406 
00407 /**************************************************/
00408 
00409 template<int N,class T>
00410 inline void numfixarray<N,T>::add (double d)
00411 {
00412   nvp  first  = fixarray<N,T>::begin();
00413   cnvp last   = fixarray<N,T>::end();
00414 
00415   while(first != last)
00416     {
00417       (*first++) += d;
00418     }
00419 }
00420 
00421 /**************************************************/
00422 
00423 template<int N,class T>
00424 inline void numfixarray<N,T>::add (T d, const numfixarray<N,T>& v)
00425 {
00426   nvp  first  = fixarray<N,T>::begin();
00427   cnvp last   = fixarray<N,T>::end();
00428   cnvp first2 = v.fixarray<N,T>::begin();
00429 
00430   while(first != last)
00431     {
00432       (*first++) += d*(*first2++);
00433     }
00434 }
00435 
00436 /**************************************************/
00437 
00438 template<int N,class T>
00439 inline void numfixarray<N,T>::add (double d, const numfixarray<N,T>& v,
00440                                    double e, const numfixarray<N,T>& w)
00441 {
00442   nvp  first  = fixarray<N,T>::begin();
00443   cnvp last   = fixarray<N,T>::end();
00444   cnvp first2 = v.fixarray<N,T>::begin();
00445   cnvp first3 = w.fixarray<N,T>::begin();
00446 
00447   while(first != last)
00448     {
00449       (*first++) += d*(*first2++) + e*(*first3++);
00450     }
00451 }
00452 
00453 /**************************************************/
00454 
00455 template<int N,class T>
00456 inline void numfixarray<N,T>::add (double d, const numfixarray<N,T>& v,
00457                                    double e, const numfixarray<N,T>& w,
00458                                    double f, const numfixarray<N,T>& x)
00459 {
00460   nvp  first  = fixarray<N,T>::begin();
00461   cnvp last   = fixarray<N,T>::end();
00462   cnvp first2 = v.fixarray<N,T>::begin();
00463   cnvp first3 = w.fixarray<N,T>::begin();
00464   cnvp first4 = x.fixarray<N,T>::begin();
00465 
00466   while(first != last)
00467     {
00468       (*first++) += d*(*first2++) + e*(*first3++) + f*(*first4++);
00469     }
00470 }
00471 
00472 /**************************************************/
00473 
00474 template<int N,class T>
00475 inline void numfixarray<N,T>::sadd (double a, double d, const numfixarray<N,T>& v)
00476 {
00477   nvp  first  = fixarray<N,T>::begin();
00478   cnvp last   = fixarray<N,T>::end();
00479   cnvp first2 = v.fixarray<N,T>::begin();
00480 
00481   while(first != last)
00482     {
00483       (*first) = a*(*first) + d*(*first2++);
00484       first++;
00485     }
00486 }
00487 }
00488 
00489 #endif
00490 

Generated on Thu Sep 14 10:34:35 2006 for Gascoigne by  doxygen 1.4.7