Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
_copy = UtilPrototype("matrix_obj matrix_alloc_copy(matrix)" )
_sub_copy = UtilPrototype("matrix_obj matrix_alloc_sub_copy(matrix, int , int , int , int)" )
_free = UtilPrototype("void matrix_free(matrix)")
_iget = UtilPrototype("double matrix_iget( matrix , int , int )")
_iset = UtilPrototype("void matrix_iset( matrix , int , int , double)")
_set_all = UtilPrototype("void matrix_scalar_set( matrix , double)")
_scale_column = UtilPrototype("void matrix_scale_column(matrix , int , double)")
_scale_row = UtilPrototype("void matrix_scale_row(matrix , int , double)")
_copy_column = UtilPrototype("void matrix_copy_column(matrix , matrix , int , int)" , bind = False)
_rows = UtilPrototype("int matrix_get_rows(matrix)")
_columns = UtilPrototype("int matrix_get_columns(matrix)")
_equal = UtilPrototype("bool matrix_equal(matrix, matrix)")
_pretty_print = UtilPrototype("void matrix_pretty_print(matrix, char*, char*)")
_fprint = UtilPrototype("void matrix_fprintf(matrix, char*, FILE)")
_random_init = UtilPrototype("void matrix_random_init(matrix, rng)")
_dump_csv = UtilPrototype("void matrix_dump_csv(matrix, char*)")
# Requires BLAS. If the library does not have the
# matrix_alloc_matmul() function the prototype will have _func =
# None, and NotImplementedError( ) will be raised int the
# __call__() method if we try to use this function.
_alloc_matmul = UtilPrototype("matrix_obj matrix_alloc_matmul(matrix, matrix)" , bind = False, allow_attribute_error = True)
# Requires BLAS!
@classmethod
def matmul(cls, m1,m2):
"""
Will return a new matrix which is matrix product of m1 and m2.
"""
if m1.columns( ) == m2.rows( ):
return cls._alloc_matmul( m1, m2)
else:
return self.build_time
def getGitCommit(self, short=False):
if self.git_commit is None:
return "???????"
else:
if short:
return self.git_commit[0:8]
else:
return self.git_commit
class EclVersion(Version):
_build_time = UtilPrototype("char* ecl_version_get_build_time()")
_git_commit = UtilPrototype("char* ecl_version_get_git_commit()")
_major_version = UtilPrototype("int ecl_version_get_major_version()")
_minor_version = UtilPrototype("int ecl_version_get_minor_version()")
_micro_version = UtilPrototype("char* ecl_version_get_micro_version()")
_is_devel = UtilPrototype("bool ecl_version_is_devel_version()")
def __init__(self):
major = self._major_version( )
minor = self._minor_version( )
micro = self._micro_version( )
git_commit = self._git_commit( )
build_time = self._build_time( )
super( EclVersion, self).__init__( major, minor , micro , git_commit, build_time)
from cwrap import BaseCClass,CFILE
from ecl.util import UtilPrototype
class Matrix(BaseCClass):
_matrix_alloc = UtilPrototype("void* matrix_alloc(int, int )" , bind = False)
_matrix_alloc_identity = UtilPrototype("matrix_obj matrix_alloc_identity( int )" , bind = False)
_alloc_transpose = UtilPrototype("matrix_obj matrix_alloc_transpose(matrix)")
_inplace_transpose = UtilPrototype("void matrix_inplace_transpose(matrix)")
_copy = UtilPrototype("matrix_obj matrix_alloc_copy(matrix)" )
_sub_copy = UtilPrototype("matrix_obj matrix_alloc_sub_copy(matrix, int , int , int , int)" )
_free = UtilPrototype("void matrix_free(matrix)")
_iget = UtilPrototype("double matrix_iget( matrix , int , int )")
_iset = UtilPrototype("void matrix_iset( matrix , int , int , double)")
_set_all = UtilPrototype("void matrix_scalar_set( matrix , double)")
_scale_column = UtilPrototype("void matrix_scale_column(matrix , int , double)")
_scale_row = UtilPrototype("void matrix_scale_row(matrix , int , double)")
_copy_column = UtilPrototype("void matrix_copy_column(matrix , matrix , int , int)" , bind = False)
_rows = UtilPrototype("int matrix_get_rows(matrix)")
_columns = UtilPrototype("int matrix_get_columns(matrix)")
_equal = UtilPrototype("bool matrix_equal(matrix, matrix)")
_pretty_print = UtilPrototype("void matrix_pretty_print(matrix, char*, char*)")
_fprint = UtilPrototype("void matrix_fprintf(matrix, char*, FILE)")
_random_init = UtilPrototype("void matrix_random_init(matrix, rng)")
_dump_csv = UtilPrototype("void matrix_dump_csv(matrix, char*)")
# Requires BLAS. If the library does not have the
# matrix_alloc_matmul() function the prototype will have _func =
# None, and NotImplementedError( ) will be raised int the
# __call__() method if we try to use this function.
_alloc_matmul = UtilPrototype("matrix_obj matrix_alloc_matmul(matrix, matrix)" , bind = False, allow_attribute_error = True)
if self.git_commit is None:
return "???????"
else:
if short:
return self.git_commit[0:8]
else:
return self.git_commit
class EclVersion(Version):
_build_time = UtilPrototype("char* ecl_version_get_build_time()")
_git_commit = UtilPrototype("char* ecl_version_get_git_commit()")
_major_version = UtilPrototype("int ecl_version_get_major_version()")
_minor_version = UtilPrototype("int ecl_version_get_minor_version()")
_micro_version = UtilPrototype("char* ecl_version_get_micro_version()")
_is_devel = UtilPrototype("bool ecl_version_is_devel_version()")
def __init__(self):
major = self._major_version( )
minor = self._minor_version( )
micro = self._micro_version( )
git_commit = self._git_commit( )
build_time = self._build_time( )
super( EclVersion, self).__init__( major, minor , micro , git_commit, build_time)
return "?????"
else:
return self.build_time
def getGitCommit(self, short=False):
if self.git_commit is None:
return "???????"
else:
if short:
return self.git_commit[0:8]
else:
return self.git_commit
class EclVersion(Version):
_build_time = UtilPrototype("char* ecl_version_get_build_time()")
_git_commit = UtilPrototype("char* ecl_version_get_git_commit()")
_major_version = UtilPrototype("int ecl_version_get_major_version()")
_minor_version = UtilPrototype("int ecl_version_get_minor_version()")
_micro_version = UtilPrototype("char* ecl_version_get_micro_version()")
_is_devel = UtilPrototype("bool ecl_version_is_devel_version()")
def __init__(self):
major = self._major_version( )
minor = self._minor_version( )
micro = self._micro_version( )
git_commit = self._git_commit( )
build_time = self._build_time( )
super( EclVersion, self).__init__( major, minor , micro , git_commit, build_time)
# expect a matrix instance as input (i.e. the LARS estimator). For
# general linear algebra in Python the numpy library is a natural
# choice.
from cwrap import BaseCClass,CFILE
from ecl.util import UtilPrototype
class Matrix(BaseCClass):
_matrix_alloc = UtilPrototype("void* matrix_alloc(int, int )" , bind = False)
_matrix_alloc_identity = UtilPrototype("matrix_obj matrix_alloc_identity( int )" , bind = False)
_alloc_transpose = UtilPrototype("matrix_obj matrix_alloc_transpose(matrix)")
_inplace_transpose = UtilPrototype("void matrix_inplace_transpose(matrix)")
_copy = UtilPrototype("matrix_obj matrix_alloc_copy(matrix)" )
_sub_copy = UtilPrototype("matrix_obj matrix_alloc_sub_copy(matrix, int , int , int , int)" )
_free = UtilPrototype("void matrix_free(matrix)")
_iget = UtilPrototype("double matrix_iget( matrix , int , int )")
_iset = UtilPrototype("void matrix_iset( matrix , int , int , double)")
_set_all = UtilPrototype("void matrix_scalar_set( matrix , double)")
_scale_column = UtilPrototype("void matrix_scale_column(matrix , int , double)")
_scale_row = UtilPrototype("void matrix_scale_row(matrix , int , double)")
_copy_column = UtilPrototype("void matrix_copy_column(matrix , matrix , int , int)" , bind = False)
_rows = UtilPrototype("int matrix_get_rows(matrix)")
_columns = UtilPrototype("int matrix_get_columns(matrix)")
_equal = UtilPrototype("bool matrix_equal(matrix, matrix)")
_pretty_print = UtilPrototype("void matrix_pretty_print(matrix, char*, char*)")
_fprint = UtilPrototype("void matrix_fprintf(matrix, char*, FILE)")
_random_init = UtilPrototype("void matrix_random_init(matrix, rng)")
_dump_csv = UtilPrototype("void matrix_dump_csv(matrix, char*)")
# Requires BLAS. If the library does not have the
_matrix_alloc_identity = UtilPrototype("matrix_obj matrix_alloc_identity( int )" , bind = False)
_alloc_transpose = UtilPrototype("matrix_obj matrix_alloc_transpose(matrix)")
_inplace_transpose = UtilPrototype("void matrix_inplace_transpose(matrix)")
_copy = UtilPrototype("matrix_obj matrix_alloc_copy(matrix)" )
_sub_copy = UtilPrototype("matrix_obj matrix_alloc_sub_copy(matrix, int , int , int , int)" )
_free = UtilPrototype("void matrix_free(matrix)")
_iget = UtilPrototype("double matrix_iget( matrix , int , int )")
_iset = UtilPrototype("void matrix_iset( matrix , int , int , double)")
_set_all = UtilPrototype("void matrix_scalar_set( matrix , double)")
_scale_column = UtilPrototype("void matrix_scale_column(matrix , int , double)")
_scale_row = UtilPrototype("void matrix_scale_row(matrix , int , double)")
_copy_column = UtilPrototype("void matrix_copy_column(matrix , matrix , int , int)" , bind = False)
_rows = UtilPrototype("int matrix_get_rows(matrix)")
_columns = UtilPrototype("int matrix_get_columns(matrix)")
_equal = UtilPrototype("bool matrix_equal(matrix, matrix)")
_pretty_print = UtilPrototype("void matrix_pretty_print(matrix, char*, char*)")
_fprint = UtilPrototype("void matrix_fprintf(matrix, char*, FILE)")
_random_init = UtilPrototype("void matrix_random_init(matrix, rng)")
_dump_csv = UtilPrototype("void matrix_dump_csv(matrix, char*)")
# Requires BLAS. If the library does not have the
# matrix_alloc_matmul() function the prototype will have _func =
# None, and NotImplementedError( ) will be raised int the
# __call__() method if we try to use this function.
_alloc_matmul = UtilPrototype("matrix_obj matrix_alloc_matmul(matrix, matrix)" , bind = False, allow_attribute_error = True)
# Requires BLAS!
@classmethod
def matmul(cls, m1,m2):
"""
Will return a new matrix which is matrix product of m1 and m2.
"""
# 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 cwrap import BaseCClass
from ecl.util import UtilPrototype
class CThreadPool(BaseCClass):
TYPE_NAME = "thread_pool"
_alloc = UtilPrototype("void* thread_pool_alloc(int, bool)", bind = False)
_free = UtilPrototype("void thread_pool_free(thread_pool)")
_add_job = UtilPrototype("void thread_pool_add_job(thread_pool, void*, void*)")
_join = UtilPrototype("void thread_pool_join(thread_pool)")
def __init__(self, pool_size, start=True):
c_ptr = self._alloc(pool_size, start)
super(CThreadPool, self).__init__(c_ptr)
self.arg_list = []
def addTaskFunction(self, name, lib, c_function_name):
function = CThreadPool.lookupCFunction(lib, c_function_name)
def wrappedFunction(arg):
return self.addTask(function, arg)
setattr(self, name, wrappedFunction)
# See the GNU General Public License at
# for more details.
import ctypes
from cwrap import BaseCClass
from ecl.util import UtilPrototype
class CThreadPool(BaseCClass):
TYPE_NAME = "thread_pool"
_alloc = UtilPrototype("void* thread_pool_alloc(int, bool)", bind = False)
_free = UtilPrototype("void thread_pool_free(thread_pool)")
_add_job = UtilPrototype("void thread_pool_add_job(thread_pool, void*, void*)")
_join = UtilPrototype("void thread_pool_join(thread_pool)")
def __init__(self, pool_size, start=True):
c_ptr = self._alloc(pool_size, start)
super(CThreadPool, self).__init__(c_ptr)
self.arg_list = []
def addTaskFunction(self, name, lib, c_function_name):
function = CThreadPool.lookupCFunction(lib, c_function_name)
def wrappedFunction(arg):
return self.addTask(function, arg)
setattr(self, name, wrappedFunction)
def addTask(self, cfunc, arg):
"""
# 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.
"""
Module with utility functions from util.c
"""
from ecl.util import UtilPrototype
strcmp_int = UtilPrototype("int util_strcmp_int( char* , char* )")
"""
Function to compare strings with embedded integers.
Will use proper numeric comparison when comparing strings with
embedded numbers, i.e. "CASE-9" will follow after "CASE-10" when
sorting:
>> l = ["CASE-9" , "CASE-10"]
>> l.sort()
>> print(l)
["CASE-10" , "CASE-9"]
>> l.sort( strcmp_int )
>> print(l)
["CASE-9" , "CASE-10"]
When the standard strcmp() function is used for comparing strings