51#ifndef GUM_PROJECTION_PATTERN_ALLOWED
62# ifdef GUM_MULTI_DIM_PROJECTION_NAME
63# define GUM_MULTI_DIM_PROJECTION_TYPE GUM_SCALAR
65 template <
typename GUM_SCALAR >
73#ifdef GUM_MULTI_DIM_PROJECTION_POINTER_NAME
74#define GUM_MULTI_DIM_PROJECTION_TYPE GUM_SCALAR *
75#define GUM_MULTI_DIM_PROJECTION_POINTER
76 template <
typename GUM_SCALAR>
82#ifdef GUM_MULTI_DIM_PROJECTION_NAME_F
83#define GUM_MULTI_DIM_PROJECTION_TYPE GUM_SCALAR
84 template <
typename GUM_SCALAR>
88 GUM_SCALAR ( *f )(
const GUM_SCALAR&,
const GUM_SCALAR& ) )
91#ifdef GUM_MULTI_DIM_PROJECTION_POINTER_NAME_F
92#define GUM_MULTI_DIM_PROJECTION_TYPE GUM_SCALAR *
93#define GUM_MULTI_DIM_PROJECTION_POINTER
94 template <
typename GUM_SCALAR>
98 GUM_SCALAR* ( *f )(
const GUM_SCALAR
const*,
99 const GUM_SCALAR
const* ) )
102#ifdef GUM_MULTI_DIM_PROJECTION_IMPL2ARRAY_NAME
103#define GUM_MULTI_DIM_PROJECTION_TYPE GUM_SCALAR
104 template <
typename GUM_SCALAR>
106 GUM_MULTI_DIM_PROJECTION_IMPL2ARRAY_NAME(
111#ifdef GUM_MULTI_DIM_PROJECTION_POINTER_IMPL2ARRAY_NAME
112#define GUM_MULTI_DIM_PROJECTION_TYPE GUM_SCALAR *
113#define GUM_MULTI_DIM_PROJECTION_POINTER
114 template <
typename GUM_SCALAR>
116 GUM_MULTI_DIM_PROJECTION_POINTER_IMPL2ARRAY_NAME(
125# ifdef GUM_MULTI_DIM_PROJECTION_IMPL2ARRAY_NAME
130# ifdef GUM_MULTI_DIM_PROJECTION_POINTER_IMPL2ARRAY_NAME
137 const GUM_SCALAR neutral_element = GUM_MULTI_DIM_PROJECTION_NEUTRAL;
142 bool need_swapping = table_vars.
size() >= 2 * del_vars.size();
144 if (!need_swapping) {
154 std::vector< Idx > table_and_result_offset;
155 std::vector< Idx > table_and_result_domain;
156 std::vector< Idx > before_incr;
157 unsigned int nb_positive_before_incr = 0;
158 Idx table_alone_domain_size = 1;
159 Idx result_domain_size = 1;
160 Idx table_domain_size = 1;
163 Idx tmp_before_incr = 1;
164 bool has_before_incr =
false;
166 for (
const auto var: table_vars) {
167 table_domain_size *= var->domainSize();
169 if (!del_vars.exists(var)) {
170 if (has_before_incr) {
171 before_incr.push_back(tmp_before_incr - 1);
172 has_before_incr =
false;
173 ++nb_positive_before_incr;
175 before_incr.push_back(0);
178 table_and_result_domain.push_back(var->domainSize());
179 table_and_result_offset.push_back(result_domain_size);
180 result_domain_size *= var->domainSize();
182 result_varSeq << var;
184 tmp_before_incr *= var->domainSize();
185 has_before_incr =
true;
186 table_alone_domain_size *= var->domainSize();
190 std::vector< Idx > table_and_result_value = table_and_result_domain;
191 std::vector< Idx > current_incr = before_incr;
192 std::vector< Idx > table_and_result_down = table_and_result_offset;
194 for (
unsigned int i = 0; i < table_and_result_down.size(); ++i) {
195 table_and_result_down[i] *= (table_and_result_domain[i] - 1);
205 if (!result_varSeq.size()) {
return result; }
209 for (
const auto var: result_varSeq)
213# ifdef GUM_MULTI_DIM_PROJECTION_POINTER
214 result->endMultipleChanges();
216 for (
Idx i = 0; i < result_domain_size; ++i) {
217 result->unsafeSet(i,
new GUM_SCALAR(neutral_element));
221 result->endMultipleChanges(neutral_element);
236 GUM_MULTI_DIM_PROJECTION_TYPE* pt
237 =
const_cast< GUM_MULTI_DIM_PROJECTION_TYPE*
>(&(table->unsafeGet(0)));
238 GUM_MULTI_DIM_PROJECTION_TYPE* pres
239 =
const_cast< GUM_MULTI_DIM_PROJECTION_TYPE*
>(&(result->unsafeGet(0)));
240 GUM_MULTI_DIM_PROJECTION_TYPE* pres_deb = pres;
242 if (!nb_positive_before_incr) {
243 for (
Idx i = 0; i < table_alone_domain_size; ++i) {
244 for (
Idx j = 0; j < result_domain_size; ++j) {
245# ifdef GUM_MULTI_DIM_PROJECTION_EFFECTIVE_TYPE
246 GUM_MULTI_DIM_PROJECTION(*pres, *pt);
248# ifdef GUM_MULTI_DIM_PROJECTION_POINTER
249 **pres = GUM_MULTI_DIM_PROJECTION(*pres, *pt);
251 *pres = GUM_MULTI_DIM_PROJECTION(*pres, *pt);
266 Idx result_offset = 0;
268 for (
Idx i = 0; i < table_domain_size; ++i) {
269# ifdef GUM_MULTI_DIM_PROJECTION_EFFECTIVE_TYPE
270 GUM_MULTI_DIM_PROJECTION(pres[result_offset], *pt);
272# ifdef GUM_MULTI_DIM_PROJECTION_POINTER
273 *(pres[result_offset]) = GUM_MULTI_DIM_PROJECTION(pres[result_offset], *pt);
275 pres[result_offset] = GUM_MULTI_DIM_PROJECTION(pres[result_offset], *pt);
283 for (
unsigned int k = 0; k < current_incr.size(); ++k) {
285 if (current_incr[k]) {
290 current_incr[k] = before_incr[k];
293 --table_and_result_value[k];
295 if (table_and_result_value[k]) {
296 result_offset += table_and_result_offset[k];
300 table_and_result_value[k] = table_and_result_domain[k];
301 result_offset -= table_and_result_down[k];
318 std::vector< Idx > table_alone_offset;
319 std::vector< Idx > table_alone_domain;
321 Idx table_alone_domain_size = 1;
324 for (
const auto var: table_vars) {
325 if (del_vars.exists(var)) {
326 table_alone_domain.push_back(var->domainSize());
327 table_alone_offset.push_back(offset);
328 table_alone_domain_size *= var->domainSize();
331 var1offset.insert(var, offset);
332 offset *= var->domainSize();
335 std::vector< Idx > table_alone_value = table_alone_domain;
336 std::vector< Idx > table_alone_down = table_alone_offset;
338 for (
unsigned int i = 0; i < table_alone_down.size(); ++i)
339 table_alone_down[i] *= (table_alone_domain[i] - 1);
351 std::vector< Idx > table_and_result_offset;
352 std::vector< Idx > table_and_result_domain;
353 Idx result_domain_size = 1;
354 bool has_before_incr =
false;
355 bool found_proj_var =
false;
357 for (
const auto var: table_vars) {
358 if (!del_vars.exists(var)) {
359 table_and_result_domain.push_back(var->domainSize());
360 table_and_result_offset.push_back(var1offset[var]);
361 found_proj_var =
true;
362 result_domain_size *= var->domainSize();
363 result_varSeq << var;
365 if (found_proj_var) has_before_incr =
true;
369 std::vector< Idx > table_and_result_value = table_and_result_domain;
370 std::vector< Idx > table_and_result_down = table_and_result_offset;
372 for (
unsigned int i = 0; i < table_and_result_down.size(); ++i) {
373 table_and_result_down[i] *= (table_and_result_domain[i] - 1);
384 for (
const auto var: result_varSeq)
387# ifdef GUM_MULTI_DIM_PROJECTION_POINTER
388 result->endMultipleChanges();
391 for (
Idx i = 0; i < result_domain_size; ++i) {
392 result->unsafeSet(i,
new GUM_SCALAR(neutral_element));
396 result->endMultipleChanges(neutral_element);
411 GUM_MULTI_DIM_PROJECTION_TYPE* pt
412 =
const_cast< GUM_MULTI_DIM_PROJECTION_TYPE*
>(&(table->unsafeGet(0)));
413 GUM_MULTI_DIM_PROJECTION_TYPE* pres
414 =
const_cast< GUM_MULTI_DIM_PROJECTION_TYPE*
>(&(result->unsafeGet(0)));
418 if (!has_before_incr) {
419 for (
Idx i = 0; i < result_domain_size; ++i) {
420 for (
Idx j = 0; j < table_alone_domain_size; ++j) {
421# ifdef GUM_MULTI_DIM_PROJECTION_EFFECTIVE_TYPE
422 GUM_MULTI_DIM_PROJECTION(*pres, *pt);
424# ifdef GUM_MULTI_DIM_PROJECTION_POINTER
425 **pres = GUM_MULTI_DIM_PROJECTION(*pres, *pt);
427 *pres = GUM_MULTI_DIM_PROJECTION(*pres, *pt);
441 Idx table_offset = 0;
443 for (
Idx j = 0; j < result_domain_size; ++j) {
444 for (
Idx i = 0; i < table_alone_domain_size; ++i) {
445# ifdef GUM_MULTI_DIM_PROJECTION_EFFECTIVE_TYPE
446 GUM_MULTI_DIM_PROJECTION(*pres, pt[table_offset]);
448# ifdef GUM_MULTI_DIM_PROJECTION_POINTER
449 **pres = GUM_MULTI_DIM_PROJECTION(*pres, pt[table_offset]);
451 *pres = GUM_MULTI_DIM_PROJECTION(*pres, pt[table_offset]);
456 for (
unsigned int k = 0; k < table_alone_value.size(); ++k) {
457 --table_alone_value[k];
459 if (table_alone_value[k]) {
460 table_offset += table_alone_offset[k];
464 table_alone_value[k] = table_alone_domain[k];
465 table_offset -= table_alone_down[k];
470 for (
unsigned int k = 0; k < table_and_result_value.size(); ++k) {
471 --table_and_result_value[k];
473 if (table_and_result_value[k]) {
474 table_offset += table_and_result_offset[k];
478 table_and_result_value[k] = table_and_result_domain[k];
479 table_offset -= table_and_result_down[k];
492# undef GUM_MULTI_DIM_PROJECTION_TYPE
494# ifdef GUM_MULTI_DIM_PROJECTION_POINTER
495# undef GUM_MULTI_DIM_PROJECTION_POINTER
The class for generic Hash Tables.
Multidimensional matrix stored as an array in memory.
<agrum/base/multidim/multiDimImplementation.h>
void beginMultipleChanges() override
Call this method before doing important changes in this MultiDimContainer.
Size size() const noexcept
Returns the size of the sequence.
The generic class for storing (ordered) sequences of objects.
Size Idx
Type for indexes.
gum is the global namespace for all aGrUM entities
Set< const DiscreteVariable * > VariableSet