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

fix bucket_sorter bug affecting min_degree_ordering #86

Open
wants to merge 14 commits into
base: develop
Choose a base branch
from

Conversation

felix-salfelder
Copy link
Contributor

removing an element from a stack does not always work, since the
predecessor of a stack element is not (always) stored. this patch
merges the array head into next, so a top element in a stack can point
to the head of the stack it is in.

remarks:

  • i am guessing the intended use (see test below), as it works like that
    for elements deeper down in a stack
  • the fix abuses pointers/iterators and infers offsets from address
    differences. (yes it's a bit ugly.)
  • memory needs and complexity are unaffected, size_type is probably big
    enough.

test case. B is a bucketsorter operating on a vector V.

V[0]=0;
V[1]=1;
B.push(0);
B.push(1);

// now, stacks 0 and 1 are singletons.
// try to move 0 to stack 1, should result in
// head_1->0->1->end, but calls remove first, then

V[0]=1;
B.update(0); // <- BOOM

// the update calls remove, it "removes" 0 from stack V[0]=1.
// it's not there yet (!).
// instead 1 (top of bucket 1) must die.
// the result is head_1->0->end, and wrong.

@felix-salfelder
Copy link
Contributor Author

need to redesign my patch.. don't know how to do it yet.

the value index datatype may be too small to represent twice the range. so
actually the longer head array may be outside of the addressable range (if too
many indexes are used). otoh adding an extra bit will affect run time.

at the same time i'ts unclear to me, why the addressed bug does not affect algorithms such
as min_degree_ordering. it does use remove.

@jeremy-murphy
Copy link
Contributor

I think the best thing is if you can make the simplest unit test that fails when it should pass according to the intended behaviour of the component.

@felix-salfelder
Copy link
Contributor Author

felix-salfelder commented Jul 25, 2018 via email

@jeremy-murphy
Copy link
Contributor

I think it's best if you put the relevant unit test into this PR. Whoever is maintaining Boost.Graph won't want to look around at code elsewhere on the web. Ideally (if I was the maintainer, which I'm not) I would want to see that a) the unit test is correct and that b) it fails on master but c) passes with the change to the algorithm.

@felix-salfelder
Copy link
Contributor Author

felix-salfelder commented Jul 25, 2018 via email

@anadon
Copy link
Contributor

anadon commented Aug 31, 2018

I'm helping out with the PR backlog. Looks like you have a bugfix, incomplete tests, and no new examples will be needed. Please make your PR complete. This is to let you know and help me prioritize PR's.

@felix-salfelder
Copy link
Contributor Author

thanks. I commited the test from treedec mentioned above.

another bug in min_degree_ordering seems related to this. min_degree_ordering assert fails on some empty and on some complete graphs. see the test.

@anadon
Copy link
Contributor

anadon commented Aug 31, 2018

This may be tangled then. The PR needs to be clean and not affect other parts of the implementation. I'm going to hold off on messing with this until after the first two batches of merges.

@felix-salfelder
Copy link
Contributor Author

felix-salfelder commented Aug 31, 2018 via email

@anadon
Copy link
Contributor

anadon commented Aug 31, 2018

There really shouldn't be unintended side effects. I'm not going to promote a PR that knowingly introduces regressions.

@felix-salfelder
Copy link
Contributor Author

felix-salfelder commented Aug 31, 2018 via email

@anadon
Copy link
Contributor

anadon commented Aug 31, 2018

Ah crud. I'm going to keep this out of the first two batches of merges. I need to sink time into PR.

@felix-salfelder felix-salfelder changed the title bucket_sorter bug fix in "remove" fix bucket_sorter bug affecting min_degree_ordering Sep 1, 2018
@jeremy-murphy
Copy link
Contributor

@felix-salfelder thanks for adding the unit test.

Earlier, you wrote:

need to redesign my patch.. don't know how to do it yet.

the value index datatype may be too small to represent twice the range. so
actually the longer head array may be outside of the addressable range (if too
many indexes are used). otoh adding an extra bit will affect run time.

Is this still an open implementation issue for this patch? I.e., does it need some work before being merged?
Bucket sort is not an overly complex algorithm in general: we could potentially make a new, simpler, generic implementation, depending on how tightly coupled the buckets are with how Boost.Graph is using it. (I have a little experience with these algorithms and a little spare time to work on open source projects at the moment.)

at the same time i'ts unclear to me, why the addressed bug does not affect algorithms such
as min_degree_ordering. it does use remove.

I guess the answer in the end was that it does affect it.

@felix-salfelder
Copy link
Contributor Author

felix-salfelder commented Oct 14, 2018 via email

@jeremy-murphy
Copy link
Contributor

I just ran the unit test and it returned "broken", which was unexpected. Is that what it's returning for you?

@jeremy-murphy
Copy link
Contributor

Hmmm, maybe just something to do with the way I compiled it manually, because when I run it as part of the Boost.Graph test suite, it passes. Kinda weird, though.

@felix-salfelder
Copy link
Contributor Author

felix-salfelder commented Oct 14, 2018 via email

@jeremy-murphy
Copy link
Contributor

OK, yeah, I must have picked up the system headers by accident when I compiled it manually.

@jeremy-murphy
Copy link
Contributor

I ticked the "Allow edits from maintainers" box. please feel free.

I'm not a maintainer. :)

@anadon
Copy link
Contributor

anadon commented Oct 15, 2018

@felix-salfelder Could you rebase your PR? More CI tests are in devel, as well as other fixes.

@pdimov
Copy link
Member

pdimov commented Oct 16, 2018

This PR is against master, and should be against develop.

@felix-salfelder felix-salfelder changed the base branch from master to develop October 16, 2018 06:53
@anadon
Copy link
Contributor

anadon commented Nov 1, 2018

@felix-salfelder What is your status on this?

@felix-salfelder
Copy link
Contributor Author

felix-salfelder commented Nov 5, 2018 via email

@anadon
Copy link
Contributor

anadon commented Nov 5, 2018

It really is just rebasing on boostorg/develop .

@felix-salfelder
Copy link
Contributor Author

felix-salfelder commented Jan 27, 2019 via email

@mclow
Copy link
Contributor

mclow commented Jan 27, 2019

When you try to create an vector::iterator from a pointer, you are relying on undocumented implementation details of whatever standard library you are using. This will compile (and work) for libstdc++ (as far as I know), not for libc++, probably for MSVC in release mode, and not for MSVC in debug mode.

But that doesn't make it portable.

@felix-salfelder
Copy link
Contributor Author

felix-salfelder commented Jan 27, 2019 via email

@felix-salfelder
Copy link
Contributor Author

any clues what might be wrong with msvc? the output is a bit cryptic, but it says "Assertion failed: vector iterator not dereferencable" in one of the logs... thanks

@jeremy-murphy
Copy link
Contributor

@felix-salfelder, I really appreciate how long you persisted with this bug fix.
We had some issues with the CI and a lack of maintainers for a while but now things are (slowly) moving ahead.
If you have time to resolve the conflicts, then I'll look at it again, although not in the next week or so.
I have the magical maintainer hat now, so I can actually merge it in when it's ready!

@jeremy-murphy jeremy-murphy self-assigned this Mar 6, 2022
@felix-salfelder
Copy link
Contributor Author

felix-salfelder commented Mar 7, 2022 via email

@jeremy-murphy
Copy link
Contributor

Thanks for keeping up. Yes it's been a while... Lots of whitespace conflicts, but not much else. I think a rebase will be easier and less messy, would that be acceptable? (No worries -- It won't happen this week anyway.) Why has the bucket_sorter been classified "pending" in the first place? Is there another issue with it that I have missed?

Sure, whatever is easier for you. It's been so long that I looked at this in any detail that I will essentially be looking at it afresh anyway.

I don't actually know the history of the "pending" stuff. I guess it was for data structures that they thought should be moved into separate, more general-purpose Boost libraries.

@felix-salfelder
Copy link
Contributor Author

felix-salfelder commented Mar 14, 2022 via email

This is not a merge, which is completely impossible due to whitespace
changes. Instead, manually applying the patch produced by

$ git diff -w c583bfa...e62d657

and make it look like a merge.
@felix-salfelder felix-salfelder force-pushed the bucket_sorter branch 2 times, most recently from cd58f6b to fd20cf6 Compare March 16, 2022 21:54
@jeremy-murphy
Copy link
Contributor

Several checks fail -- any idea why?

@felix-salfelder
Copy link
Contributor Author

felix-salfelder commented Mar 16, 2022 via email

@jeremy-murphy
Copy link
Contributor

Thanks. I think the current CI failures are unrelated to your changes, although I'll have to confirm that before merging anything.

@felix-salfelder
Copy link
Contributor Author

felix-salfelder commented Mar 23, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants