Andy Panov - 2005-06-17

Hi,

First of all I would like to say thank you to all developers of itpp for the great library to use.

I would suggest to include more helper functions to help_functions.h in order to provide some means for inplace transformations of itpp vectors and matrices, so
additional copying can be avoided.

Transform function templates can be implemented as follows:

include <functional>

//vector elements transform
template<class T>
inline void vector_transform(std::pointer_to_unary_function<const T&,T>& f, Vec<T>& x){
for (int i=0; i<x.length(); i++)
x(i) = f(x(i));
}

template<class T>
inline void vector_transform(std::pointer_to_unary_function<const T,T>& f, Vec<T>& x){
for (int i=0; i<x.length(); i++)
x(i) = f(x(i));
}

template<class T>
inline void vector_transform(std::pointer_to_unary_function<T,T>& f, Vec<T>& x){
for (int i=0; i<x.length(); i++)
x(i) = f(x(i));
}

//matrix elements transform
template<class T>
inline void matrix_transform(std::pointer_to_unary_function<const T&,T>& f, Mat<T>& x){
for (int i=0;i<x.rows();i++) {
for (int j=0;j<x.cols();j++) {
x(i,j) = f(x(i,j));
}
}
}

template<class T>
inline void matrix_transform(std::pointer_to_unary_function<const T,T>& f, Mat<T>& x){
for (int i=0;i<x.rows();i++) {
for (int j=0;j<x.cols();j++) {
x(i,j) = f(x(i,j));
}
}
}

template<class T>
inline void matrix_transform(std::pointer_to_unary_function<T,T>& f, Mat<T>& x){
for (int i=0;i<x.rows();i++) {
for (int j=0;j<x.cols();j++) {
x(i,j) = f(x(i,j));
}
}
}

Definitely, the best approach is to use the standard iterators with itpp containers, but this code minimizes changes in the existing design of the library.

Best regards and thank you
Andy.