Python ctypes.c_longlong() Examples

The following are 30 code examples of ctypes.c_longlong(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module ctypes , or try the search function .
Example #1
Source File: _internal.py    From twitter-stock-recommendation with MIT License 6 votes vote down vote up
def _getintp_ctype():
    val = _getintp_ctype.cache
    if val is not None:
        return val
    if ctypes is None:
        import numpy as np
        val = dummy_ctype(np.intp)
    else:
        char = dtype('p').char
        if (char == 'i'):
            val = ctypes.c_int
        elif char == 'l':
            val = ctypes.c_long
        elif char == 'q':
            val = ctypes.c_longlong
        else:
            val = ctypes.c_long
    _getintp_ctype.cache = val
    return val 
Example #2
Source File: _internal.py    From predictive-maintenance-using-machine-learning with Apache License 2.0 6 votes vote down vote up
def _getintp_ctype():
    val = _getintp_ctype.cache
    if val is not None:
        return val
    if ctypes is None:
        import numpy as np
        val = dummy_ctype(np.intp)
    else:
        char = dtype('p').char
        if (char == 'i'):
            val = ctypes.c_int
        elif char == 'l':
            val = ctypes.c_long
        elif char == 'q':
            val = ctypes.c_longlong
        else:
            val = ctypes.c_long
    _getintp_ctype.cache = val
    return val 
Example #3
Source File: _internal.py    From Mastering-Elasticsearch-7.0 with MIT License 6 votes vote down vote up
def _getintp_ctype():
    val = _getintp_ctype.cache
    if val is not None:
        return val
    if ctypes is None:
        import numpy as np
        val = dummy_ctype(np.intp)
    else:
        char = dtype('p').char
        if (char == 'i'):
            val = ctypes.c_int
        elif char == 'l':
            val = ctypes.c_long
        elif char == 'q':
            val = ctypes.c_longlong
        else:
            val = ctypes.c_long
    _getintp_ctype.cache = val
    return val 
Example #4
Source File: _internal.py    From Computable with MIT License 6 votes vote down vote up
def _getintp_ctype():
    from .multiarray import dtype
    val = _getintp_ctype.cache
    if val is not None:
        return val
    char = dtype('p').char
    import ctypes
    if (char == 'i'):
        val = ctypes.c_int
    elif char == 'l':
        val = ctypes.c_long
    elif char == 'q':
        val = ctypes.c_longlong
    else:
        val = ctypes.c_long
    _getintp_ctype.cache = val
    return val 
Example #5
Source File: _internal.py    From GraphicDesignPatternByPython with MIT License 6 votes vote down vote up
def _getintp_ctype():
    val = _getintp_ctype.cache
    if val is not None:
        return val
    if ctypes is None:
        import numpy as np
        val = dummy_ctype(np.intp)
    else:
        char = dtype('p').char
        if (char == 'i'):
            val = ctypes.c_int
        elif char == 'l':
            val = ctypes.c_long
        elif char == 'q':
            val = ctypes.c_longlong
        else:
            val = ctypes.c_long
    _getintp_ctype.cache = val
    return val 
Example #6
Source File: _internal.py    From vnpy_crypto with MIT License 6 votes vote down vote up
def _getintp_ctype():
    val = _getintp_ctype.cache
    if val is not None:
        return val
    if ctypes is None:
        import numpy as np
        val = dummy_ctype(np.intp)
    else:
        char = dtype('p').char
        if (char == 'i'):
            val = ctypes.c_int
        elif char == 'l':
            val = ctypes.c_long
        elif char == 'q':
            val = ctypes.c_longlong
        else:
            val = ctypes.c_long
    _getintp_ctype.cache = val
    return val 
Example #7
Source File: __init__.py    From afnumpy with BSD 2-Clause "Simplified" License 6 votes vote down vote up
def inplace_setitem(self, key, val):
    try:
        n_dims = self.numdims()
        if (arrayfire.util._is_number(val)):
            tdims = arrayfire.array._get_assign_dims(key, self.dims())
            other_arr = arrayfire.array.constant_array(val, tdims[0], tdims[1], tdims[2], tdims[3], self.type())
            del_other = True
        else:
            other_arr = val.arr
            del_other = False

        inds  = arrayfire.array._get_indices(key)

        # In place assignment. Notice passing a pointer to self.arr as output
        arrayfire.util.safe_call(arrayfire.backend.get().af_assign_gen(ctypes.pointer(self.arr),
                                                                            self.arr, ctypes.c_longlong(n_dims),
                                                                            inds.pointer,
                                                                            other_arr))
        if del_other:
            arrayfire.safe_call(arrayfire.backend.get().af_release_array(other_arr))
    except RuntimeError as e:
        raise IndexError(str(e)) 
Example #8
Source File: _internal.py    From lambda-packs with MIT License 6 votes vote down vote up
def _getintp_ctype():
    val = _getintp_ctype.cache
    if val is not None:
        return val
    if ctypes is None:
        import numpy as np
        val = dummy_ctype(np.intp)
    else:
        char = dtype('p').char
        if (char == 'i'):
            val = ctypes.c_int
        elif char == 'l':
            val = ctypes.c_long
        elif char == 'q':
            val = ctypes.c_longlong
        else:
            val = ctypes.c_long
    _getintp_ctype.cache = val
    return val 
Example #9
Source File: _internal.py    From Fluid-Designer with GNU General Public License v3.0 6 votes vote down vote up
def _getintp_ctype():
    from .multiarray import dtype
    val = _getintp_ctype.cache
    if val is not None:
        return val
    char = dtype('p').char
    import ctypes
    if (char == 'i'):
        val = ctypes.c_int
    elif char == 'l':
        val = ctypes.c_long
    elif char == 'q':
        val = ctypes.c_longlong
    else:
        val = ctypes.c_long
    _getintp_ctype.cache = val
    return val 
Example #10
Source File: _internal.py    From pySINDy with MIT License 6 votes vote down vote up
def _getintp_ctype():
    val = _getintp_ctype.cache
    if val is not None:
        return val
    if ctypes is None:
        import numpy as np
        val = dummy_ctype(np.intp)
    else:
        char = dtype('p').char
        if (char == 'i'):
            val = ctypes.c_int
        elif char == 'l':
            val = ctypes.c_long
        elif char == 'q':
            val = ctypes.c_longlong
        else:
            val = ctypes.c_long
    _getintp_ctype.cache = val
    return val 
Example #11
Source File: _internal.py    From mxnet-lambda with Apache License 2.0 6 votes vote down vote up
def _getintp_ctype():
    val = _getintp_ctype.cache
    if val is not None:
        return val
    if ctypes is None:
        import numpy as np
        val = dummy_ctype(np.intp)
    else:
        char = dtype('p').char
        if (char == 'i'):
            val = ctypes.c_int
        elif char == 'l':
            val = ctypes.c_long
        elif char == 'q':
            val = ctypes.c_longlong
        else:
            val = ctypes.c_long
    _getintp_ctype.cache = val
    return val 
Example #12
Source File: _internal.py    From ImageFusion with MIT License 6 votes vote down vote up
def _getintp_ctype():
    from .multiarray import dtype
    val = _getintp_ctype.cache
    if val is not None:
        return val
    char = dtype('p').char
    import ctypes
    if (char == 'i'):
        val = ctypes.c_int
    elif char == 'l':
        val = ctypes.c_long
    elif char == 'q':
        val = ctypes.c_longlong
    else:
        val = ctypes.c_long
    _getintp_ctype.cache = val
    return val 
Example #13
Source File: _internal.py    From Splunking-Crime with GNU Affero General Public License v3.0 6 votes vote down vote up
def _getintp_ctype():
    val = _getintp_ctype.cache
    if val is not None:
        return val
    if ctypes is None:
        import numpy as np
        val = dummy_ctype(np.intp)
    else:
        char = dtype('p').char
        if (char == 'i'):
            val = ctypes.c_int
        elif char == 'l':
            val = ctypes.c_long
        elif char == 'q':
            val = ctypes.c_longlong
        else:
            val = ctypes.c_long
    _getintp_ctype.cache = val
    return val 
Example #14
Source File: archive_read.py    From PyEasyArchive with GNU General Public License v2.0 6 votes vote down vote up
def _read_by_block(archive_res):
    buffer_ = ctypes.c_char_p()
    num = ctypes.c_size_t()
    offset = ctypes.c_longlong()

    while 1:
        r = libarchive.calls.archive_read.c_archive_read_data_block(
                archive_res,
                ctypes.cast(ctypes.byref(buffer_),
                            ctypes.POINTER(ctypes.c_void_p)),
                ctypes.byref(num),
                ctypes.byref(offset))

        if r == libarchive.constants.archive.ARCHIVE_OK:
            block = ctypes.string_at(buffer_, num.value)
            assert len(block) == num.value

            yield block

        elif r == libarchive.constants.archive.ARCHIVE_EOF:
            break

        else:
            raise ValueError("Read failed (archive_read_data_block): (%d)" %
                             (r,)) 
Example #15
Source File: _internal.py    From elasticintel with GNU General Public License v3.0 6 votes vote down vote up
def _getintp_ctype():
    val = _getintp_ctype.cache
    if val is not None:
        return val
    if ctypes is None:
        import numpy as np
        val = dummy_ctype(np.intp)
    else:
        char = dtype('p').char
        if (char == 'i'):
            val = ctypes.c_int
        elif char == 'l':
            val = ctypes.c_long
        elif char == 'q':
            val = ctypes.c_longlong
        else:
            val = ctypes.c_long
    _getintp_ctype.cache = val
    return val 
Example #16
Source File: elbow_wrapper.py    From pyclustering with GNU General Public License v3.0 6 votes vote down vote up
def elbow(sample, kmin, kmax, initializer, random_state):
    random_state = random_state or -1
    pointer_data = package_builder(sample, c_double).create()

    ccore = ccore_library.get()
    if initializer == elbow_center_initializer.KMEANS_PLUS_PLUS:
        ccore.elbow_method_ikpp.restype = POINTER(pyclustering_package)
        package = ccore.elbow_method_ikpp(pointer_data, c_size_t(kmin), c_size_t(kmax), c_longlong(random_state))
    elif initializer == elbow_center_initializer.RANDOM:
        ccore.elbow_method_irnd.restype = POINTER(pyclustering_package)
        package = ccore.elbow_method_irnd(pointer_data, c_size_t(kmin), c_size_t(kmax), c_longlong(random_state))
    else:
        raise ValueError("Not supported type of center initializer '" + str(initializer) + "'.")

    results = package_extractor(package).extract()
    ccore.free_pyclustering_package(package)

    return (results[elbow_package_indexer.ELBOW_PACKAGE_INDEX_AMOUNT][0],
            results[elbow_package_indexer.ELBOW_PACKAGE_INDEX_WCE]) 
Example #17
Source File: WnfDump.py    From wnfun with BSD 2-Clause "Simplified" License 6 votes vote down vote up
def DoWrite(StateName, Data):
    StateName = ctypes.c_longlong(int(StateName, 16))
    dataBuffer = ctypes.c_char_p(Data)
    bufferSize = len(Data)
    status = ZwUpdateWnfStateData(ctypes.byref(StateName), dataBuffer, bufferSize, 0, 0, 0, 0)
    status = ctypes.c_ulong(status).value

    if status == 0:
        return True
    else:
        print('[Error] Could not write for this statename: 0x{:x}'.format(status))
        return False

   

#########################################################################################



############### MAIN ############### 
Example #18
Source File: wnfcom.py    From wnfun with BSD 2-Clause "Simplified" License 6 votes vote down vote up
def SetStateName(self, WnfName):
        tmpName = 0
        try:
            tmpName = g_WellKnownWnfNames[WnfName.upper()]
        except:
            if len(WnfName)>2 and WnfName[1] == 'x':
                WnfName = WnfName[2:]
            try:
                tmpName = int(WnfName, 16)
            except:
                tmpName = 0
                self.pprint("[Error] Could not validate the provided name")
                return False

        self.StateName = ctypes.c_longlong(tmpName)
        self.internalName.value = ctypes.c_ulonglong(tmpName ^ WNF_STATE_KEY)
        return True 
Example #19
Source File: _internal.py    From coffeegrindsize with MIT License 6 votes vote down vote up
def _getintp_ctype():
    val = _getintp_ctype.cache
    if val is not None:
        return val
    if ctypes is None:
        import numpy as np
        val = dummy_ctype(np.intp)
    else:
        char = dtype('p').char
        if (char == 'i'):
            val = ctypes.c_int
        elif char == 'l':
            val = ctypes.c_long
        elif char == 'q':
            val = ctypes.c_longlong
        else:
            val = ctypes.c_long
    _getintp_ctype.cache = val
    return val 
Example #20
Source File: nervanamkl.py    From neon with Apache License 2.0 6 votes vote down vote up
def fprop_relu(self, layer, x, slope):
        if layer is None:
            layer = layer_mkl.ReluLayerMKL()
        if not hasattr(x, 'shape5D'):
            return self.maximum(x, 0) + slope * self.minimum(0, x)
        if slope != 0:
            self.convert(x)
            x.clean_mkl()
            return self.maximum(x, 0) + slope * self.minimum(0, x)

        if x.shape5D is not None:
            C, D, H, W, N = x.shape5D
        else:
            C, N = x._tensor.shape
            D, H, W = 1, 1, 1
            x.shape5D = C, D, H, W, N
        layer.shape5D = C, D, H, W, N

        primitives = c_longlong(layer.dnnPrimitives.ctypes.data)
        if x.primitive[3] == 0:
            layer.inputMKL = False
        self.mklEngine.Relu_f(x.get_prim(), primitives, layer.initOk_f, N, C, H, W)
        layer.initOk_f = 1
        return x 
Example #21
Source File: nervanamkl.py    From neon with Apache License 2.0 6 votes vote down vote up
def compound_bprop_bn(self, deltas, grad_gamma, grad_beta,
                          error, inputs, xsum, xvar, gamma,
                          eps, binary=False, layer=None):
        if not layer or not isinstance(layer.in_shape, tuple):
            super(NervanaMKL, self).compound_bprop_bn(deltas, grad_gamma,
                                                      grad_beta, error,
                                                      inputs, xsum, xvar,
                                                      gamma, eps, binary,
                                                      layer)
            return

        primitives = c_longlong(layer.dnnPrimitives.ctypes.data)

        self.mklEngine.BatchNormBackp(inputs.get_prim(), error.get_prim(),
                                      deltas.get_prim(), grad_gamma.get_prim(),
                                      grad_beta.get_prim(), layer.in_shape[0],
                                      primitives, layer.init_b)
        layer.init_b = 1
        deltas.shape5D = layer.shape5D 
Example #22
Source File: _internal.py    From Carnets with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def _getintp_ctype():
    val = _getintp_ctype.cache
    if val is not None:
        return val
    if ctypes is None:
        import numpy as np
        val = dummy_ctype(np.intp)
    else:
        char = dtype('p').char
        if (char == 'i'):
            val = ctypes.c_int
        elif char == 'l':
            val = ctypes.c_long
        elif char == 'q':
            val = ctypes.c_longlong
        else:
            val = ctypes.c_long
    _getintp_ctype.cache = val
    return val 
Example #23
Source File: api.py    From aws-builders-fair-projects with Apache License 2.0 6 votes vote down vote up
def _set_input(self, name, data):
        """Set the input using the input name with data

        Parameters
        __________
        name : str
            The name of an input.
        data : list of numbers
            The data to be set.
        """
        in_data = np.ascontiguousarray(data, dtype=np.float32)
        shape = np.array(in_data.shape, dtype=np.int64)
        _check_call(_LIB.SetDLRInput(byref(self.handle),
                                     c_char_p(name.encode('utf-8')),
                                     shape.ctypes.data_as(POINTER(c_longlong)),
                                     in_data.ctypes.data_as(POINTER(c_float)),
                                     c_int(in_data.ndim)))
        if self.backend == 'treelite':
            self._lazy_init_output_shape() 
Example #24
Source File: api.py    From aws-builders-fair-projects with Apache License 2.0 6 votes vote down vote up
def _get_output_size_dim(self, index):
        """Get the size and the dimenson of the index-th output.

        Parameters
        __________
        index : int
            The index of the output.

        Returns
        _______
        size : int
            The size of the index-th output.
        dim : int
            The dimension of the index-th output.
        """
        idx = ctypes.c_int(index)
        size = ctypes.c_longlong()
        dim = ctypes.c_int()
        _check_call(_LIB.GetDLROutputSizeDim(byref(self.handle), idx,
                                                      byref(size), byref(dim)))
        return size.value, dim.value 
Example #25
Source File: api.py    From aws-builders-fair-projects with Apache License 2.0 6 votes vote down vote up
def _get_output_shape(self, index):
        """Get the shape for the index-th output.

        Parameters
        __________
        index : int
            The index of the output.

        Returns
        _______
        shape : list
            The shape of the index-th output.
        """
        size, dim = self._get_output_size_dim(index)
        if not self.output_size_dim:
            self.output_size_dim = [(0, 0)] * self._get_num_outputs()
        self.output_size_dim[index] = (size, dim)
        shape = np.zeros(dim, dtype=np.int64)
        _check_call(_LIB.GetDLROutputShape(byref(self.handle),
                                                    c_int(index),
                    shape.ctypes.data_as(ctypes.POINTER(ctypes.c_longlong))))
        return shape 
Example #26
Source File: _internal.py    From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License 6 votes vote down vote up
def _getintp_ctype():
    val = _getintp_ctype.cache
    if val is not None:
        return val
    if ctypes is None:
        import numpy as np
        val = dummy_ctype(np.intp)
    else:
        char = dtype('p').char
        if (char == 'i'):
            val = ctypes.c_int
        elif char == 'l':
            val = ctypes.c_long
        elif char == 'q':
            val = ctypes.c_longlong
        else:
            val = ctypes.c_long
    _getintp_ctype.cache = val
    return val 
Example #27
Source File: _internal.py    From recruit with Apache License 2.0 6 votes vote down vote up
def _getintp_ctype():
    val = _getintp_ctype.cache
    if val is not None:
        return val
    if ctypes is None:
        import numpy as np
        val = dummy_ctype(np.intp)
    else:
        char = dtype('p').char
        if (char == 'i'):
            val = ctypes.c_int
        elif char == 'l':
            val = ctypes.c_long
        elif char == 'q':
            val = ctypes.c_longlong
        else:
            val = ctypes.c_long
    _getintp_ctype.cache = val
    return val 
Example #28
Source File: nervanamkl.py    From neon with Apache License 2.0 5 votes vote down vote up
def sum_tensor(self, sum, layer_num, tensors, output, shape5D):
        C, D, H, W, N = shape5D
        inp = c_longlong(tensors.ctypes.data)
        size = c_longlong(np.prod(output.shape))
        prim = c_longlong(sum.ctypes.data)
        self.mklEngine.MklSumTensor(layer_num, inp, size, output.get_prim(), prim, N, C, H, W) 
Example #29
Source File: nervanamkl.py    From neon with Apache License 2.0 5 votes vote down vote up
def compound_fprop_bn(self, x, xsum, xvar, gmean, gvar, gamma, beta, y,
                          eps, rho, compute_batch_sum,
                          accumbeta=0.0, relu=False, binary=False,
                          inference=False, outputs=None, layer=None):
        if layer is None or outputs is None or not isinstance(layer.in_shape, tuple):
            super(NervanaMKL, self).compound_fprop_bn(x, xsum, xvar, gmean, gvar,
                                                      gamma, beta, y, eps, rho,
                                                      compute_batch_sum,
                                                      accumbeta, relu, binary,
                                                      inference, outputs, layer
                                                      )
            return

        primitives = c_longlong(layer.dnnPrimitives.ctypes.data)
        if len(layer.in_shape) == 3:
            C = layer.in_shape[0]
            H = layer.in_shape[1]
            W = layer.in_shape[2]
            D = 1
        elif len(layer.in_shape) == 2:
            C = layer.in_shape[0]
            H = layer.in_shape[1]
            W = layer.in_shape[1]
            D = 1
        elif len(layer.in_shape) == 4:
            C = layer.in_shape[0]
            H = layer.in_shape[1]
            W = layer.in_shape[2]
            D = layer.in_shape[3]

        N = int(x.shape[-1]) // H // W // D  # this is/corresponds to the batch size
        gmean = c_longlong(gmean._tensor.ctypes.data)
        gvar = c_longlong(gvar._tensor.ctypes.data)
        self.mklEngine.BatchNormFprop(x.get_prim(), outputs.get_prim(),
                                      gamma.get_prim(), beta.get_prim(), gmean, gvar,
                                      c_float(rho), N, C, H, W * D, c_double(eps),
                                      primitives, layer.init_f, c_int(inference))
        layer.init_f = 1
        layer.shape5D = outputs.shape5D = C, D, H, W, N 
Example #30
Source File: _internal.py    From coffeegrindsize with MIT License 5 votes vote down vote up
def strides_as(self, obj):
        """
        Return the strides tuple as an array of some other
        c-types type. For example: ``self.strides_as(ctypes.c_longlong)``.
        """
        if self._zerod:
            return None
        return (obj*self._arr.ndim)(*self._arr.strides)