Am 24.11.2017 um 23:29 schrieb Allin Cottrell:
In the course of some recent experimentation I found it useful to
have a
built-in function to "flatten" an array of matrices to one big matrix,
and I enabled such a function in my working copy of the gretl sources.
The function in question takes as argument 1 an array of matrices and as
argument 2 either "hcat" or "vcat": in the hcat case the member
matrices
are concatenated horizontally (which requires that they all have the
same number of rows); under vcat they're concatenated vertically
(requiring a common number of columns). In either case a hansl function
could be written quite easily to do the job, but a built-in function is
likely a good deal faster.
Anyway, my particular need for this function has passed but I was
wondering if others would find it useful. If so I can add it to git, if
not I'll quietly retire it.
My spontaneous reaction is of course, yes give me that function. But
still, some thoughts on that.
First, since the reason is speed, then I guess it would be natural to
have the converse as an internal function as well: something like
"mat2array" which takes a big matrix and puts equal-sized chunks in
array elements.
OTOH, when we think about why do we want all that conversion and
transfers, probably the underlying reason is that there are things that
cannot be done with arrays (easily). In that sense, maybe an alternative
would be to extend some (all?) functions that operate on matrix
arguments to cover matrices arrays as well: For example:
matrices mm = defarray(ones(1,2), zeros(1,2))
matrices smm = sin(mm)
This would be understood as "apply the usual function meaning to every
element in the array".
Then perhaps having conversion functions array-to-matrix and vice versa
might be much less important.
cheers,
sven