In this tutorial we learn how combinations of RVecs can be build.
{
RVec<double> v1{1., 2., 3.};
RVec<double> v2{-4., -5.};
std::cout << "Combinations of " << v1 << " and " << v2 << ":" << std::endl;
for(size_t i=0; i<v3.size(); i++) {
std::cout <<
c1[i] <<
" * " <<
c2[i] <<
" = " << v3[i] << std::endl;
}
std::cout << std::endl;
RVec<double> v4{1., 2., 3., 4.};
auto c4 =
Take(v4, idx2[1]);
auto c5 =
Take(v4, idx2[2]);
std::cout << "Unique triples of " << v4 << ":" << std::endl;
for(size_t i=0; i<v4.size(); i++) {
std::cout <<
c3[i] <<
" * " << c4[i] <<
" * " << c5[i] <<
" = " << v5[i] << std::endl;
}
std::cout << std::endl;
}
RVec< T > Take(const RVec< T > &v, const RVec< typename RVec< T >::size_type > &i)
Return elements of a vector at given indices.
RVec< RVec< std::size_t > > Combinations(const std::size_t size1, const std::size_t size2)
Return the indices that represent all combinations of the elements of two RVecs.
Combinations of { 1, 2, 3 } and { -4, -5 }:
1 * -4 = -4
1 * -5 = -5
2 * -4 = -8
2 * -5 = -10
3 * -4 = -12
3 * -5 = -15
Unique triples of { 1, 2, 3, 4 }:
1 * 2 * 3 = 6
1 * 2 * 4 = 8
1 * 3 * 4 = 12
2 * 3 * 4 = 24
- Date
- August 2018
- Author
- Stefan Wunsch
Definition in file vo005_Combinations.C.