Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add unicode function #384

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 17, 2022
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
3 changes: 2 additions & 1 deletion symengine/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
FunctionSymbol as AppliedUndef,
golden_ratio as GoldenRatio,
catalan as Catalan,
eulergamma as EulerGamma
eulergamma as EulerGamma,
unicode
)
from .utilities import var, symbols
from .functions import *
Expand Down
1 change: 1 addition & 0 deletions symengine/lib/symengine.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -1103,6 +1103,7 @@ cdef extern from "<symengine/printers.h>" namespace "SymEngine":
string ccode(const Basic &x) nogil except +
string latex(const Basic &x) nogil except +
string latex(const DenseMatrix &x, unsigned max_rows, unsigned max_cols) nogil except +
string unicode(const Basic &x) nogil except +

## Defined in 'symengine/cwrapper.cpp'
cdef struct CRCPBasic:
Expand Down
5 changes: 5 additions & 0 deletions symengine/lib/symengine_wrapper.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -5471,6 +5471,11 @@ def latex(expr):
basic_expr = sympify(expr)
return symengine.latex(deref(basic_expr.thisptr)).decode("utf-8")

def unicode(expr):
cdef Basic basic_expr
basic_expr = sympify(expr)
return symengine.unicode(deref(basic_expr.thisptr)).decode("utf-8")

cdef _flattened_vec(symengine.vec_basic &vec, exprs):
cdef Basic b
if is_sequence(exprs):
Expand Down
8 changes: 7 additions & 1 deletion symengine/tests/test_printing.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from symengine import (ccode, Symbol, sqrt, Pow, Max, sin, Integer, MutableDenseMatrix)
from symengine import (ccode, unicode, Symbol, sqrt, Pow, Max, sin, Integer, MutableDenseMatrix)
from symengine.utilities import raises
from symengine.printing import CCodePrinter, init_printing

Expand Down Expand Up @@ -30,3 +30,9 @@ def test_init_printing():
assert x._repr_latex_() is None
init_printing()
assert x._repr_latex_() == '$x$'


def test_unicode():
x = Symbol("x")
y = Integer(2)
assert unicode(x / 2) == "x\n―\n2"
2 changes: 1 addition & 1 deletion symengine_version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
36ac51d06e248657d828bfa4859cff32ab5f03ba
v0.9.0