In this tutorial we learn how the RVec class can be used to express easily mathematical operations involving arrays and scalars.
void vo002_VectorCalculations()
{
auto v_sum = v1 + v2;
auto v_mul = v1 * v2;
std::cout << "v1 = " << v1 << "\n"
<< "v2 = " << v2 << "\n"
<< "v1 + v2 = " << v_sum << "\n"
<< "v1 * v2 = " << v_mul << std::endl;
auto v_diff_s_0 = v1 - 2;
auto v_diff_s_1 = 2 - v1;
auto v_div_s_0 = v1 / 2.;
auto v_div_s_1 = 2. / v1;
std::cout << v1 << " - 2 = " << v_diff_s_0 << "\n"
<< "2 - " << v1 << " = " << v_diff_s_1 << "\n"
<< v1 << " / 2 = " << v_div_s_0 << "\n"
<< "2 / " << v1 << " = " << v_div_s_1 << std::endl;
auto v1_dot_v2 =
Dot(v1, v2);
std::cout << "Mean of " << v1 << " is " << v1_mean << "\n"
<< "Dot product of " << v1 << " and " << v2 << " is " << v1_dot_v2 << std::endl;
std::cout << "exp(" << v1 << ") = " << v_exp << "\n"
<< "log(" << v1 << ") = " << v_log << "\n"
<< "sin(" << v1 << ") = " << v_sin << std::endl;
#ifdef R__HAS_VDT
auto v_fast_exp = fast_exp(v1);
auto v_fast_log = fast_log(v1);
auto v_fast_sin = fast_sin(v1);
std::cout << "fast_exp(" << v1 << ") = " << v_fast_exp << "\n"
<< "fast_log(" << v1 << ") = " << v_fast_log << "\n"
<< "fast_sin(" << v1 << ") = " << v_fast_sin << std::endl;
auto v_transf =
Map(v1, [](
double x) {
return x * 2 / 3; });
std::cout << "Applying [](double x){return x * 2 / 3;} to " << v1 << " leads to " << v_transf << "\n";
#endif
}
- Date
- May 2018
- Author
- Danilo Piparo
Definition in file vo002_VectorCalculations.C.