我试图在Julia中使用LsqFit包,文档使用宏@.而没有真正解释它是如何工作的.我从包文档中不清楚这是一个标准的Julia宏还是包特有的东西,我在其他地方找不到对这个宏的引用.如何@.在朱莉娅工作?
Prz*_*fel 12
您可以通过按?转到帮助模式查看任何Julia功能的文档,请参阅下面的输出:
help?> @.
@. expr
Convert every function call or operator in expr into a "dot call" (e.g. convert f(x) to f.(x)), and convert
every assignment in expr to a "dot assignment" (e.g. convert += to .+=).
If you want to avoid adding dots for selected function calls in expr, splice those function calls in with $.
For example, @. sqrt(abs($sort(x))) is equivalent to sqrt.(abs.(sort(x))) (no dot for sort).
Run Code Online (Sandbox Code Playgroud)
换句话说,描述上面的文档@.允许您在宏后面的表达式中向量化所有函数调用.
如果您不确定Julia宏是如何工作的,我建议使用@macroexpand宏,例如:
julia> @macroexpand @. [1, 2, 3] + [4, 5, 6]
:((+).([1, 2, 3], [4, 5, 6]))
Run Code Online (Sandbox Code Playgroud)