This question already has an answer here:
- How to compile effectively? 6 answers
As evidenced in my last question there is much I do not know about how to write compilable functions.
The basics are clear: one must load the appropriate packages
and should check the availability of a suitable compiler:
and it is helpful to remind oneself of the functions that can be used that avoid
MainEvaluate (for which I had not recorded the source but am now happy to credit to this thread where there is also other useful information)
Compile`CompilerFunctions // Sort Internal`CompileValues;(*to trigger \ auto-load*)ClearAttributes[Internal`CompileValues, ReadProtected]; syms = DownValues[Internal`CompileValues] /. HoldPattern[ Verbatim[HoldPattern][Internal`CompileValues[sym_]] :> _] :> sym; Complement[syms, Compile`CompilerFunctions]
But, once all that is done must still remember that a compiled function definition expects its arguments to be of well-defined kinds - Integer, Real, Complex and n-dimensional tensors (matrices).
What is unclear, even after re-reading documentation, is the proper specification and use of temporary variables. It appears, for example, that these too must be of simple types and that the compiler does not automatically coerce them to compatible types. Then too there is the question of using e.g. GetElement even thought Part is a compilable function, and why Do may be better than Table.
Where can such additional information be found and what guidance would the community offer re writing functions for compilation?