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
10f5d515
Commit
10f5d515
authored
9 years ago
by
Stéphane Adjemian
Browse files
Options
Downloads
Patches
Plain Diff
Changed the behaviour of the unique method...
As in commit
6beaf7b0
(for the sort method).
parent
e444a33e
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/@dates/subsref.m
+1
-1
1 addition, 1 deletion
src/@dates/subsref.m
src/@dates/unique.m
+72
-11
72 additions, 11 deletions
src/@dates/unique.m
src/@dates/unique_.m
+97
-0
97 additions, 0 deletions
src/@dates/unique_.m
with
170 additions
and
12 deletions
src/@dates/subsref.m
+
1
−
1
View file @
10f5d515
...
...
@@ -36,7 +36,7 @@ switch S(1).type
error
([
'dates::subsref: '
S
(
1
)
.
subs
' is not a method but a member!'
])
end
B
=
builtin
(
'subsref'
,
A
,
S
(
1
));
case
{
'sort'
,
'sort_'
,
'unique'
,
'double'
,
'isempty'
,
'length'
,
'char'
,
'ndat'
}
% Public methods (without input arguments)
case
{
'sort'
,
'sort_'
,
'unique'
,
'
unique_'
,
'
double'
,
'isempty'
,
'length'
,
'char'
,
'ndat'
}
% Public methods (without input arguments)
B
=
feval
(
S
(
1
)
.
subs
,
A
);
if
length
(
S
)
>
1
&&
isequal
(
S
(
2
)
.
type
,
'()'
)
&&
isempty
(
S
(
2
)
.
subs
)
S
=
shiftS
(
S
,
1
);
...
...
This diff is collapsed.
Click to expand it.
src/@dates/unique.m
+
72
−
11
View file @
10f5d515
...
...
@@ -30,13 +30,8 @@ if o.ndat()<=1
return
end
if
isoctave
||
matlab_ver_less_than
(
'8.1.0'
)
[
tmp
,
id
,
jd
]
=
unique
(
o
.
time
,
'rows'
);
else
[
tmp
,
id
,
jd
]
=
unique
(
o
.
time
,
'rows'
,
'legacy'
);
end
o
.
time
=
o
.
time
(
sort
(
id
),:);
o
=
copy
(
o
);
o
.
unique_
();
%@test:1
%$ % Define some dates
...
...
@@ -49,14 +44,80 @@ o.time = o.time(sort(id),:);
%$ % Define expected results.
%$ e.time = [1953 4; 1950 1; 1945 3; 1950 2];
%$ e.freq = 4;
%$ f.time = [1953 4; 1950 2; 1950 1; 1945 3; 1950 2];
%$
%$ % Call the tested routine.
%$ d = dates(B1,B2,B3,B4,B5);
%$ d = d.unique();
%$ try
%$ c = d.unique();
%$ t(1) = true;
%$ catch
%$ t(1) = false;
%$ end
%$
%$ % Check the results.
%$ t(1) = dassert(d.time,e.time);
%$ t(2) = dassert(d.freq,e.freq);
%$ t(3) = size(e.time,1) == d.ndat();
%$ if t(1)
%$ t(2) = dassert(d.time,f.time);
%$ t(3) = dassert(c.time,e.time);
%$ t(4) = dassert(d.freq,e.freq);
%$ end
%$ T = all(t);
%@eof:1
%@test:2
%$ % Define some dates
%$ B1 = '1953Q4';
%$ B2 = '1950Q2';
%$ B3 = '1950q1';
%$ B4 = '1945Q3';
%$ B5 = '1950Q2';
%$
%$ % Define expected results.
%$ e.time = [1953 4; 1950 1; 1945 3; 1950 2];
%$ e.freq = 4;
%$ f.time = [1953 4; 1950 2; 1950 1; 1945 3; 1950 2];
%$
%$ % Call the tested routine.
%$ d = dates(B1,B2,B3,B4,B5);
%$ try
%$ c = unique(d);
%$ t(1) = true;
%$ catch
%$ t(1) = false;
%$ end
%$
%$ % Check the results.
%$ if t(1)
%$ t(2) = dassert(d.time,f.time);
%$ t(3) = dassert(c.time,e.time);
%$ t(4) = dassert(d.freq,e.freq);
%$ end
%$ T = all(t);
%@eof:2
%@test:3
%$ % Define some dates
%$ B1 = '1953Q4';
%$
%$ % Define expected results.
%$ e.time = [1953 4];
%$ e.freq = 4;
%$ f.time = e.time;
%$
%$ % Call the tested routine.
%$ d = dates(B1);
%$ try
%$ c = d.unique();
%$ t(1) = true;
%$ catch
%$ t(1) = false;
%$ end
%$
%$ % Check the results.
%$ if t(1)
%$ t(2) = dassert(d.time,f.time);
%$ t(3) = dassert(c.time,e.time);
%$ t(4) = dassert(d.freq,e.freq);
%$ end
%$ T = all(t);
%@eof:3
This diff is collapsed.
Click to expand it.
src/@dates/unique_.m
0 → 100644
+
97
−
0
View file @
10f5d515
function
o
=
unique_
(
o
)
% --*-- Unitary tests --*--
% Overloads the unique function for dates objects (in place modification).
%
% INPUTS
% - o [dates]
%
% OUPUTS
% - o [dates]
%
% REMARKS
% 1. Only the last occurence of a date is kept.
% Copyright (C) 2013-2015 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
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% Dynare dates submodule is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
if
o
.
ndat
()
<=
1
return
end
if
isoctave
||
matlab_ver_less_than
(
'8.1.0'
)
[
tmp
,
id
,
jd
]
=
unique
(
o
.
time
,
'rows'
);
else
[
tmp
,
id
,
jd
]
=
unique
(
o
.
time
,
'rows'
,
'legacy'
);
end
o
.
time
=
o
.
time
(
sort
(
id
),:);
%@test:1
%$ % Define some dates
%$ B1 = '1953Q4';
%$ B2 = '1950Q2';
%$ B3 = '1950q1';
%$ B4 = '1945Q3';
%$ B5 = '1950Q2';
%$
%$ % Define expected results.
%$ e.time = [1953 4; 1950 1; 1945 3; 1950 2];
%$ e.freq = 4;
%$
%$ % Call the tested routine.
%$ d = dates(B1,B2,B3,B4,B5);
%$ try
%$ d.unique_();
%$ t(1) = true;
%$ catch
%$ t(1) = false;
%$ end
%$
%$ % Check the results.
%$ if t(1)
%$ t(2) = dassert(d.time,e.time);
%$ t(3) = dassert(d.freq,e.freq);
%$ end
%$ T = all(t);
%@eof:1
%@test:1
%$ % Define some dates
%$ B1 = '1953Q4';
%$ B2 = '1950Q2';
%$ B3 = '1950q1';
%$ B4 = '1945Q3';
%$ B5 = '1950Q2';
%$
%$ % Define expected results.
%$ e.time = [1953 4; 1950 1; 1945 3; 1950 2];
%$ e.freq = 4;
%$
%$ % Call the tested routine.
%$ d = dates(B1,B2,B3,B4,B5);
%$ try
%$ unique_(d);
%$ t(1) = true;
%$ catch
%$ t(1) = false;
%$ end
%$
%$ % Check the results.
%$ if t(1)
%$ t(2) = dassert(d.time,e.time);
%$ t(3) = dassert(d.freq,e.freq);
%$ end
%$ T = all(t);
%@eof:1
\ 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