My code is below.
deltaX = 1/128;
W=256;
Mmax=40;
lPoly = ParallelTable[
LegendreP[
order, (-1.) + (deltaX/2.) + ((index - 1.)*deltaX)],
{order, 0, Mmax}, {index, 1, W}];
XPoly = Compile[{{index, _Integer}},
Block[{},
polyMatrix =
PadRight[Table[lPoly[[m - n + 1, index]], {m, 0, Mmax}, {n, 0, m}]];
polyMatrix], CompilationTarget -> "C",
RuntimeAttributes -> {Listable}, Parallelization -> True,
RuntimeOptions -> {"CatchMachineIntegerOverflow" -> False}];
If I run XPoly[1]
, it will return:
CompiledFunction::cfse : Compiled expression {{1.},{-0.996094,1.},<<48>>,<<71>>} should be a machine-size real number.
I have encountered this kinda error multiple times, sometimes it solved. But I dont know why.
Compile
, I suggest starting from reading this post: mathematica.stackexchange.com/a/104031/1871 And now you're against rule (2) and rule (6) there. $\endgroup$Table
constructs a ragged array (rows are are not all the same length). Ragged arrays are not allowed inCompile
. $\endgroup$PadRight
here. For avoiding confusion, I didnt post it. If you mean constructing ragged array is not allowed, it would solve my problem. $\endgroup$PadRight
, you first generate a ragged array before it is padded. But you can applyPadRight
outside ofCompile
to generateXPoly
as rectangular array. Also make sure that all0
are actually floating point0.
. (I am not sure whetherCompile
is clever enough to convert them on its own.) $\endgroup$