Sympy.Zero versus 0.0

33 views
Skip to first unread message

d...@inlet.geol.sc.edu

unread,
May 4, 2016, 9:39:11 AM5/4/16
to sympy
I have run across an issue with some of my user functions where a value could be 0.0 and during the process of evaluation, Sympy converts it to Zero.
This in turn causes my _eval_evalf() function to not be called. Below is my sample function class. If the obs_symbol has a value of 0.0, _eval_evalf() does not get called.  If I cast a 0 value to int, then the _eval_evalf() does get called. If the variable is a Float and 0.0 is passed into the evalf(), _eval_evalf() does not get called.
if data[obs_var.name] != 0:
  mlr_symbols
[obs_var] = symFloat(data[obs_var.name])
else:
  mlr_symbols
[obs_var] = int(data[obs_var.name])
self.mlrResult = sym_expr.evalf(subs=mlr_symbols)

Test function:
class TEST_FUNC(Function):
  nargs
= 4

 
def _eval_evalf(self, nprec):
    obs_symbol
, a, b, c= symbols('obs_symbol a b c')
    test_func
= a + b * obs_symbol + c * obs_symbol**2
    result
= test_func.evalf(subs={obs_symbol: symFloat(self.args[0]), a: symFloat(self.args[1]), b: symFloat(self.args[2]), c: symFloat(self.args[3])})
   
return result

I suspect I am missing an element in my TEST_FUNC class that would address this issue, but I'm not sure what that is.
Reply all
Reply to author
Forward
0 new messages