Skip to content

Correct number of srcs in complete #2468

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

Merged
merged 1 commit into from
Feb 17, 2024
Merged

Conversation

Keno
Copy link
Contributor

@Keno Keno commented Feb 14, 2024

When constructing the inverse match, complete was allocating a vector with length of the forward match. This isn't quite the right number. What you want is to use the actual number of srcs (or failing that the maximum number that appears in the matching). In practice, this was mostly working out, because an overestimate is fine here and usually there are more variables than equations, but there don't have to be in all places where Matching is used. Fix that by defaulting complete to the maximum used src and explicitly passing the correct number of sources in a few places.

When constructing the inverse match, `complete` was allocating a vector
with length of the forward match. This isn't quite the right number.
What you want is to use the actual number of srcs (or failing that
the maximum number that appears in the matching). In practice, this
was mostly working out, because an overestimate is fine here and
usually there are more variables than equations, but there don't
have to be in all places where Matching is used. Fix that by defaulting
`complete` to the maximum used src and explicitly passing the correct
number of sources in a few places.
@Keno Keno force-pushed the kf/completedefault branch from a7bd421 to 23c010b Compare February 15, 2024 06:02
@@ -88,7 +88,7 @@ function Base.push!(m::Matching, v)
end
end

function complete(m::Matching{U}, N = length(m.match)) where {U}
function complete(m::Matching{U}, N = maximum((x for x in m.match if isa(x, Int)); init=0)) where {U}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is init used for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handles the case when m is empty.

@Keno
Copy link
Contributor Author

Keno commented Feb 17, 2024

@YingboMa good to go?

@YingboMa YingboMa merged commit 6b96fec into SciML:master Feb 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants