I'm having difficulty loading binary data from a file into a tensor, where the data is of different types. The final tensor is of a single float type.
For example, the byte stream is a double followed by an integer -- f0, f1, ..., f7, i0, i1, i2, i3.
I can't seem to find the method to coerce 8 bytes into a lua float or the 4 int bytes into a float.
Using bytes = tensor.ByteStorage(file) as the input stream treats each element independently and doesn't allow coercion of slices.
Similarly, ffi.cast('float', ...) doesn't appear to function with bytes:cdata() or bytes:data() as the 2nd arg.
Is there nothing in the language that will allow coercion?
Using the struct package and unpack() does provide a solution, but this requires the input as a string. I'm trying to avoid this for both performance reasons and that string uses lua-land data which is limited.
What's the best way to deal with this?
Thanks!