0
$\begingroup$

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}
  1. For what Mathematica objects, does the concept of 'packed/unpacked' exist? (only for List?)

  2. 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'.

  3. How can we check/verify a Mathematica object is packed/unpacked ? (+ inspect the degree/methods/kinds)

I have more questions :

  1. Does Developer`FromPackedArray do nothing for unpacked array ?
  2. Does Developer`ToPackedArray do nothing for packed array ?
  3. Are there any option for Developer`FromPackedArray/Developer`ToPackedArray ?
  4. Are there any other function that can change the state of packed/unpacked (or degrees/methods/kinds) ?
$\endgroup$
5
  • 1
    $\begingroup$ Surprisingly it has been documented Developer`ToPackedArray/Developer`FromPackedArray. ToPackedArray seem to have at least type and Tolerance options. For checking (+ type and rank) you can use Developer`PackedArrayQ. As noted "successfully pack full lists of any depth containing integer/real/complex numbers". $\endgroup$
    – Ben Izd
    Commented May 9, 2022 at 4:41
  • $\begingroup$ And "If expr is not a packed array, FromPackedArray[expr] returns expr unchanged". $\endgroup$
    – Ben Izd
    Commented May 9, 2022 at 4:41
  • 2
    $\begingroup$ Does this answer your question: mathematica.stackexchange.com/questions/3496/… -- by "array" whether packed or unpacked is meant a list (vector), a rectangular list of lists (matrix), or higher-rank tensor. "Packed" is applied only to arrays (currently). $\endgroup$
    – Michael E2
    Commented May 9, 2022 at 4:48
  • 2
    $\begingroup$ Also related: mathematica.stackexchange.com/questions/5258/… $\endgroup$
    – Michael E2
    Commented May 9, 2022 at 4:54
  • $\begingroup$ Thank you, now I knew something, I want to write something(the answer) in my question if I have time, but only helpful for beginner. $\endgroup$
    – imida k
    Commented May 9, 2022 at 20:37

0