JuliaDiff / JuliaDiff/ForwardDiff.jl

LinAlg.normalize fails on Vector{ForwardDiff.Dual}

Open
#175 1 comment 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

example:

import ForwardDiff: Dual

v = ForwardDiff.Dual{6,Float64}[Dual(-0.0927781,-0.0679932,0.0650883,-0.0217832,0.00395549,0.0415781,0.128862),Dual(0.370172,0.0333549,0.0891681,0.0439229,0.0209036,-0.011965,0.0331594),Dual(-0.456713,0.0373191,0.0385198,0.0652645,0.00863201,-0.0826074,-0.20347),Dual(-0.46295,-0.00857001,-0.116858,-0.0657061,-0.0169481,0.0535432,0.0957022),Dual(0.656853,-0.00849306,-0.0966359,-0.0287605,-0.0171647,-0.00708444,-0.0745087)]

normalize(v, 1)

fails with

ERROR: MethodError: no method matching __normalize!(::Array{ForwardDiff.Dual{6,Float64},1}, ::ForwardDiff.Dual{6,Float64})

I isolated the problem and would be willing to make a PR, but I am unsure what an elegant fix would be. Possibly a method __normalize!{N, T <: AbstractFloat}(v::AbstractVector, nrm::ForwardDiff.Dual{N,T}) that does the same thing, branching on the size of nrm, but using typemax(T) instead here?

On a related note, I don't understand why Dual does not restrict T to AbstractFloat (I see little practical utility for AD using other types), but I am new to AD so perhaps I need to study the library more.

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

Reproduce the example with ForwardDiff.Dual and normalize(v, 1), then inspect Julia's base/linalg/generic.jl around the linked __normalize! implementation and its existing methods. Done means the supplied Vector{ForwardDiff.Dual} example no longer raises a MethodError, with regression coverage if the repository has a suitable test location.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.