# HG changeset patch
# User Timo Kluck <tkluck@infty.nl>
# Date 1344521180 7200
# Node ID aae73ef825642da8f76d731cd4d7f37d79d8d13b
# Parent d683f2edd6b10f1e8b770dec7ebd761492c4a176
handle domain properly in evalf functions
diff git a/sage/ext/fast_callable.pyx b/sage/ext/fast_callable.pyx
a

b


387  387  Check that fast_callable also works for symbolic functions with evaluation 
388  388  functions: 
389  389  
390   sage: def evalf_func(self, x, y, parent): return parent(x*y) 
 390  sage: def evalf_func(self, x, y, parent): return parent(x*y) if parent!=None else x*y 
391  391  sage: x,y = var('x,y') 
392  392  sage: f = function('f', evalf_func=evalf_func) 
393  393  sage: fc = fast_callable(f(x,y), vars=[x,y]) 
394  394  sage: fc(3,4) 
395   12.0 
 395  12 
 396  
 397  And also when there's complex values involved: 
 398  
 399  sage: def evalf_func(self, x, y, parent): return parent(I*x*y) if parent!=None else I*x*y 
 400  sage: g = function('g', evalf_func=evalf_func) 
 401  sage: fc = fast_callable(g(x,y), vars=[x,y]) 
 402  sage: fc(3,4) 
 403  12*I 
 404  sage: fc2 = fast_callable(g(x,y), domain=complex, vars=[x,y]) 
 405  sage: fc2(3,4) 
 406  12j 
 407  sage: fc3 = fast_callable(g(x,y), domain=float, vars=[x,y]) 
 408  sage: fc3(3,4) 
 409  Traceback (most recent call last): 
 410  ... 
 411  TypeError: unable to simplify to float approximation 
396  412  """ 
397  413  cdef Expression et 
398  414  if isinstance(x, Expression): 
diff git a/sage/symbolic/expression_conversions.py b/sage/symbolic/expression_conversions.py
a

b


1410  1410  sage: def evalf_func(self, x, y, parent): return parent(x*y) 
1411  1411  sage: f = function('f', evalf_func=evalf_func) 
1412  1412  sage: f(x,y)._fast_callable_(etb) 
1413   {evalf_func}(v_0, v_1, <type 'float'>) 
 1413  {placeholder_function}(v_0, v_1) 
1414  1414  """ 
1415   try: 
1416   domain = self.etb._domain 
1417   if domain == None: 
1418   domain = float 
1419   return self.etb.call(function._evalf_, *(ex.operands() + [domain])) 
1420   except AttributeError: 
 1415  if hasattr(function, "_evalf_"): 
 1416  def placeholder_function(*args): 
 1417  return function._evalf_(*(args + (self.etb._domain,))) 
 1418  return self.etb.call(placeholder_function, *ex.operands()) 
 1419  else: 
1421  1420  return self.etb.call(function, *ex.operands()) 
1422  1421  
1423  1422  