checktag's permissive fallback silently disables tag checking (e.g. for derivative(f!, y, x, cfg))
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 50/100
- Issue-Typ
- Bug
- Klarheit
- Größtenteils klar
- Aktivitätsstatus
- Ruhig
- Bereich
- tooling
Rechercherichtung
Beginne mit den checktag-Methoden und den Aufrufstellen von derivative/derivative!, und vergleiche anschließend ihr Verhalten mit dem InvalidTagException-Pfad von gradient. Als abgeschlossen gilt, wenn eine DerivativeConfig für die falsche Funktion bei skalaren derivative-Aufrufen abgelehnt wird und das Verhalten bei dokumentiertem nothing sowie bei benutzerdefinierten Tags berücksichtigt ist.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
A DerivativeConfig built for one function is silently accepted by another, so derivative(f!, y, x, cfg) gets no perturbation confusion protection at all:
julia> a!(y, x) = (y .= sin(x)); b!(y, x) = (y .= cos(x));
julia> y = Vector{Float64}(undef, 2);
julia> cfg = ForwardDiff.DerivativeConfig(a!, y, 0.0);
julia> ForwardDiff.derivative(b!, y, 0.0, cfg) # cfg belongs to a!, no complaint
2-element Vector{Float64}:
-0.0
-0.0
gradient does raise InvalidTagException in the analogous situation. This reproduces with a real y on master, so it is unrelated to complex support.
The immediate cause is that every non-fallback checktag method requires x::AbstractArray:
checktag(::Type{Tag{FT,VT}}, f::F, x::AbstractArray{V}) where {FT,VT,F,V} = throw(InvalidTagException{...}())
checktag(::Type{Tag{F,V}}, f::F, x::AbstractArray{V}) where {F,V} = true
while derivative/derivative! call checktag(T, f!, x) with a scalar x. Dispatch lands on the catch-all checktag(z, f, x) = true, so the check argument of derivative(f!, y, x, cfg, Val{true}()) has no effect.
Adding scalar counterparts of those two methods fixes this particular case, but the more interesting question is whether the permissive checktag(z, f, x) = true default should stay. As it stands, any signature that does not match a specific method silently opts out of checking, which is how this gap went unnoticed -- the failure mode is "no error", not "no method". Defaulting to rejection and explicitly accepting only validated tags would make such gaps loud instead of silent.
Two things to note for anyone attempting that:
- The return value is currently discarded -- every call site is
CHK && checktag(...), andchecktagworks purely by throwing. So flipping the default tofalseon its own changes nothing; the call sites would have to throw on afalseresult. Nothingneeds to be accepted explicitly, since anothingtag is documented as usable with any target function. Custom tag types currently pass via the same fallback ("custom tag: you're on your own"), so rejecting by default would be breaking for them unless they opt in by definingchecktagfor their tag type -- arguably the point, but worth a deprecation path.
- Vorherrschende Sprache
- Julia
- Sterne
- 1k
- Forks
- 162
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Entwicklungsumgebung
Dieses Projekt bietet weder Dev-Container noch Dockerfile noch Beitragsleitfaden – die Einrichtung liegt bei Ihnen. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus JuliaDiff/ForwardDiff.jl
-
missing floatmin, floatmax, and issubnormal for DualEvtl. vergeben @devmotion hat das vor 16 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
JuliaDiff/ForwardDiff.jl#852 · 6 Kommentare ·
-
`fma` and `muladd` ignore NaN-safe modeEvtl. vergeben @devmotion hat das vor 2 Tagen übernommen. Offen
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 55/100
JuliaDiff/ForwardDiff.jl#860 ·
-
Enable NaN-safe mode by defaultEvtl. vergeben @devmotion hat das vor 4 Tagen übernommen. Offen
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 25/100
JuliaDiff/ForwardDiff.jl#857 · 1 Reaktion ·
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 52/100
JuliaDiff/ForwardDiff.jl#854 · 1 Kommentar ·
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 75/100
JuliaDiff/ForwardDiff.jl#849 ·
Alle Issues in JuliaDiff/ForwardDiff.jl
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
JuliaGPU/KernelAbstractions.jl#897 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
oscar-system/GAP.jl#1455 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
JuliaAI/MLJTransforms.jl#85 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100
SciML/OrdinaryDiffEq.jl#4875 ·
Maintainer antworten meist innerhalb von 4 Tagen