29 #ifndef HELP_FUNCTIONS_H 
   30 #define HELP_FUNCTIONS_H 
   33 #include <itpp/itexports.h> 
   46 template<
typename Ret, 
typename Arg>
 
   47 class Unary_Function_Wrapper
 
   49   typedef Ret(*Ftn)(Arg);
 
   52   explicit Unary_Function_Wrapper(Ftn f): _f(f) {}
 
   53   Ret operator()(Arg v)
 const { 
return _f(v);}
 
   57 template<
typename Ret, 
typename Arg>
 
   58 class Binary_Function_With_Bound_1st
 
   60   typedef Ret(*Ftn)(Arg, Arg);
 
   64   Binary_Function_With_Bound_1st(Ftn f, 
const Arg b): _f(f), _b(b) {}
 
   65   Ret operator()(Arg v)
 const { 
return _f(_b, v);}
 
   70 template<
typename Ret, 
typename Arg>
 
   71 class Binary_Function_With_Bound_1st<Ret, const Arg&>
 
   73   typedef Ret(*Ftn)(
const Arg&, 
const Arg&);
 
   77   Binary_Function_With_Bound_1st(Ftn f, 
const Arg& b): _f(f), _b(b) {}
 
   78   Ret operator()(
const Arg& v)
 const { 
return _f(_b, v);}
 
   82 template<
typename Ret, 
typename Arg>
 
   83 class Binary_Function_With_Bound_2nd
 
   85   typedef Ret(*Ftn)(Arg, Arg);
 
   89   Binary_Function_With_Bound_2nd(Ftn f, Arg b): _f(f), _b(b) {}
 
   90   Ret operator()(Arg v)
 const { 
return _f(v, _b);}
 
   95 template<
typename Ret, 
typename Arg>
 
   96 class Binary_Function_With_Bound_2nd<Ret, const Arg&>
 
   98   typedef Ret(*Ftn)(
const Arg&, 
const Arg&);
 
  102   Binary_Function_With_Bound_2nd(Ftn f, 
const Arg& b): _f(f), _b(b) {}
 
  103   Ret operator()(
const Arg& v)
 const { 
return _f(v, _b);}
 
  112 template<
typename T, 
typename Ftn>
 
  116   for(
int i = 0; i < v.
length(); i++) {
 
  126   return apply_functor(details::Unary_Function_Wrapper<T, T>(f), v);
 
  133   return apply_functor(details::Unary_Function_Wrapper<T, const T&>(f), v);
 
  137 template<
typename T, 
typename Ftn>
 
  141   for(
int i = 0; i < m.
rows(); i++) {
 
  142     for(
int j = 0; j < m.
cols(); j++) {
 
  143       out(i, j) = f(m(i, j));
 
  152   return apply_functor(details::Unary_Function_Wrapper<T, T>(f), m);
 
  159   return apply_functor(details::Unary_Function_Wrapper<T, const T&>(f), m);
 
  166   return apply_functor(details::Binary_Function_With_Bound_1st<T, T>(f, x), v);
 
  175   return apply_functor(details::Binary_Function_With_Bound_1st<T, const T&>(f, x), v);
 
  182   return apply_functor(details::Binary_Function_With_Bound_1st<T, T>(f, x), m);
 
  191   return apply_functor(details::Binary_Function_With_Bound_1st<T, const T&>(f, x), m);
 
  198   return apply_functor(details::Binary_Function_With_Bound_2nd<T, T>(f, x), v);
 
  207   return apply_functor(details::Binary_Function_With_Bound_2nd<T, const T&>(f, x), v);
 
  214   return apply_functor(details::Binary_Function_With_Bound_2nd<T, T>(f, x), m);
 
  223   return apply_functor(details::Binary_Function_With_Bound_2nd<T, const T&>(f, x), m);
 
  234 ITPP_EXPORT_TEMPLATE 
template ITPP_EXPORT vec 
apply_function(
double(*f)(
double), 
const vec &v);
 
  235 ITPP_EXPORT_TEMPLATE 
template ITPP_EXPORT cvec 
apply_function(std::complex<double> (*f)(
const std::complex<double> &),
 
  237 ITPP_EXPORT_TEMPLATE 
template ITPP_EXPORT svec 
apply_function(
short(*f)(
short), 
const svec &v);
 
  238 ITPP_EXPORT_TEMPLATE 
template ITPP_EXPORT ivec 
apply_function(
int (*f)(
int), 
const ivec &v);
 
  239 ITPP_EXPORT_TEMPLATE 
template ITPP_EXPORT bvec 
apply_function(bin(*f)(bin), 
const bvec &v);
 
  241 ITPP_EXPORT_TEMPLATE 
template ITPP_EXPORT mat 
apply_function(
double(*f)(
double), 
const mat &m);
 
  242 ITPP_EXPORT_TEMPLATE 
template ITPP_EXPORT cmat 
apply_function(std::complex<double> (*f)(
const std::complex<double> &),
 
  244 ITPP_EXPORT_TEMPLATE 
template ITPP_EXPORT smat 
apply_function(
short(*f)(
short), 
const smat &m);
 
  245 ITPP_EXPORT_TEMPLATE 
template ITPP_EXPORT imat 
apply_function(
int (*f)(
int), 
const imat &m);
 
  248 ITPP_EXPORT_TEMPLATE 
template ITPP_EXPORT vec 
apply_function(
double(*f)(
double, 
double), 
const double& x, 
const vec &v);
 
  249 ITPP_EXPORT_TEMPLATE 
template ITPP_EXPORT cvec 
apply_function(std::complex<double> (*f)(
const std::complex<double> &,
 
  250                                     const std::complex<double> &),
 
  251                                     const std::complex<double>& x, 
const cvec &v);
 
  252 ITPP_EXPORT_TEMPLATE 
template ITPP_EXPORT svec 
apply_function(
short(*f)(
short, 
short), 
const short& x, 
const svec &v);
 
  253 ITPP_EXPORT_TEMPLATE 
template ITPP_EXPORT ivec 
apply_function(
int (*f)(
int, 
int), 
const int& x, 
const ivec &v);
 
  254 ITPP_EXPORT_TEMPLATE 
template ITPP_EXPORT bvec 
apply_function(bin(*f)(bin, bin), 
const bin& x, 
const bvec &v);
 
  256 ITPP_EXPORT_TEMPLATE 
template ITPP_EXPORT mat 
apply_function(
double(*f)(
double, 
double), 
const double& x, 
const mat &m);
 
  257 ITPP_EXPORT_TEMPLATE 
template ITPP_EXPORT cmat 
apply_function(std::complex<double> (*f)(
const std::complex<double> &,
 
  258                                     const std::complex<double> &),
 
  259                                     const std::complex<double>& x, 
const cmat &m);
 
  260 ITPP_EXPORT_TEMPLATE 
template ITPP_EXPORT smat 
apply_function(
short(*f)(
short, 
short), 
const short& x, 
const smat &m);
 
  261 ITPP_EXPORT_TEMPLATE 
template ITPP_EXPORT imat 
apply_function(
int (*f)(
int, 
int), 
const int& x, 
const imat &m);
 
  262 ITPP_EXPORT_TEMPLATE 
template ITPP_EXPORT 
bmat apply_function(bin(*f)(bin, bin), 
const bin& x, 
const bmat &m);
 
  264 ITPP_EXPORT_TEMPLATE 
template ITPP_EXPORT vec 
apply_function(
double(*f)(
double, 
double), 
const vec &v, 
const double& x);
 
  265 ITPP_EXPORT_TEMPLATE 
template ITPP_EXPORT cvec 
apply_function(std::complex<double> (*f)(
const std::complex<double> &,
 
  266                                     const std::complex<double> &),
 
  267                                     const cvec &v, 
const std::complex<double>& x);
 
  268 ITPP_EXPORT_TEMPLATE 
template ITPP_EXPORT svec 
apply_function(
short(*f)(
short, 
short), 
const svec &v, 
const short& x);
 
  269 ITPP_EXPORT_TEMPLATE 
template ITPP_EXPORT ivec 
apply_function(
int (*f)(
int, 
int), 
const ivec &v, 
const int& x);
 
  270 ITPP_EXPORT_TEMPLATE 
template ITPP_EXPORT bvec 
apply_function(bin(*f)(bin, bin), 
const bvec &v, 
const bin& x);
 
  272 ITPP_EXPORT_TEMPLATE 
template ITPP_EXPORT mat 
apply_function(
double(*f)(
double, 
double), 
const mat &m, 
const double& x);
 
  273 ITPP_EXPORT_TEMPLATE 
template ITPP_EXPORT cmat 
apply_function(std::complex<double> (*f)(
const std::complex<double> &,
 
  274                                     const std::complex<double> &),
 
  275                                     const cmat &m, 
const std::complex<double>& x);
 
  276 ITPP_EXPORT_TEMPLATE 
template ITPP_EXPORT smat 
apply_function(
short(*f)(
short, 
short), 
const smat &m, 
const short& x);
 
  277 ITPP_EXPORT_TEMPLATE 
template ITPP_EXPORT imat 
apply_function(
int (*f)(
int, 
int), 
const imat &m, 
const int& x);
 
  278 ITPP_EXPORT_TEMPLATE 
template ITPP_EXPORT 
bmat apply_function(bin(*f)(bin, bin), 
const bmat &m, 
const bin& x);
 
  284 #endif // #ifndef HELP_FUNCTIONS_H