使用withCallingHandlers()无法捕获S4泛型函数的求值参数时生成的警告.
withCallingHandlers的正常行为示意图:
### simple function that sends a warning
send_warning <- function() {
warning('send_warning')
}
send_warning()
# Warning message:
# In send_warning() : send_warning
### the warning can be caught by withCallingHandlers
withCallingHandlers(send_warning(), warning = function(w)
{ stop('got warning:', w) })
# Error in (function (w) :
# got warning:simpleWarning in send_warning(): send_warning
Run Code Online (Sandbox Code Playgroud)
现在,让我们在S4发送期间发出警告:
### simplest method ever
setGeneric('my_method', function(x) standardGeneric('my_method') )
setMethod('my_method', 'ANY', function(x) str(x) )
### call it with an argument that produces a …Run Code Online (Sandbox Code Playgroud) 我想矢量化以下操作:
V[i+1] = max(V[i] - c, V[i+1]) for i=1 to n-1 (V[0] = 0)
Run Code Online (Sandbox Code Playgroud)
相应的天真伪代码是:
for (i=0; i < n; i++) {
if (V[i]-c > V[i+1]) V[i+1] = V[i]-c
}
Run Code Online (Sandbox Code Playgroud)
哪些SIMD说明有用?