From 6b97aabcfa859418ea1c3bef0d7b34752c6aae30 Mon Sep 17 00:00:00 2001 From: "Matthias C. M. Troffaes" Date: Wed, 18 Sep 2024 09:42:08 +0100 Subject: [PATCH] Some range conversions for cython. --- cython/pycddlib.pxi | 11 ++++++----- test/test_set_type.py | 0 2 files changed, 6 insertions(+), 5 deletions(-) create mode 100644 test/test_set_type.py diff --git a/cython/pycddlib.pxi b/cython/pycddlib.pxi index be4b4f2..eb26732 100644 --- a/cython/pycddlib.pxi +++ b/cython/pycddlib.pxi @@ -80,13 +80,13 @@ cdef _get_set(set_type set_): # create Python Set from given set_type cdef unsigned long elem return { - elem for elem from 0 <= elem < set_[0] if set_member(elem + 1, set_) + elem for elem in range(set_[0]) if set_member(elem + 1, set_) } cdef _set_set(set_type set_, pset): # set elements of set_type by elements from a Python Container cdef unsigned long elem - for elem from 0 <= elem < set_[0]: + for elem in range(set_[0]): if elem in pset: set_addelem(set_, elem + 1) else: @@ -96,16 +96,17 @@ cdef _get_dd_setfam(dd_SetFamilyPtr setfam): # create Python Sequence[Set] from dd_SetFamilyPtr, and # free the pointer; indexing of the sets start at 0, unlike the # string output from cddlib, which starts at 1 - cdef long elem + cdef dd_bigrange elem + cdef dd_bigrange i if setfam == NULL: raise ValueError("failed to get set family") result = [ { elem - for elem from 0 <= elem < setfam.setsize + for elem in range(setfam.setsize) if set_member(elem + 1, setfam.set[i]) } - for i from 0 <= i < setfam.famsize + for i in range(setfam.famsize) ] dd_FreeSetFamily(setfam) return result diff --git a/test/test_set_type.py b/test/test_set_type.py new file mode 100644 index 0000000..e69de29