Verified Commit 507ec822 authored by Stéphane Adjemian's avatar Stéphane Adjemian
Browse files

Add new comparison methods.

Closes #4.

*Example*

>> a = dseries(randn(4,5),'2000Q1')

a is a dseries object:

       | Variable_1 | Variable_2 | Variable_3 | Variable_4 | Variable_5
2000Q1 | 2.4245     | -1.036     | -0.87587   | -0.57001   | -1.6989
2000Q2 | 0.9594     | 1.8779     | 0.31995    | -1.0257    | 0.6076
2000Q3 | -0.31577   | 0.9407     | -0.55829   | -0.90875   | -0.1178
2000Q4 | 0.42862    | 0.78735    | -0.31143   | -0.2099    | 0.69916

>> a.Variable_3>0

ans =

  4x1 logical array

   0
   1
   0
   0

>> a(a.Variable_3>0)

ans is a dseries object:

       | Variable_1 | Variable_2 | Variable_3 | Variable_4 | Variable_5
2000Q2 | 0.9594     | 1.8779     | 0.31995    | -1.0257    | 0.6076
parent 5f829d00
Pipeline #5366 passed with stage
in 2 minutes and 16 seconds
function l = ge(varargin) % --*-- Unitary tests --*--
% Overloads the >= operator for dseries objects.
% Copyright © 2021 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 isreal(varargin{2}) && isdseries(varargin{1})
l = varargin{1}.data>=varargin{2};
elseif isreal(varargin{1}) && isdseries(varargin{2})
l = varargin{1}>=varargin{2}.data;
elseif isdseries(varargin{1}) && isdseries(varargin{2})
l = varargin{1}.data>=varargin{2}.data;
else
error('dseries::ge: wrong types.')
end
\ No newline at end of file
function l = gt(varargin) % --*-- Unitary tests --*--
% Overloads the > operator for dseries objects.
% Copyright © 2021 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 isreal(varargin{2}) && isdseries(varargin{1})
l = varargin{1}.data>varargin{2};
elseif isreal(varargin{1}) && isdseries(varargin{2})
l = varargin{1}>varargin{2}.data;
elseif isdseries(varargin{1}) && isdseries(varargin{2})
l = varargin{1}.data>varargin{2}.data;
else
error('dseries::gt: wrong types.')
end
\ No newline at end of file
function l = le(varargin) % --*-- Unitary tests --*--
% Overloads the <= operator for dseries objects.
% Copyright © 2021 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 isreal(varargin{2}) && isdseries(varargin{1})
l = varargin{1}.data<=varargin{2};
elseif isreal(varargin{1}) && isdseries(varargin{2})
l = varargin{1}<=varargin{2}.data;
elseif isdseries(varargin{1}) && isdseries(varargin{2})
l = varargin{1}.data<=varargin{2}.data;
else
error('dseries::le: wrong types.')
end
\ No newline at end of file
function l = lt(varargin) % --*-- Unitary tests --*--
% Overloads the < operator for dseries objects.
% Copyright © 2021 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 isreal(varargin{2}) && isdseries(varargin{1})
l = varargin{1}.data<varargin{2};
elseif isreal(varargin{1}) && isdseries(varargin{2})
l = varargin{1}<varargin{2}.data;
elseif isdseries(varargin{1}) && isdseries(varargin{2})
l = varargin{1}.data<varargin{2}.data;
else
error('dseries::lt: wrong types.')
end
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment