Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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}
Expand Down
16 changes: 4 additions & 12 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,12 @@ Requirements

- `PPL <http://bugseng.com/products/ppl/>`_

- `Cython <http://cython.org>`_
- `Cython <http://cython.org>`_ (tested with both 0.29 and 3.0)

- `cysignals <https://pypi.python.org/pypi/cysignals>`_

- `gmpy2 <https://pypi.python.org/pypi/gmpy2>`_: version >= 2.1.0a4 (see below)
- `gmpy2 <https://pypi.python.org/pypi/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
37 changes: 26 additions & 11 deletions ppl/linear_algebra.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -641,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))
Expand Down Expand Up @@ -1088,7 +1093,11 @@ cdef class Linear_Expression(object):
"""
cdef Linear_Expression lhs, rhs

lhs = <Linear_Expression> self
if isinstance(self, Linear_Expression):
lhs = <Linear_Expression> 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 = <Linear_Expression> other
Expand Down Expand Up @@ -1181,9 +1190,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
Expand All @@ -1194,8 +1203,14 @@ cdef class Linear_Expression(object):
"""
cdef Linear_Expression e
cdef c
e = <Linear_Expression> self
c = other

if isinstance(self, Linear_Expression):
e = <Linear_Expression> self
c = other
else:
# NOTE: this code path will only be executed when compiled with cython < 3.0.0
e = <Linear_Expression> other
c = self

cdef PPL_Coefficient cc = PPL_Coefficient_from_pyobject(c)
cdef Linear_Expression result = Linear_Expression()
Expand Down