Skip to content

Commit

Permalink
improved to_range() robustness
Browse files Browse the repository at this point in the history
  • Loading branch information
orso82 committed Oct 2, 2024
1 parent 945b866 commit 72f053a
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/math.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ Turn a vector into a range (if possible)
function to_range(vector::AbstractVector{<:Real})
N = length(vector)
dv = vector[2] - vector[1]
if !(1 - sum(abs(vector[k] - vector[k-1] - dv) for k in 2:N) / (N - 1) 1.0)

if maximum(abs(vector[k] - vector[k-1]) - dv for k in 2:N) > dv / 1000.0
error("to_range requires vector data to be equally spaced: $(vector)")
end
return range(vector[1], vector[end], N)
Expand Down

0 comments on commit 72f053a

Please sign in to comment.