-
Notifications
You must be signed in to change notification settings - Fork 1
Gaussian Elimination #4
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
LGTM. It might be nice to add a test for an unsolvable system. |
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.
LGTM. Let's revisit bit-op efficiency questions after V1 is done.
# Using gmpy to find the index of the least significant bit. Sources: | ||
# https://stackoverflow.com/questions/5520655/return-index-of-least-significant-bit-in-python | ||
# https://stackoverflow.com/questions/12078277/is-this-a-bug-in-gmpy2-or-am-i-mad | ||
index_of_first_set_bit_in_chunk = gmpy2.bit_scan1(gmpy2.mpz(chunk)) |
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.
This is do-able via a few bit shift ops - is gmpy2 faster? If not, then maybe we can remove the gmpy dependency.
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 benchmarked it but the stack overflow post I linked claims gmpy is 4x faster than using ctypes. not sure if that uses bit ops but we can revisit this later if needed
# TODO: np.where searches the whole array, and doesnt stop at the first | ||
# sight of nonzero, can we optimize this? | ||
equation = self._equations[equation_id] | ||
first_nonzero_chunk_id = np.where(equation != 0)[0][0] |
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.
In LazyGaussianElimination.py, we use:
for chunk_id, chunk in enumerate(equation):
if flag > 0:
break
lsb_index = chunk_id * self._num_variables_per_chunk + index_of_first_set_bit_in_chunk
Let's check for performance on equations with ~1 million entries - it's a question of whether Python loops with early termination win against C loops without early termination.
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.
sounds good. ill keep the TODO so we can profile this if needed
No description provided.