On Wed, 2 Nov 2011, Riccardo (Jack) Lucchetti wrote:
On Tue, 1 Nov 2011, Allin Cottrell wrote:
> (b) Row and/or column names are attached to the gretl_matrix struct
> itself, rather than the wrapper. That is more plausible, but I still
> don't like it much. The extra memory required for an empty
> gretl_matrix would only be two pointers (8 bytes on a 32-bit system)
> but it represents additional complexity that I'd prefer to keep out
> of what is in concept a mathematical type.
I agree: matrices should stay as lean-and-mean as possible.
Besides, there is the possibility of achieving Artur's
original aim in Hansl, albeit in a way that most people will
find a bit convoluted: here's two ways to do it [...]
Thanks, Jack. These functions nicely illustrate what you can
do with bundles.
But after some more thinking I think I may have come up with a
solution to the matrix column/row names issue which satisfies
the "lean and mean" criterion as well as allowing a simple way
to return decorated matrices from functions.
The thing is, we already have some "metadata" in the
gretl_matrix struct, namely the two integer members "t1" and
"t2". These are bloat from the point of view of pure matrix
arithmetic, but gretl needs them in many contexts for keeping
track of the alignment between matrices and series. My new
idea is this:
Remove t1 and t2 as members of gretl_matrix and replace them
with a single pointer member (so gretl_matrix becomes leaner
by 4 bytes). This pointer member is just NULL by default, but
one it's allocated it has space to record t1 and t2, as well
as column and/or row names if wanted.
The metadata struct that can be allocated on a gretl_matrix is
a private thing that lives in gretl_matrix.c. Anything you
want to do with it (get/set t1, t2 or names) you do via
accessor functions -- and the "set" accessors take care of
allocating the storage as needed.
I'm not committing this change just yet since it needs more
testing, but I'm hopeful it'll do the job.
Allin