当前位置: 首页>>代码示例>>Python>>正文


Python UndefinedFunction._imp_方法代码示例

本文整理汇总了Python中sympy.core.function.UndefinedFunction._imp_方法的典型用法代码示例。如果您正苦于以下问题:Python UndefinedFunction._imp_方法的具体用法?Python UndefinedFunction._imp_怎么用?Python UndefinedFunction._imp_使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sympy.core.function.UndefinedFunction的用法示例。


在下文中一共展示了UndefinedFunction._imp_方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: implemented_function

# 需要导入模块: from sympy.core.function import UndefinedFunction [as 别名]
# 或者: from sympy.core.function.UndefinedFunction import _imp_ [as 别名]
def implemented_function(symfunc, implementation):
    """ Add numerical ``implementation`` to function ``symfunc``.

    ``symfunc`` can be an ``UndefinedFunction`` instance, or a name string.
    In the latter case we create an ``UndefinedFunction`` instance with that
    name.

    Be aware that this is a quick workaround, not a general method to create
    special symbolic functions. If you want to create a symbolic function to be
    used by all the machinery of SymPy you should subclass the ``Function``
    class.

    Parameters
    ----------
    symfunc : ``str`` or ``UndefinedFunction`` instance
       If ``str``, then create new ``UndefinedFunction`` with this as
       name.  If `symfunc` is a sympy function, attach implementation to it.
    implementation : callable
       numerical implementation to be called by ``evalf()`` or ``lambdify``

    Returns
    -------
    afunc : sympy.FunctionClass instance
       function with attached implementation

    Examples
    ========

    >>> from sympy.abc import x
    >>> from sympy.utilities.lambdify import lambdify, implemented_function
    >>> from sympy import Function
    >>> f = implemented_function(Function('f'), lambda x: x+1)
    >>> lam_f = lambdify(x, f(x))
    >>> lam_f(4)
    5
    """
    # Delayed import to avoid circular imports
    from sympy.core.function import UndefinedFunction
    # if name, create function to hold implementation
    if isinstance(symfunc, string_types):
        symfunc = UndefinedFunction(symfunc)
    elif not isinstance(symfunc, UndefinedFunction):
        raise ValueError('symfunc should be either a string or'
                         ' an UndefinedFunction instance.')
    # We need to attach as a method because symfunc will be a class
    symfunc._imp_ = staticmethod(implementation)
    return symfunc
开发者ID:Davidjohnwilson,项目名称:sympy,代码行数:49,代码来源:lambdify.py

示例2: implemented_function

# 需要导入模块: from sympy.core.function import UndefinedFunction [as 别名]
# 或者: from sympy.core.function.UndefinedFunction import _imp_ [as 别名]
def implemented_function(symfunc, implementation):
    """ Add numerical `implementation` to function `symfunc`

    `symfunc` can by a Function, or a name, in which case we make an
    anonymous function with this name.  The function is anonymous in the
    sense that the name is not unique in the sympy namespace.

    Parameters
    ----------
    symfunc : str or ``sympy.FunctionClass`` instance
       If str, then create new anonymous sympy function with this as
       name.  If `symfunc` is a sympy function, attach implementation to
       function
    implementation : callable
       numerical implementation of function for use in ``lambdify``

    Returns
    -------
    afunc : sympy.FunctionClass instance
       function with attached implementation

    Examples
    --------
    >>> from sympy.abc import x, y, z
    >>> from sympy.utilities.lambdify import lambdify, implemented_function
    >>> from sympy import Function
    >>> f = implemented_function(Function('f'), lambda x : x+1)
    >>> lam_f = lambdify(x, f(x))
    >>> lam_f(4)
    5
    """
    # Delayed import to avoid circular imports
    from sympy.core.function import UndefinedFunction

    # if name, create anonymous function to hold implementation
    if isinstance(symfunc, basestring):
        symfunc = UndefinedFunction(symfunc)
    # We need to attach as a method because symfunc will be a class
    symfunc._imp_ = staticmethod(implementation)
    return symfunc
开发者ID:sherjilozair,项目名称:sympy,代码行数:42,代码来源:lambdify.py


注:本文中的sympy.core.function.UndefinedFunction._imp_方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。