Example #1
0
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)
Example #2
0
def attach_operator_projector_ctypes_ccalls(lib, single_precision=False):
	if 'ok_float' not in lib.__dict__:
		attach_base_ctypes(lib, single_precision)
	if 'operator_p' not in lib.__dict__:
		attach_operator_ctypes(lib, single_precision)
	if 'projector_p' not in lib.__dict__:
		attach_projector_ctypes(lib, single_precision)

	ok_float = lib.ok_float
	vector_p = lib.vector_p
	operator_p = lib.operator_p
	projector_p = lib.projector_p

	# types
	class indirect_projector(Structure):
		_fields_ = [('A', operator_p),
					('cgls_work', c_void_p),
					('flag', c_uint)]

	lib.indirect_projector = indirect_projector
	lib.indirect_projector_p = POINTER(lib.indirect_projector)
	indirect_projector_p = lib.indirect_projector_p

	class indirect_projector_generic(Structure):
		_fields_ = [('A', operator_p),
					('cgls_work', c_void_p),
					('linalg_handle', c_void_p),
					('normA', ok_float),
					('normalized', c_int),
					('flag', c_uint)]

	lib.indirect_projector_generic = indirect_projector_generic
	lib.indirect_projector_generic_p = POINTER(lib.indirect_projector_generic)


	# calls
	lib.indirect_projector_alloc.argtypes = [indirect_projector_p, operator_p]
	lib.indirect_projector_initialize.argtypes = [c_void_p,
												  indirect_projector_p, c_int]
	lib.indirect_projector_project.argtypes = [c_void_p, indirect_projector_p,
											   vector_p, vector_p, vector_p,
											   vector_p]
	lib.indirect_projector_free.argtypes = [indirect_projector_p]
	lib.indirect_projector_generic_alloc.argtypes = [operator_p]

	lib.indirect_projector_alloc.restype = c_uint
	lib.indirect_projector_initialize.restype = c_uint
	lib.indirect_projector_project.restype = c_uint
	lib.indirect_projector_free.restype = c_uint
	lib.indirect_projector_generic_alloc.restype = projector_p
Example #3
0
def attach_operator_projector_ctypes_ccalls(lib, single_precision=False):
    if 'ok_float' not in lib.__dict__:
        attach_base_ctypes(lib, single_precision)
    if 'operator_p' not in lib.__dict__:
        attach_operator_ctypes(lib, single_precision)
    if 'projector_p' not in lib.__dict__:
        attach_projector_ctypes(lib, single_precision)

    ok_float = lib.ok_float
    vector_p = lib.vector_p
    operator_p = lib.operator_p
    projector_p = lib.projector_p

    # types
    class indirect_projector(Structure):
        _fields_ = [('A', operator_p), ('cgls_work', c_void_p),
                    ('flag', c_uint)]

    lib.indirect_projector = indirect_projector
    lib.indirect_projector_p = POINTER(lib.indirect_projector)
    indirect_projector_p = lib.indirect_projector_p

    class indirect_projector_generic(Structure):
        _fields_ = [('A', operator_p), ('cgls_work', c_void_p),
                    ('linalg_handle', c_void_p), ('normA', ok_float),
                    ('normalized', c_int), ('flag', c_uint)]

    lib.indirect_projector_generic = indirect_projector_generic
    lib.indirect_projector_generic_p = POINTER(lib.indirect_projector_generic)

    # calls
    lib.indirect_projector_alloc.argtypes = [indirect_projector_p, operator_p]
    lib.indirect_projector_initialize.argtypes = [
        c_void_p, indirect_projector_p, c_int
    ]
    lib.indirect_projector_project.argtypes = [
        c_void_p, indirect_projector_p, vector_p, vector_p, vector_p, vector_p
    ]
    lib.indirect_projector_free.argtypes = [indirect_projector_p]
    lib.indirect_projector_generic_alloc.argtypes = [operator_p]

    lib.indirect_projector_alloc.restype = c_uint
    lib.indirect_projector_initialize.restype = c_uint
    lib.indirect_projector_project.restype = c_uint
    lib.indirect_projector_free.restype = c_uint
    lib.indirect_projector_generic_alloc.restype = projector_p
Example #4
0
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
Example #5
0
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
Example #6
0
File: cg.py Project: bungun/optkit
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