def attach_projector_ccalls(lib, single_precision=False): if 'matrix_p' not in lib.__dict__: attach_dense_linsys_ctypes(lib, single_precision) if 'projector_p' not in lib.__dict__: attach_projector_ctypes(lib, single_precision) vector_p = lib.vector_p matrix_p = lib.matrix_p direct_projector_p = lib.direct_projector_p projector_p = lib.projector_p # args: # -direct lib.direct_projector_alloc.argtypes = [direct_projector_p, matrix_p] lib.direct_projector_initialize.argtypes = [ c_void_p, direct_projector_p, c_int ] lib.direct_projector_project.argtypes = [ c_void_p, direct_projector_p, vector_p, vector_p, vector_p, vector_p ] lib.direct_projector_free.argtypes = [direct_projector_p] lib.dense_direct_projector_alloc.argtypes = [matrix_p] # returns: # -direct lib.direct_projector_alloc.restype = c_uint lib.direct_projector_initialize.restype = c_uint lib.direct_projector_project.restype = c_uint lib.direct_projector_free.restype = c_uint lib.dense_direct_projector_alloc.restype = projector_p
def attach_projector_ctypes(lib, single_precision=False): if 'matrix_p' not in lib.__dict__: attach_dense_linsys_ctypes(lib, single_precision) ok_float = lib.ok_float ok_float_p = lib.ok_float_p vector_p = lib.vector_p matrix_p = lib.matrix_p class direct_projector(Structure): _fields_ = [('A', matrix_p), ('L', matrix_p), ('normA', ok_float), ('skinny', c_int), ('normalized', c_int)] lib.direct_projector = direct_projector lib.direct_projector_p = POINTER(lib.direct_projector) class projector(Structure): _fields_ = [('kind', c_uint), ('size1', c_size_t), ('size2', c_size_t), ('data', c_void_p), ('initialize', CFUNCTYPE(c_uint, c_void_p, c_int)), ('project', CFUNCTYPE(c_uint, c_void_p, vector_p, vector_p, vector_p, vector_p, ok_float)), ('free', CFUNCTYPE(c_uint, c_void_p))] lib.projector = projector lib.projector_p = POINTER(lib.projector) class dense_direct_projector(Structure): _fields_ = [('A', matrix_p), ('L', matrix_p), ('linalg_handle', c_void_p), ('normA', ok_float), ('skinny', c_int), ('normalized', c_int)] lib.dense_direct_projector = dense_direct_projector lib.dense_direct_projector_p = POINTER(lib.dense_direct_projector)
def attach_cg_ctypes(lib, single_precision=False): if not 'vector_p' in lib.__dict__: attach_dense_linsys_ctypes(lib, single_precision) ok_float = lib.ok_float vector_p = lib.vector_p class cgls_helper(Structure): _fields_ = [('p', vector_p), ('q', vector_p), ('r', vector_p), ('s', vector_p), ('norm_s', ok_float), ('norm_s0', ok_float), ('norm_x', ok_float), ('xmax', ok_float), ('alpha', ok_float), ('beta', ok_float), ('delta', ok_float), ('gamma', ok_float), ('gamma_prev', ok_float), ('shrink', ok_float), ('blas_handle', c_void_p)] lib.cgls_helper = cgls_helper lib.cgls_helper_p = POINTER(lib.cgls_helper) class pcg_helper(Structure): _fields_ = [('p', vector_p), ('q', vector_p), ('r', vector_p), ('z', vector_p), ('temp', vector_p), ('norm_r', ok_float), ('alpha', ok_float), ('gamma', ok_float), ('gamma_prev', ok_float), ('blas_handle', c_void_p), ('never_solved', c_int)] lib.pcg_helper = pcg_helper lib.pcg_helper_p = POINTER(lib.pcg_helper)
def attach_projector_ccalls(lib, single_precision=False): if 'matrix_p' not in lib.__dict__: attach_dense_linsys_ctypes(lib, single_precision) if 'projector_p' not in lib.__dict__: attach_projector_ctypes(lib, single_precision) vector_p = lib.vector_p matrix_p = lib.matrix_p direct_projector_p = lib.direct_projector_p projector_p = lib.projector_p # args: # -direct lib.direct_projector_alloc.argtypes = [direct_projector_p, matrix_p] lib.direct_projector_initialize.argtypes = [c_void_p, direct_projector_p, c_int] lib.direct_projector_project.argtypes = [c_void_p, direct_projector_p, vector_p, vector_p, vector_p, vector_p] lib.direct_projector_free.argtypes = [direct_projector_p] lib.dense_direct_projector_alloc.argtypes = [matrix_p] # returns: # -direct lib.direct_projector_alloc.restype = c_uint lib.direct_projector_initialize.restype = c_uint lib.direct_projector_project.restype = c_uint lib.direct_projector_free.restype = c_uint lib.dense_direct_projector_alloc.restype = projector_p
def attach_pogs_common_ccalls(lib, single_precision=False): if not 'vector_p' in lib.__dict__: attach_dense_linsys_ctypes(lib, single_precision) if not 'function_vector_p' in lib.__dict__: attach_prox_ctypes(lib, single_precision) if not 'pogs_variables_p' in lib.__dict__: attach_pogs_common_ctypes(lib, single_precision) ok_float = lib.ok_float ok_float_p = lib.ok_float_p vector_p = lib.vector_p function_vector_p = lib.function_vector_p pogs_output_p = lib.pogs_output_p pogs_info_p = lib.pogs_info_p pogs_settings_p = lib.pogs_settings_p adapt_params_p = lib.adapt_params_p block_vector_p = lib.block_vector_p pogs_residuals_p = lib.pogs_residuals_p pogs_tolerances = lib.pogs_tolerances pogs_tolerances_p = lib.pogs_tolerances_p pogs_objectives_p = lib.pogs_objectives_p pogs_variables_p = lib.pogs_variables_p lib.set_default_settings.argtypes = [pogs_settings_p] lib.set_default_settings.restype = c_uint # Private API if lib.full_api_accessible: ## argtypes lib.initialize_conditions.argtypes = [pogs_objectives_p, pogs_residuals_p, pogs_tolerances_p, pogs_settings_p, c_size_t, c_size_t] lib.set_prev.argtypes = [pogs_variables_p] lib.prox.argtypes = [c_void_p, function_vector_p, function_vector_p, pogs_variables_p, ok_float] lib.update_dual.argtypes = [c_void_p, pogs_variables_p, ok_float] lib.adaptrho.argtypes = [pogs_variables_p, pogs_settings_p, ok_float_p, adapt_params_p, pogs_residuals_p, pogs_tolerances_p, c_uint] lib.copy_output.argtypes = [pogs_output_p, pogs_variables_p, vector_p, vector_p, ok_float, c_uint] ## results lib.initialize_conditions.restype = c_uint lib.set_prev.restype = c_uint lib.prox.restype = c_uint lib.update_dual.restype = c_uint lib.adaptrho.restype = c_uint lib.copy_output.restype = c_uint else: lib.initialize_conditions = AttributeError() lib.set_prev = AttributeError() lib.prox = AttributeError() lib.update_dual = AttributeError() lib.adaptrho = AttributeError() lib.copy_output = AttributeError()
def attach_pogs_abstract_ctypes(lib, single_precision=False): if not 'vector_p' in lib.__dict__: attach_dense_linsys_ctypes(lib, single_precision) if not 'function_vector_p' in lib.__dict__: attach_prox_ctypes(lib, single_precision) if not 'operator_p' in lib.__dict__: attach_operator_ctypes(lib, single_precision) if not 'projector_p' in lib.__dict__: attach_projector_ctypes(lib, single_precision) if not 'pogs_settings_p' in lib.__dict__: attach_pogs_common_ctypes(lib, single_precision) ok_float = lib.ok_float vector_p = lib.vector_p function_vector_p = lib.function_vector_p operator_p = lib.operator_p projector_p = lib.projector_p pogs_settings_p = lib.pogs_settings_p pogs_variables_p = lib.pogs_variables_p # lib properties lib.private_api_accessible.restype = c_int lib.full_api_accessible = lib.private_api_accessible() class PogsWork(Structure): _fields_ = [('A', operator_p), ('P', projector_p), ('d', vector_p), ('e', vector_p), ('operator_scale', CFUNCTYPE(c_uint, operator_p, ok_float)), ('operator_equilibrate', CFUNCTYPE(c_uint, c_void_p, operator_p, vector_p, vector_p, ok_float)), ('normA', ok_float), ('skinny', c_int), ('normalized', c_int), ('equilibrated', c_int)] lib.pogs_work = PogsWork lib.pogs_work_p = POINTER(lib.pogs_work) class PogsSolver(Structure): _fields_ = [('W', lib.pogs_work_p), ('z', pogs_variables_p), ('f', function_vector_p), ('g', function_vector_p), ('rho', ok_float), ('settings', pogs_settings_p), ('linalg_handle', c_void_p), ('init_time', ok_float)] lib.pogs_solver = PogsSolver lib.pogs_solver_p = POINTER(lib.pogs_solver)
def attach_equilibration_ccalls(lib, single_precision=False): if not 'matrix_p' in lib.__dict__: attach_dense_linsys_ctypes(lib, single_precision) ok_float_p = lib.ok_float_p vector_p = lib.vector_p matrix_p = lib.matrix_p # argument types lib.regularized_sinkhorn_knopp.argtypes = [c_void_p, ok_float_p, matrix_p, vector_p, vector_p, c_uint] # return types lib.regularized_sinkhorn_knopp.restype = c_uint
def attach_prox_ccalls(lib, single_precision=False): if not 'vector_p' in lib.__dict__: attach_dense_linsys_ctypes(lib, single_precision) if not 'function_vector_p' in lib.__dict__: attach_prox_ctypes(lib, single_precision) ok_float = lib.ok_float ok_float_p = lib.ok_float_p vector_p = lib.vector_p function_p = lib.function_p function_vector_p = lib.function_vector_p # Function Vector # ------ ## arguments lib.function_vector_alloc.argtypes = [function_vector_p, c_size_t] lib.function_vector_calloc.argtypes = [function_vector_p, c_size_t] lib.function_vector_free.argtypes = [function_vector_p] lib.function_vector_memcpy_va.argtypes = [function_vector_p, function_p] lib.function_vector_memcpy_av.argtypes = [function_p, function_vector_p] lib.function_vector_mul.argtypes = [function_vector_p, vector_p] lib.function_vector_div.argtypes = [function_vector_p, vector_p] lib.function_vector_print.argtypes = [function_vector_p] ## return values lib.function_vector_alloc.restype = c_uint lib.function_vector_calloc.restype = c_uint lib.function_vector_free.restype = c_uint lib.function_vector_memcpy_va.restype = c_uint lib.function_vector_memcpy_av.restype = c_uint lib.function_vector_mul.restype = c_uint lib.function_vector_div.restype = c_uint lib.function_vector_print.restype = c_uint # Prox & Function evaluation # -------------------------- ## arguments lib.prox_eval_vector.argtypes = [ function_vector_p, ok_float, vector_p, vector_p ] lib.function_eval_vector.argtypes = [ function_vector_p, vector_p, ok_float_p ] ## return values lib.prox_eval_vector.restype = c_uint lib.function_eval_vector.restype = c_uint
def attach_pogs_ctypes(lib, single_precision=False): if not 'matrix_p' in lib.__dict__: attach_dense_linsys_ctypes(lib, single_precision) if not 'function_vector_p' in lib.__dict__: attach_prox_ctypes(lib, single_precision) if not 'pogs_settings_p' in lib.__dict__: print("HERE") attach_pogs_common_ctypes(lib, single_precision) ok_float = lib.ok_float vector_p = lib.vector_p matrix_p = lib.matrix_p function_vector_p = lib.function_vector_p pogs_settings_p = lib.pogs_settings_p pogs_variables_p = lib.pogs_variables_p # lib properties full_api_accessible = lib.full_api_accessible lib.is_direct.restype = c_int lib.direct = lib.is_direct() class PogsMatrix(Structure): _fields_ = [('A', matrix_p), ('P', c_void_p), ('d', vector_p), ('e', vector_p), ('normA', ok_float), ('skinny', c_int), ('normalized', c_int), ('equilibrated', c_int)] lib.pogs_matrix = PogsMatrix lib.pogs_matrix_p = POINTER(lib.pogs_matrix) pogs_matrix_p = lib.pogs_matrix_p class PogsSolver(Structure): _fields_ = [('M', pogs_matrix_p), ('z', pogs_variables_p), ('f', function_vector_p), ('g', function_vector_p), ('rho', ok_float), ('settings', pogs_settings_p), ('linalg_handle', c_void_p), ('init_time', ok_float)] lib.pogs_solver = PogsSolver lib.pogs_solver_p = POINTER(lib.pogs_solver)
def attach_prox_ccalls(lib, single_precision=False): if not 'vector_p' in lib.__dict__: attach_dense_linsys_ctypes(lib, single_precision) if not 'function_vector_p' in lib.__dict__: attach_prox_ctypes(lib, single_precision) ok_float = lib.ok_float ok_float_p = lib.ok_float_p vector_p = lib.vector_p function_p = lib.function_p function_vector_p = lib.function_vector_p # Function Vector # ------ ## arguments lib.function_vector_alloc.argtypes = [function_vector_p, c_size_t] lib.function_vector_calloc.argtypes = [function_vector_p, c_size_t] lib.function_vector_free.argtypes = [function_vector_p] lib.function_vector_memcpy_va.argtypes = [function_vector_p, function_p] lib.function_vector_memcpy_av.argtypes = [function_p, function_vector_p] lib.function_vector_mul.argtypes = [function_vector_p, vector_p] lib.function_vector_div.argtypes = [function_vector_p, vector_p] lib.function_vector_print.argtypes = [function_vector_p] ## return values lib.function_vector_alloc.restype = c_uint lib.function_vector_calloc.restype = c_uint lib.function_vector_free.restype = c_uint lib.function_vector_memcpy_va.restype = c_uint lib.function_vector_memcpy_av.restype = c_uint lib.function_vector_mul.restype = c_uint lib.function_vector_div.restype = c_uint lib.function_vector_print.restype = c_uint # Prox & Function evaluation # -------------------------- ## arguments lib.prox_eval_vector.argtypes = [function_vector_p, ok_float, vector_p, vector_p] lib.function_eval_vector.argtypes = [function_vector_p, vector_p, ok_float_p] ## return values lib.prox_eval_vector.restype = c_uint lib.function_eval_vector.restype = c_uint
def attach_projector_ctypes(lib, single_precision=False): if 'matrix_p' not in lib.__dict__: attach_dense_linsys_ctypes(lib, single_precision) ok_float = lib.ok_float ok_float_p = lib.ok_float_p vector_p = lib.vector_p matrix_p = lib.matrix_p class direct_projector(Structure): _fields_ = [('A', matrix_p), ('L', matrix_p), ('normA', ok_float), ('skinny', c_int), ('normalized', c_int)] lib.direct_projector = direct_projector lib.direct_projector_p = POINTER(lib.direct_projector) class projector(Structure): _fields_ = [('kind', c_uint), ('size1', c_size_t), ('size2', c_size_t), ('data', c_void_p), ('initialize', CFUNCTYPE(c_uint, c_void_p, c_int)), ('project', CFUNCTYPE(c_uint, c_void_p, vector_p, vector_p, vector_p, vector_p, ok_float)), ('free', CFUNCTYPE(c_uint, c_void_p))] lib.projector = projector lib.projector_p = POINTER(lib.projector) class dense_direct_projector(Structure): _fields_ = [('A', matrix_p), ('L', matrix_p), ('linalg_handle', c_void_p), ('normA', ok_float), ('skinny', c_int), ('normalized', c_int)] lib.dense_direct_projector = dense_direct_projector lib.dense_direct_projector_p = POINTER(lib.dense_direct_projector)
def attach_cg_ctypes(lib, single_precision=False): if not 'vector_p' in lib.__dict__: attach_dense_linsys_ctypes(lib, single_precision) ok_float = lib.ok_float vector_p = lib.vector_p class cgls_helper(Structure): _fields_ = [('p', vector_p), ('q', vector_p), ('r', vector_p), ('s', vector_p), ('norm_s', ok_float), ('norm_s0', ok_float), ('norm_x', ok_float), ('xmax', ok_float), ('alpha', ok_float), ('beta', ok_float), ('delta', ok_float), ('gamma', ok_float), ('gamma_prev', ok_float), ('shrink', ok_float), ('blas_handle', c_void_p)] lib.cgls_helper = cgls_helper lib.cgls_helper_p = POINTER(lib.cgls_helper) class pcg_helper(Structure): _fields_ = [('p', vector_p), ('q', vector_p), ('r', vector_p), ('z', vector_p), ('temp', vector_p), ('norm_r', ok_float), ('alpha', ok_float), ('gamma', ok_float), ('gamma_prev', ok_float), ('blas_handle', c_void_p), ('never_solved', c_int)] lib.pcg_helper = pcg_helper lib.pcg_helper_p = POINTER(lib.pcg_helper)
def attach_operator_equilibration_ccalls(lib, single_precision=False): if not 'vector_p' in lib.__dict__: attach_dense_linsys_ctypes(lib, single_precision) if not 'operator_p' in lib.__dict__: attach_operator_ctypes(lib, single_precision) ok_float = lib.ok_float vector_p = lib.vector_p operator_p = lib.operator_p # argument types lib.operator_regularized_sinkhorn.argtypes = [c_void_p, operator_p, vector_p, vector_p, ok_float] lib.operator_equilibrate.argtypes = [c_void_p, operator_p, vector_p, vector_p, ok_float] lib.operator_estimate_norm.argtypes = [c_void_p, operator_p] # return types lib.operator_regularized_sinkhorn.restype = c_uint lib.operator_equilibrate.restype = c_uint lib.operator_estimate_norm.restype = c_uint
def attach_operator_ctypes(lib, single_precision=False): if not 'vector_p' in lib.__dict__: attach_dense_linsys_ctypes(lib, single_precision) ok_float = lib.ok_float vector_p = lib.vector_p class ok_operator(Structure): _fields_ = [('size1', c_size_t), ('size2', c_size_t), ('data', c_void_p), ('apply', CFUNCTYPE(c_uint, c_void_p, vector_p, vector_p)), ('adjoint', CFUNCTYPE(c_uint, c_void_p,vector_p, vector_p)), ('fused_apply', CFUNCTYPE(c_uint, c_void_p, ok_float, vector_p, ok_float, vector_p)), ('fused_adjoint', CFUNCTYPE(c_uint, c_void_p, ok_float, vector_p, ok_float, vector_p)), ('free', CFUNCTYPE(c_uint, c_void_p)), ('kind', c_uint)] lib.operator = ok_operator lib.operator_p = POINTER(lib.operator)
def attach_cg_ccalls(lib, single_precision=False): if not 'vector_p' in lib.__dict__: attach_dense_linsys_ctypes(lib, single_precision) if not 'operator_p' in lib.__dict__: attach_operator_ctypes(lib, single_precision) if not 'cgls_helper_p' in lib.__dict__: attach_cg_ctypes(lib, single_precision) ok_float = lib.ok_float vector_p = lib.vector_p operator_p = lib.operator_p cgls_helper_p = lib.cgls_helper_p pcg_helper_p = lib.pcg_helper_p c_uint_p = POINTER(c_uint) # argument types lib.cgls_helper_alloc.argtypes = [c_size_t, c_size_t] lib.cgls_helper_free.argtypes = [cgls_helper_p] lib.cgls_nonallocating.argtypes = [ cgls_helper_p, operator_p, vector_p, vector_p, ok_float, ok_float, c_size_t, c_int, c_uint_p ] lib.cgls.argtypes = [ operator_p, vector_p, vector_p, ok_float, ok_float, c_size_t, c_int, c_uint_p ] lib.cgls_init.argtypes = [c_size_t, c_size_t] lib.cgls_solve.argtypes = [ c_void_p, operator_p, vector_p, vector_p, ok_float, ok_float, c_size_t, c_int, c_uint_p ] lib.cgls_finish.argtypes = [c_void_p] lib.CGLS_MAXFLAG = 4 lib.pcg_helper_alloc.argtypes = [c_size_t, c_size_t] lib.pcg_helper_free.argtypes = [pcg_helper_p] lib.diagonal_preconditioner.argtypes = [operator_p, vector_p, ok_float] lib.pcg_nonallocating.argtypes = [ pcg_helper_p, operator_p, operator_p, vector_p, vector_p, ok_float, ok_float, c_size_t, c_int, c_uint_p ] lib.pcg.argtypes = [ operator_p, operator_p, vector_p, vector_p, ok_float, ok_float, c_size_t, c_int, c_uint_p ] lib.pcg_init.argtypes = [c_size_t, c_size_t] lib.pcg_solve.argtypes = [ c_void_p, operator_p, operator_p, vector_p, vector_p, ok_float, ok_float, c_size_t, c_int, c_uint_p ] lib.pcg_finish.argtypes = [c_void_p] # return types lib.cgls_helper_alloc.restype = cgls_helper_p lib.cgls_helper_free.retype = c_uint lib.cgls_nonallocating.restype = c_uint lib.cgls.restype = c_uint lib.cgls_init.restype = c_void_p lib.cgls_solve.restype = c_uint lib.cgls_finish.restype = c_uint lib.pcg_helper_alloc.restype = pcg_helper_p lib.pcg_helper_free.retype = c_uint lib.diagonal_preconditioner.restype = c_uint lib.pcg_nonallocating.restype = c_uint lib.pcg.restype = c_uint lib.pcg_init.restype = c_void_p lib.pcg_solve.restype = c_uint lib.pcg_finish.restype = c_uint
def attach_cg_ccalls(lib, single_precision=False): if not 'vector_p' in lib.__dict__: attach_dense_linsys_ctypes(lib, single_precision) if not 'operator_p' in lib.__dict__: attach_operator_ctypes(lib, single_precision) if not 'cgls_helper_p' in lib.__dict__: attach_cg_ctypes(lib, single_precision) ok_float = lib.ok_float vector_p = lib.vector_p operator_p = lib.operator_p cgls_helper_p = lib.cgls_helper_p pcg_helper_p = lib.pcg_helper_p c_uint_p = POINTER(c_uint) # argument types lib.cgls_helper_alloc.argtypes = [c_size_t, c_size_t] lib.cgls_helper_free.argtypes = [cgls_helper_p] lib.cgls_nonallocating.argtypes = [cgls_helper_p, operator_p, vector_p, vector_p, ok_float, ok_float, c_size_t, c_int, c_uint_p] lib.cgls.argtypes = [operator_p, vector_p, vector_p, ok_float, ok_float, c_size_t, c_int, c_uint_p] lib.cgls_init.argtypes = [c_size_t, c_size_t] lib.cgls_solve.argtypes = [c_void_p, operator_p, vector_p, vector_p, ok_float, ok_float, c_size_t, c_int, c_uint_p] lib.cgls_finish.argtypes = [c_void_p] lib.CGLS_MAXFLAG = 4; lib.pcg_helper_alloc.argtypes = [c_size_t, c_size_t] lib.pcg_helper_free.argtypes = [pcg_helper_p] lib.diagonal_preconditioner.argtypes = [operator_p, vector_p, ok_float] lib.pcg_nonallocating.argtypes = [pcg_helper_p, operator_p, operator_p, vector_p, vector_p, ok_float, ok_float, c_size_t, c_int, c_uint_p] lib.pcg.argtypes = [operator_p, operator_p, vector_p, vector_p, ok_float, ok_float, c_size_t, c_int, c_uint_p] lib.pcg_init.argtypes = [c_size_t, c_size_t] lib.pcg_solve.argtypes = [c_void_p, operator_p, operator_p, vector_p, vector_p, ok_float, ok_float, c_size_t, c_int, c_uint_p] lib.pcg_finish.argtypes = [c_void_p] # return types lib.cgls_helper_alloc.restype = cgls_helper_p lib.cgls_helper_free.retype = c_uint lib.cgls_nonallocating.restype = c_uint lib.cgls.restype = c_uint lib.cgls_init.restype = c_void_p lib.cgls_solve.restype = c_uint lib.cgls_finish.restype = c_uint lib.pcg_helper_alloc.restype = pcg_helper_p lib.pcg_helper_free.retype = c_uint lib.diagonal_preconditioner.restype = c_uint lib.pcg_nonallocating.restype = c_uint lib.pcg.restype = c_uint lib.pcg_init.restype = c_void_p lib.pcg_solve.restype = c_uint lib.pcg_finish.restype = c_uint
def attach_pogs_ccalls(lib, single_precision=False): if not 'vector_p' in lib.__dict__: attach_dense_linsys_ctypes(lib, single_precision) if not 'function_vector_p' in lib.__dict__: attach_prox_ctypes(lib, single_precision) if not 'pogs_solver_p' in lib.__dict__: attach_pogs_ctypes(lib, single_precision) ok_float = lib.ok_float ok_float_p = lib.ok_float_p vector_p = lib.vector_p function_vector_p = lib.function_vector_p pogs_output_p = lib.pogs_output_p pogs_info_p = lib.pogs_info_p pogs_settings_p = lib.pogs_settings_p adapt_params_p = lib.adapt_params_p block_vector_p = lib.block_vector_p pogs_residuals_p = lib.pogs_residuals_p pogs_tolerances = lib.pogs_tolerances pogs_tolerances_p = lib.pogs_tolerances_p pogs_objectives_p = lib.pogs_objectives_p pogs_matrix_p = lib.pogs_matrix_p pogs_variables_p = lib.pogs_variables_p pogs_solver_p = lib.pogs_solver_p ## arguments lib.pogs_init.argtypes = [ok_float_p, c_size_t, c_size_t, c_uint] lib.pogs_solve.argtypes = [c_void_p, function_vector_p, function_vector_p, pogs_settings_p, pogs_info_p, pogs_output_p] lib.pogs_finish.argtypes = [c_void_p, c_int] lib.pogs.argtypes = [ok_float_p, function_vector_p, function_vector_p, pogs_settings_p, pogs_info_p, pogs_output_p, c_uint, c_int] lib.pogs_load_solver.argtypes = [ok_float_p, ok_float_p, ok_float_p, ok_float_p, ok_float_p, ok_float_p, ok_float_p, ok_float_p, ok_float_p, ok_float, c_size_t, c_size_t, c_uint] lib.pogs_extract_solver.argtypes = [c_void_p, ok_float_p, ok_float_p, ok_float_p, ok_float_p, ok_float_p, ok_float_p, ok_float_p, ok_float_p, ok_float_p, ok_float_p, c_uint] ## return types lib.pogs_init.restype = pogs_solver_p lib.pogs_solve.restype = c_uint lib.pogs_finish.restype = c_uint lib.pogs.restype = c_uint lib.pogs_load_solver.restype = pogs_solver_p lib.pogs_extract_solver.restype = c_uint # Private API if lib.full_api_accessible: ## argtypes lib.update_problem.argtypes = [pogs_solver_p, function_vector_p, function_vector_p] lib.initialize_variables.argtypes = [pogs_solver_p] lib.pogs_solver_loop.argtypes = [pogs_solver_p, pogs_info_p] lib.project_primal.argtypes = [c_void_p, c_void_p, pogs_variables_p, ok_float] lib.check_convergence.argtypes = [c_void_p, pogs_solver_p, pogs_objectives_p, pogs_residuals_p, pogs_tolerances_p] ## results lib.update_problem.restype = c_uint lib.initialize_variables.restype = c_uint lib.pogs_solver_loop.restype = c_uint lib.project_primal.restype = c_uint lib.check_convergence.restype = c_int proj_argtypes = [c_void_p, c_void_p, vector_p, vector_p, vector_p, vector_p] proj_restype = c_uint if lib.direct: lib.direct_projector_project.argtypes = proj_argtypes lib.direct_projector_project.restype = proj_restype else: lib.indirect_projector_project.argtypes = proj_argtypes lib.indirect_projector_project.restype = proj_restype else: lib.update_problem = AttributeError() lib.initialize_variables = AttributeError() lib.pogs_solver_loop = AttributeError() lib.project_primal = AttributeError() lib.check_convergence = AttributeError() lib.direct_projector_project = AttributeError() lib.indirect_projector_project = AttributeError()
def attach_clustering_ccalls(lib, single_precision=False): if not 'matrix_p' in lib.__dict__: attach_dense_linsys_ctypes(lib, single_precision) if not 'kmeans_work_p' in lib.__dict__: attach_cluster_ctypes(lib, single_precision) ok_float = lib.ok_float ok_float_p = lib.ok_float_p c_size_t_p = lib.c_size_t_p indvector = lib.indvector vector_p = lib.vector_p matrix_p = lib.matrix_p upsamplingvec_p = lib.upsamplingvec_p cluster_aid_p = lib.cluster_aid_p kmeans_work_p = lib.kmeans_work_p kmeans_settings_p = lib.kmeans_settings_p kmeans_io_p = lib.kmeans_io_p # argument types lib.upsamplingvec_alloc.argtypes = [upsamplingvec_p, c_size_t, c_size_t] lib.upsamplingvec_free.argtypes = [upsamplingvec_p] lib.upsamplingvec_check_bounds.argtypes = [upsamplingvec_p] lib.upsamplingvec_update_size.argtypes = [upsamplingvec_p] lib.upsamplingvec_subvector.argtypes = [upsamplingvec_p, upsamplingvec_p, c_size_t, c_size_t, c_size_t] lib.upsamplingvec_mul_matrix.argtypes = [c_void_p, c_uint, c_uint, c_uint, ok_float, upsamplingvec_p, matrix_p, ok_float, matrix_p] lib.upsamplingvec_count.argtypes = [upsamplingvec_p, vector_p] lib.cluster_aid_alloc.argtypes = [cluster_aid_p, c_size_t, c_size_t, c_uint] lib.cluster_aid_free.argtypes = [cluster_aid_p] lib.kmeans_work_alloc.argtypes = [kmeans_work_p, c_size_t, c_size_t, c_size_t] lib.kmeans_work_free.argtypes = [kmeans_work_p] lib.kmeans_work_subselect.argtypes = [kmeans_work_p, c_size_t, c_size_t, c_size_t] lib.kmeans_work_load.argtypes = [kmeans_work_p, ok_float_p, c_uint, ok_float_p, c_uint, c_size_t_p, c_size_t, ok_float_p, c_size_t] lib.kmeans_work_extract.argtypes = [ok_float_p, c_uint, c_size_t_p, c_size_t, ok_float_p, c_size_t, kmeans_work_p] lib.cluster.argtypes = [matrix_p, matrix_p, upsamplingvec_p, cluster_aid_p, ok_float] lib.calculate_centroids.argtypes = [matrix_p, matrix_p, upsamplingvec_p, vector_p, cluster_aid_p] lib.k_means.argtypes = [matrix_p, matrix_p, upsamplingvec_p, vector_p, cluster_aid_p, ok_float, c_size_t, c_size_t, c_uint] lib.kmeans_easy_init.argtypes = [c_size_t, c_size_t, c_size_t] lib.kmeans_easy_resize.argtypes = [c_void_p, c_size_t, c_size_t, c_size_t] lib.kmeans_easy_run.argtypes = [c_void_p, kmeans_settings_p, kmeans_io_p] lib.kmeans_easy_finish.argtypes = [c_void_p] # return types lib.upsamplingvec_alloc.restype = c_uint lib.upsamplingvec_free.restype = c_uint lib.upsamplingvec_check_bounds.restype = c_uint lib.upsamplingvec_update_size.restype = c_uint lib.upsamplingvec_subvector.restype = c_uint lib.upsamplingvec_mul_matrix.restype = c_uint lib.upsamplingvec_count.restype = c_uint lib.cluster_aid_alloc.restype = c_uint lib.cluster_aid_free.restype = c_uint lib.kmeans_work_alloc.restype = c_uint lib.kmeans_work_free.restype = c_uint lib.kmeans_work_subselect.restype = c_uint lib.kmeans_work_load.restype = c_uint lib.kmeans_work_extract.restype = c_uint lib.cluster.restype = c_uint lib.calculate_centroids.restype = c_uint lib.k_means.restype = c_uint lib.kmeans_easy_init.restype = c_void_p lib.kmeans_easy_resize.restype = c_uint lib.kmeans_easy_run.restype = c_uint lib.kmeans_easy_finish.restype = c_uint
def attach_pogs_common_ctypes(lib, single_precision=False): if not 'vector_p' in lib.__dict__: attach_dense_linsys_ctypes(lib, single_precision) ok_float = lib.ok_float ok_float_p = lib.ok_float_p vector_p = lib.vector_p # lib properties lib.private_api_accessible.restype = c_int lib.full_api_accessible = lib.private_api_accessible() # Public API class PogsSettings(Structure): _fields_ = [('alpha', ok_float), ('rho', ok_float), ('abstol', ok_float), ('reltol', ok_float), ('maxiter', c_uint), ('verbose', c_uint), ('suppress', c_uint), ('adaptiverho', c_int), ('gapstop', c_int), ('warmstart', c_int), ('resume', c_int), ('x0', ok_float_p), ('nu0', ok_float_p)] lib.pogs_settings = PogsSettings lib.pogs_settings_p = POINTER(lib.pogs_settings) class PogsInfo(Structure): _fields_ = [('err', c_int), ('converged', c_int), ('k', c_uint), ('obj', ok_float), ('rho', ok_float), ('setup_time', ok_float), ('solve_time', ok_float)] def __init__(self): self.err = 0 self.converged = 0 self.k = 0 self.obj = nan self.rho = nan self.setup_time = nan self.solve_time = nan lib.pogs_info = PogsInfo lib.pogs_info_p = POINTER(lib.pogs_info) class PogsOutput(Structure): _fields_ = [('x', ok_float_p), ('y', ok_float_p), ('mu', ok_float_p), ('nu', ok_float_p)] lib.pogs_output = PogsOutput lib.pogs_output_p = POINTER(lib.pogs_output) class AdaptiveRhoParameters(Structure): _fields_ = [('delta', ok_float), ('l', ok_float), ('u', ok_float), ('xi', ok_float)] lib.adapt_params = AdaptiveRhoParameters lib.adapt_params_p = POINTER(lib.adapt_params) class PogsBlockVector(Structure): _fields_ = [('size', c_size_t), ('m', c_size_t), ('n', c_size_t), ('x', vector_p), ('y', vector_p), ('vec', vector_p)] lib.block_vector = PogsBlockVector lib.block_vector_p = POINTER(lib.block_vector) block_vector_p = lib.block_vector_p class PogsResiduals(Structure): _fields_ = [('primal', ok_float), ('dual', ok_float), ('gap', ok_float)] def __init__(self): self.primal = nan self.dual = nan self.gap = nan lib.pogs_residuals = PogsResiduals lib.pogs_residuals_p = POINTER(lib.pogs_residuals) class PogsTolerances(Structure): _fields_ = [('primal', ok_float), ('dual', ok_float), ('gap', ok_float), ('reltol', ok_float), ('abstol', ok_float), ('atolm', ok_float), ('atoln', ok_float), ('atolmn', ok_float)] lib.pogs_tolerances = PogsTolerances lib.pogs_tolerances_p = POINTER(lib.pogs_tolerances) class PogsObjectives(Structure): _fields_ = [('primal', ok_float), ('dual', ok_float), ('gap', ok_float)] def __init__(self): self.primal = nan self.dual = nan self.gap = nan lib.pogs_objectives = PogsObjectives lib.pogs_objectives_p = POINTER(lib.pogs_objectives) class PogsVariables(Structure): _fields_ = [('primal', block_vector_p), ('primal12', block_vector_p), ('dual', block_vector_p), ('dual12', block_vector_p), ('prev', block_vector_p), ('temp', block_vector_p), ('m', c_size_t), ('n', c_size_t)] lib.pogs_variables = PogsVariables lib.pogs_variables_p = POINTER(lib.pogs_variables)
def attach_clustering_ctypes(lib, single_precision=False): if not 'matrix' in lib.__dict__: attach_dense_linsys_ctypes(lib, single_precision) ok_float = lib.ok_float ok_float_p = lib.ok_float_p c_size_t_p = lib.c_size_t_p vector = lib.vector indvector = lib.indvector matrix = lib.matrix matrix_p = lib.matrix_p class upsamplingvec(Structure): _fields_ = [('size1', c_size_t), ('size2', c_size_t), ('stride', c_size_t), ('indices', c_size_t_p), ('vec', indvector)] lib.upsamplingvec = upsamplingvec lib.upsamplingvec_p = POINTER(lib.upsamplingvec) class cluster_aid(Structure): _fields_ = [('indicator', POINTER(c_int)), ('hdl', c_void_p), ('a2c_tentative_full', upsamplingvec), ('a2c_tentative', upsamplingvec), ('d_min_full', vector), ('d_min', vector), ('c_squared_full', vector), ('c_squared', vector), ('D_full', matrix), ('D', matrix), ('A_reducible', matrix), ('reassigned', c_size_t)] lib.cluster_aid = cluster_aid lib.cluster_aid_p = POINTER(lib.cluster_aid) class kmeans_work(Structure): _fields_ = [('indicator', POINTER(c_int)), ('n_vectors', c_size_t), ('n_clusters', c_size_t), ('vec_length', c_size_t), ('A', matrix), ('C', matrix), ('a2c', upsamplingvec), ('counts', vector), ('h', cluster_aid)] lib.kmeans_work = kmeans_work lib.kmeans_work_p = POINTER(lib.kmeans_work) class kmeans_settings(Structure): _fields_ = [('dist_reltol', ok_float), ('change_abstol', c_size_t), ('maxiter', c_size_t), ('verbose', c_uint)] lib.kmeans_settings = kmeans_settings lib.kmeans_settings_p = POINTER(lib.kmeans_settings) class kmeans_io(Structure): _fields_ = [('A', ok_float_p), ('C', ok_float_p), ('counts', ok_float_p), ('a2c', c_size_t_p), ('orderA', c_uint), ('orderC', c_uint), ('stride_a2c', c_uint), ('stride_counts', c_size_t)] lib.kmeans_io = kmeans_io lib.kmeans_io_p = POINTER(lib.kmeans_io)