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
19 changes: 19 additions & 0 deletions sympy/printing/tests/test_theanocode.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,3 +611,22 @@ def test_complexfunctions():
def test_constantfunctions():
tf = theano_function([],[1+1j])
assert(tf()==1+1j)


def test_Exp1():
"""
Test that exp(1) prints without error and evaluates close to sympy's E
"""
# sy.exp(1) should yield same instance of E as sy.E (singleton), but extra
# check added for sanity
e_a = sy.exp(1)
e_b = sy.E

np.testing.assert_allclose(float(e_a), np.e)
np.testing.assert_allclose(float(e_b), np.e)

e = theano_code_(e_a)
np.testing.assert_allclose(float(e_a), e.eval())

e = theano_code_(e_b)
np.testing.assert_allclose(float(e_b), e.eval())
3 changes: 3 additions & 0 deletions sympy/printing/theanocode.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,9 @@ def _print_slice(self, expr, **kwargs):
def _print_Pi(self, expr, **kwargs):
return 3.141592653589793

def _print_Exp1(self, expr, **kwargs):
return ts.exp(1)

def _print_Piecewise(self, expr, **kwargs):
import numpy as np
e, cond = expr.args[0].args # First condition and corresponding value
Expand Down