-
Notifications
You must be signed in to change notification settings - Fork 97
inbounds for is_strictly_increasing #1325
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
Conversation
odow
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it really make that much of a difference for #1287? It's not often we have functions with 10k terms.
|
This seems to be proportional to the overall number of non-zeros, not just in one function. |
|
Before After function MathOptInterface.Utilities.is_strictly_sorted(x::Vector, by, filter)
if isempty(x)
return true
end
current_x = first(x)
if !filter(current_x)
return false
end
current_fx = by(current_x)
@inbounds for i in eachindex(x)[2:end]
next_x = x[i]
if !filter(next_x)
return false
end
next_fx = by(next_x)
if next_fx <= current_fx
return false
end
current_x, current_fx = next_x, next_fx
end
return true
end |
|
Actually this was better function MathOptInterface.Utilities.is_strictly_sorted(x::Vector, by, filter)
if isempty(x)
return true
end
@inbounds current_x = first(x)
if !filter(current_x)
return false
end
current_fx = by(current_x)
for i in eachindex(x)[2:end]
@inbounds next_x = x[i]
if !filter(next_x)
return false
end
next_fx = by(next_x)
if next_fx <= current_fx
return false
end
current_x, current_fx = next_x, next_fx
end
return true
endThere's too much noise with only 10k terms. |
|
This is the part of copying to |

As this is taking a non-negligeable time in #1287, it is worth optimizing.
Consider the benchmark:
Before:
Initial suggestion:
@odow improved implementation: