19#if __has_include(<omp.h>)
21__host__ __device__
static inline int get_max_threads() {
25 return omp_get_max_threads();
28__host__ __device__
static inline int get_thread_num() {
32 return omp_get_thread_num();
36constexpr static inline int get_max_threads() {
return 1; }
37constexpr static inline int get_thread_num() {
return 0; }
42 template<
class U,
void* dummy = (&U::operator[], &U::resize,
nullptr)>
43 static std::true_type
test(U*);
44 static std::false_type
test(...);
84 debug_constructor_printf((Copy));
87 __host__ __device__
int value()
const {
return m_N; };
89 __host__ __device__
int max()
const {
return m_Max; };
100 std::cout <<
"IntegerComposition.status()"
102 <<
"\tValue:" << this->m_N <<
"\n"
103 <<
"\tLength:" << this->m_Length <<
"\n"
104 <<
"\tMax: " << this->m_Max <<
"\n"
105 <<
"\tDim: " << this->m_dim << std::endl;
106 std::cout <<
"workA:\n"
109 <<
workB << std::endl;
121 template<
typename Vector_t>
133 template<
class Vector_t>
137 Eigen::RowVectorXi res(this->m_Length);
142 template<
typename Index_>
143 __host__ __device__
int locNumber(Index_
const num, Index_
const pos)
const;
145 template<
class Vector_t>
147 Vector_t& workSpace)
const;
151 return this->
translate(num, trans, config);
158 m_Max(Max < N ? Max : N),
159 workA(N + 1, Length),
160 workB(N + 1, Length) {
168 int max = std::min(Max, N);
170 for(
int l = 0; l < Length; ++l) Dims(0, l) = 1;
171 for(
int n = N; n >
max; --n) {
176 for(
int n =
max; n >= 0; --n) {
182 for(
int l = 2; l < Length; ++l)
183 for(
int n = 1; n <= N; ++n) {
185 for(
int k = 0; k <= std::min(
max, n); ++k) { Dims(n, l) += Dims(n - k, l - 1); }
189 for(
int l = 1; l < Length; ++l) {
190 workA(0, l) = Dims(N, Length - l);
191 for(
int n = 1; n <= N; ++n)
workA(n, l) =
workA(n - 1, l) + Dims(N - n, Length - l);
195 for(
int l = 0; l < Length; ++l)
workB(0, l) = 0;
196 for(
int n = 1; n <= N; ++n) {
197 for(
int l = 1; l < Length - 1; ++l)
workB(n, l) =
workA(n - 1, l) -
workA(n - 1, l + 1);
198 workB(n, Length - 1) =
workA(n - 1, Length - 1);
204 debug_printf(
"(END) IntegerComposition::IntegerComposition(%d,%d,%d) : Dim = %d\n", (
int)N,
205 (
int)Length, (
int)Max, (
int)
m_dim);
208template<
typename Vector_t>
210 Vector_t
const& vec)
const {
212 for(
int l = 1; l != int(
m_Length); ++l) {
217 assert(z <
workB.rows());
218 assert(l <
workB.cols());
224template<
typename Vector_t>
228 int z = 0, zprev = 0;
235 for(
int l = 1; l !=
m_Length; ++l) {
236 assert(z <
workA.rows());
237 assert(l <
workA.cols());
238 while(
workA(z, l) <= num_copy) z += 1;
245 assert(z <
workB.rows());
246 assert(l <
workB.cols());
247 num_copy -=
workB(z, l);
252template<
typename Index_>
254 Index_
const pos)
const {
261 int z = 0, zprev = 0;
263 for(l = 1; l !=
m_Length - position; ++l) {
264 assert(z <
workA.rows());
265 assert(l <
workA.cols());
266 while(
workA(z, l) <= num_copy) z += 1;
269 assert(z <
workB.rows());
270 assert(l <
workB.cols());
271 num_copy -=
workB(z, l);
273 assert(z <
workA.rows());
274 assert(l <
workA.cols());
275 if(pos == 0) {
return m_N - z; }
277 while(
workA(z, l) <= num_copy) z += 1;
282template<
class Vector_t>
286 debug_printf(
"%s\n\tworkSpace.size()=%d\n", __PRETTY_FUNCTION__, (
int)workSpace.size());
287 assert(workSpace.size() >=
m_Length);
292 for(
int l = 0; l < int(
m_Length); ++l) {
297 assert(z <
workB.rows());
298 assert(l <
workB.cols());
301 assert(
int(
m_Length - 1 - l + trans) % workSpace.size() < workSpace.size());
302 z += workSpace[int(
m_Length - 1 - l + trans) % workSpace.size()];
constexpr bool is_container_v
Definition IntegerComposition.hpp:50
Lists a weak composition of an integer N up to length L with a constraint that each summand does not ...
Definition IntegerComposition.hpp:57
__host__ __device__ IntegerComposition()
Construct a new Integer Composition object.
Definition IntegerComposition.hpp:75
__host__ __device__ int locNumber(Index_ const num, Index_ const pos) const
Definition IntegerComposition.hpp:253
__host__ __device__ Index_t translate(Index_t const num, int trans) const
Definition IntegerComposition.hpp:149
int m_Length
Definition IntegerComposition.hpp:61
__host__ void status(void) const
Show the status of the instance.
Definition IntegerComposition.hpp:99
__host__ __device__ IntegerComposition(IntegerComposition const &other)
Definition IntegerComposition.hpp:77
__host__ __device__ Eigen::RowVectorXi ordinalToPart(Index_t const num) const
Definition IntegerComposition.hpp:136
int m_N
Definition IntegerComposition.hpp:60
__host__ __device__ Index_t dim() const
Definition IntegerComposition.hpp:90
Eigen::MatrixX< Index_t > workB
Definition IntegerComposition.hpp:65
unsigned long Index_t
Definition IntegerComposition.hpp:59
__host__ __device__ int max() const
Definition IntegerComposition.hpp:89
__host__ __device__ void ordinalToPart(Vector_t &vec, Index_t const num) const
Converts an ordinal number of a composition of the integer N to a vector form.
Definition IntegerComposition.hpp:225
__host__ __device__ int value() const
Definition IntegerComposition.hpp:87
int m_Max
Definition IntegerComposition.hpp:62
__host__ __device__ Index_t translate(Index_t const num, int trans, Vector_t &workSpace) const
Definition IntegerComposition.hpp:283
__host__ __device__ int length() const
Definition IntegerComposition.hpp:88
__host__ __device__ Index_t partToOrdinal(Vector_t const &vec) const
Converts an composition of the integer N from a vector form to an ordinal number.
Definition IntegerComposition.hpp:209
Eigen::MatrixX< Index_t > workA
Definition IntegerComposition.hpp:64
Index_t m_dim
Definition IntegerComposition.hpp:63
Definition IntegerComposition.hpp:41
static std::false_type test(...)
static std::true_type test(U *)
static constexpr bool value
Definition IntegerComposition.hpp:47