I would like to ask a question regarding an operation on two columns of a matrix as you can see below. Here I proposed two functions to perform the task. The function f1 has two allocations even though I used @view, while the function f2 has no allocation. I am wondering whether it is possible to perform the task with no allocations without using a loop as proposed in function f2? Thanks in advance!
f1(x,A,iA,iB) = x .= view(A,:,iA) - view(A,:,iB); function f2(x,A,iA,iB) @inbounds @simd for i in 1:size(A,1) x[i] = A[i,iA] - A[i,iB] end end A = rand(10_000,10_000); x1 = rand(10_000); x2 = rand(10_000); x0 = A[:,6] - A[:,8]; @time f1(x1,A,6,8); @time f2(x2,A,6,8); @test x0 ≈ x1 @test x0 ≈ x2