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


Python ctypes.c_float方法代码示例

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


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

示例1: _calibrate_quantized_sym

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_float [as 别名]
def _calibrate_quantized_sym(qsym, th_dict):
    """Given a dictionary containing the thresholds for quantizing the layers,
    set the thresholds into the quantized symbol as the params of requantize operators.
    """
    if th_dict is None or len(th_dict) == 0:
        return qsym
    num_layer_outputs = len(th_dict)
    layer_output_names = []
    min_vals = []
    max_vals = []
    for k, v in th_dict.items():
        layer_output_names.append(k)
        min_vals.append(v[0])
        max_vals.append(v[1])

    calibrated_sym = SymbolHandle()
    check_call(_LIB.MXSetCalibTableToQuantizedSymbol(qsym.handle,
                                                     mx_uint(num_layer_outputs),
                                                     c_str_array(layer_output_names),
                                                     c_array(ctypes.c_float, min_vals),
                                                     c_array(ctypes.c_float, max_vals),
                                                     ctypes.byref(calibrated_sym)))
    return Symbol(calibrated_sym) 
开发者ID:awslabs,项目名称:dynamic-training-with-apache-mxnet-on-aws,代码行数:25,代码来源:quantization.py

示例2: spmv_wrapper

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_float [as 别名]
def spmv_wrapper(n, alpha, ap, x, beta = 0.0, incx = 1, incy = 1, lower=0):
  """ Small blas wrapper that is missing in scipy.linalg.blas in scipy.version<=1 """

  if ap.size != n*(n+1)//2:
    raise ValueError("simple wrapper, you MUST provide x.size = n, ap.size = n*(n+1)/2")
    
  if ap.dtype == np.float32:
    y = np.zeros((n), dtype=np.float32)
    libsparsetools.SSPMV_wrapper(c_int(lower), c_int(n), c_float(alpha),
                ap.ctypes.data_as(POINTER(c_float)),
                x.ctypes.data_as(POINTER(c_float)), c_int(incx), c_float(beta),
                y.ctypes.data_as(POINTER(c_float)), c_int(incy))
  elif ap.dtype == np.float64:
    y = np.zeros((n), dtype=np.float64)
    libsparsetools.DSPMV_wrapper(c_int(lower), c_int(n), c_double(alpha),
                ap.ctypes.data_as(POINTER(c_double)),
                x.ctypes.data_as(POINTER(c_double)), c_int(incx), c_double(beta),
                y.ctypes.data_as(POINTER(c_double)), c_int(incy))
  else:
    raise ValueError("dtype error, only np.float32 and np.float64 implemented")

  return y 
开发者ID:pyscf,项目名称:pyscf,代码行数:24,代码来源:m_blas_wrapper.py

示例3: _ar_arsdk_encode_type_info

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_float [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: _AiNodeSetArray

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_float [as 别名]
def _AiNodeSetArray(node, param, value):
    t = value[0]
    _len = len(value)
    if type(t) is float:
        int_arr_type = ctypes.c_float * len(value)
        oftype = arnold.AI_TYPE_FLOAT
        _a = arnold.AiArrayConvert(_len, 1, oftype, int_arr_type(*value))
    if type(t) is list:
        oftype = arnold.AI_TYPE_RGB
        arr_t = ctypes.c_float * 3
        arr_of_arr_t = arr_t * len(value)
        _a = arnold.AiArrayConvert(_len, 1, oftype, arr_of_arr_t(arr_t(*value[0]), arr_t(*value[1])))
    if type(t) is int:
        int_arr_type = ctypes.c_int * len(value)
        oftype = arnold.AI_TYPE_INT
        _a = arnold.AiArrayConvert(_len, 1, oftype, int_arr_type(*value))
    arnold.AiNodeSetArray(node, param, _a) 
开发者ID:griffin-copperfield,项目名称:Arnold-For-Blender,代码行数:19,代码来源:__init__.py

示例5: ENaddcontrol

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_float [as 别名]
def ENaddcontrol(self, ctype, lindex, setting, nindex, level ):
        """Sets the parameters of a simple control statement.
        Arguments:
           ctype:   control type code  EN_LOWLEVEL   (Low Level Control)
                                       EN_HILEVEL    (High Level Control)  
                                       EN_TIMER      (Timer Control)       
                                       EN_TIMEOFDAY  (Time-of-Day Control)
           lindex:  index of link being controlled
           setting: value of the control setting
           nindex:  index of controlling node
           level:   value of controlling water level or pressure for level controls
                    or of time of control action (in seconds) for time-based controls"""
        #int ENsetcontrol(int cindex, int* ctype, int* lindex, float* setting, int* nindex, float* level )
        cindex = ctypes.c_int()
        ierr= self._lib.EN_addcontrol(self.ph, ctypes.byref(cindex), ctypes.c_int(ctype),
                                ctypes.c_int(lindex), ctypes.c_float(setting), 
                                ctypes.c_int(nindex), ctypes.c_float(level))
        if ierr!=0: raise ENtoolkitError(self, ierr)
        return cindex 
开发者ID:Vitens,项目名称:epynet,代码行数:21,代码来源:epanet2.py

示例6: ENsetcontrol

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_float [as 别名]
def ENsetcontrol(self, cindex, ctype, lindex, setting, nindex, level ):
        """Sets the parameters of a simple control statement.
        Arguments:
           cindex:  control statement index
           ctype:   control type code  EN_LOWLEVEL   (Low Level Control)
                                       EN_HILEVEL    (High Level Control)  
                                       EN_TIMER      (Timer Control)       
                                       EN_TIMEOFDAY  (Time-of-Day Control)
           lindex:  index of link being controlled
           setting: value of the control setting
           nindex:  index of controlling node
           level:   value of controlling water level or pressure for level controls
                    or of time of control action (in seconds) for time-based controls"""
        #int ENsetcontrol(int cindex, int* ctype, int* lindex, float* setting, int* nindex, float* level )
        ierr= self._lib.EN_setcontrol(self.ph, ctypes.c_int(cindex), ctypes.c_int(ctype),
                                ctypes.c_int(lindex), ctypes.c_float(setting), 
                                ctypes.c_int(nindex), ctypes.c_float(level) )
        if ierr!=0: raise ENtoolkitError(self, ierr) 
开发者ID:Vitens,项目名称:epynet,代码行数:20,代码来源:epanet2.py

示例7: ENgetcurve

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_float [as 别名]
def ENgetcurve(self, curveIndex):
        curveid = ctypes.create_string_buffer(self._max_label_len)
        nValues = ctypes.c_int()
        xValues= (ctypes.c_float*100)()
        yValues= (ctypes.c_float*100)()
        ierr= self._lib.EN_getcurve(self.ph, curveIndex,
                              ctypes.byref(curveid),
                             ctypes.byref(nValues),
                             xValues,
                             yValues
                             )
        # strange behavior of ENgetcurve: it returns also curveID
        # better split in two distinct functions ....
        if ierr!=0: raise ENtoolkitError(self, ierr)
        curve= []
        for i in range(nValues.value):
           curve.append( (xValues[i],yValues[i]) )
        return curve 
开发者ID:Vitens,项目名称:epynet,代码行数:20,代码来源:epanet2.py

示例8: test_ready_argument_list2

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_float [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

示例9: cudnnSetTensor

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_float [as 别名]
def cudnnSetTensor(handle, srcDesc, srcData, value):
    """"
    Set all data points of a tensor to a given value : srcDest = alpha.

    Parameters
    ----------
    handle : cudnnHandle
        Handle to a previously created cuDNN context.
    srcDesc : cudnnTensorDescriptor
        Handle to a previously initialized tensor descriptor.
    srcData : void_p
        Pointer to data of the tensor described by srcDesc descriptor.
    value : float
        Value that all elements of the tensor will be set to.
    """

    dataType, _, _, _, _, _, _, _, _ = cudnnGetTensor4dDescriptor(srcDesc)
    if dataType == cudnnDataType['CUDNN_DATA_DOUBLE']:
        alphaRef = ctypes.byref(ctypes.c_double(alpha))
    else:
        alphaRef = ctypes.byref(ctypes.c_float(alpha))

    status = _libcudnn.cudnnSetTensor(handle, srcDesc, srcData, alphaRef)
    cudnnCheckStatus(status) 
开发者ID:TalwalkarLab,项目名称:paleo,代码行数:26,代码来源:libcudnn.py

示例10: __init__

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_float [as 别名]
def __init__(self, cfg):
        self.__is_use_can_port = cfg['use_can']

        # Data for store
        self.rx_counter_servo_unit = multiprocessing.Value(ctypes.c_int,0)
        self.rx_time_us_diff = multiprocessing.Value(ctypes.c_int,0)
        self.rx_button_y = multiprocessing.Value(ctypes.c_bool,False)
        self.rx_button_g = multiprocessing.Value(ctypes.c_bool,False)
        self.rx_button_r = multiprocessing.Value(ctypes.c_bool,False)
        self.rx_actual_angle = multiprocessing.Value(ctypes.c_float,0.0)
        self.can_error_count_rx = multiprocessing.Value(ctypes.c_int,0)

        # Initialize process
        self.__m = multiprocessing.Process(target=self.__process_can, \
                                           args=(cfg['can_name'], \
                                                 cfg['can_bustype'], \
                                                 cfg['can_bitrate'], \
                                                 cfg['can_dbc_path'], \
                                                 cfg['can_rx_interval']))
        # Start process
        self.__m.start()

        return 
开发者ID:YanbaruRobotics,项目名称:PythonPilot,代码行数:25,代码来源:io_can.py

示例11: _set_dtype

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_float [as 别名]
def _set_dtype(self, force_cast=False):
        self._dtype = ctypes.c_float if self._use_float else ctypes.c_double

        if force_cast:
            if self.coef_.dtype != self._dtype:
                self.coef_ = self.coef_.astype(self._dtype)
            if self._XtX.dtype != self._dtype:
                self._XtX = self._XtX.astype(self._dtype)
            if self._invXtX.dtype != self._dtype:
                self._invXtX = self._invXtX.astype(self._dtype)
            if self._XtY.dtype != self._dtype:
                self._XtY = self._XtY.astype(self._dtype)
            if self._bufferX.dtype != self._dtype:
                self._bufferX = self._bufferX.astype(self._dtype) 
开发者ID:david-cortes,项目名称:contextualbandits,代码行数:16,代码来源:__init__.py

示例12: cf_number_to_number

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_float [as 别名]
def cf_number_to_number(value):
        """
        Converts a CFNumber object to a python float or integer

        :param value:
            The CFNumber object

        :return:
            A python number (float or integer)
        """

        type_ = CoreFoundation.CFNumberGetType(_cast_pointer_p(value))
        c_type = {
            1: c_byte,              # kCFNumberSInt8Type
            2: ctypes.c_short,      # kCFNumberSInt16Type
            3: ctypes.c_int32,      # kCFNumberSInt32Type
            4: ctypes.c_int64,      # kCFNumberSInt64Type
            5: ctypes.c_float,      # kCFNumberFloat32Type
            6: ctypes.c_double,     # kCFNumberFloat64Type
            7: c_byte,              # kCFNumberCharType
            8: ctypes.c_short,      # kCFNumberShortType
            9: ctypes.c_int,        # kCFNumberIntType
            10: c_long,             # kCFNumberLongType
            11: ctypes.c_longlong,  # kCFNumberLongLongType
            12: ctypes.c_float,     # kCFNumberFloatType
            13: ctypes.c_double,    # kCFNumberDoubleType
            14: c_long,             # kCFNumberCFIndexType
            15: ctypes.c_int,       # kCFNumberNSIntegerType
            16: ctypes.c_double,    # kCFNumberCGFloatType
        }[type_]
        output = c_type(0)
        CoreFoundation.CFNumberGetValue(_cast_pointer_p(value), type_, byref(output))
        return output.value 
开发者ID:wbond,项目名称:oscrypto,代码行数:35,代码来源:_core_foundation_ctypes.py

示例13: siesta_hsx_read

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_float [as 别名]
def siesta_hsx_read(fname, force_gamma=None): 

  fname = create_string_buffer(fname.encode())
  if force_gamma is None: 
    ft = c_int64(-1)
  elif force_gamma: 
    ft = c_int64(1)
  elif not force_gamma: 
    ft = c_int64(2)
  
  bufsize, row_ptr_size, col_ind_size = c_int64(), c_int64(), c_int64()
  libnao.siesta_hsx_size(fname, ft, bufsize, row_ptr_size, col_ind_size)
  if bufsize.value<=0 or row_ptr_size.value <= 0 or col_ind_size.value <= 0: return None
  
  dat = empty(bufsize.value, dtype=np.float32)
  dimensions = empty(4, dtype=np.int64)
  row_ptr = empty(row_ptr_size.value, dtype=np.int64)
  col_ind = empty(col_ind_size.value, dtype=np.int64)

  libnao.siesta_hsx_read(fname, ft, dat.ctypes.data_as(POINTER(c_float)),
      row_ptr.ctypes.data_as(POINTER(c_int64)), row_ptr_size,
      col_ind.ctypes.data_as(POINTER(c_int64)), col_ind_size,
      dimensions.ctypes.data_as(POINTER(c_int64)))
  return dat, row_ptr, col_ind, dimensions

#
#
# 
开发者ID:pyscf,项目名称:pyscf,代码行数:30,代码来源:m_siesta_hsx.py

示例14: csr_matvec

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_float [as 别名]
def csr_matvec(csr, x):

    if not sparse.isspmatrix_csr(csr):
        raise Exception("Matrix must be in csr format")

    nrow, ncol = csr.shape
    nnz = csr.data.shape[0]
    if x.size != ncol:
      print(x.size, ncol)
      raise ValueError("wrong dimension!")

    xx = np.require(x, requirements=["A", "O"])
    
    if csr.dtype == np.float32:
        y = np.zeros((nrow), dtype=np.float32)
        libsparsetools.scsr_matvec(c_int(nrow), c_int(ncol), c_int(nnz), 
                csr.indptr.ctypes.data_as(POINTER(c_int)),
                csr.indices.ctypes.data_as(POINTER(c_int)), 
                csr.data.ctypes.data_as(POINTER(c_float)),
                xx.ctypes.data_as(POINTER(c_float)), 
                y.ctypes.data_as(POINTER(c_float)))

    elif csr.dtype == np.float64:
        y = np.zeros((nrow), dtype=np.float64)
        libsparsetools.dcsr_matvec(c_int(nrow), c_int(ncol), c_int(nnz), 
                csr.indptr.ctypes.data_as(POINTER(c_int)),
                csr.indices.ctypes.data_as(POINTER(c_int)), 
                csr.data.ctypes.data_as(POINTER(c_double)),
                xx.ctypes.data_as(POINTER(c_double)), 
                y.ctypes.data_as(POINTER(c_double)))
    else:
        raise ValueError("Not implemented")

    return y 
开发者ID:pyscf,项目名称:pyscf,代码行数:36,代码来源:m_sparsetools.py

示例15: csc_matvec

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_float [as 别名]
def csc_matvec(csc, x):
    """
        Matrix vector multiplication
        using csc format
    """

    if not sparse.isspmatrix_csc(csc):
        raise Exception("Matrix must be in csc format")

    nrow, ncol = csc.shape
    nnz = csc.data.shape[0]
    if x.size != ncol:
      print(x.size, ncol)
      raise ValueError("wrong dimension!")

    xx = np.require(x, requirements="C")

    if csc.dtype == np.float32:
        y = np.zeros((nrow), dtype=np.float32)
        libsparsetools.scsc_matvec(c_int(nrow), c_int(ncol), c_int(nnz), 
                csc.indptr.ctypes.data_as(POINTER(c_int)),
                csc.indices.ctypes.data_as(POINTER(c_int)), 
                csc.data.ctypes.data_as(POINTER(c_float)),
                xx.ctypes.data_as(POINTER(c_float)), 
                y.ctypes.data_as(POINTER(c_float)))

    elif csc.dtype == np.float64:
        y = np.zeros((nrow), dtype=np.float64)
        libsparsetools.dcsc_matvec(c_int(nrow), c_int(ncol), c_int(nnz), 
                csc.indptr.ctypes.data_as(POINTER(c_int)),
                csc.indices.ctypes.data_as(POINTER(c_int)), 
                csc.data.ctypes.data_as(POINTER(c_double)),
                xx.ctypes.data_as(POINTER(c_double)), 
                y.ctypes.data_as(POINTER(c_double)))
    else:
        raise ValueError("Not implemented")

    return y 
开发者ID:pyscf,项目名称:pyscf,代码行数:40,代码来源:m_sparsetools.py


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