# Compression results in unpacking of integers but not reals

Consider the following;

Pack some integers.

In[287]:= Clear[p5i, p5ic, p5icu, p5r, p5rc, p5rcu]
In[288]:= p5i = ToPackedArray@Range@5

Out[288]= {1, 2, 3, 4, 5}


Pack some reals.

In[289]:= p5r = ToPackedArray@N@Range@5

Out[289]= {1., 2., 3., 4., 5.}

In[290]:= PackedArrayQ@# & /@ {p5i, p5r}

Out[290]= {True, True}


Now let's compress and decompress.

In[298]:= p5ic = Compress@p5i
p5rc = Compress@p5r

Out[298]= "1:eJxTTMoPSmNlYGAoZgESPpnFJZ6MQIYhmDQCk8Zg0gRMmgIAufkGNA=="

Out[299]= "1:eJxTTMoPSmVkYGBgZYCBD/ZQhgOE4oDSAlBaxAEAi8sECw=="

In[300]:= p5icu = Uncompress@p5ic
p5rcu = Uncompress@p5rc

Out[300]= {1, 2, 3, 4, 5}

Out[301]= {1., 2., 3., 4., 5.}

In[302]:= PackedArrayQ@# & /@ {p5ic, p5rc, p5icu, p5rcu}

Out[302]= {False, False, False, True}


Now the fact that the compressed versions are not packed isn't too surprising, given that they are essentially ASCII strings (that's my understanding). However, it appears that packing is preserved for reals on compression and decompression but not for integers.

Please could someone explain to me why this should be the case.

• Unrelated to your main issue, but you don’t need to build a pure function to map a function with one argument over a list as in PackedArrayQ@# & /@ {...}. Instead PackedArrayQ /@ {...} will do. Jan 15 at 13:33
• @MarcoB - it may not be related, but nonetheless I am grateful to you for pointing this out as I am always looking to improve my WL skills. Previously I'd thought that a function needed to be Listable for this to be true. Thanks once again. Jan 15 at 14:47

There is an undocumented Method option to Compress that you can use to control this. A packed integer array:

p = Range[10];
DeveloperPackedArrayQ @ p


True

Using Compress:

c = Compress[p, Method -> {Version -> 6}];
u = Uncompress[c];
DeveloperPackedArrayQ @ u


True

• Thanks for this. I wonder why this changed between versions. Jan 15 at 18:45