Re: How to return a mixture of vectors and matrices from compiled functions

*To*: mathgroup at smc.vnet.net*Subject*: [mg79657] Re: How to return a mixture of vectors and matrices from compiled functions*From*: yatesd at mac.com*Date*: Wed, 1 Aug 2007 05:02:48 -0400 (EDT)*References*: <f89r26$65j$1@smc.vnet.net>

Don't know the answer, but noticed the following: (1) Your sample above has a 0 instead of 0. in the second row, last entry of the matrix. So not all the entries are Real. (2) I corrected (1) and you still get the same error. I suspect your hunch about packed arrays is correct. Developer`ToPackedArray never returns an error. The only way I know to see if it really did pack the array is to do Developer`PackedArrayQ[Developer`ToPackedArray[...]]. When I try that on {vector,vector,matrix}, I get False. As it does not look like your return structure can be packed, can you break up your function into 3 functions? If that is sub-optimal, you could have a "wrapper" function which takes your input, uses Compiled functions internally where possible and stores required intermediate results, and then returns a list where the elements have been packed. (i.e. {packedvector, packedvector, packedmatrix}.) So some of your function will end up running in uncompiled mode, but hopefully the numerically intensive bits can still run in compiled mode. I also noticed there is an undocumented option to Compile (at least in version 6): CompileOptimizations -> Automatic. Perhaps there is a way you can ask for unpacked return values. You can then pack the individual bits yourself if required (or live without the packing). Perhaps someone at Wolfram can tell us about the option. Regards, Derek