Arthur Anger <[email protected]> wrote:
> I have long envisioned the storage of a Level-0 array as a string prefixed by
> a shape vector. I have seldom tried to envision the storage of a nested
> array, which must be a nest of such prefixed strings.
In the off chance you are not aware of of (3!:3), it let's you peek at the
internal representation of J nouns. I find it empowering to have a clear mental
image of how J represents my data in memory. Here is what I have pieced
together in the past from poking around:
3!:3 i. 2 3 4
e300000000000000
0400000000000000
1800000000000000
0300000000000000
0200000000000000
0300000000000000
0400000000000000
0000000000000000
0100000000000000
0200000000000000
0300000000000000
0400000000000000
0500000000000000
...
Each line is a machine word (either 32 or 64 bytes). The very first byte tells
J the endianness and word size. See jsrc/xb.c in the source for details, but in
this case 0xe3 specifies that we have 64-bit words in little endian byte order.
The next word---here 0x04---specifies the type. The documentation for (3!:0)
tells us what the numbers in this slot mean. In this case 4 means "integer".
The next word, 0x18, specifies the tally of atoms in our array, i.e. (#@,). In
this case 2*3*4 = 24 = 0x18. So far so good.
Next, we have 0x03. This word specifies the rank of our array. In particular it
tells us how many words we need to specify the array's shape. The subsequent
such words specify rank, here 0x02, 0x03, and 0x04.
Finally, we have the array of atoms itself. Of note is the fact that the memory
layout of the actual atoms doesn't depend on the array's rank.
Pretty clean!
Check out how boxed arrays are represented. Really good stuff.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm