File: stack_container.cpp

package info (click to toggle)
dynare 4.5.7-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 49,408 kB
  • sloc: cpp: 84,998; ansic: 29,058; pascal: 13,843; sh: 4,833; objc: 4,236; yacc: 3,622; makefile: 2,278; lex: 1,541; python: 236; lisp: 69; xml: 8
file content (570 lines) | stat: -rw-r--r-- 13,064 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
/*1:*/
#line 6 "./stack_container.cweb"

#include "stack_container.h"
#include "pyramid_prod2.h"
#include "ps_tensor.h"

double FoldedStackContainer::fill_threshold= 0.00005;
double UnfoldedStackContainer::fill_threshold= 0.00005;
/*2:*/
#line 59 "./stack_container.cweb"

void FoldedStackContainer::multAndAdd(const FSSparseTensor&t,
FGSTensor&out)const
{
TL_RAISE_IF(t.nvar()!=getAllSize(),
"Wrong number of variables of tensor for FoldedStackContainer::multAndAdd");
multAndAddSparse2(t,out);
}

/*:2*/
#line 13 "./stack_container.cweb"
;
/*3:*/
#line 73 "./stack_container.cweb"

void FoldedStackContainer::multAndAdd(int dim,const FGSContainer&c,FGSTensor&out)const
{
TL_RAISE_IF(c.num()!=numStacks(),
"Wrong symmetry length of container for FoldedStackContainer::multAndAdd");

THREAD_GROUP gr;
SymmetrySet ss(dim,c.num());
for(symiterator si(ss);!si.isEnd();++si){
if(c.check(*si)){
THREAD*worker= new WorkerFoldMAADense(*this,*si,c,out);
gr.insert(worker);
}
}
gr.run();
}

/*:3*/
#line 14 "./stack_container.cweb"
;
/*4:*/
#line 93 "./stack_container.cweb"

void WorkerFoldMAADense::operator()()
{
Permutation iden(dense_cont.num());
IntSequence coor(sym,iden.getMap());
const FGSTensor*g= dense_cont.get(sym);
cont.multAndAddStacks(coor,*g,out,&out);
}

/*:4*/
#line 15 "./stack_container.cweb"
;
/*5:*/
#line 103 "./stack_container.cweb"

WorkerFoldMAADense::WorkerFoldMAADense(const FoldedStackContainer&container,
const Symmetry&s,
const FGSContainer&dcontainer,
FGSTensor&outten)
:cont(container),sym(s),dense_cont(dcontainer),out(outten)
{}

/*:5*/
#line 16 "./stack_container.cweb"
;
/*6:*/
#line 113 "./stack_container.cweb"

void FoldedStackContainer::multAndAddSparse1(const FSSparseTensor&t,
FGSTensor&out)const
{
THREAD_GROUP gr;
UFSTensor dummy(0,numStacks(),t.dimen());
for(Tensor::index ui= dummy.begin();ui!=dummy.end();++ui){
THREAD*worker= new WorkerFoldMAASparse1(*this,t,out,ui.getCoor());
gr.insert(worker);
}
gr.run();
}

/*:6*/
#line 17 "./stack_container.cweb"
;
/*7:*/
#line 135 "./stack_container.cweb"

void WorkerFoldMAASparse1::operator()()
{
const EquivalenceSet&eset= ebundle.get(out.dimen());
const PermutationSet&pset= tls.pbundle->get(t.dimen());
Permutation iden(t.dimen());

UPSTensor slice(t,cont.getStackSizes(),coor,
PerTensorDimens(cont.getStackSizes(),coor));
for(int iper= 0;iper<pset.getNum();iper++){
const Permutation&per= pset.get(iper);
IntSequence percoor(coor.size());
per.apply(coor,percoor);
for(EquivalenceSet::const_iterator it= eset.begin();
it!=eset.end();++it){
if((*it).numClasses()==t.dimen()){
StackProduct<FGSTensor> sp(cont,*it,out.getSym());
if(!sp.isZero(percoor)){
KronProdStack<FGSTensor> kp(sp,percoor);
kp.optimizeOrder();
const Permutation&oper= kp.getPer();
if(Permutation(oper,per)==iden){
FPSTensor fps(out.getDims(),*it,slice,kp);
{
SYNCHRO syn(&out,"WorkerUnfoldMAASparse1");
fps.addTo(out);
}
}
}
}
}
}
}

/*:7*/
#line 18 "./stack_container.cweb"
;
/*8:*/
#line 170 "./stack_container.cweb"

WorkerFoldMAASparse1::WorkerFoldMAASparse1(const FoldedStackContainer&container,
const FSSparseTensor&ten,
FGSTensor&outten,const IntSequence&c)
:cont(container),t(ten),out(outten),coor(c),ebundle(*(tls.ebundle)){}


/*:8*/
#line 19 "./stack_container.cweb"
;
/*9:*/
#line 183 "./stack_container.cweb"

void FoldedStackContainer::multAndAddSparse2(const FSSparseTensor&t,
FGSTensor&out)const
{
THREAD_GROUP gr;
FFSTensor dummy_f(0,numStacks(),t.dimen());
for(Tensor::index fi= dummy_f.begin();fi!=dummy_f.end();++fi){
THREAD*worker= new WorkerFoldMAASparse2(*this,t,out,fi.getCoor());
gr.insert(worker);
}
gr.run();
}

/*:9*/
#line 20 "./stack_container.cweb"
;
/*10:*/
#line 207 "./stack_container.cweb"

void WorkerFoldMAASparse2::operator()()
{
GSSparseTensor slice(t,cont.getStackSizes(),coor,
TensorDimens(cont.getStackSizes(),coor));
if(slice.getNumNonZero()){
if(slice.getUnfoldIndexFillFactor()> FoldedStackContainer::fill_threshold){
FGSTensor dense_slice(slice);
int r1= slice.getFirstNonZeroRow();
int r2= slice.getLastNonZeroRow();
FGSTensor dense_slice1(r1,r2-r1+1,dense_slice);
FGSTensor out1(r1,r2-r1+1,out);
cont.multAndAddStacks(coor,dense_slice1,out1,&out);
}else
cont.multAndAddStacks(coor,slice,out,&out);
}
}

/*:10*/
#line 21 "./stack_container.cweb"
;
/*11:*/
#line 226 "./stack_container.cweb"

WorkerFoldMAASparse2::WorkerFoldMAASparse2(const FoldedStackContainer&container,
const FSSparseTensor&ten,
FGSTensor&outten,const IntSequence&c)
:cont(container),t(ten),out(outten),coor(c)
{}


/*:11*/
#line 22 "./stack_container.cweb"
;
/*12:*/
#line 248 "./stack_container.cweb"

void FoldedStackContainer::multAndAddSparse3(const FSSparseTensor&t,
FGSTensor&out)const
{
const EquivalenceSet&eset= ebundle.get(out.dimen());
for(Tensor::index run= out.begin();run!=out.end();++run){
Vector outcol(out,*run);
FRSingleTensor sumcol(t.nvar(),t.dimen());
sumcol.zeros();
for(EquivalenceSet::const_iterator it= eset.begin();
it!=eset.end();++it){
if((*it).numClasses()==t.dimen()){
StackProduct<FGSTensor> sp(*this,*it,out.getSym());
IrregTensorHeader header(sp,run.getCoor());
IrregTensor irten(header);
irten.addTo(sumcol);
}
}
t.multColumnAndAdd(sumcol,outcol);
}
}

/*:12*/
#line 23 "./stack_container.cweb"
;
/*13:*/
#line 278 "./stack_container.cweb"

void FoldedStackContainer::multAndAddSparse4(const FSSparseTensor&t,FGSTensor&out)const
{
THREAD_GROUP gr;
FFSTensor dummy_f(0,numStacks(),t.dimen());
for(Tensor::index fi= dummy_f.begin();fi!=dummy_f.end();++fi){
THREAD*worker= new WorkerFoldMAASparse4(*this,t,out,fi.getCoor());
gr.insert(worker);
}
gr.run();
}

/*:13*/
#line 24 "./stack_container.cweb"
;
/*14:*/
#line 294 "./stack_container.cweb"

void WorkerFoldMAASparse4::operator()()
{
GSSparseTensor slice(t,cont.getStackSizes(),coor,
TensorDimens(cont.getStackSizes(),coor));
if(slice.getNumNonZero())
cont.multAndAddStacks(coor,slice,out,&out);
}

/*:14*/
#line 25 "./stack_container.cweb"
;
/*15:*/
#line 304 "./stack_container.cweb"

WorkerFoldMAASparse4::WorkerFoldMAASparse4(const FoldedStackContainer&container,
const FSSparseTensor&ten,
FGSTensor&outten,const IntSequence&c)
:cont(container),t(ten),out(outten),coor(c)
{}


/*:15*/
#line 26 "./stack_container.cweb"
;
/*16:*/
#line 321 "./stack_container.cweb"

void FoldedStackContainer::multAndAddStacks(const IntSequence&coor,
const FGSTensor&g,
FGSTensor&out,const void*ad)const
{
const EquivalenceSet&eset= ebundle.get(out.dimen());

UGSTensor ug(g);
UFSTensor dummy_u(0,numStacks(),g.dimen());
for(Tensor::index ui= dummy_u.begin();ui!=dummy_u.end();++ui){
IntSequence tmp(ui.getCoor());
tmp.sort();
if(tmp==coor){
Permutation sort_per(ui.getCoor());
sort_per.inverse();
for(EquivalenceSet::const_iterator it= eset.begin();
it!=eset.end();++it){
if((*it).numClasses()==g.dimen()){
StackProduct<FGSTensor> sp(*this,*it,sort_per,out.getSym());
if(!sp.isZero(coor)){
KronProdStack<FGSTensor> kp(sp,coor);
if(ug.getSym().isFull())
kp.optimizeOrder();
FPSTensor fps(out.getDims(),*it,sort_per,ug,kp);
{
SYNCHRO syn(ad,"multAndAddStacks");
fps.addTo(out);
}
}
}
}
}
}
}

/*:16*/
#line 27 "./stack_container.cweb"
;
/*17:*/
#line 362 "./stack_container.cweb"

void FoldedStackContainer::multAndAddStacks(const IntSequence&coor,
const GSSparseTensor&g,
FGSTensor&out,const void*ad)const
{
const EquivalenceSet&eset= ebundle.get(out.dimen());
UFSTensor dummy_u(0,numStacks(),g.dimen());
for(Tensor::index ui= dummy_u.begin();ui!=dummy_u.end();++ui){
IntSequence tmp(ui.getCoor());
tmp.sort();
if(tmp==coor){
Permutation sort_per(ui.getCoor());
sort_per.inverse();
for(EquivalenceSet::const_iterator it= eset.begin();
it!=eset.end();++it){
if((*it).numClasses()==g.dimen()){
StackProduct<FGSTensor> sp(*this,*it,sort_per,out.getSym());
if(!sp.isZero(coor)){
KronProdStack<FGSTensor> kp(sp,coor);
FPSTensor fps(out.getDims(),*it,sort_per,g,kp);
{
SYNCHRO syn(ad,"multAndAddStacks");
fps.addTo(out);
}
}
}
}
}
}
}

/*:17*/
#line 28 "./stack_container.cweb"
;

/*18:*/
#line 397 "./stack_container.cweb"

void UnfoldedStackContainer::multAndAdd(const FSSparseTensor&t,
UGSTensor&out)const
{
TL_RAISE_IF(t.nvar()!=getAllSize(),
"Wrong number of variables of tensor for UnfoldedStackContainer::multAndAdd");
multAndAddSparse2(t,out);
}

/*:18*/
#line 30 "./stack_container.cweb"
;
/*19:*/
#line 419 "./stack_container.cweb"

void UnfoldedStackContainer::multAndAdd(int dim,const UGSContainer&c,
UGSTensor&out)const
{
TL_RAISE_IF(c.num()!=numStacks(),
"Wrong symmetry length of container for UnfoldedStackContainer::multAndAdd");

THREAD_GROUP gr;
SymmetrySet ss(dim,c.num());
for(symiterator si(ss);!si.isEnd();++si){
if(c.check(*si)){
THREAD*worker= new WorkerUnfoldMAADense(*this,*si,c,out);
gr.insert(worker);
}
}
gr.run();
}

/*:19*/
#line 31 "./stack_container.cweb"
;
/*20:*/
#line 438 "./stack_container.cweb"

void WorkerUnfoldMAADense::operator()()
{
Permutation iden(dense_cont.num());
IntSequence coor(sym,iden.getMap());
const UGSTensor*g= dense_cont.get(sym);
cont.multAndAddStacks(coor,*g,out,&out);
}

/*:20*/
#line 32 "./stack_container.cweb"
;
/*21:*/
#line 448 "./stack_container.cweb"

WorkerUnfoldMAADense::WorkerUnfoldMAADense(const UnfoldedStackContainer&container,
const Symmetry&s,
const UGSContainer&dcontainer,
UGSTensor&outten)
:cont(container),sym(s),dense_cont(dcontainer),out(outten){}


/*:21*/
#line 33 "./stack_container.cweb"
;
/*22:*/
#line 473 "./stack_container.cweb"

void UnfoldedStackContainer::multAndAddSparse1(const FSSparseTensor&t,
UGSTensor&out)const
{
THREAD_GROUP gr;
UFSTensor dummy(0,numStacks(),t.dimen());
for(Tensor::index ui= dummy.begin();ui!=dummy.end();++ui){
THREAD*worker= new WorkerUnfoldMAASparse1(*this,t,out,ui.getCoor());
gr.insert(worker);
}
gr.run();
}

/*:22*/
#line 34 "./stack_container.cweb"
;
/*23:*/
#line 512 "./stack_container.cweb"

void WorkerUnfoldMAASparse1::operator()()
{
const EquivalenceSet&eset= ebundle.get(out.dimen());
const PermutationSet&pset= tls.pbundle->get(t.dimen());
Permutation iden(t.dimen());

UPSTensor slice(t,cont.getStackSizes(),coor,
PerTensorDimens(cont.getStackSizes(),coor));
for(int iper= 0;iper<pset.getNum();iper++){
const Permutation&per= pset.get(iper);
IntSequence percoor(coor.size());
per.apply(coor,percoor);
for(EquivalenceSet::const_iterator it= eset.begin();
it!=eset.end();++it){
if((*it).numClasses()==t.dimen()){
StackProduct<UGSTensor> sp(cont,*it,out.getSym());
if(!sp.isZero(percoor)){
KronProdStack<UGSTensor> kp(sp,percoor);
kp.optimizeOrder();
const Permutation&oper= kp.getPer();
if(Permutation(oper,per)==iden){
UPSTensor ups(out.getDims(),*it,slice,kp);
{
SYNCHRO syn(&out,"WorkerUnfoldMAASparse1");
ups.addTo(out);
}
}
}
}
}
}
}

/*:23*/
#line 35 "./stack_container.cweb"
;
/*24:*/
#line 547 "./stack_container.cweb"

WorkerUnfoldMAASparse1::WorkerUnfoldMAASparse1(const UnfoldedStackContainer&container,
const FSSparseTensor&ten,
UGSTensor&outten,const IntSequence&c)
:cont(container),t(ten),out(outten),coor(c),ebundle(*(tls.ebundle)){}


/*:24*/
#line 36 "./stack_container.cweb"
;
/*25:*/
#line 575 "./stack_container.cweb"

void UnfoldedStackContainer::multAndAddSparse2(const FSSparseTensor&t,
UGSTensor&out)const
{
THREAD_GROUP gr;
FFSTensor dummy_f(0,numStacks(),t.dimen());
for(Tensor::index fi= dummy_f.begin();fi!=dummy_f.end();++fi){
THREAD*worker= new WorkerUnfoldMAASparse2(*this,t,out,fi.getCoor());
gr.insert(worker);
}
gr.run();
}

/*:25*/
#line 37 "./stack_container.cweb"
;
/*26:*/
#line 595 "./stack_container.cweb"

void WorkerUnfoldMAASparse2::operator()()
{
GSSparseTensor slice(t,cont.getStackSizes(),coor,
TensorDimens(cont.getStackSizes(),coor));
if(slice.getNumNonZero()){
FGSTensor fslice(slice);
UGSTensor dense_slice(fslice);
int r1= slice.getFirstNonZeroRow();
int r2= slice.getLastNonZeroRow();
UGSTensor dense_slice1(r1,r2-r1+1,dense_slice);
UGSTensor out1(r1,r2-r1+1,out);

cont.multAndAddStacks(coor,dense_slice1,out1,&out);
}
}

/*:26*/
#line 38 "./stack_container.cweb"
;
/*27:*/
#line 613 "./stack_container.cweb"

WorkerUnfoldMAASparse2::WorkerUnfoldMAASparse2(const UnfoldedStackContainer&container,
const FSSparseTensor&ten,
UGSTensor&outten,const IntSequence&c)
:cont(container),t(ten),out(outten),coor(c){}


/*:27*/
#line 39 "./stack_container.cweb"
;
/*28:*/
#line 636 "./stack_container.cweb"

void UnfoldedStackContainer::multAndAddStacks(const IntSequence&fi,
const UGSTensor&g,
UGSTensor&out,const void*ad)const
{
const EquivalenceSet&eset= ebundle.get(out.dimen());

UFSTensor dummy_u(0,numStacks(),g.dimen());
for(Tensor::index ui= dummy_u.begin();ui!=dummy_u.end();++ui){
IntSequence tmp(ui.getCoor());
tmp.sort();
if(tmp==fi){
Permutation sort_per(ui.getCoor());
sort_per.inverse();
for(EquivalenceSet::const_iterator it= eset.begin();
it!=eset.end();++it){
if((*it).numClasses()==g.dimen()){
StackProduct<UGSTensor> sp(*this,*it,sort_per,out.getSym());
if(!sp.isZero(fi)){
KronProdStack<UGSTensor> kp(sp,fi);
if(g.getSym().isFull())
kp.optimizeOrder();
UPSTensor ups(out.getDims(),*it,sort_per,g,kp);
{
SYNCHRO syn(ad,"multAndAddStacks");
ups.addTo(out);
}
}
}
}
}
}
}

/*:28*/
#line 40 "./stack_container.cweb"
;


/*:1*/