Skip to content

Commit

Permalink
add require_one_based_indexing
Browse files Browse the repository at this point in the history
  • Loading branch information
jw3126 committed Jun 2, 2022
1 parent d07881a commit a071843
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/RangeHelpers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ end #module HandleUnitStep
const HUS = HandleUnitStep

module HandleApproach
function start_step_stop end
function start_step_stop end
end
const HAP = HandleApproach

Expand Down Expand Up @@ -563,11 +563,18 @@ function bincenters(r::AbstractRange)::AbstractRange
return binwalls(r, first=false, last=false)
end

if isdefined(Base, :require_one_based_indexing)
using Base: require_one_based_indexing
else
function require_one_based_indexing(v)
(firstindex(v) == one(eltype(v))) || throw(ArgumentError("First index must be one."))
end
end
function bincenters(v::AbstractVector)
if isempty(v)
throw(ArgumentError("Cannot compute bincenters of empty vector."))
end
Base.require_one_based_indexing(v)
require_one_based_indexing(v)
T = float(eltype(v))
ret = similar(v, T, length(v)-1)
half = T(1/2)
Expand Down

2 comments on commit a071843

@jw3126
Copy link
Owner Author

@jw3126 jw3126 commented on a071843 Jun 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/61626

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.9 -m "<description of version>" a071843c43d2d295a20bd70a87c7b5b9792af071
git push origin v0.1.9

Please sign in to comment.