本文整理汇总了Python中numpy.sctypeDict方法的典型用法代码示例。如果您正苦于以下问题:Python numpy.sctypeDict方法的具体用法?Python numpy.sctypeDict怎么用?Python numpy.sctypeDict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numpy
的用法示例。
在下文中一共展示了numpy.sctypeDict方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_umf_family
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import sctypeDict [as 别名]
def _get_umf_family(A):
"""Get umfpack family string given the sparse matrix dtype."""
_families = {
(np.float64, np.int32): 'di',
(np.complex128, np.int32): 'zi',
(np.float64, np.int64): 'dl',
(np.complex128, np.int64): 'zl'
}
f_type = np.sctypeDict[A.dtype.name]
i_type = np.sctypeDict[A.indices.dtype.name]
try:
family = _families[(f_type, i_type)]
except KeyError:
msg = 'only float64 or complex128 matrices with int32 or int64' \
' indices are supported! (got: matrix: %s, indices: %s)' \
% (f_type, i_type)
raise ValueError(msg)
return family
示例2: test_longdouble
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import sctypeDict [as 别名]
def test_longdouble(self):
assert_(np.sctypeDict['f8'] is not np.longdouble)
assert_(np.sctypeDict['c16'] is not np.clongdouble)
示例3: __init__
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import sctypeDict [as 别名]
def __init__(self, floating=None, shared_memory=False, numpy_dtype=None):
if numpy_dtype:
log.debug('Using numpy')
if numpy_dtype in NUMPY_DEFAULTS:
numpy_dtype = 'float32'
if numpy_dtype not in numpy.sctypeDict:
raise ValueError(BAD_NUMPY_TYPE_ERROR % numpy_dtype)
if shared_memory and numpy_dtype:
log.error('Shared memory for numpy arrays is not yet supported.')
numpy_dtype = None
if floating is None:
floating = not shared_memory
c_type = c_float if floating else c_uint8
if shared_memory:
self.bytes = lambda size: RawArray(c_uint8, size)
self.color_list = lambda size: RawArray(3 * c_type, size)
# Note https://stackoverflow.com/questions/37705974/
elif numpy_dtype:
self.bytes = bytearray
self.color_list = lambda size: numpy.zeros((size, 3), numpy_dtype)
else:
self.bytes = bytearray
self.color_list = lambda size: [(0, 0, 0)] * size
示例4: impl
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import sctypeDict [as 别名]
def impl(self, x, y):
x = numpy.asarray(x)
y = numpy.asarray(y)
if all(a.dtype in discrete_types for a in (x, y)):
return numpy.sctypeDict[config.floatX](float(x) / y)
else:
return x / y
示例5: __init__
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import sctypeDict [as 别名]
def __init__(self, A):
if not (isspmatrix_csc(A) or isspmatrix_csr(A)):
A = csc_matrix(A)
warn('spsolve requires A be CSC or CSR matrix format',
SparseEfficiencyWarning)
A.sort_indices()
A = A.asfptype() # upcast to a floating point format
M, N = A.shape
if (M != N):
raise ValueError("matrix must be square (has shape %s)" % ((M, N),))
f_type = np.sctypeDict[A.dtype.name]
i_type = np.sctypeDict[A.indices.dtype.name]
try:
family = _families[(f_type, i_type)]
except KeyError:
msg = 'only float64 or complex128 matrices with int32 or int64' \
' indices are supported! (got: matrix: %s, indices: %s)' \
% (f_type, i_type)
raise ValueError(msg)
self.umf = UmfpackContext(family)
self.umf.numeric(A)
self._A = A
self._L = None
self._U = None
self._P = None
self._Q = None
self._R = None