Skip to content

Commit

Permalink
Update positive.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
Tortar authored Nov 4, 2024
1 parent 49cc8f3 commit 3783ad1
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/utils/positive.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 3783ad1

Please sign in to comment.