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


Python ctypes.c_int32方法代码示例

本文整理汇总了Python中ctypes.c_int32方法的典型用法代码示例。如果您正苦于以下问题:Python ctypes.c_int32方法的具体用法?Python ctypes.c_int32怎么用?Python ctypes.c_int32使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ctypes的用法示例。


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

示例1: init_libnao_orbs

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_int32 [as 别名]
def init_libnao_orbs(self):
    """ Initialization of data on libnao site """
    from pyscf.nao.m_libnao import libnao
    from pyscf.nao.m_sv_chain_data import sv_chain_data
    from ctypes import POINTER, c_double, c_int64, c_int32, byref
    data = sv_chain_data(self)
    size_x = np.array([1,self.nspin,self.norbs,self.norbs,1], dtype=np.int32)
    libnao.init_sv_libnao_orbs.argtypes = (POINTER(c_double), POINTER(c_int64), POINTER(c_int32))
    libnao.init_sv_libnao_orbs(data.ctypes.data_as(POINTER(c_double)), c_int64(len(data)), size_x.ctypes.data_as(POINTER(c_int32)))
    self.init_sv_libnao_orbs = True

    libnao.init_aos_libnao.argtypes = (POINTER(c_int64), POINTER(c_int64))
    info = c_int64(-999)
    libnao.init_aos_libnao(c_int64(self.norbs), byref(info))
    if info.value!=0: raise RuntimeError("info!=0")
    return self 
开发者ID:pyscf,项目名称:pyscf,代码行数:18,代码来源:nao.py

示例2: _add_fd_to_loop

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_int32 [as 别名]
def _add_fd_to_loop(self, fd, cb, fd_events, userdata=None):
        if cb is None:
            self.logger.info(
                "Cannot add fd '{}' to pomp loop without "
                "a valid callback function".format(fd)
            )
            return None
        self.fd_userdata[fd] = userdata
        userdata = ctypes.cast(
            ctypes.pointer(ctypes.py_object(userdata)), ctypes.c_void_p
        )
        self.c_fd_userdata[fd] = userdata
        self.pomp_fd_callbacks[fd] = od.pomp_fd_event_cb_t(cb)
        res = od.pomp_loop_add(
            self.pomp_loop,
            ctypes.c_int32(fd),
            od.uint32_t(int(fd_events)),
            self.pomp_fd_callbacks[fd],
            userdata
        )
        if res != 0:
            raise RuntimeError(
                "Cannot add fd '{}' to pomp loop: {} ({})".format(
                    fd, os.strerror(-res), res)
            ) 
开发者ID:Parrot-Developers,项目名称:olympe,代码行数:27,代码来源:pomp_loop_thread.py

示例3: _ar_arsdk_encode_type_info

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_int32 [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] 
开发者ID:Parrot-Developers,项目名称:olympe,代码行数:18,代码来源:messages.py

示例4: test_ready_argument_list2

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_int32 [as 别名]
def test_ready_argument_list2():
    arg1 = numpy.array([1, 2, 3]).astype(numpy.float32)
    arg2 = numpy.int32(7)
    arg3 = numpy.float32(6.0)
    arguments = [arg1, arg2, arg3]

    cfunc = CFunctions()
    output = cfunc.ready_argument_list(arguments)
    print(output)

    output_arg1 = numpy.ctypeslib.as_array(output[0].ctypes, shape=arg1.shape)

    assert output_arg1.dtype == 'float32'
    assert isinstance(output[1].ctypes, C.c_int32)
    assert isinstance(output[2].ctypes, C.c_float)

    assert all(output_arg1 == arg1)
    assert output[1][1].value == arg2
    assert output[2][1].value == arg3 
开发者ID:benvanwerkhoven,项目名称:kernel_tuner,代码行数:21,代码来源:test_c_functions.py

示例5: c_int_array

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_int32 [as 别名]
def c_int_array(data):
    """Get pointer of int numpy array / list."""
    if is_1d_list(data):
        data = np.array(data, copy=False)
    if is_numpy_1d_array(data):
        data = convert_from_sliced_object(data)
        assert data.flags.c_contiguous
        if data.dtype == np.int32:
            ptr_data = data.ctypes.data_as(ctypes.POINTER(ctypes.c_int32))
            type_data = C_API_DTYPE_INT32
        elif data.dtype == np.int64:
            ptr_data = data.ctypes.data_as(ctypes.POINTER(ctypes.c_int64))
            type_data = C_API_DTYPE_INT64
        else:
            raise TypeError("Expected np.int32 or np.int64, met type({})"
                            .format(data.dtype))
    else:
        raise TypeError("Unknown type({})".format(type(data).__name__))
    return (ptr_data, type_data, data)  # return `data` to avoid the temporary copy is freed 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:21,代码来源:basic.py

示例6: __init_from_csc

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_int32 [as 别名]
def __init_from_csc(self, csc, params_str, ref_dataset):
        """Initialize data from a CSC matrix."""
        if len(csc.indices) != len(csc.data):
            raise ValueError('Length mismatch: {} vs {}'.format(len(csc.indices), len(csc.data)))
        self.handle = ctypes.c_void_p()

        ptr_indptr, type_ptr_indptr, __ = c_int_array(csc.indptr)
        ptr_data, type_ptr_data, _ = c_float_array(csc.data)

        assert csc.shape[0] <= MAX_INT32
        csc.indices = csc.indices.astype(np.int32, copy=False)

        _safe_call(_LIB.LGBM_DatasetCreateFromCSC(
            ptr_indptr,
            ctypes.c_int(type_ptr_indptr),
            csc.indices.ctypes.data_as(ctypes.POINTER(ctypes.c_int32)),
            ptr_data,
            ctypes.c_int(type_ptr_data),
            ctypes.c_int64(len(csc.indptr)),
            ctypes.c_int64(len(csc.data)),
            ctypes.c_int64(csc.shape[0]),
            c_str(params_str),
            ref_dataset,
            ctypes.byref(self.handle)))
        return self 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:27,代码来源:basic.py

示例7: win32_path_short

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_int32 [as 别名]
def win32_path_short (self, path):
		if not path:
			return ''
		path = os.path.abspath(path)
		if self.unix:
			return path
		self._win32_load_kernel()
		if not self.GetShortPathName:
			try:
				import ctypes
				self.GetShortPathName = self.kernel32.GetShortPathNameA
				args = [ ctypes.c_char_p, ctypes.c_char_p, ctypes.c_int32 ]
				self.GetShortPathName.argtypes = args
				self.GetShortPathName.restype = ctypes.c_uint32
			except: pass
		if not self.GetShortPathName:
			return path
		retval = self.GetShortPathName(path, self.textdata, 2048)
		shortpath = self.textdata.value
		if retval <= 0:
			import ctypes
			print 'ERROR(%d): %s'%(ctypes.GetLastError(), path)
			return ''
		return shortpath 
开发者ID:skywind3000,项目名称:terminal,代码行数:26,代码来源:terminal.py

示例8: win32_path_full

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_int32 [as 别名]
def win32_path_full (self, path):
		if not path:
			return ''
		path = os.path.abspath(path)
		if self.unix:
			return path
		self._win32_load_kernel()
		if not self.GetFullPathName:
			try:
				import ctypes
				self.GetFullPathName = self.kernel32.GetFullPathNameA
				args = [ ctypes.c_char_p, ctypes.c_int32, ctypes.c_char_p ]
				self.GetFullPathName.argtypes = args + [ctypes.c_char_p]
				self.GetFullPathName.restype = ctypes.c_uint32
			except: pass
		if not self.GetFullPathName:
			return path
		retval = self.GetFullPathName(path, 2048, self.textdata, None)
		fullpath = self.textdata.value
		if retval <= 0:
			return ''
		return fullpath

	# win32 get long pathname 
开发者ID:skywind3000,项目名称:terminal,代码行数:26,代码来源:terminal.py

示例9: win32_path_long

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_int32 [as 别名]
def win32_path_long (self, path):
		if not path:
			return ''
		path = os.path.abspath(path)
		if self.unix:
			return path
		self._win32_load_kernel()
		if not self.GetLongPathName:
			try:
				import ctypes
				self.GetLongPathName = self.kernel32.GetLongPathNameA
				args = [ ctypes.c_char_p, ctypes.c_char_p, ctypes.c_int32 ]
				self.GetLongPathName.argtypes = args
				self.GetLongPathName.restype = ctypes.c_uint32
			except: pass
		if not self.GetLongPathName:
			return path
		retval = self.GetLongPathName(path, self.textdata, 2048)
		longpath = self.textdata.value
		if retval <= 0:
			return ''
		return longpath 
开发者ID:skywind3000,项目名称:terminal,代码行数:24,代码来源:terminal.py

示例10: win32_shell_execute

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_int32 [as 别名]
def win32_shell_execute (self, op, filename, parameters, cwd = None):
		if self.unix:
			return False
		if not cwd:
			cwd = os.getcwd()
		self._win32_load_kernel()
		if not self.ShellExecute:
			try:
				import ctypes
				self.shell32 = ctypes.windll.LoadLibrary('shell32.dll')
				self.ShellExecute = self.shell32.ShellExecuteA
				args = [ ctypes.c_void_p, ctypes.c_char_p, ctypes.c_char_p ]
				args += [ ctypes.c_char_p, ctypes.c_char_p, ctypes.c_int32 ]
				self.ShellExecute.argtypes = args
				self.ShellExecute.restype = ctypes.wintypes.HINSTANCE
			except: pass
		if not self.ShellExecute:
			return False
		nShowCmd = 5
		self.ShellExecute(None, op, filename, parameters, cwd, nShowCmd)
		return True
	
	# win32 correct casing path: c:/windows -> C:\Windows 
开发者ID:skywind3000,项目名称:terminal,代码行数:25,代码来源:terminal.py

示例11: _python_open_any_unit

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_int32 [as 别名]
def _python_open_any_unit(self, resolution):
        status = None
        if len(self._open_unit.argtypes) == 3:
            if resolution is None:
                resolution = self.DEFAULT_RESOLUTION
            chandle = c_int16()
            cresolution = c_int32()
            cresolution.value = resolution
            status = self._open_unit(byref(chandle), None, cresolution)
            handle = chandle.value
        elif len(self._open_unit.argtypes) == 2:
            chandle = c_int16()
            status = self._open_unit(byref(chandle), None)
            handle = chandle.value
        else:
            handle = self._open_unit()

        return handle, status 
开发者ID:picotech,项目名称:picosdk-python-wrappers,代码行数:20,代码来源:library.py

示例12: adapt_int_width

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_int32 [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 
开发者ID:eth-sri,项目名称:debin,代码行数:22,代码来源:utils.py

示例13: getSum

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_int32 [as 别名]
def getSum(self, a, b):
        """
        :type a: int
        :type b: int
        :rtype: int
        """
        # https://leetcode.com/discuss/111582/java-simple-easy-understand-solution-with-explanation
        # in Python this problem is much different because of the negative number
        # https://leetcode.com/discuss/111705/one-positive-one-negative-case-successful-for-python-rules
        import ctypes
        sum = 0
        carry = ctypes.c_int32(b)
        while carry.value != 0:
            sum = a ^ carry.value
            carry = ctypes.c_int32(a & carry.value)
            carry.value <<= 1
            a = sum
        return sum 
开发者ID:qiyuangong,项目名称:leetcode,代码行数:20,代码来源:371_Sum_of_Two_Integers.py

示例14: GetDeviceIntProperty

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_int32 [as 别名]
def GetDeviceIntProperty(dev_ref, key):
  """Reads int property from the HID device."""
  cf_key = CFStr(key)
  type_ref = iokit.IOHIDDeviceGetProperty(dev_ref, cf_key)
  cf.CFRelease(cf_key)
  if not type_ref:
    return None

  if cf.CFGetTypeID(type_ref) != cf.CFNumberGetTypeID():
    raise errors.OsHidError('Expected number type, got {}'.format(
        cf.CFGetTypeID(type_ref)))

  out = ctypes.c_int32()
  ret = cf.CFNumberGetValue(type_ref, K_CF_NUMBER_SINT32_TYPE,
                            ctypes.byref(out))
  if not ret:
    return None

  return out.value 
开发者ID:google,项目名称:pyu2f,代码行数:21,代码来源:macos.py

示例15: tecpolyface

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_int32 [as 别名]
def tecpolyface(num_faces, face_node_counts, face_nodes, face_left_elems, face_right_elems):
    tecio.tecpolyface142.restype=ctypes.c_int32
    tecio.tecpolyface142.argtypes=(
            ctypes.POINTER(ctypes.c_int32), # NumFaces
            ctypes.POINTER(ctypes.c_int32), # FaceNodeCounts array
            ctypes.POINTER(ctypes.c_int32), # FaceNodes array
            ctypes.POINTER(ctypes.c_int32), # Face Left Elems array
            ctypes.POINTER(ctypes.c_int32)) # Face Right Elems array

    face_node_count_array = None
    if face_node_counts:
        face_node_counts = np.asarray(face_node_counts,dtype=np.int32)
        face_node_count_array = ctypes.cast(face_node_counts.ctypes.data, ctypes.POINTER(ctypes.c_int32))

    face_nodes = np.asarray(face_nodes,dtype=np.int32)
    face_left_elems = np.asarray(face_left_elems,dtype=np.int32)
    face_right_elems = np.asarray(face_right_elems,dtype=np.int32)
    ret = tecio.tecpolyface142(
            ctypes.byref(ctypes.c_int32(num_faces)),
            face_node_count_array, #ctypes.cast(face_node_counts.ctypes.data, ctypes.POINTER(ctypes.c_int32)),
            ctypes.cast(face_nodes.ctypes.data, ctypes.POINTER(ctypes.c_int32)),
            ctypes.cast(face_left_elems.ctypes.data, ctypes.POINTER(ctypes.c_int32)),
            ctypes.cast(face_right_elems.ctypes.data, ctypes.POINTER(ctypes.c_int32)))
    if ret != 0:
        raise Exception("tecpolyface Error") 
开发者ID:Tecplot,项目名称:handyscripts,代码行数:27,代码来源:tecio.py


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