-
Notifications
You must be signed in to change notification settings - Fork 43
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
Widen (inv)quad(!) signatures to allow StridedArrays #62
Conversation
Based on my understanding of the logic here, widening the signatures to |
I tested it with a One question, though: the Perhaps more to the point: what method does |
src/pdmat.jl
Outdated
@@ -65,8 +65,8 @@ end | |||
|
|||
### quadratic forms | |||
|
|||
quad(a::PDMat, x::StridedVector) = dot(x, a * x) | |||
invquad(a::PDMat, x::StridedVector) = dot(x, a \ x) | |||
quad(a::PDMat, x::AbstractVector) = dot(x, a * x) |
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.
Is there a method *(a::PDMat, x::AbstractVector)
or only *(a::PDMat, x::StridedVecOrMat)
?
I get
julia> methods(*, (PDMat, AbstractVector))
# 1 method for generic function "*":
*(a::PDMats.PDMat, x::Union{Union{Base.ReshapedArray{T,1,A,MI} where MI<:Tuple{Vararg{Base.MultiplicativeInverses.SignedMultiplicativeInverse{Int64},N} where N} where A<:DenseArray, DenseArray{T,1}, SubArray{T,1,A,I,L} where L} where I<:Tuple{Vararg{Union{Base.AbstractCartesianIndex, Int64, Range{Int64}},N} where N} where A<:Union{Base.ReshapedArray{T,N,A,MI} where MI<:Tuple{Vararg{Base.MultiplicativeInverses.SignedMultiplicativeInverse{Int64},N} where N} where A<:DenseArray where N where T, DenseArray}, Union{Base.ReshapedArray{T,2,A,MI} where MI<:Tuple{Vararg{Base.MultiplicativeInverses.SignedMultiplicativeInverse{Int64},N} where N} where A<:DenseArray, DenseArray{T,2}, SubArray{T,2,A,I,L} where L} where I<:Tuple{Vararg{Union{Base.AbstractCartesianIndex, Int64, Range{Int64}},N} where N} where A<:Union{Base.ReshapedArray{T,N,A,MI} where MI<:Tuple{Vararg{Base.MultiplicativeInverses.SignedMultiplicativeInverse{Int64},N} where N} where A<:DenseArray where N where T, DenseArray}} where T) in PDMats at /Users/jmxp/.julia/v0.6/PDMats/src/pdmat.jl:39
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.
Ah, you're right. It looks like the definition of *
is
*(a::PDMat, x::StridedVecOrMat) = a.mat * x
where the mat
field is <:AbstractMatrix
. So I suppose one could end up with a multiplication that doesn't make sense even with x::StridedVecOrMat
depending on what a.mat
is. To that end, perhaps the signature for *
should be widened as well, and we can just let the type mismatch case fall back to a MethodError
in *
?
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'd like to have @andreasnoack weigh in, but that seems reasonable. It would let people know that *
and \
are the minimal interface they'd need to define for everything else to work.
In this case, you'd also want to widen quad!
and invquad!
everywhere, I think.
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.
Looking through the internals of quad!
and invquad!
for the various types, all of the things that are called look safe to allow AbstractArray
s, so that shouldn't be a problem. Thanks for your help here, @jmxpearson!
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.
Sounds good!
Do you mean with this change or without it?
Currently it's a |
Allowing |
No, because in Distributions we're using a |
julia> view(randn(2,2), :, 1) isa StridedVector
true
julia> view(randn(2,2), [1,2], 1) isa StridedVector
false |
...oh |
Thanks for setting me straight, @andreasnoack. I'll revert the |
How do things look now, @andreasnoack? |
Should help with JuliaStats/Distributions.jl#594.