IT++ Logo Newcom Logo

help_functions.h

Go to the documentation of this file.
00001 
00033 #ifndef HELP_FUNCTIONS_H
00034 #define HELP_FUNCTIONS_H
00035 
00036 #include <itpp/base/vec.h>
00037 #include <itpp/base/mat.h>
00038 
00039 
00040 namespace itpp {
00041 
00046   inline vec vec_function(double (*f)(double), const vec &x)
00047     {
00048       vec out(x.length());
00049       for (int i=0;i<x.length();i++) 
00050         out(i) = f(x(i));
00051       return out;
00052     }
00053 
00058   inline cvec cvec_function(std::complex<double> (*f)(const std::complex<double> &), const cvec &x)
00059     {
00060       cvec out(x.length());
00061       for (int i=0;i<x.length();i++) 
00062         out(i) = f(x(i));
00063       return out;
00064     }
00065 
00070   inline mat mat_function(double (*f)(double), const mat &x)
00071     {
00072       mat out(x.rows(),x.cols());
00073       for (int i=0;i<out.rows();i++) {
00074         for (int j=0;j<out.cols();j++) {
00075           out(i,j) = f(x(i,j));
00076         }
00077       }
00078       return out;
00079     }
00085   inline cmat cmat_function(std::complex<double> (*f)(const std::complex<double> &), const cmat &x)
00086     {
00087       cmat out(x.rows(),x.cols());
00088       for (int i=0;i<out.rows();i++) {
00089         for (int j=0;j<out.cols();j++) {
00090           out(i,j) = f(x(i,j));
00091         }
00092       }
00093       return out;
00094     }
00095 
00100   inline vec double_vec_function(double (*f)(double,double), const double x, const vec &y)
00101     {
00102       vec out(y.length());
00103       for (int i=0;i<y.length();i++) 
00104         out(i) = f(x,y(i));
00105       return out;
00106     }
00107 
00112   inline mat double_mat_function(double (*f)(double,double), const double x, const mat &y)
00113     {
00114       mat out(y.rows(),y.cols());
00115       for (int i=0;i<out.rows();i++) {
00116         for (int j=0;j<out.cols();j++) {
00117           out(i,j) = f(x, y(i,j));
00118         }
00119       }
00120       return out;
00121     }
00122 
00127   inline vec vec_double_function(double (*f)(double,double), const vec &x, const double y)
00128     {
00129       vec out(x.length());
00130       for (int i=0;i<x.length();i++) 
00131         out(i) = f(x(i),y);
00132       return out;
00133     }
00134 
00139   inline mat mat_double_function(double (*f)(double,double), const mat &x, const double y)
00140     {
00141       mat out(x.rows(),x.cols());
00142       for (int i=0;i<out.rows();i++) {
00143         for (int j=0;j<out.cols();j++) {
00144           out(i,j) = f(x(i,j), y);
00145         }
00146       }
00147       return out;
00148     }
00149 
00150 } // namespace itpp
00151 
00152 #endif // #ifndef HELP_FUNCTIONS_H
00153 
SourceForge Logo

Generated on Thu Aug 30 02:47:18 2007 for IT++ by Doxygen 1.5.3