Re: Mixed tensors as arguments of compiled functions

*To*: mathgroup at smc.vnet.net*Subject*: [mg66821] Re: Mixed tensors as arguments of compiled functions*From*: Giuseppe Bilotta <bilotta78 at hotpop.com>*Date*: Wed, 31 May 2006 06:31:38 -0400 (EDT)*References*: <e5h63c$eub$1@smc.vnet.net>*Sender*: owner-wri-mathgroup at wolfram.com

On Tue, 30 May 2006 10:17:16 +0000 (UTC), Bill Rowe wrote: > On 5/29/06 at 6:05 AM, bilotta78 at hotpop.com (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 > > In[14]:= > a^2 > > Out[14]//InputForm= > {{1, 0.777778}, {4, 0.488225}, {9, 0.522976}, > {16, 0.509629}, {25, 0.948508}} Sorry if my phrasing seemed to suggest I thought Mathematica didn't allow mxied-type matrices at all. I was only talking specifically about Compiled functions. > 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. Yes, I'm starting to see that, so I guess I will have to redesign the structure of my data. Thanks for your help. -- Giuseppe "Oblomov" Bilotta Hic manebimus optime