Difference between @view and view

If A = [1,2; 3 4] What is the difference between b = view(A, :, 1) and b = @view A[:,1]

Is the macro form just shorthand for the other?

Thanks

Yes, just for convenience. Also, the macro supports using end.

(There is also @views)

1 Like

The way to check this is to use @macroexpand, which shows you what the macro expands to:

julia> using MacroTools # makes the output a bit cleaner

julia> @macroexpand( @view A[:, 1] )
:(true && (view)(A, :, 1))
4 Likes