-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Make dot
handle missing
s
#40769
base: master
Are you sure you want to change the base?
Make dot
handle missing
s
#40769
Conversation
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.
Seems uncontroversial enough to me.
The doc says that
Extending this to also encompass the full LinearAlgebra standard library seems excessive. This would require adding a huge number of this special cased Missing methods. And if the goal is not the whole LinearAlgebra standard library, what is special about this function? What about |
When I read:
then I expect that the The julia> using LinearAlgebra
julia> norm([1.0, missing, 2.0])
ERROR: TypeError: non-boolean (Missing) used in boolean context
Stacktrace:
[1] generic_normInf(x::Vector{Union{Missing, Float64}})
@ LinearAlgebra C:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.6\LinearAlgebra\src\generic.jl:472
[2] normInf
@ C:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.6\LinearAlgebra\src\generic.jl:556 [inlined]
[3] generic_norm2(x::Vector{Union{Missing, Float64}})
@ LinearAlgebra C:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.6\LinearAlgebra\src\generic.jl:497
[4] norm2
@ C:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.6\LinearAlgebra\src\generic.jl:558 [inlined]
[5] norm(itr::Vector{Union{Missing, Float64}}, p::Int64)
@ LinearAlgebra C:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.6\LinearAlgebra\src\generic.jl:627
[6] norm(itr::Vector{Union{Missing, Float64}})
@ LinearAlgebra C:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.6\LinearAlgebra\src\generic.jl:625 Perhaps e.g. I came across the |
I think That said,
Downside is that it's going to be less fast than handling I have a stagnant PR here which should provide a more general and performant solution. Implementation is a bit beyond me, so I'm looking for someone to take it over. EDIT: My solution doesn't actually fix OP's problem. They want |
BTW, we do have a definition of |
I'm gonna push the corresponding changes to make using LinearAlgebra, BenchmarkTools
x = convert(Vector{Union{Missing,Float64}}, rand(10000))
@btime norm($x) and seem to get massive speed-up on this branch?! (33.714 μs vs 2.089 ms (10004 allocations: 156.34 KiB)) EDIT: The speed-up seems to be real, and probably because of some type-instability that is "fixed" here. |
That seems like an issue with
The frequency by which a function is called surely cannot be used as a deciding factor for whether it should be Missing-special-cased? Either it makes sense, or it doesn't, no matter how often the function is called. |
No, it's not, Let's re-wind a bit. @KristofferC can you please state here your definition of a "dot product"? If we have different definitions in mind, then we can clarify that first. However, if we have the same definition in mind, then the situation is clear. StatsBase does what its supposed to, and a dot product of two vectors with missing values must return |
It's important to note that As I said above, it's the recursiveness that's causing the problem, and this is a technical detail. If |
@dkarrasch can you split the |
I noticed that |
It's a bit unclear. The difference is that both |
I think the rationale to support |
(just pointing out that I don't/didn't mean to block this PR but I do think the arguments for it have been kinda weak) |
See #42812 for another case where this PR would have been useful. |
So the failure here is a consequence of #27401. @Datseris and @pdeffebach are expecting julia> x'w
missing so I think it make more sense just to use that syntax in e.g. StatsBase instead of introducing special handling of missing in linear algebra functions. See also #27677 for a version of |
From triage:
|
Fixes JuliaLang/LinearAlgebra.jl#844.