Compile
Usage
• Compile[vars, expr,   ,  , ... ] 假设 expr中的匹配  的子表达式有匹配  的类型。
Notes
• 由Compile处理的类型是:
| "\!\(\*StyleBox[\"\\\"_Integer\\\"\", \"MR\"]\) " | 机器整数 | | "\!\(\*StyleBox[\"\\\"_Real\\\"\", \"MR\"]\) " | 机器精度近似实数(缺省) | | "\!\(\*StyleBox[\"\\\"_Complex\\\"\", \"MR\"]\) " | 机器精度近似复数 | | "\!\(\*StyleBox[\"\\\"True\\\"\", \"MR\"]\) \!\(\*StyleBox[\"\\\"|\\\"\", \"MR\"]\) \!\(\*StyleBox[\"\\\"False\\\"\", \"MR\"]\) " | 逻辑变量 |
•作为一个编译函数的输入的嵌套列表必须有完整的数字数组。 • Compile 处理数值函数,矩阵运算,编程结构,列表操作函数,功能编程结构等等。 • Compile 产生CompiledFunction对象。 • 编译代码并不以和普通的Mathematica代码相同的方式处理数值精度和局部变量。 • 如果不能用编译代码对有特殊参数的编译函数求值,则代替使用普通的Mathematica代码。 •普通Mathematica代码可以从编译代码内部调用。由Mathematica代码获得的结果假设是近似实数,除非特别指明,否则由Compile的第三个参数指定。 • 用Compile计算的对象的次数和次序可能和普通的Mathematica代码不同。 • Compile有属性HoldAll,在缺省情况下在编译前并不进行计算。 •可以使用Compile[ ... , Evaluate[expr]]指明expr应当在编译前从符号上计算。
Further Examples
This is an iteration of times starting with a value of .
In[1]:=
|
Out[1]=
|
Compiling this procedure speeds it up considerably, especially for a large number of iterations.
In[2]:=
|
In[3]:=
|
Out[3]=
|
In[4]:=
|
This compiles an expression that performs an operation on a matrix.
In[5]:=
|
Out[5]=
|
The list operations are now carried out in a compiled way, and the result is an integer.
In[6]:=
|
Out[6]=
|
|