Exemple #1
0
    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
            assert lib and (lib == pogsCPU or lib == pogsGPU)

            self.m = A.shape[0]
            self.n = A.shape[1]
            self.A = A
            self.lib = lib

            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 = ORD["ROW_MAJ"] if (self.CSR
                                            or self.dense) else ORD["COL_MAJ"]

            if self.dense and not self.double_precision:
                self.work = self.lib.pogs_init_dense_single(
                    self.order, self.m, self.n, cptr(A, c_float))
            elif self.dense:
                self.work = self.lib.pogs_init_dense_double(
                    self.order, self.m, self.n, cptr(A, c_double))
            elif not self.double_precision:
                self.work = self.lib.pogs_init_sparse_single(
                    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.pogs_init_sparse_double(
                    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"
Exemple #2
0
    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
            assert lib and (lib == pogsCPU or lib == pogsGPU)

            self.m = A.shape[0]
            self.n = A.shape[1]
            self.A = A
            self.lib = lib

            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 = ORD["ROW_MAJ"] if (self.CSR or self.dense) else ORD["COL_MAJ"]

            if self.dense and not self.double_precision:
                self.work = self.lib.pogs_init_dense_single(self.order, self.m, self.n, cptr(A, c_float))
            elif self.dense:
                self.work = self.lib.pogs_init_dense_double(self.order, self.m, self.n, cptr(A, c_double))
            elif not self.double_precision:
                self.work = self.lib.pogs_init_sparse_single(
                    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.pogs_init_sparse_double(
                    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"
Exemple #3
0
    def solve(self, f, g, **kwargs):
        try:
            # assert f,g types
            assert isinstance(f, FunctionVector)
            assert isinstance(g, FunctionVector)

            # assert f,g lengths
            assert f.length() == self.m
            assert g.length() == self.n

            # pass previous rho through, if not first run (rho=0)
            if self.info.rho > 0:
                self.settings.rho = self.info.rho

            # apply user inputs
            change_settings(self.settings, **kwargs)
            change_solution(self.pysolution, **kwargs)

            if not self.work:
                print "no viable POGS_work pointer to call solve(). call Solver.init( args... ) first"
                return
            elif not self.double_precision:
                self.lib.pogs_solve_single(self.work, pointer(self.settings),
                                           pointer(self.solution),
                                           pointer(self.info),
                                           cptr(f.a, c_float),
                                           cptr(f.b, c_float),
                                           cptr(f.c, c_float),
                                           cptr(f.d, c_float),
                                           cptr(f.e,
                                                c_float), cptr(f.h, c_int),
                                           cptr(g.a, c_float),
                                           cptr(g.b, c_float),
                                           cptr(g.c, c_float),
                                           cptr(g.d, c_float),
                                           cptr(g.e, c_float),
                                           cptr(g.h, c_int))
            else:
                self.lib.pogs_solve_double(self.work, pointer(self.settings),
                                           pointer(self.solution),
                                           pointer(self.info),
                                           cptr(f.a, c_double),
                                           cptr(f.b, c_double),
                                           cptr(f.c, c_double),
                                           cptr(f.d, c_double),
                                           cptr(f.e,
                                                c_double), cptr(f.h, c_int),
                                           cptr(g.a, c_double),
                                           cptr(g.b, c_double),
                                           cptr(g.c, c_double),
                                           cptr(g.d, c_double),
                                           cptr(g.e, c_double),
                                           cptr(g.h, c_int))

        except AssertionError:
            print "\nf and g must be objects of type FunctionVector with:"
            print ">length of f = m, # of rows in solver's data matrix A"
            print ">length of g = n, # of columns in solver's data matrix A"
Exemple #4
0
    def solve(self, f, g, **kwargs):
        try:
            # assert f,g types
            assert isinstance(f, FunctionVector)
            assert isinstance(g, FunctionVector)

            # assert f,g lengths
            assert f.length() == self.m
            assert g.length() == self.n

            # pass previous rho through, if not first run (rho=0)
            if self.info.rho > 0:
                self.settings.rho = self.info.rho

                # apply user inputs
            change_settings(self.settings, **kwargs)
            change_solution(self.pysolution, **kwargs)

            if not self.work:
                print "no viable POGS_work pointer to call solve(). call Solver.init( args... ) first"
                return
            elif not self.double_precision:
                self.lib.pogs_solve_single(
                    self.work,
                    pointer(self.settings),
                    pointer(self.solution),
                    pointer(self.info),
                    cptr(f.a, c_float),
                    cptr(f.b, c_float),
                    cptr(f.c, c_float),
                    cptr(f.d, c_float),
                    cptr(f.e, c_float),
                    cptr(f.h, c_int),
                    cptr(g.a, c_float),
                    cptr(g.b, c_float),
                    cptr(g.c, c_float),
                    cptr(g.d, c_float),
                    cptr(g.e, c_float),
                    cptr(g.h, c_int),
                )
            else:
                self.lib.pogs_solve_double(
                    self.work,
                    pointer(self.settings),
                    pointer(self.solution),
                    pointer(self.info),
                    cptr(f.a, c_double),
                    cptr(f.b, c_double),
                    cptr(f.c, c_double),
                    cptr(f.d, c_double),
                    cptr(f.e, c_double),
                    cptr(f.h, c_int),
                    cptr(g.a, c_double),
                    cptr(g.b, c_double),
                    cptr(g.c, c_double),
                    cptr(g.d, c_double),
                    cptr(g.e, c_double),
                    cptr(g.h, c_int),
                )

        except AssertionError:
            print "\nf and g must be objects of type FunctionVector with:"
            print ">length of f = m, # of rows in solver's data matrix A"
            print ">length of g = n, # of columns in solver's data matrix A"