The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Inactive » comp.soft-sys.math.mathematica

Topic: RE: [mg18963] Packed Arrays in version 4
Replies: 1   Last Post: Aug 5, 1999 2:29 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
John Tanner

Posts: 10
Registered: 12/7/04
Re: [mg18963] Packed Arrays in version 4
Posted: Aug 5, 1999 2:29 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

In article <7o5fd0$>, Ersek, Ted R
<> 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 -
mantra - curse Microsoft, curse... work -
I hate this 'orrible computer, I really ought to sell it:
It never does what I want, but only what I tell it.

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2017. All Rights Reserved.