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

Can we make at-expression more general? #525

Closed
IainNZ opened this issue Aug 11, 2015 · 6 comments · Fixed by #2070
Closed

Can we make at-expression more general? #525

IainNZ opened this issue Aug 11, 2015 · 6 comments · Fixed by #2070
Labels
Category: Containers Related to the Containers submodule
Milestone

Comments

@IainNZ
Copy link
Collaborator

IainNZ commented Aug 11, 2015

At the moment if only works for linear expressions, which means it can't be used for extensions (or even quadratics). One option would be just to use JuMPDicts of Anys, I guess, but that could hurt you if you wanted to use it for matrix ops later I suppose.

@mlubin
Copy link
Member

mlubin commented Aug 11, 2015

The scalar @defExpr should work for generic expressions on 0.4 (but not 0.3).
For collections of expressions, we should probably choose the type of the JuMP container optimistically (like map) and widen it if we need to. Will be easier to implement once the JuMPArray code becomes nicer.

@IainNZ
Copy link
Collaborator Author

IainNZ commented Aug 11, 2015

Yeah I was thinking of collections.

@IainNZ IainNZ added this to the 0.11 milestone Aug 11, 2015
@mlubin mlubin modified the milestones: 0.12, 0.11 Dec 1, 2015
@mlubin mlubin modified the milestones: 0.13, 0.12 Feb 21, 2016
@mlubin mlubin removed this from the 0.13 milestone Apr 29, 2016
@mlubin mlubin added this to the 1.0 milestone Dec 11, 2016
@mlubin mlubin added the Category: Containers Related to the Containers submodule label Jan 8, 2017
@mlubin mlubin changed the title Can we make at-defExpr more general? Can we make at-expression more general? May 20, 2017
@mlubin
Copy link
Member

mlubin commented Feb 25, 2019

This still doesn't work:

julia> @expression(m, [i=1:2], x^2)
ERROR: Collection of expressions with @expression must be linear. For quadratic expressions, use your own array.

@blegat
Copy link
Member

blegat commented Feb 25, 2019

We should make containers infer the element type by creating the first element and looking at its value. This would also remove the need for JuMP.constraint_type which is bad since it does not return a concrete type

@mlubin
Copy link
Member

mlubin commented Mar 1, 2019

We should make containers infer the element type by creating the first element and looking at its value.

We shouldn't assume that the element type is homogeneous. We should use the same approach as map and widen/promote if needed:

julia> map(+, Any[1, 2, 3], Any[10, 20, 30])
3-element Array{Int64,1}:
 11
 22
 33

julia> map(+, Any[1, 2, 3], Any[10, 20, 30.0])
3-element Array{Real,1}:
 11  
 22  
 33.0

@blegat
Copy link
Member

blegat commented Mar 1, 2019

We shouldn't assume that the element type is homogeneous. We should use the same approach as map and widen/promote if needed

I agree, normally, this is what is done by Base.collect_to_with_first! for Vector, implementing Base.collect_to_with_first! for Containers might be the way to go.
The broad idea is instead of creating nested loops, we create a function that given the indices, return the element for these indices, we feed this function to a Base.Generator and then we collect. That is what map does.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category: Containers Related to the Containers submodule
Development

Successfully merging a pull request may close this issue.

3 participants