29#ifndef HELP_FUNCTIONS_H
30#define HELP_FUNCTIONS_H
33#include <itpp/itexports.h>
46template<
typename Ret,
typename Arg>
47class 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);}
57template<
typename Ret,
typename Arg>
58class 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);}
70template<
typename Ret,
typename Arg>
71class 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);}
82template<
typename Ret,
typename Arg>
83class 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);}
95template<
typename Ret,
typename Arg>
96class 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);}
112template<
typename T,
typename Ftn>
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);
137template<
typename T,
typename Ftn>
141 for(
int i = 0;
i < m.rows();
i++) {
142 for(
int j = 0;
j < m.cols();
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);
234ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT vec
apply_function(
double(*f)(
double),
const vec &v);
235ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT cvec
apply_function(std::complex<double> (*f)(
const std::complex<double> &),
237ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT svec
apply_function(
short(*f)(
short),
const svec &v);
238ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT ivec
apply_function(
int (*f)(
int),
const ivec &v);
239ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT bvec
apply_function(bin(*f)(bin),
const bvec &v);
241ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT mat
apply_function(
double(*f)(
double),
const mat &m);
242ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT cmat
apply_function(std::complex<double> (*f)(
const std::complex<double> &),
244ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT smat
apply_function(
short(*f)(
short),
const smat &m);
245ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT imat
apply_function(
int (*f)(
int),
const imat &m);
248ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT vec
apply_function(
double(*f)(
double,
double),
const double& x,
const vec &v);
249ITPP_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);
252ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT svec
apply_function(
short(*f)(
short,
short),
const short& x,
const svec &v);
253ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT ivec
apply_function(
int (*f)(
int,
int),
const int& x,
const ivec &v);
254ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT bvec
apply_function(bin(*f)(bin, bin),
const bin& x,
const bvec &v);
256ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT mat
apply_function(
double(*f)(
double,
double),
const double& x,
const mat &m);
257ITPP_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);
260ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT smat
apply_function(
short(*f)(
short,
short),
const short& x,
const smat &m);
261ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT imat
apply_function(
int (*f)(
int,
int),
const int& x,
const imat &m);
262ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
bmat apply_function(bin(*f)(bin, bin),
const bin& x,
const bmat &m);
264ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT vec
apply_function(
double(*f)(
double,
double),
const vec &v,
const double& x);
265ITPP_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);
268ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT svec
apply_function(
short(*f)(
short,
short),
const svec &v,
const short& x);
269ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT ivec
apply_function(
int (*f)(
int,
int),
const ivec &v,
const int& x);
270ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT bvec
apply_function(bin(*f)(bin, bin),
const bvec &v,
const bin& x);
272ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT mat
apply_function(
double(*f)(
double,
double),
const mat &m,
const double& x);
273ITPP_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);
276ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT smat
apply_function(
short(*f)(
short,
short),
const smat &m,
const short& x);
277ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT imat
apply_function(
int (*f)(
int,
int),
const imat &m,
const int& x);
278ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
bmat apply_function(bin(*f)(bin, bin),
const bmat &m,
const bin& x);
int length() const
Returns the number of data elements in the array object.
Vec< T > apply_function(T(*f)(T), const Vec< T > &v)
Help function to call for a function: Vec<T> function(Vec<T>)
Vec< T > apply_functor(Ftn f, const Vec< T > &v)
Help function to apply function object to Vec<T>
Matrix Class Definitions.
Mat< bin > bmat
bin matrix