FromPackedArray¶
Status: Stable
documented, exercised by the test suite and/or worked examples, with no known limitations recorded.
Description¶
FromPackedArray[expr]
is FromNDArray[expr]: it returns expr with any dense buffer storage undone, so a packed List becomes an ordinary List of separate elements and an NDArray[...] becomes the nested List of its entries. Provided under Mathematica's name for the same operation; see FromNDArray.
Examples (6)¶
Every input below was run against the current Mathilda build and its output recorded.
Basic examples (3)¶
In[1]:= FromPackedArray[ToPackedArray[{1., 2., 3., 4.}]]
Out[1]= {1.0, 2.0, 3.0, 4.0}
In[2]:= NDArrayQ[FromPackedArray[ToPackedArray[{1., 2., 3., 4.}]]]
Out[2]= False
In[3]:= FromPackedArray[NDArray[{1., 2., 3.}]]
Out[3]= {1.0, 2.0, 3.0}
Applications (3)¶
Mathematica's name; undoes the buffer
The result is an ordinary List
Unpacks a visible NDArray too
Implementation notes¶
Algorithm. FromPackedArray is Mathematica's name (DeveloperFromPackedArray) for
FromNDArray and is the same C builtin (builtin_fromndarray) registered under a second
name — an aliased builtin, not a DownValue that rewrites to the other, so it costs no extra
evaluation pass and cannot be shadowed. It undoes both forms of buffer storage: a packed
List becomes an ordinary List of separate element nodes (NDArrayQ then False), and a
visible NDArray[...] becomes the nested List of its entries (ndarray_to_nested_list).
Anything that is not an EXPR_NDARRAY is returned unchanged. It is the inverse of
ToPackedArray.
Data structures. Reads the dense row-major buffer and allocates one boxed Expr leaf per
element (Integer/Real/True/False by dtype), rebuilding the nested List from the
stored int64 dims.
Complexity / limits. O(n), allocating an expression node per element — the per-element
cost packing avoids, so this is where a large array stops being cheap to hold. The value is
unchanged; only the representation differs.
Attributes: Protected.
References¶
See also: FromNDArray, ToPackedArray, List
- Source:
src/pack.c - Specification:
docs/spec/builtins/packed-arrays.md - Tests:
tests/test_dirichletl.c - Tests:
tests/test_elliptic_machine.c - Tests:
tests/test_erf.c - Tests:
tests/test_erfc.c
Notes & additional examples¶
Notes¶
FromPackedArray is the Wolfram Language's name (DeveloperFromPackedArray) for
FromNDArray, and is the same builtin registered twice — not a rule that rewrites to the
other — so it costs no extra evaluation pass and cannot be shadowed. It undoes both forms of
buffer storage: a packed List becomes an ordinary List of separate elements (so NDArrayQ
is then False), and a visible NDArray[...] becomes the nested List of its entries.
Anything else is returned unchanged. It is the inverse of ToPackedArray.
The value is unchanged; only the representation differs. Like FromNDArray, it allocates one
expression node per element — the per-element cost that packing avoids.