Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/shapes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ julia> reshape_vector([1, 2, 3], SymmetricMatrixShape(2))
"""
function reshape_vector end

reshape_vector(::Nothing, ::AbstractShape) = nothing

"""
shape(c::AbstractConstraint)::AbstractShape

Expand Down Expand Up @@ -145,6 +147,8 @@ struct ScalarShape <: AbstractShape end

reshape_vector(α, ::ScalarShape) = α

reshape_vector(::Nothing, ::ScalarShape) = nothing

"""
VectorShape()

Expand All @@ -165,7 +169,7 @@ VectorShape()
"""
struct VectorShape <: AbstractShape end

reshape_vector(vectorized_form, ::VectorShape) = vectorized_form
reshape_vector(x::Vector, ::VectorShape) = x

vectorize(x, ::VectorShape) = x

Expand Down Expand Up @@ -193,7 +197,6 @@ struct ArrayShape{N} <: AbstractShape
dims::NTuple{N,Int}
end

reshape_vector(x, shape::ArrayShape) = reshape(x, shape.dims)
reshape_vector(::Nothing, shape::ArrayShape) = nothing
reshape_vector(x::Vector, shape::ArrayShape) = reshape(x, shape.dims)

vectorize(x, ::ArrayShape) = vec(x)
21 changes: 21 additions & 0 deletions test/test_constraint.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2228,4 +2228,25 @@ function test_shadow_price_errors()
return
end

function test_reshape_vector_nothing()
for shape in (
ScalarShape(),
VectorShape(),
ArrayShape((2, 2)),
SymmetricMatrixShape(2),
SymmetricMatrixAdjointShape(2),
SkewSymmetricMatrixShape(2),
SquareMatrixShape(2),
HermitianMatrixShape(2),
HermitianMatrixAdjointShape(2),
)
@test reshape_vector(nothing, shape) === nothing
end
model = Model()
@variable(model, x[1:2, 1:2], PSD)
c = VariableInSetRef(x)
@test dual_start_value(c) === nothing
return
end

end # module
Loading