Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
dseries
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Sébastien Villemot
dseries
Commits
677c1e18
Verified
Commit
677c1e18
authored
Dec 11, 2018
by
Stéphane Adjemian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cosmetic changes.
parent
5a198932
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
88 additions
and
118 deletions
+88
-118
src/@dseries/dseries.m
src/@dseries/dseries.m
+1
-1
src/@dseries/subsref.m
src/@dseries/subsref.m
+87
-117
No files found.
src/@dseries/dseries.m
View file @
677c1e18
...
...
@@ -2,7 +2,7 @@ classdef dseries<handle % --*-- Unitary tests --*--
% Class for time series.
% Copyright (C) 2013-201
7
Dynare Team
% Copyright (C) 2013-201
8
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
...
...
src/@dseries/subsref.m
View file @
677c1e18
function
B
=
subsref
(
A
,
S
)
%
--*-
-
Unitary
tests
--*--
%
@info
:
%!
@deftypefn
{
Function
File
}
{
@var
{
us
}
=
}
subsref
(
@var
{
ts
},
S
)
%!
@anchor
{
@dseries
/
subsref
}
%!
@sp
1
%!
Overloads
the
subsref
method
for
the
Dynare
time
series
class
(
@ref
{
dseries
}).
%!
@sp
2
%!
@strong
{
Inputs
}
%!
@sp
1
%!
@table
@
@var
%!
@item
ts
%!
Dynare
time
series
object
instantiated
by
@ref
{
dseries
}.
%!
@item
S
%!
Matlab
'
s
structure
array
S
with
two
fields
,
type
and
subs
.
The
type
field
is
string
containing
'
()
'
,
'
@{
@
}
'
,
or
'.'
,
where
'
()
'
specifies
%!
integer
subscripts
,
'
@{
@
}
'
specifies
cell
array
subscripts
,
and
'.'
specifies
subscripted
structure
fields
.
The
subs
field
is
a
cell
array
%!
or
a
string
containing
the
actual
subscripts
(
see
matlab
'
s
documentation
).
%!
@end
table
%!
@sp
1
%!
@strong
{
Outputs
}
%!
@sp
1
%!
@table
@
@var
%!
@item
us
%!
Dynare
time
series
object
.
Depending
on
the
calling
sequence
@var
{
us
}
is
a
transformation
of
@var
{
ts
}
obtained
by
applying
a
public
method
on
@var
{
ts
},
%!
or
a
dseries
object
built
by
extracting
a
variable
from
@var
{
ts
},
or
a
dseries
object
containing
a
subsample
of
the
all
the
variable
in
@var
{
ts
}.
%!
@end
table
%!
@sp
2
%!
@strong
{
Example
1
.}
Let
@var
{
ts
}
be
a
dseries
object
containing
three
variables
named
'
A1
'
,
'
A2
'
and
'
A3
'
.
Then
the
following
syntax
:
%!
@example
%!
us
=
ts
.
A1
;
%!
@end
example
%!
will
create
a
new
dseries
object
@var
{
us
}
containing
the
variable
'
A1
'
.
%!
@sp
1
%!
@strong
{
Example
2
.}
Let
@var
{
ts
}
be
a
dseries
object
.
Then
the
following
syntax
:
%!
@example
%!
us
=
ts
.
log
;
%!
@end
example
%!
will
create
a
new
dseries
object
@var
{
us
}
containing
all
the
variables
of
@var
{
ts
}
transformed
by
the
neperian
logarithm
.
%!
@sp
1
%!
@strong
{
Example
3
.}
Let
@var
{
ts
}
be
a
dseries
object
.
The
following
syntax
:
%!
@example
%!
us
=
ts
(
3
:
50
);
%!
@end
example
%!
will
create
a
new
dseries
object
@var
{
us
}
by
selecting
a
subsample
out
of
@var
{
ts
}.
%!
@end
deftypefn
%
@eod
:
%
Copyright
(
C
)
2011
-
2017
Dynare
Team
function
r
=
subsref
(
o
,
S
)
% --*-- Unitary tests --*--
% Overloads the subsref method for dseries class.
%
% INPUTS
% - o [dseries] Time series object instantiated by dseries.
% - S [struct] Matlab's structure array S with two fields, type and subs. The type field is
% a string containing '()', '{}', or '.', where '()' specifies integer
% subscripts, '{}' specifies cell array subscripts, and '.' specifies
% subscripted structure fields. The subs field is a cell array or a string
% containing the actual subscripts (see matlab's documentation).
%
% OUTPUTS
% - r [dseries] Depending on the calling sequence `r` is a transformation of `o` obtained
% by applying a public method on `o`, or a dseries object built by extracting
% a variable from `o`, or a dseries object containing a subsample.
% Copyright (C) 2011-2018 Dynare Team
%
% This file is part of Dynare.
%
...
...
@@ -69,37 +39,37 @@ switch S(1).type
if
length
(
S
)
>
1
&&
isequal
(
S
(
2
)
.
type
,
'()'
)
&&
isempty
(
S
(
2
)
.
subs
)
error
([
'dseries::subsref: '
S
(
1
)
.
subs
' is not a method but a member!'
])
end
B
=
builtin
(
'
subsref
'
,
A
,
S
(
1
));
r
=
builtin
(
'subsref'
,
o
,
S
(
1
));
case
'nobs'
% Returns the number of observations.
B
=
rows
(
A
.
data
);
r
=
rows
(
o
.
data
);
case
'vobs'
% Returns the number of variables.
B
=
columns
(
A
.
data
);
r
=
columns
(
o
.
data
);
case
'init'
% Returns a dates object (first date).
B
=
A
.
dates
(
1
);
r
=
o
.
dates
(
1
);
case
'last'
% Returns a dates object (last date).
B
=
A
.
dates
(
end
);
r
=
o
.
dates
(
end
);
case
'freq'
% Returns an integer characterizing the data frequency (1, 4, 12 or 52)
B
=
A
.
dates
.
freq
;
r
=
o
.
dates
.
freq
;
case
'length'
error
([
'dseries::subsref: we do not support the length operator on '
...
'dseries. Please use
''
nobs
''
or
''
vobs
''
'
]);
case
'save'
% Save dseries object on disk (default is a mat file).
B
=
NaN
;
r
=
NaN
;
if
isequal
(
length
(
S
),
2
)
if
strcmp
(
S
(
2
)
.
type
,
'()'
)
if
isempty
(
S
(
2
)
.
subs
)
save
(
A
);
save
(
o
);
else
if
isempty
(
S
(
2
)
.
subs
{
1
})
save
(
A
,
''
,
S
(
2
).
subs
{
2
}
);
save
(
o
,
''
,
S
(
2
)
.
subs
{
2
});
else
save
(
A
,
S
(
2
).
subs
{
:
}
);
save
(
o
,
S
(
2
)
.
subs
{:});
end
end
S
=
shiftS
(
S
,
1
);
...
...
@@ -107,12 +77,12 @@ switch S(1).type
error
(
'dseries::subsref: Wrong syntax.'
)
end
elseif
isequal
(
length
(
S
),
1
)
save
(
A
);
save
(
o
);
else
error
(
'dseries::subsref: Call to save method must come in last position!'
)
end
case
'struct'
B
=
dseries2struct
(
A
);
r
=
dseries2struct
(
o
);
case
{
'baxter_king_filter'
,
'baxter_king_filter_'
,
...
'cumsum'
,
'cumsum_'
,
...
'insert'
,
...
...
...
@@ -149,48 +119,48 @@ switch S(1).type
'resetops'
,
'resettags'
}
if
length
(
S
)
>
1
&&
isequal
(
S
(
2
)
.
type
,
'()'
)
if
isempty
(
S
(
2
)
.
subs
)
B
=
feval
(
S
(
1
).
subs
,
A
);
r
=
feval
(
S
(
1
)
.
subs
,
o
);
S
=
shiftS
(
S
,
1
);
else
B
=
feval
(
S
(
1
).
subs
,
A
,
S
(
2
).
subs
{
:
}
);
r
=
feval
(
S
(
1
)
.
subs
,
o
,
S
(
2
)
.
subs
{:});
S
=
shiftS
(
S
,
1
);
end
else
B
=
feval
(
S
(
1
).
subs
,
A
);
r
=
feval
(
S
(
1
)
.
subs
,
o
);
end
case
'size'
if
isequal
(
length
(
S
),
2
)
&&
strcmp
(
S
(
2
)
.
type
,
'()'
)
if
isempty
(
S
(
2
)
.
subs
)
[
x
,
y
]
=
size
(
A
);
B
=
[
x
,
y
];
[
x
,
y
]
=
size
(
o
);
r
=
[
x
,
y
];
else
B
=
size
(
A
,
S
(
2
).
subs
{
1
}
);
r
=
size
(
o
,
S
(
2
)
.
subs
{
1
});
end
S
=
shiftS
(
S
,
1
);
elseif
isequal
(
length
(
S
),
1
)
[
x
,
y
]
=
size
(
A
);
B
=
[
x
,
y
];
[
x
,
y
]
=
size
(
o
);
r
=
[
x
,
y
];
else
error
(
'dseries::subsref: Call to size method must come in last position!'
)
end
case
{
'set_names'
,
'rename'
,
'rename_'
,
'tex_rename'
,
'tex_rename_'
,
'tag'
}
B
=
feval
(
S
(
1
).
subs
,
A
,
S
(
2
).
subs
{
:
}
);
r
=
feval
(
S
(
1
)
.
subs
,
o
,
S
(
2
)
.
subs
{:});
S
=
shiftS
(
S
,
1
);
case
{
'disp'
}
feval
(
S
(
1
).
subs
,
A
);
feval
(
S
(
1
)
.
subs
,
o
);
return
otherwise
% Extract a sub-object by selecting one variable.
ndx
=
find
(
strcmp
(
S
(
1
).
subs
,
A
.
name
));
ndx
=
find
(
strcmp
(
S
(
1
)
.
subs
,
o
.
name
));
if
~
isempty
(
ndx
)
B
=
dseries
();
B
.
data
=
A
.
data
(:,
ndx
);
B
.
name
=
A
.
name
(
ndx
);
B
.
tex
=
A
.
tex
(
ndx
);
B
.
dates
=
A
.
dates
;
B
.
ops
=
A
.
ops
(
ndx
);
tagnames
=
fieldnames
(
A
.
tags
);
r
=
dseries
();
r
.
data
=
o
.
data
(:,
ndx
);
r
.
name
=
o
.
name
(
ndx
);
r
.
tex
=
o
.
tex
(
ndx
);
r
.
dates
=
o
.
dates
;
r
.
ops
=
o
.
ops
(
ndx
);
tagnames
=
fieldnames
(
o
.
tags
);
for
i
=
1
:
length
(
tagnames
)
B
.
tags
.(
tagnames
{
i
})
=
A
.
tags
.(
tagnames
{
i
})(
ndx
);
r
.
tags
.
(
tagnames
{
i
})
=
o
.
tags
.
(
tagnames
{
i
})(
ndx
);
end
else
error
(
'dseries::subsref: Unknown public method, public member or variable!'
)
...
...
@@ -199,9 +169,9 @@ switch S(1).type
case
'()'
if
ischar
(
S
(
1
)
.
subs
{
1
})
&&
~
isdate
(
S
(
1
)
.
subs
{
1
})
% If ts is an empty dseries object, populate this object by reading data in a file.
if
isempty
(
A
)
if
isempty
(
o
)
if
exist
(
S
(
1
)
.
subs
{
1
},
'file'
)
B
=
dseries
(
S
(
1
).
subs
{
1
}
);
r
=
dseries
(
S
(
1
)
.
subs
{
1
});
else
error
(
'dseries::subsref: Cannot find file %s'
,
S
(
1
)
.
subs
{
1
})
end
...
...
@@ -211,12 +181,12 @@ switch S(1).type
elseif
isscalar
(
S
(
1
)
.
subs
{
1
})
&&
isnumeric
(
S
(
1
)
.
subs
{
1
})
&&
isint
(
S
(
1
)
.
subs
{
1
})
% Input is also interpreted as a backward/forward operator
if
S
(
1
)
.
subs
{
1
}
>
0
B
=
feval
(
'
lead
'
,
A
,
S
(
1
).
subs
{
1
});
r
=
feval
(
'lead'
,
o
,
S
(
1
)
.
subs
{
1
});
elseif
S
(
1
)
.
subs
{
1
}
<
0
B
=
feval
(
'
lag
'
,
A
,
-
S
(
1
).
subs
{
1
});
r
=
feval
(
'lag'
,
o
,
-
S
(
1
)
.
subs
{
1
});
else
% Do nothing.
B
=
A
;
r
=
o
;
end
elseif
isdates
(
S
(
1
)
.
subs
{
1
})
||
isdate
(
S
(
1
)
.
subs
{
1
})
% Select observation(s) with date(s)
...
...
@@ -226,34 +196,34 @@ switch S(1).type
Dates
=
S
(
1
)
.
subs
{
1
};
end
% Test if Dates is out of bounds
if
min
(
Dates
)
<
min
(
A
.
dates
)
error
([
'
dseries
:
:
subsref
:
Indices
are
out
of
bounds
!
Subsample
cannot
start
before
'
date2string
(
A
.
dates
(
1
))
'.'
])
if
min
(
Dates
)
<
min
(
o
.
dates
)
error
([
'dseries::subsref: Indices are out of bounds! Subsample cannot start before '
date2string
(
o
.
dates
(
1
))
'.'
])
end
if
max
(
Dates
)
>
max
(
A
.
dates
)
error
([
'
dseries
:
:
subsref
:
Indices
are
out
of
bounds
!
Subsample
cannot
end
after
'
date2string
(
A
.
dates
(
end
))
'.'
])
if
max
(
Dates
)
>
max
(
o
.
dates
)
error
([
'dseries::subsref: Indices are out of bounds! Subsample cannot end after '
date2string
(
o
.
dates
(
end
))
'.'
])
end
% Extract a subsample using a dates object
[
~
,
tdx
]
=
intersect
(
A
.
dates
.
time
,
Dates
.
time
,
'
rows
'
);
B
=
copy
(
A
);
B
.
data
=
B
.
data
(
tdx
,
:
);
B
.
dates
=
B
.
dates
(
tdx
);
[
~
,
tdx
]
=
intersect
(
o
.
dates
.
time
,
Dates
.
time
,
'rows'
);
r
=
copy
(
o
);
r
.
data
=
r
.
data
(
tdx
,:);
r
.
dates
=
r
.
dates
(
tdx
);
elseif
isnumeric
(
S
(
1
)
.
subs
{
1
})
&&
isequal
(
ndims
(
S
(
1
)
.
subs
{
1
}),
2
)
if
isempty
(
A
)
if
isempty
(
o
)
% Populate an empty dseries object.
if
isempty
(
A
.
dates
)
B
=
copy
(
A
);
B
.
dates
=
dates
(
'
1
Y
'
)
:
dates
(
'
1
Y
'
)
+
(
rows
(
S
(
1
).
subs
{
1
})
-
1
);
B
.
data
=
S
(
1
).
subs
{
1
};
B
.
name
=
default_name
(
columns
(
B
.
data
));
B
.
tex
=
name2tex
(
B
.
name
);
B
.
ops
=
cell
(
length
(
B
.
name
),
1
);
if
isempty
(
o
.
dates
)
r
=
copy
(
o
);
r
.
dates
=
dates
(
'1Y'
):
dates
(
'1Y'
)
+
(
rows
(
S
(
1
)
.
subs
{
1
})
-
1
);
r
.
data
=
S
(
1
)
.
subs
{
1
};
r
.
name
=
default_name
(
columns
(
r
.
data
));
r
.
tex
=
name2tex
(
r
.
name
);
r
.
ops
=
cell
(
length
(
r
.
name
),
1
);
else
B
=
copy
(
A
);
B
.
dates
=
B
.
dates
:
B
.
dates
+
(
rows
(
S
(
1
).
subs
{
1
})
-
1
);
B
.
data
=
S
(
1
).
subs
{
1
};
B
.
name
=
default_name
(
columns
(
B
.
data
));
B
.
tex
=
name2tex
(
B
.
name
);
B
.
ops
=
cell
(
length
(
B
.
name
),
1
);
r
=
copy
(
o
);
r
.
dates
=
r
.
dates
:
r
.
dates
+
(
rows
(
S
(
1
)
.
subs
{
1
})
-
1
);
r
.
data
=
S
(
1
)
.
subs
{
1
};
r
.
name
=
default_name
(
columns
(
r
.
data
));
r
.
tex
=
name2tex
(
r
.
name
);
r
.
ops
=
cell
(
length
(
r
.
name
),
1
);
end
else
error
(
'dseries::subsref: It is not possible to populate a non empty dseries object!'
);
...
...
@@ -263,21 +233,21 @@ switch S(1).type
end
case
'{}'
if
iscellofchar
(
S
(
1
)
.
subs
)
B
=
extract
(
A
,
S
(
1
).
subs
{
:
}
);
r
=
extract
(
o
,
S
(
1
)
.
subs
{:});
elseif
isequal
(
length
(
S
(
1
)
.
subs
),
1
)
&&
all
(
isint
(
S
(
1
)
.
subs
{
1
}))
idx
=
S
(
1
)
.
subs
{
1
};
if
max
(
idx
)
>
size
(
A
.
data
,
2
)
||
min
(
idx
)
<
1
if
max
(
idx
)
>
size
(
o
.
data
,
2
)
||
min
(
idx
)
<
1
error
(
'dseries::subsref: Indices are out of bounds!'
)
end
B
=
dseries
();
B
.
data
=
A
.
data
(
:
,
idx
);
B
.
name
=
A
.
name
(
idx
);
B
.
tex
=
A
.
tex
(
idx
);
B
.
dates
=
A
.
dates
;
B
.
ops
=
A
.
ops
(
idx
);
tagnames
=
fieldnames
(
A
.
tags
);
r
=
dseries
();
r
.
data
=
o
.
data
(:,
idx
);
r
.
name
=
o
.
name
(
idx
);
r
.
tex
=
o
.
tex
(
idx
);
r
.
dates
=
o
.
dates
;
r
.
ops
=
o
.
ops
(
idx
);
tagnames
=
fieldnames
(
o
.
tags
);
for
i
=
1
:
length
(
tagnames
)
B
.
tags
.(
tagnames
{
i
})
=
A
.
tags
.(
tagnames
{
i
})(
idx
);
r
.
tags
.
(
tagnames
{
i
})
=
o
.
tags
.
(
tagnames
{
i
})(
idx
);
end
else
error
(
'dseries::subsref: What the Hell are you tryin
''
to do?!'
)
...
...
@@ -288,7 +258,7 @@ end
S
=
shiftS
(
S
,
1
);
if
~
isempty
(
S
)
B
=
subsref
(
B
,
S
);
r
=
subsref
(
r
,
S
);
end
return
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment