Skip to content

Commit

Permalink
Export Utilities.num_rows (#1644)
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat authored Nov 11, 2021
1 parent 0e54b76 commit 16eb3d6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/src/submodules/Utilities/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ Utilities.set_index
Utilities.set_types
Utilities.add_set
Utilities.rows
Utilities.num_rows
Utilities.set_with_dimension
```

Expand Down
12 changes: 9 additions & 3 deletions src/Utilities/product_of_sets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,13 @@ function final_touch(sets::OrderedProductOfSets)
return
end

function _num_rows(sets::OrderedProductOfSets, ::Type{S}) where {S}
"""
num_rows(sets::OrderedProductOfSets, ::Type{S}) where {S}
Return the number of rows corresponding to a set of type `S`. That is, it is
the sum of the dimensions of the sets of type `S`.
"""
function num_rows(sets::OrderedProductOfSets, ::Type{S}) where {S}
i = set_index(sets, S)
if !sets.final_touch || i == 1
return sets.num_rows[i]
Expand All @@ -259,7 +265,7 @@ function MOI.get(
) where {T}
return Tuple{Type,Type}[
(_affine_function_type(T, S), S) for
S in set_types(sets) if _num_rows(sets, S) > 0
S in set_types(sets) if num_rows(sets, S) > 0
]
end

Expand Down Expand Up @@ -312,7 +318,7 @@ function _range_iterator(
if i === nothing || F != _affine_function_type(T, S)
return
end
return _range_iterator(sets, i, 1, _num_rows(sets, S), F)
return _range_iterator(sets, i, 1, num_rows(sets, S), F)
end

_length(::Nothing) = 0
Expand Down
3 changes: 3 additions & 0 deletions test/Utilities/product_of_sets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ function test_vector_basic()
equalto_ci = MOI.ConstraintIndex{SAF,MOI.EqualTo{Float64}}(equalto_i)
@test MOI.is_valid(sets, equalto_ci)
@test MOI.Utilities.rows(sets, equalto_ci) == 3
@test MOI.Utilities.num_rows(sets, MOI.Nonnegatives) == 2
@test MOI.Utilities.num_rows(sets, MOI.EqualTo{Float64}) == 1
@test MOI.Utilities.num_rows(sets, MOI.Nonpositives) == 0
end

function test_vector_dimension()
Expand Down

0 comments on commit 16eb3d6

Please sign in to comment.