File: tl_static.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 (88 lines) | stat: -rw-r--r-- 1,335 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
/*1:*/
#line 5 "./tl_static.cweb"

#include "tl_static.h"
#include "tl_exception.h"

TLStatic tls;
/*2:*/
#line 17 "./tl_static.cweb"

TLStatic::TLStatic()
{
ebundle= NULL;
pbundle= NULL;
ptriang= NULL;
}

TLStatic::~TLStatic()
{
if(ebundle)
delete ebundle;
if(pbundle)
delete pbundle;
if(ptriang)
delete ptriang;
}

void TLStatic::init(int dim,int nvar)
{
if(ebundle)
ebundle->generateUpTo(dim);
else
ebundle= new EquivalenceBundle(dim);

if(pbundle)
pbundle->generateUpTo(dim);
else
pbundle= new PermutationBundle(dim);

if(ptriang)
delete ptriang;
ptriang= new PascalTriangle(nvar,dim);
}

/*:2*/
#line 10 "./tl_static.cweb"
;
/*3:*/
#line 59 "./tl_static.cweb"

PascalTriangle::PascalTriangle(int n,int k)
:data(new int[(n+1)*(k+1)]),kmax(k),nmax(n)
{
for(int i= 0;i<=n;i++)
data[i]= 1;
for(int j= 1;j<=k;j++){
data[j*(nmax+1)]= 1;
for(int i= 1;i<=n;i++)
data[j*(nmax+1)+i]= noverk(i+j-1,j)+noverk(i+j-1,j-1);
}
}

/*:3*/
#line 11 "./tl_static.cweb"
;
/*4:*/
#line 73 "./tl_static.cweb"

int PascalTriangle::noverk(int n,int k)const
{
TL_RAISE_IF(k> n||n<0,
"Wrong arguments for PascalTriangle::noverk");

if(k<=kmax&&n-k<=nmax)
return data[k*(nmax+1)+n-k];

if(n-k<=kmax&&k<=nmax)
return data[(n-k)*(nmax+1)+k];

TL_RAISE("n or k out of range in PascalTriangle::noverk");
return 0;
}

/*:4*/
#line 12 "./tl_static.cweb"
;

/*:1*/