本文整理汇总了Python中ctypes.c_int8方法的典型用法代码示例。如果您正苦于以下问题:Python ctypes.c_int8方法的具体用法?Python ctypes.c_int8怎么用?Python ctypes.c_int8使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ctypes
的用法示例。
在下文中一共展示了ctypes.c_int8方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _ar_arsdk_encode_type_info
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_int8 [as 别名]
def _ar_arsdk_encode_type_info(cls, ar_argtype):
arsdk_encode_type_info_map = {
arsdkparser.ArArgType.I8: (od.ARSDK_ARG_TYPE_I8, "i8", ctypes.c_int8),
arsdkparser.ArArgType.U8: (od.ARSDK_ARG_TYPE_U8, "u8", ctypes.c_uint8),
arsdkparser.ArArgType.I16: (od.ARSDK_ARG_TYPE_I16, "i16", ctypes.c_int16),
arsdkparser.ArArgType.U16: (od.ARSDK_ARG_TYPE_U16, "u16", ctypes.c_uint16),
arsdkparser.ArArgType.I32: (od.ARSDK_ARG_TYPE_I32, "i32", ctypes.c_int32),
arsdkparser.ArArgType.U32: (od.ARSDK_ARG_TYPE_U32, "u32", ctypes.c_uint32),
arsdkparser.ArArgType.I64: (od.ARSDK_ARG_TYPE_I64, "i64", ctypes.c_int64),
arsdkparser.ArArgType.U64: (od.ARSDK_ARG_TYPE_U64, "u64", ctypes.c_uint64),
arsdkparser.ArArgType.FLOAT: (od.ARSDK_ARG_TYPE_FLOAT, "f32", ctypes.c_float),
arsdkparser.ArArgType.DOUBLE: (od.ARSDK_ARG_TYPE_DOUBLE, "f64", ctypes.c_double),
arsdkparser.ArArgType.STRING: (od.ARSDK_ARG_TYPE_STRING, "cstr", od.char_pointer_cast),
arsdkparser.ArArgType.ENUM: (od.ARSDK_ARG_TYPE_ENUM, "i32", ctypes.c_int32),
}
return arsdk_encode_type_info_map[ar_argtype]
示例2: adapt_int_width
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_int8 [as 别名]
def adapt_int_width(n, width, signed=True):
n = int(n)
if width == 1:
result = n
elif width == 2:
result = n
elif width == 4:
result = ctypes.c_int8(n).value if signed else ctypes.c_uint8(n).value
elif width == 8:
result = ctypes.c_int8(n).value if signed else ctypes.c_uint8(n).value
elif width == 16:
result = ctypes.c_int16(n).value if signed else ctypes.c_uint16(n).value
elif width == 32:
result = ctypes.c_int32(n).value if signed else ctypes.c_uint32(n).value
elif width == 64:
result = ctypes.c_int64(n).value if signed else ctypes.c_uint64(n).value
else:
result = n
return result
示例3: ctypes_type
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_int8 [as 别名]
def ctypes_type(t):
mapping = {
"I": _ctypes.c_ulong,
"i": _ctypes.c_long,
"b": _ctypes.c_int8,
}
if isinstance(t, PackedType):
return mapping[t.packchar]
if isinstance(t, CharType):
return _ctypes.c_char
if isinstance(t, Array):
subtype = ctypes_type(t._type)
return subtype * t.count
if isinstance(t, Pointer):
subtype = ctypes_type(t._target)
return ctypes.POINTER(subtype)
raise NotImplementedError("Type not implemented: %s" % t.__class__.__name__)
示例4: _SMC_get_value
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_int8 [as 别名]
def _SMC_get_value(conn, key):
"""Returns a processed measurement via AppleSMC for a specified key.
Returns None on failure.
"""
val = _SMC_read_key(conn, key)
if not val or not val.size:
return None
t = ''.join(map(chr, val.type))
if t == 'sp78\0' and val.size == 2:
# Format is first byte signed int8, second byte uint8 fractional.
return round(
float(ctypes.c_int8(val.bytes[0]).value) + (val.bytes[1] / 256.),
2)
if t == 'fpe2\0' and val.size == 2:
# Format is unsigned 14 bits big endian, 2 bits fractional.
return round((float((val.bytes[0] << 6) + (val.bytes[1] >> 2)) +
(val.bytes[1] & 3) / 4.), 2)
# TODO(maruel): Handler other formats like 64 bits long. This is used for fan
# speed.
logging.error('_SMC_get_value(%s) got unknown format: %s of %d bytes', key, t,
val.size)
return None
示例5: _return_ctype
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_int8 [as 别名]
def _return_ctype(self):
""" Returns the associated ctype of a given datatype. """
_datatype_ctype = {
DataType.Bool: ctypes.c_uint8,
DataType.I8: ctypes.c_int8,
DataType.U8: ctypes.c_uint8,
DataType.I16: ctypes.c_int16,
DataType.U16: ctypes.c_uint16,
DataType.I32: ctypes.c_int32,
DataType.U32: ctypes.c_uint32,
DataType.I64: ctypes.c_int64,
DataType.U64: ctypes.c_uint64,
DataType.Sgl: ctypes.c_float,
DataType.Dbl: ctypes.c_double,
DataType.Fxp: ctypes.c_uint32,
DataType.Cluster: ctypes.c_uint32,
}
return _datatype_ctype[self]
示例6: to_int
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_int8 [as 别名]
def to_int(seq, lEle, dEle2Int):
"""
translate a sequence into numbers
@param seq a sequence
"""
num_decl = len(seq) * ct.c_int8
num = num_decl()
for i,ele in enumerate(seq):
try:
n = dEle2Int[ele]
except KeyError:
n = dEle2Int[lEle[-1]]
finally:
num[i] = n
return num
示例7: _create_shared_arr
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_int8 [as 别名]
def _create_shared_arr(self):
TYPE = {
np.float32: ctypes.c_float,
np.float64: ctypes.c_double,
np.uint8: ctypes.c_uint8,
np.int8: ctypes.c_int8,
np.int32: ctypes.c_int32,
}
ctype = TYPE[self.output_dtype]
arr = mp.RawArray(ctype, int(np.prod(self.output_shape)))
return arr
示例8: sum_8bit
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_int8 [as 别名]
def sum_8bit(self, a, b):
"""Add two 8-bit signed integers.
Python only has one :class:`int` data type to represent integer values.
The :meth:`~.fortran32.Fortran32.sum_8bit` method converts the data types
of `a` and `b` to be :class:`ctypes.c_int8`.
The corresponding FORTRAN code is
.. code-block:: fortran
function sum_8bit(a, b) result(value)
!DEC$ ATTRIBUTES DLLEXPORT, ALIAS:'sum_8bit' :: sum_8bit
implicit none
integer(1) :: a, b, value
value = a + b
end function sum_8bit
See the corresponding 64-bit :meth:`~.fortran64.Fortran64.sum_8bit` method.
Parameters
----------
a : :class:`int`
The first 8-bit signed integer.
b : :class:`int`
The second 8-bit signed integer.
Returns
-------
:class:`int`
The sum of `a` and `b`.
"""
ac = ctypes.c_int8(a)
bc = ctypes.c_int8(b)
self.lib.sum_8bit.restype = ctypes.c_int8
return self.lib.sum_8bit(ctypes.byref(ac), ctypes.byref(bc))
示例9: factorial
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_int8 [as 别名]
def factorial(self, n):
"""Compute the n'th factorial.
The corresponding FORTRAN code is
.. code-block:: fortran
function factorial(n) result(value)
!DEC$ ATTRIBUTES DLLEXPORT, ALIAS:'factorial' :: factorial
implicit none
integer(1) :: n
integer(4) :: i
double precision value
if (n < 0) then
value = 0.d0
print *, "Cannot compute the factorial of a negative number", n
else
value = 1.d0
do i = 2, n
value = value * i
enddo
endif
end function factorial
See the corresponding 64-bit :meth:`~.fortran64.Fortran64.factorial` method.
Parameters
----------
n : :class:`int`
The integer to computer the factorial of. The maximum allowed value is 127.
Returns
-------
:class:`float`
The factorial of `n`.
"""
ac = ctypes.c_int8(n)
self.lib.factorial.restype = ctypes.c_double
return self.lib.factorial(ctypes.byref(ac))
示例10: setup
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_int8 [as 别名]
def setup(self):
# counter "ValueError: number of bits invalid for bit field"
monkeypatch_pyclibrary_ctypes_struct()
# register header- and library paths
# https://pyclibrary.readthedocs.org/en/latest/get_started/configuration.html#specifying-headers-and-libraries-locations
# TODO: this probably acts on a global basis; think about it
if self.include_path:
add_header_locations([self.include_path])
if self.library_path:
add_library_locations([self.library_path])
# define extra types suitable for embedded use
types = {
'uint8_t': c_uint8,
'uint16_t': c_uint16,
'uint32_t': c_uint32,
'int8_t': c_int8,
'int16_t': c_int16,
'int32_t': c_int32,
}
# TODO: this probably acts on a global basis; think about it
if not (CParser._init or CLibrary._init):
auto_init(extra_types=types)
示例11: _get_numpy_type
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_int8 [as 别名]
def _get_numpy_type():
name2ctype = dict()
pairs = [
(np.dtype('int8'), ctypes.c_int8),
(np.dtype('int16'), ctypes.c_int16),
(np.dtype('int32'), ctypes.c_int32),
(np.dtype('int64'), ctypes.c_int64), # alias: np.int
(np.dtype('float32'), ctypes.c_float),
(np.dtype('float64'), ctypes.c_double), # alias: np.float
]
for dtype, ctype in pairs:
name2ctype[dtype.name] = ctype
return name2ctype
示例12: get_array_upper_bound
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_int8 [as 别名]
def get_array_upper_bound(self, die):
for child in die.iter_children():
if child.tag == 'DW_TAG_subrange_type':
upper_bound_attr = child.attributes.get('DW_AT_upper_bound', None)
if upper_bound_attr is None:
return None
else:
if upper_bound_attr.form in ('DW_FORM_data1',
'DW_FORM_data2',
'DW_FORM_data4',
'DW_FORM_data8'):
return upper_bound_attr.value
elif upper_bound_attr.form == 'DW_FORM_exprloc':
loc = upper_bound_attr.value
if loc[0] == ENUM_DW_FORM_exprloc['DW_OP_const1u']:
return ctypes.c_uint8(loc[1]).value
elif loc[0] == ENUM_DW_FORM_exprloc['DW_OP_const1s']:
return ctypes.c_int8(loc[1]).value
elif loc[0] == ENUM_DW_FORM_exprloc['DW_OP_const2u']:
return ctypes.c_uint16(utils.decode_kbytes(loc[1:], 2)).value
elif loc[0] == ENUM_DW_FORM_exprloc['DW_OP_const2s']:
return ctypes.c_int16(utils.decode_kbytes(loc[1:], 2)).value
elif loc[0] == ENUM_DW_FORM_exprloc['DW_OP_const4u']:
return ctypes.c_uint32(utils.decode_kbytes(loc[1:], 2)).value
elif loc[0] == ENUM_DW_FORM_exprloc['DW_OP_const4s']:
return ctypes.c_int32(utils.decode_kbytes(loc[1:], 2)).value
elif loc[0] == ENUM_DW_FORM_exprloc['DW_OP_const8u']:
return ctypes.c_uint64(utils.decode_kbytes(loc[1:], 2)).value
elif loc[0] == ENUM_DW_FORM_exprloc['DW_OP_const8s']:
return ctypes.c_int64(utils.decode_kbytes(loc[1:], 2)).value
elif loc[0] == ENUM_DW_FORM_exprloc['DW_OP_constu']:
return utils.decode_uleb128(loc[1:])
elif loc[0] == ENUM_DW_FORM_exprloc['DW_OP_consts']:
return utils.decode_sleb128(loc[1:])
else:
return None
else:
return None
示例13: test_output_arg
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_int8 [as 别名]
def test_output_arg(self):
string = String('\u1156\u2278\u3390\u44AB')
for btarray in ([0] * 4,
(0,) * 4,
jarray(jbyte)([0] * 4)):
# This version of getBytes returns the 8 low-order of each Unicode character.
string.getBytes(0, 4, btarray, 0)
if not isinstance(btarray, tuple):
self.assertEquals(btarray, [ctypes.c_int8(x).value
for x in [0x56, 0x78, 0x90, 0xAB]])