Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


Math Forum » Discussions » Software » 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$rgp@smc.vnet.net>, Ersek, Ted R
<ErsekTR@navair.navy.mil> writes
<Snip>
>---------------------------------------
>
>John,
>
>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.
>
>
>In[1]:=
>HiddenSymbols`ModifyTimes=True;
>Unprotect[Times];
>
>Times[z_Complex,arr_?Developer`PackedArrayQ]/;
> HiddenSymbols`ModifyTimes:=
> Block[{HiddenSymbols`ModifyTimes},
> Developer`ToPackedArray[Times[z,arr]]
> ];
>
>Protect[Times];
>
>------------------
>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.
>
>
>Regards,
>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!

***********example***************
In[1]:=
avbytesize[arr_] := ByteCount[arr]/Length[Flatten[{arr}]] // N

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

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

Out[4]=
{{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:

*********************************
In[5]:=
HiddenSymbols`ModifyTimes = True;
Unprotect[Times];
Times[z_Complex, arr_?Developer`PackedArrayQ] /;
HiddenSymbols`ModifyTimes :=
Block[{HiddenSymbols`ModifyTimes},
Developer`ToPackedArray[Times[z, arr]]];
Protect[Times];

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

Out[9]=
{{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@janacek.demon.co.uk
mantra - curse Microsoft, curse... work - john.tanner@gecm.com
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]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.