From 3783ad1497e67392881bcd2077aa073fdc34005b Mon Sep 17 00:00:00 2001 From: Adriano Meligrana <68152031+Tortar@users.noreply.github.com> Date: Mon, 4 Nov 2024 15:50:19 +0100 Subject: [PATCH] Update positive.jl --- src/utils/positive.jl | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/utils/positive.jl b/src/utils/positive.jl index a02a6f0..ee047e3 100644 --- a/src/utils/positive.jl +++ b/src/utils/positive.jl @@ -89,6 +89,19 @@ function neg(number::T) where {T <: Number} end end +""" + neg!(vector) -> vector + +In-place version of `neg`. Mimicks min(0, vector) in Matlab. +Returns the updated vector. +""" +function neg!(A) + @simd for i in eachindex(A) + A[i] = ifelse(isnan(A[i]), zero(eltype(A)), min(zero(eltype(A)), A[i])) + end + return A +end + # like in the original code function matlab_round(x) return Base.round(x, RoundNearestTiesUp)