From 8fb4f623196fc456297408deca027d0c88742db4 Mon Sep 17 00:00:00 2001 From: Vincent Delecroix Date: Sat, 2 Sep 2023 23:09:33 +0200 Subject: [PATCH 1/4] also test cython<3.0.0 --- .github/workflows/test.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 763e7a2..2a6b6dc 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,6 +13,7 @@ jobs: strategy: matrix: python-version: ["3.8", "3.9", "3.10", "3.11"] + cython: ["cython", "cython<3.0.0"] steps: - uses: actions/checkout@v2 with: { submodules: recursive } @@ -21,7 +22,7 @@ jobs: - name: Install pplpy dependencies shell: bash -l {0} run: | - mamba env update --quiet -n test -f environment.yml + mamba install --quiet setuptools gmpy2 cysignals ppl "${{matrix.cython}}" conda list - name: Install pplpy shell: bash -l {0} From 47251ea2db9287762fe12718b04d937dfc20588f Mon Sep 17 00:00:00 2001 From: Vincent Delecroix Date: Sun, 3 Sep 2023 12:39:45 +0200 Subject: [PATCH 2/4] make mul and add compatible with cython < 3.0.0 --- ppl/linear_algebra.pyx | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/ppl/linear_algebra.pyx b/ppl/linear_algebra.pyx index 9bbe2d9..9b07045 100644 --- a/ppl/linear_algebra.pyx +++ b/ppl/linear_algebra.pyx @@ -284,7 +284,11 @@ cdef class Variable(object): ... TypeError: ppl coefficients must be integral """ - return Linear_Expression(self) * other + if isinstance(self, Variable): + return Linear_Expression(self) * other + else: + # NOTE: this code path will only be executed when compiled with cython < 3.0.0 + return Linear_Expression(other) * self def __rmul__(self, other): return Linear_Expression(self) * other @@ -1088,7 +1092,11 @@ cdef class Linear_Expression(object): """ cdef Linear_Expression lhs, rhs - lhs = self + if isinstance(self, Linear_Expression): + lhs = self + else: + # NOTE: this code path will only be executed when compiled with cython < 3.0.0 + lhs = Linear_Expression(self) if isinstance(other, Linear_Expression): rhs = other @@ -1181,9 +1189,9 @@ cdef class Linear_Expression(object): >>> from ppl import Variable >>> x = Variable(0) >>> y = Variable(1) - >>> 8*(x+1) + >>> 8 * (x + 1) 8*x0+8 - >>> y*8 + >>> y * 8 8*x1 >>> 2**128 * x 340282366920938463463374607431768211456*x0 @@ -1194,8 +1202,14 @@ cdef class Linear_Expression(object): """ cdef Linear_Expression e cdef c - e = self - c = other + + if isinstance(self, Linear_Expression): + e = self + c = other + else: + # NOTE: this code path will only be executed when compiled with cython < 3.0.0 + e = other + c = self cdef PPL_Coefficient cc = PPL_Coefficient_from_pyobject(c) cdef Linear_Expression result = Linear_Expression() From a5b4a7449e0d85df046def1885f6d9e0738ab976 Mon Sep 17 00:00:00 2001 From: Vincent Delecroix Date: Sun, 3 Sep 2023 12:41:11 +0200 Subject: [PATCH 3/4] fix Linear_Expression constructor for non-zero length object that evaluates to False --- ppl/linear_algebra.pyx | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/ppl/linear_algebra.pyx b/ppl/linear_algebra.pyx index 9b07045..58f2d79 100644 --- a/ppl/linear_algebra.pyx +++ b/ppl/linear_algebra.pyx @@ -645,11 +645,12 @@ cdef class Linear_Expression(object): a = args[0] b = args[1] self.thisptr = new PPL_Linear_Expression() - if isinstance(a, dict) and a: - self.thisptr.set_space_dimension(1 + max(a)) - for i, coeff in a.items(): - self.thisptr.set_coefficient(PPL_Variable(i), PPL_Coefficient_from_pyobject(coeff)) - elif a: + if isinstance(a, dict): + if a: + self.thisptr.set_space_dimension(1 + max(a)) + for i, coeff in a.items(): + self.thisptr.set_coefficient(PPL_Variable(i), PPL_Coefficient_from_pyobject(coeff)) + else: self.thisptr.set_space_dimension(len(a)) for i, coeff in enumerate(a): self.thisptr.set_coefficient(PPL_Variable(i), PPL_Coefficient_from_pyobject(coeff)) From 6a83deef7aa2cbb214ca8ef1f08e234923b6f74c Mon Sep 17 00:00:00 2001 From: Vincent Delecroix Date: Sun, 3 Sep 2023 12:41:51 +0200 Subject: [PATCH 4/4] update README --- README.rst | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/README.rst b/README.rst index 8152d48..8f9ff01 100644 --- a/README.rst +++ b/README.rst @@ -94,20 +94,12 @@ Requirements - `PPL `_ -- `Cython `_ +- `Cython `_ (tested with both 0.29 and 3.0) - `cysignals `_ -- `gmpy2 `_: version >= 2.1.0a4 (see below) +- `gmpy2 `_ -On Debian/Ubuntu systems these can be installed with:: +On Debian/Ubuntu systems the dependencies can be installed with:: - $ sudo apt-get install libgmp-dev libmpfr-dev libmpc-dev libppl-dev cython - $ pip install cysignals --user - $ pip install gmpy2 --pre --user - -The pip optional option `--user` allows to install python packages for a single -user with no need for administrator rights. The two pip install commands might -be replaced by `sudo pip install PKG` (not recommended). On recent Debian/Ubuntu systems, -cysignals is also available as a package under the name `python-cysignals` for -Python 2 and `python3-cysignals` for Python 3. + $ sudo apt-get install libgmp-dev libmpfr-dev libmpc-dev libppl-dev cython3 python3-gmpy2 python3-cysignals-pari