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

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

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

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:

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

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

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

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