14 void vo002_VectorCalculations()
27 std::cout <<
"v1 = " << v1 <<
"\n" 28 <<
"v2 = " << v2 <<
"\n" 29 <<
"v1 + v2 = " << v_sum <<
"\n" 30 <<
"v1 * v2 = " << v_mul << std::endl;
33 auto v_diff_s_0 = v1 - 2;
34 auto v_diff_s_1 = 2 - v1;
35 auto v_div_s_0 = v1 / 2.;
36 auto v_div_s_1 = 2. / v1;
38 std::cout << v1 <<
" - 2 = " << v_diff_s_0 <<
"\n" 39 <<
"2 - " << v1 <<
" = " << v_diff_s_1 <<
"\n" 40 << v1 <<
" / 2 = " << v_div_s_0 <<
"\n" 41 <<
"2 / " << v1 <<
" = " << v_div_s_1 << std::endl;
46 auto v1_mean =
Mean(v1);
47 auto v1_dot_v2 =
Dot(v1, v2);
49 std::cout <<
"Mean of " << v1 <<
" is " << v1_mean <<
"\n" 50 <<
"Dot product of " << v1 <<
" and " << v2 <<
" is " << v1_dot_v2 << std::endl;
57 std::cout <<
"exp(" << v1 <<
") = " << v_exp <<
"\n" 58 <<
"log(" << v1 <<
") = " << v_log <<
"\n" 59 <<
"sin(" << v1 <<
") = " << v_sin << std::endl;
64 auto v_fast_exp = fast_exp(v1);
65 auto v_fast_log = fast_log(v1);
66 auto v_fast_sin = fast_sin(v1);
68 std::cout <<
"fast_exp(" << v1 <<
") = " << v_fast_exp <<
"\n" 69 <<
"fast_log(" << v1 <<
") = " << v_fast_log <<
"\n" 70 <<
"fast_sin(" << v1 <<
") = " << v_fast_sin << std::endl;
74 auto v_transf =
Map(v1, [](
double x) {
return x * 2 / 3; });
76 std::cout <<
"Applying [](double x){return x * 2 / 3;} to " << v1 <<
" leads to " << v_transf <<
"\n";
auto Map(const RVec< T > &v, F &&f) -> RVec< decltype(f(v[0]))>
Create new collection applying a callable to the elements of the input collection.
A "std::vector"-like collection of values implementing handy operation to analyse them...
double Mean(const RVec< T > &v)
Get Mean.
auto Dot(const RVec< T > &v0, const RVec< V > &v1) -> decltype(v0[0] *v1[0])
Inner product.