Skip to content

Commit

Permalink
restore allocation free maxdiff (#1051)
Browse files Browse the repository at this point in the history
The mapreduce based version allocates which is undesirable.
This change restores the previous allocation free code for normal Arrays while still allowing gpu arrays using mapreduce
  • Loading branch information
annuges authored Oct 7, 2023
1 parent 5fa5d61 commit 7fbfb36
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/utilities/maxdiff.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# generic version for gpu support
function maxdiff(x::AbstractArray, y::AbstractArray)
return mapreduce((a, b) -> abs(a - b), max, x, y)
end

# allocation free version for normal arrays
function maxdiff(x::Array, y::Array)
res = real(zero(x[1] - y[1]))
@inbounds for i in 1:length(x)
delta = abs(x[i] - y[i])
if delta > res
res = delta
end
end
return res
end

0 comments on commit 7fbfb36

Please sign in to comment.