I have rather large equations that profit a lot from compiling, unfortunately they require input from external numerics and need to be interpolated.
In the end this costs a lot of performance as InterpolatingFunction
triggers a MainEvaluate
.
A minimal example:
testInt = Interpolation[{{0., 0.}, {2.5, 2.5}, {5., 5.}, {10., 10.}, {15.,
15.}}];
testCompile = With[{testInt = testInt},
Compile[{{x, _Real}, {a, _Real}},
testInt[a*x], CompilationTarget -> "C",
"RuntimeOptions" -> "Speed",
CompilationOptions -> {"InlineExternalDefinitions" -> True,
"InlineCompiledFunctions" -> True},
RuntimeAttributes -> {Listable}, Parallelization -> False
]];
CompilePrint[testCompile]
Out[3]= "
2 arguments
4 Real registers
Underflow checking off
Overflow checking off
Integer overflow checking off
RuntimeAttributes -> {Listable}
R0 = A1
R1 = A2
Result = R3
1 R2 = R1 * R0
2 R3 = MainEvaluate[ Hold[InterpolatingFunction[{{0., 15.}}, <>]][ R2]]
3 Return
"
The options are set as in the case of my application.
Is there any way to access circumvent this the non compilabilty of InterpolatingFunction
by accessing for example the resulting piece wise polynomial?
InterpolatingFunction
supports. $\endgroup$