Consider a vector
vec[x_,y_,z_]={x^0.5*y^0.1,y^0.3*z^0.1,z^2*x*y};
I need to calculate, say, a table with vector values for the coordinates
tabscord=RandomReal[{0, 1}, {10^7, 3}];
I would like to use Compile. This is my realization:
tabcompiled =
Hold@Compile[{{tabscord, _Real, 2}},
Table[vec[tabscord[[i]][[1]], tabscord[[i]][[2]],
tabscord[[i]][[3]]], {i, 1, Length[tabscord], 1}],
CompilationTarget -> "C", RuntimeOptions -> "Speed"] /.
DownValues@vec//ReleaseHold
However, it says
CompiledFunction::cfse: Compiled expression {0.815274,0.188035,0.433407} should be a machine-size real number.
To avoid this problem, I need to define first the coordinates of the vector, say,
vecx[x_,y_,z_]=vec[x,y,z][[1]];
vecy[x_,y_,z_]=vec[x,y,z][[2]];
vecz[x_,y_,z_]=vec[x,y,z][[3]];
And then
tabcompiled =
Hold@Compile[{{tabscord, _Real, 2}},
Table[{vecx[tabscord[[i]][[1]], tabscord[[i]][[2]],
tabscord[[i]][[3]]],vecy[tabscord[[i]][[1]], tabscord[[i]][[2]],
tabscord[[i]][[3]]],vecz[tabscord[[i]][[1]], tabscord[[i]][[2]],
tabscord[[i]][[3]]]}, {i, 1, Length[tabscord], 1}],
CompilationTarget -> "C", RuntimeOptions -> "Speed"] /.
DownValues@vecx/.DownValues@vecy/.DownValues@vecz//ReleaseHold
Could you please tell me whether it is possible to avoid defining separate coordinates of vec
if using Compile?