Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor Refactor, Fixes & Upgrades #155

Open
wants to merge 14 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@
__.SYMDEF

ecostester
ecos_bb_test
runecos
runecosexp
python/build
python/dist
python/*.pyc

# VS temp files
*.vs
11 changes: 8 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ runecosexp: src/runecos_exp.c libecos.a

# Shared library
.PHONY: shared
shared: $(SHAREDNAME)
$(SHAREDNAME): $(LDL) $(AMD) $(ECOS_OBJS)
shared: $(SHARED_ECOS) $(SHARED_ECOS_BB)
$(SHARED_ECOS): $(LDL) $(AMD) $(ECOS_OBJS)
$(CC) $(CFLAGS) -shared -o $@ $^ $(LDFLAGS)
$(SHARED_ECOS_BB): $(LDL) $(AMD) $(ECOS_BB_OBJS)
$(CC) $(CFLAGS) -shared -o $@ $^ $(LDFLAGS)

# ECOS tester
Expand Down Expand Up @@ -101,4 +103,7 @@ clean:
purge: clean
( cd external/ldl ; $(MAKE) purge )
( cd external/amd ; $(MAKE) purge )
- $(RM) libecos.a libecos_bb.a runecos runecosexp
- $(RM) runecos runecosexp \
libecos*.a libecos*.so libecos*.dylib libecos*.dll \
ecos_bb_test ecos_bb_test.exe \
ecostester ecostester.exe
11 changes: 7 additions & 4 deletions ecos.mk
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,20 @@ ifeq ($(UNAME), Darwin)
# we're on apple, no need to link rt library
LDFLAGS = -lm
# shared library has extension .dylib
SHAREDNAME = libecos.dylib
SHARED_ECOS = libecos.dylib
SHARED_ECOS_BB = libecos_bb.dylib
else ifeq ($(ISWINDOWS), 1)
# we're on windows (cygwin or msys)
LDFLAGS = -lm
# shared library has extension .dll
SHAREDNAME = libecos.dll
SHARED_ECOS = libecos.dll
SHARED_ECOS_BB = libecos_bb.dll
else
# we're on a linux system, use accurate timer provided by clock_gettime()
LDFLAGS = -lm -lrt
# shared library has extension .so
SHAREDNAME = libecos.so
SHARED_ECOS = libecos.so
SHARED_ECOS_BB = libecos_bb.so
endif


Expand All @@ -60,4 +63,4 @@ ARCHIVE = $(AR) $(ARFLAGS)
RANLIB = ranlib

## WHICH FILES TO CLEAN UP
CLEAN = *.o *.obj *.ln *.bb *.bbg *.da *.tcov *.gcov gmon.out *.bak *.d *.gcda *.gcno libecos*.a libecos*.so libecos*.dylib libecos*.dll ecos_bb_test ecostester ecostester.exe runecosexp
CLEAN = *.o *.obj *.ln *.bb *.bbg *.da *.tcov *.gcov gmon.out *.bak *.d *.gcda *.gcno
8 changes: 4 additions & 4 deletions external/amd/include/amd_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@
AMD will be exceedingly slow when running in debug mode. The next three
lines ensure that debugging is turned off.
*/
#ifndef NDEBUG
#define NDEBUG
#endif
// #ifndef NDEBUG
// #define NDEBUG
// #endif

/*
To enable debugging, uncomment the following line:
#undef NDEBUG
*/
// #undef NDEBUG

/* ------------------------------------------------------------------------- */
/* ANSI include files */
Expand Down
4 changes: 4 additions & 0 deletions include/ecos_bb.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,14 @@
/* define INFINITY and isinf for MSFT */
#ifdef _MSC_VER
#include "float.h"
#ifndef INFINITY
#define INFINITY (DBL_MAX+DBL_MAX)
#endif
/* this will also return true if x is nan, but we don't check that anyway */
#ifndef isinf
#define isinf(x) (!_finite(x))
#endif
#endif

#ifdef __cplusplus
extern "C" {
Expand Down
15 changes: 14 additions & 1 deletion include/glblopts.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@
typedef double pfloat; /* for numerical values */

/* SET PRINT LEVEL ----------------------------------------------------- */
#ifndef PRINTLEVEL
#define PRINTLEVEL (2) /* 0: no prints */
/* 1: only final info */
/* 2: progress print per iteration */
/* 3: debug level, enables print & dump fcns. */
#endif

#define MATLAB_FLUSH_PRINTS
/* print each iteration directly to Matlab. */
Expand All @@ -39,14 +41,21 @@ typedef double pfloat; /* for numerical values */
/* problems. */

/* SET PROFILING LEVEL ------------------------------------------------- */
#ifndef PROFILING
#define PROFILING (1) /* 0: no timing information */
/* 1: runtime (divided in setup and solve) */
/* 2: detailed profiling */
#endif

/* SET DEBUG LEVEL ----------------------------------------------------- */
#ifndef DEBUG
#define DEBUG (0) /* 0: no debugging information */
/* 1: debug info & dump intermediate results */
/* (flag used only for development) */
#endif

/* SYSTEM INCLUDES FOR NAN & INFINITY ---------------------------------- */
#include <math.h>

/* NAN ----------------------------------------------------------------- */
#ifndef NAN
Expand All @@ -62,6 +71,11 @@ typedef double pfloat; /* for numerical values */
#define EXPCONE /*When defined the exponential cone solver code is enabled*/

/* SYSTEM INCLUDES FOR PRINTING ---------------------------------------- */
#if DEBUG || PRINTLEVEL > 0
#include <stdio.h>
#endif

/* PRINTTEXT ----------------------------------------------------------- */
#if PRINTLEVEL > 0
#ifdef MATLAB_MEX_FILE
#include "mex.h"
Expand All @@ -72,7 +86,6 @@ typedef double pfloat; /* for numerical values */
#else
#define PRINTTEXT printf
#endif
#include <stdio.h>
#else
#define PRINTTEXT(...)
#endif
Expand Down
5 changes: 4 additions & 1 deletion include/splamm.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
/**
* Create a sparse matrix from existing arrays.
*/
spmat* createSparseMatrix(idxint m, idxint n, idxint nnz, idxint* jc, idxint* ir, pfloat* pr);
spmat* EcosCreateSparseMatrix(idxint m, idxint n, idxint nnz, idxint* jc, idxint* ir, pfloat* pr);


/**
Expand Down Expand Up @@ -100,6 +100,9 @@ void printDenseMatrix_i(idxint *M, idxint dim1, idxint dim2, char *name);
*/
void printSparseMatrix(spmat* M);

#endif

#if DEBUG

/**
* Dumps a sparse matrix in Matlab format.
Expand Down
1 change: 0 additions & 1 deletion src/cone.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include "ecos.h"
#include "expcone.h"

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

Expand Down
18 changes: 10 additions & 8 deletions src/ecos.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@
/* NEEDED FOR SQRT ----------------------------------------------------- */
#include <math.h>

#if (defined _WIN32 || defined _WIN64 )
/* include stdio.h for _set_output_format */
#include <stdio.h>
#endif
// DEPRICATED - _set_output_format
// #if (defined _WIN32 || defined _WIN64 )
// /* include stdio.h for _set_output_format */
// #include <stdio.h>
// #endif



Expand Down Expand Up @@ -1088,10 +1089,11 @@ idxint ECOS_solve(pwork* w)
char fn[20];
#endif

#if (defined _WIN32 || defined _WIN64 )
/* sets width of exponent for floating point numbers to 2 instead of 3 */
unsigned int old_output_format = _set_output_format(_TWO_DIGIT_EXPONENT);
#endif
// DEPRICATED - _set_output_format
// #if (defined _WIN32 || defined _WIN64 )
// /* sets width of exponent for floating point numbers to 2 instead of 3 */
// unsigned int old_output_format = _set_output_format(_TWO_DIGIT_EXPONENT);
// #endif

#if PROFILING > 0
timer tsolve;
Expand Down
10 changes: 5 additions & 5 deletions src/preproc.c
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ void createKKT_U(spmat* Gt, spmat* At, cone* C, idxint** S, spmat** K,

/* return Sign vector and KKT matrix */
*S = Sign;
*K = createSparseMatrix(nK, nK, nnzK, Kjc, Kir, Kpr);
*K = EcosCreateSparseMatrix(nK, nK, nnzK, Kjc, Kir, Kpr);
}

/**
Expand Down Expand Up @@ -791,15 +791,15 @@ pwork* ECOS_setup(idxint n, idxint m, idxint p, idxint l, idxint ncones, idxint*

/* Store problem data */
if(Apr && Ajc && Air) {
mywork->A = createSparseMatrix(p, n, Ajc[n], Ajc, Air, Apr);
mywork->A = EcosCreateSparseMatrix(p, n, Ajc[n], Ajc, Air, Apr);
} else {
mywork->A = NULL;
}
if (Gpr && Gjc && Gir) {
mywork->G = createSparseMatrix(m, n, Gjc[n], Gjc, Gir, Gpr);
mywork->G = EcosCreateSparseMatrix(m, n, Gjc[n], Gjc, Gir, Gpr);
} else {
/* create an empty sparse matrix */
mywork->G = createSparseMatrix(m, n, 0, Gjc, Gir, Gpr);
mywork->G = EcosCreateSparseMatrix(m, n, 0, Gjc, Gir, Gpr);
}

#if defined EQUILIBRATE && EQUILIBRATE > 0
Expand Down Expand Up @@ -992,7 +992,7 @@ pwork* ECOS_setup(idxint n, idxint m, idxint p, idxint l, idxint ncones, idxint*
#endif
Lir = (idxint *)MALLOC(lnz*sizeof(idxint));
Lpr = (pfloat *)MALLOC(lnz*sizeof(pfloat));
mywork->KKT->L = createSparseMatrix(nK, nK, lnz, Ljc, Lir, Lpr);
mywork->KKT->L = EcosCreateSparseMatrix(nK, nK, lnz, Ljc, Lir, Lpr);
#if PRINTLEVEL > 2
PRINTTEXT("Created Cholesky factor of K in KKT struct\n");
#endif
Expand Down
31 changes: 22 additions & 9 deletions src/splamm.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
#include "splamm.h"

/* SYSTEM INCLUDES FOR MEMORY ALLOCATION ------------------------------- */
#if PRINTLEVEL > 2
#include <stdlib.h>
#if DEBUG || PRINTLEVEL > 0
#include <stdio.h>
#endif


Expand Down Expand Up @@ -103,14 +103,14 @@ spmat* newSparseMatrix(idxint m, idxint n, idxint nnz)
idxint* ir = (idxint *)MALLOC(nnz*sizeof(idxint));
pfloat* pr = (pfloat *)MALLOC(nnz*sizeof(pfloat));
jc[n] = nnz;
return createSparseMatrix(m, n, nnz, jc, ir, pr);
return EcosCreateSparseMatrix(m, n, nnz, jc, ir, pr);
}


/**
* Create a sparse matrix from existing arrays (no MALLOC)
*/
spmat* createSparseMatrix(idxint m, idxint n, idxint nnz, idxint* jc, idxint* ir, pfloat* pr)
spmat* EcosCreateSparseMatrix(idxint m, idxint n, idxint nnz, idxint* jc, idxint* ir, pfloat* pr)
{
spmat* M = (spmat *)MALLOC(sizeof(spmat));
M->m = m;
Expand Down Expand Up @@ -274,8 +274,9 @@ void printSparseMatrix(spmat* M)
}
}
}
#endif


#if DEBUG
/* dump a sparse matrix in Matlab format */
/* use LOAD and SPCONVERT to read in the file in MATLAB */
void dumpSparseMatrix(spmat* M, char* fn)
Expand All @@ -297,9 +298,13 @@ void dumpSparseMatrix(spmat* M, char* fn)
}
fprintf(f,"%d\t%d\t%20.18e\n", (int)M->m, (int)M->n, 0.0);
fclose(f);
#if PRINTLEVEL > 0
PRINTTEXT("File %s successfully written.\n", fn);
#endif
} else {
#if PRINTLEVEL > 0
PRINTTEXT("Error during writing file %s.\n", fn);
#endif
}
}

Expand Down Expand Up @@ -332,9 +337,13 @@ void dumpDenseMatrix(pfloat *M, int dim1, int dim2, char *fn)
}
}
fclose(f);
printf("Written %d x %d matrix to '%s'.\n",i,dim2,fn);
#if PRINTLEVEL > 0
PRINTTEXT("Written %d x %d matrix to '%s'.\n",i,dim2,fn);
#endif
} else {
printf("ERROR: file %s could not be opened. Exiting.",fn);
#if PRINTLEVEL > 0
PRINTTEXT("ERROR: file %s could not be opened. Exiting.",fn);
#endif
exit(1);
}
}
Expand Down Expand Up @@ -368,9 +377,13 @@ void dumpDenseMatrix_i(idxint *M, int dim1, int dim2, char *fn)
}
}
fclose(f);
printf("Written %d x %d matrix to '%s'.\n",i,dim2,fn);
#if PRINTLEVEL > 0
PRINTTEXT("Written %d x %d matrix to '%s'.\n",i,dim2,fn);
#endif
} else {
printf("ERROR: file %s could not be opened. Exiting.",fn);
#if PRINTLEVEL > 0
PRINTTEXT("ERROR: file %s could not be opened. Exiting.",fn);
#endif
exit(1);
}
}
Expand Down
2 changes: 2 additions & 0 deletions test/bb_test.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include <stdio.h>

#include "timer.h"
#include "ecos.h"
#include "ecos_bb.h"
Expand Down
2 changes: 1 addition & 1 deletion test/generated/inv_pos/inv_pos.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ extern "C" {

/* the parameter struct */
typedef struct inv_pos_params {

int : 0;
} inv_pos_params;

/* the input dimensions struct */
Expand Down
2 changes: 1 addition & 1 deletion test/generated/norm/norm.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ extern "C" {

/* the parameter struct */
typedef struct norm_params {

int : 0;
} norm_params;

/* the input dimensions struct */
Expand Down
2 changes: 1 addition & 1 deletion test/generated/quad_over_lin/quad_over_lin.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ extern "C" {

/* the parameter struct */
typedef struct quad_over_lin_params {

int : 0;
} quad_over_lin_params;

/* the input dimensions struct */
Expand Down
2 changes: 1 addition & 1 deletion test/generated/sq_norm/sq_norm.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ extern "C" {

/* the parameter struct */
typedef struct sq_norm_params {

int : 0;
} sq_norm_params;

/* the input dimensions struct */
Expand Down
2 changes: 1 addition & 1 deletion test/generated/sum_sq/sum_sq.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ extern "C" {

/* the parameter struct */
typedef struct sum_sq_params {

int : 0;
} sum_sq_params;

/* the input dimensions struct */
Expand Down
6 changes: 6 additions & 0 deletions vstudio/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# VS temp files
Debug
Export
Release
*.vcxproj.filters
*.vcxproj.user
Loading