Skip to content

Commit

Permalink
keep rep consistent with domain
Browse files Browse the repository at this point in the history
  • Loading branch information
smichr committed Sep 29, 2024
1 parent dc69be1 commit 47723d7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
6 changes: 5 additions & 1 deletion sympy/polys/polyclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from __future__ import annotations

from sympy.external.gmpy import GROUND_TYPES
from sympy.external.gmpy import GROUND_TYPES, MPQ

from sympy.utilities.exceptions import sympy_deprecation_warning

Expand Down Expand Up @@ -1241,6 +1241,10 @@ def _new(cls, rep, dom, lev):
obj._rep = rep
obj.lev = lev
obj.dom = dom
if dom == ZZ and any(isinstance(i, MPQ) for i in rep):
raise ValueError('rep should not be MPQ when domain is ZZ')
if dom == QQ and not all(isinstance(i, MPQ) for i in rep):
raise ValueError('rep should be MPQ when domain is QQ')
return obj

def _strict_eq(f, g):
Expand Down
11 changes: 10 additions & 1 deletion sympy/polys/tests/test_polyclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

from sympy.functions.elementary.miscellaneous import sqrt
from sympy.polys.domains import ZZ, QQ
from sympy.polys.polyclasses import DMP, DMF, ANP
from sympy.polys.polyclasses import DMP, DMF, ANP, DMP_Python
from sympy.polys.polyerrors import (CoercionFailed, ExactQuotientFailed,
NotInvertible)
from sympy.polys.specialpolys import f_polys
from sympy.external.gmpy import MPQ
from sympy.testing.pytest import raises, warns_deprecated_sympy

f_0, f_1, f_2, f_3, f_4, f_5, f_6 = [ f.to_dense() for f in f_polys() ]
Expand All @@ -29,6 +30,14 @@ def test_DMP___init__():
assert f.dom == ZZ
assert f.lev == 1

raises(ValueError, lambda: DMP_Python([MPQ(2,1)], ZZ))
raises(ValueError, lambda: DMP_Python([2], QQ))


def test_DMP_Python_convert():
assert not isinstance(DMP_Python([MPQ(2,1)], QQ).convert(ZZ).to_list()[0], MPQ)
assert isinstance(DMP_Python([2], ZZ).convert(QQ).to_list()[0], MPQ)


def test_DMP_rep_deprecation():
f = DMP([1, 2, 3], ZZ)
Expand Down

0 comments on commit 47723d7

Please sign in to comment.