Reputation: 2310
I am trying to use the LsqFit package in Julia, and the documentation makes use of a macro @.
without really explaining how it works. It is not clear to me from the package documentation whether this is a standard Julia macro or something peculiar to the package, and I can't find a reference to this macro elsewhere. How does @.
work in Julia?
Upvotes: 4
Views: 921
Reputation: 42194
You can check documentation for any Julia function by pressing ?
to go to the help mode, see the output below:
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).
Describing the documentation above in other words the @.
allows you to vectorize all function calls in the expression following a macro.
If you are unsure how any Julia macro works I recommend using the @macroexpand
macro, for example:
julia> @macroexpand @. [1, 2, 3] + [4, 5, 6]
:((+).([1, 2, 3], [4, 5, 6]))
Upvotes: 16