I would like to write a compile function
cf =
Compile[{{tracefab, _Complex, 1}},
Module[{fab, i, j},
fab = Table[0., {i, 1, 5, 1}, {j, 1, 5, 1}];
For[i = 1, i <= 5, i++,
For[j = 1, j <= 5, j++,
fab[[i, j]] = tracefab[[i]];];];
fab]];
However, by using CompilePrint
I found that the compiled function calls MainEvluate
,
18 C0 = Part[ T(C1)0, I7]
19 V17T(R2)2I7I2 = MainEvaluate[Function[{tracefab, fabCompile$322, iCompile$323, jCompile$324}, Block[{fab = fabCompile$322, i = iCompile$323, j = jCompile$324}, {fab[[i,j]] = tracefab[[i]], fab, i, j}]][ T(C1)0, T(R2)2, I7, I2]]
20 I5 = I2
Is there a way to avoid calling Mainevaluate in my case?
Any suggestion is welcome!
fab = Table[0. I, {i, 5}, {j, 5}]
instead so that the type is not being coerced from real to complex. $\endgroup$