def __init__(self, A, lib, **kwargs): try: self.dense = isinstance(A, ndarray) and len(A.shape) == 2 self.CSC = isinstance(A, csc_matrix) self.CSR = isinstance(A, csr_matrix) assert self.dense or self.CSC or self.CSR self.m = A.shape[0] self.n = A.shape[1] self.A = A self.lib = lib self.wDev = 0 if A.dtype == np.float64: self.double_precision = 1 if A.dtype == np.float32: self.double_precision = 0 # TODO remake all settings self.settings = make_settings(self.double_precision, **kwargs) self.pysolution = Solution(self.double_precision, self.m, self.n) self.solution = make_solution(self.pysolution) self.info = make_info(self.double_precision) self.order = self.lib.ROW_MAJ if (self.CSR or self.dense) \ else self.lib.COL_MAJ if self.dense and not self.double_precision: self.work = self.lib.h2o4gpu_init_dense_single( self.wDev, self.order, self.m, self.n, A) elif self.dense: self.work = self.lib.h2o4gpu_init_dense_double( self.wDev, self.order, self.m, self.n, A) elif not self.double_precision: self.work = self.lib.h2o4gpu_init_sparse_single( self.wDev, self.order, self.m, self.n, A.nnz, A.data, A.indices, A.indptr) else: self.work = self.lib.h2o4gpu_init_sparse_double( self.wDev, self.order, self.m, self.n, A.nnz, A.data, A.indices, A.indptr) except AssertionError: print("Data must be a (m x n) numpy ndarray or scipy csc_matrix " "containing float32 or float64 values")
def __init__(self, A, lib, **kwargs): try: self.dense = isinstance(A, ndarray) and len(A.shape) == 2 self.CSC = isinstance(A, csc_matrix) self.CSR = isinstance(A, csr_matrix) assert self.dense or self.CSC or self.CSR assert A.dtype == c_float or A.dtype == c_double self.m = A.shape[0] self.n = A.shape[1] self.A = A self.lib = lib self.wDev = 0 self.double_precision = A.dtype == c_double self.settings = make_settings(self.double_precision, **kwargs) self.pysolution = Solution(self.double_precision, self.m, self.n) self.solution = make_solution(self.pysolution) self.info = make_info(self.double_precision) self.order = H2OConstants.ROW_MAJ if (self.CSR or self.dense) \ else H2OConstants.COL_MAJ if self.dense and not self.double_precision: self.work = self.lib.h2o4gpu_init_dense_single( self.wDev, self.order, self.m, self.n, cptr(A, c_float)) elif self.dense: self.work = self.lib.h2o4gpu_init_dense_double( self.wDev, self.order, self.m, self.n, cptr(A, c_double)) elif not self.double_precision: self.work = self.lib.h2o4gpu_init_sparse_single( self.wDev, self.order, self.m, self.n, A.nnz, cptr(A.data, c_float), cptr(A.indices, c_int), cptr(A.indptr, c_int)) else: self.work = self.lib.h2o4gpu_init_sparse_double( self.wDev, self.order, self.m, self.n, A.nnz, cptr(A.data, c_double), cptr(A.indices, c_int), cptr(A.indptr, c_int)) except AssertionError: print("Data must be a (m x n) numpy ndarray or scipy csc_matrix " "containing float32 or float64 values")