I get an error trying to assign to the view
result of a function call directly, but not when assigning to that same view
after saving it in a variable. I can’t figure out why.
@generated function view_slice_last(arr::Array{T,D}, dx) where {T,D}
initial_colons = [:(:) for i in 1:(D-1)]
quote
@view arr[$(initial_colons...),dx]
end
end
example = rand(5,4,3)
view_slice_last(example, 2) .*= 0.0 # ERROR: LoadError: Invalid assignment location "view_slice_last(example,2)
saved_view = view_slice_last(example,2)
saved_view .*= 0.0 # works fine!
(also if anyone has a better way to do what I did with the generated function please do tell – I imagine there must be something but I couldn’t find anything else)