python2 support fixes

This commit is contained in:
urojony 2020-04-11 09:23:21 +02:00
parent a5854e31d7
commit e36cf4b81e
2 changed files with 3 additions and 4 deletions

View File

@ -1,6 +1,5 @@
from __future__ import (absolute_import, division,
print_function, unicode_literals)
from builtins import *
import warnings,operator
warnings.filterwarnings("ignore")
#Seed is needed to select the weights in linprog function.
@ -39,8 +38,8 @@ def _remzero(coef,fun):
nfun+=[f]
return ncoef,nfun
def slatex(formula): #fancy function which makes latex code more readable, but still correct
formula=re.sub('\^{(.)}',r'^\1',latex(formula,fold_short_frac=True).replace(' ','').replace('\\left(','(').replace('\\right)',')'))
return re.sub('\{(\(.+?\))\}',r'\1',formula)
formula=re.sub(r'\^{(.)}',r'^\1',latex(formula,fold_short_frac=True).replace(' ','').replace('\\left(','(').replace('\\right)',')'))
return re.sub(r'\{(\(.+?\))\}',r'\1',formula)
def _writ2(coef,fun,variables):
return slatex(S((str(coef)+'*'+'*'.join([str(x)+'^'+str(y) for x,y in zip(variables,fun)]))))
def _writ(coef,fun,nullvar):
@ -59,7 +58,7 @@ def _powr(formula):
def fractioncancel(formula):
#workaround for buggy cancel function
num,den=fraction(cancel(formula/S('tmp')))
den=den.subs('tmp','1')
den=den.subs(S('tmp'),S('1'))
return num,den
def ssolve(formula,variables):
#workaround for inconsistent solve function