From 332cc29b04d4aba0c06f6831f511f6c82d4cdd7b Mon Sep 17 00:00:00 2001 From: annuges <33180039+annuges@users.noreply.github.com> Date: Thu, 5 Oct 2023 20:45:09 +0200 Subject: [PATCH] restore allocation free maxdiff 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 --- src/utilities/maxdiff.jl | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/utilities/maxdiff.jl b/src/utilities/maxdiff.jl index a8bf2117e..d25a8e7f6 100644 --- a/src/utilities/maxdiff.jl +++ b/src/utilities/maxdiff.jl @@ -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