Skip to content

Re-factor promote_operation and operate #2203

Closed

Description

@odow

There are a bunch of rules for various promote_operation and operate.

###################################### +/- #####################################
## 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

# + 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.

Activity

  1. changed the title [-]Re-write promote_operation and operate[/-] [+]Re-factor promote_operation and operate[/+] on Jun 12, 2023
  2. blegat commented on Jun 12, 2023

    @blegat
    Member

    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.

  3. odow commented on Jun 14, 2023

    @odow
    MemberAuthor

    I've been looking into operate, and it is...not fun. We have operate and operate! and operate_term and map_terms! and operate_terms and operate_terms! and operate_output_index!.

    I haven't quite figured out a sensible approach yet.

  4. odow commented on Jun 21, 2023

    @odow
    MemberAuthor
  5. odow commented on Jun 22, 2023

    @odow
    MemberAuthor

    Closing because this is now a lot cleaner.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions