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

RFC: Changes to allow JuMPeR to use matrix operations #513

Merged
merged 1 commit into from
Aug 8, 2015
Merged

Conversation

IainNZ
Copy link
Collaborator

@IainNZ IainNZ commented Aug 6, 2015

  • Introduce a new abstract type, to allow Uncertain to be a "JuMPType" basically
  • Tighten a few operator overloads, to avoid ambiguities
  • Introduce a new function, _multiply_type, to determine the storage for matrix multiply

@@ -244,7 +244,8 @@ setPrintHook(m::Model, f) = (m.printhook = f)
###############################################################################
# Variable class
# Doesn't actually do much, just a pointer back to the model
immutable Variable <: ReverseDiffSparse.Placeholder
abstract AbstractVariable <: ReverseDiffSparse.Placeholder
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to allow JuMPTypes to be more general. It may also allow for other code savings in JuMPeR, but just focussed on linalg right now

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like the name though

@joehuchette
Copy link
Contributor

I've been thinking about this for a few weeks now, and how about something like

abstract AbstractScalar <: ReverseDiffSparse.Placeholder
immutable Variable <: AbstractScalar ... end
type GenericAffExpr <: AbstractScalar ... end
type JuMPeR.Uncertain <: AbstractScalar ... end

The only thing I'm unsure about is the <: ReverseDiffSparse.Placeholder. Maybe that could go to a trails-like interface anyway? Seems a bit odd to be doing it through types like this.

@joehuchette
Copy link
Contributor

Or maybe name it something else like AbstractJuMPScalar so then we can do typealias AbstractScalar Union(AbstractJuMPScalar, Number)

@@ -496,13 +496,13 @@ end

# Don't do size checks here in _return_array, defer that to (*)
function _return_array{R,S}(A::AbstractArray{R}, x::AbstractArray{S,1})
Q = (R <: JuMPTypes && S <: JuMPTypes) ? QuadExpr : AffExpr
Q = promote_type(R,S)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works the same way on v0.3 and v0.4? If so that's great, I was never happy about this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Things are not working entirely, but are at least working partially

@IainNZ IainNZ changed the title WIP: Minimal changes to allow JuMP to use matrix operators RFC: Changes to allow JuMPeR to use matrix operations Aug 6, 2015
@joehuchette
Copy link
Contributor

LGTM. Does it make sense to make AffExpr <: AbstractJuMPScalar?

IainNZ added a commit that referenced this pull request Aug 8, 2015
Changes to allow JuMPeR to use matrix operations
@IainNZ IainNZ merged commit 07c23de into master Aug 8, 2015
@IainNZ IainNZ deleted the abstractvar branch August 8, 2015 19:33
(*)(lhs::AffExpr, rhs::Variable) = (*)(rhs,lhs)
(/)(lhs::AffExpr, rhs::Variable) = error("Cannot divide affine expression by a variable")
# AffExpr--Norm
(+){C,V}(lhs::GenericAffExpr{C,V}, rhs::GenericNorm{2,C,V}) = GenericSOCExpr{C,V}(copy(rhs), one(C), copy(lhs))
(-){C,V}(lhs::GenericAffExpr{C,V}, rhs::GenericNorm{2,C,V}) = GenericSOCExpr{C,V}(copy(rhs), -one(C), copy(lhs))
# AffExpr--AffExpr
(+){T<:GenericAffExpr}(lhs::T, rhs::T) = (operator_warn(lhs,rhs); GenericAffExpr(vcat(lhs.vars,rhs.vars),vcat(lhs.coeffs, rhs.coeffs),lhs.constant+rhs.constant))
(-){T<:GenericAffExpr}(lhs::T, rhs::T) = GenericAffExpr(vcat(lhs.vars,rhs.vars),vcat(lhs.coeffs,-rhs.coeffs),lhs.constant-rhs.constant)
(+){C,V<:JuMPTypes}(lhs::GenericAffExpr{C,V}, rhs::GenericAffExpr{C,V}) = (operator_warn(lhs,rhs); GenericAffExpr(vcat(lhs.vars,rhs.vars),vcat(lhs.coeffs, rhs.coeffs),lhs.constant+rhs.constant))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why change this? The previous definition seems fine.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ambiguity warnings, again. Plus, new definition also seemed fine, and this was a minimal change that I couldn't see causing any issues that couldn't be fixed with the new abstract type

@IainNZ
Copy link
Collaborator Author

IainNZ commented Aug 9, 2015

To be clear, the only things I think really needed to be done was the notion of _multiply_type and widening JuMPTypes. Everything else was ambiguity related, so if you have a refactoring I'm definitely into it.

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