`gradient!`, `jacobian!` and `hessian!` do not support an immutable `DiffResult` unless `x` is a `StaticArray`
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 75/100
Direzione di ricerca
Start with extract_gradient_chunk! in src/gradient.jl, hessian!(::DiffResult, …) in src/hessian.jl, and extract_jacobian! in src/jacobian.jl; compare them with vector-mode gradient!'s DiffResults.gradient! handling. Run the supplied immutable DiffResult examples across the listed chunk sizes and confirm gradient!, jacobian!, and hessian! work without requiring mutable buffers.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
The methods in src store derivatives by mutating the buffer they pull out of a DiffResult, so they cannot handle a result whose buffers are genuinely immutable. The StaticArrays extension does handle one, but its methods are only reached when x is itself a StaticArray.
using ForwardDiff, DiffResults, StaticArrays
x = [1.0, 2.0, 3.0]
sq(z) = z .^ 2
# succeeds or fails depending only on the chunk size
for c in (1, 2, 3)
cfg = ForwardDiff.GradientConfig(prod, x, ForwardDiff.Chunk{c}())
ForwardDiff.gradient!(DiffResults.GradientResult(@SVector zeros(3)), prod, x, cfg)
end
# chunk 1, 2: ERROR: setindex!(::SVector{3, Float64}, value, ::Int) is not defined.
# chunk 3: ImmutableDiffResult(6.0, ([6.0, 3.0, 2.0],))
ForwardDiff.hessian!(DiffResults.HessianResult(@SVector zeros(3)), prod, x)
# ERROR: setindex!(::SVector{3, Float64}, value, ::Int) is not defined.
ForwardDiff.jacobian!(DiffResults.JacobianResult(@SVector(zeros(3)), @SVector(zeros(3))), sq, x)
# ERROR: MethodError: no method matching extract_jacobian!(…, ::ImmutableDiffResult{…}, …)
All three work with x = SVector(1.0, 2.0, 3.0).
Cause
extract_gradient_chunk! (gradient.jl#L83-L86) and hessian!(::DiffResult, …) (hessian.jl#L69) write the extracted buffer via setindex!/broadcast, and extract_jacobian! (jacobian.jl#L104) only has AbstractArray and MutableDiffResult methods.
Vector-mode gradient! shows what the others need: extract_gradient!(::Type{T}, ::DiffResult, ::Dual) stores through DiffResults.gradient!, rebuilding the struct instead of writing the buffer.
Scope
Only about genuinely immutable buffers. A result holding MArray buffers hits some of the same errors, but that is DiffResults#25 — those are writable and should give a MutableDiffResult.
Independent of #696; reproduces before and after the re-aliasing fix there.
ForwardDiff master (v1.4.6), Julia 1.12.7, StaticArrays 1.9.22, DiffResults 1.1.0.
- Lingua principale
- Julia
- Stelle
- 1k
- Fork
- 162
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di JuliaDiff/ForwardDiff.jl
-
missing floatmin, floatmax, and issubnormal for DualForse già presa @devmotion l’ha presa 16 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
JuliaDiff/ForwardDiff.jl#852 · 6 commenti ·
-
`fma` and `muladd` ignore NaN-safe modeForse già presa @devmotion l’ha presa 2 giorni fa. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 55/100
JuliaDiff/ForwardDiff.jl#860 ·
-
Enable NaN-safe mode by defaultForse già presa @devmotion l’ha presa 4 giorni fa. Aperta
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
JuliaDiff/ForwardDiff.jl#857 · 1 reazione ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 52/100
JuliaDiff/ForwardDiff.jl#854 · 1 commento ·
-
`gradient!` leaves part of the result unwritten when `f` does not depend on its argumentForse già presa @devmotion l’ha presa 45 giorni fa. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 78/100
JuliaDiff/ForwardDiff.jl#847 ·
Tutte le issue di JuliaDiff/ForwardDiff.jl
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
JuliaGPU/KernelAbstractions.jl#897 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
oscar-system/GAP.jl#1455 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
JuliaAI/MLJTransforms.jl#85 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
SciML/OrdinaryDiffEq.jl#4875 ·
I maintainer di solito rispondono entro 4 giorni