[Bf-blender-cvs] [5e52433] master: OpenNL: convert source file to C++, remove some unused functions.

Brecht Van Lommel noreply at git.blender.org
Sun Nov 22 22:54:37 CET 2015


Commit: 5e524333719794f140dafee0555ede5fd308b9ae
Author: Brecht Van Lommel
Date:   Sun Nov 22 00:51:47 2015 +0100
Branches: master
https://developer.blender.org/rB5e524333719794f140dafee0555ede5fd308b9ae

OpenNL: convert source file to C++, remove some unused functions.

===================================================================

M	intern/opennl/CMakeLists.txt
M	intern/opennl/SConscript
M	intern/opennl/extern/ONL_opennl.h
D	intern/opennl/intern/opennl.c
A	intern/opennl/intern/opennl.cpp

===================================================================

diff --git a/intern/opennl/CMakeLists.txt b/intern/opennl/CMakeLists.txt
index af8fde8..32bd438 100644
--- a/intern/opennl/CMakeLists.txt
+++ b/intern/opennl/CMakeLists.txt
@@ -51,7 +51,7 @@ set(INC_SYS
 )
 
 set(SRC
-	intern/opennl.c
+	intern/opennl.cpp
 	superlu/get_perm_c.c
 	superlu/heap_relax_snode.c
 	superlu/lsame.c
diff --git a/intern/opennl/SConscript b/intern/opennl/SConscript
index f47dd56..dcd9ea4 100644
--- a/intern/opennl/SConscript
+++ b/intern/opennl/SConscript
@@ -27,7 +27,7 @@
 
 Import ('env')
 
-sources = env.Glob('intern/*.c') + env.Glob('superlu/*.c')
+sources = env.Glob('intern/*.cpp') + env.Glob('superlu/*.c')
 
 incs = 'extern superlu ../../extern/colamd/Include'
 
diff --git a/intern/opennl/extern/ONL_opennl.h b/intern/opennl/extern/ONL_opennl.h
index c89a4aa..6a36e13 100644
--- a/intern/opennl/extern/ONL_opennl.h
+++ b/intern/opennl/extern/ONL_opennl.h
@@ -57,16 +57,8 @@ extern "C" {
 
 typedef unsigned int	NLenum;
 typedef unsigned char	NLboolean;
-typedef unsigned int	NLbitfield;
-typedef void			NLvoid;
-typedef signed char		NLbyte;		/* 1-byte signed */
-typedef short			NLshort;	/* 2-byte signed */
 typedef int				NLint;		/* 4-byte signed */
-typedef unsigned char	NLubyte;	/* 1-byte unsigned */
-typedef unsigned short	NLushort;	/* 2-byte unsigned */
 typedef unsigned int	NLuint;		/* 4-byte unsigned */
-typedef int				NLsizei;	/* 4-byte signed */
-typedef float			NLfloat;	/* single precision float */
 typedef double			NLdouble;	/* double precision float */
 
 typedef void* NLContext;
@@ -100,24 +92,14 @@ NLContext nlGetCurrent(void);
 
 /* State get/set */
 
-void nlSolverParameterf(NLenum pname, NLdouble param);
 void nlSolverParameteri(NLenum pname, NLint param);
 
-void nlGetBooleanv(NLenum pname, NLboolean* params);
-void nlGetFloatv(NLenum pname, NLdouble* params);
-void nlGetIntergerv(NLenum pname, NLint* params);
-
-void nlEnable(NLenum pname);
-void nlDisable(NLenum pname);
-NLboolean nlIsEnabled(NLenum pname);
-
 /* Variables */
 
 void nlSetVariable(NLuint rhsindex, NLuint index, NLdouble value);
 NLdouble nlGetVariable(NLuint rhsindex, NLuint index);
 void nlLockVariable(NLuint index);
 void nlUnlockVariable(NLuint index);
-NLboolean nlVariableIsLocked(NLuint index);
 
 /* Begin/End */
 
diff --git a/intern/opennl/intern/opennl.c b/intern/opennl/intern/opennl.cpp
similarity index 88%
rename from intern/opennl/intern/opennl.c
rename to intern/opennl/intern/opennl.cpp
index 8cf4bf1..dbe59c9 100644
--- a/intern/opennl/intern/opennl.c
+++ b/intern/opennl/intern/opennl.cpp
@@ -59,7 +59,7 @@
 /* Assertions */
 
 
-static void __nl_assertion_failed(char* cond, char* file, int line) {
+static void __nl_assertion_failed(const char* cond, const char* file, int line) {
 	fprintf(
 		stderr, 
 		"OpenNL assertion failed: %s, file:%s, line:%d\n",
@@ -69,7 +69,7 @@ static void __nl_assertion_failed(char* cond, char* file, int line) {
 }
 
 static void __nl_range_assertion_failed(
-	double x, double min_val, double max_val, char* file, int line
+	double x, double min_val, double max_val, const char* file, int line
 ) {
 	fprintf(
 		stderr, 
@@ -79,7 +79,7 @@ static void __nl_range_assertion_failed(
 	abort();
 }
 
-static void __nl_should_not_have_reached(char* file, int line) {
+static void __nl_should_not_have_reached(const char* file, int line) {
 	fprintf(
 		stderr, 
 		"OpenNL should not have reached this point: file:%s, line:%d\n",
@@ -95,9 +95,9 @@ static void __nl_should_not_have_reached(char* file, int line) {
 	}														   \
 } 
 
-#define __nl_range_assert(x,min_val,max_val) {				  \
-	if(((x) < (min_val)) || ((x) > (max_val))) {				\
-		__nl_range_assertion_failed(x, min_val, max_val,		\
+#define __nl_range_assert(x,max_val) {						  \
+	if(((x) > (max_val))) {										\
+		__nl_range_assertion_failed(x, 0.0, max_val,			\
 			__FILE__, __LINE__								  \
 		);													 \
 	}														   \
@@ -611,32 +611,6 @@ static void __nlTransition(NLenum from_state, NLenum to_state) {
 /************************************************************************************/
 /* Get/Set parameters */
 
-void nlSolverParameterf(NLenum pname, NLdouble param) {
-	__nlCheckState(__NL_STATE_INITIAL);
-	switch(pname) {
-	case NL_NB_VARIABLES: {
-		__nl_assert(param > 0);
-		__nlCurrentContext->nb_variables = (NLuint)param;
-	} break;
-	case NL_NB_ROWS: {
-		__nl_assert(param > 0);
-		__nlCurrentContext->nb_rows = (NLuint)param;
-	} break;
-	case NL_LEAST_SQUARES: {
-		__nlCurrentContext->least_squares = (NLboolean)param;
-	} break;
-	case NL_SYMMETRIC: {
-		__nlCurrentContext->symmetric = (NLboolean)param;		
-	} break;
-	case NL_NB_RIGHT_HAND_SIDES: {
-		__nlCurrentContext->nb_rhs = (NLuint)param;
-	} break;
-	default: {
-		__nl_assert_not_reached;
-	} break;
-	}
-}
-
 void nlSolverParameteri(NLenum pname, NLint param) {
 	__nlCheckState(__NL_STATE_INITIAL);
 	switch(pname) {
@@ -663,91 +637,6 @@ void nlSolverParameteri(NLenum pname, NLint param) {
 	}
 }
 
-void nlGetBooleanv(NLenum pname, NLboolean* params) {
-	switch(pname) {
-	case NL_LEAST_SQUARES: {
-		*params = __nlCurrentContext->least_squares;
-	} break;
-	case NL_SYMMETRIC: {
-		*params = __nlCurrentContext->symmetric;
-	} break;
-	default: {
-		__nl_assert_not_reached;
-	} break;
-	}
-}
-
-void nlGetFloatv(NLenum pname, NLdouble* params) {
-	switch(pname) {
-	case NL_NB_VARIABLES: {
-		*params = (NLdouble)(__nlCurrentContext->nb_variables);
-	} break;
-	case NL_NB_ROWS: {
-		*params = (NLdouble)(__nlCurrentContext->nb_rows);
-	} break;
-	case NL_LEAST_SQUARES: {
-		*params = (NLdouble)(__nlCurrentContext->least_squares);
-	} break;
-	case NL_SYMMETRIC: {
-		*params = (NLdouble)(__nlCurrentContext->symmetric);
-	} break;
-	case NL_ERROR: {
-		*params = (NLdouble)(__nlCurrentContext->error);
-	} break;
-	default: {
-		__nl_assert_not_reached;
-	} break;
-	}
-}
-
-void nlGetIntergerv(NLenum pname, NLint* params) {
-	switch(pname) {
-	case NL_NB_VARIABLES: {
-		*params = (NLint)(__nlCurrentContext->nb_variables);
-	} break;
-	case NL_NB_ROWS: {
-		*params = (NLint)(__nlCurrentContext->nb_rows);
-	} break;
-	case NL_LEAST_SQUARES: {
-		*params = (NLint)(__nlCurrentContext->least_squares);
-	} break;
-	case NL_SYMMETRIC: {
-		*params = (NLint)(__nlCurrentContext->symmetric);
-	} break;
-	default: {
-		__nl_assert_not_reached;
-	} break;
-	}
-}
-
-/************************************************************************************/
-/* Enable / Disable */
-
-void nlEnable(NLenum pname) {
-	switch(pname) {
-	default: {
-		__nl_assert_not_reached;
-	}
-	}
-}
-
-void nlDisable(NLenum pname) {
-	switch(pname) {
-	default: {
-		__nl_assert_not_reached;
-	}
-	}
-}
-
-NLboolean nlIsEnabled(NLenum pname) {
-	switch(pname) {
-	default: {
-		__nl_assert_not_reached;
-	}
-	}
-	return NL_FALSE;
-}
-
 /************************************************************************************/
 /* Get/Set Lock/Unlock variables */
 
@@ -775,12 +664,6 @@ void nlUnlockVariable(NLuint index) {
 	__nlCurrentContext->variable[index].locked = NL_FALSE;
 }
 
-NLboolean nlVariableIsLocked(NLuint index) {
-	__nl_assert(__nlCurrentContext->state != __NL_STATE_INITIAL);
-	__nl_parano_range_assert(index, 0, __nlCurrentContext->nb_variables - 1);
-	return __nlCurrentContext->variable[index].locked;
-}
-
 /************************************************************************************/
 /* System construction */
 
@@ -953,8 +836,8 @@ void nlMatrixAdd(NLuint row, NLuint col, NLdouble value)
 			row = context->variable[row].index;
 		col = context->variable[col].index;
 		
-		__nl_range_assert(row, 0, context->m - 1);
-		__nl_range_assert(col, 0, context->n - 1);
+		__nl_range_assert(row, context->m - 1);
+		__nl_range_assert(col, context->n - 1);
 
 		__nlSparseMatrixAdd(M, row, col, value);
 	}
@@ -968,13 +851,13 @@ void nlRightHandSideAdd(NLuint rhsindex, NLuint index, NLdouble value)
 	__nlCheckState(__NL_STATE_MATRIX);
 
 	if(context->least_squares) {
-		__nl_range_assert(index, 0, context->m - 1);
+		__nl_range_assert(index, context->m - 1);
 		b[rhsindex*context->m + index] += value;
 	}
 	else {
 		if(!context->variable[index].locked) {
 			index = context->variable[index].index;
-			__nl_range_assert(index, 0, context->m - 1);
+			__nl_range_assert(index, context->m - 1);
 
 			b[rhsindex*context->m + index] += value;
 		}
@@ -989,13 +872,13 @@ void nlRightHandSideSet(NLuint rhsindex, NLuint index, NLdouble value)
 	__nlCheckState(__NL_STATE_MATRIX);
 
 	if(context->least_squares) {
-		__nl_range_assert(index, 0, context->m - 1);
+		__nl_range_assert(index, context->m - 1);
 		b[rhsindex*context->m + index] = value;
 	}
 	else {
 		if(!context->variable[index].locked) {
 			index = context->variable[index].index;
-			__nl_range_assert(index, 0, context->m - 1);
+			__nl_range_assert(index, context->m - 1);
 
 			b[rhsindex*context->m + index] = value;
 		}
@@ -1189,7 +1072,7 @@ void nlPrintMatrix(void) {
 	NLuint m = context->m;
 	NLuint n = context->n;
 	__NLRowColumn* Ri = NULL;
-	double *value = malloc(sizeof(*value)*(n+m));
+	double *value = (double*)malloc(sizeof(*value)*(n+m));
 
 	printf("A:\n");
 	for(i=0; i<m; i++) {
@@ -1205,7 +1088,7 @@ void nlPrintMatrix(void) {
 	}
 
 	for(k=0; k<context->nb_rhs; k++) {
-		printf("b (%d):\n", k);
+		printf("b (%u):\n", k);
 		for(i=0; i<n; i++)
 			printf("%f ", b[context->n*k + i]);
 		printf("\n");
@@ -1226,7 +1109,7 @@ void nlPrintMatrix(void) {
 		}
 
 		for(k=0; k<context->nb_rhs; k++) {
-			printf("Mtb (%d):\n", k);
+			printf("Mtb (%u):\n", k);
 			for(i=0; i<n; i++)
 				printf("%f ", context->Mtb[context->n*k + i]);
 			printf("\n");




More information about the Bf-blender-cvs mailing list