Skip to content

Commit

Permalink
uniform csc field names
Browse files Browse the repository at this point in the history
  • Loading branch information
goulart-paul committed Aug 28, 2019
1 parent 38989c6 commit 5e7d7b3
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 23 deletions.
15 changes: 9 additions & 6 deletions algebra/csc_tools/csc_math.h
Expand Up @@ -36,16 +36,15 @@ void csc_update_values(csc *M,
/*****************************************************************************
* CSC Algebraic Operations ******************************************************************************/

//DEBUG : ADD documentation

/* matrix times scalar */

// A = sc*A
void csc_scale(csc* A, c_float sc);

// A = diag(L)*A
void csc_lmult_diag(csc* A, const c_float *L);

// A = A*diag(R)
void csc_rmult_diag(csc* A, const c_float *R);

//y = alpha*A*x + beta*y, where A is symmetric and only triu is stored
void csc_Axpy_sym_triu(const csc *A,
const c_float *x,
Expand All @@ -60,19 +59,23 @@ void csc_Axpy(const csc *A,
c_float alpha,
c_float beta);


//y = alpha*A^T*x + beta*y
void csc_Atxpy(const csc *A,
const c_float *x,
c_float *y,
c_float alpha,
c_float beta);

// returns 1/2 x'*P*x
c_float csc_quad_form(const csc *P, const c_float *x);

// E[i] = inf_norm(M(:,i))
void csc_col_norm_inf(const csc *M, c_float *E);

// E[i] = inf_norm(M(i,:))
void csc_row_norm_inf(const csc *M, c_float *E);

// E[i] = inf_norm(M(i,:)), where M stores triu part only
void csc_row_norm_inf_sym_triu(const csc *M, c_float *E);


Expand Down
4 changes: 2 additions & 2 deletions algebra/default/matrix.c
Expand Up @@ -4,7 +4,7 @@
#include "csc_math.h"
#include "csc_utils.h"

/* logical functions ------------------------------------------------------*/
/* logical test functions ----------------------------------------------------*/

c_int OSQPMatrix_is_eq(OSQPMatrix *A, OSQPMatrix* B, c_float tol){
return (A->symmetry == B->symmetry &&
Expand Down Expand Up @@ -53,7 +53,7 @@ c_int OSQPMatrix_get_n(const OSQPMatrix *M){return M->csc->n;}
c_float* OSQPMatrix_get_x(const OSQPMatrix *M){return M->csc->x;}
c_int* OSQPMatrix_get_i(const OSQPMatrix *M){return M->csc->i;}
c_int* OSQPMatrix_get_p(const OSQPMatrix *M){return M->csc->p;}
c_int OSQPMatrix_get_nnz(const OSQPMatrix *M){return M->csc->p[M->csc->n];}
c_int OSQPMatrix_get_nz(const OSQPMatrix *M){return M->csc->p[M->csc->n];}


/* math functions ----------------------------------------------------------*/
Expand Down
17 changes: 14 additions & 3 deletions include/algebra_matrix.h
Expand Up @@ -33,8 +33,8 @@ OSQPMatrix* OSQPMatrix_new_from_csc(const csc* A, c_int is_triu);

/* direct data access functions ---------------------------------------------*/

/* These functions allow getting/setting data
* in the OSQPMatrix type. Data is passed in/out using bare
/* These functions allow getting data in csc format from the
* the OSQPMatrix type. Data is passed in/out using bare
* pointers instead of OSQPVectors since these functions interface
* with user defined linear solvers and the user API
*/
Expand All @@ -44,12 +44,23 @@ void OSQPMatrix_update_values(OSQPMatrix *M,
const c_int *Mx_new_idx,
c_int M_new_n);

/* returns the row dimension */
c_int OSQPMatrix_get_m(const OSQPMatrix *M);

/* returns the columns dimension */
c_int OSQPMatrix_get_n(const OSQPMatrix *M);

/* returns a pointer to the array of data values */
c_float* OSQPMatrix_get_x(const OSQPMatrix *M);

/* returns a pointer to the array of row indices */
c_int* OSQPMatrix_get_i(const OSQPMatrix *M);

/* returns a pointer to the array of col indices (csc format). Should be n+1 long */
c_int* OSQPMatrix_get_p(const OSQPMatrix *M);
c_int OSQPMatrix_get_nnz(const OSQPMatrix *M);

/* returns the number of nonzeros (length of x and i arrays) */
c_int OSQPMatrix_get_nz(const OSQPMatrix *M);


/* math functions ----------------------------------------------------------*/
Expand Down
6 changes: 4 additions & 2 deletions include/algebra_vector.h
Expand Up @@ -170,7 +170,7 @@ c_float OSQPVectorf_mean(const OSQPVectorf *a);
c_float OSQPVectorf_dot_prod(const OSQPVectorf *a,
const OSQPVectorf *b);

/* Inner product a'b, but using only the positive or Negative
/* Inner product a'b, but using only the positive or negative
* terms in b. Use sign = 1 for positive terms, sign = -1 for
* negative terms. Setting any other value for sign will return
* the normal dot product
Expand All @@ -184,7 +184,9 @@ void OSQPVectorf_ew_prod(OSQPVectorf *c,
const OSQPVectorf *a,
const OSQPVectorf *b);

/* check l <= u elementwise */
/* check l <= u elementwise. Returns 1 if inequality is true
* for every element pair in both vectors
*/
c_int OSQPVectorf_all_leq(OSQPVectorf *l, OSQPVectorf* u);

/* Elementwise bounding vectors x = min(max(z,l),u)
Expand Down
4 changes: 2 additions & 2 deletions lin_sys/direct/pardiso/pardiso_interface.c
Expand Up @@ -137,8 +137,8 @@ c_int init_linsys_solver_pardiso(pardiso_solver ** sp, const OSQPMatrix * P, con
else { // Called from ADMM algorithm

// Allocate vectors of indices
s->PtoKKT = c_malloc(OSQPMatrix_get_nnz(P) * sizeof(c_int));
s->AtoKKT = c_malloc(OSQPMatrix_get_nnz(A) * sizeof(c_int));
s->PtoKKT = c_malloc(OSQPMatrix_get_nz(P) * sizeof(c_int));
s->AtoKKT = c_malloc(OSQPMatrix_get_nz(A) * sizeof(c_int));
s->rhotoKKT = c_malloc(OSQPMatrix_get_m(A) * sizeof(c_int));

// Use s->rho_inv_vec for storing param2 = rho_inv_vec
Expand Down
6 changes: 3 additions & 3 deletions lin_sys/direct/qdldl/qdldl_interface.c
Expand Up @@ -271,8 +271,8 @@ c_int init_linsys_solver_qdldl(qdldl_solver ** sp, const OSQPMatrix* P, const OS
else { // Called from ADMM algorithm

// Allocate vectors of indices
s->PtoKKT = c_malloc(OSQPMatrix_get_nnz(P) * sizeof(c_int));
s->AtoKKT = c_malloc(OSQPMatrix_get_nnz(A) * sizeof(c_int));
s->PtoKKT = c_malloc(OSQPMatrix_get_nz(P) * sizeof(c_int));
s->AtoKKT = c_malloc(OSQPMatrix_get_nz(A) * sizeof(c_int));
s->rhotoKKT = c_malloc(OSQPMatrix_get_m(A) * sizeof(c_int));

// Use p->rho_inv_vec for storing param2 = rho_inv_vec
Expand All @@ -295,7 +295,7 @@ c_int init_linsys_solver_qdldl(qdldl_solver ** sp, const OSQPMatrix* P, const OS

// Permute matrix
if (KKT_temp)
permute_KKT(&KKT_temp, s, OSQPMatrix_get_nnz(P), OSQPMatrix_get_nnz(A), s->m, s->PtoKKT, s->AtoKKT, s->rhotoKKT);
permute_KKT(&KKT_temp, s, OSQPMatrix_get_nz(P), OSQPMatrix_get_nz(A), s->m, s->PtoKKT, s->AtoKKT, s->rhotoKKT);
}

// Check if matrix has been created
Expand Down
8 changes: 4 additions & 4 deletions src/osqp_api.c
Expand Up @@ -1038,7 +1038,7 @@ c_int osqp_update_P(OSQPSolver *solver,
osqp_tic(work->timer); // Start timer
#endif /* ifdef PROFILING */

nnzP = OSQPMatrix_get_nnz(work->data->P);
nnzP = OSQPMatrix_get_nz(work->data->P);

if (Px_new_idx) { // Passing the index of elements changed
// Check if number of elements is less or equal than the total number of
Expand Down Expand Up @@ -1109,7 +1109,7 @@ c_int osqp_update_A(OSQPSolver *solver,
osqp_tic(work->timer); // Start timer
#endif /* ifdef PROFILING */

nnzA = OSQPMatrix_get_nnz(work->data->A);
nnzA = OSQPMatrix_get_nz(work->data->A);

if (Ax_new_idx) { // Passing the index of elements changed
// Check if number of elements is less or equal than the total number of
Expand Down Expand Up @@ -1184,8 +1184,8 @@ c_int osqp_update_P_A(OSQPSolver *solver,
osqp_tic(work->timer); // Start timer
#endif /* ifdef PROFILING */

nnzP = OSQPMatrix_get_nnz(work->data->P);
nnzA = OSQPMatrix_get_nnz(work->data->A);
nnzP = OSQPMatrix_get_nz(work->data->P);
nnzA = OSQPMatrix_get_nz(work->data->A);


if (Px_new_idx) { // Passing the index of elements changed
Expand Down
2 changes: 1 addition & 1 deletion src/util.c
Expand Up @@ -70,7 +70,7 @@ void print_setup_header(const OSQPSolver *solver) {
settings = solver->settings;

// Number of nonzeros
nnz = OSQPMatrix_get_nnz(data->P) + OSQPMatrix_get_nnz(data->A);
nnz = OSQPMatrix_get_nz(data->P) + OSQPMatrix_get_nz(data->A);

print_line();
c_print(" OSQP v%s - Operator Splitting QP Solver\n"
Expand Down

0 comments on commit 5e7d7b3

Please sign in to comment.