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
11 changes: 8 additions & 3 deletions .github/actions/install-dependencies/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,22 @@ runs:
sudo apt-get install -y cmake
sudo apt-get install -y libgmp-dev
sudo apt-get install -y python3-pip
pip3 install sympy
python3 -m pip install sympy
echo "Install Linux dependencies [DONE]"

- name: Install Mac Dependencies
if: runner.os == 'macOS'
shell: bash
run: |
echo "Install Mac dependencies"
brew update
brew update || true
## gmp and python are already installed in the latest macOS
# brew install gmp
# brew install python
pip install sympy
## Install sympy - use --break-system-packages for CI environment
## First ensure pip is available and up to date
python3 -m ensurepip --upgrade || python3 -m ensurepip || true
python3 -m pip install --upgrade pip || true
## Install sympy with --break-system-packages flag (required for PEP 668)
python3 -m pip install --break-system-packages sympy
echo "Install Mac dependencies [DONE]"
24 changes: 22 additions & 2 deletions test/python/polypy_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import polypy
import random
import sympy

try:
import sympy
_sympy_available = True
except ImportError:
_sympy_available = False
sympy = None

PASS = 0
FAIL = 0
Expand Down Expand Up @@ -61,7 +67,13 @@ class SympyWrapper:

enabled = True

def __init__(self):
if not _sympy_available:
self.enabled = False

def sympy_from_upolynomial(self, p):
if not _sympy_available:
raise RuntimeError("sympy is not available")
coeffs = p.coefficients()
sympy_p = 0
x = sympy.symbols('x')
Expand All @@ -71,13 +83,17 @@ def sympy_from_upolynomial(self, p):
return sympy_p

def sympy_factor(self, p):
if not _sympy_available:
raise RuntimeError("sympy is not available")
sympy_p = self.sympy_from_upolynomial(p)
if (p.ring().modulus() is None):
return sympy.factor_list(sympy_p)
else:
return sympy.factor_list(sympy_p, modulus=p.ring().modulus())

def sympy_gcd(self, p, q):
if not _sympy_available:
raise RuntimeError("sympy is not available")
sympy_p = self.sympy_from_upolynomial(p)
sympy_q = self.sympy_from_upolynomial(q)
if (p.ring().modulus() is None):
Expand All @@ -86,6 +102,8 @@ def sympy_gcd(self, p, q):
return sympy.gcd(sympy_p, sympy_q, modulus=p.ring().modulus())

def sympy_extended_gcd(self, p, q):
if not _sympy_available:
raise RuntimeError("sympy is not available")
sympy_p = self.sympy_from_upolynomial(p)
sympy_q = self.sympy_from_upolynomial(q)
if (p.ring().modulus() is None):
Expand Down Expand Up @@ -143,9 +161,11 @@ def check_extended_gcd(self, p, q, gcd, u, v):


"""
By default sympy is enabled.
By default sympy is enabled if available.
"""
sympy_checker = SympyWrapper();
if not _sympy_available:
sympy_checker.enabled = False

"""
Initialize the testing.
Expand Down