本文整理汇总了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
#----------------------------------------------------------------------------
示例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()
示例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()
示例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()
示例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))
示例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
#
示例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
#