MathGroup Archive 1999

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

Search the Archive

Re: Packed Arrays in version 4

  • To: mathgroup at
  • Subject: [mg19081] Re: Packed Arrays in version 4
  • From: John Tanner <john at>
  • Date: Thu, 5 Aug 1999 01:35:03 -0400
  • Organization: Peace with the World
  • References: <7nrevk$> <7o5h0k$>
  • Sender: owner-wri-mathgroup at

In article <7o5h0k$rjs at>, Bruno Daniel
<bruno.daniel at> writes
>Hi John
>You could use contexts: Define a new context "Efficient`" and put it
>in front of "System`" in the context search path. Then you can 
>define your own "Transpose" etc inside this context and use the
>built-in "Transpose" by fully qualifying it (System`Transpose) in
>the implementation of your "Transpose".
>Here's an example how this can be done in the context "Global`":
>In[1]:= Global`Transpose[x_]:= System`Transpose[x] + a
>In[2]:= Transpose[{{c,d,e}}]
>Out[2]:= {{a+c},{a+d},{a+e}}
>Yours sincerely
>  Bruno

Thank you: that is really neat, and I really appreciate not having to
Unprotect and modify the System definition.

This works well for Transpose, and for other functions which "sometimes"
unpack PackedArrays.  My list so far of "higher level" functions with
this behaviour is:

  (1) Transpose: a multidimensional Transpose always unpacks

  (2) Outer:     always unpacks

  (3) Map:       usually OK but can surprise you (see below)

What I intend to do at present is to modify Transpose and Outer (and
possibly also Map) as suggested above and/or by Ted Ersek (MG18963) -
thank you both.

I give some illustrations here of 3 different ways of doing exactly the
same thing, with 3 wholly different results (i.e. "Packed", "Unpacked"
and "List of Packed" for Dot, Outer and Map).  Yes I know that Dot is
the best to use in this case, but the choice is not so simple for
functions other than Times!

avbytesize[arr_] := ByteCount[arr]/Length[Flatten[{arr}]] // N

arr1 = Range[1., 10.];
arr2 = Range[1., 100.];

arr1dot2 = Transpose[{arr1}].{arr2};
arr1outer2 = Outer[Times, arr1, arr2];
arr2map1 = arr2*# & /@ arr1;

Dimensions[#] & /@ {arr1, arr2, arr1dot2, arr1outer2, arr2map1}

{{10}, {100}, {10, 100}, {10, 100}, {10, 100}}

avbytesize[#] & /@ {arr1, arr2, arr1dot2, arr1outer2, arr2map1}

{13.6, 8.56, 8.06, 20.296, 8.616}

Developer`PackedArrayQ[#] & /@ {arr1, arr2, arr1dot2, arr1outer2,

{True, True, True, False, False}

A much more risky redefinition to get around the problem of
Times[I*realarray] is also possible, since redefinition of Times seems
to be very problematic (see my reply to Ted Ersek(MG18963)): 

Global`I := N[System`I]

I am still struggling with the full implications of this - I suspect it
would seriously mess up symbolic simplifications.

Thank you,

  from -   John Tanner                 home -  john at
  mantra - curse Microsoft, curse...   work -  john.tanner at
I hate this 'orrible computer,  I really ought to sell it:
It never does what I want,      but only what I tell it.

  • Prev by Date: need help.
  • Next by Date: Re: equaltity of lists
  • Previous by thread: Re: Packed Arrays in version 4
  • Next by thread: Re: Packed Arrays in version 4