Repository navigation
Closed
Description
There are a bunch of rules for various promote_operation and operate.
MathOptInterface.jl/src/Utilities/functions.jl
Lines 1597 to 1610 in 6b2192a
| ###################################### +/- ##################################### | |
| ## promote_operation | |
| function promote_operation(::typeof(-), ::Type{T}, ::Type{T}) where {T} | |
| return T | |
| end | |
| function promote_operation( | |
| ::typeof(-), | |
| ::Type{T}, | |
| ::Type{<:Union{MOI.VariableIndex,MOI.ScalarAffineFunction{T}}}, | |
| ) where {T} | |
| return MOI.ScalarAffineFunction{T} | |
| end |
MathOptInterface.jl/src/Utilities/functions.jl
Lines 1697 to 1715 in 6b2192a
| # + with at least 3 arguments, can use in-place as the user cannot use | |
| # intermediate results | |
| function operate(::typeof(+), ::Type{T}, f, g, h, args...) where {T} | |
| return operate!(+, T, operate(+, T, f, g), h, args...) | |
| end | |
| # Unary + | |
| function operate(::typeof(+), ::Type{T}, f::MOI.AbstractFunction) where {T} | |
| return f | |
| end | |
| # Scalar number +/- ... | |
| function operate(op::typeof(+), ::Type{T}, α::T, f::ScalarLike{T}) where {T} | |
| return operate(op, T, f, α) | |
| end | |
| function operate(::typeof(-), ::Type{T}, α::T, f::ScalarLike{T}) where {T} | |
| return operate!(+, T, operate(-, T, f), α) | |
| end |
Defining a new function is really hard because it requires whack-a-mole: #2201
I think we need an explicit write up of what functions are implemented, along with tests, so that we can check everything is working as intended.
Reacted by Chris Coey
Metadata
Metadata
Assignees
Labels
No labels
Activity
[-]Re-write promote_operation and operate[/-][+]Re-factor promote_operation and operate[/+]blegat commentedon Jun 12, 2023
Yes, I added them gradually whenever one was needed by a bridge but it would be nice to have a more structured list of what's functions should implement which is useful when defining a new function and what bridges can expect functions have implemented so that you know what you can use when writing a bridge.
odow commentedon Jun 14, 2023
I've been looking into
operate, and it is...not fun. We haveoperateandoperate!andoperate_termandmap_terms!andoperate_termsandoperate_terms!andoperate_output_index!.I haven't quite figured out a sensible approach yet.
odow commentedon Jun 21, 2023
To update this:
Base.overloadsScalarNonlinearFunctionodow commentedon Jun 22, 2023
Closing because this is now a lot cleaner.