From a2c6ed14519f019b157eac1aac66d9528dd9208a Mon Sep 17 00:00:00 2001 From: simon Date: Mon, 24 Aug 2009 09:20:03 +0000 Subject: updating *find2d for loops order in order to have the result in the same result than scilab updating *find* prototype , adding to all a argument "int max" , in order to avoid useless computation when only a limited number of results is requested --- src/c/auxiliaryFunctions/find/cfinda.c | 4 +- src/c/auxiliaryFunctions/find/dfinda.c | 4 +- src/c/auxiliaryFunctions/find/sfinda.c | 4 +- src/c/auxiliaryFunctions/find/zfinda.c | 4 +- src/c/auxiliaryFunctions/find2d/cfind2da.c | 8 ++- src/c/auxiliaryFunctions/find2d/dfind2da.c | 8 ++- src/c/auxiliaryFunctions/find2d/sfind2da.c | 10 +-- src/c/auxiliaryFunctions/find2d/testFind2d.c | 62 ++++++++--------- src/c/auxiliaryFunctions/find2d/zfind2da.c | 8 ++- src/c/auxiliaryFunctions/includes/find.h | 12 ++-- src/c/auxiliaryFunctions/includes/find2d.h | 12 ++-- src/c/auxiliaryFunctions/interfaces/int_conj.h | 2 +- src/c/auxiliaryFunctions/interfaces/int_find.h | 90 ++++++++++++------------- src/c/auxiliaryFunctions/interfaces/int_isnan.h | 8 +-- src/c/auxiliaryFunctions/interfaces/int_max.h | 4 +- src/c/auxiliaryFunctions/interfaces/int_min.h | 4 +- 16 files changed, 131 insertions(+), 113 deletions(-) diff --git a/src/c/auxiliaryFunctions/find/cfinda.c b/src/c/auxiliaryFunctions/find/cfinda.c index f846ce50..819d423b 100644 --- a/src/c/auxiliaryFunctions/find/cfinda.c +++ b/src/c/auxiliaryFunctions/find/cfinda.c @@ -12,7 +12,7 @@ #include "find.h" -void cfinda(floatComplex* z, int size, float *out, int *indiceOut) { +void cfinda(floatComplex* z, int size, float *out, int *indiceOut , int max) { int i = 0; indiceOut[1]=0; @@ -20,6 +20,8 @@ void cfinda(floatComplex* z, int size, float *out, int *indiceOut) { out[0]=-1; for (i = 0; i < size ; ++i) { + /*to avoid useless search if we only want to find the max first founded value */ + if (indiceOut[1] == max ) return ; if (creals(z[i]) != 0 || cimags(z[i]) != 0) { out[indiceOut[1]] = (float)(i+1); indiceOut[1]++; diff --git a/src/c/auxiliaryFunctions/find/dfinda.c b/src/c/auxiliaryFunctions/find/dfinda.c index 986be373..1f07b674 100644 --- a/src/c/auxiliaryFunctions/find/dfinda.c +++ b/src/c/auxiliaryFunctions/find/dfinda.c @@ -13,7 +13,7 @@ #include "find.h" -void dfinda(double* x, int size ,double *out, int *indiceOut) { +void dfinda(double* x, int size ,double *out, int *indiceOut , int max ) { int i = 0; indiceOut[1]=0; @@ -22,6 +22,8 @@ void dfinda(double* x, int size ,double *out, int *indiceOut) { for (i = 0; i < size ; ++i) { + /*to avoid useless search if we only want to find the max first founded value */ + if (indiceOut[1] == max ) return ; if (x[i] != 0) { out[indiceOut[1]] = (double)(i+1); indiceOut[1]++; diff --git a/src/c/auxiliaryFunctions/find/sfinda.c b/src/c/auxiliaryFunctions/find/sfinda.c index 6a23a9dd..73c86d37 100644 --- a/src/c/auxiliaryFunctions/find/sfinda.c +++ b/src/c/auxiliaryFunctions/find/sfinda.c @@ -12,7 +12,7 @@ #include "find.h" -void sfinda(float* x, int size, float* out, int *indiceOut) { +void sfinda(float* x, int size, float* out, int *indiceOut , int max ) { int i = 0; indiceOut[1]=0; @@ -22,6 +22,8 @@ void sfinda(float* x, int size, float* out, int *indiceOut) { for (i = 0; i < size ; ++i) { + /*to avoid useless search if we only want to find the max first founded value */ + if (indiceOut[1] == max ) return ; if (x[i] != 0) { out[indiceOut[1]] = (float)(i+1); indiceOut[1]++; diff --git a/src/c/auxiliaryFunctions/find/zfinda.c b/src/c/auxiliaryFunctions/find/zfinda.c index f9c3f970..0fa7e178 100644 --- a/src/c/auxiliaryFunctions/find/zfinda.c +++ b/src/c/auxiliaryFunctions/find/zfinda.c @@ -12,7 +12,7 @@ #include "find.h" -void zfinda(doubleComplex* z, int size, double *out, int* indiceOut) { +void zfinda(doubleComplex* z, int size, double *out, int* indiceOut, int max ) { int i = 0; indiceOut[1]=0; @@ -20,6 +20,8 @@ void zfinda(doubleComplex* z, int size, double *out, int* indiceOut) { out[0]=-1; for (i = 0; i < size ; ++i) { + /*to avoid useless search if we only want to find the max first founded value */ + if (indiceOut[1] == max ) return ; if (zreals(z[i]) != 0 || zimags(z[i]) != 0) { out[indiceOut[1]] = (double)(i+1); indiceOut[1]++; diff --git a/src/c/auxiliaryFunctions/find2d/cfind2da.c b/src/c/auxiliaryFunctions/find2d/cfind2da.c index 8aefa06d..e44bab0e 100644 --- a/src/c/auxiliaryFunctions/find2d/cfind2da.c +++ b/src/c/auxiliaryFunctions/find2d/cfind2da.c @@ -13,7 +13,7 @@ #include "find2d.h" #include -void cfind2da(floatComplex* x, int rows, int columns, float* out1,int* indiceOut1, float* out2,int* indiceOut2) { +void cfind2da(floatComplex* x, int rows, int columns, float* out1,int* indiceOut1, float* out2,int* indiceOut2,int max) { int i = 0, j=0; indiceOut1[1] = 0; @@ -21,8 +21,10 @@ void cfind2da(floatComplex* x, int rows, int columns, float* out1,int* indiceOut out1[0]=-1; out2[0]=-1; - for (i = 0; i < rows ; ++i) { - for (j = 0; j < columns ; ++j) { + for (j = 0; j < columns ; ++j){ + for (i = 0; i < rows ; ++i) { + /*to avoid useless search if we only want to find the max first founded value */ + if (indiceOut1[1] == max ) return ; if ((creals(x[j*rows+i]) != 0) || (cimags(x[j*rows+i])!=0) ) { out1[indiceOut1[1]] = (float)(i+1); diff --git a/src/c/auxiliaryFunctions/find2d/dfind2da.c b/src/c/auxiliaryFunctions/find2d/dfind2da.c index f4e80de8..74551817 100644 --- a/src/c/auxiliaryFunctions/find2d/dfind2da.c +++ b/src/c/auxiliaryFunctions/find2d/dfind2da.c @@ -13,7 +13,7 @@ #include "find2d.h" #include -void dfind2da(double* x, int rows, int columns, double* out1,int* indiceOut1, double* out2,int* indiceOut2) { +void dfind2da(double* x, int rows, int columns, double* out1,int* indiceOut1, double* out2,int* indiceOut2,int max) { int i = 0, j=0; indiceOut1[1] = 0; @@ -21,8 +21,10 @@ void dfind2da(double* x, int rows, int columns, double* out1,int* indiceOut1, do out1[0]=-1; out2[0]=-1; - for (i = 0; i < rows ; ++i) { - for (j = 0; j < columns ; ++j) { + for (j = 0; j < columns ; ++j){ + for (i = 0; i < rows ; ++i) { + /*to avoid useless search if we only want to find the max first founded value */ + if (indiceOut1[1] == max ) return ; if (x[j*rows+i] != 0) { out1[indiceOut1[1]] = (double)(i+1); diff --git a/src/c/auxiliaryFunctions/find2d/sfind2da.c b/src/c/auxiliaryFunctions/find2d/sfind2da.c index a0f9fae6..241e1e58 100644 --- a/src/c/auxiliaryFunctions/find2d/sfind2da.c +++ b/src/c/auxiliaryFunctions/find2d/sfind2da.c @@ -12,8 +12,8 @@ #include "find2d.h" #include -#include -void sfind2da(float* x, int rows, int columns, float* out1,int* indiceOut1, float* out2,int* indiceOut2) { + +void sfind2da(float* x, int rows, int columns, float* out1,int* indiceOut1, float* out2,int* indiceOut2,int max) { int i = 0, j=0; indiceOut1[1] = 0; @@ -21,8 +21,10 @@ void sfind2da(float* x, int rows, int columns, float* out1,int* indiceOut1, floa out1[0]=-1; out2[0]=-1; - for (i = 0; i < rows ; ++i) { - for (j = 0; j < columns ; ++j) { + for (j = 0; j < columns ; ++j){ + for (i = 0; i < rows ; ++i) { + /*to avoid useless search if we only want to find the max first founded value */ + if (indiceOut1[1] == max ) return ; if (x[j*rows+i] != 0) { out1[indiceOut1[1]] = (float)(i+1); diff --git a/src/c/auxiliaryFunctions/find2d/testFind2d.c b/src/c/auxiliaryFunctions/find2d/testFind2d.c index b726ab7d..a6f38b56 100644 --- a/src/c/auxiliaryFunctions/find2d/testFind2d.c +++ b/src/c/auxiliaryFunctions/find2d/testFind2d.c @@ -30,7 +30,7 @@ int sfind2daTest() { printf(">> Floats \n"); /* Test tab 1 ligne 6 colonnes */ - sfind2da(goodArray, 1, 6, out1Good, size1, out2Good, size2); + sfind2da(goodArray, 1, 6, out1Good, size1, out2Good, size2 , -1); for (i=0;i> Double \n"); /* Test tab 1 ligne 6 colonnes */ - dfind2da(goodArray, 1, 6, out1Good, size1, out2Good, size2); + dfind2da(goodArray, 1, 6, out1Good, size1, out2Good, size2,-1); for (i=0;i> Float Complex \n"); /* Test tab 1 ligne 6 colonnes */ - cfind2da(goodArray, 1, 6, out1Good, size1, out2Good, size2); + cfind2da(goodArray, 1, 6, out1Good, size1, out2Good, size2,-1); for (i=0;i> Double Complex \n"); /* Test tab 1 ligne 6 colonnes */ - zfind2da(goodArray, 1, 6, out1Good, size1, out2Good, size2); + zfind2da(goodArray, 1, 6, out1Good, size1, out2Good, size2,-1); for (i=0;i -void zfind2da(doubleComplex* x, int rows, int columns, double* out1,int* indiceOut1, double* out2,int* indiceOut2) { +void zfind2da(doubleComplex* x, int rows, int columns, double* out1,int* indiceOut1, double* out2,int* indiceOut2,int max) { int i = 0, j=0; indiceOut1[1] = 0; @@ -21,8 +21,10 @@ void zfind2da(doubleComplex* x, int rows, int columns, double* out1,int* indiceO out1[0]=-1; out2[0]=-1; - for (i = 0; i < rows ; ++i) { - for (j = 0; j < columns ; ++j) { + for (j = 0; j < columns ; ++j){ + for (i = 0; i < rows ; ++i) { + /*to avoid useless search if we only want to find the max first founded value */ + if (indiceOut1[1] == max ) return ; if ((zreals(x[j*rows+i]) != 0) || (zimags(x[j*rows+i])!=0) ) { out1[indiceOut1[1]] = (double)(i+1); diff --git a/src/c/auxiliaryFunctions/includes/find.h b/src/c/auxiliaryFunctions/includes/find.h index 202219c8..7cc876e9 100644 --- a/src/c/auxiliaryFunctions/includes/find.h +++ b/src/c/auxiliaryFunctions/includes/find.h @@ -22,23 +22,27 @@ extern "C" { #endif /* ** \brief Float Find function +** max is an integer giving the maximum number of indices to return. (use -1 to search them all) */ -EXTERN_AUXFUNCT void sfinda(float* x, int size, float *out, int *sizeOut); +EXTERN_AUXFUNCT void sfinda(float* x, int size, float *out, int *sizeOut,int max); /* ** \brief Double Find function +** max is an integer giving the maximum number of indices to return. (use -1 to search them all) */ -EXTERN_AUXFUNCT void dfinda(double*x, int size, double *out, int *sizeOut); +EXTERN_AUXFUNCT void dfinda(double*x, int size, double *out, int *sizeOut,int max); /* ** \brief Float Complex Find function +** max is an integer giving the maximum number of indices to return. (use -1 to search them all) */ -EXTERN_AUXFUNCT void cfinda(floatComplex* z, int size, float *out, int *sizeOut); +EXTERN_AUXFUNCT void cfinda(floatComplex* z, int size, float *out, int *sizeOut,int max); /* ** \brief Double Complex Find function +** max is an integer giving the maximum number of indices to return. (use -1 to search them all) */ -EXTERN_AUXFUNCT void zfinda(doubleComplex* z, int size, double *out, int *sizeOut); +EXTERN_AUXFUNCT void zfinda(doubleComplex* z, int size, double *out, int *sizeOut,int max); #ifdef __cplusplus } /* extern "C" */ diff --git a/src/c/auxiliaryFunctions/includes/find2d.h b/src/c/auxiliaryFunctions/includes/find2d.h index 72c036d5..6e365107 100644 --- a/src/c/auxiliaryFunctions/includes/find2d.h +++ b/src/c/auxiliaryFunctions/includes/find2d.h @@ -22,23 +22,27 @@ extern "C" { #endif /* ** \brief Float Find function +** max is an integer giving the maximum number of indices to return. (use -1 to search them all) */ -EXTERN_AUXFUNCT void sfind2da(float* x, int rows, int columns, float* out1, int* sizeOut1, float* out2, int* sizeOut2); +EXTERN_AUXFUNCT void sfind2da(float* x, int rows, int columns, float* out1, int* sizeOut1, float* out2, int* sizeOut2,int max); /* ** \brief Double Find function +** max is an integer giving the maximum number of indices to return. (use -1 to search them all) */ -EXTERN_AUXFUNCT void dfind2da(double* x, int rows, int columns, double* out1, int* sizeOut1, double* out2, int* sizeOut2); +EXTERN_AUXFUNCT void dfind2da(double* x, int rows, int columns, double* out1, int* sizeOut1, double* out2, int* sizeOut2,int max); /* ** \brief Float Complex Find function +** max is an integer giving the maximum number of indices to return. (use -1 to search them all) */ -EXTERN_AUXFUNCT void cfind2da(floatComplex* z, int rows, int columns, float* out1, int* sizeOut1, float* out2, int* sizeOut2); +EXTERN_AUXFUNCT void cfind2da(floatComplex* z, int rows, int columns, float* out1, int* sizeOut1, float* out2, int* sizeOut2,int max); /* ** \brief Double Complex Find function +** max is an integer giving the maximum number of indices to return. (use -1 to search them all) */ -EXTERN_AUXFUNCT void zfind2da(doubleComplex* z, int rows, int columns, double* out1, int* sizeOut1, double* out2, int* sizeOut2); +EXTERN_AUXFUNCT void zfind2da(doubleComplex* z, int rows, int columns, double* out1, int* sizeOut1, double* out2, int* sizeOut2,int max); #ifdef __cplusplus } /* extern "C" */ diff --git a/src/c/auxiliaryFunctions/interfaces/int_conj.h b/src/c/auxiliaryFunctions/interfaces/int_conj.h index e37819e4..f54de243 100644 --- a/src/c/auxiliaryFunctions/interfaces/int_conj.h +++ b/src/c/auxiliaryFunctions/interfaces/int_conj.h @@ -15,7 +15,7 @@ #ifndef __INT_CONJ_H__ #define __INT_CONJ_H__ -#define copy(in, size, out) {int i;for (i=0; i