sbmlmath 0.4.0__tar.gz → 0.4.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {sbmlmath-0.4.0 → sbmlmath-0.4.1}/.github/workflows/ci.yaml +6 -6
- {sbmlmath-0.4.0 → sbmlmath-0.4.1}/.github/workflows/deploy_release.yaml +2 -2
- {sbmlmath-0.4.0/sbmlmath.egg-info → sbmlmath-0.4.1}/PKG-INFO +1 -1
- {sbmlmath-0.4.0 → sbmlmath-0.4.1}/sbmlmath/mathml_parser.py +11 -7
- {sbmlmath-0.4.0 → sbmlmath-0.4.1}/sbmlmath/mathml_printer.py +11 -2
- {sbmlmath-0.4.0 → sbmlmath-0.4.1/sbmlmath.egg-info}/PKG-INFO +1 -1
- {sbmlmath-0.4.0 → sbmlmath-0.4.1}/tests/test_printer.py +20 -0
- {sbmlmath-0.4.0 → sbmlmath-0.4.1}/.github/dependabot.yml +0 -0
- {sbmlmath-0.4.0 → sbmlmath-0.4.1}/.gitignore +0 -0
- {sbmlmath-0.4.0 → sbmlmath-0.4.1}/.pre-commit-config.yaml +0 -0
- {sbmlmath-0.4.0 → sbmlmath-0.4.1}/.readthedocs.yml +0 -0
- {sbmlmath-0.4.0 → sbmlmath-0.4.1}/CITATION.cff +0 -0
- {sbmlmath-0.4.0 → sbmlmath-0.4.1}/LICENSE +0 -0
- {sbmlmath-0.4.0 → sbmlmath-0.4.1}/README.md +0 -0
- {sbmlmath-0.4.0 → sbmlmath-0.4.1}/doc/.gitignore +0 -0
- {sbmlmath-0.4.0 → sbmlmath-0.4.1}/doc/Makefile +0 -0
- {sbmlmath-0.4.0 → sbmlmath-0.4.1}/doc/about.rst +0 -0
- {sbmlmath-0.4.0 → sbmlmath-0.4.1}/doc/api.rst +0 -0
- {sbmlmath-0.4.0 → sbmlmath-0.4.1}/doc/conf.py +0 -0
- {sbmlmath-0.4.0 → sbmlmath-0.4.1}/doc/index.rst +0 -0
- {sbmlmath-0.4.0 → sbmlmath-0.4.1}/doc/make.bat +0 -0
- {sbmlmath-0.4.0 → sbmlmath-0.4.1}/doc/rtd_requirements.txt +0 -0
- {sbmlmath-0.4.0 → sbmlmath-0.4.1}/pyproject.toml +0 -0
- {sbmlmath-0.4.0 → sbmlmath-0.4.1}/sbmlmath/__init__.py +0 -0
- {sbmlmath-0.4.0 → sbmlmath-0.4.1}/sbmlmath/cfunction.py +0 -0
- {sbmlmath-0.4.0 → sbmlmath-0.4.1}/sbmlmath/csymbol.py +0 -0
- {sbmlmath-0.4.0 → sbmlmath-0.4.1}/sbmlmath/species_symbol.py +0 -0
- {sbmlmath-0.4.0 → sbmlmath-0.4.1}/sbmlmath.egg-info/SOURCES.txt +0 -0
- {sbmlmath-0.4.0 → sbmlmath-0.4.1}/sbmlmath.egg-info/dependency_links.txt +0 -0
- {sbmlmath-0.4.0 → sbmlmath-0.4.1}/sbmlmath.egg-info/requires.txt +0 -0
- {sbmlmath-0.4.0 → sbmlmath-0.4.1}/sbmlmath.egg-info/top_level.txt +0 -0
- {sbmlmath-0.4.0 → sbmlmath-0.4.1}/setup.cfg +0 -0
- {sbmlmath-0.4.0 → sbmlmath-0.4.1}/tests/test_csymbol.py +0 -0
- {sbmlmath-0.4.0 → sbmlmath-0.4.1}/tests/test_mathml_parser_sbml_semantic_suite.py +0 -0
- {sbmlmath-0.4.0 → sbmlmath-0.4.1}/tests/test_misc.py +0 -0
- {sbmlmath-0.4.0 → sbmlmath-0.4.1}/tests/test_parser.py +0 -0
- {sbmlmath-0.4.0 → sbmlmath-0.4.1}/tests/test_species_symbol.py +0 -0
|
@@ -16,10 +16,10 @@ jobs:
|
|
|
16
16
|
|
|
17
17
|
steps:
|
|
18
18
|
- name: Check out repository
|
|
19
|
-
uses: actions/checkout@
|
|
19
|
+
uses: actions/checkout@v5
|
|
20
20
|
|
|
21
21
|
- name: Set up Python ${{ matrix.python-version }}
|
|
22
|
-
uses: actions/setup-python@
|
|
22
|
+
uses: actions/setup-python@v6
|
|
23
23
|
with:
|
|
24
24
|
python-version: ${{ matrix.python-version }}
|
|
25
25
|
|
|
@@ -63,10 +63,10 @@ jobs:
|
|
|
63
63
|
|
|
64
64
|
steps:
|
|
65
65
|
- name: Check out repository
|
|
66
|
-
uses: actions/checkout@
|
|
66
|
+
uses: actions/checkout@v5
|
|
67
67
|
|
|
68
68
|
- name: Set up Python ${{ matrix.python-version }}
|
|
69
|
-
uses: actions/setup-python@
|
|
69
|
+
uses: actions/setup-python@v6
|
|
70
70
|
with:
|
|
71
71
|
python-version: ${{ matrix.python-version }}
|
|
72
72
|
|
|
@@ -107,10 +107,10 @@ jobs:
|
|
|
107
107
|
|
|
108
108
|
steps:
|
|
109
109
|
- name: Check out repository
|
|
110
|
-
uses: actions/checkout@
|
|
110
|
+
uses: actions/checkout@v5
|
|
111
111
|
|
|
112
112
|
- name: Set up Python ${{ matrix.python-version }}
|
|
113
|
-
uses: actions/setup-python@
|
|
113
|
+
uses: actions/setup-python@v6
|
|
114
114
|
with:
|
|
115
115
|
python-version: ${{ matrix.python-version }}
|
|
116
116
|
|
|
@@ -343,11 +343,8 @@ class SBMLMathMLParser:
|
|
|
343
343
|
)
|
|
344
344
|
return expr
|
|
345
345
|
|
|
346
|
-
#
|
|
347
|
-
#
|
|
348
|
-
# {int,float} -> bool
|
|
349
|
-
# `Piecewise((True, expr != 0),(False,True))`
|
|
350
|
-
# as sympy doesn't do that automatically
|
|
346
|
+
# explicit boolean->{int,float} conversion for non-boolean functions,
|
|
347
|
+
# since sympy does not do that automatically
|
|
351
348
|
if operator.tag not in mathml_op_sympy_boolean:
|
|
352
349
|
sym_operands = list(map(_bool2num, sym_operands))
|
|
353
350
|
|
|
@@ -584,9 +581,12 @@ class SBMLMathMLParser:
|
|
|
584
581
|
|
|
585
582
|
|
|
586
583
|
def _bool2num(x: sp.Basic) -> sp.Basic:
|
|
587
|
-
"""Convert sympy Booleans
|
|
584
|
+
"""Convert sympy Booleans to expressions or Integers.
|
|
585
|
+
|
|
586
|
+
Peforms boolean->{int,float} conversion via
|
|
587
|
+
``Piecewise((1, expr), (0, True))``.
|
|
588
588
|
|
|
589
|
-
Return anything else as is
|
|
589
|
+
Return anything else as is.
|
|
590
590
|
"""
|
|
591
591
|
if isinstance(x, BooleanFalse):
|
|
592
592
|
return sp.Integer(0)
|
|
@@ -602,6 +602,10 @@ def _bool2num(x: sp.Basic) -> sp.Basic:
|
|
|
602
602
|
def _num2bool(x: sp.Basic) -> sp.Basic:
|
|
603
603
|
"""Convert non-Booleans to Boolean expressions.
|
|
604
604
|
|
|
605
|
+
Convert non-Boolean expressions to Piecewise or Boolean expressions:
|
|
606
|
+
|
|
607
|
+
``expr -> Piecewise((True, expr != 0), (False, True))``
|
|
608
|
+
|
|
605
609
|
Return anything else as is.
|
|
606
610
|
"""
|
|
607
611
|
if not isinstance(x, Boolean):
|
|
@@ -109,7 +109,7 @@ class SBMLMathMLPrinter(MathMLContentPrinter):
|
|
|
109
109
|
|
|
110
110
|
def _print_Number(self, e):
|
|
111
111
|
# only try printing as int if it fits int32
|
|
112
|
-
if isinstance(e, int) and e
|
|
112
|
+
if isinstance(e, int) and _is_sbml_compatible_int(e):
|
|
113
113
|
res = self._print_int(e)
|
|
114
114
|
else:
|
|
115
115
|
res = super()._print_Number(e)
|
|
@@ -123,6 +123,10 @@ class SBMLMathMLPrinter(MathMLContentPrinter):
|
|
|
123
123
|
# don't divide by one
|
|
124
124
|
return self._print_int(e.p)
|
|
125
125
|
|
|
126
|
+
if not (_is_sbml_compatible_int(e.p) and _is_sbml_compatible_int(e.q)):
|
|
127
|
+
# avoid int32 under/overflow in libsbml and print as float
|
|
128
|
+
return self._print_Number(e.evalf())
|
|
129
|
+
|
|
126
130
|
res = self.dom.createElement("cn")
|
|
127
131
|
res.setAttribute("type", "rational")
|
|
128
132
|
res.appendChild(self.dom.createTextNode(f"{e.p} <sep/> {e.q}"))
|
|
@@ -132,7 +136,7 @@ class SBMLMathMLPrinter(MathMLContentPrinter):
|
|
|
132
136
|
return res
|
|
133
137
|
|
|
134
138
|
def _print_int(self, e):
|
|
135
|
-
if
|
|
139
|
+
if not _is_sbml_compatible_int(e):
|
|
136
140
|
# avoid int32 under/overflow in libsbml and print as float
|
|
137
141
|
return self._print_Number(e)
|
|
138
142
|
res = super()._print_int(e)
|
|
@@ -192,3 +196,8 @@ class SBMLMathMLPrinter(MathMLContentPrinter):
|
|
|
192
196
|
dom_element.appendChild(self._print(arg))
|
|
193
197
|
|
|
194
198
|
return dom_element
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
def _is_sbml_compatible_int(value: int) -> bool:
|
|
202
|
+
"""Check if integer is compatible with SBML (fits into signed int32)."""
|
|
203
|
+
return 2**31 > value >= -(2**31)
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
from math import fabs
|
|
2
|
+
|
|
3
|
+
import libsbml
|
|
4
|
+
from sympy import Rational
|
|
5
|
+
|
|
1
6
|
from sbmlmath import SBMLMathMLPrinter, SpeciesSymbol
|
|
2
7
|
|
|
3
8
|
|
|
@@ -23,3 +28,18 @@ def test_species_symbol_spec_ref():
|
|
|
23
28
|
'<ci multi:speciesReference="ref_to_A">A</ci>'
|
|
24
29
|
"</math>"
|
|
25
30
|
)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def test_print_large_rational():
|
|
34
|
+
# too large for SBML int32 -> must be printed as float
|
|
35
|
+
assert "rational" not in SBMLMathMLPrinter().doprint(Rational(1, 2**42))
|
|
36
|
+
assert "rational" not in SBMLMathMLPrinter().doprint(Rational(2**42, 7))
|
|
37
|
+
assert (
|
|
38
|
+
fabs(
|
|
39
|
+
libsbml.readMathMLFromString(
|
|
40
|
+
SBMLMathMLPrinter().doprint(Rational(1, 2**42))
|
|
41
|
+
).getValue()
|
|
42
|
+
- 1 / 2**42
|
|
43
|
+
)
|
|
44
|
+
< 1e-15
|
|
45
|
+
)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|