How to use the ert.util.UtilPrototype 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 Ensembles / ert / devel / python / python / ert / util / version.py View on Github external
def cmp_method(method):
    def cmp_wrapper(self, other):
        if not isinstance(other, Version):
            other = Version(other[0], other[1], other[2])

        return method(self, other)

    return cmp_wrapper


class Version(object):
    _build_time = UtilPrototype("char* version_get_build_time()")
    _git_commit = UtilPrototype("char* version_get_git_commit()")
    _git_commit_short = UtilPrototype("char* version_get_git_commit_short()")
    _major_version = UtilPrototype("int version_get_major_ert_version()")
    _minor_version = UtilPrototype("int version_get_minor_ert_version()")
    _micro_version = UtilPrototype("char* version_get_micro_ert_version()")
    _is_devel = UtilPrototype("bool version_is_ert_devel_version()")

    def __init__(self, major, minor, micro):
        self.major = major
        self.minor = minor
        self.micro = micro
        try:
            self.micro_int = int(micro)
            self.is_devel = False
        except ValueError:
            self.micro_int = -1
            self.is_devel = True

    def isDevelVersion(self):
        return self.is_devel
github OPM / ResInsight / ThirdParty / Ert / python / python / ert / util / bool_vector.py View on Github external
#  See the GNU General Public License at  
#  for more details. 


import warnings

from ert.util import VectorTemplate, UtilPrototype


class BoolVector(VectorTemplate):
    default_format       = "%8d"

    _alloc               = UtilPrototype("void*  bool_vector_alloc( int , bool )" , bind = False)
    _create_active_mask  = UtilPrototype("bool_vector_obj string_util_alloc_active_mask( char* )" , bind = False)
    _active_list         = UtilPrototype("int_vector_obj bool_vector_alloc_active_list(bool_vector)", bind = False)
    _alloc_copy          = UtilPrototype("bool_vector_obj bool_vector_alloc_copy( bool_vector )")
    _update_active_mask  = UtilPrototype("bool string_util_update_active_mask(char*, bool_vector)" , bind = False)

    _strided_copy        = UtilPrototype("bool_vector_obj bool_vector_alloc_strided_copy( bool_vector , int , int , int)")
    _free                = UtilPrototype("void   bool_vector_free( bool_vector )")
    _iget                = UtilPrototype("bool   bool_vector_iget( bool_vector , int )")
    _safe_iget           = UtilPrototype("bool   bool_vector_safe_iget( bool_vector , int )")
    _iset                = UtilPrototype("void   bool_vector_iset( bool_vector , int , bool)")
    _size                = UtilPrototype("int    bool_vector_size( bool_vector )")
    _append              = UtilPrototype("void   bool_vector_append( bool_vector , bool )")
    _idel_block          = UtilPrototype("void   bool_vector_idel_block( bool_vector , bool , bool )")
    _idel                = UtilPrototype("void   bool_vector_idel( bool_vector , int )")
    _pop                 = UtilPrototype("bool   bool_vector_pop( bool_vector )")
    _lshift              = UtilPrototype("void   bool_vector_lshift( bool_vector , int )")
    _rshift              = UtilPrototype("void   bool_vector_rshift( bool_vector , int )")
    _insert              = UtilPrototype("void   bool_vector_insert( bool_vector , int , bool)")
    _fprintf             = UtilPrototype("void   bool_vector_fprintf( bool_vector , FILE , char* , char*)")
github Ensembles / ert / devel / python / python / ert / util / int_vector.py View on Github external
#   
#  See the GNU General Public License at  
#  for more details. 

from ert.util import VectorTemplate, UtilPrototype


class IntVector(VectorTemplate):
    default_format       = "%d"

    _alloc               = UtilPrototype("void*  int_vector_alloc( int , int )" , bind = False)
    _create_active_list  = UtilPrototype("int_vector_obj string_util_alloc_active_list( char*)" , bind = False)
    _create_value_list   = UtilPrototype("int_vector_obj string_util_alloc_value_list( char*)" , bind = False)
    _alloc_copy          = UtilPrototype("int_vector_obj int_vector_alloc_copy( int_vector )")
    _strided_copy        = UtilPrototype("int_vector_obj int_vector_alloc_strided_copy( int_vector , int , int , int)")
    _free                = UtilPrototype("void   int_vector_free( int_vector )")
    _iget                = UtilPrototype("int    int_vector_iget( int_vector , int )")
    _safe_iget           = UtilPrototype("int    int_vector_safe_iget( int_vector , int )")
    _iset                = UtilPrototype("int    int_vector_iset( int_vector , int , int)")
    _size                = UtilPrototype("int    int_vector_size( int_vector )")
    _append              = UtilPrototype("void   int_vector_append( int_vector , int )")
    _idel_block          = UtilPrototype("void   int_vector_idel_block( int_vector , int , int )")
    _pop                 = UtilPrototype("int    int_vector_pop( int_vector )")
    _idel                = UtilPrototype("void   int_vector_idel( int_vector , int )")
    _insert              = UtilPrototype("void   int_vector_insert( int_vector , int , int)")
    _lshift              = UtilPrototype("void   int_vector_lshift( int_vector , int )")
    _rshift              = UtilPrototype("void   int_vector_rshift( int_vector , int )")
    _fprintf             = UtilPrototype("void   int_vector_fprintf( int_vector , FILE , char* , char*)")
    _sort                = UtilPrototype("void   int_vector_sort( int_vector )")
    _rsort               = UtilPrototype("void   int_vector_rsort( int_vector )")
    _reset               = UtilPrototype("void   int_vector_reset( int_vector )")
    _set_read_only       = UtilPrototype("void   int_vector_set_read_only( int_vector , bool )")
github OPM / ResInsight / ThirdParty / Ert / python / python / ert / util / bool_vector.py View on Github external
from ert.util import VectorTemplate, UtilPrototype


class BoolVector(VectorTemplate):
    default_format       = "%8d"

    _alloc               = UtilPrototype("void*  bool_vector_alloc( int , bool )" , bind = False)
    _create_active_mask  = UtilPrototype("bool_vector_obj string_util_alloc_active_mask( char* )" , bind = False)
    _active_list         = UtilPrototype("int_vector_obj bool_vector_alloc_active_list(bool_vector)", bind = False)
    _alloc_copy          = UtilPrototype("bool_vector_obj bool_vector_alloc_copy( bool_vector )")
    _update_active_mask  = UtilPrototype("bool string_util_update_active_mask(char*, bool_vector)" , bind = False)

    _strided_copy        = UtilPrototype("bool_vector_obj bool_vector_alloc_strided_copy( bool_vector , int , int , int)")
    _free                = UtilPrototype("void   bool_vector_free( bool_vector )")
    _iget                = UtilPrototype("bool   bool_vector_iget( bool_vector , int )")
    _safe_iget           = UtilPrototype("bool   bool_vector_safe_iget( bool_vector , int )")
    _iset                = UtilPrototype("void   bool_vector_iset( bool_vector , int , bool)")
    _size                = UtilPrototype("int    bool_vector_size( bool_vector )")
    _append              = UtilPrototype("void   bool_vector_append( bool_vector , bool )")
    _idel_block          = UtilPrototype("void   bool_vector_idel_block( bool_vector , bool , bool )")
    _idel                = UtilPrototype("void   bool_vector_idel( bool_vector , int )")
    _pop                 = UtilPrototype("bool   bool_vector_pop( bool_vector )")
    _lshift              = UtilPrototype("void   bool_vector_lshift( bool_vector , int )")
    _rshift              = UtilPrototype("void   bool_vector_rshift( bool_vector , int )")
    _insert              = UtilPrototype("void   bool_vector_insert( bool_vector , int , bool)")
    _fprintf             = UtilPrototype("void   bool_vector_fprintf( bool_vector , FILE , char* , char*)")
    _sort                = UtilPrototype("void   bool_vector_sort( bool_vector )")
    _rsort               = UtilPrototype("void   bool_vector_rsort( bool_vector )")
    _reset               = UtilPrototype("void   bool_vector_reset( bool_vector )")
    _set_read_only       = UtilPrototype("void   bool_vector_set_read_only( bool_vector , bool )")
    _get_read_only       = UtilPrototype("bool   bool_vector_get_read_only( bool_vector )")
github Ensembles / ert / devel / python / python / ert / util / time_vector.py View on Github external
_pop                 = UtilPrototype("time_t   time_t_vector_pop( time_t_vector )")
    _lshift              = UtilPrototype("void     time_t_vector_lshift( time_t_vector , int )")
    _rshift              = UtilPrototype("void     time_t_vector_rshift( time_t_vector , int )")
    _insert              = UtilPrototype("void     time_t_vector_insert( time_t_vector , int , time_t)")
    _fprintf             = UtilPrototype("void     time_t_vector_fprintf( time_t_vector , FILE , char* , char*)")
    _sort                = UtilPrototype("void     time_t_vector_sort( time_t_vector )")
    _rsort               = UtilPrototype("void     time_t_vector_rsort( time_t_vector )")
    _reset               = UtilPrototype("void     time_t_vector_reset( time_t_vector )")
    _set_read_only       = UtilPrototype("void     time_t_vector_set_read_only( time_t_vector , bool )")
    _get_read_only       = UtilPrototype("bool     time_t_vector_get_read_only( time_t_vector )")
    _get_max             = UtilPrototype("time_t   time_t_vector_get_max( time_t_vector )")
    _get_min             = UtilPrototype("time_t   time_t_vector_get_min( time_t_vector )")
    _get_max_index       = UtilPrototype("int      time_t_vector_get_max_index( time_t_vector , bool)")
    _get_min_index       = UtilPrototype("int      time_t_vector_get_min_index( time_t_vector , bool)")
    _shift               = UtilPrototype("void     time_t_vector_shift( time_t_vector , time_t )")
    _scale               = UtilPrototype("void     time_t_vector_scale( time_t_vector , time_t )")
    _div                 = UtilPrototype("void     time_t_vector_div( time_t_vector , time_t )")
    _inplace_add         = UtilPrototype("void     time_t_vector_inplace_add( time_t_vector , time_t_vector )")
    _inplace_mul         = UtilPrototype("void     time_t_vector_inplace_mul( time_t_vector , time_t_vector )")
    _assign              = UtilPrototype("void     time_t_vector_set_all( time_t_vector , time_t)")
    _memcpy              = UtilPrototype("void     time_t_vector_memcpy(time_t_vector , time_t_vector )")
    _set_default         = UtilPrototype("void     time_t_vector_set_default( time_t_vector , time_t)")
    _get_default         = UtilPrototype("time_t   time_t_vector_get_default( time_t_vector )")
    _element_size        = UtilPrototype("int      time_t_vector_element_size( time_t_vector )")

    _permute             = UtilPrototype("void time_t_vector_permute(time_t_vector, permutation_vector)")
    _sort_perm           = UtilPrototype("permutation_vector_obj time_t_vector_alloc_sort_perm(time_t_vector)")
    _rsort_perm          = UtilPrototype("permutation_vector_obj time_t_vector_alloc_rsort_perm(time_t_vector)")
    _contains            = UtilPrototype("bool time_t_vector_contains(time_t_vector, time_t)")
    _select_unique       = UtilPrototype("void time_t_vector_select_unique(time_t_vector)")
    _element_sum         = UtilPrototype("time_t time_t_vector_sum(time_t_vector)")
    _count_equal         = UtilPrototype("int time_t_vector_count_equal(time_t_vector, time_t)")
github Ensembles / ert / devel / python / python / ert / util / stringlist.py View on Github external
from ert.cwrap import BaseCClass


class StringList(BaseCClass):
    TYPE_NAME = "stringlist"

    _alloc      = UtilPrototype("void* stringlist_alloc_new( )", bind = False)
    _free       = UtilPrototype("void stringlist_free(stringlist )")
    _append     = UtilPrototype("void stringlist_append_copy(stringlist , char* )")
    _iget       = UtilPrototype("char* stringlist_iget(stringlist , int )")
    _front      = UtilPrototype("char* stringlist_front( stringlist )")
    _back       = UtilPrototype("char* stringlist_back( stringlist )")
    _iget_copy  = UtilPrototype("char* stringlist_iget_copy(stringlist, int)")
    _iset       = UtilPrototype("void  stringlist_iset_copy( stringlist , int , char* )")
    _get_size   = UtilPrototype("int  stringlist_get_size( stringlist )")
    _contains   = UtilPrototype("bool stringlist_contains(stringlist , char*)")
    _equal      = UtilPrototype("bool stringlist_equal(stringlist , stringlist)")
    _sort       = UtilPrototype("void stringlist_python_sort( stringlist , int)")
    _pop        = UtilPrototype("char* stringlist_pop(stringlist)")
    _last       = UtilPrototype("char* stringlist_get_last(stringlist)")
    _find_first = UtilPrototype("int stringlist_find_first(stringlist, char*)")

    def __init__(self, initial=None):
        """
        Creates a new stringlist instance.
        
        Creates a new stringlist instance. The optional argument
        @initial should be an iterable of strings which will be the
        initial content of the StringList; the content will be copied
        from the initial list:

            S = StringList( initial = ["My" , "name" , "is", "John" , "Doe"] )
github Ensembles / ert / devel / python / python / ert / util / substitution_list.py View on Github external
from ert.cwrap import BaseCClass
from ert.util import UtilPrototype


class SubstitutionList(BaseCClass):
    TYPE_NAME = "subst_list"

    _alloc = UtilPrototype("void* subst_list_alloc(void*)" , bind = False)
    _free = UtilPrototype("void subst_list_free(subst_list)")
    _size = UtilPrototype("int subst_list_get_size(subst_list)")
    _get_key = UtilPrototype("char* subst_list_iget_key(subst_list, int)")
    _get_value = UtilPrototype("char* subst_list_iget_value(subst_list, int)")
    _get_doc_string = UtilPrototype("char* subst_list_iget_doc_string(subst_list, int)")
    _append_copy = UtilPrototype("void subst_list_append_copy(subst_list, char*, char*, char*)")

    def __init__(self):
        c_ptr = self._alloc(0)
        super(SubstitutionList, self).__init__(c_ptr)

    def __len__(self):
        return self._size()

    def addItem(self, key, value, doc_string=""):
        self._append_copy(key, value, doc_string)

    def __getitem__(self, index_or_key):
        if not isinstance(index_or_key, int):
github Ensembles / ert / devel / python / python / ert / util / cstring.py View on Github external
#  the Free Software Foundation, either version 3 of the License, or 
#  (at your option) any later version. 
#   
#  ERT is distributed in the hope that it will be useful, but WITHOUT ANY 
#  WARRANTY; without even the implied warranty of MERCHANTABILITY or 
#  FITNESS FOR A PARTICULAR PURPOSE.   
#   
#  See the GNU General Public License at  
#  for more details. 


import ctypes

from ert.util import UtilPrototype

_free = UtilPrototype("void free(void*)")


def cStringObject(c_ptr):
    """The cStringObject function is a convenience function which creates a
    Python string copy, and discards the underlying C allocated storage
    for strings created with *alloc() functions in C.

    This function should not be invoked directly, only indirectly
    through the prototyping of the symbol 'cstring_obj'.

    """
    if c_ptr is not None:
        python_string = ctypes.c_char_p(c_ptr).value
        _free(c_ptr)
        return python_string
    else:
github Ensembles / ert / devel / python / python / ert / util / hash.py View on Github external
def __setitem__(self, key, value):
        if isinstance(value, str):
            self._insert_string(key, value)
        else:
            raise ValueError("StringHash does not support type: %s" % value.__class__)

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


class IntegerHash(Hash):
    _get_int = UtilPrototype("int hash_get_int(hash, char*)")
    _insert_int = UtilPrototype("void hash_insert_int(hash, char*, int)")

    def __init__(self):
        super(IntegerHash, self).__init__()

    def __setitem__(self, key, value):
        if isinstance(value, int):
            self._insert_int(key, value)
        else:
            raise ValueError("IntegerHash does not support type: %s" % value.__class__)

    def __getitem__(self, key):
        if key in self:
            return self._get_int(key)
        else:
            raise KeyError("Hash does not have key: %s" % key)
github Ensembles / ert / devel / python / python / ert / util / int_vector.py View on Github external
#  for more details. 

from ert.util import VectorTemplate, UtilPrototype


class IntVector(VectorTemplate):
    default_format       = "%d"

    _alloc               = UtilPrototype("void*  int_vector_alloc( int , int )" , bind = False)
    _create_active_list  = UtilPrototype("int_vector_obj string_util_alloc_active_list( char*)" , bind = False)
    _create_value_list   = UtilPrototype("int_vector_obj string_util_alloc_value_list( char*)" , bind = False)
    _alloc_copy          = UtilPrototype("int_vector_obj int_vector_alloc_copy( int_vector )")
    _strided_copy        = UtilPrototype("int_vector_obj int_vector_alloc_strided_copy( int_vector , int , int , int)")
    _free                = UtilPrototype("void   int_vector_free( int_vector )")
    _iget                = UtilPrototype("int    int_vector_iget( int_vector , int )")
    _safe_iget           = UtilPrototype("int    int_vector_safe_iget( int_vector , int )")
    _iset                = UtilPrototype("int    int_vector_iset( int_vector , int , int)")
    _size                = UtilPrototype("int    int_vector_size( int_vector )")
    _append              = UtilPrototype("void   int_vector_append( int_vector , int )")
    _idel_block          = UtilPrototype("void   int_vector_idel_block( int_vector , int , int )")
    _pop                 = UtilPrototype("int    int_vector_pop( int_vector )")
    _idel                = UtilPrototype("void   int_vector_idel( int_vector , int )")
    _insert              = UtilPrototype("void   int_vector_insert( int_vector , int , int)")
    _lshift              = UtilPrototype("void   int_vector_lshift( int_vector , int )")
    _rshift              = UtilPrototype("void   int_vector_rshift( int_vector , int )")
    _fprintf             = UtilPrototype("void   int_vector_fprintf( int_vector , FILE , char* , char*)")
    _sort                = UtilPrototype("void   int_vector_sort( int_vector )")
    _rsort               = UtilPrototype("void   int_vector_rsort( int_vector )")
    _reset               = UtilPrototype("void   int_vector_reset( int_vector )")
    _set_read_only       = UtilPrototype("void   int_vector_set_read_only( int_vector , bool )")
    _get_read_only       = UtilPrototype("bool   int_vector_get_read_only( int_vector )")
    _get_max             = UtilPrototype("int    int_vector_get_max( int_vector )")