How to use the ert.cwrap.CWrapper.registerType function in ert

To help you get started, we’ve selected a few ert examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github OPM / ResInsight / ThirdParty / Ert / devel / python / python / ert / util / hash.py View on Github external
if key in self:
            return DoubleHash.cNamespace().get_double(self, key)
        else:
            raise KeyError("Hash does not have key: %s" % key)


cwrapper = CWrapper(UTIL_LIB)
CWrapper.registerType("hash", Hash) #c_void_p type
CWrapper.registerType("integer_hash", IntegerHash)
CWrapper.registerType("string_has", StringHash)
CWrapper.registerType("double_hash", DoubleHash)

CWrapper.registerType("hash_obj", Hash.createPythonObject) #c_void_p type
CWrapper.registerType("string_hash_obj", StringHash.createPythonObject)
CWrapper.registerType("integer_hash_obj", IntegerHash.createPythonObject)
CWrapper.registerType("double_hash_obj", DoubleHash.createPythonObject)

CWrapper.registerType("hash_ref", Hash.createCReference) #c_void_p type
CWrapper.registerType("string_hash_ref", StringHash.createCReference)
CWrapper.registerType("integer_hash_ref", IntegerHash.createCReference)
CWrapper.registerType("double_hash_ref", DoubleHash.createCReference)


Hash.cNamespace().alloc = cwrapper.prototype("long hash_alloc()")
Hash.cNamespace().free = cwrapper.prototype("void hash_free(hash)")
Hash.cNamespace().size = cwrapper.prototype("int hash_get_size(hash)")
Hash.cNamespace().keys = cwrapper.prototype("stringlist_obj hash_alloc_stringlist(hash)")
Hash.cNamespace().has_key = cwrapper.prototype("bool hash_has_key(hash, char*)")

Hash.cNamespace().get = cwrapper.prototype("c_void_p hash_get(hash, char*)")
IntegerHash.cNamespace().get_int = cwrapper.prototype("int hash_get_int(hash, char*)")
DoubleHash.cNamespace().get_double = cwrapper.prototype("double hash_get_double(hash, char*)")
github equinor / libecl / devel / python / python / ert / util / tvector.py View on Github external
def __init__(self, default_value=0, initial_size=0):
        super(TimeVector, self).__init__(default_value, initial_size)


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

buffer_from_ptr = ctypes.pythonapi.PyBuffer_FromMemory
buffer_from_ptr.restype  = ctypes.py_object
buffer_from_ptr.argtypes = [ ctypes.c_void_p , ctypes.c_long ]

CWrapper.registerType("double_vector", DoubleVector)
CWrapper.registerType("double_vector_obj", DoubleVector.createPythonObject)
CWrapper.registerType("double_vector_ref", DoubleVector.createCReference)

CWrapper.registerType("int_vector", IntVector)
CWrapper.registerType("int_vector_obj", IntVector.createPythonObject)
CWrapper.registerType("int_vector_ref", IntVector.createCReference)

CWrapper.registerType("bool_vector", BoolVector)
CWrapper.registerType("bool_vector_obj", BoolVector.createPythonObject)
CWrapper.registerType("bool_vector_ref", BoolVector.createCReference)

CWrapper.registerType("time_t_vector", TimeVector)
CWrapper.registerType("time_t_vector_obj", TimeVector.createPythonObject)
CWrapper.registerType("time_t_vector_ref", TimeVector.createCReference)


cwrapper = CWrapper(UTIL_LIB)
github equinor / libecl / devel / python / python / ert / util / tvector.py View on Github external
#################################################################

buffer_from_ptr = ctypes.pythonapi.PyBuffer_FromMemory
buffer_from_ptr.restype  = ctypes.py_object
buffer_from_ptr.argtypes = [ ctypes.c_void_p , ctypes.c_long ]

CWrapper.registerType("double_vector", DoubleVector)
CWrapper.registerType("double_vector_obj", DoubleVector.createPythonObject)
CWrapper.registerType("double_vector_ref", DoubleVector.createCReference)

CWrapper.registerType("int_vector", IntVector)
CWrapper.registerType("int_vector_obj", IntVector.createPythonObject)
CWrapper.registerType("int_vector_ref", IntVector.createCReference)

CWrapper.registerType("bool_vector", BoolVector)
CWrapper.registerType("bool_vector_obj", BoolVector.createPythonObject)
CWrapper.registerType("bool_vector_ref", BoolVector.createCReference)

CWrapper.registerType("time_t_vector", TimeVector)
CWrapper.registerType("time_t_vector_obj", TimeVector.createPythonObject)
CWrapper.registerType("time_t_vector_ref", TimeVector.createCReference)


cwrapper = CWrapper(UTIL_LIB)



DoubleVector.cNamespace().alloc            = cwrapper.prototype("c_void_p   double_vector_alloc( int , double )")
DoubleVector.cNamespace().alloc_copy       = cwrapper.prototype("double_vector_obj   double_vector_alloc_copy( double_vector )")
DoubleVector.cNamespace().strided_copy     = cwrapper.prototype("double_vector_obj   double_vector_alloc_strided_copy( double_vector , int , int , int)")
DoubleVector.cNamespace().free             = cwrapper.prototype("void   double_vector_free( double_vector )")
DoubleVector.cNamespace().iget             = cwrapper.prototype("double double_vector_iget( double_vector , int )")
github OPM / ResInsight / ThirdParty / Ert / devel / python / python / ert / util / rng.py View on Github external
return RandomNumberGenerator.cNamespace().get_double(self)


    def getInt(self):
        """ @rtype: float """
        return RandomNumberGenerator.cNamespace().get_int(self)


    def free(self):
        RandomNumberGenerator.cNamespace().free(self)


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

cwrapper = CWrapper(UTIL_LIB)
CWrapper.registerType("rng", RandomNumberGenerator)
CWrapper.registerType("rng_obj", RandomNumberGenerator.createPythonObject)
CWrapper.registerType("rng_ref", RandomNumberGenerator.createCReference)

RandomNumberGenerator.cNamespace().rng_alloc = cwrapper.prototype("c_void_p rng_alloc(rng_alg_type_enum, rng_init_mode_enum)")
RandomNumberGenerator.cNamespace().free = cwrapper.prototype("void rng_free(rng)")
RandomNumberGenerator.cNamespace().get_double = cwrapper.prototype("double rng_get_double(rng)")
RandomNumberGenerator.cNamespace().get_int = cwrapper.prototype("int rng_get_int(rng)")
RandomNumberGenerator.cNamespace().state_size = cwrapper.prototype("int rng_state_size(rng)")
RandomNumberGenerator.cNamespace().set_state = cwrapper.prototype("void rng_set_state(rng , char*)")
github OPM / ResInsight / ThirdParty / Ert / devel / python / python / ert / enkf / node_id.py View on Github external
class NodeId(Structure):
    """
    NodeId is specified in enkf_types.h
    """
    _fields_ = [("report_step", c_int),
                ("iens", c_int)]

    def __init__(self, report_step, realization_number):
        """
        @type report_step: int
        @type realization_number: int
        """
        super(NodeId, self).__init__(report_step, realization_number)


CWrapper.registerType("node_id", NodeId)
github equinor / libecl / devel / python / python / ert / util / tvector.py View on Github external
class TimeVector(TVector):
    default_format = "%d"

    def __init__(self, default_value=0, initial_size=0):
        super(TimeVector, self).__init__(default_value, initial_size)


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

buffer_from_ptr = ctypes.pythonapi.PyBuffer_FromMemory
buffer_from_ptr.restype  = ctypes.py_object
buffer_from_ptr.argtypes = [ ctypes.c_void_p , ctypes.c_long ]

CWrapper.registerType("double_vector", DoubleVector)
CWrapper.registerType("double_vector_obj", DoubleVector.createPythonObject)
CWrapper.registerType("double_vector_ref", DoubleVector.createCReference)

CWrapper.registerType("int_vector", IntVector)
CWrapper.registerType("int_vector_obj", IntVector.createPythonObject)
CWrapper.registerType("int_vector_ref", IntVector.createCReference)

CWrapper.registerType("bool_vector", BoolVector)
CWrapper.registerType("bool_vector_obj", BoolVector.createPythonObject)
CWrapper.registerType("bool_vector_ref", BoolVector.createCReference)

CWrapper.registerType("time_t_vector", TimeVector)
CWrapper.registerType("time_t_vector_obj", TimeVector.createPythonObject)
CWrapper.registerType("time_t_vector_ref", TimeVector.createCReference)
github OPM / ResInsight / ThirdParty / Ert / devel / python / python / ert / util / hash.py View on Github external
else:
            raise ValueError("DoubleHash does not support type: %s" % value.__class__)


    def __getitem__(self, key):
        if key in self:
            return DoubleHash.cNamespace().get_double(self, key)
        else:
            raise KeyError("Hash does not have key: %s" % key)


cwrapper = CWrapper(UTIL_LIB)
CWrapper.registerType("hash", Hash) #c_void_p type
CWrapper.registerType("integer_hash", IntegerHash)
CWrapper.registerType("string_has", StringHash)
CWrapper.registerType("double_hash", DoubleHash)

CWrapper.registerType("hash_obj", Hash.createPythonObject) #c_void_p type
CWrapper.registerType("string_hash_obj", StringHash.createPythonObject)
CWrapper.registerType("integer_hash_obj", IntegerHash.createPythonObject)
CWrapper.registerType("double_hash_obj", DoubleHash.createPythonObject)

CWrapper.registerType("hash_ref", Hash.createCReference) #c_void_p type
CWrapper.registerType("string_hash_ref", StringHash.createCReference)
CWrapper.registerType("integer_hash_ref", IntegerHash.createCReference)
CWrapper.registerType("double_hash_ref", DoubleHash.createCReference)


Hash.cNamespace().alloc = cwrapper.prototype("long hash_alloc()")
Hash.cNamespace().free = cwrapper.prototype("void hash_free(hash)")
Hash.cNamespace().size = cwrapper.prototype("int hash_get_size(hash)")
Hash.cNamespace().keys = cwrapper.prototype("stringlist_obj hash_alloc_stringlist(hash)")
github OPM / ResInsight / ThirdParty / Ert / devel / python / python / ert / util / hash.py View on Github external
def __getitem__(self, key):
        if key in self:
            return DoubleHash.cNamespace().get_double(self, key)
        else:
            raise KeyError("Hash does not have key: %s" % key)


cwrapper = CWrapper(UTIL_LIB)
CWrapper.registerType("hash", Hash) #c_void_p type
CWrapper.registerType("integer_hash", IntegerHash)
CWrapper.registerType("string_has", StringHash)
CWrapper.registerType("double_hash", DoubleHash)

CWrapper.registerType("hash_obj", Hash.createPythonObject) #c_void_p type
CWrapper.registerType("string_hash_obj", StringHash.createPythonObject)
CWrapper.registerType("integer_hash_obj", IntegerHash.createPythonObject)
CWrapper.registerType("double_hash_obj", DoubleHash.createPythonObject)

CWrapper.registerType("hash_ref", Hash.createCReference) #c_void_p type
CWrapper.registerType("string_hash_ref", StringHash.createCReference)
CWrapper.registerType("integer_hash_ref", IntegerHash.createCReference)
CWrapper.registerType("double_hash_ref", DoubleHash.createCReference)


Hash.cNamespace().alloc = cwrapper.prototype("long hash_alloc()")
Hash.cNamespace().free = cwrapper.prototype("void hash_free(hash)")
Hash.cNamespace().size = cwrapper.prototype("int hash_get_size(hash)")
Hash.cNamespace().keys = cwrapper.prototype("stringlist_obj hash_alloc_stringlist(hash)")
Hash.cNamespace().has_key = cwrapper.prototype("bool hash_has_key(hash, char*)")
github OPM / ResInsight / ThirdParty / Ert / devel / python / python / ert / util / hash.py View on Github external
if isinstance(value, float):
            DoubleHash.cNamespace().insert_double(self, key, value)
        else:
            raise ValueError("DoubleHash does not support type: %s" % value.__class__)


    def __getitem__(self, key):
        if key in self:
            return DoubleHash.cNamespace().get_double(self, key)
        else:
            raise KeyError("Hash does not have key: %s" % key)


cwrapper = CWrapper(UTIL_LIB)
CWrapper.registerType("hash", Hash) #c_void_p type
CWrapper.registerType("integer_hash", IntegerHash)
CWrapper.registerType("string_has", StringHash)
CWrapper.registerType("double_hash", DoubleHash)

CWrapper.registerType("hash_obj", Hash.createPythonObject) #c_void_p type
CWrapper.registerType("string_hash_obj", StringHash.createPythonObject)
CWrapper.registerType("integer_hash_obj", IntegerHash.createPythonObject)
CWrapper.registerType("double_hash_obj", DoubleHash.createPythonObject)

CWrapper.registerType("hash_ref", Hash.createCReference) #c_void_p type
CWrapper.registerType("string_hash_ref", StringHash.createCReference)
CWrapper.registerType("integer_hash_ref", IntegerHash.createCReference)
CWrapper.registerType("double_hash_ref", DoubleHash.createCReference)


Hash.cNamespace().alloc = cwrapper.prototype("long hash_alloc()")
Hash.cNamespace().free = cwrapper.prototype("void hash_free(hash)")