Consider the following toy code:
table = Table[{i^0.11, i^0.005}, {i, 1, 1000, 0.5}];
val = Compile[{{table, _Real, 2}, {i, _Integer}}, table[[i]][[1]], CompilationOptions ->
"InlineCompiledFunctions" ->
True, CompilationTarget -> "C"]
sum = Hold@
Compile[{{table, _Real, 2}},
Sum[val[table, i], {i, 1, Length[table], 1}], CompilationOptions ->
"InlineCompiledFunctions" ->
True, CompilationTarget -> "C", Parallelization -> True] /. OwnValues@val //
ReleaseHold
where I define compiled value val[table,i]
, and then compiled sum over i, sum[table]
. I get error
Function::flpar: Parameter specification {table,1} in {table,1}\[Function]table[[1]][[1]] should be a symbol or a list of symbols.
Could you please tell me how to have the compile the sum over i? I need this since in realistic case table
is also a (very complicated) compiled function, and I also cannot omit the intermediate definition val
, as there are too many intermediate actions that I need to get in order to obtain val
.