-
Notifications
You must be signed in to change notification settings - Fork 20
Code Overhaul. #3
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
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
70d2cc0
implement improvements from other repo from myself and ana-096, refac…
bertie2 218503d
back out multithreading changes for a different pull request, rename …
bertie2 d6b518e
cleanup of annotations, optimisation to break early on seeing a canon…
bertie2 287dffd
remove legacy parrelism test file
bertie2 2059b9f
try faster packing and unpacking with builtin byte conversions
bertie2 0f3220d
- cube_hash is now not int but bytes:
VladimirFokow 7dd61a5
6% faster with better cropped cube
joulebit 0c5ca24
Merge pull request #2 from joulebit/overhaul
bertie2 2459e21
Merge pull request #1 from VladimirFokow/overhaul
bertie2 15816f7
still pack the bits to save memory but now use frombuffer for much fa…
bertie2 6de8ef8
add test data, make unit-tests correctly auto discover, update README
bertie2 1e380a8
fix minor typo
bertie2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
Do we need
int.from_bytes(data, 'big'), or can we simply returndata?There is some time overhead of
int.from_bytes.Not large for polycube of size 8000, for example (about 10 µs), but can add up, and is more noticeable for larger sizes.
int.from_bytesconstructs an integer (ifdatais very big, e.g. 100_000 bytes - this can take a very long time).bytesobjects are already comparable (for theget_canoincal_packingfunction in cubes.py).cube_hashto theknown_hashesin thegenerate_polycubesfunction in cubes.py, thesetinternally computes a 64-bit integerhash(cube_hash)anyway.So the
intspecifically is not required;byteswill be enough for our purposes, right?Maybe
cube_hashwould be better named ascube_id- because it's not yet a hash (which set uses internally), it's just another representation of a numpy array - that is hashable and comparable, and which corresponds to our cube (rotationally invariantly).pull request: bertie2#1
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.
I haven't had time to try it, so may or may not help in practice, but I did wonder if cube_hash should be like a true hash - e.g a value that indicates that 2 shapes MAY be identical (e.g. collisions allowed) and if a hash match is found then those candidates would be tested for true equality.
I thought the hash could be an hash of these properties combined (which I think should yield the same hash for all rotations, so maybe cutting time down for rotations?):-
E.g a 2x2x2 cube with one corner missing would be (2,2,2,
7,
((3,4),(3,4),(3,4) --to be sorted in some way
)
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.
@RibenaJT
Your comment seems unrelated to the changes that I've proposed in my comment.
But I'll reply to you here:
oh, so you think of like a heuristic - even before any hash calculations for all 24 rotations...
However:
cube_idright away)So we're calculating these 24 rotations in any case anyway?
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.
Yes, sorry it should probably been a new comment.
Yes, if there was a collision - you would still need to compare all 24 rotations.
If no collision - I don't think you need to rotate, since the hash should be the same for all rotations (if the properties are sorted in a way that makes the orientation of the shape irrelevant, e.g. sorting the w/h/d/slices so that e.g. a 3x2x4 oblong would have an hash of {2,3,4,{sorted_slices}} for all orientations) - therefore we know it is a new shape.
It was just a vague idea - it all depends on how "discriminating" the hash is to how effective this would be (versus the cost of rotating).
Yes, by 3d slice, I meant taking all (2d) slices of the shape in all 3 axis.