diff --git a/NEWS.md b/NEWS.md index cf693147dd7..f3f99102d14 100644 --- a/NEWS.md +++ b/NEWS.md @@ -5,8 +5,7 @@ Unversioned ----------- * Support (on Julia 0.4 and later) for conditions in indexing ``@defVar`` and ``@addConstraint`` constructs, e.g. ``@defVar(m, x[i=1:5,j=1:5; i+j >= 3])`` - * Support for vectorized operations on Variables, expressions, and JuMPArrays with indexing over unit-step ranges starting at one. See - the documentation for details. + * Support for vectorized operations on Variables and expressions. See the documentation for details. * New ``getVar()`` method to access variables in a model by name * Support for semidefinite programming. * Dual solutions are now available for general nonlinear problems. You may call ``getDual`` on a reference object for a nonlinear constraint, and ``getDual`` on a variable object for Lagrange multipliers from active bounds. @@ -14,6 +13,7 @@ Unversioned * Second-order cone constraints can be written directly with the ``norm()`` and ``norm2{}`` syntax. * Implement MathProgBase interface for querying Hessian-vector products. * Iteration over ``JuMPContainer``s is deprecated; instead, use the ``keys`` and ``values`` functions, and ``zip(keys(d),values(d))`` for the old behavior. + * ``@defVar`` returns ``Array{Variable,N}`` when each of ``N`` index sets are of the form ``1:nᵢ``. Version 0.9.3 (August 11, 2015) ------------------------------- diff --git a/doc/refexpr.rst b/doc/refexpr.rst index 6b6f05d902b..7270a27bdc0 100644 --- a/doc/refexpr.rst +++ b/doc/refexpr.rst @@ -139,16 +139,16 @@ Vectorized operations ^^^^^^^^^^^^^^^^^^^^^ JuMP supports vectorized expressions and constraints for linear and quadratic models. Although this syntax may -be familiar for users coming from MATLAB-based modeling languages, we caution that this syntax can be slow---especially -for large operations. Nevertheless, the syntax often proves useful, for example in constraints involving small, -dense matrix-vector products. +be familiar for users coming from MATLAB-based modeling languages, we caution that this syntax may be slower than +the scalar versions using loops---especially for large operations. Nevertheless, the syntax often proves useful, +for example in constraints involving small, dense matrix-vector products. Linear algebraic operators are available to give meaning to expressions like ``A*x`` where ``A`` is a matrix -of numbers and ``x`` is a vector of ``Variable``s. You may also use ``JuMPArray``s in these types of expressions, -but only if the index sets that define them are matrix-like: that is, the index sets are ranges of the type +of numbers and ``x`` is a vector of ``Variable``s. You may also use ``Array{Variable}``s in these types of +expressions; for example, any object you construct with ``@defVar`` where each of the index sets are of the form ``1:n``. For example:: - @defVar(m, x[1:3]) + @defVar(m, x[1:3,1:4]) expr = rand(3,3)*x is allowed, while:: @@ -169,8 +169,8 @@ and ``.<=``. For instance, you can write constraints of the form:: Note that scalar literals (such as 1 or 0) are allowed in expressions. -Concatenation is also overloaded for these matrix-like ``JuMPArray``s. For instance, the following will create -a matrix of ``QuadExpr`` that you can use elsewhere in your model:: +Concatenation is also possible for these ``Array``s of ``Variable``s or expressions. For instance, the following +will create a matrix of ``QuadExpr`` that you can use elsewhere in your model:: @defVar(m, x[1:3]) A = [1 x' diff --git a/src/JuMP.jl b/src/JuMP.jl index af369101d85..7f688451351 100644 --- a/src/JuMP.jl +++ b/src/JuMP.jl @@ -378,7 +378,6 @@ function getValue(arr::Array{Variable}) registered = haskey(m.varData, arr) name = registered ? m.varData[arr].name : m.colName[v.col] for I in eachindex(arr) - # TODO: Only warn once v = arr[I] value = _getValue(v) ret[I] = value @@ -614,7 +613,7 @@ end # scalars, and Xᵢ are n×n symmetric variable matrices. The inequality # is taken w.r.t. the psd partial order. type SDPConstraint <: JuMPConstraint - terms # purposely leave this untyped so that we can special-case OneIndexedArray with no additional variables + terms end # Special-case X ≥ 0, which is often convenient diff --git a/test/model.jl b/test/model.jl index 2b3f5fed8ee..c388fc585f6 100644 --- a/test/model.jl +++ b/test/model.jl @@ -347,7 +347,7 @@ facts("[model] Test model copying") do addSOS2(source, [x, 2y]) @addSDPConstraint(source, x*ones(3,3) >= eye(3,3)) @addSDPConstraint(source, ones(3,3) <= 0) - @defVar(source, z[1:3]) # OneIndexedArray + @defVar(source, z[1:3]) @defVar(source, w[2:4]) # JuMPArray @defVar(source, v[[:red],1:3]) # JuMPDict setSolveHook(source, m -> 1) @@ -716,5 +716,6 @@ end facts("[model] Test getValue on OneIndexedArrays") do m = Model() @defVar(m, x[i=1:5], start=i) + @fact typeof(x) --> Vector{Variable} @fact typeof(getValue(x)) --> Vector{Float64} end diff --git a/test/print.jl b/test/print.jl index 61da6dd0df7..4ad98f61d58 100644 --- a/test/print.jl +++ b/test/print.jl @@ -65,7 +65,7 @@ facts("[print] JuMPContainer{Variable}") do #------------------------------------------------------------------ # Test index set printing context("index set printing") do - @defVar(m, rng_unit1[1:10]) # OneIndexedArray + @defVar(m, rng_unit1[1:10]) # Array{Variable} @defVar(m, rng_unit2[-2:3]) # JuMPArray @defVar(m, rng_unit3[[1:10;]]) # JuMPDict @defVar(m, rng_step1[1:2:10])