9 #ifndef CT_VEC_FUNCTIONS_H
10 #define CT_VEC_FUNCTIONS_H
35 inline void copyn(
size_t n,
const T& x, T& y)
37 std::copy(x.begin(), x.begin() + n, y.begin());
51 std::transform(x.begin(), x.end(), y.begin(),
52 x.begin(), std::divides<typename T::value_type>());
68 std::transform(x.begin(), x.end(), y.begin(),
69 x.begin(), std::multiplies<typename T::value_type>());
80 template<
class T,
class S>
81 inline void scale(T& x, S scale_factor)
83 scale(x.begin(), x.end(), x.begin(), scale_factor);
97 return std::inner_product(x.begin(), x.end(), y.begin(), 0.0);
111 return _dot_ratio(x.begin(), x.end(), y.begin(), 0.0);
125 std::transform(x.begin(), x.end(), y.begin(),
126 x.begin(), std::plus<typename T::value_type>());
148 template<
class InputIter,
class S>
149 inline doublereal
_dot_ratio(InputIter x_begin, InputIter x_end,
150 InputIter y_begin, S start_value)
152 for (; x_begin != x_end; ++x_begin, ++y_begin) {
153 start_value += *x_begin / *y_begin;
172 for (
int i = 0; i < n; i++) {
186 inline std::ostream& operator<<(std::ostream& os, const std::vector<T>& v)
189 for (
size_t i = 0; i < n; i++) {
doublereal _dot_ratio(InputIter x_begin, InputIter x_end, InputIter y_begin, S start_value)
Templated dot ratio class.
void divide_each(OutputIter x_begin, OutputIter x_end, InputIter y_begin)
Templated divide of each element of x by the corresponding element of y.
void add_each(T &x, const T &y)
Returns a templated addition operation of two objects.
Various templated functions that carry out common vector operations (see Templated Utility Functions)...
This file contains definitions of terms that are used in internal routines and are unlikely to need m...
void multiply_each(OutputIter x_begin, OutputIter x_end, InputIter y_begin)
Multiply each entry in x by the corresponding entry in y.
doublereal absmax(InputIter begin, InputIter end)
The maximum absolute value (templated version)
void copyn(size_t n, const T &x, T &y)
Templated function that copies the first n entries from x to y.
doublereal dot_ratio(const T &x, const T &y)
Returns the templated dot ratio of two objects.
void scale(InputIter begin, InputIter end, OutputIter out, S scale_factor)
Multiply elements of an array by a scale factor.
doublereal dot_product(const T &x, const T &y)
Return the templated dot product of two objects.