-
Notifications
You must be signed in to change notification settings - Fork 11
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
WIP: Improve inference of unflatten #46
base: master
Are you sure you want to change the base?
Conversation
src/flatten.jl
Outdated
return x_vec, Array_from_vec | ||
end | ||
|
||
function flatten(::Type{T}, x::SparseMatrixCSC) where {T<:Real} | ||
x_vec, from_vec = flatten(T, x.nzval) | ||
Array_from_vec(x_vec) = SparseMatrixCSC(x.m, x.n, x.colptr, x.rowval, from_vec(x_vec)) | ||
Array_from_vec(x_vec) = _oftype(x, SparseMatrixCSC(x.m, x.n, x.colptr, x.rowval, from_vec(x_vec))) |
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.
[JuliaFormatter] reported by reviewdog 🐶
Array_from_vec(x_vec) = _oftype(x, SparseMatrixCSC(x.m, x.n, x.colptr, x.rowval, from_vec(x_vec))) | |
function Array_from_vec(x_vec) | |
return _oftype(x, SparseMatrixCSC(x.m, x.n, x.colptr, x.rowval, from_vec(x_vec))) | |
end |
Codecov Report
@@ Coverage Diff @@
## master #46 +/- ##
==========================================
+ Coverage 96.55% 96.64% +0.09%
==========================================
Files 4 4
Lines 174 179 +5
==========================================
+ Hits 168 173 +5
Misses 6 6
Continue to review full report at Codecov.
|
Thanks for opening this. I like the general thrust (getting type stability). I'm concerned about the things you've had to do to get it. In particular, one of the things we're trying to do in #39 is remove these kinds of casting operations, so that we can push dual numbers through unflatten. I'm kind of intruiged that it helps to be honest. I'll have a play around locally to try and understand what's going on better. |
I had meant to add in my descrition that this was speculative because I was a little suspicious of these changes (using an annotation) but couldn't see a way for this without that. Regardless, I should have looked closer at the other MRs in play - if the longer term intention is to remove these these operations then this of course is incompatible with that, and i'm happy if this gets closed. |
I'm actually struggling to replicate your problem locally @AlexRobson . Could you provide your |
julia> versioninfo() |
Ah, interesting. Could you try running on 1.6.3? I'll see if I can get a copy of 1.6.2. edit: I actually don't know how to get a copy of 1.6.2 anymore without building from source... |
Hmm i still see this on 1.6.3.
|
Hmm. So I think I've managed to track down the problem, and it's in the unflattener for function flatten(::Type{T}, x::Vector{R}) where {T<:Real,R<:Real}
unflatten_to_Vector(v) = Vector{R}(v)
return Vector{T}(x), unflatten_to_Vector
end also solves the problem on your end? |
d322a9d
to
cf662a8
Compare
Aha! Looks like it. This does fix the majority of the inference tests - thanks. The one that doesn't work is the one related to mvnormal.
This does seem fixed with this change to Deferred though - is this one problematic? Otherwise, I can just set the test above to not check inference as the args are already there.
->
|
Hmm yeah, it'll have the same issue regarding pushing dual numbers through. I'm a bit confused as to why this is failing to infer, because when I dig down a bit everything else seems to infer. I wonder whether we're hitting some kind of compiler heuristic and it's giving up trying to infer or something. edit: I think this is beyond my skill set. Maybe we could ask around a bit? See if someone who knows the compiler better could assist? |
Hmm yeah this is very true. This is still just casting.
I've been playing around with this a bit - descent and REPL play. For what it's worth, I think the point at which inference breaks is the output of the map in
That makes sense. Definitly beyond me! At this point, perhaps it's appropriate for me to just tidy this up with just your suggested fix and adding in the inference tests, and leave |
This is pretty minor but I noticed that there are a few cases where
unflatten
doesn't seem to infer.Some exampes in master on 1.6:
Adding a test for type inference into the test sets shows up a few. I'm aware of the gotcha listed on the docs - ironically that one seems to work on master (Normal => normal)
This MR:
oftype
, so it should know the output.I came to this because I was seeing some inference issues as part of the CRTU tests using a program with deferred, so put this MR together