Skip to content

Commit 6baf622

Browse files
committed
Update
1 parent 009183f commit 6baf622

File tree

2 files changed

+8
-46
lines changed

2 files changed

+8
-46
lines changed

src/Utilities/promote_operation.jl

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,16 @@
1414
Compute the return type of the call `operate(op, T, args...)`, where the types
1515
of the arguments `args` are `ArgsTypes`.
1616
17+
One assumption is that the element type `T` is invariant under each operation.
18+
That is, `op(::T, ::T)::T` where `op` is a `+`, `-`, `*`, and `/`.
19+
1720
There are five methods for which we implement `Utilities.promote_operation`:
1821
1922
1. `+`
2023
a. `promote_operation(::typeof(+), ::Type{T}, ::Type{F1}, ::Type{F2})`
2124
2. `-`
2225
a. `promote_operation(::typeof(-), ::Type{T}, ::Type{F})`
2326
b. `promote_operation(::typeof(-), ::Type{T}, ::Type{F1}, ::Type{F2})`
24-
c. `promote_operation(::typeof(-), ::Type{T}, ::Type{F1}, ::Type{Vector{T}})`
2527
3. `*`
2628
a. `promote_operation(::typeof(*), ::Type{T}, ::Type{T}, ::Type{F})`
2729
b. `promote_operation(::typeof(*), ::Type{T}, ::Type{F}, ::Type{T})`
@@ -33,10 +35,13 @@ There are five methods for which we implement `Utilities.promote_operation`:
3335
5. `vcat`
3436
a. `promote_operation(::typeof(vcat), ::Type{T}, ::Type{F}...)`
3537
6. `imag`
36-
a. `promote_operation(::typeof(imag), ::Type{T}, ::Type{F}`
38+
a. `promote_operation(::typeof(imag), ::Type{T}, ::Type{F})`
3739
where `F` is `VariableIndex` or `VectorOfVariables`
3840
39-
There are nine types:
41+
In each case, `F` (or `F1` and `F2`) is one of the nine supported types, with
42+
a restriction that the mathematical operation makes sense, for example, we don't
43+
define `promote_operation(-, T, F1, F2)` where `F1` is a scalar-valued function
44+
and `F2` is a vector-valued function. The nine supported types are:
4045
4146
1. ::T
4247
2. ::VariableIndex
@@ -166,33 +171,6 @@ function promote_operation(
166171
return MOI.VectorAffineFunction{T}
167172
end
168173

169-
### Method 2c
170-
171-
function promote_operation(
172-
::typeof(-),
173-
::Type{T},
174-
::Type{F},
175-
::Type{<:AbstractVector{T}},
176-
) where {
177-
T,
178-
F<:Union{
179-
AbstractVector{T},
180-
MOI.VectorAffineFunction{T},
181-
MOI.VectorQuadraticFunction{T},
182-
},
183-
}
184-
return F
185-
end
186-
187-
function promote_operation(
188-
::typeof(-),
189-
::Type{T},
190-
::Type{MOI.VectorOfVariables},
191-
::Type{<:AbstractVector{T}},
192-
) where {T}
193-
return MOI.VectorAffineFunction{T}
194-
end
195-
196174
### Method 3a
197175

198176
function promote_operation(

test/Utilities/test_promote_operation.jl

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -106,22 +106,6 @@ function test_promote_operation_2b()
106106
return
107107
end
108108

109-
function test_promote_operation_2c()
110-
T = Int
111-
F = (
112-
Vector{T},
113-
MOI.VectorOfVariables,
114-
MOI.VectorAffineFunction{T},
115-
MOI.VectorQuadraticFunction{T},
116-
)
117-
special_cases = Dict(2 => 3)
118-
for i in 1:4
119-
j = get(special_cases, i, i)
120-
@test MOI.Utilities.promote_operation(-, T, F[i], F[1]) == F[j]
121-
end
122-
return
123-
end
124-
125109
function test_promote_operation_3a()
126110
T = Int
127111
F = (

0 commit comments

Comments
 (0)