MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Mixed tensors as arguments of compiled functions

On 5/29/06 at 6:05 AM, bilotta78 at (Giuseppe Bilotta) wrote:

>I am trying to thoroughly optimize my code, and was now looking into
>compiled functions. A problem I have is that some of the structures
>I need to manipulate are matrices of the form {{_Integer,_Real}..}),
>but Mathematica only allows me to specify tensors whose elements are
>all of the same type. Is there a way to work around this limitation?

It simply isn't true Mathematica only allows matrices to be defined with a single type. For example here is a matrix having the form {{_Integer, _Real} ... }

a = Table[{n, Random[]}, {n, 5}];

and this can easily be manipulated with say


{{1, 0.777778}, {4, 0.488225}, {9, 0.522976}, 
 {16, 0.509629}, {25, 0.948508}}

However, several things used by Mathematica to enhance performance will not be in effect with arrays of mixed type elements. For example Mathematica does not use packed arrays with arrays of the form {{_Integer,_Real} ...}.

The only way to be able to take advantage of those performance enhancements would be to separate the various types. For an array with this particular structure, defining two new variables, i.e.,

c = a[[All,1]];
d = a[[All,2]];

should effective usage of packed arrays, Compile etc.
To reply via email subtract one hundred and four

  • Prev by Date: Re: Discrete Functions... Signal Simulation... A Study Using Mathematica
  • Next by Date: Re: Defining N for a new entity
  • Previous by thread: Mixed tensors as arguments of compiled functions
  • Next by thread: Re: Mixed tensors as arguments of compiled functions