Skip to content

Commit 75302a6

Browse files
committed
Define dimension for AbstractScalarSet, add some tests.
1 parent cd3115d commit 75302a6

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

src/sets.jl

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,30 @@ Abstract supertype for set objects used to encode constraints.
77
"""
88
abstract type AbstractSet end
99

10+
"""
11+
dimension(s::AbstractSet)
12+
13+
Return the underlying dimension (number of vector components) in the set `s`, i.e.,
14+
``n`` if the set is a subset of ``\\mathbb{R}^n``.
15+
"""
16+
function dimension end
17+
1018
"""
1119
AbstractScalarSet
1220
1321
Abstract supertype for subsets of ``\\mathbb{R}``.
1422
"""
1523
abstract type AbstractScalarSet <: AbstractSet end
1624

25+
dimension(s::AbstractScalarSet) = 1
26+
1727
"""
1828
AbstractVectorSet
1929
2030
Abstract supertype for subsets of ``\\mathbb{R}^n`` for some ``n``.
2131
"""
2232
abstract type AbstractVectorSet <: AbstractSet end
2333

24-
"""
25-
dimension(s::AbstractVectorSet)
26-
27-
Return the underlying dimension (number of vector components) in the set `s`, i.e.,
28-
``n`` if the set is a subset of ``\\mathbb{R}^n``.
29-
"""
3034
dimension(s::AbstractVectorSet) = s.dimension # .dimension field is conventional, overwrite this method if not applicable
3135

3236
"""
@@ -184,7 +188,7 @@ dimension(s::Union{ExponentialCone, DualExponentialCone, PowerCone, DualPowerCon
184188
185189
The (vectorized) cone of symmetric positive semidefinite matrices, with side length `dimension` and with off-diagonals unscaled.
186190
The entries of the upper triangular part of the matrix are given column by column (or equivalently, the entries of the lower triangular part are given row by row).
187-
An ``dimension \\times dimension`` matrix has ``dimension(dimension+1)/2`` lower-triangular elements, so for the vectorized cone of dimension ``n``, the corresponding symmetric matrix has side dimension ``\\sqrt{1/4 + 2 n} - 1/2`` elements.
191+
An ``dimension \\times dimension`` matrix has ``dimension * (dimension+1)/2`` lower-triangular elements, so for the vectorized cone of dimension ``n``, the corresponding symmetric matrix has side dimension ``\\sqrt{1/4 + 2 n} - 1/2`` elements.
188192
189193
### Examples
190194

test/sets.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,16 @@
33
@test MOIU.getconstant(MOI.GreaterThan(6)) == 6
44
@test MOIU.getconstant(MOI.LessThan(2)) == 2
55
end
6+
7+
@testset "Set dimension" begin
8+
@test MOI.dimension(MOI.EqualTo(3.0)) === 1
9+
@test MOI.dimension(MOI.Reals(8)) === 8
10+
@test MOI.dimension(MOI.DualExponentialCone()) === 3
11+
@test MOI.dimension(MOI.PositiveSemidefiniteConeTriangle(4)) === 10
12+
@test MOI.dimension(MOI.PositiveSemidefiniteConeSquare(5)) === 25
13+
@test MOI.dimension(MOI.RootDetConeTriangle(6)) === 22
14+
@test MOI.dimension(MOI.LogDetConeTriangle(6)) === 22
15+
@test MOI.dimension(MOI.RootDetConeSquare(4)) === 17
16+
@test MOI.dimension(MOI.LogDetConeSquare(4)) === 17
17+
@test MOI.dimension(MOI.SOS2(collect(1 : 6))) === 6
18+
end

0 commit comments

Comments
 (0)