IDL lambda:尝试下标超出范围
IDL lambda: Attempt to subscript is out of range
idl 8.4 引入了 lambda
功能。我有 IDL 8.6.1 并且 lambda
函数没有完全按照记录工作:
IDL> f = lambda(x : x * x)
IDL> print, call_function(f, findgen(10))
0.00000 1.00000 4.00000 9.00000 16.0000 25.0000 36.0000 49.0000 64.0000
81.0000
IDL> print, f(findgen(10))
IDL$LAMBDAF5 IDL$LAMBDAF5 IDL$LAMBDAF5 IDL$LAMBDAF5 IDL$LAMBDAF5 IDL$LAMBDAF5 IDL$LAMBDAF5 IDL$LAMBDAF5 IDL$LAMBDAF5
IDL$LAMBDAF5
IDL> print, f(5)
% Attempt to subscript F with <INT ( 5)> is out of range.
那么,为什么 f(5)
没有 return 25
?
哦,如评论here, this is documented。
Note: To make direct calls on a Lambda function, you should make sure that compile_opt strictarr (or compile_opt idl2) is turned on so that IDL interprets the parentheses as a function call instead of array indices. See COMPILE_OPT for details.
所以
compile_opt strictarr
要么
compile_opt idl2
.
不过,我本以为默认情况下可以直接调用。
idl 8.4 引入了 lambda
功能。我有 IDL 8.6.1 并且 lambda
函数没有完全按照记录工作:
IDL> f = lambda(x : x * x)
IDL> print, call_function(f, findgen(10))
0.00000 1.00000 4.00000 9.00000 16.0000 25.0000 36.0000 49.0000 64.0000
81.0000
IDL> print, f(findgen(10))
IDL$LAMBDAF5 IDL$LAMBDAF5 IDL$LAMBDAF5 IDL$LAMBDAF5 IDL$LAMBDAF5 IDL$LAMBDAF5 IDL$LAMBDAF5 IDL$LAMBDAF5 IDL$LAMBDAF5
IDL$LAMBDAF5
IDL> print, f(5)
% Attempt to subscript F with <INT ( 5)> is out of range.
那么,为什么 f(5)
没有 return 25
?
哦,如评论here, this is documented。
Note: To make direct calls on a Lambda function, you should make sure that compile_opt strictarr (or compile_opt idl2) is turned on so that IDL interprets the parentheses as a function call instead of array indices. See COMPILE_OPT for details.
所以
compile_opt strictarr
要么
compile_opt idl2
.
不过,我本以为默认情况下可以直接调用。