-
Notifications
You must be signed in to change notification settings - Fork 158
Add tagdepth fast path to tag comparison #807
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,10 +20,16 @@ end | |
|
|
||
| Tag(::Nothing, ::Type{V}) where {V} = nothing | ||
|
|
||
| @inline tagdepth(::Type) = 0 | ||
| @inline tagdepth(::Type{<:Dual{T,V,N}}) where {T,V,N} = 1 + tagdepth(V) | ||
| @inline tagdepth(::Type{<:Tag{F,V}}) where {F,V} = 1 + tagdepth(V) | ||
|
|
||
| @inline function ≺(::Type{Tag{F1,V1}}, ::Type{Tag{F2,V2}}) where {F1,V1,F2,V2} | ||
| tagcount(Tag{F1,V1}) < tagcount(Tag{F2,V2}) | ||
| end | ||
| d1 = tagdepth(Tag{F1,V1}) | ||
| d2 = tagdepth(Tag{F2,V2}) | ||
| d1 != d2 && return d1 < d2 | ||
|
Comment on lines
+28
to
+30
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can define
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the tags are defined according to the interfaces in the package, T is the type being differentiated. If T is the type being differentiated, then this gaurentees tag ordering by differentiation hierarchy. We previously had PRs closed about documenting this saying that it is non public API, so since this package always obeys that invarient internally and it's purposefully non public, it would be non breaking to enforce it. |
||
| return tagcount(Tag{F1,V1}) < tagcount(Tag{F2,V2}) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems one could still run into the same precompilation-caused problems here, e.g., if
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Build an example? All of the examples from before that cannot happen because it's not Float64 in both cases but Dual of Float64, and that tag nesting is exactly the part you missed from the earlier part. |
||
| end | ||
|
|
||
| struct InvalidTagException{E,O} <: Exception | ||
| end | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just defining this function on
::TypeandType{<:Dual}? Why::Type{<:Tag}as well?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because when you nest it's a tag of duals