Skip to content

Commit

Permalink
Format code
Browse files Browse the repository at this point in the history
  • Loading branch information
gaviny82 committed Aug 13, 2023
1 parent 4e49456 commit 186d06a
Show file tree
Hide file tree
Showing 18 changed files with 827 additions and 875 deletions.
6 changes: 4 additions & 2 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Language: Cpp

# Breaks
ColumnLimit: 0
ColumnLimit: 120
BreakBeforeBraces: Custom
BraceWrapping:
AfterClass: true
Expand All @@ -12,7 +12,9 @@ BraceWrapping:
AfterNamespace: true
AfterStruct: true
AfterUnion: true

BinPackParameters: false
AlwaysBreakTemplateDeclarations: Yes
AlignAfterOpenBracket: BlockIndent

# Indentation
IndentWidth: 4
Expand Down
12 changes: 4 additions & 8 deletions examples/c/example_expcone.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ int main(void)
{
// 3 x 3 zero matrix
ClarabelCscMatrix P;
clarabel_CscMatrix_init(&P,
clarabel_CscMatrix_init(
&P,
3, // row
3, // col
(uintptr_t[]){ 0, 0, 0, 0 }, // colptr
Expand Down Expand Up @@ -36,11 +37,7 @@ int main(void)

ClarabelFloat b[5] = { 0., 0., 0., 1., exp(5.0) };

ClarabelSupportedConeT cones[2] =
{
ClarabelExponentialConeT(),
ClarabelZeroConeT(2)
};
ClarabelSupportedConeT cones[2] = { ClarabelExponentialConeT(), ClarabelZeroConeT(2) };

// Settings
ClarabelDefaultSettings settings = clarabel_DefaultSettings_default();
Expand All @@ -53,8 +50,7 @@ int main(void)
&A, // A
b, // b
2, // n_cones
cones,
&settings
cones, &settings
);

// Solve
Expand Down
8 changes: 2 additions & 6 deletions examples/c/example_lp.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ int main(void)

ClarabelFloat b[4] = { 1.0, 1.0, 1.0, 1.0 };

ClarabelSupportedConeT cones[1] =
{
ClarabelNonnegativeConeT(4)
};
ClarabelSupportedConeT cones[1] = { ClarabelNonnegativeConeT(4) };

// Settings
ClarabelDefaultSettings settings = clarabel_DefaultSettings_default();
Expand All @@ -48,8 +45,7 @@ int main(void)
&A, // A
b, // b
1, // n_cones
cones,
&settings
cones, &settings
);

// Solve
Expand Down
30 changes: 12 additions & 18 deletions examples/c/example_powcone.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ int main(void)
ClarabelFloat q[6] = { 0., 0., -1., 0., 0., -1. };

/* From dense matrix:
* [[-1., 0., 0., 0., 0., 0.],
* [0., -1., 0., 0., 0., 0.],
* [0., 0., -1., 0., 0., 0.],
* [0., 0., 0., -1., 0., 0.],
* [0., 0., 0., 0., -1., 0.],
* [0., 0., 0., 0., 0., -1.],
* [1., 2., 0., 3., 0., 0.],
* [0., 0., 0., 0., 1., 0.]]
*/
* [[-1., 0., 0., 0., 0., 0.],
* [0., -1., 0., 0., 0., 0.],
* [0., 0., -1., 0., 0., 0.],
* [0., 0., 0., -1., 0., 0.],
* [0., 0., 0., 0., -1., 0.],
* [0., 0., 0., 0., 0., -1.],
* [1., 2., 0., 3., 0., 0.],
* [0., 0., 0., 0., 1., 0.]]
*/
ClarabelCscMatrix A;
clarabel_CscMatrix_init(
&A,
Expand All @@ -51,13 +51,8 @@ int main(void)

ClarabelFloat b[8] = { 0., 0., 0., 0., 0., 0., 3., 1. };

ClarabelSupportedConeT cones[4] =
{
ClarabelPowerConeT(0.6),
ClarabelPowerConeT(0.1),
ClarabelZeroConeT(1),
ClarabelZeroConeT(1)
};
ClarabelSupportedConeT cones[4] = { ClarabelPowerConeT(0.6), ClarabelPowerConeT(0.1), ClarabelZeroConeT(1),
ClarabelZeroConeT(1) };

// Settings
ClarabelDefaultSettings settings = clarabel_DefaultSettings_default();
Expand All @@ -71,8 +66,7 @@ int main(void)
&A, // A
b, // b
4, // n_cones
cones,
&settings
cones, &settings
);

// Solve
Expand Down
9 changes: 2 additions & 7 deletions examples/c/example_qp.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,7 @@ int main(void)

ClarabelFloat b[5] = { 0., 1., 1., 1., 1. };

ClarabelSupportedConeT cones[2] =
{
ClarabelZeroConeT(1),
ClarabelNonnegativeConeT(4)
};
ClarabelSupportedConeT cones[2] = { ClarabelZeroConeT(1), ClarabelNonnegativeConeT(4) };

// Settings
ClarabelDefaultSettings settings = clarabel_DefaultSettings_default();
Expand All @@ -60,8 +56,7 @@ int main(void)
&A, // A
b, // b
2, // n_cones
cones,
&settings
cones, &settings
);

// Solve
Expand Down
9 changes: 2 additions & 7 deletions examples/c/example_qp_f32.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,7 @@ int main(void)

float b[5] = { 0., 1., 1., 1., 1. };

ClarabelSupportedConeT_f32 cones[2] =
{
ClarabelZeroConeT_f32(1),
ClarabelNonnegativeConeT_f32(4)
};
ClarabelSupportedConeT_f32 cones[2] = { ClarabelZeroConeT_f32(1), ClarabelNonnegativeConeT_f32(4) };

// Settings
ClarabelDefaultSettings_f32 settings = clarabel_DefaultSettings_f32_default();
Expand All @@ -57,8 +53,7 @@ int main(void)
&A, // A
b, // b
2, // n_cones
cones,
&settings
cones, &settings
);

// Solve
Expand Down
9 changes: 2 additions & 7 deletions examples/c/example_qp_f64.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,7 @@ int main(void)

double b[5] = { 0., 1., 1., 1., 1. };

ClarabelSupportedConeT_f64 cones[2] =
{
ClarabelZeroConeT_f64(1),
ClarabelNonnegativeConeT_f64(4)
};
ClarabelSupportedConeT_f64 cones[2] = { ClarabelZeroConeT_f64(1), ClarabelNonnegativeConeT_f64(4) };

// Settings
ClarabelDefaultSettings_f64 settings = clarabel_DefaultSettings_f64_default();
Expand All @@ -57,8 +53,7 @@ int main(void)
&A, // A
b, // b
2, // n_cones
cones,
&settings
cones, &settings
);

// Solve
Expand Down
14 changes: 6 additions & 8 deletions examples/c/example_sdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ int main(void)
ClarabelCscMatrix P;
clarabel_CscMatrix_init(
&P,
nvec, // row
nvec, // col
nvec, // row
nvec, // col
(uintptr_t[]){ 0, 0, 0, 0, 0, 0, 0 }, // colptr
NULL, // rowval
NULL // nzval
Expand All @@ -44,15 +44,14 @@ int main(void)
&A,
7, // row
6, // col
(uintptr_t[]){0, 2, 4, 6, 8, 10, 12}, // colptr
(uintptr_t[]){0, 6, 1, 6, 2, 6, 3, 6, 4, 6, 5, 6}, // rowval
(uintptr_t[]){ 0, 2, 4, 6, 8, 10, 12 }, // colptr
(uintptr_t[]){ 0, 6, 1, 6, 2, 6, 3, 6, 4, 6, 5, 6 }, // rowval
(ClarabelFloat[]){ -1.0, 1.0, -sqrt2, 4.0, -1.0, 3.0, -sqrt2, 8.0, -sqrt2, 10.0, -1.0, 6.0 } // nzval
);

ClarabelFloat b[7] = { 0., 0., 0., 0., 0., 0., 1. };

ClarabelSupportedConeT cones[2] =
{
ClarabelSupportedConeT cones[2] = {
ClarabelPSDTriangleConeT(n),
ClarabelZeroConeT(1),
};
Expand All @@ -67,8 +66,7 @@ int main(void)
&A, // A
b, // b
2, // n_cones
cones,
&settings
cones, &settings
);

// Solve
Expand Down
8 changes: 2 additions & 6 deletions examples/c/example_socp.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@ int main(void)

ClarabelFloat b[3] = { 1., -2., -2. };

ClarabelSupportedConeT cones[1] =
{
ClarabelSecondOrderConeT(3)
};
ClarabelSupportedConeT cones[1] = { ClarabelSecondOrderConeT(3) };

// Settings
ClarabelDefaultSettings settings = clarabel_DefaultSettings_default();
Expand All @@ -54,8 +51,7 @@ int main(void)
&A, // A
b, // b
1, // n_cones
cones,
&settings
cones, &settings
);

// Solve
Expand Down
1 change: 1 addition & 0 deletions examples/c/utils.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "utils.h"

#include <stdio.h>

// f64
Expand Down
39 changes: 18 additions & 21 deletions include/c/CscMatrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,35 +58,32 @@ typedef ClarabelCscMatrix_f64 ClarabelCscMatrix;
// ClarabelCscMatrix APIs

// ClarabelCscMatrix::init
void clarabel_CscMatrix_f32_init(
ClarabelCscMatrix_f32 *ptr,
uintptr_t m,
uintptr_t n,
const uintptr_t *colptr,
const uintptr_t *rowval,
const float *nzval);
void clarabel_CscMatrix_f32_init(ClarabelCscMatrix_f32 *ptr,
uintptr_t m,
uintptr_t n,
const uintptr_t *colptr,
const uintptr_t *rowval,
const float *nzval);

void clarabel_CscMatrix_f64_init(
ClarabelCscMatrix_f64 *ptr,
uintptr_t m,
uintptr_t n,
const uintptr_t *colptr,
const uintptr_t *rowval,
const double *nzval);
void clarabel_CscMatrix_f64_init(ClarabelCscMatrix_f64 *ptr,
uintptr_t m,
uintptr_t n,
const uintptr_t *colptr,
const uintptr_t *rowval,
const double *nzval);

/// @brief Initialize a sparse matrix in Compressed Sparse Column format
/// @param m Number of rows
/// @param n Number of columns
/// @param colptr CSC format column pointer array (always have length n+1)
/// @param rowval Array of row indices (always have length colptr[n])
/// @param nzval Array of nonzero values (always have length colptr[n])
static inline void clarabel_CscMatrix_init(
ClarabelCscMatrix_f64 *ptr,
uintptr_t m,
uintptr_t n,
const uintptr_t *colptr,
const uintptr_t *rowval,
const double *nzval)
static inline void clarabel_CscMatrix_init(ClarabelCscMatrix_f64 *ptr,
uintptr_t m,
uintptr_t n,
const uintptr_t *colptr,
const uintptr_t *rowval,
const double *nzval)
{
#ifdef CLARABEL_USE_FLOAT
clarabel_CscMatrix_f32_init(ptr, m, n, colptr, rowval, nzval);
Expand Down
49 changes: 23 additions & 26 deletions include/c/DefaultSolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,29 @@ typedef ClarabelDefaultSolver_f64 ClarabelDefaultSolver;
// Default solver APIs

// DefaultSolver::new
ClarabelDefaultSolver_f64 *clarabel_DefaultSolver_f64_new(
const ClarabelCscMatrix_f64 *P,
const double *q,
const ClarabelCscMatrix_f64 *A,
const double *b,
uintptr_t n_cones,
const ClarabelSupportedConeT_f64 *cones,
const ClarabelDefaultSettings_f64 *settings);

ClarabelDefaultSolver_f32 *clarabel_DefaultSolver_f32_new(
const ClarabelCscMatrix_f32 *P,
const float *q,
const ClarabelCscMatrix_f32 *A,
const float *b,
uintptr_t n_cones,
const ClarabelSupportedConeT_f32 *cones,
const ClarabelDefaultSettings_f32 *settings);

static inline ClarabelDefaultSolver *clarabel_DefaultSolver_new(
const ClarabelCscMatrix *P,
const ClarabelFloat *q,
const ClarabelCscMatrix *A,
const ClarabelFloat *b,
uintptr_t n_cones,
const ClarabelSupportedConeT *cones,
const ClarabelDefaultSettings *settings)
ClarabelDefaultSolver_f64 *clarabel_DefaultSolver_f64_new(const ClarabelCscMatrix_f64 *P,
const double *q,
const ClarabelCscMatrix_f64 *A,
const double *b,
uintptr_t n_cones,
const ClarabelSupportedConeT_f64 *cones,
const ClarabelDefaultSettings_f64 *settings);

ClarabelDefaultSolver_f32 *clarabel_DefaultSolver_f32_new(const ClarabelCscMatrix_f32 *P,
const float *q,
const ClarabelCscMatrix_f32 *A,
const float *b,
uintptr_t n_cones,
const ClarabelSupportedConeT_f32 *cones,
const ClarabelDefaultSettings_f32 *settings);

static inline ClarabelDefaultSolver *clarabel_DefaultSolver_new(const ClarabelCscMatrix *P,
const ClarabelFloat *q,
const ClarabelCscMatrix *A,
const ClarabelFloat *b,
uintptr_t n_cones,
const ClarabelSupportedConeT *cones,
const ClarabelDefaultSettings *settings)
{
#ifdef CLARABEL_USE_FLOAT
return clarabel_DefaultSolver_f32_new(P, q, A, b, n_cones, cones, settings);
Expand Down
Loading

0 comments on commit 186d06a

Please sign in to comment.