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++) {