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

Make rlevel calculation more efficient, and power of 2 check more robust. #529

Open
wants to merge 3 commits into
base: devel
Choose a base branch
from

Conversation

feature-engineer
Copy link
Contributor

@feature-engineer
Copy link
Contributor Author

In case the benchmark file is not available, here are its contents:

import numpy as np
%alias_magic t timeit
def pow2_1():
    for step in range(1, 10000):
        if np.abs(np.log2(step) - np.round(np.log2(step))) > 1e-6:
            msg = "Row and column strides must be powers of 2."
            continue
        yield int(np.round(np.log2(step)))

def pow2_2():
    for step in range(1, 10000):
        rlevel = step.bit_length() - 1
        if (step % (1 << rlevel)) != 0:
            msg = "Row and column strides must be powers of 2."
            #raise ValueError(msg)
            continue
        yield rlevel

Performance test

%%t
levels1 = [rlevel for rlevel in pow2_1()]

69.4 ms ± 4.39 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)

%%t
levels2 = [rlevel for rlevel in pow2_2()]

1.32 ms ± 20.7 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)

Test

levels1 = [rlevel for rlevel in pow2_1()]
levels2 = [rlevel for rlevel in pow2_2()]
assert len(levels1 == levels2)
assert all(level1 == level2 for level1, level2 in zip(levels1, levels2))

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.

1 participant