`gradient!`, `jacobian!` and `hessian!` do not support an immutable `DiffResult` unless `x` is a `StaticArray`
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 75/100
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- Julia
- Estrellas
- 1k
- Forks
- 162
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de JuliaDiff/ForwardDiff.jl
-
missing floatmin, floatmax, and issubnormal for DualPosiblemente ocupada @devmotion la tomó hace 13 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
JuliaDiff/ForwardDiff.jl#852 · 6 comentarios ·
-
Enable NaN-safe mode by defaultPosiblemente ocupada @devmotion la tomó hace 1 día. Abierto
Dificultad 5/5 Más de una semana Aptitud para principiantes 25/100
JuliaDiff/ForwardDiff.jl#857 · 1 reacción ·
-
Dificultad 4/5 3-5 días Aptitud para principiantes 52/100
JuliaDiff/ForwardDiff.jl#854 · 1 comentario ·
-
`gradient!` leaves part of the result unwritten when `f` does not depend on its argumentPosiblemente ocupada @devmotion la tomó hace 42 días. Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 78/100
JuliaDiff/ForwardDiff.jl#847 ·
-
hessian!(::ImmutableDiffResult, f, ::StaticArray) errors when f does not depend on its argumentPosiblemente ocupada @devmotion la tomó hace 43 días. Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 76/100
JuliaDiff/ForwardDiff.jl#846 · 1 comentario ·
Todos los issues de JuliaDiff/ForwardDiff.jl
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
CliMA/ClimaAtmos.jl#4891 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
tagbot-manual
Dificultad 1/5 Menos de una hora Aptitud para principiantes 75/100
tshort/StaticCompiler.jl#191 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
SciML/SciMLSensitivity.jl#1703 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
JuliaGPU/GPUCompiler.jl#1008 ·
Los mantenedores suelen responder en 1 día
-
`biggs6` disagrees with CUTEst and is unbounded belowPosiblemente ocupada @timholy la tomó hace 1 día. Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100