recent broadcast changes (iterate by default), scalar struct, and `@.`

Thanks for bringing this up — it’s a very good point that the suggested deprecation simply won’t work in a @. deprecation. There are several alternatives, but they all have their downsides:

  • You can protect the Ref from being dotted by using $Ref like was suggested above. This is a special syntax that just applies to the macro, though, so it’s not terribly intuitive.
  • You can also use a tuple literal like @. f(x, (y,)) to treat y kind-of like a scalar. For most purposes this should be just as fast and scalar-like as a Ref, but it’s not 100% scalar-like: if x is scalar-like or a zero-dimensional array, f.(x, Ref(y)) will return an unwrapped scalar, whereas f.(x, (y,)) will return a 1-tuple. Some array types might also not support broadcasting with tuples as nicely as they do scalars.

The solution here, I think, will be a special syntax that will work everywhere to put values in a Ref. We’ve been talking about &y. That’s currently available and would make for a better alternative all around.

8 Likes