# Nested list can not be packed?

Why can't nested list be packed?

In[252]:= ftest = {1., {3.}};
ftest = DeveloperToPackedArray[ftest];
DeveloperPackedArrayQ[ftest]


Out[254]= False

• Only tensors (passes ArrayQ[]) can be packed. {{1.}, {3.}}, {{1., 3.}}, and {1., 3.} can all be packed, but yours can't. – J. M. is away Mar 30 '16 at 5:07
• Thanks! I guess it has something to do how memory can be allocated. – Al Guy Mar 30 '16 at 5:12
• (P.S. could anyone who can link to the appropriate place in the docs answer this question for me? I promise to upvote. ;)) – J. M. is away Mar 30 '16 at 5:14
• @J.M. _"Packed arrays are a representation for rectangular tensors of machine integers, machine reals, and complex numbers with real and imaginary parts that are machine reals." reference.wolfram.com/mathematica/tutorial/… – Dr. belisarius Mar 30 '16 at 5:18
• Just think about how you would implement such a data structure in a low-level language like C. It's much more complicated than dealing with a rectangular array. For a rectangular array you only need to store its data and its dimensions, and indexing into it is trivial. That's what "packed" means here: use one flat block of memory, which is very fast. For a ragged 2D array you'd likely have multiple 1D sub-arrays allocated separately and a pointer vector with references to each. Each sub-array needs to store its length separately. This is exactly what a non-packed list is. – Szabolcs Mar 30 '16 at 7:31

Per J.M.'s and Dr. Belisarius's comment:

Only tensors passing ArrayQ can be packed. Any of {{1.}, {3.}}, {{1., 3.}}, and {1., 3.} can be packed, but ragged, non-rectangular lists (e.g. {{1, 2}, {3, 4, 5}} or {1, {2}, 3}) cannot.

"Packed arrays are a representation for rectangular tensors of machine integers, machine reals, and complex numbers with real and imaginary parts that are machine reals"

lists = N@{
{{1}, {3}},
{{1, 3}},
{1, 3},
{1},
{1, 2},
{1, {2}, 3},
{{1, 2}, {3, 4, 5}}
};
ArrayQ /@ lists
packed = DeveloperToPackedArray /@ lists;
DeveloperPackedArrayQ /@ packed

{True, True, True, True, True, False, False} (* ArrayQ *)

{True, True, True, True, True, False, False} (* PackedArrayQ *)


from the documentation.