Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
PermutationWithRepetition.h
Go to the documentation of this file.
1/* This file is part of MoDELib, the Mechanics Of Defects Evolution Library.
2 *
3 *
4 * MoDELib is distributed without any warranty under the
5 * GNU General Public License (GPL) v2 <http://www.gnu.org/licenses/>.
6 */
7
8#ifndef model_PERMUTATIONWITHREPETITION_H_
9#define model_PERMUTATIONWITHREPETITION_H_
10
11#include <Eigen/Dense>
12#include <CTM.h>
13
14namespace model
15{
16 template <int _k>
18 {
19 /* The permutation P (n, k) =n Pk is the number of ways to form ordered sets of k objects taken from a pool of n objects if repetition is allowed. */
20
21 /* This should be computed as N^K rows of K columns */
22
23 static constexpr int k=_k;
24// static_assert(N>0,"N MUST BE >0.");
25 static_assert(k>0,"k MUST BE >0.");
26
27
28 template<typename T,int N>
29 static Eigen::Matrix<T,k,CTM::pow(N,k)> permute(const Eigen::Matrix<T,1,N>& pool)
30 {
31
32 Eigen::Matrix<T,k-1,CTM::pow(N,k-1)> temp=PermutationWithRepetition<k-1>::permute(pool);
33 Eigen::Matrix<T,k,CTM::pow(N,k)> temp1;
34 for(size_t p=0;p<N;++p)
35 {
36 temp1.template block< 1,CTM::pow(N,k-1)>(0,p*CTM::pow(N,k-1))=Eigen::Matrix<T,1,CTM::pow(N,k-1)>::Constant(pool(p));
37 temp1.template block<k-1,CTM::pow(N,k-1)>(1,p*CTM::pow(N,k-1))=temp;
38 }
39
40 return temp1;
41 }
42 };
43
44 template <>
46 {
47 /* The permutation P (n, k) =n Pk is the number of ways to form ordered sets of k objects taken from a pool of n objects if repetition is allowed. */
48
49 /* This should be computed as N^K rows of K columns */
50
51 static constexpr int k=1;
52
53
54 template<typename T,int N>
55 static const Eigen::Matrix<T,k,CTM::pow(N,k)>& permute(const Eigen::Matrix<T,1,N>& pool)
56 {
57 return pool;
58 }
59 };
60
61}
62#endif
static constexpr int pow(int x, int n)
A compile-time implementation of the power function.
Definition CTM.h:40
static const Eigen::Matrix< T, k, CTM::pow(N, k)> & permute(const Eigen::Matrix< T, 1, N > &pool)
static Eigen::Matrix< T, k, CTM::pow(N, k)> permute(const Eigen::Matrix< T, 1, N > &pool)
vertex p[3]
vertex temp
INEXACT REAL _k