Skip to content

Commit 8fc8aad

Browse files
committed
Update docstrings
1 parent b315722 commit 8fc8aad

File tree

2 files changed

+64
-57
lines changed

2 files changed

+64
-57
lines changed

src/Utilities/functions.jl

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,26 @@ function scalar_type(::Type{MOI.VectorQuadraticFunction{T}}) where {T}
482482
return MOI.ScalarQuadraticFunction{T}
483483
end
484484

485+
"""
486+
vector_type(::Type{<:MOI.AbstractScalarFunction})
487+
488+
Return the [`MOI.AbstractVectorFunction`](@ref) associated with the scalar type
489+
`F`.
490+
"""
491+
function vector_type end
492+
493+
vector_type(::Type{T}) where {T} = Vector{T}
494+
495+
vector_type(::Type{MOI.VariableIndex}) = MOI.VectorOfVariables
496+
497+
function vector_type(::Type{MOI.ScalarAffineFunction{T}}) where {T}
498+
return MOI.VectorAffineFunction{T}
499+
end
500+
501+
function vector_type(::Type{MOI.ScalarQuadraticFunction{T}}) where {T}
502+
return MOI.VectorQuadraticFunction{T}
503+
end
504+
485505
"""
486506
ScalarFunctionIterator{F<:MOI.AbstractVectorFunction}
487507
@@ -1330,19 +1350,6 @@ function operate_output_index!(
13301350
return x[i] = operate!(op, T, x[i], args...)
13311351
end
13321352

1333-
"""
1334-
promote_operation(
1335-
op::Function,
1336-
::Type{T},
1337-
ArgsTypes::Type{<:Union{T, MOI.AbstractFunction}}...,
1338-
) where {T}
1339-
1340-
Returns the type of the `MOI.AbstractFunction` returned to the call
1341-
`operate(op, T, args...)` where the types of the arguments `args` are
1342-
`ArgsTypes`.
1343-
"""
1344-
function promote_operation end
1345-
13461353
# Helpers
13471354

13481355
function operate_term(

src/Utilities/promote_operation.jl

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4,50 +4,50 @@
44
# Use of this source code is governed by an MIT-style license that can be found
55
# in the LICENSE.md file or at https://opensource.org/licenses/MIT.
66

7-
# There are five methods for which we implement `Utilities.promote_operation`
8-
# and `Utilities.operate`:
9-
#
10-
# 1. `+`
11-
# a. `promote_operation(::typeof(+), ::Type{T}, ::Type{F1}, ::Type{F2})`
12-
# 2. `-`
13-
# a. `promote_operation(::typeof(-), ::Type{T}, ::Type{F})`
14-
# b. `promote_operation(::typeof(-), ::Type{T}, ::Type{F1}, ::Type{F2})`
15-
# c. `promote_operation(::typeof(-), ::Type{T}, ::Type{F1}, ::Type{Vector{T}})`
16-
# 3. `*`
17-
# a. `promote_operation(::typeof(*), ::Type{T}, ::Type{T}, ::Type{F})`
18-
# b. `promote_operation(::typeof(*), ::Type{T}, ::Type{F1}, ::Type{F2})`
19-
# where `F1` and `F2` are `VariableIndex` or `ScalarAffineFunction`
20-
# c. `promote_operation(::typeof(*), ::Type{T}, ::Type{<:Diagonal{T}}, ::Type{F}`
21-
# 4. `/`
22-
# a. `promote_operation(::typeof(/), ::Type{T}, ::Type{F}, ::Type{T})`
23-
# 5. `vcat`
24-
# a. `promote_operation(::typeof(vcat), ::Type{T}, ::Type{F}...)`
25-
# 6. `imag`
26-
# a. `promote_operation(::typeof(imag), ::Type{T}, ::Type{F}`
27-
# where `F` is `VariableIndex` or `VectorOfVariables`
28-
#
29-
# There are eight types:
30-
#
31-
# 1. ::T
32-
# 2. ::VariableIndex
33-
# 3. ::ScalarAffineFunction{T}
34-
# 4. ::ScalarQuadraticFunction{T}
35-
# 5. ::AbstractVector{T}
36-
# 6. ::VectorOfVariables
37-
# 7. ::VectorAffineFunction{T}
38-
# 8. ::VectorQuadraticFunction{T}
39-
40-
vector_type(::Type{T}) where {T} = Vector{T}
41-
42-
vector_type(::Type{MOI.VariableIndex}) = MOI.VectorOfVariables
43-
44-
function vector_type(::Type{MOI.ScalarAffineFunction{T}}) where {T}
45-
return MOI.VectorAffineFunction{T}
46-
end
47-
48-
function vector_type(::Type{MOI.ScalarQuadraticFunction{T}}) where {T}
49-
return MOI.VectorQuadraticFunction{T}
50-
end
7+
"""
8+
promote_operation(
9+
op::Function,
10+
::Type{T},
11+
ArgsTypes::Type{<:Union{T,AbstractVector{T},MOI.AbstractFunction}}...,
12+
) where {T}
13+
14+
Compute the return type of the call `operate(op, T, args...)`, where the types
15+
of the arguments `args` are `ArgsTypes`.
16+
17+
There are five methods for which we implement `Utilities.promote_operation`:
18+
19+
1. `+`
20+
a. `promote_operation(::typeof(+), ::Type{T}, ::Type{F1}, ::Type{F2})`
21+
2. `-`
22+
a. `promote_operation(::typeof(-), ::Type{T}, ::Type{F})`
23+
b. `promote_operation(::typeof(-), ::Type{T}, ::Type{F1}, ::Type{F2})`
24+
c. `promote_operation(::typeof(-), ::Type{T}, ::Type{F1}, ::Type{Vector{T}})`
25+
3. `*`
26+
a. `promote_operation(::typeof(*), ::Type{T}, ::Type{T}, ::Type{F})`
27+
b. `promote_operation(::typeof(*), ::Type{T}, ::Type{F1}, ::Type{F2})`
28+
where `F1` and `F2` are `VariableIndex` or `ScalarAffineFunction`
29+
c. `promote_operation(::typeof(*), ::Type{T}, ::Type{<:Diagonal{T}}, ::Type{F}`
30+
4. `/`
31+
a. `promote_operation(::typeof(/), ::Type{T}, ::Type{F}, ::Type{T})`
32+
5. `vcat`
33+
a. `promote_operation(::typeof(vcat), ::Type{T}, ::Type{F}...)`
34+
6. `imag`
35+
a. `promote_operation(::typeof(imag), ::Type{T}, ::Type{F}`
36+
where `F` is `VariableIndex` or `VectorOfVariables`
37+
38+
There are nine types:
39+
40+
1. ::T
41+
2. ::VariableIndex
42+
3. ::ScalarAffineFunction{T}
43+
4. ::ScalarQuadraticFunction{T}
44+
5. ::ScalarNonlinearFunction
45+
6. ::AbstractVector{T}
46+
7. ::VectorOfVariables
47+
8. ::VectorAffineFunction{T}
48+
9. ::VectorQuadraticFunction{T}
49+
"""
50+
function promote_operation end
5151

5252
### Method 1a and 2b
5353

0 commit comments

Comments
 (0)