Ticket #13355: plot_with_complex_intermediates_002.patch

File plot_with_complex_intermediates_002.patch, 2.5 KB (added by tkluck, 7 years ago)
  • sage/ext/fast_callable.pyx

    # 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  
    387387    Check that fast_callable also works for symbolic functions with evaluation
    388388    functions:
    389389
    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
    391391        sage: x,y = var('x,y')
    392392        sage: f = function('f', evalf_func=evalf_func)
    393393        sage: fc = fast_callable(f(x,y), vars=[x,y])
    394394        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
    396412    """
    397413    cdef Expression et
    398414    if isinstance(x, Expression):
  • sage/symbolic/expression_conversions.py

    diff --git a/sage/symbolic/expression_conversions.py b/sage/symbolic/expression_conversions.py
    a b  
    14101410            sage: def evalf_func(self, x, y, parent): return parent(x*y)
    14111411            sage: f = function('f', evalf_func=evalf_func)
    14121412            sage: f(x,y)._fast_callable_(etb)
    1413             {evalf_func}(v_0, v_1, <type 'float'>)
     1413            {placeholder_function}(v_0, v_1)
    14141414        """
    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:
    14211420            return self.etb.call(function, *ex.operands())
    14221421
    14231422