Dear all,
I like the @. macro, but is there a way to partly escape it? Use case is a situation where in an expression 9 out of 10 operations need the .
and one operation does not.
@. sum(a + b + c + d)
where a to d are vectors and I want the sum of the sum them, so sum
should not be broadcast.
I could imagine one just inverts the notation, i.e. .
then means “do not broadcast, but that did not work”.
Thanks!
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).
(@. is equivalent to a call to @__dot__.)
Examples
≡≡≡≡≡≡≡≡≡≡
julia> x = 1.0:3.0; y = similar(x);
julia> @. y = x + 3 * sin(x)
3-element Vector{Float64}:
3.5244129544236893
4.727892280477045
3.4233600241796016
So perhaps try
@. $sum(a + b + c + d)
3 Likes
Thanks - should have read the help indeed