Skip to content
Permalink
Browse files

Rename reshape -> reshape_result

  • Loading branch information...
blegat committed Feb 5, 2019
1 parent f46a461 commit 8c044f4a03ca154c363ca50722c6ecbb9a68df4c
Showing with 20 additions and 20 deletions.
  1. +1 −1 docs/src/extensions.md
  2. +1 −1 examples/multi.jl
  3. +2 −2 src/JuMP.jl
  4. +10 −10 src/constraints.jl
  5. +5 −5 src/sd.jl
  6. +1 −1 test/operator.jl
@@ -73,7 +73,7 @@ used to reshape the result computed in [`value`](@ref) and [`dual`](@ref).
```@docs
AbstractShape
shape
reshape
reshape_result
dual_shape
ScalarShape
VectorShape
@@ -45,7 +45,7 @@ function example_multi(; verbose = true)
limit = [625.0 for j in 1:numorig, i in 1:numdest]

# cost(dest, orig, prod) Shipment cost per unit
cost = Base.reshape([
cost = reshape([
[
[ 30, 10, 8, 10, 11, 71, 6];
[ 22, 7, 10, 7, 21, 82, 13];
@@ -528,8 +528,8 @@ Use `has_dual` to check if a result exists before asking for values.
See also [`shadow_price`](@ref).
"""
function dual(cr::ConstraintRef{Model, <:MOICON})
return reshape(MOI.get(cr.model, MOI.ConstraintDual(), cr),
dual_shape(cr.shape))
return reshape_result(MOI.get(cr.model, MOI.ConstraintDual(), cr),
dual_shape(cr.shape))
end

"""
@@ -12,7 +12,7 @@
AbstractShape
Abstract vectorizable shape. Given a flat vector form of an object of shape
`shape`, the original object can be obtained by [`reshape`](@ref).
`shape`, the original object can be obtained by [`reshape_result`](@ref).
"""
abstract type AbstractShape end

@@ -36,7 +36,7 @@ end
struct PolynomialShape <: AbstractShape
monomials::Vector{Monomial}
end
JuMP.reshape(x::Vector, shape::PolynomialShape) = Polynomial(x, shape.monomials)
JuMP.reshape_result(x::Vector, shape::PolynomialShape) = Polynomial(x, shape.monomials)
```
and a shape for moments can be defined as follows:
```julia
@@ -47,7 +47,7 @@ end
struct MomentsShape <: AbstractShape
monomials::Vector{Monomial}
end
JuMP.reshape(x::Vector, shape::MomentsShape) = Moments(x, shape.monomials)
JuMP.reshape_result(x::Vector, shape::MomentsShape) = Moments(x, shape.monomials)
```
The `dual_shape` allows to define the shape of the dual of polynomial and moment
constraints:
@@ -59,7 +59,7 @@ dual_shape(shape::MomentsShape) = PolynomialShape(shape.monomials)
dual_shape(shape::AbstractShape) = shape

"""
reshape(vectorized_form::Vector, shape::AbstractShape)
reshape_result(vectorized_form::Vector, shape::AbstractShape)
Return an object in its original shape `shape` given its vectorized form
`vectorized_form`.
@@ -69,10 +69,10 @@ Return an object in its original shape `shape` given its vectorized form
Given a [`SymmetricMatrixShape`](@ref) of vectorized form `[1, 2, 3]`, the
following code returns the matrix `Symmetric(Matrix[1 2; 2 3])`:
```julia
reshape([1, 2, 3], SymmetricMatrixShape(2))
reshape_result([1, 2, 3], SymmetricMatrixShape(2))
```
"""
function reshape end
function reshape_result end

"""
shape(c::AbstractConstraint)::AbstractShape
@@ -87,15 +87,15 @@ function shape end
Shape of scalar constraints.
"""
struct ScalarShape <: AbstractShape end
reshape(α, ::ScalarShape) = α
reshape_result(α, ::ScalarShape) = α

"""
VectorShape
Vector for which the vectorized form corresponds exactly to the vector given.
"""
struct VectorShape <: AbstractShape end
reshape(vectorized_form, ::VectorShape) = vectorized_form
reshape_result(vectorized_form, ::VectorShape) = vectorized_form

"""
ConstraintRef
@@ -523,8 +523,8 @@ evaluation of `2x + 3y`.
```
"""
function value(cref::ConstraintRef{Model, <:MOICON})
return reshape(MOI.get(cref.model, MOI.ConstraintPrimal(), cref),
cref.shape)
return reshape_result(MOI.get(cref.model, MOI.ConstraintPrimal(), cref),
cref.shape)
end

"""
@@ -53,7 +53,7 @@ lower-left triangular part given row by row).
struct SymmetricMatrixShape <: AbstractShape
side_dimension::Int
end
function reshape(vectorized_form::Vector{T}, shape::SymmetricMatrixShape) where T
function reshape_result(vectorized_form::Vector{T}, shape::SymmetricMatrixShape) where T
matrix = Matrix{T}(undef, shape.side_dimension, shape.side_dimension)
k = 0
for j in 1:shape.side_dimension
@@ -76,10 +76,10 @@ row).
struct SquareMatrixShape <: AbstractShape
side_dimension::Int
end
function reshape(vectorized_form::Vector{T}, shape::SquareMatrixShape) where T
return Base.reshape(vectorized_form,
shape.side_dimension,
shape.side_dimension)
function reshape_result(vectorized_form::Vector{T}, shape::SquareMatrixShape) where T
return Base.reshape_result(vectorized_form,
shape.side_dimension,
shape.side_dimension)
end

"""
@@ -569,7 +569,7 @@ function operators_test(ModelType::Type{<:JuMP.AbstractModel}, VariableRefType::
6 0 7]
B = sparse(A)
# force vector output
cref1 = @constraint(m, Base.reshape(x, (1, 3)) * A * x .>= 1)
cref1 = @constraint(m, reshape(x, (1, 3)) * A * x .>= 1)
c1 = JuMP.constraint_object.(cref1)
f1 = map(c -> c.func, c1)
@test JuMP.isequal_canonical(f1, [x[1]*x[1] + 2x[1]*x[2] + 4x[2]*x[2] + 9x[1]*x[3] + 5x[2]*x[3] + 7x[3]*x[3]])

0 comments on commit 8c044f4

Please sign in to comment.
You can’t perform that action at this time.