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


Python compatibility.callable函数代码示例

本文整理汇总了Python中sympy.core.compatibility.callable函数的典型用法代码示例。如果您正苦于以下问题:Python callable函数的具体用法?Python callable怎么用?Python callable使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: apply_to_curve

 def apply_to_curve(self, verts, u_set, set_len=None, inc_pos=None):
     """
     Apply this color scheme to a
     set of vertices over a single
     independent variable u.
     """
     bounds = create_bounds()
     cverts = list()
     if callable(set_len): set_len(len(u_set)*2)
     # calculate f() = r,g,b for each vert
     # and find the min and max for r,g,b
     for _u in xrange(len(u_set)):
         if verts[_u] is None:
             cverts.append(None)
         else:
             x,y,z = verts[_u]
             u,v = u_set[_u], None
             c = self(x,y,z,u,v)
             if c is not None:
                 c = list(c)
                 update_bounds(bounds, c)
             cverts.append(c)
         if callable(inc_pos): inc_pos()
     # scale and apply gradient
     for _u in xrange(len(u_set)):
         if cverts[_u] is not None:
             for _c in xrange(3):
                 # scale from [f_min, f_max] to [0,1]
                 cverts[_u][_c] = rinterpolate(bounds[_c][0], bounds[_c][1], cverts[_u][_c])
             # apply gradient
             cverts[_u] = self.gradient(*cverts[_u])
         if callable(inc_pos): inc_pos()
     return cverts
开发者ID:ArchKaine,项目名称:sympy,代码行数:33,代码来源:color_scheme.py

示例2: check

def check(a, check_attr=True):
    """ Check that pickling and copying round-trips.
    """
    # The below hasattr() check will warn about is_Real in Python 2.5, so
    # disable this to keep the tests clean
    warnings.filterwarnings("ignore", ".*is_Real.*")
    protocols = [0, 1, 2, copy.copy, copy.deepcopy]
    # Python 2.x doesn't support the third pickling protocol
    if sys.version_info[0] > 2:
        protocols.extend([3])
    for protocol in protocols:
        if callable(protocol):
            if isinstance(a, BasicType):
                # Classes can't be copied, but that's okay.
                return
            b = protocol(a)
        else:
            b = pickle.loads(pickle.dumps(a, protocol))

        d1 = dir(a)
        d2 = dir(b)
        assert d1==d2

        if not check_attr:
            continue
        def c(a, b, d):
            for i in d:
                if not hasattr(a, i) or i in excluded_attrs:
                    continue
                attr = getattr(a, i)
                if not hasattr(attr, "__call__"):
                    assert hasattr(b,i), i
                    assert getattr(b,i) == attr
        c(a,b,d1)
        c(b,a,d2)
开发者ID:parleur,项目名称:sympy,代码行数:35,代码来源:test_pickling.py

示例3: check

def check(a, check_attr = True):
    """ Check that pickling and copying round-trips.
    """
    # The below hasattr() check will warn about is_Real in Python 2.5, so
    # disable this to keep the tests clean
    warnings.filterwarnings("ignore", ".*is_Real.*", DeprecationWarning)
    #FIXME-py3k: Add support for protocol 3.
    for protocol in [0, 1, 2, copy.copy, copy.deepcopy]:
        if callable(protocol):
            if isinstance(a, BasicType):
                # Classes can't be copied, but that's okay.
                return
            b = protocol(a)
        else:
            b = pickle.loads(pickle.dumps(a, protocol))

        d1 = dir(a)
        d2 = dir(b)
        assert d1==d2

        if not check_attr:
            continue
        def c(a,b,d):
            for i in d:
                if not hasattr(a,i):
                    continue
                attr = getattr(a,i)
                if not hasattr(attr, "__call__"):
                    assert hasattr(b,i), i
                    assert getattr(b,i)==attr
        c(a,b,d1)
        c(b,a,d2)
开发者ID:Narsil,项目名称:sympy,代码行数:32,代码来源:test_pickling.py

示例4: check

def check(a, check_attr = True):
    """ Check that pickling and copying round-trips.
    """
    for protocol in [0, 1, 2, copy.copy, copy.deepcopy]:
        if callable(protocol):
            if isinstance(a, BasicType):
                # Classes can't be copied, but that's okay.
                return
            b = protocol(a)
        else:
            b = pickle.loads(pickle.dumps(a, protocol))

        d1 = dir(a)
        d2 = dir(b)
        assert d1==d2

        if not check_attr:
            continue
        def c(a,b,d):
            for i in d:
                if not hasattr(a,i):
                    continue
                attr = getattr(a,i)
                if not hasattr(attr, "__call__"):
                    assert hasattr(b,i), i
                    assert getattr(b,i)==attr
        c(a,b,d1)
        c(b,a,d2)
开发者ID:wxgeo,项目名称:sympy,代码行数:28,代码来源:test_pickling.py

示例5: _calculate_verts

 def _calculate_verts(self):
     if self._calculating_verts.isSet(): return
     self._calculating_verts.set()
     try: self._on_calculate_verts()
     finally: self._calculating_verts.clear()
     if callable(self.bounds_callback):
         self.bounds_callback()
开发者ID:ArchKaine,项目名称:sympy,代码行数:7,代码来源:plot_mode_base.py

示例6: _test_color_function

 def _test_color_function(self):
     if not callable(self.f):
         raise ValueError("Color function is not callable.")
     try:
         result = self.f(0, 0, 0, 0, 0)
         assert len(result) == 3
     except TypeError, te:
         raise ValueError("Color function needs to accept x,y,z,u,v, "
                          "as arguments even if it doesn't use all of them.")
开发者ID:101man,项目名称:sympy,代码行数:9,代码来源:color_scheme.py

示例7: example

 def example(i):
     if callable(i):
         p.clear()
         i()
     elif i >= 0 and i < len(examples):
         p.clear()
         examples[i]()
     else: print "Not a valid example.\n"
     print p
开发者ID:wxgeo,项目名称:sympy,代码行数:9,代码来源:plotting.py

示例8: draw

 def draw(self):
     for f in self.predraw:
         if callable(f): f()
     if self.style_override:
         style = self.styles[self.style_override]
     else:
         style = self.styles[self._style]
     # Draw solid component if style includes solid
     if style & 2:
         dl = self._render_stack_top(self._draw_solid)
         if dl > 0 and GL_TRUE == glIsList(dl):
             self._draw_solid_display_list(dl)
     # Draw wireframe component if style includes wireframe
     if style & 1:
         dl = self._render_stack_top(self._draw_wireframe)
         if dl > 0 and GL_TRUE == glIsList(dl):
             self._draw_wireframe_display_list(dl)
     for f in self.postdraw:
         if callable(f): f()
开发者ID:ArchKaine,项目名称:sympy,代码行数:19,代码来源:plot_mode_base.py

示例9: push_solid

 def push_solid(self, function):
     """
     Push a function which performs gl commands
     used to build a display list. (The list is
     built outside of the function)
     """
     assert callable(function)
     self._draw_solid.append(function)
     if len(self._draw_solid) > self._max_render_stack_size:
         del self._draw_solid[1] # leave marker element
开发者ID:101man,项目名称:sympy,代码行数:10,代码来源:plot_mode_base.py

示例10: _test_color_function

 def _test_color_function(self):
     if not callable(self.f):
         raise ValueError("Color function is not callable.")
     try:
         result = self.f(0, 0, 0, 0, 0)
         assert len(result) == 3
     except TypeError as te:
         raise ValueError("Color function needs to accept x,y,z,u,v, "
                          "as arguments even if it doesn't use all of them.")
     except AssertionError as ae:
         raise ValueError("Color function needs to return 3-tuple r,g,b.")
     except Exception as ie:
         pass  # color function probably not valid at 0,0,0,0,0
开发者ID:alhirzel,项目名称:sympy,代码行数:13,代码来源:color_scheme.py

示例11: _eval_args

 def _eval_args(cls, args):
     if len(args) != 2:
         raise QuantumError(
             'Insufficient/excessive arguments to Oracle.  Please ' +
                 'supply the number of qubits and an unknown function.'
         )
     sub_args = args[0],
     sub_args = UnitaryOperator._eval_args(sub_args)
     if not sub_args[0].is_Integer:
         raise TypeError('Integer expected, got: %r' % sub_args[0])
     if not callable(args[1]):
         raise TypeError('Callable expected, got: %r' % args[1])
     sub_args = UnitaryOperator._eval_args(tuple(range(args[0])))
     return (sub_args, args[1])
开发者ID:MichaelMayorov,项目名称:sympy,代码行数:14,代码来源:grover.py

示例12: _render_stack_top

 def _render_stack_top(self, render_stack):
     top = render_stack[-1]
     if top == -1:
         return -1 # nothing to display
     elif callable(top):
         dl = self._create_display_list(top)
         render_stack[-1] = (dl, top)
         return dl # display newly added list
     elif len(top) == 2:
         if GL_TRUE == glIsList(top[0]):
             return top[0] # display stored list
         dl = self._create_display_list(top[1])
         render_stack[-1] = (dl, top[1])
         return dl # display regenerated list
开发者ID:101man,项目名称:sympy,代码行数:14,代码来源:plot_mode_base.py

示例13: get_class

def get_class(lookup_view):
    """
    Convert a string version of a class name to the object.

    For example, get_class('sympy.core.Basic') will return
    class Basic located in module sympy.core
    """
    if isinstance(lookup_view, str):
        lookup_view = lookup_view
        mod_name, func_name = get_mod_func(lookup_view)
        if func_name != "":
            lookup_view = getattr(__import__(mod_name, {}, {}, [""]), func_name)
            if not callable(lookup_view):
                raise AttributeError("'%s.%s' is not a callable." % (mod_name, func_name))
    return lookup_view
开发者ID:hitej,项目名称:meta-core,代码行数:15,代码来源:source.py

示例14: get_class

def get_class(lookup_view):
    """
    Convert a string version of a class name to the object.

    For example, get_class('sympy.core.Basic') will return
    class Basic located in module sympy.core
    """
    if isinstance(lookup_view, str):
        # Bail early for non-ASCII strings (they can't be functions).
        lookup_view = lookup_view.encode('ascii')
        mod_name, func_name = get_mod_func(lookup_view)
        if func_name != '':
            lookup_view = getattr(__import__(mod_name, {}, {}, ['']), func_name)
            if not callable(lookup_view):
                raise AttributeError("'%s.%s' is not a callable." % (mod_name, func_name))
    return lookup_view
开发者ID:wxgeo,项目名称:sympy,代码行数:16,代码来源:source.py

示例15: __init__

    def __init__(self, *args, **kwargs):
        self.args = args
        self.f, self.gradient = None, ColorGradient()

        if len(args) == 1 and not isinstance(args[0], Basic) and callable(args[0]):
            self.f = args[0]
        elif len(args) == 1 and isinstance(args[0], str):
            if args[0] in default_color_schemes:
                cs = default_color_schemes[args[0]]
                self.f, self.gradient = cs.f, cs.gradient.copy()
            else:
                self.f = lambdify('x,y,z,u,v', args[0])
        else:
            self.f, self.gradient = self._interpret_args(args, kwargs)
        self._test_color_function()
        if not isinstance(self.gradient, ColorGradient):
            raise ValueError("Color gradient not properly initialized. "
                             "(Not a ColorGradient instance.)")
开发者ID:101man,项目名称:sympy,代码行数:18,代码来源:color_scheme.py


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