diff options
Diffstat (limited to 'src/matrixOperations/eye/testMatrixEye.c')
-rw-r--r-- | src/matrixOperations/eye/testMatrixEye.c | 190 |
1 files changed, 184 insertions, 6 deletions
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; } |