comparison diffOp.jl @ 118:4c0c02a80cd4 cell_based_test

Change uview to view. It seems the compiler is now able to remove the allocation
author Jonatan Werpers <jonatan@werpers.com>
date Tue, 12 Feb 2019 13:15:16 +0100
parents ff7f377433b4
children 631eb9b35d72
comparison
equal deleted inserted replaced
117:ff7f377433b4 118:4c0c02a80cd4
117 h = Grid.spacings(L.grid)[1] 117 h = Grid.spacings(L.grid)[1]
118 uᵢ = L.a * apply(L.op, h, v, i) 118 uᵢ = L.a * apply(L.op, h, v, i)
119 return uᵢ 119 return uᵢ
120 end 120 end
121 121
122 using UnsafeArrays
123 function apply(L::Laplace{2}, v::AbstractArray{T,2} where T, I::Tuple{Index{R1}, Index{R2}}) where {R1, R2} 122 function apply(L::Laplace{2}, v::AbstractArray{T,2} where T, I::Tuple{Index{R1}, Index{R2}}) where {R1, R2}
124 h = Grid.spacings(L.grid) 123 h = Grid.spacings(L.grid)
125 # 2nd x-derivative 124 # 2nd x-derivative
126 @inbounds vx = uview(v, :, Int(I[2])) 125 @inbounds vx = view(v, :, Int(I[2]))
127 @inbounds uᵢ = L.a*apply(L.op, h[1], vx , I[1]) 126 @inbounds uᵢ = L.a*apply(L.op, h[1], vx , I[1])
128 # 2nd y-derivative 127 # 2nd y-derivative
129 @inbounds vy = uview(v, Int(I[1]), :) 128 @inbounds vy = view(v, Int(I[1]), :)
130 @inbounds uᵢ += L.a*apply(L.op, h[2], vy, I[2]) 129 @inbounds uᵢ += L.a*apply(L.op, h[2], vy, I[2])
131 return uᵢ 130 return uᵢ
132 end 131 end
133 132
134 # Slow but maybe convenient? 133 # Slow but maybe convenient?