MathGroup Archive 1999

[Date Index] [Thread Index] [Author Index]

Search the Archive

RE: Packed Array Angst

  • To: mathgroup at
  • Subject: [mg20992] RE: [mg20962] Packed Array Angst
  • From: "Ersek, Ted R" <ErsekTR at>
  • Date: Thu, 2 Dec 1999 21:41:07 -0500 (EST)
  • Sender: owner-wri-mathgroup at

Mark Reeve wrote:
I've been experimenting with packed arrays and have observed that a
number of common functional programming constructs force unpacking, thus
greatly lessening the utility of packed arrays.

For example:  Transpose, Inner, Outer, and MapThread.  The latter is
particularly annoying.  I should clarify that for a 2-D array (and
possibly for higher-dimensions as well), Transpose[arr], works just fine
and preserves packing.  But if the user specifies a permutation vector,
even the trivial Transpose[arr2d,{1,2}], unpacking occurs.

Another nasty thing is that if "a" and "b" are two packed arrays, the
composite c={a,b} is not, although c[[1]] and c[[2]] are still each

Has anyone found a way around some of these limitations?  A generic
replacement for MapThread which preserves packing?  I have experimented
with several forms but have so far only run into further limitations.


Come on there are hundreds of cases, and there are bound be some where this
could be improved, and I expect it will improve in future versions. In the
mean time it might help to use the functions Developer`ToPackedArray,
Developer`PackedArrayQ. They are documented in the Help Browser.

A more serious problem is a bug that was discussed here earlier. Below I
copy a summary that I posted earlier.


I have more on the 4.0 bug reported by 
(slinger at  The following code gives a simple yet
practical demonstration of the problem.

ideal={1.5 + 0.2 I, 2.3 + 0.4 I};

{2.68701 + 0.424264 I, -0.565685 - 0.141421 I}


{1.5 + 1.5 I, -0.565685 - 0.141421 I}

Of course the first part in Out[4] should be 
(1.5 + 0.2 I)
We all agree this is a bug.

As far as I can tell we don't have the problem when ReplacePart is used (as
below).  This solution allows one to keep the advantages of packed arrays,
and I think it's more direct than using Part anyway.

{1.5 + 0.2*I, -0.565686 - 0.141421 I}

ReplacePart[output, 1.5+0.2I, 1]

{1.5 + 0.2 I, -0.565685 - 0.141421 I}


We can also unpack the complex array we get from Fourier, and we get the
right result using Part as below.


{1.5 + 0.2 I, -0.565685 - 0.141421 I}

As indicated in an earlier message the error seems to occur when using Part
to change a value in a complex, packed array.

Ted Ersek

For Mathematica tips, tricks see

  • Prev by Date: Re: date/time ListPlot
  • Next by Date: Re: MathLink Data Types
  • Previous by thread: Packed Array Angst
  • Next by thread: Re: Packed Array Angst