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: Packed Arrays in version 4
Replies: 2   Last Post: Aug 5, 1999 2:28 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
Packed Arrays in version 4
Posted: Jul 30, 1999 1:59 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

The use of Packed Arrays on version 4 is a huge boon: this means that
much larger problems can be handled directly in the kernel. There are a
few cases however when "trivial" operations on PackedArrays mean that a
conventional unpacked array results: while this is very "safe" it can be
annoying, and quite difficult to modify existing code to make the best
use of the new capabilities.

The two most severe cases are:

(1) multi-dimensional transposes

(i.e. "Transpose[packedarray]" returns a packed array, but
"Transpose[packedarray,{3,2,1}]" returns an unpacked List.)

(2) conversion of an Integer or Real PackedArray to Complex (e.g. by
multiplication by \[ImaginaryI] )

(i.e. "Times[I,realpackedarray]" returns an unpacked list,
which is especially nasty for such classic constructs as
"Exp[I*2*Pi*realpackedarray]")

In both cases it seems only possible to recover some of the speed and
storage space improvement by wrapping the offending construct with
Developer`ToPackedArray[] as early as possible.

At this point I get stuck! How is it possible to redefine built-in
functions such as Transpose and \[ImaginaryI] (and similar, less
important cases...) so that this occurs automatically? I really do not
wish to completely redefine all of the Mathematica built-in commands
within my own commands (e.g. myTranspose).

With Transpose, I can get part way: the pattern matching works:

Unprotect[Transpose];
Transpose[arr_?Developer`PackedArrayQ, extraargs_] :=
myTranspose[arr, extraargs];
Protect[Transpose]

the problem is that this causes infinite recursion (i.e. once it
identifies a PackedArrayQ argument, it keeps on calling Transpose
recursively since myTranspose calls Transpose with a PackedArray
argument....).

With \[ImaginaryI], it does not seem possible to redefine \[ImaginaryI]
itself, and attempts to overload Times, Plus etc. fail since the pattern
match "Times[\[ImaginaryI],a_?Developer`PackedArrayQ,b___]" fails
(why?).

I must be missing something(s) simple, all suggestions welcome.
--
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.