write(f, a).
write(f, reshape(a, prod(size(a))))
I need to write a 4 dimensional a array to file and use
write(f, a).
What is the canonical binary representation of a? It looks like the the line above is equivalent to
Is the canonical binary representation going to be machine and OS independent
(except for the endianness)? What about reshape?I am porting code from MATLAB and the specs for the file format are defined by the MATLAB code implementation.
You can write multiple values with the same write
call. i.e. the following are equivalent:
write(stream, x, y...) write(stream, x) + write(stream, y...)
write(stream, x); write(stream, y...)
Matlab arrays are also column major, so reading a Matlab-produced binary format is probably straightforward, but you have to be careful of the byte order. Obviously, you'll have to read the documentation on your file format carefully. Whatever the format is, however, Julia offers enough low-level control to read and write it efficiently.
write on a numeric array will output the raw bytes, i.e. Column-major data in the native byte order.