Skip to content

Commit cc56507

Browse files
authored
Merge pull request #342 from tkoolen/tk/scalar-dim
Define dimension for AbstractScalarSet, add some tests.
2 parents b687aad + 15c4246 commit cc56507

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

src/sets.jl

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,43 @@ 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 output dimension that an [`AbstractFunction`](@ref) should have to be used with the set `s`.
14+
15+
### Examples
16+
17+
```julia-repl
18+
julia> dimension(Reals(4))
19+
4
20+
21+
julia> dimension(LessThan(3.0))
22+
1
23+
24+
julia> dimension(PositiveSemidefiniteConeTriangle(2))
25+
3
26+
```
27+
28+
"""
29+
function dimension end
30+
1031
"""
1132
AbstractScalarSet
1233
1334
Abstract supertype for subsets of ``\\mathbb{R}``.
1435
"""
1536
abstract type AbstractScalarSet <: AbstractSet end
1637

38+
dimension(s::AbstractScalarSet) = 1
39+
1740
"""
1841
AbstractVectorSet
1942
2043
Abstract supertype for subsets of ``\\mathbb{R}^n`` for some ``n``.
2144
"""
2245
abstract type AbstractVectorSet <: AbstractSet end
2346

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-
"""
3047
dimension(s::AbstractVectorSet) = s.dimension # .dimension field is conventional, overwrite this method if not applicable
3148

3249
"""

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)