In FunctionCompile
, system does not recognize external functions and external global variables by default. But we can use KernelFunction
to call external function. However, I cannot find any method to use variables or arrays in kernel. Is it possible to use them?
$\begingroup$
$\endgroup$
1
-
3$\begingroup$ Pass them as an argument to the function why not $\endgroup$– Jason B.Commented Oct 26, 2022 at 21:55
Add a comment
|
2 Answers
$\begingroup$
$\endgroup$
It seems like it is possible:
$numberOfWeekDaysInAYear = 260; (* global variable *)
annualise[days_] := days/$numberOfWeekDaysInAYear;
annualiseC =
FunctionCompile[
Function[
Typed[days, "MachineInteger"],
Typed[KernelFunction[annualise], {"MachineInteger"} -> "MachineInteger"][days]
]
];
annualiseC[120] (*6/13*)
$\begingroup$
$\endgroup$
Such as you have a global variables a
:
a = 7;
You can use it in FunctionCompile
with a With
like this:
cf = With[{avalue = a}, FunctionCompile[
Function[Typed[arg, "MachineInteger"], arg + avalue]]]
cf[20]
27