Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
dynare
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
dynare
Commits
2bd2f171
Commit
2bd2f171
authored
11 years ago
by
Stéphane Adjemian
Browse files
Options
Downloads
Patches
Plain Diff
Code optimization. Removed manipulations of dseries objects in the
main loop.
parent
4665c3f3
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
matlab/utilities/dseries/from.m
+31
-7
31 additions, 7 deletions
matlab/utilities/dseries/from.m
with
31 additions
and
7 deletions
matlab/utilities/dseries/from.m
+
31
−
7
View file @
2bd2f171
...
...
@@ -184,16 +184,40 @@ else
error
(
'Not yet implemented! Only one assignment is allowed in the FROM-TO-DO statement.'
)
end
% Transform the indexed variables after the assignment symbol: X(t-1) -> X(t-1).data
expression
=
EXPRESSION
(
equal_id
+
1
:
end
);
expression
=
regexprep
(
expression
,
'\w*\(t\)|\w*\(t\-\d\)|\w*\(t\+\d\)'
,
'$0.data'
);
EXPRESSION
=
[
EXPRESSION
(
1
:
equal_id
),
expression
];
% Put all the variables in a unique dseries object.
list_of_variables
=
leadlagtable
{
1
,
1
};
for
i
=
2
:
number_of_variables
list_of_variables
=
[
list_of_variables
,
','
leadlagtable
{
i
,
1
}];
end
try
eval
(
sprintf
(
'tmp = [%s];'
,
list_of_variables
));
catch
error
(
'dseries::from: All the dseries objects should contain variables with different names!'
)
end
% Get base time index
t1
=
find
(
d1
==
tmp
.
dates
);
t2
=
find
(
d2
==
tmp
.
dates
);
% Get data
data
=
tmp
.
data
;
% Transform EXPRESSION by replacing calls to the dseries objects by references to data.
for
i
=
1
:
number_of_variables
EXPRESSION
=
regexprep
(
EXPRESSION
,
sprintf
(
'%s\\(t\\)'
,
leadlagtable
{
i
,
1
}),
sprintf
(
'data(t,%s)'
,
num2str
(
i
)));
for
lag
=
1
:
leadlagtable
{
i
,
2
}
EXPRESSION
=
regexprep
(
EXPRESSION
,
sprintf
(
'%s\\(t-%s\\)'
,
leadlagtable
{
i
,
1
},
num2str
(
lag
)),
sprintf
(
'data(t-%s,%s)'
,
num2str
(
lag
),
num2str
(
i
)));
end
for
lead
=
1
:
leadlagtable
{
i
,
4
}
EXPRESSION
=
regexprep
(
EXPRESSION
,
sprintf
(
'%s\\(t+%s\\)'
,
leadlagtable
{
i
,
1
},
num2str
(
lead
)),
sprintf
(
'data(t+%s,%s)'
,
num2str
(
lead
),
num2str
(
i
)));
end
end
%
Run
the recursion
!
eval
(
sprintf
(
'
t=dates(
''
%s
''
); while t<=dates(
''
%s
''
), %s; t = t+1; end'
,
cha
r
(
d
1
),
cha
r
(
d
2
),
EXPRESSION
))
%
Do the job. Evaluate
the recursion
.
eval
(
sprintf
(
'
for t=%s:%s, %s; end'
,
num2st
r
(
t
1
),
num2st
r
(
t
2
),
EXPRESSION
))
;
% Put assigned variable back in the caller workspace...
eval
(
sprintf
(
'assignin(
''
caller
''
,
assignedvariablename, %s)
'
,
assignedvariablename
))
;
eval
(
sprintf
(
'assignin(
''
caller
''
,
''
%s
''
, dseries(data(:,indva),y.init,y.name,y.tex));
'
,
assignedvariablename
))
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment