compile(compiler)
compile()所属R语言包:compiler
Byte Code Compiler
字节码编译器
译者:生物统计家园网 机器人LoveR
描述----------Description----------
These functions provide an interface to a byte code compiler for R.
这些功能提供了一个接口为R的字节码编译器
用法----------Usage----------
cmpfun(f, options = NULL)
compile(e, env = .GlobalEnv, options = NULL)
cmpfile(infile, outfile, ascii = FALSE, env = .GlobalEnv,
verbose = FALSE, options = NULL)
loadcmp(file, envir = .GlobalEnv, chdir = FALSE)
disassemble(code)
enableJIT(level)
compilePKGS(enable)
getCompilerOption(name, options)
setCompilerOptions(...)
参数----------Arguments----------
参数:f
a closure.
封闭。
参数:options
list of named compiler options
命名的编译器选项列表
参数:env
the top level environment for the compiling.
顶级编译环境。
参数:file,infile,outfile
pathnames; outfile defaults to infile with a .Rc extension in place of any existing extension.
路径; OUTFILE默认与RC任何现有的扩展延伸到INFILE。
参数:ascii
logical; should the compiled file be saved in ascii format?
逻辑;编译后的文件应该以ASCII格式保存?
参数:verbose
logical; should the compiler show what is being compiled
逻辑;编译器显示应该是被编译
参数:envir
environment to evaluate loaded expressions in.
环境评估加载表达式英寸
参数:chdir
logical; change directory before evaluation?
逻辑;变化评估前的目录?
参数:code
byte code expression or compiled closure
字节码表达或编译封闭
参数:e
expression to compile
表达式编译
参数:level
integer; the JIT level to use
整数;使用JIT的水平
参数:enable
logical; enable compiling packages if TRUE
逻辑;启用编译软件包如果TRUE
参数:name
character string; name of option to return
字符串;选项返回的名称
参数:...
named compiler options to set
命名的编译器选项设置
Details
详情----------Details----------
The function cmpfun compiles the body of a closure and returns a new closure with the same formals and the body replaced by the compiled body expression.
功能cmpfun编译一个封闭的身体,并返回一个新的具有相同的形参,取而代之的是在编译的身体表达身体的封闭。
compile compiles an expression into a byte code object; the object can then be evaluated with eval.
compile编译成字节代码对象表达的对象,然后可以用eval评估。
cmpfile parses the expression in infile, compiles them, and writes the compiled expressions to outfile. If outfile is not provided, it is formed from infile by replacing or appending a .Rc suffix.
cmpfile分析表达infile,编译他们,并写入编译的表达式outfile。如果outfile不提供的,它是从infile更换或追加一个.Rc后缀组成。
loadcmp is used to load compiled files. It is similar to sys.source, except that its default loading environment is the global environment rather than the base environment.
loadcmp用来加载编译的文件。它类似于sys.source,除了其默认装载环境是全球性的环境,而不是基础环境。
disassemble produces a printed representation of the code that may be useful to give a hint of what is going on.
disassemble产生的代码,可能是有用的给予提示是怎么回事印表示。
enableJIT enables or disables just-in-time (JIT) compilation. JIT is disabled if the argument is 0. If enable is 1 then closures are compiled before their first use. If enable is 2, then in addition closures are also compiled before they are duplicated (useful for some packages, like lattice, that store closures in lists). If enable is 3 then in addition all loops are compiled before they are executed. JIT can also be enabled by starting R with the environment variable R_ENABLE_JIT set to one of these values.
enableJIT启用或禁用只是在实时(JIT)编译。如果参数是0,禁用JIT。 enable如果是1,那么封锁是他们第一次使用前编译。如果enable2,然后在另外封,也编译之前,他们是重复的(有用的一些包,像lattice,商店列表中封)。如果enable是在另外3所有循环被执行之前,他们编制。 JIT的也可以启用启动ŕ与环境变量R_ENABLE_JIT设置为下列值之一。
compilePKGS enables or disables compiling packages when they are installed. This requires that the package use lazy loading as compilation occurs as functions are written to the lazy loading data base. This can also be enabled by starting R with the environment variable R_COMPILE_PKGS set to a positive integer value.
compilePKGS启用或禁用编译安装时他们的包。这需要该软件包使用延迟加载编译功能写入延迟加载数据的基础上发生。这也可以通过环境变量R_COMPILE_PKGS设置为一个正整数开始ŕ启用。
Currently the compiler warns about a variety of things. It does this by using cat to print messages. Eventually this should use the condition handling mechanism.
目前的编译器警告各种各样的事情。它通过使用cat打印消息。最终,本应使用条件的处理机制。
The options argument can be used to control compiler operation. There are currently three options: optimize, suppressAll, and suppressUndefined. optimize specifies the optimization level, which can be an integer form 0 to 3. suppressAll should be a scalar logical; if TRUE no messages will be shown. suppressUndefined can be TRUE to suppress all messages about undefined variables, or it can be a character vector of the names of variables for which messages should not be shown.
options参数可以用来控制编译器的操作。目前有三种选择:optimize,suppressAll,suppressUndefined。 optimize指定优化级别,它可以是一个整数的形式0到3。 suppressAll应该是一个标量逻辑; TRUE如果将会显示任何消息。 suppressUndefined能TRUE压制关于未定义变量的所有邮件,或者它可以是一个特征向量消息不应该显示的变量的名称。
getCompilerOption returns the value of the specified option. The default value is returned unless a value is supplied in the options argument; the options argument is primarily for internal use. setCompilerOption sets the default option values. It returns a named list of the previous values.
getCompilerOption返回指定的选项的值。除非options参数提供一个值,则返回默认值;options参数主要是供内部使用。 setCompilerOption设置默认选项值。它返回一个以前的值命名列表。
Calling the compiler a byte code compiler is actually a bit of a misnomer: the external representation of code objects currently uses int operands, and when compiled with gcc the internal representation is actually threaded code rather than byte code.
调用字节码编译器的编译器实际上是一个有点用词不当:代码对象的外部表示,目前使用int操作数,并以gcc编译内部表示实际上是线程代码,而不是字节码。
作者(S)----------Author(s)----------
Luke Tierney
举例----------Examples----------
# a simple example[一个简单的例子]
f <- function(x) x+1
fc <- cmpfun(f)
fc(2)
disassemble(fc)
# old R version of lapply[老R版本的lapply]
la1 <- function(X, FUN, ...) {
FUN <- match.fun(FUN)
if (!is.list(X))
X <- as.list(X)
rval <- vector("list", length(X))
for(i in seq(along = X))
rval[i] <- list(FUN(X[[i]], ...))
names(rval) <- names(X) # keep `names' ![保持名!]
return(rval)
}
# a small variation[一个小的变化]
la2 <- function(X, FUN, ...) {
FUN <- match.fun(FUN)
if (!is.list(X))
X <- as.list(X)
rval <- vector("list", length(X))
for(i in seq(along = X)) {
v <- FUN(X[[i]], ...)
if (is.null(v)) rval[i] <- list(v)
else rval[[i]] <- v
}
names(rval) <- names(X) # keep `names' ![保持名!]
return(rval)
}
# Compiled versions[编译版本]
la1c <- cmpfun(la1)
la2c <- cmpfun(la2)
# some timings[一些计时]
x <- 1:10
y <- 1:100
system.time(for (i in 1:10000) lapply(x, is.null))
system.time(for (i in 1:10000) la1(x, is.null))
system.time(for (i in 1:10000) la1c(x, is.null))
system.time(for (i in 1:10000) la2(x, is.null))
system.time(for (i in 1:10000) la2c(x, is.null))
system.time(for (i in 1:1000) lapply(y, is.null))
system.time(for (i in 1:1000) la1(y, is.null))
system.time(for (i in 1:1000) la1c(y, is.null))
system.time(for (i in 1:1000) la2(y, is.null))
system.time(for (i in 1:1000) la2c(y, is.null))
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|