當前位置: 首頁>>代碼示例>>Python>>正文


Python types.ComplexType方法代碼示例

本文整理匯總了Python中types.ComplexType方法的典型用法代碼示例。如果您正苦於以下問題:Python types.ComplexType方法的具體用法?Python types.ComplexType怎麽用?Python types.ComplexType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在types的用法示例。


在下文中一共展示了types.ComplexType方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: init_info

# 需要導入模塊: import types [as 別名]
# 或者: from types import ComplexType [as 別名]
def init_info(self):
        scalar_converter.init_info(self)
        self.type_name = 'complex'
        self.check_func = 'PyComplex_Check'
        self.c_type = 'std::complex<double>'
        self.return_type = 'std::complex<double>'
        self.to_c_return = "std::complex<double>(PyComplex_RealAsDouble(py_obj),"\
                                                "PyComplex_ImagAsDouble(py_obj))"
        self.matching_types = [types.ComplexType]

#----------------------------------------------------------------------------
#
# List, Tuple, and Dict converters.
#
# Based on SCXX by Gordon McMillan
#---------------------------------------------------------------------------- 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:18,代碼來源:c_spec.py

示例2: assertEquals

# 需要導入模塊: import types [as 別名]
# 或者: from types import ComplexType [as 別名]
def assertEquals( exp, got ):
        """assertEquals(exp, got)

        Two objects test as "equal" if:
        
        * they are the same object as tested by the 'is' operator.
        * either object is a float or complex number and the absolute
          value of the difference between the two is less than 1e-8.
        * applying the equals operator ('==') returns True.
        """
        from types import FloatType, ComplexType
        if exp is got:
            r = True
        elif ( type( exp ) in ( FloatType, ComplexType ) or
               type( got ) in ( FloatType, ComplexType ) ):
            r = abs( exp - got ) < 1e-8
        else:
            r = ( exp == got )
        if not r:
            print >>sys.stderr, "Error: expected <%s> but got <%s>" % ( repr( exp ), repr( got ) )
            traceback.print_stack() 
開發者ID:ActiveState,項目名稱:code,代碼行數:23,代碼來源:recipe-577473.py

示例3: assertEquals

# 需要導入模塊: import types [as 別名]
# 或者: from types import ComplexType [as 別名]
def assertEquals( exp, got, msg = None ):
    """assertEquals( exp, got[, message] )

    Two objects test as "equal" if:
    
    * they are the same object as tested by the 'is' operator.
    * either object is a float or complex number and the absolute
      value of the difference between the two is less than 1e-8.
    * applying the equals operator ('==') returns True.
    """
    if exp is got:
        r = True
    elif ( type( exp ) in ( FloatType, ComplexType ) or
           type( got ) in ( FloatType, ComplexType ) ):
        r = abs( exp - got ) < 1e-8
    else:
        r = ( exp == got )
    if not r:
        print >>sys.stderr, "Error: expected <%s> but got <%s>%s" % ( repr( exp ), repr( got ), colon( msg ) )
        traceback.print_stack() 
開發者ID:ActiveState,項目名稱:code,代碼行數:22,代碼來源:recipe-577538.py

示例4: assertNotEquals

# 需要導入模塊: import types [as 別名]
# 或者: from types import ComplexType [as 別名]
def assertNotEquals( exp, got, msg = None ):
    """assertNotEquals( exp, got[, message] )

    Two objects test as "equal" if:
    
    * they are the same object as tested by the 'is' operator.
    * either object is a float or complex number and the absolute
      value of the difference between the two is less than 1e-8.
    * applying the equals operator ('==') returns True.
    """
    if exp is got:
        r = False
    elif ( type( exp ) in ( FloatType, ComplexType ) or
           type( got ) in ( FloatType, ComplexType ) ):
        r = abs( exp - got ) >= 1e-8
    else:
        r = ( exp != got )
    if not r:
        print >>sys.stderr, "Error: expected different values but both are equal to <%s>%s" % ( repr( exp ), colon( msg ) )
        traceback.print_stack() 
開發者ID:ActiveState,項目名稱:code,代碼行數:22,代碼來源:recipe-577538.py

示例5: _is_unsupported_type

# 需要導入模塊: import types [as 別名]
# 或者: from types import ComplexType [as 別名]
def _is_unsupported_type(obj):
    return isinstance(obj, (types.ComplexType, types.TupleType, types.FunctionType, types.LambdaType,
                           types.GeneratorType, types.MethodType, types.UnboundMethodType, types.BuiltinFunctionType, types.BuiltinMethodType, types.FileType,
                           types.XRangeType, types.TracebackType, types.FrameType, types.DictProxyType, types.NotImplementedType, types.GetSetDescriptorType,
                           types.MemberDescriptorType)) 
開發者ID:zstackio,項目名稱:zstack-utility,代碼行數:7,代碼來源:jsonobject.py

示例6: realpolyroots

# 需要導入模塊: import types [as 別名]
# 或者: from types import ComplexType [as 別名]
def realpolyroots(*cs):
    r"""returns the roots of a polynom with given coefficients

    polynomial with coefficients given in cs:
      0 = \sum_i  cs[i] * x^(len(cs)-i-1)
    """
    if not cs:
        return [0]
    try:
        f = 1.0/cs[0]
        cs = [f*c for c in cs[1:]]
    except ArithmeticError:
        return realpolyroots(*cs[1:])
    else:
        n = len(cs)
        if n == 0:
            return []
        elif n == 1:
            return [-cs[0]]
        elif n == 2:
            return _realroots_quadratic(*cs)
        elif n == 3:
            return _realroots_cubic(*cs)
        elif n == 4:
            return _realroots_quartic(*cs)
        else:
            raise RuntimeError("realpolyroots solver currently limited to polynoms up to the power of 4")


# def realpolyroots_eigenvalue(*cs):
#     # as realpolyroots but using an equivalent eigenvalue problem
#     # (this code is currently used for functional tests only)
#     if not _has_numeric:
#         raise RuntimeError("realpolyroots_eigenvalue depends on Numeric")
#     if not cs:
#         return [0]
#     try:
#         f = 1.0/cs[0]
#         cs = [f*c for c in cs[1:]]
#     except ArithmeticError:
#         return realpolyroots_eigenvalue(*cs[1:])
#     else:
#         if not cs:
#             return []
#         n = len(cs)
#         a = Numeric.zeros((n, n), Numeric.Float)
#         for i in range(n-1):
#             a[i+1][i] = 1
#         for i in range(n):
#             a[0][i] = -cs[i]
#         rs = []
#         for r in LinearAlgebra.eigenvalues(a):
#             if type(r) == types.ComplexType:
#                 if not r.imag:
#                     rs.append(r.real)
#             else:
#                 rs.append(r)
#         return rs
# 
開發者ID:pyx-project,項目名稱:pyx,代碼行數:61,代碼來源:mathutils.py

示例7: realpolyroots

# 需要導入模塊: import types [as 別名]
# 或者: from types import ComplexType [as 別名]
def realpolyroots(*cs):
    """returns the roots of a polynom with given coefficients

    polynomial with coefficients given in cs:
      0 = \sum_i  cs[i] * x^(len(cs)-i-1)
    """
    if not cs:
        return [0]
    try:
        f = 1.0/cs[0]
        cs = [f*c for c in cs[1:]]
    except ArithmeticError:
        return realpolyroots(*cs[1:])
    else:
        n = len(cs)
        if n == 0:
            return []
        elif n == 1:
            return [-cs[0]]
        elif n == 2:
            return _realroots_quadratic(*cs)
        elif n == 3:
            return _realroots_cubic(*cs)
        elif n == 4:
            return _realroots_quartic(*cs)
        else:
            raise RuntimeError("realpolyroots solver currently limited to polynoms up to the power of 4")


# def realpolyroots_eigenvalue(*cs):
#     # as realpolyroots but using an equivalent eigenvalue problem
#     # (this code is currently used for functional tests only)
#     if not _has_numeric:
#         raise RuntimeError("realpolyroots_eigenvalue depends on Numeric")
#     if not cs:
#         return [0]
#     try:
#         f = 1.0/cs[0]
#         cs = [f*c for c in cs[1:]]
#     except ArithmeticError:
#         return realpolyroots_eigenvalue(*cs[1:])
#     else:
#         if not cs:
#             return []
#         n = len(cs)
#         a = Numeric.zeros((n, n), Numeric.Float)
#         for i in range(n-1):
#             a[i+1][i] = 1
#         for i in range(n):
#             a[0][i] = -cs[i]
#         rs = []
#         for r in LinearAlgebra.eigenvalues(a):
#             if type(r) == types.ComplexType:
#                 if not r.imag:
#                     rs.append(r.real)
#             else:
#                 rs.append(r)
#         return rs
# 
開發者ID:VLSIDA,項目名稱:OpenRAM,代碼行數:61,代碼來源:mathutils.py


注:本文中的types.ComplexType方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。