Improve type stability of ProjectTo(non-numeric array).#557
Improve type stability of ProjectTo(non-numeric array).#557ToucheSir wants to merge 1 commit intoJuliaDiff:mainfrom
ProjectTo(non-numeric array).#557Conversation
This improves type stability when elements hit `ProjectTo(::Any)`.
Codecov Report
@@ Coverage Diff @@
## main #557 +/- ##
=======================================
Coverage 93.02% 93.02%
=======================================
Files 15 15
Lines 860 860
=======================================
Hits 800 800
Misses 60 60
Continue to review full report at Codecov.
|
|
Are there any relevant weird cases where these may differ? An irrelevant one is this (because adjoint vectors have their own path): julia> map(sqrt, [1,2,3]')
1×3 adjoint(::Vector{Float64}) with eltype Float64:
1.0 1.41421 1.73205
julia> sqrt.([1,2,3]')
1×3 Matrix{Float64}:
1.0 1.41421 1.73205 |
|
I thought SparseArrays might, but it appears map and broadcast behave similarly for them. One concern I did find though while writing up FluxML/Zygote.jl#1248 (comment) is that this PR appears to add a few seconds of latency to the MWE there. Will have to do a proper investigation to confirm that. |
|
OK, that's interesting. Nothing about ProjectTo was closely looked at for latency, sadly. |
Use broadcasting instead of
mapfor non-numeric array projectors. This improves type stability when elements hitProjectTo(::Any).I found this while trying to use https://github.com/JuliaDiff/ChainRules.jl/blob/v1.35.3/src/rulesets/Base/mapreduce.jl#L425 with a vector of callables. It's unfortunate that inference can't figure out the map call, but at least broadcasting works.