Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1999

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

Search the Archive

Re: Packed Arrays in version 4

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

In article <7o5fd0$rgp at>, Ersek, Ted R
<ErsekTR at> writes
>The following should do what you want for Times and you can make a similar
>definition for Transpose.  However, I don't recommend it because it will
>slow done Times in every case when this rule isn't used.
>  HiddenSymbols`ModifyTimes:=
>    Block[{HiddenSymbols`ModifyTimes},
>      Developer`ToPackedArray[Times[z,arr]]
>    ];
>How does it work?
>The above definition is only used when 
>(HiddenSymbols`ModifyTimes=True).  When the rule is used Block
>temporarily clears the value of (HiddenSymbols`ModifyTimes), so
>the kernel doesn't go back and use the rule again.
>Ted Ersek

Thank you, Ted: this is a good solution for Transpose (see also my reply
to Bruno Daniel).  Just by replacing Transpose for Times everywhere (and
a little mixing of arguments) gave a good result.

However I still have great difficulty with Times: I cannot make your
function above give satisfactory results.   I give an example below, it
actually seems to be counter-productive.  Is this because Transpose does
not have Listable (etc.) Attributes like Times?

It has been suggested to me by e-mail that using (N[I]*array) instead of
(I*array) solves the problem, and indeed I had found that
((I+0.0)*array) also solved the problem.  The real problem is that
multiplying a real array by I is so common in electronics/microwaves!  I
have many, many notebooks with many,many,many occurrences of this and I
do not want to start chasing them all down.  Thus I have a real
motivation for making this work as a redefinition of Times or
\[ImaginaryI].  A global redefinition of Global`I := N[System`I] (see my
reply to Bruno Daniel) is probably extremely risky!

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

tmp1 = Table[Random[], {100000}];
tmp2 = Developer`FromPackedArray[tmp1];

{avbytesize[#], Developer`PackedArrayQ[#]} & /@ 
  {tmp1, tmp2,
   Times[tmp1, tmp1], tmp1*tmp2,
   I*tmp1, N[I]*tmp1,
   I*tmp2, N[I]*tmp2}

{{8.00056, True}, {20.0002, False},
 {8.00056, True}, {8.00056, True},
 {60.0002, False}, {16.0006, True},
 {60.0002, False}, {16.0006, True}}


but I dont understand what happens after evaluating your function,
especially mystifying since the results for Transpose were so good:

HiddenSymbols`ModifyTimes = True;
Times[z_Complex, arr_?Developer`PackedArrayQ] /;
HiddenSymbols`ModifyTimes := 
      Developer`ToPackedArray[Times[z, arr]]];

{avbytesize[#], Developer`PackedArrayQ[#]} & /@ 
{tmp1, tmp2, 
 Times[tmp1, tmp1], tmp1*tmp2,
 I*tmp1, N[I]*tmp1,
 I*tmp2, N[I]*tmp2}

{{8.00056, True}, {20.0002, False},
 {20.0002, False}, {20.0002, False},
 {60.0002, False}, {60.0002, False},
 {60.0002, False}, {60.0002, False}}
  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: Re: Biased Random[Integer]?
  • Next by Date: Re: Lists to mask other lists
  • Previous by thread: Re: Packed Arrays in version 4
  • Next by thread: RE: Re: Packed Arrays in version 4