I am using OptionsPattern
and OptionValue
to define some switches for my custom function. Here is a minimal example:
t[vars_, expr_,
OptionsPattern[{ Experimental`OptimizeExpression,
Compile}]] :=
(
Compile[vars, expr,
CompilationOptions -> OptionValue[CompilationOptions],
CompilationTarget -> OptionValue[CompilationTarget],
Parallelization -> OptionValue[Parallelization],
RuntimeAttributes -> OptionValue[RuntimeAttributes],
RuntimeOptions -> OptionValue[RuntimeOptions]
]
)
t[{x, y}, Sin[x*y]]
This produces the errors:
"Options expected (instead of \
OptionValue[{Experimental`OptimizeExpression,Compile},{},\
CompilationOptions]) beyond position 2 in \
Method->{OptionValue[{Experimental`OptimizeExpression,Compile},{},\
CompilationOptions]}. An option must be a rule or a list of rules."
"Options expected (instead of \
OptionValue[{Experimental`OptimizeExpression,Compile},{},\
RuntimeOptions]) beyond position 2 in \
Method->{OptionValue[{Experimental`OptimizeExpression,Compile},{},\
RuntimeOptions]}. An option must be a rule or a list of rules"
"OptionValue[{Experimental`OptimizeExpression,Compile},{},\
RuntimeAttributes] is not a known runtime attribute and will be \
ignored"
and fails to execute with default values passed to the options. OptionValue appears to fail to grab the correct value. (Moreover, Method
appears to be being assigned a value even though Compile
has no such option, but this could just be internal definitions to Compile)
Assigning explicitly something like
t[{x, y}, Sin[x*y],
CompilationOptions -> {"ExpressionOptimization" -> True}]
produces similar errors. Why isn't the correct OptionValues
being parsed?