In Mathematica, there is a concept called packed array.
In[1]:= ClearAll[A, B, L1, L2, L3, L4];
A = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30};
B = Range[30];
L1 = Developer`FromPackedArray[A];
L2 = Developer`ToPackedArray[A];
L3 = Developer`FromPackedArray[B];
L4 = Developer`ToPackedArray[B];
In[2]:= A === B === L1 === L2 === L3 === L4
Out[2]= True
In[3]:= {ByteCount[A], ByteCount[B], ByteCount[L1], ByteCount[L2],
ByteCount[L3], ByteCount[L4]}
Out[3]= {768, 360, 768, 360, 768, 360}
For what Mathematica objects, does the concept of 'packed/unpacked' exist? (only for
List
?)We can define compression method (7z/zip/tar/...) or compression level (store/very fast/fast/normal...) for archive utility like 7-zip. Likewise, are there various degrees/methods/kinds of packing in Mathematica? Or it is just 'packed or unpacked' like '0 or 1'.
How can we check/verify a Mathematica object is packed/unpacked ? (+ inspect the degree/methods/kinds)
I have more questions :
- Does
Developer`FromPackedArray
do nothing for unpacked array ? - Does
Developer`ToPackedArray
do nothing for packed array ? - Are there any option for
Developer`FromPackedArray
/Developer`ToPackedArray
? - Are there any other function that can change the state of packed/unpacked (or degrees/methods/kinds) ?
Developer`ToPackedArray
/Developer`FromPackedArray
.ToPackedArray
seem to have at leasttype
andTolerance
options. For checking (+ type and rank) you can useDeveloper`PackedArrayQ
. As noted "successfully pack full lists of any depth containing integer/real/complex numbers". $\endgroup$FromPackedArray[expr]
returns expr unchanged". $\endgroup$