JuliaDiff / JuliaDiff/ForwardDiff.jl

seed! dimension mismatch

Open
#441 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Julia
Stars
1k
Forks
160
PR merge metrics
No merged PRs in 30d

Description

Hi,

I use ForwardDiff.jl applied to CUDA arrays and I want to vary the number of partials in the dual. I want to seed each entry in the array with my own values and partials. For doing that I used seed! and ran into issues. I fixed it by implementing my own seed function:

function myseed!(duals::AbstractArray{ForwardDiff.Dual{T,V,N}}, x,
               seeds::AbstractArray{ForwardDiff.Partials{N,V}}) where {T,V,N}
    for i in 1:size(duals,1)
        duals[i] = ForwardDiff.Dual{T,V,N}(x[i], seeds[i])
    end
    return duals
end

The original implementation looks like this:

function seed!(duals::AbstractArray{Dual{T,V,N}}, x,
               seeds::NTuple{N,Partials{N,V}}) where {T,V,N}
    for i in 1:N
        duals[i] = Dual{T,V,N}(x[i], seeds[i])
    end
    return duals
end

I don't see why the loop should be over N, the number of partials. Shouldn't it be over the number of duals, and thus over the size of the dual array? In particular, I ended up with uninitialized values with the original implementation, which can give you nasty wrong values.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the seed! entry point shown in the issue and compare its iteration over the number of partials with the dimensions of the dual array. Reproduce the mismatch using an array whose length differs from N, then verify that every dual receives the intended seed and that no entries remain uninitialized.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.