Skip to content
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

Merged
merged 1 commit into from
Jun 2, 2015
Merged

Make dot more generic (and safer) #459

merged 1 commit into from
Jun 2, 2015

Conversation

joehuchette
Copy link
Contributor

Also adds a missing method so that e.g. +(::OneIndexedArray, ::OneIndexedArray) works as expected.

joehuchette added a commit that referenced this pull request Jun 2, 2015
Make dot more generic (and safer)
@joehuchette joehuchette merged commit 79448dd into master Jun 2, 2015
@joehuchette
Copy link
Contributor Author

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})
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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

Copy link
Contributor Author

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.

@joehuchette joehuchette deleted the array-fixes branch June 9, 2015 01:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants