JuliaArrays / JuliaArrays/OffsetArrays.jl
No default rounding to `center` method
Nobody has claimed this yet.
- Dominant language
- Julia
- Stars
- 212
- Forks
- 45
- PR merge metrics
- No merged PRs in 30d
Description
Working through #242 #251 and #254, I have to admit that I made a design mistake here, instead of current
function center(A::AbstractArray, r::RoundingMode=RoundDown)
map(axes(A)) do inds
round(Int, (length(inds)-1)/2, r) + first(inds)
end
end
centered(A::AbstractArray, cp::Dims=center(A)) = OffsetArray(A, .-cp)
A better approach is perhaps to:
function center(A::AbstractArray)
map(axes(A)) do inds
length(inds)-1)/2 + first(inds)
end
end
function centered(A::AbstractArray, cp::Dims=center(A), r::RoundingMode=RoundDown)
OffsetArray(A, map(x->round(Int, x, r), .-cp))
end
This enables users to get the raw float point center coordinate and thus can be used in other scenarios. For instance, in interpolations, arrays are not required to be placed at the grids points. Also, unlike the previous version, applying rounding mode to centered will not be ambiguous anymore (See #250)
Unfortunately, to support this breaking behavior transition, a major version bump is required. For now, we should just stick to the current integer world. Also, I'm not sure how much people want this change so it's better to leave it open for a while before making any deprecations.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Read the current center and centered definitions, then review the discussions in #242, #251, #254, and #250. Determine whether the proposed separation of raw center coordinates from rounding in centered is accepted; done would require a maintainer decision on the breaking-change and versioning plan, since this issue currently leaves the change open.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- data
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100