diff options
author | simon | 2008-10-30 14:59:23 +0000 |
---|---|---|
committer | simon | 2008-10-30 14:59:23 +0000 |
commit | 2be2cd11107322ac6b9ed1870191686d51a71410 (patch) | |
tree | ae390edeacd63d7d903633e58dac9282ced68452 /src/matrixOperations | |
parent | 22827e45d6fa043ee7f29da84bdfc04d6d953778 (diff) | |
download | scilab2c-2be2cd11107322ac6b9ed1870191686d51a71410.tar.gz scilab2c-2be2cd11107322ac6b9ed1870191686d51a71410.tar.bz2 scilab2c-2be2cd11107322ac6b9ed1870191686d51a71410.zip |
corrected a nasty ignored case
Diffstat (limited to 'src/matrixOperations')
-rw-r--r-- | src/matrixOperations/eye/Makefile.am | 29 | ||||
-rw-r--r-- | src/matrixOperations/eye/Makefile.in | 27 | ||||
-rw-r--r-- | src/matrixOperations/eye/ceyea.c | 7 | ||||
-rw-r--r-- | src/matrixOperations/eye/deyea.c | 7 | ||||
-rw-r--r-- | src/matrixOperations/eye/seyea.c | 7 | ||||
-rw-r--r-- | src/matrixOperations/eye/testMatrixEye.c | 190 | ||||
-rw-r--r-- | src/matrixOperations/eye/zeyea.c | 10 |
7 files changed, 209 insertions, 68 deletions
diff --git a/src/matrixOperations/eye/Makefile.am b/src/matrixOperations/eye/Makefile.am index c1087ce5..74280acd 100644 --- a/src/matrixOperations/eye/Makefile.am +++ b/src/matrixOperations/eye/Makefile.am @@ -12,9 +12,7 @@ libMatrixEye_la_CFLAGS = -I $(top_builddir)/type \ -I $(top_builddir)/matrixOperations/includes \ - -I $(top_builddir)/auxiliaryFunctions/includes \ - -I $(top_builddir)/includes \ - -I $(top_builddir)/elementaryFunctions/includes + -I $(top_builddir)/includes instdir = $(top_builddir)/lib @@ -27,36 +25,19 @@ libMatrixEye_la_SOURCES = $(HEAD) \ seyea.c \ deyea.c \ ceyea.c \ - zeyea.c + zeyea.c + + check_PROGRAMS = testMatrixEye check_LDADD = $(top_builddir)/type/libDoubleComplex.la \ $(top_builddir)/type/libFloatComplex.la \ - $(top_builddir)/operations/addition/libAddition.la \ - $(top_builddir)/auxiliaryFunctions/abs/libAbs.la \ - $(top_builddir)/auxiliaryFunctions/sign/libSign.la \ - $(top_builddir)/auxiliaryFunctions/pythag/libPythag.la \ - $(top_builddir)/auxiliaryFunctions/frexp/libFrexp.la \ - $(top_builddir)/elementaryFunctions/sqrt/libSqrt.la \ - $(top_builddir)/elementaryFunctions/exp/libExp.la \ - $(top_builddir)/elementaryFunctions/cos/libCos.la \ - $(top_builddir)/elementaryFunctions/pow/libPow.la \ - $(top_builddir)/elementaryFunctions/log/libLog.la \ - $(top_builddir)/elementaryFunctions/log1p/libLog1p.la \ - $(top_builddir)/elementaryFunctions/lnp1m1/libLnp1m1.la\ - $(top_builddir)/elementaryFunctions/cosh/libCosh.la \ - $(top_builddir)/elementaryFunctions/sin/libSin.la \ - $(top_builddir)/elementaryFunctions/sinh/libSinh.la \ - $(top_builddir)/lib/lapack/libscilapack.la \ - $(top_builddir)/lib/blas/libsciblas.la \ libMatrixEye.la check_INCLUDES = -I $(top_builddir)/type \ -I $(top_builddir)/matrixOperations/includes \ - -I $(top_builddir)/auxiliaryFunctions/includes \ - -I $(top_builddir)/includes \ - -I $(top_builddir)/elementaryFunctions/includes + -I $(top_builddir)/includes testMatrixEye_SOURCES = testMatrixEye.c testMatrixEye_LDADD = $(check_LDADD) diff --git a/src/matrixOperations/eye/Makefile.in b/src/matrixOperations/eye/Makefile.in index 4131d74b..62ae1f2f 100644 --- a/src/matrixOperations/eye/Makefile.in +++ b/src/matrixOperations/eye/Makefile.in @@ -196,9 +196,7 @@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ libMatrixEye_la_CFLAGS = -I $(top_builddir)/type \ -I $(top_builddir)/matrixOperations/includes \ - -I $(top_builddir)/auxiliaryFunctions/includes \ - -I $(top_builddir)/includes \ - -I $(top_builddir)/elementaryFunctions/includes + -I $(top_builddir)/includes instdir = $(top_builddir)/lib pkglib_LTLIBRARIES = libMatrixEye.la @@ -207,34 +205,15 @@ libMatrixEye_la_SOURCES = $(HEAD) \ seyea.c \ deyea.c \ ceyea.c \ - zeyea.c + zeyea.c check_LDADD = $(top_builddir)/type/libDoubleComplex.la \ $(top_builddir)/type/libFloatComplex.la \ - $(top_builddir)/operations/addition/libAddition.la \ - $(top_builddir)/auxiliaryFunctions/abs/libAbs.la \ - $(top_builddir)/auxiliaryFunctions/sign/libSign.la \ - $(top_builddir)/auxiliaryFunctions/pythag/libPythag.la \ - $(top_builddir)/auxiliaryFunctions/frexp/libFrexp.la \ - $(top_builddir)/elementaryFunctions/sqrt/libSqrt.la \ - $(top_builddir)/elementaryFunctions/exp/libExp.la \ - $(top_builddir)/elementaryFunctions/cos/libCos.la \ - $(top_builddir)/elementaryFunctions/pow/libPow.la \ - $(top_builddir)/elementaryFunctions/log/libLog.la \ - $(top_builddir)/elementaryFunctions/log1p/libLog1p.la \ - $(top_builddir)/elementaryFunctions/lnp1m1/libLnp1m1.la\ - $(top_builddir)/elementaryFunctions/cosh/libCosh.la \ - $(top_builddir)/elementaryFunctions/sin/libSin.la \ - $(top_builddir)/elementaryFunctions/sinh/libSinh.la \ - $(top_builddir)/lib/lapack/libscilapack.la \ - $(top_builddir)/lib/blas/libsciblas.la \ libMatrixEye.la check_INCLUDES = -I $(top_builddir)/type \ -I $(top_builddir)/matrixOperations/includes \ - -I $(top_builddir)/auxiliaryFunctions/includes \ - -I $(top_builddir)/includes \ - -I $(top_builddir)/elementaryFunctions/includes + -I $(top_builddir)/includes testMatrixEye_SOURCES = testMatrixEye.c testMatrixEye_LDADD = $(check_LDADD) diff --git a/src/matrixOperations/eye/ceyea.c b/src/matrixOperations/eye/ceyea.c index a0ef2759..735018c6 100644 --- a/src/matrixOperations/eye/ceyea.c +++ b/src/matrixOperations/eye/ceyea.c @@ -14,10 +14,11 @@ void ceyea(floatComplex *in, int _iRows, int _iCols) { - int i ; + int i , j ; - for ( i = 0 ; i < _iRows*_iCols ; i++ ) - in[i] = FloatComplex ( (i%(_iCols+1) == 0)?1.0f:0.0f , 0) ; + for ( i = 0 ; i < _iCols ; i++ ) + for ( j = 0 ; j < _iRows ; j++ ) + in[i*_iRows + j] = FloatComplex ( (i == j)? 1.0f:0 , 0) ; } diff --git a/src/matrixOperations/eye/deyea.c b/src/matrixOperations/eye/deyea.c index 8152ac22..eed9c05d 100644 --- a/src/matrixOperations/eye/deyea.c +++ b/src/matrixOperations/eye/deyea.c @@ -14,9 +14,10 @@ void deyea(double *in, int _iRows, int _iCols) { - int i ; + int i, j ; - for ( i = 0 ; i < _iRows*_iCols ; i++ ) - in[i] = (i%(_iCols+1) == 0)?1:0 ; + for ( i = 0 ; i < _iCols ; i++ ) + for ( j = 0 ; j < _iRows ; j++ ) + in[i*_iRows + j] = (i == j)?1:0 ; } diff --git a/src/matrixOperations/eye/seyea.c b/src/matrixOperations/eye/seyea.c index 91b56662..2f256b86 100644 --- a/src/matrixOperations/eye/seyea.c +++ b/src/matrixOperations/eye/seyea.c @@ -14,9 +14,10 @@ void seyea(float* in, int _iRows, int _iCols) { - int i ; + int i, j ; - for ( i = 0 ; i < _iRows*_iCols ; i++ ) - in[i] = (i%(_iCols+1) == 0)?1.0f:0.0f ; + for ( i = 0 ; i < _iCols ; i++ ) + for ( j = 0 ; j < _iRows ; j++ ) + in[i*_iRows + j] = (i == j)?1.0f:0 ; } diff --git a/src/matrixOperations/eye/testMatrixEye.c b/src/matrixOperations/eye/testMatrixEye.c index adb7d113..e47edcf3 100644 --- a/src/matrixOperations/eye/testMatrixEye.c +++ b/src/matrixOperations/eye/testMatrixEye.c @@ -17,17 +17,22 @@ #include "eye.h" #define LEADDIM 10 +#define ROWS 10 +#define COLS 5 + +#define ROWS2 5 +#define COLS2 10 static void deyeaTest ( void ) { - int i = 0 ; + int i, j = 0 ; double result = 0 ; - double in [LEADDIM*LEADDIM] ; + double in2 [ROWS * COLS]; + double in3 [ROWS2 * COLS2]; deyea ( in , LEADDIM , LEADDIM ) ; - for ( i = 0 ; i < LEADDIM*LEADDIM ; i++ ) { if ( i%(LEADDIM+1) == 0 ) @@ -42,17 +47,61 @@ static void deyeaTest ( void ) else assert ( fabs ( in[i] - result) / fabs( in[i]) < 1e-14 ) ; } + + deyea ( in2, ROWS, COLS ); + for ( i = 0 ; i < ROWS ; i++ ) + { + for ( j = 0 ; j < COLS ; ++j ) + { + if ( i == j ) + result = 1 ; + else + result = 0 ; + + printf ( "\t\t in[%d, %d] : %e\tresult : %e\tassert : %e \n" , i, j, + in[i * ROWS + j] , result , + fabs( in[i * ROWS + j] - result) / fabs( in[i * ROWS + j]) ) ; + + if ( in[i * ROWS + j] < 1e-14 && result < 1e-14 ) + assert(1); + else + assert ( fabs ( in[i * ROWS + j] - result) / fabs( in[i * ROWS + j]) < 1e-14 ) ; + } + } + + deyea ( in3, ROWS2, COLS2); + for ( j = 0 ; j < COLS2 ; ++j ) + { + for ( i = 0 ; i < ROWS2 ; i++ ) + { + if ( i == j ) + result = 1 ; + else + result = 0 ; + + printf ( "\t\t in[%d, %d] : %e\tresult : %e\tassert : %e \n" , i, j, + in3[j * ROWS2 + i] , result , + fabs( in3[j * ROWS2 + i] - result) / fabs( in3[j * ROWS2 + i]) ) ; + + if ( in3[j * ROWS2 + i] < 1e-14 && result < 1e-14 ) + assert(1); + else + assert ( fabs ( in3[j * ROWS2 + i] - result) / fabs( in3[j * ROWS2 + i]) < 1e-14 ) ; + } + } + } static void seyeaTest ( void ) { - int i = 0 ; + int i, j = 0 ; float result = 0 ; float in[LEADDIM*LEADDIM] ; - + float in2 [ROWS * COLS]; + float in3 [ROWS2 * COLS2]; seyea ( in , LEADDIM , LEADDIM ) ; for ( i = 0 ; i < LEADDIM*LEADDIM ; i++) @@ -68,6 +117,49 @@ static void seyeaTest ( void ) else assert ( fabs ( in[i] - result) / fabs( in[i]) < 1e-6 ) ; } + + seyea ( in2, ROWS, COLS ); + for ( i = 0 ; i < ROWS ; i++ ) + { + for ( j = 0 ; j < COLS ; ++j ) + { + if ( i == j ) + result = 1 ; + else + result = 0 ; + + printf ( "\t\t in[%d, %d] : %e\tresult : %e\tassert : %e \n" , i, j, + in[i * ROWS + j] , result , + fabs( in[i * ROWS + j] - result) / fabs( in[i * ROWS + j]) ) ; + + if ( in[i * ROWS + j] < 1e-8 && result < 1e-8 ) + assert(1); + else + assert ( fabs ( in[i * ROWS + j] - result) / fabs( in[i * ROWS + j]) < 1e-8 ) ; + } + } + + seyea ( in3, ROWS2, COLS2); + for ( j = 0 ; j < COLS2 ; ++j ) + { + for ( i = 0 ; i < ROWS2 ; i++ ) + { + if ( i == j ) + result = 1 ; + else + result = 0 ; + + printf ( "\t\t in[%d, %d] : %e\tresult : %e\tassert : %e \n" , i, j, + in3[j * ROWS2 + i] , result , + fabs( in3[j * ROWS2 + i] - result) / fabs( in3[j * ROWS2 + i]) ) ; + + if ( in3[j * ROWS2 + i] < 1e-14 && result < 1e-14 ) + assert(1); + else + assert ( fabs ( in3[j * ROWS2 + i] - result) / fabs( in3[j * ROWS2 + i]) < 1e-14 ) ; + } + } + } @@ -138,11 +230,80 @@ static void ceyeaTest ( void ) } } +/* EYES TEST */ + +static void ceyesTest ( void ) +{ + + + floatComplex result = FloatComplex ( 1.0f , 0 ) ; + + floatComplex in = FloatComplex ( LEADDIM, LEADDIM ) ; + + in = ceyes ( in ) ; + + + + assert ( (creals(in) - creals(result)) / fabs( creals(in)) < 1e-6 ) ; + assert ( cimags (in) == 0) ; +} + + + + + +static void zeyesTest ( void ) +{ + + doubleComplex result = DoubleComplex ( 1 , 0 ) ; + + doubleComplex in = DoubleComplex ( LEADDIM , LEADDIM ) ; + + in = zeyes ( in ) ; + + + assert ( (zreals(in) - zreals(result)) / fabs( zreals(in)) < 1e-16 ) ; + assert ( zimags (in) == 0) ; +} + + + +static void deyesTest ( void ) +{ + + + double result = 1 ; + + double in = LEADDIM ; + + in = deyes ( in ) ; + + + assert ( (in - result) / in < 1e-16 ) ; ; +} + + + +static void seyesTest ( void ) +{ + + + float result = 1.0f ; + + float in = 154.0f ; + + in = seyes ( in ) ; + + + assert ( (in - result) / in < 1e-8 ) ; + +} + static int testEye(void) { - printf("\n>>>> Matrix Exponential Tests\n"); + printf("\n>>>> Matrix Eye Tests\n"); printf("\t>>>> Matrix Double Realt Tests\n"); deyeaTest(); @@ -156,6 +317,23 @@ static int testEye(void) { printf("\n\n\n"); printf("\t>>>> Matrix Double Complex Tests\n"); zeyeaTest(); + + + + + printf("\t>>>> Matrix Double Realt Tests\n"); + deyesTest(); + + printf("\n\n\t>>>> Matrix Float Realt Tests\n"); + seyesTest(); + + printf("\n\n\n"); + printf("\t>>>> Matrix Float Complex Tests\n"); + ceyesTest(); + + printf("\n\n\n"); + printf("\t>>>> Matrix Double Complex Tests\n"); + zeyesTest(); return 0; } diff --git a/src/matrixOperations/eye/zeyea.c b/src/matrixOperations/eye/zeyea.c index cb85dba2..622cc48e 100644 --- a/src/matrixOperations/eye/zeyea.c +++ b/src/matrixOperations/eye/zeyea.c @@ -14,11 +14,11 @@ void zeyea(doubleComplex *in, int _iRows, int _iCols) { - int i ; - - for ( i = 0 ; i < _iRows*_iCols ; i++ ) - in[i] = DoubleComplex ( (i%(_iCols+1) == 0)?1:0 , 0) ; - + int i , j ; + + for ( i = 0 ; i < _iCols ; i++ ) + for ( j = 0 ; j < _iRows ; j++ ) + in[i*_iRows + j] = DoubleComplex ( (i == j)? 1:0 , 0) ; } |