void vo002_VectorCalculations()
{
std::cout <<
"v1 = " <<
v1 <<
"\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;
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
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
}
RVec< PromoteType< T > > log(const RVec< T > &v)
auto Map(Args &&... args)
Create new collection applying a callable to the elements of the input collection.
RVec< PromoteType< T > > exp(const RVec< T > &v)
RVec< PromoteType< T > > sin(const RVec< T > &v)
__roodevice__ double fast_exp(double x)
__roodevice__ double fast_sin(double x)
__roodevice__ double fast_log(double x)
Double_t Mean(Long64_t n, const T *a, const Double_t *w=nullptr)
Returns the weighted mean of an array a with length n.
v1 = { 1, 2, 3 }
v2 = { 4, 5, 6 }
v1 + v2 = { 5, 7, 9 }
v1 * v2 = { 4, 10, 18 }
{ 1, 2, 3 } - 2 = { -1, 0, 1 }
2 - { 1, 2, 3 } = { 1, 0, -1 }
{ 1, 2, 3 } / 2 = { 0.5, 1, 1.5 }
2 / { 1, 2, 3 } = { 2, 1, 0.666667 }
Mean of { 1, 2, 3 } is 2
Dot product of { 1, 2, 3 } and { 4, 5, 6 } is 32
exp({ 1, 2, 3 }) = { 2.71828, 7.38906, 20.0855 }
log({ 1, 2, 3 }) = { 0, 0.693147, 1.09861 }
sin({ 1, 2, 3 }) = { 0.841471, 0.909297, 0.14112 }
fast_exp({ 1, 2, 3 }) = { 2.71828, 7.38906, 20.0855 }
fast_log({ 1, 2, 3 }) = { 0, 0.693147, 1.09861 }
fast_sin({ 1, 2, 3 }) = { 0.841471, 0.909297, 0.14112 }
Applying [](double x){return x * 2 / 3;} to { 1, 2, 3 } leads to { 0.666667, 1.33333, 2 }