On Wed, 21 Feb 2018, Sven Schreiber wrote:
Am 20.02.2018 um 17:11 schrieb Sven Schreiber:
> So Allin had the great idea to enable binary-mode transfer between Python
> and Gretl, and I tried it. [...]
One more follow-up on this. We should probably aim to extend the
binary matrix transfer facility for R too, and maybe octave. But I'm
not going to hold the next release for that; and I should point out
that it can be a little fiddly, for two reasons.
1) The gretl_matrix struct employs column-major order, and when we
write or read matrices in binary mode we just dump out, or read in,
all the values in that order. So when implementing a "foreign"
transfer it's important to check the code via round-tripping. In the
case of Julia, for example, when reading a binary matrix written by
gretl we can't just read (rows * cols) doubles in directly, we have to
place the values properly, as in
for j=1:c
for i=1:r
M[i,j] = read(f, Float64)
end
end
as opposed to "read(f, Float64, r*c)", which would scramble the
matrix!
2) In gretl_binary_matrix files we standardized on little-endian
format. Pretty much everything is little-endian these days, but all
the same we should guard against getting total garbage in the case of
mixing byte-orders. In the unlikely event that Python or Julia are
running on a big-endian machine we need to convert to little-endian
format on writing, and from little-endian format on reading.
Both of these points are handled in the facilities for Python and
Julia in current git.
Allin