Skip to content

Commit 8e93421

Browse files
authored
Fix floating point slice indices in _string_rep in Cython 3.1.* (#136)
Tracked down the issue preventing `TestString::test_large_list` from passing when compiling with Cython 3.1.*. Specifically, the issue came down to the calculated `num_rows` in `_string_rep` staying floating point instead of getting cast to an int. I'm not sure whether Cython 3.1.* broke variable shadowing, or optimized out `num_rows = int(num_rows)`... or something else. But in any case, we can avoid the floating point operations (and float-typed variable) by switching _string_rep to use the following formula for calculating the celing of integer division: `ceil(x / y) = (x + y - 1) // y` Since all tests now pass on Cython 3.1.*, this change also removes the upper constraints on Cython. Fixes: #134
1 parent fa8f92b commit 8e93421

File tree

3 files changed

+3
-6
lines changed

3 files changed

+3
-6
lines changed

pyroaring/abstract_bitmap.pxi

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,7 @@ def _string_rep(bm):
6868

6969
num_columns = table_max_width // column_width
7070

71-
num_rows = len(bm) / float(num_columns)
72-
if not num_rows.is_integer():
73-
num_rows += 1
74-
num_rows = int(num_rows)
71+
num_rows = (len(bm) + num_columns - 1) // num_columns
7572
rows = []
7673
row_idx = 0
7774
skipped = False

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
version=VERSION,
8989
description='Library for handling efficiently sorted integer sets.',
9090
long_description=long_description,
91-
setup_requires=['cython>=3.0.2,<3.1.0'],
91+
setup_requires=['cython>=3.0.2'],
9292
url='https://github.com/Ezibenroc/PyRoaringBitMap',
9393
author='Tom Cornebize',
9494
author_email='[email protected]',

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ setenv =
1313
deps =
1414
hypothesis
1515
pytest
16-
cython>=3.0.2,<3.1.0
16+
cython>=3.0.2
1717
passenv =
1818
HYPOTHESIS_PROFILE
1919
ROARING_BITSIZE

0 commit comments

Comments
 (0)