Skip to content

Commit

Permalink
Added HadamardPower printing (#300)
Browse files Browse the repository at this point in the history
* Added HadamardPower printing

* Import HadamardPower only for sympy.__version__ > (1,4)

* Fixed the HadamardPower printer.

Co-authored-by: Martin Roelfs <u0114255@kuleuven.be>
  • Loading branch information
tBuLi and Martin Roelfs authored Mar 19, 2020
1 parent ecc567a commit ed20d29
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
11 changes: 10 additions & 1 deletion symfit/core/printing.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Users using both ``symfit`` and ``sympy`` should be aware of this.
"""

import pkg_resources
from sympy import HadamardProduct, MatPow, Idx, Inverse
from sympy.printing.codeprinter import CodePrinter

Expand Down Expand Up @@ -41,6 +41,15 @@ def _print_HadamardProduct(self, printer):
printer.doprint(self.args[1]))
HadamardProduct._numpycode = _print_HadamardProduct

if pkg_resources.parse_version(pkg_resources.get_distribution('sympy').version) \
> pkg_resources.parse_version('1.4'):
from sympy import HadamardPower

def _print_HadamardPower(self, printer):
return "%s**%s" % (printer.doprint(self.args[0]),
printer.doprint(self.args[1]))
HadamardPower._numpycode = _print_HadamardPower

def _print_Idx(self, printer):
"""
Print ``Idx`` objects.
Expand Down
4 changes: 2 additions & 2 deletions tests/test_ode.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@ def test_initial_parameters():
fit = Fit(ode_model, t=tdata, a=AA, c=AAB, d=BAAB)
results = fit.execute()
print(results)
assert results.value(a0) == 10
assert results.value(c0) == pytest.approx(0)
assert results.value(a0) == pytest.approx(10, abs=1e-8)
assert results.value(c0) == pytest.approx(0, abs=1e-8)

assert ode_model.params == [a0, c0, k, l, m, p]
assert ode_model.initial_params == [a0, c0]
Expand Down

0 comments on commit ed20d29

Please sign in to comment.