JuliaDiff / JuliaDiff/ChainRulesCore.jl
Projection for `x:: AbstractRange`
Nobody has claimed this yet.
- Dominant language
- Julia
- Stars
- 267
- Forks
- 66
- PR merge metrics
- No merged PRs in 30d
Description
If we want something like https://github.com/JuliaArrays/FillArrays.jl/pull/153 to project the gradient of a Fill onto a one-dimensional subspace, then I think we probably want something similar for the gradient of a range, but projecting onto a two-dimensional space, parameterised by the endpoints. Before I lose the bit of scrap paper I wrote this on, I think this would look as follows:
ProjectTo(x::AbstractRange) = ProjectTo{AbstractRange}()
function (project::ProjectTo{AbstractRange})(dx::AbstractVector)
L = length(dx)
μ = mean(dx)
# δ = -sum(diff(dx))/2
δ = sum(Base.splat(-), zip(dx, @view dx[2:end]))/2
return LinRange(μ + δ, μ - δ, L)
end
(project::ProjectTo{AbstractRange})(dx::AbstractRange) = dx
Using LinRange allows for zero slope (e.g. for constant dx) and skips the high-precision machinery which StepRangeLen uses to hit endpoints exactly, as I don't think we're concerned about the last digit here. This isn't yet careful about element types etc.
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
Start by reviewing the ProjectTo entry point for AbstractRange and the proposed vector and range methods in the issue. Determine the intended projection onto endpoint-parameterized ranges, including element-type handling and constant gradients, then establish tests for vector inputs and unchanged range inputs before considering the work complete.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- backend-api-design
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100