changeset 12692:13815b367946 octave-forge

use size_t instead of mwSize/mwIndex whenever possible
author schloegl
date Sat, 12 Sep 2015 14:59:20 +0000
parents 6d6285a2a633
children c76411f5c22e
files extra/NaN/src/histo_mex.cpp extra/NaN/src/kth_element.cpp extra/NaN/src/str2array.cpp extra/NaN/src/sumskipnan_mex.cpp extra/NaN/src/xptopen.cpp
diffstat 5 files changed, 35 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/extra/NaN/src/histo_mex.cpp	Sat Sep 12 14:16:39 2015 +0000
+++ b/extra/NaN/src/histo_mex.cpp	Sat Sep 12 14:59:20 2015 +0000
@@ -46,6 +46,12 @@
 #include <string.h>
 #include "mex.h"
 
+/* 
+   math.h has isnan() defined for all sizes of floating point numbers, 
+   but c++ assumes isnan(double), causing possible conversions for float and long double
+*/
+#define ISNAN(a) (a!=a)
+
 
 #ifdef tmwtypes_h
   #if (MX_API_VER<=0x07020000)
@@ -109,7 +115,7 @@
 			float f1,f2;
 			f1 = ((float*)Sort.Table)[ix1];
 			f2 = ((float*)Sort.Table)[ix2];
-			z = isnan(f1) - isnan(f2);
+			z = ISNAN(f1) - ISNAN(f2);
 			if (z) break;
 			
 			if (f1<f2) z = -1; 
@@ -121,7 +127,7 @@
 			double f1,f2;
 			f1 = ((double*)Sort.Table)[ix1];
 			f2 = ((double*)Sort.Table)[ix2];
-			z = isnan(f1) - isnan(f2);
+			z = ISNAN(f1) - ISNAN(f2);
 			if (z) break;
 			
 			if (f1<f2) z = -1; 
@@ -178,7 +184,7 @@
     	const mwSize	*SZ;	    
 	char 		flag_rows = 0; 
 	char 		done = 0; 
-    	mwSize    	j, k, l;	// running indices 
+    	size_t    	j, k, l;	// running indices 
 	const mxArray	*W = NULL; 
     	double 		*w = NULL; 
 
--- a/extra/NaN/src/kth_element.cpp	Sat Sep 12 14:16:39 2015 +0000
+++ b/extra/NaN/src/kth_element.cpp	Sat Sep 12 14:59:20 2015 +0000
@@ -59,20 +59,26 @@
   #endif 
 #endif 
 
+/* 
+   math.h has isnan() defined for all sizes of floating point numbers, 
+   but c++ assumes isnan(double), causing possible conversions for float and long double
+*/
+#define ISNAN(a) (a!=a)
+
 
 #define SWAP(a,b) {temp = a; a=b; b=temp;} 
  
 static void findFirstK(double *array, size_t left, size_t right, size_t k)
 {
         while (right > left) {
-                mwIndex pivotIndex = (left + right) / 2;
+                size_t pivotIndex = (left + right) / 2;
 
 		/* partition */
 	        double temp;
 	        double pivotValue = array[pivotIndex];
         	SWAP(array[pivotIndex], array[right]);
         	pivotIndex = left;
-	        for (mwIndex i = left; i <= right - 1; ++i ) {
+	        for (size_t i = left; i <= right - 1; ++i ) {
         	        // if (array[i] <= pivotValue || isnan(pivotValue)) // needed if data contains NaN's 
         	        if (array[i] <= pivotValue) 
         	        {
@@ -93,8 +99,8 @@
 
 void mexFunction(int POutputCount,  mxArray* POutput[], int PInputCount, const mxArray *PInputs[]) 
 {
-    	mwIndex k, n;	// running indices 
-    	mwSize  szK, szX;
+    	size_t k, n;	// running indices 
+    	size_t szK, szX;
     	double 	*T,*X,*Y,*K; 
     	char flag = 0; // default value 
 
@@ -112,7 +118,7 @@
 	}  
 	else if (PInputCount == 3) {
 		// check value of flag
-		mwSize N = mxGetNumberOfElements(PInputs[2]); 
+		size_t N = mxGetNumberOfElements(PInputs[2]); 
 		if (N>1)
 		        mexErrMsgTxt("KTH_ELEMENT: flag argument must be scalar\n");
 		else if (N==1) {
@@ -180,7 +186,7 @@
 		else  {
 			/* do not copy NaN's */
 			for (k=0,n=0; k < szX; k++) {
-				if (!isnan(X[k])) T[n++]=X[k]; 
+				if (!ISNAN(X[k])) T[n++]=X[k]; 
 			}
 			szX = n; 
 		}	
--- a/extra/NaN/src/str2array.cpp	Sat Sep 12 14:16:39 2015 +0000
+++ b/extra/NaN/src/str2array.cpp	Sat Sep 12 14:59:20 2015 +0000
@@ -122,7 +122,8 @@
 			return(2); 
 		}
 	}
-	else if (*endptr && !isspace(*endptr)) {
+	else //if (*endptr && !isspace(*endptr)) 
+	{
 		// conversion failed 
 		return(0); 
 	}
@@ -131,9 +132,9 @@
 
 
 void mexFunction(
-    int           nlhs,           /* number of expected outputs */
+    mwSize          nlhs,           /* number of expected outputs */
     mxArray       *plhs[],        /* array of pointers to output arguments */
-    int           nrhs,           /* number of inputs */
+    mwSize          nrhs,           /* number of inputs */
     const mxArray *prhs[]         /* array of pointers to input arguments */
 )
 
@@ -200,7 +201,7 @@
 			}
 			else {
 				int typ = str2val(s, o+k, &ival);
-				if ((nlhs>2) && (typ==0)) mxSetCell(plhs[2], k, mxCreateString(s));
+				if ((nlhs>2) && (typ==0)) mxSetCell(plhs[2], (mwSize)k, mxCreateString(s));
 				if ((nlhs>1) && (typ> 0)) v[k] = 0;
 				if (typ==2) {
 					if (mxGetPi(plhs[0])==NULL) {
--- a/extra/NaN/src/sumskipnan_mex.cpp	Sat Sep 12 14:16:39 2015 +0000
+++ b/extra/NaN/src/sumskipnan_mex.cpp	Sat Sep 12 14:59:20 2015 +0000
@@ -90,12 +90,12 @@
     	double  	x;
     	double*		W = NULL;		// weight vector 
 
-    	mwSize		DIM = 0; 
-    	mwSize		D1, D2, D3; 	// NN; 	//  	
-    	mwSize    	ND, ND2;	// number of dimensions: input, output
-    	mwSize		ix0, ix1, ix2;	// index to input and output
-    	mwSize    	j, l;		// running indices 
-    	mwSize 		*SZ2;		// size of output 	    
+    	size_t		DIM = 0; 
+    	size_t		D1, D2, D3; 	// NN; 	//  	
+    	size_t    	ND, ND2;	// number of dimensions: input, output
+    	size_t		ix0, ix1, ix2;	// index to input and output
+    	size_t    	j, l;		// running indices 
+    	mwIndex		*SZ2;		// size of output 	    
 	char	 	flag_isNaN = 0;
 
 	// check for proper number of input and output arguments
--- a/extra/NaN/src/xptopen.cpp	Sat Sep 12 14:16:39 2015 +0000
+++ b/extra/NaN/src/xptopen.cpp	Sat Sep 12 14:59:20 2015 +0000
@@ -933,7 +933,7 @@
 		H2 = (char*) realloc(H2,HeadLen2);
 		memset(H2,0,HeadLen2);
 
-		mwIndex M = 0;
+		size_t M = 0;
 		mxArray **F = (mxArray**) mxMalloc(NS*sizeof(mxArray*));
 		char **Fstr = (char**) malloc(NS*sizeof(char*));
 		size_t *MAXLEN = (size_t*) malloc(NS*sizeof(size_t*));
@@ -954,7 +954,7 @@
 			}
 			else if (mxIsCell(F[k])) {
 				size_t maxlen = 0;
-				for (mwIndex m = 0; m<M; m++) {
+				for (size_t m = 0; m<M; m++) {
 					mxArray *f = mxGetCell(F[k],m);
 					if (mxIsChar(f) || mxIsEmpty(f)) {
 						size_t len = mxGetNumberOfElements(f);
@@ -978,7 +978,7 @@
 		count += fwrite(H2, 1, HeadLen2, fid);
 		/* write OBS header line */
 		count += fwrite(LO, 1, strlen(LO), fid);
-		for (mwIndex m = 0; m < M; m++) {
+		for (size_t m = 0; m < M; m++) {
 			for (uint16_t k = 0; k < NS; k++) {
 
 				if (*(int16_t*)(H2+k*sz2) == b_endian_u16(1)) {