Skip to content

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

Merged
merged 15 commits into from
Oct 4, 2022
Merged

Gaussian Elimination #4

merged 15 commits into from
Oct 4, 2022

Conversation

dtr3
Copy link
Collaborator

@dtr3 dtr3 commented Sep 30, 2022

No description provided.

@dtr3 dtr3 requested review from bc3ai and vihan29 September 30, 2022 22:32
@vihan29
Copy link
Collaborator

vihan29 commented Oct 3, 2022

LGTM. It might be nice to add a test for an unsolvable system.

Base automatically changed from LazyGaussianElimination_dev to main October 4, 2022 04:28
Copy link
Collaborator

@bc3ai bc3ai left a 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))
Copy link
Collaborator

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.

Copy link
Collaborator Author

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]
Copy link
Collaborator

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.

Copy link
Collaborator Author

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

@dtr3 dtr3 merged commit a6b125b into main Oct 4, 2022
@dtr3 dtr3 deleted the GaussianElimination branch October 13, 2022 03:25
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.

3 participants