Skip to content

Commit 34dca87

Browse files
committed
WIP
1 parent a7213aa commit 34dca87

File tree

6 files changed

+434
-11
lines changed

6 files changed

+434
-11
lines changed

dev_higher_1.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
from dyno.modfile import DynareModel
2+
3+
def do_it():
4+
5+
model = DynareModel("examples/modfiles/RBC.mod", deriv_order=3)
6+
7+
res = model.compute_derivatives()
8+
return res
9+
10+
res = do_it()
11+
import time
12+
t1 = time.time()
13+
14+
do_it()
15+
t2 = time.time()
16+
print("Elapsed:", t2-t1)
17+
18+
from rich import print
19+
20+
for r in res:
21+
print(r)
22+
23+
model = DynareModel("examples/modfiles/RBC.mod", deriv_order=3)
24+
25+
n = len(model.symbols['endogenous'])
26+
m = len(model.symbols['exogenous'])
27+
indices = {}
28+
for i,el in enumerate(model.data.symbol_info):
29+
symtype = el[0].name
30+
if symtype =='endogenous':
31+
k,p = el[1], el[2]
32+
j = n-p*n + k
33+
indices[i] = j
34+
elif symtype =='exogenous':
35+
k,p = el[1], el[2]
36+
j = 3*n + k
37+
indices[i] = j
38+
elif symtype =='parameter':
39+
pass
40+
else:
41+
raise Exception(f"Unknown symbol type {symtype}")
42+
43+
t1 = time.time()
44+
nres = [res[0]]
45+
for r in res[1:]:
46+
d = []
47+
for el in r:
48+
ind,v = el
49+
ind2 = [ind[0]] + [indices[e] for e in ind[1:]]
50+
d.append((ind2,v))
51+
nres.append(d)
52+
t2 = time.time()
53+
54+
tt = [SymTensor(r, (n,)+(3*n+m,)*i) for i,r in enumerate(nres)]
55+
print("Reindexing time:", t2-t1)
56+
57+
class SymTensor:
58+
"All dimensions are symmetric, except the first one"
59+
60+
def __init__(self, data, shape):
61+
62+
self.data = data
63+
self.shape = shape
64+
65+
@property
66+
def ndims(self):
67+
return len(self.shape)
68+

0 commit comments

Comments
 (0)