Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1999
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*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

Packed Arrays in version 4

  • To: mathgroup at smc.vnet.net
  • Subject: [mg18963] Packed Arrays in version 4
  • From: John Tanner <john at janacek.demon.co.uk>
  • Date: Fri, 30 Jul 1999 01:33:50 -0400
  • Organization: Peace with the World
  • Sender: owner-wri-mathgroup at wolfram.com

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 at janacek.demon.co.uk
  mantra - curse Microsoft, curse...   work -  john.tanner at 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.



  • Prev by Date: Re: saving a list.
  • Next by Date: Re: how to calculate surfuce and content of ellipse shapes?
  • Previous by thread: Removing Graphics3D polygon edges
  • Next by thread: Help on GroupOpenCloseIcon