Home | Doxygen Documentation | Tutorials | Developer Tools (restricted)

toolbox/arrayOp.hh
Go to the documentation of this file.
00001 
00005 #ifndef ArrayOp_hh
00006 #define ArrayOp_hh
00007 
00008 #include <stdarg.h>
00009 #include "toolbox/array.hh"
00010 
00011 // debugging
00012 #define ArrayProduct_D 0
00013 
00014 namespace std {
00015 
00016   // *************************************************************** product **
00017 
00019   template<typename F>
00020   F product(const concepts::Array<F>& a) {
00021     const F* d = (const F*)a;
00022     F val = F(1);
00023     for(uint i = a.size(); i--; ) val *= *d++;
00024     return val;
00025   }
00026 
00028   template<typename F>
00029   F product(const concepts::Array<F>& a, uint j) {
00030     const F* d = (const F*)a;
00031     F val = F(1);
00032     for(uint i = 0; i < a.size(); ++i, ++d)
00033       if (i != j) val *= *d;
00034     return val;
00035   }
00036 
00040   template<typename F>
00041   F product(const concepts::Array<F>& a, uint j, uint k) {
00042     const F* d = (const F*)a;
00043     F val = F(1);
00044     for(uint i = 0; i < a.size(); ++i, ++d) 
00045       if (i != j && i != k) val *= *d;
00046     return val;
00047   }
00048 
00049   // ******************************************************************* abs **
00050 
00052   template<typename F>
00053   concepts::Array<F> abs(const concepts::Array<F>& a) {
00054     concepts::Array<F> res(a.size());
00055     const F* d = a; F* e = res;
00056     for(uint i = a.size(); i--; ) *e++ = std::abs(*d++);
00057     return res;
00058   }
00059 
00060   // ******************************************************************* min **
00061 
00063   template<typename F>
00064   F min(const concepts::Array<F>& a) {
00065     conceptsAssert(a.size() > 0, concepts::Assertion());
00066     const F* d = a;
00067     F val = *d++;
00068     for(uint i = a.size()-1; i--; ) 
00069       val = std::min(val, *d++);
00070     return val;
00071   }
00072 
00073 } // namespace std
00074 
00075 namespace concepts {
00076 
00077   // ************************************************************* makeArray **
00078 
00086   template<class F>
00087   Array<F> makeArray(uint n, const F& first, ...) {
00088     Array<F> data(n);
00089     data[0] = first;
00090 
00091     va_list param;
00092     va_start(param, first);
00093     for(uint i = 1; i < n; ++i)
00094       data[i] = va_arg(param, F);
00095     va_end(param);  
00096     return data;
00097   }
00098 
00099   // ******************************************************* chebychevPoints **
00100 
00105   inline void chebychevPoints(concepts::Array<Real>& p) {
00106     uint n = p.size();
00107     const Real f = M_PI / (2*n);
00108     Real *x = (Real*)p;
00109     while(n) *x++ = cos(f*(2*--n+1));
00110   }
00111 
00112 } // namespace concepts
00113 
00114 #endif // ArrayOp_hh

Home | Doxygen Documentation | Tutorials | Developer Tools (restricted)