Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
dseries
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
dseries
Commits
0a50b59d
Verified
Commit
0a50b59d
authored
4 years ago
by
Stéphane Adjemian
Browse files
Options
Downloads
Patches
Plain Diff
Fixed subsref overloaded method.
parent
1a0a4898
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
src/@dates/subsref.m
+199
-191
199 additions, 191 deletions
src/@dates/subsref.m
with
199 additions
and
191 deletions
src/@dates/subsref.m
+
199
−
191
View file @
0a50b59d
...
...
@@ -13,7 +13,7 @@ function B = subsref(A,S) % --*-- Unitary tests --*--
% 1. The type of the returned argument depends on the content of S.
% 2. See the matlab's documentation about the subsref method.
% Copyright
(C)
2011-2020 Dynare Team
% Copyright
©
2011-2020 Dynare Team
%
% This code is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
...
...
@@ -126,7 +126,13 @@ switch S(1).type
if
~
isequal
(
n1
,
n2
,
n3
)
error
(
'dates::subsref: Second, third and fourth input arguments must have the same number of elements!'
)
end
B
.
time
=
[
S
(
1
)
.
subs
{
2
},
S
(
1
)
.
subs
{
3
},
S
(
1
)
.
subs
{
4
}];
% Check that the provided inputs form a valid date
for
i
=
1
:
length
(
S
(
1
)
.
subs
{
1
})
if
~
isvalidday
([
S
(
1
)
.
subs
{
1
}(
i
),
S
(
1
)
.
subs
{
2
}(
i
),
S
(
1
)
.
subs
{
3
}(
i
)])
error
(
'Triplet (%u, %u, %u) is not a valid date for a day.'
,
S
(
1
)
.
subs
{
1
}(
i
),
S
(
1
)
.
subs
{
2
}(
i
),
S
(
1
)
.
subs
{
3
}(
i
))
end
end
B
.
time
=
[
datenum
([
S
(
1
)
.
subs
{
1
},
S
(
1
)
.
subs
{
2
},
S
(
1
)
.
subs
{
3
}]),
NaN
(
length
(
S
(
1
)
.
subs
{
1
}),
1
)];
else
error
(
'dates::subsref: Wrong calling sequence!'
)
end
...
...
@@ -181,7 +187,13 @@ switch S(1).type
if
~
isequal
(
n3
,
n2
,
n1
)
error
(
'dates::subsref: All arguments must have the same number of rows!'
)
end
B
.
time
=
[
S
(
1
)
.
subs
{
1
},
S
(
1
)
.
subs
{
2
},
S
(
1
)
.
subs
{
3
}];
% Check that the provided inputs form a valid date
for
i
=
1
:
length
(
S
(
1
)
.
subs
{
1
})
if
~
isvalidday
([
S
(
1
)
.
subs
{
1
}(
i
),
S
(
1
)
.
subs
{
2
}(
i
),
S
(
1
)
.
subs
{
3
}(
i
)])
error
(
'Triplet (%u, %u, %u) is not a valid date for a day.'
,
S
(
1
)
.
subs
{
1
}(
i
),
S
(
1
)
.
subs
{
2
}(
i
),
S
(
1
)
.
subs
{
3
}(
i
))
end
end
B
.
time
=
[
datenum
([
S
(
1
)
.
subs
{
1
},
S
(
1
)
.
subs
{
2
},
S
(
1
)
.
subs
{
3
}]),
NaN
(
length
(
S
(
1
)
.
subs
{
1
}),
1
)];
else
error
(
'dates::subsref: Wrong number of inputs!'
)
end
...
...
@@ -207,217 +219,213 @@ if ~isempty(S)
B
=
subsref
(
B
,
S
);
end
return
%@test:1
%$ % Define a dates object
%$ B = dates('1950Q1','1950Q2','1950Q3','1950Q4','1951Q1');
%$
%$ % Try to extract a sub-dates object.
%$ d = B(2:3);
%$
%$ if isa(d,'dates')
%$ t(1) = 1;
%$ else
%$ t(1) = 0;
%$ end
%$
%$ if t(1)
%$ t(2) = dassert(d.freq,B.freq);
%$ t(3) = dassert(d.time,[1950 2; 1950 3]);
%$ t(4) = dassert(d.ndat(),2);
%$ end
%$ T = all(t);
% Define a dates object
B
=
dates
(
'1950Q1'
,
'1950Q2'
,
'1950Q3'
,
'1950Q4'
,
'1951Q1'
);
% Try to extract a sub-dates object.
try
d
=
B
(
2
:
3
);
t
(
1
)
=
true
;
catch
t
(
1
)
=
false
;
end
if
t
(
1
)
t
(
2
)
=
isequal
(
d
.
freq
,
B
.
freq
);
t
(
3
)
=
isequal
(
d
.
time
,
[
1950
2
;
1950
3
]);
t
(
4
)
=
isequal
(
d
.
ndat
(),
2
);
end
T
=
all
(
t
);
%@eof:1
%@test:2
%$ % Define a dates object
%$ B = dates('1950Q1'):dates('1960Q3');
%$
%$ % Try to extract a sub-dates object and apply a method
%$
%$ d = B(2:3).sort ;
%$
%$ if isa(d,'dates')
%$ t(1) = 1;
%$ else
%$ t(1) = 0;
%$ end
%$
%$ if t(1)
%$ t(2) = dassert(d.freq,B.freq);
%$ t(3) = dassert(d.time,[1950 2; 1950 3]);
%$ t(4) = dassert(d.ndat(),2);
%$ end
%$ T = all(t);
% Define a dates object
B
=
dates
(
'1950Q1'
):
dates
(
'1960Q3'
);
% Try to extract a sub-dates object and apply a method
try
d
=
B
(
2
:
3
)
.
sort
;
t
(
1
)
=
true
;
catch
t
(
1
)
=
false
;
end
if
t
(
1
)
t
(
2
)
=
isequal
(
d
.
freq
,
B
.
freq
);
t
(
3
)
=
isequal
(
d
.
time
,[
1950
2
;
1950
3
]);
t
(
4
)
=
isequal
(
d
.
ndat
(),
2
);
end
T
=
all
(
t
);
%@eof:2
%@test:3
%$ % Define a dates object
%$ B = dates('1950Q1'):dates('1960Q3');
%$
%$ % Try to extract a sub-dates object and apply a method
%$
%$ d = B(2:3).sort() ;
%$
%$ if isa(d,'dates')
%$ t(1) = 1;
%$ else
%$ t(1) = 0;
%$ end
%$
%$ if t(1)
%$ t(2) = dassert(d.freq,B.freq);
%$ t(3) = dassert(d.time,[1950 2; 1950 3]);
%$ t(4) = dassert(d.ndat(),2);
%$ end
%$ T = all(t);
% Define a dates object
B
=
dates
(
'1950Q1'
):
dates
(
'1960Q3'
);
% Try to extract a sub-dates object and apply a method
try
d
=
B
(
2
:
3
)
.
sort
();
t
(
1
)
=
true
;
catch
t
(
1
)
=
false
;
end
if
t
(
1
)
t
(
2
)
=
isequal
(
d
.
freq
,
B
.
freq
);
t
(
3
)
=
isequal
(
d
.
time
,[
1950
2
;
1950
3
]);
t
(
4
)
=
isequal
(
d
.
ndat
(),
2
);
end
T
=
all
(
t
);
%@eof:3
%@test:4
%$ % Define a dates object
%$ B = dates('1950Q1','1950Q2','1950Q3','1950Q4','1951Q1');
%$
%$ % Try to extract a sub-dates object.
%$ d = B(2);
%$
%$ if isa(d,'dates')
%$ t(1) = 1;
%$ else
%$ t(1) = 0;
%$ end
%$
%$ if t(1)
%$ t(2) = dassert(d.freq,B.freq);
%$ t(3) = dassert(d.time,[1950 2]);
%$ t(4) = dassert(d.ndat(),1);
%$ end
%$ T = all(t);
% Define a dates object
B
=
dates
(
'1950Q1'
,
'1950Q2'
,
'1950Q3'
,
'1950Q4'
,
'1951Q1'
);
% Try to extract a sub-dates object.
try
d
=
B
(
2
);
t
(
1
)
=
true
;
catch
t
(
1
)
=
false
;
end
if
t
(
1
)
t
(
2
)
=
isequal
(
d
.
freq
,
B
.
freq
);
t
(
3
)
=
isequal
(
d
.
time
,[
1950
2
]);
t
(
4
)
=
isequal
(
d
.
ndat
(),
1
);
end
T
=
all
(
t
);
%@eof:4
%@test:5
%$ % Define an empty dates object with quaterly frequency.
%$ qq = dates('Q');
%$
%$ % Define a ranges of dates using qq.
%$ try
%$ r1 = qq(1950,1):qq(1950,3);%qq([1950, 3]);
%$ t(1) = 1;
%$ catch
%$ t(1) = 0;
%$ end
%$ if t(1)
%$ try
%$ r2 = qq([1950, 1; 1950, 2; 1950, 3]);
%$ t(2) = 1;
%$ catch
%$ t(2) = 0;
%$ end
%$ end
%$ if t(1) && t(2)
%$ try
%$ r3 = qq(1950*ones(3,1), transpose(1:3));
%$ t(3) = 1;
%$ catch
%$ t(3) = 0;
%$ end
%$ end
%$
%$ if t(1) && t(2) && t(3)
%$ t(4) = dassert(r1,r2);
%$ t(5) = dassert(r1,r3);
%$ end
%$ T = all(t);
% Define an empty dates object with quaterly frequency.
qq
=
dates
(
'Q'
);
% Define a ranges of dates using qq.
try
r1
=
qq
(
1950
,
1
):
qq
(
1950
,
3
);
t
(
1
)
=
true
;
catch
t
(
1
)
=
false
;
end
if
t
(
1
)
try
r2
=
qq
([
1950
,
1
;
1950
,
2
;
1950
,
3
]);
t
(
2
)
=
true
;
catch
t
(
2
)
=
false
;
end
end
if
t
(
1
)
&&
t
(
2
)
try
r3
=
qq
(
1950
*
ones
(
3
,
1
),
transpose
(
1
:
3
));
t
(
3
)
=
true
;
catch
t
(
3
)
=
false
;
end
end
if
t
(
1
)
&&
t
(
2
)
&&
t
(
3
)
t
(
4
)
=
isequal
(
r1
,
r2
);
t
(
5
)
=
isequal
(
r1
,
r3
);
end
T
=
all
(
t
);
%@eof:5
%@test:6
%$
% Define an empty dates object with quaterly frequency.
%$
date = dates();
%$
%$
% Define a ranges of dates using qq.
%$
try
%$
r1 = date(4,1950,1):date(4,[1950, 3]);
%$
t(1) =
1
;
%$
catch
%$
t(1) =
0
;
%$
end
%$
if t(1)
%$
try
%$
r2 = date(4,[1950, 1; 1950, 2; 1950, 3]);
%$
t(2) =
1
;
%$
catch
%$
t(2) =
0
;
%$
end
%$
end
%$
if t(1) && t(2)
%$
try
%$
r3 = date(4,1950*ones(3,1), transpose(1:3));
%$
t(3) =
1
;
%$
catch
%$
t(3) =
0
;
%$
end
%$
end
%$
%$
if t(1) && t(2) && t(3)
%$
t(4) =
dassert
(r1,r2);
%$
t(5) =
dassert
(r1,r3);
%$
end
%$
T = all(t);
% Define an empty dates object with quaterly frequency.
date
=
dates
();
% Define a ranges of dates using qq.
try
r1
=
date
(
4
,
1950
,
1
):
date
(
4
,[
1950
,
3
]);
t
(
1
)
=
true
;
catch
t
(
1
)
=
false
;
end
if
t
(
1
)
try
r2
=
date
(
4
,[
1950
,
1
;
1950
,
2
;
1950
,
3
]);
t
(
2
)
=
true
;
catch
t
(
2
)
=
false
;
end
end
if
t
(
1
)
&&
t
(
2
)
try
r3
=
date
(
4
,
1950
*
ones
(
3
,
1
),
transpose
(
1
:
3
));
t
(
3
)
=
true
;
catch
t
(
3
)
=
false
;
end
end
if
t
(
1
)
&&
t
(
2
)
&&
t
(
3
)
t
(
4
)
=
isequal
(
r1
,
r2
);
t
(
5
)
=
isequal
(
r1
,
r3
);
end
T
=
all
(
t
);
%@eof:6
%@test:7
%$
% Define a dates object
%$
B = dates('1950Q1','1950Q2','1950Q3','1950Q4','1951Q1');
%$
%$
% Try to extract a sub-dates object.
%$
try
%$
d = B([]);
%$
t(1) = true;
%$
catch
%$
t(1) = false;
%$
end
%$
%$
if t(1)
%$
t(2) =
dassert
(isa(d,'dates'), true);
%$
t(3) =
dassert
(isempty(d), true);
%$
end
%$
T = all(t);
% Define a dates object
B
=
dates
(
'1950Q1'
,
'1950Q2'
,
'1950Q3'
,
'1950Q4'
,
'1951Q1'
);
% Try to extract a sub-dates object.
try
d
=
B
([]);
t
(
1
)
=
true
;
catch
t
(
1
)
=
false
;
end
if
t
(
1
)
t
(
2
)
=
isequal
(
isa
(
d
,
'dates'
),
true
);
t
(
3
)
=
isequal
(
isempty
(
d
),
true
);
end
T
=
all
(
t
);
%@eof:7
%@test:8
%$
% Define a dates object
%$
B = dates('1950-11-15','1950-11-16','1950-11-17','1950-11-18');
%$
%$
% Try to extract a sub-dates object.
%$
try
%$
d = B([]);
%$
t(1) = true;
%$
catch
%$
t(1) = false;
%$
end
%$
%$
if t(1)
%$
t(2) =
dassert
(isa(d,'dates'), true);
%$
t(3) =
dassert
(isempty(d), true);
%$
end
%$
T = all(t);
% Define a dates object
B
=
dates
(
'1950-11-15'
,
'1950-11-16'
,
'1950-11-17'
,
'1950-11-18'
);
% Try to extract a sub-dates object.
try
d
=
B
([]);
t
(
1
)
=
true
;
catch
t
(
1
)
=
false
;
end
if
t
(
1
)
t
(
2
)
=
isequal
(
isa
(
d
,
'dates'
),
true
);
t
(
3
)
=
isequal
(
isempty
(
d
),
true
);
end
T
=
all
(
t
);
%@eof:8
%@test:9
%$ % Define a dates object
%$ B = dates('1950-11-15','1950-11-16','1950-11-17','1950-11-18');
%$
%$ % Try to extract a sub-dates object.
%$ d = B(2);
%$
%$ if isa(d,'dates')
%$ t(1) = 1;
%$ else
%$ t(1) = 0;
%$ end
%$
%$ if t(1)
%$ t(2) = dassert(d.freq,B.freq);
%$ t(3) = dassert(d.time,[1950 11 16]);
%$ t(4) = dassert(d.ndat(),1);
%$ end
%$ T = all(t);
% Define a dates object
B
=
dates
(
'1950-11-15'
,
'1950-11-16'
,
'1950-11-17'
,
'1950-11-18'
);
% Try to extract a sub-dates object.
try
d
=
B
(
2
);
t
(
1
)
=
true
;
catch
t
(
1
)
=
false
;
end
if
t
(
1
)
t
(
2
)
=
isequal
(
d
.
freq
,
B
.
freq
);
t
(
3
)
=
isequal
(
d
.
time
(
1
),
712543
)
&&
isnan
(
d
.
time
(
2
));
t
(
4
)
=
isequal
(
d
.
ndat
(),
1
);
end
T
=
all
(
t
);
%@eof:9
\ No newline at end of file
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