Skip to content

Commit 16eb3d6

Browse files
authored
Export Utilities.num_rows (#1644)
1 parent 0e54b76 commit 16eb3d6

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

docs/src/submodules/Utilities/reference.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ Utilities.set_index
113113
Utilities.set_types
114114
Utilities.add_set
115115
Utilities.rows
116+
Utilities.num_rows
116117
Utilities.set_with_dimension
117118
```
118119

src/Utilities/product_of_sets.jl

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,13 @@ function final_touch(sets::OrderedProductOfSets)
245245
return
246246
end
247247

248-
function _num_rows(sets::OrderedProductOfSets, ::Type{S}) where {S}
248+
"""
249+
num_rows(sets::OrderedProductOfSets, ::Type{S}) where {S}
250+
251+
Return the number of rows corresponding to a set of type `S`. That is, it is
252+
the sum of the dimensions of the sets of type `S`.
253+
"""
254+
function num_rows(sets::OrderedProductOfSets, ::Type{S}) where {S}
249255
i = set_index(sets, S)
250256
if !sets.final_touch || i == 1
251257
return sets.num_rows[i]
@@ -259,7 +265,7 @@ function MOI.get(
259265
) where {T}
260266
return Tuple{Type,Type}[
261267
(_affine_function_type(T, S), S) for
262-
S in set_types(sets) if _num_rows(sets, S) > 0
268+
S in set_types(sets) if num_rows(sets, S) > 0
263269
]
264270
end
265271

@@ -312,7 +318,7 @@ function _range_iterator(
312318
if i === nothing || F != _affine_function_type(T, S)
313319
return
314320
end
315-
return _range_iterator(sets, i, 1, _num_rows(sets, S), F)
321+
return _range_iterator(sets, i, 1, num_rows(sets, S), F)
316322
end
317323

318324
_length(::Nothing) = 0

test/Utilities/product_of_sets.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ function test_vector_basic()
168168
equalto_ci = MOI.ConstraintIndex{SAF,MOI.EqualTo{Float64}}(equalto_i)
169169
@test MOI.is_valid(sets, equalto_ci)
170170
@test MOI.Utilities.rows(sets, equalto_ci) == 3
171+
@test MOI.Utilities.num_rows(sets, MOI.Nonnegatives) == 2
172+
@test MOI.Utilities.num_rows(sets, MOI.EqualTo{Float64}) == 1
173+
@test MOI.Utilities.num_rows(sets, MOI.Nonpositives) == 0
171174
end
172175

173176
function test_vector_dimension()

0 commit comments

Comments
 (0)