-
-
Notifications
You must be signed in to change notification settings - Fork 399
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 more generic (and safer) #459
Conversation
Make dot more generic (and safer)
SCS :'( |
Base.dot{T<:JuMPTypes,S<:JuMPTypes,N}(lhs::Array{T,N},rhs::Array{S,N}) = _dot(lhs,rhs) | ||
Base.dot{T,S<:JuMPTypes,N}(lhs::Array{T,N},rhs::Array{S,N}) = _dot(lhs,rhs) | ||
|
||
function _dot{T,S}(lhs::Array{T}, rhs::Array{S}) |
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.
This is slow in every case, can't we do better? At least dot(Vector{Float64},OneIndexedArray{Variable})
should be very fast.
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 rather just get rid of multidimensional dot, to be honest, considering
it's not in Base.
On Tue, Jun 2, 2015 at 6:34 AM Miles Lubin notifications@github.com wrote:
In src/operators.jl
#459 (comment):-Base.dot{T<:Real,N}(lhs::Array{T,N}, rhs::JuMPArray{Float64,N}) = dot(vec(lhs), vec(rhs.innerArray))
-Base.dot{T<:Real,N}(lhs::JuMPArray{Float64,N}, rhs::Array{T,N}) = dot(vec(rhs), vec(lhs.innerArray))
-Base.dot{T<:Real,N}(lhs::Array{T,N}, rhs::Array{Variable,N}) = AffExpr(vec(rhs), vec(float(lhs)), 0.0)-Base.dot{T<:Real,N}(rhs::Array{Variable,N}, lhs::Array{T,N}) = AffExpr(vec(rhs), vec(float(lhs)), 0.0)
-function Base.dot{N}(lhs::JuMPArray{Variable,N},rhs::JuMPArray{Variable,N})
- size(lhs.innerArray) == size(rhs.innerArray) || error("Incompatible dimensions")
- return QuadExpr(vec(lhs.innerArray), vec(rhs.innerArray), ones(length(lhs.innerArray)), AffExpr())
+Base.dot{T,S,N}(lhs::OneIndexedArray{T,N},rhs::OneIndexedArray{S,N}) = _dot(lhs.innerArray, rhs.innerArray)
+Base.dot{T,S,N}(lhs::OneIndexedArray{T,N},rhs::Array{S,N}) = _dot(lhs.innerArray, rhs)
+Base.dot{T,S,N}(lhs::Array{T,N},rhs::OneIndexedArray{S,N}) = _dot(lhs, rhs.innerArray)
+Base.dot{T<:JuMPTypes,S,N}(lhs::Array{T,N},rhs::Array{S,N}) = _dot(lhs,rhs)
+Base.dot{T<:JuMPTypes,S<:JuMPTypes,N}(lhs::Array{T,N},rhs::Array{S,N}) = _dot(lhs,rhs)
+Base.dot{T,S<:JuMPTypes,N}(lhs::Array{T,N},rhs::Array{S,N}) = _dot(lhs,rhs)
+function _dot{T,S}(lhs::Array{T}, rhs::Array{S})
This is slow in every case, can't we do better? At least
dot(Vector{Float64},OneIndexedArray{Variable}) should be very fast.—
Reply to this email directly or view it on GitHub
https://github.com/JuliaOpt/JuMP.jl/pull/459/files#r31513366.
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.
there is now a vecdot
in 0.4
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.
Cool, I thought I remembered something about to be added. I'll change the naming then.
Also adds a missing method so that e.g.
+(::OneIndexedArray, ::OneIndexedArray)
works as expected.