Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-factor promote_operation and operate #2203

Closed
odow opened this issue Jun 12, 2023 · 4 comments
Closed

Re-factor promote_operation and operate #2203

odow opened this issue Jun 12, 2023 · 4 comments

Comments

@odow
Copy link
Member

odow commented Jun 12, 2023

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.

@odow odow changed the title Re-write promote_operation and operate Re-factor promote_operation and operate Jun 12, 2023
@blegat
Copy link
Member

blegat commented 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
Copy link
Member Author

odow commented Jun 14, 2023

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.

@odow
Copy link
Member Author

odow commented Jun 21, 2023

@odow
Copy link
Member Author

odow commented Jun 22, 2023

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
Labels
None yet
Development

No branches or pull requests

2 participants