-
Notifications
You must be signed in to change notification settings - Fork 63
Add ProjectTo{Tuple}
#457
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
Add ProjectTo{Tuple}
#457
Conversation
Codecov Report
@@ Coverage Diff @@
## master #457 +/- ##
==========================================
- Coverage 92.94% 92.43% -0.52%
==========================================
Files 14 14
Lines 794 806 +12
==========================================
+ Hits 738 745 +7
- Misses 56 61 +5
Continue to review full report at Codecov.
|
Let's discuss in a separate issue |
As written this will allow It's possible that the array projector should notice this, and (1) treat a uniform array of tuples more like an array of numbers, one projector, and (2) possibly just reinterpret or something? |
src/projection.jl
Outdated
if all(p -> p isa ProjectTo{<:AbstractZero}, elements) | ||
ProjectTo{NoTangent}() # short-circuit if all elements project to zero | ||
else | ||
return ProjectTo{Tuple}(; type=typeof(xs), elements=elements) |
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.
I kinda want to stick the whole primal type into the type parameter for ProjectTo
.
We need it anyway.
This typeof is going to make accessing project.type
type unstable, since it will make a NamedTuple with a DataType typed field.
julia> (;type = Type{typeof((1,2))}) |> typeof
NamedTuple{(:type,), Tuple{DataType}}
So if we want to store it as an element we need to wrap it up in Val
julia> (;type = Val{typeof((1,2))}()) |> typeof
NamedTuple{(:type,), Tuple{Val{Tuple{Int64, Int64}}}}
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.
Good point. Same applies to Ref
.
a8fad7f
to
2dd11c8
Compare
Major comment I think we need to resolve: I think ProjectTo{Tangent}(; type=Val(typeof(xs)), elements=elements) or, and I would make a strongish case for this: ProjectTo{Tangent{typeof(xs)}(;elements=elements) If we did that later one then there are 3 advantages:
|
Yes I guess I agree that However, I'm not going to do that in this PR. It can be a fresh one, either after or instead of this one. Being able to handle tuples at all, and produce the right Tangents, was intended to simplify JuliaDiff/ChainRules.jl#526 . |
I think instead-of, rather than after.
That still applies right? Or is there a rush to get that in for a thing? |
No, there's no rush. Just revisiting things to look for loose ends. |
Besides actually projecting values, the nice thing about having this is that
project(dx)
would handle constructing the rightTangent
type. This will simplify rules overx::AbstractVecOrTuple
.The other thing which would simplify such rules is a function
_no_tuple_tangent
which does nothing to vectors but callsbacking
on Tangents, so that internally you can deal with the tuple or vector on equal terms. Not yet added here, but could be.