In this tutorial we learn how the RVec class can be used to express easily mathematical operations involving arrays and scalars.
Author: Danilo Piparo
This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Tuesday, March 28, 2023 at 10:03 AM.
Operations on RVec instances are made to be fast (vectorisation is exploited)
and easy to use. RVecF, RVecD, RVecI, ..., are handy aliases for RVec
ROOT::RVecF v1{1., 2., 3.};
ROOT::RVecF v2{4., 5., 6.};
Arithmetic operations are to be intended on pairs of elements with identical index
auto v_sum = v1 + v2;
auto v_mul = v1 * v2;
Easy to inspect:
std::cout << "v1 = " << v1 << "\n"
<< "v2 = " << v2 << "\n"
<< "v1 + v2 = " << v_sum << "\n"
<< "v1 * v2 = " << v_mul << std::endl;
v1 = { 1, 2, 3 } v2 = { 4, 5, 6 } v1 + v2 = { 5, 7, 9 } v1 * v2 = { 4, 10, 18 }
It's also possible to mix scalars and RVecs
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;
{ 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 }
Dot product and the extraction of quantities such as Mean, Min and Max are also easy to express (see here for the full list: https://root.cern.ch/doc/master/namespaceROOT_1_1VecOps.html)
auto v1_mean = Mean(v1);
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;
input_line_55:2:2: error: Syntax error auto v1_mean = Mean(v1); ^ FunctionDecl 0x7f674f1806f0 <input_line_55:1:1, line:8:1> line:1:6 __cling_Un1Qu323 'void (void *)' |-ParmVarDecl 0x7f674f180638 <col:23, col:29> col:29 vpClingValue 'void *' |-CompoundStmt 0x7f674f1896f0 <col:43, line:8:1> | |-DeclStmt 0x7f674f180ab8 <line:2:2, col:25> | | `-VarDecl 0x7f674f1807f8 <col:2, col:24> col:7 used v1_mean 'auto' cinit | | `-CallExpr 0x7f674f180a90 <col:17, col:24> '<dependent type>' | | |-DeclRefExpr 0x7f674f180a30 <col:17> '<dependent type>' lvalue Var 0x7f674f180968 'Mean' '<dependent type>' | | `-DeclRefExpr 0x7f674f180a70 <col:22> 'ROOT::RVecF':'ROOT::VecOps::RVec<float>' lvalue Var 0xb5bda50 'v1' 'ROOT::RVecF':'ROOT::VecOps::RVec<float>' | |-DeclStmt 0x7f674f181d88 <line:3:1, col:29> | | `-VarDecl 0x7f674f180b10 <col:1, col:28> col:6 used v1_dot_v2 'float':'float' cinit | | `-CallExpr 0x7f674f181c80 <col:18, col:28> 'decltype(v0[0] * v1[0])':'float' adl | | |-ImplicitCastExpr 0x7f674f181c68 <col:18> 'auto (*)(const RVec<float> &, const RVec<float> &) -> decltype(v0[0] * v1[0])' <FunctionToPointerDecay> | | | `-DeclRefExpr 0x7f674f181bc0 <col:18> 'auto (const RVec<float> &, const RVec<float> &) -> decltype(v0[0] * v1[0])' lvalue Function 0x7f674f181aa0 'Dot' 'auto (const RVec<float> &, const RVec<float> &) -> decltype(v0[0] * v1[0])' (FunctionTemplate 0x7f674f180c38 'Dot') | | |-ImplicitCastExpr 0x7f674f181cb0 <col:22> 'const RVec<float>':'const ROOT::VecOps::RVec<float>' lvalue <NoOp> | | | `-DeclRefExpr 0x7f674f180bc0 <col:22> 'ROOT::RVecF':'ROOT::VecOps::RVec<float>' lvalue Var 0xb5bda50 'v1' 'ROOT::RVecF':'ROOT::VecOps::RVec<float>' | | `-ImplicitCastExpr 0x7f674f181cc8 <col:26> 'const RVec<float>':'const ROOT::VecOps::RVec<float>' lvalue <NoOp> | | `-DeclRefExpr 0x7f674f180be0 <col:26> 'ROOT::RVecF':'ROOT::VecOps::RVec<float>' lvalue Var 0xb5ca458 'v2' 'ROOT::RVecF':'ROOT::VecOps::RVec<float>' | |-CXXOperatorCallExpr 0x7f674f1896b0 <line:5:1, line:6:86> '<dependent type>' '<<' | | |-UnresolvedLookupExpr 0x7f674f189368 <col:78> '<overloaded function type>' lvalue (ADL) = 'operator<<' 0x3c18df0 0x4cfa4b8 0x4cf9ee0 0x3c165e0 0x3c16850 0x3c16ac0 0x3c16d30 0x3c16fa0 0x3c17210 0x3c17480 0x3c176f0 0x3c17960 0x3c17bd0 0x3c17e40 0x3c180b0 0x3c18320 0x3c18590 0x3c18830 0x3c1c020 0x3c1e4a0 0x3c25368 0x3c26098 0x3c45e10 0x3c46120 0x3c4f918 0x3c50878 0x3c51a08 0x3c52c28 0x3c53db8 0x3c54f48 0x3c56e10 0x4f89978 0x4f8c788 0x36c3dd0 0x36c42d8 0x3f7aba0 0x3f985a0 0x43b1640 0x444cdc0 0x449c328 0x449c968 0x449cfa8 0x449d5e0 0x449db88 0x449e138 0x44a4e60 0x449edf0 0x449f398 0x449f978 0x44a3b30 0x44e3f48 0x45db320 0x45ee288 0x4687b48 0x46e0438 0x46e4fe8 0x46e5f38 0x46e7368 0x46e8318 0x46e9268 0x46eb008 0x46ebfd8 0x47b9ff8 0x47eafb8 0x47c61a8 0x47c70a0 0x47c7fa0 0x47ca4f0 0x4812df0 0x47cabd0 0x4828640 0x47cbad0 0x47cc9d0 0x47cd8d0 0x47d44b0 0x47f59c8 0x47f7f80 0x47fa588 0x48096f0 0x480c270 0x480f900 0x481c760 0x481f220 0x4823390 0x4825c80 0x4835670 0x483a230 0x483ed20 0x4b979f8 0x49a4650 0x49a51f0 0x49a5bb0 0x49a6570 0x49a6f90 0x4a44ae8 0x4a45488 0x4a45df8 | | |-CXXOperatorCallExpr 0x7f674f1892c8 <line:5:1, line:6:68> '<dependent type>' '<<' | | | |-UnresolvedLookupExpr 0x7f674f188f80 <col:65> '<overloaded function type>' lvalue (ADL) = 'operator<<' 0x3c18df0 0x4cfa4b8 0x4cf9ee0 0x3c165e0 0x3c16850 0x3c16ac0 0x3c16d30 0x3c16fa0 0x3c17210 0x3c17480 0x3c176f0 0x3c17960 0x3c17bd0 0x3c17e40 0x3c180b0 0x3c18320 0x3c18590 0x3c18830 0x3c1c020 0x3c1e4a0 0x3c25368 0x3c26098 0x3c45e10 0x3c46120 0x3c4f918 0x3c50878 0x3c51a08 0x3c52c28 0x3c53db8 0x3c54f48 0x3c56e10 0x4f89978 0x4f8c788 0x36c3dd0 0x36c42d8 0x3f7aba0 0x3f985a0 0x43b1640 0x444cdc0 0x449c328 0x449c968 0x449cfa8 0x449d5e0 0x449db88 0x449e138 0x44a4e60 0x449edf0 0x449f398 0x449f978 0x44a3b30 0x44e3f48 0x45db320 0x45ee288 0x4687b48 0x46e0438 0x46e4fe8 0x46e5f38 0x46e7368 0x46e8318 0x46e9268 0x46eb008 0x46ebfd8 0x47b9ff8 0x47eafb8 0x47c61a8 0x47c70a0 0x47c7fa0 0x47ca4f0 0x4812df0 0x47cabd0 0x4828640 0x47cbad0 0x47cc9d0 0x47cd8d0 0x47d44b0 0x47f59c8 0x47f7f80 0x47fa588 0x48096f0 0x480c270 0x480f900 0x481c760 0x481f220 0x4823390 0x4825c80 0x4835670 0x483a230 0x483ed20 0x4b979f8 0x49a4650 0x49a51f0 0x49a5bb0 0x49a6570 0x49a6f90 0x4a44ae8 0x4a45488 0x4a45df8 | | | |-CXXOperatorCallExpr 0x7f674f188f28 <line:5:1, line:6:58> '<dependent type>' '<<' | | | | |-UnresolvedLookupExpr 0x7f674f188be0 <col:55> '<overloaded function type>' lvalue (ADL) = 'operator<<' 0x3c18df0 0x4cfa4b8 0x4cf9ee0 0x3c165e0 0x3c16850 0x3c16ac0 0x3c16d30 0x3c16fa0 0x3c17210 0x3c17480 0x3c176f0 0x3c17960 0x3c17bd0 0x3c17e40 0x3c180b0 0x3c18320 0x3c18590 0x3c18830 0x3c1c020 0x3c1e4a0 0x3c25368 0x3c26098 0x3c45e10 0x3c46120 0x3c4f918 0x3c50878 0x3c51a08 0x3c52c28 0x3c53db8 0x3c54f48 0x3c56e10 0x4f89978 0x4f8c788 0x36c3dd0 0x36c42d8 0x3f7aba0 0x3f985a0 0x43b1640 0x444cdc0 0x449c328 0x449c968 0x449cfa8 0x449d5e0 0x449db88 0x449e138 0x44a4e60 0x449edf0 0x449f398 0x449f978 0x44a3b30 0x44e3f48 0x45db320 0x45ee288 0x4687b48 0x46e0438 0x46e4fe8 0x46e5f38 0x46e7368 0x46e8318 0x46e9268 0x46eb008 0x46ebfd8 0x47b9ff8 0x47eafb8 0x47c61a8 0x47c70a0 0x47c7fa0 0x47ca4f0 0x4812df0 0x47cabd0 0x4828640 0x47cbad0 0x47cc9d0 0x47cd8d0 0x47d44b0 0x47f59c8 0x47f7f80 0x47fa588 0x48096f0 0x480c270 0x480f900 0x481c760 0x481f220 0x4823390 0x4825c80 0x4835670 0x483a230 0x483ed20 0x4b979f8 0x49a4650 0x49a51f0 0x49a5bb0 0x49a6570 0x49a6f90 0x4a44ae8 0x4a45488 0x4a45df8 | | | | |-CXXOperatorCallExpr 0x7f674f188b88 <line:5:1, line:6:52> '<dependent type>' '<<' | | | | | |-UnresolvedLookupExpr 0x7f674f188840 <col:49> '<overloaded function type>' lvalue (ADL) = 'operator<<' 0x3c18df0 0x4cfa4b8 0x4cf9ee0 0x3c165e0 0x3c16850 0x3c16ac0 0x3c16d30 0x3c16fa0 0x3c17210 0x3c17480 0x3c176f0 0x3c17960 0x3c17bd0 0x3c17e40 0x3c180b0 0x3c18320 0x3c18590 0x3c18830 0x3c1c020 0x3c1e4a0 0x3c25368 0x3c26098 0x3c45e10 0x3c46120 0x3c4f918 0x3c50878 0x3c51a08 0x3c52c28 0x3c53db8 0x3c54f48 0x3c56e10 0x4f89978 0x4f8c788 0x36c3dd0 0x36c42d8 0x3f7aba0 0x3f985a0 0x43b1640 0x444cdc0 0x449c328 0x449c968 0x449cfa8 0x449d5e0 0x449db88 0x449e138 0x44a4e60 0x449edf0 0x449f398 0x449f978 0x44a3b30 0x44e3f48 0x45db320 0x45ee288 0x4687b48 0x46e0438 0x46e4fe8 0x46e5f38 0x46e7368 0x46e8318 0x46e9268 0x46eb008 0x46ebfd8 0x47b9ff8 0x47eafb8 0x47c61a8 0x47c70a0 0x47c7fa0 0x47ca4f0 0x4812df0 0x47cabd0 0x4828640 0x47cbad0 0x47cc9d0 0x47cd8d0 0x47d44b0 0x47f59c8 0x47f7f80 0x47fa588 0x48096f0 0x480c270 0x480f900 0x481c760 0x481f220 0x4823390 0x4825c80 0x4835670 0x483a230 0x483ed20 0x4b979f8 0x49a4650 0x49a51f0 0x49a5bb0 0x49a6570 0x49a6f90 0x4a44ae8 0x4a45488 0x4a45df8 | | | | | |-CXXOperatorCallExpr 0x7f674f1887e8 <line:5:1, line:6:41> '<dependent type>' '<<' | | | | | | |-UnresolvedLookupExpr 0x7f674f1884a0 <col:38> '<overloaded function type>' lvalue (ADL) = 'operator<<' 0x3c18df0 0x4cfa4b8 0x4cf9ee0 0x3c165e0 0x3c16850 0x3c16ac0 0x3c16d30 0x3c16fa0 0x3c17210 0x3c17480 0x3c176f0 0x3c17960 0x3c17bd0 0x3c17e40 0x3c180b0 0x3c18320 0x3c18590 0x3c18830 0x3c1c020 0x3c1e4a0 0x3c25368 0x3c26098 0x3c45e10 0x3c46120 0x3c4f918 0x3c50878 0x3c51a08 0x3c52c28 0x3c53db8 0x3c54f48 0x3c56e10 0x4f89978 0x4f8c788 0x36c3dd0 0x36c42d8 0x3f7aba0 0x3f985a0 0x43b1640 0x444cdc0 0x449c328 0x449c968 0x449cfa8 0x449d5e0 0x449db88 0x449e138 0x44a4e60 0x449edf0 0x449f398 0x449f978 0x44a3b30 0x44e3f48 0x45db320 0x45ee288 0x4687b48 0x46e0438 0x46e4fe8 0x46e5f38 0x46e7368 0x46e8318 0x46e9268 0x46eb008 0x46ebfd8 0x47b9ff8 0x47eafb8 0x47c61a8 0x47c70a0 0x47c7fa0 0x47ca4f0 0x4812df0 0x47cabd0 0x4828640 0x47cbad0 0x47cc9d0 0x47cd8d0 0x47d44b0 0x47f59c8 0x47f7f80 0x47fa588 0x48096f0 0x480c270 0x480f900 0x481c760 0x481f220 0x4823390 0x4825c80 0x4835670 0x483a230 0x483ed20 0x4b979f8 0x49a4650 0x49a51f0 0x49a5bb0 0x49a6570 0x49a6f90 0x4a44ae8 0x4a45488 0x4a45df8 | | | | | | |-CXXOperatorCallExpr 0x7f674f188448 <line:5:1, line:6:35> '<dependent type>' '<<' | | | | | | | |-UnresolvedLookupExpr 0x7f674f188100 <col:32> '<overloaded function type>' lvalue (ADL) = 'operator<<' 0x3c18df0 0x4cfa4b8 0x4cf9ee0 0x3c165e0 0x3c16850 0x3c16ac0 0x3c16d30 0x3c16fa0 0x3c17210 0x3c17480 0x3c176f0 0x3c17960 0x3c17bd0 0x3c17e40 0x3c180b0 0x3c18320 0x3c18590 0x3c18830 0x3c1c020 0x3c1e4a0 0x3c25368 0x3c26098 0x3c45e10 0x3c46120 0x3c4f918 0x3c50878 0x3c51a08 0x3c52c28 0x3c53db8 0x3c54f48 0x3c56e10 0x4f89978 0x4f8c788 0x36c3dd0 0x36c42d8 0x3f7aba0 0x3f985a0 0x43b1640 0x444cdc0 0x449c328 0x449c968 0x449cfa8 0x449d5e0 0x449db88 0x449e138 0x44a4e60 0x449edf0 0x449f398 0x449f978 0x44a3b30 0x44e3f48 0x45db320 0x45ee288 0x4687b48 0x46e0438 0x46e4fe8 0x46e5f38 0x46e7368 0x46e8318 0x46e9268 0x46eb008 0x46ebfd8 0x47b9ff8 0x47eafb8 0x47c61a8 0x47c70a0 0x47c7fa0 0x47ca4f0 0x4812df0 0x47cabd0 0x4828640 0x47cbad0 0x47cc9d0 0x47cd8d0 0x47d44b0 0x47f59c8 0x47f7f80 0x47fa588 0x48096f0 0x480c270 0x480f900 0x481c760 0x481f220 0x4823390 0x4825c80 0x4835670 0x483a230 0x483ed20 0x4b979f8 0x49a4650 0x49a51f0 0x49a5bb0 0x49a6570 0x49a6f90 0x4a44ae8 0x4a45488 0x4a45df8 | | | | | | | |-CXXOperatorCallExpr 0x7f674f1880a8 <line:5:1, line:6:14> '<dependent type>' '<<' | | | | | | | | |-UnresolvedLookupExpr 0x7f674f187d60 <col:11> '<overloaded function type>' lvalue (ADL) = 'operator<<' 0x3c18df0 0x4cfa4b8 0x4cf9ee0 0x3c165e0 0x3c16850 0x3c16ac0 0x3c16d30 0x3c16fa0 0x3c17210 0x3c17480 0x3c176f0 0x3c17960 0x3c17bd0 0x3c17e40 0x3c180b0 0x3c18320 0x3c18590 0x3c18830 0x3c1c020 0x3c1e4a0 0x3c25368 0x3c26098 0x3c45e10 0x3c46120 0x3c4f918 0x3c50878 0x3c51a08 0x3c52c28 0x3c53db8 0x3c54f48 0x3c56e10 0x4f89978 0x4f8c788 0x36c3dd0 0x36c42d8 0x3f7aba0 0x3f985a0 0x43b1640 0x444cdc0 0x449c328 0x449c968 0x449cfa8 0x449d5e0 0x449db88 0x449e138 0x44a4e60 0x449edf0 0x449f398 0x449f978 0x44a3b30 0x44e3f48 0x45db320 0x45ee288 0x4687b48 0x46e0438 0x46e4fe8 0x46e5f38 0x46e7368 0x46e8318 0x46e9268 0x46eb008 0x46ebfd8 0x47b9ff8 0x47eafb8 0x47c61a8 0x47c70a0 0x47c7fa0 0x47ca4f0 0x4812df0 0x47cabd0 0x4828640 0x47cbad0 0x47cc9d0 0x47cd8d0 0x47d44b0 0x47f59c8 0x47f7f80 0x47fa588 0x48096f0 0x480c270 0x480f900 0x481c760 0x481f220 0x4823390 0x4825c80 0x4835670 0x483a230 0x483ed20 0x4b979f8 0x49a4650 0x49a51f0 0x49a5bb0 0x49a6570 0x49a6f90 0x4a44ae8 0x4a45488 0x4a45df8 | | | | | | | | |-CXXOperatorCallExpr 0x7f674f187cc0 <line:5:1, col:55> '<dependent type>' '<<' | | | | | | | | | |-UnresolvedLookupExpr 0x7f674f187978 <col:52> '<overloaded function type>' lvalue (ADL) = 'operator<<' 0x3c18df0 0x4cfa4b8 0x4cf9ee0 0x3c165e0 0x3c16850 0x3c16ac0 0x3c16d30 0x3c16fa0 0x3c17210 0x3c17480 0x3c176f0 0x3c17960 0x3c17bd0 0x3c17e40 0x3c180b0 0x3c18320 0x3c18590 0x3c18830 0x3c1c020 0x3c1e4a0 0x3c25368 0x3c26098 0x3c45e10 0x3c46120 0x3c4f918 0x3c50878 0x3c51a08 0x3c52c28 0x3c53db8 0x3c54f48 0x3c56e10 0x4f89978 0x4f8c788 0x36c3dd0 0x36c42d8 0x3f7aba0 0x3f985a0 0x43b1640 0x444cdc0 0x449c328 0x449c968 0x449cfa8 0x449d5e0 0x449db88 0x449e138 0x44a4e60 0x449edf0 0x449f398 0x449f978 0x44a3b30 0x44e3f48 0x45db320 0x45ee288 0x4687b48 0x46e0438 0x46e4fe8 0x46e5f38 0x46e7368 0x46e8318 0x46e9268 0x46eb008 0x46ebfd8 0x47b9ff8 0x47eafb8 0x47c61a8 0x47c70a0 0x47c7fa0 0x47ca4f0 0x4812df0 0x47cabd0 0x4828640 0x47cbad0 0x47cc9d0 0x47cd8d0 0x47d44b0 0x47f59c8 0x47f7f80 0x47fa588 0x48096f0 0x480c270 0x480f900 0x481c760 0x481f220 0x4823390 0x4825c80 0x4835670 0x483a230 0x483ed20 0x4b979f8 0x49a4650 0x49a51f0 0x49a5bb0 0x49a6570 0x49a6f90 0x4a44ae8 0x4a45488 0x4a45df8 | | | | | | | | | |-CXXOperatorCallExpr 0x7f674f187920 <col:1, col:44> '<dependent type>' '<<' | | | | | | | | | | |-UnresolvedLookupExpr 0x7f674f1875d8 <col:41> '<overloaded function type>' lvalue (ADL) = 'operator<<' 0x3c18df0 0x4cfa4b8 0x4cf9ee0 0x3c165e0 0x3c16850 0x3c16ac0 0x3c16d30 0x3c16fa0 0x3c17210 0x3c17480 0x3c176f0 0x3c17960 0x3c17bd0 0x3c17e40 0x3c180b0 0x3c18320 0x3c18590 0x3c18830 0x3c1c020 0x3c1e4a0 0x3c25368 0x3c26098 0x3c45e10 0x3c46120 0x3c4f918 0x3c50878 0x3c51a08 0x3c52c28 0x3c53db8 0x3c54f48 0x3c56e10 0x4f89978 0x4f8c788 0x36c3dd0 0x36c42d8 0x3f7aba0 0x3f985a0 0x43b1640 0x444cdc0 0x449c328 0x449c968 0x449cfa8 0x449d5e0 0x449db88 0x449e138 0x44a4e60 0x449edf0 0x449f398 0x449f978 0x44a3b30 0x44e3f48 0x45db320 0x45ee288 0x4687b48 0x46e0438 0x46e4fe8 0x46e5f38 0x46e7368 0x46e8318 0x46e9268 0x46eb008 0x46ebfd8 0x47b9ff8 0x47eafb8 0x47c61a8 0x47c70a0 0x47c7fa0 0x47ca4f0 0x4812df0 0x47cabd0 0x4828640 0x47cbad0 0x47cc9d0 0x47cd8d0 0x47d44b0 0x47f59c8 0x47f7f80 0x47fa588 0x48096f0 0x480c270 0x480f900 0x481c760 0x481f220 0x4823390 0x4825c80 0x4835670 0x483a230 0x483ed20 0x4b979f8 0x49a4650 0x49a51f0 0x49a5bb0 0x49a6570 0x49a6f90 0x4a44ae8 0x4a45488 0x4a45df8 | | | | | | | | | | |-CXXOperatorCallExpr 0x7f674f187560 <col:1, col:34> 'basic_ostream<char, std::char_traits<char> >':'std::basic_ostream<char>' lvalue '<<' | | | | | | | | | | | |-ImplicitCastExpr 0x7f674f187548 <col:31> 'basic_ostream<char, std::char_traits<char> > &(*)(basic_ostream<char, std::char_traits<char> > &, const char *)' <FunctionToPointerDecay> | | | | | | | | | | | | `-DeclRefExpr 0x7f674f187528 <col:31> 'basic_ostream<char, std::char_traits<char> > &(basic_ostream<char, std::char_traits<char> > &, const char *)' lvalue Function 0x7f674ec96ec0 'operator<<' 'basic_ostream<char, std::char_traits<char> > &(basic_ostream<char, std::char_traits<char> > &, const char *)' | | | | | | | | | | | |-CXXOperatorCallExpr 0x7f674f185fd8 <col:1, col:28> 'std::ostream':'std::basic_ostream<char>' lvalue '<<' adl | | | | | | | | | | | | |-ImplicitCastExpr 0x7f674f185fc0 <col:25> 'std::ostream &(*)(std::ostream &, const RVec<float> &)' <FunctionToPointerDecay> | | | | | | | | | | | | | `-DeclRefExpr 0x7f674f185fa0 <col:25> 'std::ostream &(std::ostream &, const RVec<float> &)' lvalue Function 0x7f674eca1008 'operator<<' 'std::ostream &(std::ostream &, const RVec<float> &)' | | | | | | | | | | | | |-CXXOperatorCallExpr 0x7f674f1837e0 <col:1, col:14> 'basic_ostream<char, std::char_traits<char> >':'std::basic_ostream<char>' lvalue '<<' | | | | | | | | | | | | | |-ImplicitCastExpr 0x7f674f1837c8 <col:11> 'basic_ostream<char, std::char_traits<char> > &(*)(basic_ostream<char, std::char_traits<char> > &, const char *)' <FunctionToPointerDecay> | | | | | | | | | | | | | | `-DeclRefExpr 0x7f674f1837a8 <col:11> 'basic_ostream<char, std::char_traits<char> > &(basic_ostream<char, std::char_traits<char> > &, const char *)' lvalue Function 0x7f674ec96ec0 'operator<<' 'basic_ostream<char, std::char_traits<char> > &(basic_ostream<char, std::char_traits<char> > &, const char *)' | | | | | | | | | | | | | |-DeclRefExpr 0x7f674f181df0 <col:1, col:6> 'std::ostream':'std::basic_ostream<char>' lvalue Var 0x46f20a0 'cout' 'std::ostream':'std::basic_ostream<char>' | | | | | | | | | | | | | `-ImplicitCastExpr 0x7f674f183790 <col:14> 'const char *' <ArrayToPointerDecay> | | | | | | | | | | | | | `-StringLiteral 0x7f674f181e58 <col:14> 'const char [9]' lvalue "Mean of " | | | | | | | | | | | | `-ImplicitCastExpr 0x7f674f185f88 <col:28> 'const RVec<float>':'const ROOT::VecOps::RVec<float>' lvalue <NoOp> | | | | | | | | | | | | `-DeclRefExpr 0x7f674f183818 <col:28> 'ROOT::RVecF':'ROOT::VecOps::RVec<float>' lvalue Var 0xb5bda50 'v1' 'ROOT::RVecF':'ROOT::VecOps::RVec<float>' | | | | | | | | | | | `-ImplicitCastExpr 0x7f674f187510 <col:34> 'const char *' <ArrayToPointerDecay> | | | | | | | | | | | `-StringLiteral 0x7f674f186010 <col:34> 'const char [5]' lvalue " is " | | | | | | | | | | `-DeclRefExpr 0x7f674f187598 <col:44> 'auto' lvalue Var 0x7f674f1807f8 'v1_mean' 'auto' | | | | | | | | | `-StringLiteral 0x7f674f187958 <col:55> 'const char [2]' lvalue "\n" | | | | | | | | `-StringLiteral 0x7f674f187d38 <line:6:14> 'const char [16]' lvalue "Dot product of " | | | | | | | `-DeclRefExpr 0x7f674f1880e0 <col:35> 'ROOT::RVecF':'ROOT::VecOps::RVec<float>' lvalue Var 0xb5bda50 'v1' 'ROOT::RVecF':'ROOT::VecOps::RVec<float>' | | | | | | `-StringLiteral 0x7f674f188480 <col:41> 'const char [6]' lvalue " and " | | | | | `-DeclRefExpr 0x7f674f188820 <col:52> 'ROOT::RVecF':'ROOT::VecOps::RVec<float>' lvalue Var 0xb5ca458 'v2' 'ROOT::RVecF':'ROOT::VecOps::RVec<float>' | | | | `-StringLiteral 0x7f674f188bc0 <col:58> 'const char [5]' lvalue " is " | | | `-DeclRefExpr 0x7f674f188f60 <col:68> 'float':'float' lvalue Var 0x7f674f180b10 'v1_dot_v2' 'float':'float' | | `-UnresolvedLookupExpr 0x7f674f189320 <col:81, col:86> '<overloaded function type>' lvalue (no ADL) = 'endl' 0x449ff58 | `-NullStmt 0x7f674f1896e8 <line:7:1> |-AnnotateAttr 0x7f674f1808d0 <<invalid sloc>> Implicit R"ATTRDUMP(__ResolveAtRuntime)ATTRDUMP" `-AnnotateAttr 0x7f674f1809d0 <<invalid sloc>> Implicit R"ATTRDUMP(__ResolveAtRuntime)ATTRDUMP" <<<NULL>>>
Most used mathematical functions are supported
auto v_exp = exp(v1);
auto v_log = log(v1);
auto v_sin = sin(v1);
std::cout << "exp(" << v1 << ") = " << v_exp << "\n"
<< "log(" << v1 << ") = " << v_log << "\n"
<< "sin(" << v1 << ") = " << v_sin << std::endl;
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 }
Even an optimised version of the functions is available provided that VDT is not disabled during the configuration
#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;
Unbalanced braces. This cell was not processed.
It may happen that a custom operation needs to be applied to the RVec. In this case, the Map utitlity can be used:
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
input_line_58:5:2: error: #endif without #if #endif ^ input_line_58:2:2: error: Syntax error auto v_transf = Map(v1, [](double x) { return x * 2 / 3; }); ^ FunctionDecl 0x7f674fec0f28 <input_line_58:1:1, line:7:1> line:1:6 __cling_Un1Qu326 'void (void *)' |-ParmVarDecl 0x7f674fec0e70 <col:23, col:29> col:29 vpClingValue 'void *' |-CompoundStmt 0x7f674fec7d10 <col:43, line:7:1> | |-DeclStmt 0x7f674fec1d60 <line:2:2, col:61> | | `-VarDecl 0x7f674fec1030 <col:2, col:60> col:7 used v_transf 'auto' cinit | | `-CallExpr 0x7f674fec1d30 <col:18, col:60> '<dependent type>' | | |-DeclRefExpr 0x7f674fec1260 <col:18> '<dependent type>' lvalue Var 0x7f674fec1198 'Map' '<dependent type>' | | |-DeclRefExpr 0x7f674fec12a0 <col:22> 'ROOT::RVecF':'ROOT::VecOps::RVec<float>' lvalue Var 0xb5bda50 'v1' 'ROOT::RVecF':'ROOT::VecOps::RVec<float>' | | `-LambdaExpr 0x7f674fec1bf8 <col:26, col:59> '(lambda at input_line_58:2:26)' | | |-CXXRecordDecl 0x7f674fec13f8 <col:26> col:26 implicit class definition | | | |-DefinitionData lambda pass_in_registers empty standard_layout trivially_copyable literal can_const_default_init | | | | |-DefaultConstructor defaulted_is_constexpr | | | | |-CopyConstructor simple trivial has_const_param needs_implicit implicit_has_const_param | | | | |-MoveConstructor exists simple trivial needs_implicit | | | | |-CopyAssignment trivial has_const_param needs_implicit implicit_has_const_param | | | | |-MoveAssignment | | | | `-Destructor simple irrelevant trivial | | | |-CXXMethodDecl 0x7f674fec1558 <col:37, col:59> col:26 constexpr operator() 'double (double) const' inline | | | | |-ParmVarDecl 0x7f674fec12e0 <col:29, col:36> col:36 used x 'double' | | | | `-CompoundStmt 0x7f674fec1810 <col:39, col:59> | | | | `-ReturnStmt 0x7f674fec1800 <col:41, col:56> | | | | `-BinaryOperator 0x7f674fec16d8 <col:48, col:56> 'double' '/' | | | | |-BinaryOperator 0x7f674fec1680 <col:48, col:52> 'double' '*' | | | | | |-ImplicitCastExpr 0x7f674fec1650 <col:48> 'double' <LValueToRValue> | | | | | | `-DeclRefExpr 0x7f674fec1610 <col:48> 'double' lvalue ParmVar 0x7f674fec12e0 'x' 'double' | | | | | `-ImplicitCastExpr 0x7f674fec1668 <col:52> 'double' <IntegralToFloating> | | | | | `-IntegerLiteral 0x7f674fec1630 <col:52> 'int' 2 | | | | `-ImplicitCastExpr 0x7f674fec16c0 <col:56> 'double' <IntegralToFloating> | | | | `-IntegerLiteral 0x7f674fec16a0 <col:56> 'int' 3 | | | |-CXXConversionDecl 0x7f674fec1a40 <col:26, col:59> col:26 implicit constexpr operator double (*)(double) 'double (*() const noexcept)(double)' inline | | | |-CXXMethodDecl 0x7f674fec1af8 <col:26, col:59> col:26 implicit __invoke 'double (double)' static inline | | | | `-ParmVarDecl 0x7f674fec19d0 <col:29, col:36> col:36 x 'double' | | | `-CXXDestructorDecl 0x7f674fec1c28 <col:26> col:26 implicit referenced ~ 'void () noexcept' inline default trivial | | `-CompoundStmt 0x7f674fec1810 <col:39, col:59> | | `-ReturnStmt 0x7f674fec1800 <col:41, col:56> | | `-BinaryOperator 0x7f674fec16d8 <col:48, col:56> 'double' '/' | | |-BinaryOperator 0x7f674fec1680 <col:48, col:52> 'double' '*' | | | |-ImplicitCastExpr 0x7f674fec1650 <col:48> 'double' <LValueToRValue> | | | | `-DeclRefExpr 0x7f674fec1610 <col:48> 'double' lvalue ParmVar 0x7f674fec12e0 'x' 'double' | | | `-ImplicitCastExpr 0x7f674fec1668 <col:52> 'double' <IntegralToFloating> | | | `-IntegerLiteral 0x7f674fec1630 <col:52> 'int' 2 | | `-ImplicitCastExpr 0x7f674fec16c0 <col:56> 'double' <IntegralToFloating> | | `-IntegerLiteral 0x7f674fec16a0 <col:56> 'int' 3 | |-CXXOperatorCallExpr 0x7f674fec7cd0 <line:4:1, col:98> '<dependent type>' '<<' | | |-UnresolvedLookupExpr 0x7f674fec7988 <col:95> '<overloaded function type>' lvalue (ADL) = 'operator<<' 0x3c18df0 0x4cfa4b8 0x4cf9ee0 0x3c165e0 0x3c16850 0x3c16ac0 0x3c16d30 0x3c16fa0 0x3c17210 0x3c17480 0x3c176f0 0x3c17960 0x3c17bd0 0x3c17e40 0x3c180b0 0x3c18320 0x3c18590 0x3c18830 0x3c1c020 0x3c1e4a0 0x3c25368 0x3c26098 0x3c45e10 0x3c46120 0x3c4f918 0x3c50878 0x3c51a08 0x3c52c28 0x3c53db8 0x3c54f48 0x3c56e10 0x4f89978 0x4f8c788 0x36c3dd0 0x36c42d8 0x3f7aba0 0x3f985a0 0x43b1640 0x444cdc0 0x449c328 0x449c968 0x449cfa8 0x449d5e0 0x449db88 0x449e138 0x44a4e60 0x449edf0 0x449f398 0x449f978 0x44a3b30 0x44e3f48 0x45db320 0x45ee288 0x4687b48 0x46e0438 0x46e4fe8 0x46e5f38 0x46e7368 0x46e8318 0x46e9268 0x46eb008 0x46ebfd8 0x47b9ff8 0x47eafb8 0x47c61a8 0x47c70a0 0x47c7fa0 0x47ca4f0 0x4812df0 0x47cabd0 0x4828640 0x47cbad0 0x47cc9d0 0x47cd8d0 0x47d44b0 0x47f59c8 0x47f7f80 0x47fa588 0x48096f0 0x480c270 0x480f900 0x481c760 0x481f220 0x4823390 0x4825c80 0x4835670 0x483a230 0x483ed20 0x4b979f8 0x49a4650 0x49a51f0 0x49a5bb0 0x49a6570 0x49a6f90 0x4a44ae8 0x4a45488 0x4a45df8 | | |-CXXOperatorCallExpr 0x7f674fec7930 <col:1, col:86> '<dependent type>' '<<' | | | |-UnresolvedLookupExpr 0x7f674fec75e8 <col:83> '<overloaded function type>' lvalue (ADL) = 'operator<<' 0x3c18df0 0x4cfa4b8 0x4cf9ee0 0x3c165e0 0x3c16850 0x3c16ac0 0x3c16d30 0x3c16fa0 0x3c17210 0x3c17480 0x3c176f0 0x3c17960 0x3c17bd0 0x3c17e40 0x3c180b0 0x3c18320 0x3c18590 0x3c18830 0x3c1c020 0x3c1e4a0 0x3c25368 0x3c26098 0x3c45e10 0x3c46120 0x3c4f918 0x3c50878 0x3c51a08 0x3c52c28 0x3c53db8 0x3c54f48 0x3c56e10 0x4f89978 0x4f8c788 0x36c3dd0 0x36c42d8 0x3f7aba0 0x3f985a0 0x43b1640 0x444cdc0 0x449c328 0x449c968 0x449cfa8 0x449d5e0 0x449db88 0x449e138 0x44a4e60 0x449edf0 0x449f398 0x449f978 0x44a3b30 0x44e3f48 0x45db320 0x45ee288 0x4687b48 0x46e0438 0x46e4fe8 0x46e5f38 0x46e7368 0x46e8318 0x46e9268 0x46eb008 0x46ebfd8 0x47b9ff8 0x47eafb8 0x47c61a8 0x47c70a0 0x47c7fa0 0x47ca4f0 0x4812df0 0x47cabd0 0x4828640 0x47cbad0 0x47cc9d0 0x47cd8d0 0x47d44b0 0x47f59c8 0x47f7f80 0x47fa588 0x48096f0 0x480c270 0x480f900 0x481c760 0x481f220 0x4823390 0x4825c80 0x4835670 0x483a230 0x483ed20 0x4b979f8 0x49a4650 0x49a51f0 0x49a5bb0 0x49a6570 0x49a6f90 0x4a44ae8 0x4a45488 0x4a45df8 | | | |-CXXOperatorCallExpr 0x7f674fec7570 <col:1, col:70> 'basic_ostream<char, std::char_traits<char> >':'std::basic_ostream<char>' lvalue '<<' | | | | |-ImplicitCastExpr 0x7f674fec7558 <col:67> 'basic_ostream<char, std::char_traits<char> > &(*)(basic_ostream<char, std::char_traits<char> > &, const char *)' <FunctionToPointerDecay> | | | | | `-DeclRefExpr 0x7f674fec7538 <col:67> 'basic_ostream<char, std::char_traits<char> > &(basic_ostream<char, std::char_traits<char> > &, const char *)' lvalue Function 0x7f674ec96ec0 'operator<<' 'basic_ostream<char, std::char_traits<char> > &(basic_ostream<char, std::char_traits<char> > &, const char *)' | | | | |-CXXOperatorCallExpr 0x7f674fec5fe8 <col:1, col:64> 'std::ostream':'std::basic_ostream<char>' lvalue '<<' adl | | | | | |-ImplicitCastExpr 0x7f674fec5fd0 <col:61> 'std::ostream &(*)(std::ostream &, const RVec<float> &)' <FunctionToPointerDecay> | | | | | | `-DeclRefExpr 0x7f674fec5fb0 <col:61> 'std::ostream &(std::ostream &, const RVec<float> &)' lvalue Function 0x7f674eca1008 'operator<<' 'std::ostream &(std::ostream &, const RVec<float> &)' | | | | | |-CXXOperatorCallExpr 0x7f674fec37f0 <col:1, col:14> 'basic_ostream<char, std::char_traits<char> >':'std::basic_ostream<char>' lvalue '<<' | | | | | | |-ImplicitCastExpr 0x7f674fec37d8 <col:11> 'basic_ostream<char, std::char_traits<char> > &(*)(basic_ostream<char, std::char_traits<char> > &, const char *)' <FunctionToPointerDecay> | | | | | | | `-DeclRefExpr 0x7f674fec37b8 <col:11> 'basic_ostream<char, std::char_traits<char> > &(basic_ostream<char, std::char_traits<char> > &, const char *)' lvalue Function 0x7f674ec96ec0 'operator<<' 'basic_ostream<char, std::char_traits<char> > &(basic_ostream<char, std::char_traits<char> > &, const char *)' | | | | | | |-DeclRefExpr 0x7f674fec1dc8 <col:1, col:6> 'std::ostream':'std::basic_ostream<char>' lvalue Var 0x46f20a0 'cout' 'std::ostream':'std::basic_ostream<char>' | | | | | | `-ImplicitCastExpr 0x7f674fec37a0 <col:14> 'const char *' <ArrayToPointerDecay> | | | | | | `-StringLiteral 0x7f674fec1e38 <col:14> 'const char [45]' lvalue "Applying [](double x){return x * 2 / 3;} to " | | | | | `-ImplicitCastExpr 0x7f674fec5f98 <col:64> 'const RVec<float>':'const ROOT::VecOps::RVec<float>' lvalue <NoOp> | | | | | `-DeclRefExpr 0x7f674fec3828 <col:64> 'ROOT::RVecF':'ROOT::VecOps::RVec<float>' lvalue Var 0xb5bda50 'v1' 'ROOT::RVecF':'ROOT::VecOps::RVec<float>' | | | | `-ImplicitCastExpr 0x7f674fec7520 <col:70> 'const char *' <ArrayToPointerDecay> | | | | `-StringLiteral 0x7f674fec6020 <col:70> 'const char [11]' lvalue " leads to " | | | `-DeclRefExpr 0x7f674fec75a8 <col:86> 'auto' lvalue Var 0x7f674fec1030 'v_transf' 'auto' | | `-StringLiteral 0x7f674fec7968 <col:98> 'const char [2]' lvalue "\n" | `-NullStmt 0x7f674fec7d08 <line:6:1> |-AnnotateAttr 0x7f674fec1108 <<invalid sloc>> Implicit R"ATTRDUMP(__ResolveAtRuntime)ATTRDUMP" `-AnnotateAttr 0x7f674fec1200 <<invalid sloc>> Implicit R"ATTRDUMP(__ResolveAtRuntime)ATTRDUMP" <<<NULL>>>