我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用ctypes.c_int32()。
def align_one(ssw, qProfile, rNum, nRLen, nOpen, nExt, nFlag, nMaskLen): """ align one pair of sequences @param qProfile query profile @param rNum number array for reference @param nRLen length of reference sequence @param nFlag alignment flag @param nMaskLen mask length """ res = ssw.ssw_align(qProfile, rNum, ct.c_int32(nRLen), nOpen, nExt, nFlag, 0, 0, nMaskLen) nScore = res.contents.nScore nScore2 = res.contents.nScore2 nRefBeg = res.contents.nRefBeg nRefEnd = res.contents.nRefEnd nQryBeg = res.contents.nQryBeg nQryEnd = res.contents.nQryEnd nRefEnd2 = res.contents.nRefEnd2 lCigar = [res.contents.sCigar[idx] for idx in range(res.contents.nCigarLen)] nCigarLen = res.contents.nCigarLen ssw.align_destroy(res) return (nScore, nScore2, nRefBeg, nRefEnd, nQryBeg, nQryEnd, nRefEnd2, nCigarLen, lCigar)
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, } return _datatype_ctype[self]
def align_one(ssw, qProfile, rNum, nRLen, nOpen, nExt, nFlag, nMaskLen): """ this function calculate the score and other results from the alignment """ res = ssw.ssw_align(qProfile, rNum, ct.c_int32(nRLen), nOpen, nExt, nFlag, 0, 0, int(nMaskLen)) nScore = res.contents.nScore nScore2 = res.contents.nScore2 nRefBeg = res.contents.nRefBeg nRefEnd = res.contents.nRefEnd nQryBeg = res.contents.nQryBeg nQryEnd = res.contents.nQryEnd nRefEnd2 = res.contents.nRefEnd2 lCigar = [res.contents.sCigar[idx] for idx in range(res.contents.nCigarLen)] nCigarLen = res.contents.nCigarLen ssw.align_destroy(res) return nScore, nScore2, nRefBeg, nRefEnd, nQryBeg, nQryEnd, nRefEnd2, nCigarLen, lCigar
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
def get_count_rate(self, channel): """ Get the current count rate for the @param int channel: which input channel to read (0 or 1): @return int: count rate in ps. The hardware rate meters emply a gate time of 100ms. You must allow at least 100ms after PH_Initialize or PH_SetDyncDivider to get a valid rate meter reading. Similarly, wait at least 100ms to get a new reading. The readings are corrected for the snyc devider setting and deliver the external (undivided) rate. The gate time cannot be changed. The readings may therefore be inaccurate of fluctuating when the rate are very low. If accurate rates are needed you must perform a full blown measurement and sum up the recorded events. """ if not ((channel !=0) or (channel != 1)): self.log.error('PicoHarp: Count Rate could not be read out, ' 'Channel does not exist.\nChannel has to be 0 or 1 ' 'but {0} was passed.'.format(channel)) return -1 else: rate = ctypes.c_int32() self.check(self._dll.PH_GetCountRate(self._deviceID, channel, ctypes.byref(rate))) return rate.value
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
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], shape=arg1.shape) assert output_arg1.dtype == 'float32' assert isinstance(output[1], C.c_int32) assert isinstance(output[2], C.c_float) assert all(output_arg1 == arg1) assert output[1].value == arg2 assert output[2].value == arg3
def hash(self, timestamp, latitude, longitude, altitude, authticket, sessiondata, requests): self.location_hash = None self.location_auth_hash = None self.request_hashes = [] first_hash = self.hash32(authticket, seed=HASH_SEED) location_bytes = d2h(latitude) + d2h(longitude) + d2h(altitude) loc_hash = self.hash32(location_bytes, seed=first_hash) self.location_auth_hash = ctypes.c_int32(loc_hash).value loc_hash = self.hash32(location_bytes, seed=HASH_SEED) self.location_hash = ctypes.c_int32(loc_hash).value first_hash = self.hash64salt32(authticket, seed=HASH_SEED) for request in requests: req_hash = self.hash64salt64(request.SerializeToString(), seed=first_hash) self.request_hashes.append(ctypes.c_int64(req_hash).value)
def generate_location_hash_by_seed(authticket, lat, lng, acc=5): first_hash = hash32(authticket, seed=HASH_SEED) location_bytes = d2h(lat) + d2h(lng) + d2h(acc) loc_hash = loc_hash = hash32(location_bytes, seed=first_hash) return ctypes.c_int32(loc_hash).value
def generate_location_hash(lat, lng, acc=5): location_bytes = d2h(lat) + d2h(lng) + d2h(acc) loc_hash = loc_hash = hash32(location_bytes, seed=HASH_SEED) return ctypes.c_int32(loc_hash).value
def keyEvent(self, key, val): """ Generate a key or btn event @param int axis key or btn event (KEY_* or BTN_*) @param int val event value """ self._lib.uinput_key(self._fd, ctypes.c_uint16(key), ctypes.c_int32(val))
def axisEvent(self, axis, val): """ Generate a abs event (joystick/pad axes) @param int axis abs event (ABS_*) @param int val event value """ self._lib.uinput_abs(self._fd, ctypes.c_uint16(axis), ctypes.c_int32(val))
def relEvent(self, rel, val): """ Generate a rel event (move move) @param int rel rel event (REL_*) @param int val event value """ self._lib.uinput_rel(self._fd, ctypes.c_uint16(rel), ctypes.c_int32(val))
def scanEvent(self, val): """ Generate a scan event (MSC_SCAN) @param int val scan event value (scancode) """ self._lib.uinput_scan(self._fd, ctypes.c_int32(val))
def length(self) -> int: """Return the number of items in the T_ARRAY, T_MAP, T_FUNCTION and T_OBJECT sciter::value.""" if not self.get_type() in (VALUE_TYPE.T_ARRAY, VALUE_TYPE.T_MAP, VALUE_TYPE.T_FUNCTION, VALUE_TYPE.T_OBJECT): raise AttributeError("'%s' has no attribute '%s'" % (self.get_type(), 'length')) n = ctypes.c_int32() ok = _api.ValueElementsCount(self, byref(n)) self._throw_if(ok) return n.value
def num_ckt_elements(): """This parameter will deliver the number of CktElements included in the active circuit.""" return dsslib.CircuitI(ctypes.c_int32(0), ctypes.c_int32(0))
def num_buses(): """This parameter will deliver the number of buses included in the active circuit.""" return dsslib.CircuitI(ctypes.c_int32(1), ctypes.c_int32(0))
def num_nodes(): """This parameter will deliver the number of nodes included in the active circuit.""" return dsslib.CircuitI(ctypes.c_int32(2), ctypes.c_int32(0))
def first_pc_element(): """This parameter sets the first PCElement to be the active PCElement, as a result, this parameter will deliver the index of the active PCElement (ideally 1).""" return dsslib.CircuitI(ctypes.c_int32(3), ctypes.c_int32(0))
def next_pc_element(): """This parameter sets the next PCElement to be the active PCElement, as a result, this parameter will deliver the index of the active PCElement (if there is no more it will return a 0).""" return dsslib.CircuitI(ctypes.c_int32(4), ctypes.c_int32(0))
def next_pd_element(): """This parameter sets the next PDElement to be the active PDElement, as a result, this parameter will deliver the index of the active PDElement (if there is no more it will return a 0).""" return dsslib.CircuitI(ctypes.c_int32(6), ctypes.c_int32(0))
def sample(): """This parameter forces all meters and monitors to take a sample, returns 0.""" return dsslib.CircuitI(ctypes.c_int32(7), ctypes.c_int32(0))
def save_sample(): """This parameter forces all meters and monitors to save their sample buffers, returns 0.""" return dsslib.CircuitI(ctypes.c_int32(8), ctypes.c_int32(0))
def set_active_nbus(index): """This parameter sets active the bus specified by index, which is compatible with the index delivered by AllBusNames, returns 0 it everything ok.""" return dsslib.CircuitI(ctypes.c_int32(9), ctypes.c_int32(index))
def first_element(): """This parameter sets the first Element of the active class to be the active Element, as a result, this parameter will deliver the index of the active Element (0 if none).""" return dsslib.CircuitI(ctypes.c_int32(10), ctypes.c_int32(0))
def update_storage(): """This parameter forces all storage classes to update. Typically done after a solution.""" return dsslib.CircuitI(ctypes.c_int32(12), ctypes.c_int32(0))
def parent_pd_element(): """This parameter sets parent PD Element, if any, to be the active circuit element and returns index > 0 if it fails or not applicable.""" return dsslib.CircuitI(ctypes.c_int32(13), ctypes.c_int32(0))
def end_of_time_step_update(): """This parameter calls end of time step cleanup routine in solutionalgs.pas. Returns 0.""" return dsslib.CircuitI(ctypes.c_int32(14), ctypes.c_int32(0))
def capacity(c_start=0.0, c_increment=0.0): """This parameter returns the total capacity of the active circuit. Or this parameter it is necessary to specify the start and increment of the capacity in the arguments argument1 and argument2 respectively.""" return dsslib.CircuitF(ctypes.c_int32(0), ctypes.c_double(c_start), ctypes.c_double(c_increment))
def name(): """This parameter returns the name of the active circuit.""" return dsslib.CircuitS(ctypes.c_int32(0), ''.encode('ascii')).decode('ascii')
def enable(element): """This parameter allows to enable an element of the active circuit, the element must be specified by name. As a result, this parameter will deliver the string “Ok”.""" return dsslib.CircuitS(ctypes.c_int32(2), element.encode('ascii')).decode('ascii')
def set_active_element(element): """This parameter allows to activate an element of the active circuit, the element must be specified by name. As a result, this parameter will deliver a string with the index of the active element.""" return dsslib.CircuitS(ctypes.c_int32(3), element.encode('ascii')).decode('ascii')
def set_active_bus(bus): """This parameter allows to activate a bus of the active circuit, the bus must be specified by name. As a result, this parameter will deliver a string with the index of the active Bus.""" return dsslib.CircuitS(ctypes.c_int32(4), bus.encode('ascii')).decode('ascii')
def set_active_class(class_name): """This parameter allows to activate a Class of the active circuit, the Class must be specified by name. As a result, this parameter will deliver a string with the index of the active Class.""" return dsslib.CircuitS(ctypes.c_int32(5), class_name.encode('ascii')).decode('ascii')
def num_terminals(): """This parameter will deliver the number of terminals of the active DSS object.""" return dsslib.CktElementI(ctypes.c_int32(0), ctypes.c_int32(0))
def num_phases(): """""" return dsslib.CktElementI(ctypes.c_int32(2), ctypes.c_int32(0))
def open(terminal): """This parameter will open the specified terminal (Argument) of the active DSS object.""" return dsslib.CktElementI(ctypes.c_int32(3), ctypes.c_int32(terminal))
def close(terminal): """This parameter will close the specified terminal (Argument) of the active DSS object.""" return dsslib.CktElementI(ctypes.c_int32(4), ctypes.c_int32(terminal))
def is_open(): """This parameter will return a 1 if any terminal of the active DSS object is open, otherwise, it will return a 0.""" return dsslib.CktElementI(ctypes.c_int32(5), ctypes.c_int32(0))
def get_normal_amps(): """This parameter will deliver the normal ampere rating for the active PDElement.""" return dsslib.CktElementF(ctypes.c_int32(0), ctypes.c_double(0))
def get_emerg_amps(): """This parameter will deliver the Emergency ampere rating for the active PDElement.""" return dsslib.CktElementF(ctypes.c_int32(2), ctypes.c_double(0))
def set_emerg_amps(amps=0.0): """This parameter allows to fix the Emergency ampere rating for the active PDElement. The new value must be defined in the variable “Argument”.""" return dsslib.CktElementF(ctypes.c_int32(3), ctypes.c_double(amps))
def name(): """This parameter delivers the full name of the active circuit element.""" return dsslib.CktElementS(ctypes.c_int32(0), ''.encode('ascii')).decode('ascii')
def guid(): """This parameter delivers the unique name for the active circuit element.""" return dsslib.CktElementS(ctypes.c_int32(3), ''.encode('ascii')).decode('ascii')
def energy_meter(): """This parameter delivers the name of the EnergyMeter linked to the active circuit element.""" return dsslib.CktElementS(ctypes.c_int32(4), ''.encode('ascii')).decode('ascii')
def num_nodes(): """This parameter returns the number of nodes of this bus.""" return dsslib.BUSI(ctypes.c_int32(0), ctypes.c_int32(0))
def coord_defined(): """This parameter returns 1 if a coordinate has been defined for this bus; otherwise, it will return 0.""" return dsslib.BUSI(ctypes.c_int32(2), ctypes.c_int32(0))
def get_unique_node_number(): """This parameter returns a unique node number at the active bus to avoid node collisions and adds it to the node list for the bus. The start number can be specified in the argument.""" return dsslib.BUSI(ctypes.c_int32(3), ctypes.c_int32(0))
def n_customers(): """This parameter returns the total number of customers server down line from this bus.""" return dsslib.BUSI(ctypes.c_int32(4), ctypes.c_int32(0))
def section_id(): """This parameter returns the integer ID of the feeder section in which this bus is located.""" return dsslib.BUSI(ctypes.c_int32(5), ctypes.c_int32(0))