JuliaDiff / JuliaDiff/DifferentiationInterface.jl
Conversion of basis to input type can fail
Nobody has claimed this yet.
- Dominant language
- Julia
- Stars
- 313
- Forks
- 35
- PR merge metrics
- No merged PRs in 30d
Description
The reason is that I use zero in DI.basis to construct basis vectors, and zero(x) doesn't necessarily have the same type as x. Subsequently, when I convert dx for Enzyme to ensure that Duplicated gets two arguments of the same type, I get an error.
julia> x = view(ones(2), 1:2)
2-element view(::Vector{Float64}, 1:2) with eltype Float64:
1.0
1.0
julia> zero(x)
2-element Vector{Float64}:
0.0
0.0
julia> convert(typeof(x), zero(x))
ERROR: MethodError: Cannot `convert` an object of type Vector{Float64} to an object of type SubArray{Float64, 1, Vector{Float64}, Tuple{UnitRange{Int64}}, true}
Detected in https://github.com/SciML/NonlinearSolve.jl/issues/476#issuecomment-2402984370
Enzyme.onehot uses similar so it has the same problem.
Related:
Contributor guide
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 tracing DI.basis and Enzyme.onehot, especially how they create values with zero or similar before converting dx for Enzyme. Reproduce the view/SubArray example and verify that Duplicated receives two arguments of the same compatible type without conversion errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- backend-api-design
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100