I can't see that Repa specifies memory layouts for the data in any of its "manifest representations". Is this specified somewhere?
Of course I can find out through experimentation, but I'd rather know if the layout is official or prone to change at any time.
Edit: To clarify, I understand how a Storable
Vector
is laid out, but I wonder whether Array U DIM2 Double
(for example) is row-major, column-major, or something crazy.
The memory layouts for data are defined by their type class instances of unboxed vectors:
The implementation uses @Data.Vector.Unboxed@ which is based on type families and picks an efficient, specialised representation for every element type. In particular, unboxed vectors of pairs are represented as pairs of unboxed vectors.
To see the layout specification of vectors, check the instances for unboxed vectors defined in the vector package, where e.g. Bool is represented with bytes:
newtype instance MVector s Bool = MV_Bool (P.MVector s Word8)
while if we dive down the rabbit hole to the primitive arrays package, you see the alignment and size constraints for the primitive types. According to Repa 1, manifest (allocated) arrays are filled in row major. The docs for the latest version also support this.
I have to do some FFI with the data as well, so getting the layout straight
Since you have to interoperate with C code (or something else), then it is vital to use Storable instances. These will guarantee that your types can be easily transferred to C (using C layout conventions, via the ForeignPtr interface to Repa, which ensures you safely map pointers to C-shaped foreign data to and from Repa.