Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
preprocessor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Dynare
preprocessor
Compare revisions
db1bad652209c2d6de9d42143bb2b51a0f507b5e to d8866fbec8a09df0d8fa1d2e7e60b2aae8685ea8
Compare revisions
Changes are shown as if the
source
revision was being merged into the
target
revision.
Learn more about comparing revisions.
Source
Dynare/preprocessor
Select target project
No results found
d8866fbec8a09df0d8fa1d2e7e60b2aae8685ea8
Select Git revision
Branches
4.6
5.x
6.x
aux_vars_fix
julia
julia-6.3.0
julia-6.4.0
julia-meson
llvm-15
master
python-codegen
rework_pac
uop
Tags
created_preprocessor_repo
julia-6.2.0
15 results
Swap
Target
Dynare/preprocessor
Select target project
normann/preprocessor
Dynare/preprocessor
FerhatMihoubi/preprocessor
MichelJuillard/preprocessor
sebastien/preprocessor
lnsongxf/preprocessor
albop/preprocessor
DoraK/preprocessor
amg/preprocessor
wmutschl/preprocessor
JohannesPfeifer/preprocessor
11 results
db1bad652209c2d6de9d42143bb2b51a0f507b5e
Select Git revision
Branches
4.6
5.x
6.x
aux_vars_fix
julia
julia-6.3.0
julia-6.4.0
julia-meson
llvm-15
master
python-codegen
rework_pac
uop
Tags
created_preprocessor_repo
julia-6.2.0
15 results
Show changes
Only incoming changes from source
Include changes to target since source was created
Compare
Commits on Source (2)
Drop legacy representation for the static model
· 2315bdb5
Sébastien Villemot
authored
1 year ago
Verified
2315bdb5
Drop M_.NNZDerivatives_objective, no longer needed
· d8866fbe
Sébastien Villemot
authored
1 year ago
Verified
d8866fbe
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/ModelEquationBlock.cc
+1
-4
1 addition, 4 deletions
src/ModelEquationBlock.cc
src/StaticModel.cc
+0
-234
0 additions, 234 deletions
src/StaticModel.cc
src/StaticModel.hh
+1
-18
1 addition, 18 deletions
src/StaticModel.hh
with
2 additions
and
256 deletions
src/ModelEquationBlock.cc
View file @
d8866fbe
...
@@ -34,10 +34,7 @@ PlannerObjective::PlannerObjective(SymbolTable& symbol_table_arg,
...
@@ -34,10 +34,7 @@ PlannerObjective::PlannerObjective(SymbolTable& symbol_table_arg,
void
void
PlannerObjective
::
writeDriverOutput
(
ostream
&
output
)
const
PlannerObjective
::
writeDriverOutput
(
ostream
&
output
)
const
{
{
output
<<
"M_.NNZDerivatives_objective = ["
;
output
<<
"M_.objective_tmp_nbr = ["
;
for
(
int
i
=
1
;
i
<
static_cast
<
int
>
(
NNZDerivatives
.
size
());
i
++
)
output
<<
(
i
>
computed_derivs_order
?
-
1
:
NNZDerivatives
[
i
])
<<
";"
;
output
<<
"];"
<<
endl
<<
"M_.objective_tmp_nbr = ["
;
for
(
const
auto
&
it
:
temporary_terms_derivatives
)
for
(
const
auto
&
it
:
temporary_terms_derivatives
)
output
<<
it
.
size
()
<<
"; "
;
output
<<
it
.
size
()
<<
"; "
;
output
<<
"];"
<<
endl
;
output
<<
"];"
<<
endl
;
...
...
This diff is collapsed.
Click to expand it.
src/StaticModel.cc
View file @
d8866fbe
...
@@ -252,237 +252,6 @@ StaticModel::computingPass(int derivsOrder, int paramsDerivsOrder,
...
@@ -252,237 +252,6 @@ StaticModel::computingPass(int derivsOrder, int paramsDerivsOrder,
}
}
}
}
void
StaticModel
::
writeStaticMFile
(
const
string
&
basename
)
const
{
auto
[
d_output
,
tt_output
]
=
writeModelFileHelper
<
ExprNodeOutputType
::
matlabStaticModel
>
();
ostringstream
init_output
,
end_output
;
init_output
<<
"residual = zeros("
<<
equations
.
size
()
<<
", 1);"
;
writeStaticMFileHelper
(
basename
,
"static_resid"
,
"residual"
,
"static_resid_tt"
,
temporary_terms_derivatives
[
0
].
size
(),
""
,
init_output
,
end_output
,
d_output
[
0
],
tt_output
[
0
]);
init_output
.
str
(
""
);
end_output
.
str
(
""
);
init_output
<<
"g1 = zeros("
<<
equations
.
size
()
<<
", "
<<
symbol_table
.
endo_nbr
()
<<
");"
;
writeStaticMFileHelper
(
basename
,
"static_g1"
,
"g1"
,
"static_g1_tt"
,
temporary_terms_derivatives
[
0
].
size
()
+
temporary_terms_derivatives
[
1
].
size
(),
"static_resid_tt"
,
init_output
,
end_output
,
d_output
[
1
],
tt_output
[
1
]);
writeStaticMWrapperFunction
(
basename
,
"g1"
);
// For order ≥ 2
int
ncols
{
symbol_table
.
endo_nbr
()};
int
ntt
{
static_cast
<
int
>
(
temporary_terms_derivatives
[
0
].
size
()
+
temporary_terms_derivatives
[
1
].
size
())};
for
(
size_t
i
{
2
};
i
<
derivatives
.
size
();
i
++
)
{
ncols
*=
symbol_table
.
endo_nbr
();
ntt
+=
temporary_terms_derivatives
[
i
].
size
();
string
gname
{
"g"
+
to_string
(
i
)};
string
gprevname
{
"g"
+
to_string
(
i
-
1
)};
init_output
.
str
(
""
);
end_output
.
str
(
""
);
if
(
derivatives
[
i
].
size
())
{
init_output
<<
gname
<<
"_i = zeros("
<<
NNZDerivatives
[
i
]
<<
",1);"
<<
endl
<<
gname
<<
"_j = zeros("
<<
NNZDerivatives
[
i
]
<<
",1);"
<<
endl
<<
gname
<<
"_v = zeros("
<<
NNZDerivatives
[
i
]
<<
",1);"
<<
endl
;
end_output
<<
gname
<<
" = sparse("
<<
gname
<<
"_i,"
<<
gname
<<
"_j,"
<<
gname
<<
"_v,"
<<
equations
.
size
()
<<
","
<<
ncols
<<
");"
;
}
else
init_output
<<
gname
<<
" = sparse([],[],[],"
<<
equations
.
size
()
<<
","
<<
ncols
<<
");"
;
writeStaticMFileHelper
(
basename
,
"static_"
+
gname
,
gname
,
"static_"
+
gname
+
"_tt"
,
ntt
,
"static_"
+
gprevname
+
"_tt"
,
init_output
,
end_output
,
d_output
[
i
],
tt_output
[
i
]);
if
(
i
<=
3
)
writeStaticMWrapperFunction
(
basename
,
gname
);
}
writeStaticMCompatFile
(
basename
);
}
void
StaticModel
::
writeStaticMWrapperFunction
(
const
string
&
basename
,
const
string
&
ending
)
const
{
string
name
;
if
(
ending
==
"g1"
)
name
=
"static_resid_g1"
;
else
if
(
ending
==
"g2"
)
name
=
"static_resid_g1_g2"
;
else
if
(
ending
==
"g3"
)
name
=
"static_resid_g1_g2_g3"
;
filesystem
::
path
filename
{
packageDir
(
basename
)
/
(
name
+
".m"
)};
ofstream
output
{
filename
,
ios
::
out
|
ios
::
binary
};
if
(
!
output
.
is_open
())
{
cerr
<<
"ERROR: Can't open file "
<<
filename
.
string
()
<<
" for writing"
<<
endl
;
exit
(
EXIT_FAILURE
);
}
if
(
ending
==
"g1"
)
output
<<
"function [residual, g1] = "
<<
name
<<
"(T, y, x, params, T_flag)"
<<
endl
<<
"% function [residual, g1] = "
<<
name
<<
"(T, y, x, params, T_flag)"
<<
endl
;
else
if
(
ending
==
"g2"
)
output
<<
"function [residual, g1, g2] = "
<<
name
<<
"(T, y, x, params, T_flag)"
<<
endl
<<
"% function [residual, g1, g2] = "
<<
name
<<
"(T, y, x, params, T_flag)"
<<
endl
;
else
if
(
ending
==
"g3"
)
output
<<
"function [residual, g1, g2, g3] = "
<<
name
<<
"(T, y, x, params, T_flag)"
<<
endl
<<
"% function [residual, g1, g2, g3] = "
<<
name
<<
"(T, y, x, params, T_flag)"
<<
endl
;
output
<<
"%"
<<
endl
<<
"% Wrapper function automatically created by Dynare"
<<
endl
<<
"%"
<<
endl
<<
endl
<<
" if T_flag"
<<
endl
<<
" T = "
<<
basename
<<
".static_"
<<
ending
<<
"_tt(T, y, x, params);"
<<
endl
<<
" end"
<<
endl
;
if
(
ending
==
"g1"
)
output
<<
" residual = "
<<
basename
<<
".static_resid(T, y, x, params, false);"
<<
endl
<<
" g1 = "
<<
basename
<<
".static_g1(T, y, x, params, false);"
<<
endl
;
else
if
(
ending
==
"g2"
)
output
<<
" [residual, g1] = "
<<
basename
<<
".static_resid_g1(T, y, x, params, false)
;
"
<< endl
<< "
g2
=
" << basename << "
.
static_g2
(
T
,
y
,
x
,
params
,
false
);
" << endl;
else if (ending == "
g3
")
output << "
[
residual
,
g1
,
g2
]
=
" << basename
<< "
.
static_resid_g1_g2
(
T
,
y
,
x
,
params
,
false
);
" << endl
<< "
g3
=
" << basename << "
.
static_g3
(
T
,
y
,
x
,
params
,
false
);
" << endl;
output << endl << "
end
" << endl;
output.close();
}
void
StaticModel::writeStaticMFileHelper(const string& basename, const string& name,
const string& retvalname, const string& name_tt, size_t ttlen,
const string& previous_tt_name, const ostringstream& init_s,
const ostringstream& end_s, const ostringstream& s,
const ostringstream& s_tt) const
{
filesystem::path filename {packageDir(basename) / (name_tt + "
.
m
")};
ofstream output {filename, ios::out | ios::binary};
if (!output.is_open())
{
cerr << "
ERROR
:
Can
'
t
open
file
" << filename.string() << "
for
writing
" << endl;
exit(EXIT_FAILURE);
}
output << "
function
T
=
" << name_tt << "
(
T
,
y
,
x
,
params
)
" << endl
<< "
%
function
T
=
" << name_tt << "
(
T
,
y
,
x
,
params
)
" << endl
<< "
%
" << endl
<< "
%
File
created
by
Dynare
Preprocessor
from
.
mod
file
" << endl
<< "
%
" << endl
<< "
%
Inputs
:
" << endl
<< "
%
T
[
#
temp
variables
by
1
]
double
vector
of
temporary
terms
to
be
filled
"
"
by
function
"
<< endl
<< "
%
y
[
M_
.
endo_nbr
by
1
]
double
vector
of
endogenous
variables
in
"
"
declaration
order
"
<< endl
<< "
%
x
[
M_
.
exo_nbr
by
1
]
double
vector
of
exogenous
variables
in
"
"
declaration
order
"
<< endl
<< "
%
params
[
M_
.
param_nbr
by
1
]
double
vector
of
parameter
values
in
"
"
declaration
order
"
<< endl
<< "
%
" << endl
<< "
%
Output
:
" << endl
<< "
%
T
[
#
temp
variables
by
1
]
double
vector
of
temporary
terms
" << endl
<< "
%
" << endl
<< endl
<< "
assert
(
length
(
T
)
>=
" << ttlen << "
);
" << endl
<< endl;
if (!previous_tt_name.empty())
output << "
T
=
" << basename << "
.
" << previous_tt_name << "
(
T
,
y
,
x
,
params
);
" << endl << endl;
output << s_tt.str() << endl << "
end
" << endl;
output.close();
filename = packageDir(basename) / (name + "
.
m
");
output.open(filename, ios::out | ios::binary);
if (!output.is_open())
{
cerr << "
ERROR
:
Can
'
t
open
file
" << filename.string() << "
for
writing
" << endl;
exit(EXIT_FAILURE);
}
output << "
function
" << retvalname << "
=
" << name << "
(
T
,
y
,
x
,
params
,
T_flag
)
" << endl
<< "
%
function
" << retvalname << "
=
" << name << "
(
T
,
y
,
x
,
params
,
T_flag
)
" << endl
<< "
%
" << endl
<< "
%
File
created
by
Dynare
Preprocessor
from
.
mod
file
" << endl
<< "
%
" << endl
<< "
%
Inputs
:
" << endl
<< "
%
T
[
#
temp
variables
by
1
]
double
vector
of
temporary
terms
to
be
filled
"
"
by
function
"
<< endl
<< "
%
y
[
M_
.
endo_nbr
by
1
]
double
vector
of
endogenous
variables
in
"
"
declaration
order
"
<< endl
<< "
%
x
[
M_
.
exo_nbr
by
1
]
double
vector
of
exogenous
variables
in
"
"
declaration
order
"
<< endl
<< "
%
params
[
M_
.
param_nbr
by
1
]
double
vector
of
parameter
values
in
"
"
declaration
order
"
<< endl
<< "
%
to
evaluate
the
model
" << endl
<< "
%
T_flag
boolean
boolean
flag
saying
whether
or
not
to
"
"
calculate
temporary
terms
"
<< endl
<< "
%
" << endl
<< "
%
Output
:
" << endl
<< "
%
" << retvalname << endl
<< "
%
" << endl
<< endl;
if (!name_tt.empty())
output << "
if
T_flag
" << endl
<< "
T
=
" << basename << "
.
" << name_tt << "
(
T
,
y
,
x
,
params
);
" << endl
<< "
end
" << endl;
output << init_s.str() << endl << s.str() << end_s.str() << endl << "
end
" << endl;
output.close();
}
void
StaticModel::writeStaticMCompatFile(const string& basename) const
{
filesystem::path filename {packageDir(basename) / "
static
.
m
"};
ofstream output {filename, ios::out | ios::binary};
if (!output.is_open())
{
cerr << "
ERROR
:
Can
'
t
open
file
" << filename.string() << "
for
writing
" << endl;
exit(EXIT_FAILURE);
}
int ntt {static_cast<int>(
temporary_terms_derivatives[0].size() + temporary_terms_derivatives[1].size()
+ temporary_terms_derivatives[2].size() + temporary_terms_derivatives[3].size())};
output << "
function
[
residual
,
g1
,
g2
,
g3
]
=
static
(
y
,
x
,
params
)
" << endl
<< "
T
=
NaN
(
" << ntt << "
,
1
);
" << endl
<< "
if
nargout
<=
1
" << endl
<< "
residual
=
" << basename << "
.
static_resid
(
T
,
y
,
x
,
params
,
true
);
" << endl
<< "
elseif
nargout
==
2
" << endl
<< "
[
residual
,
g1
]
=
" << basename << "
.
static_resid_g1
(
T
,
y
,
x
,
params
,
true
);
"
<< endl
<< "
elseif
nargout
==
3
" << endl
<< "
[
residual
,
g1
,
g2
]
=
" << basename
<< "
.
static_resid_g1_g2
(
T
,
y
,
x
,
params
,
true
);
" << endl
<< "
else
" << endl
<< "
[
residual
,
g1
,
g2
,
g3
]
=
" << basename
<< "
.
static_resid_g1_g2_g3
(
T
,
y
,
x
,
params
,
true
);
" << endl
<< "
end
" << endl
<< "
end
" << endl;
output.close();
}
void
void
StaticModel
::
writeStaticFile
(
const
string
&
basename
,
bool
use_dll
,
const
string
&
mexext
,
StaticModel
::
writeStaticFile
(
const
string
&
basename
,
bool
use_dll
,
const
string
&
mexext
,
const
filesystem
::
path
&
matlabroot
,
bool
julia
)
const
const
filesystem
::
path
&
matlabroot
,
bool
julia
)
const
...
@@ -517,9 +286,6 @@ StaticModel::writeStaticFile(const string& basename, bool use_dll, const string&
...
@@ -517,9 +286,6 @@ StaticModel::writeStaticFile(const string& basename, bool use_dll, const string&
// Legacy representation
// Legacy representation
if
(
use_dll
)
if
(
use_dll
)
writeModelCFile
<
false
>
(
basename
,
mexext
,
matlabroot
);
writeModelCFile
<
false
>
(
basename
,
mexext
,
matlabroot
);
else if (!julia) // M-files
writeStaticMFile(basename);
// The legacy representation is no longer produced for Julia
/* PlannerObjective subclass or discretionary optimal policy models don’t
/* PlannerObjective subclass or discretionary optimal policy models don’t
have as many variables as equations; bytecode does not support that
have as many variables as equations; bytecode does not support that
...
...
This diff is collapsed.
Click to expand it.
src/StaticModel.hh
View file @
d8866fbe
/*
/*
* Copyright © 2003-202
3
Dynare Team
* Copyright © 2003-202
4
Dynare Team
*
*
* This file is part of Dynare.
* This file is part of Dynare.
*
*
...
@@ -60,9 +60,6 @@ private:
...
@@ -60,9 +60,6 @@ private:
block. See the DynamicModel class for the default value in that case. */
block. See the DynamicModel class for the default value in that case. */
int
static_mfs
{
0
};
int
static_mfs
{
0
};
// Writes static model file (MATLAB/Octave version, legacy representation)
void
writeStaticMFile
(
const
string
&
basename
)
const
;
//! Writes the code of the block-decomposed model in virtual machine bytecode
//! Writes the code of the block-decomposed model in virtual machine bytecode
void
writeStaticBlockBytecode
(
const
string
&
basename
)
const
;
void
writeStaticBlockBytecode
(
const
string
&
basename
)
const
;
...
@@ -95,20 +92,6 @@ private:
...
@@ -95,20 +92,6 @@ private:
void
computeChainRuleJacobian
()
override
;
void
computeChainRuleJacobian
()
override
;
/* Helper for writing MATLAB/Octave functions for residuals/derivatives and
their temporary terms (legacy representation) */
void
writeStaticMFileHelper
(
const
string
&
basename
,
const
string
&
name
,
const
string
&
retvalname
,
const
string
&
name_tt
,
size_t
ttlen
,
const
string
&
previous_tt_name
,
const
ostringstream
&
init_s
,
const
ostringstream
&
end_s
,
const
ostringstream
&
s
,
const
ostringstream
&
s_tt
)
const
;
/* Writes MATLAB/Octave wrapper function for computing residuals and
derivatives at the same time (legacy representation) */
void
writeStaticMWrapperFunction
(
const
string
&
basename
,
const
string
&
ending
)
const
;
/* Create the compatibility static.m file for MATLAB/Octave not yet using the
temporary terms array interface (legacy representation) */
void
writeStaticMCompatFile
(
const
string
&
name
)
const
;
int
int
getBlockJacobianEndoCol
([[
maybe_unused
]]
int
blk
,
int
var
,
getBlockJacobianEndoCol
([[
maybe_unused
]]
int
blk
,
int
var
,
[[
maybe_unused
]]
int
lag
)
const
override
[[
maybe_unused
]]
int
lag
)
const
override
...
...
This diff is collapsed.
Click to expand it.