summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsimon2008-07-29 08:34:21 +0000
committersimon2008-07-29 08:34:21 +0000
commit20945137a590cc67b2a7475e2dfbc6f6890352aa (patch)
treeab74ef6c9db3782a6af8ced02b74d723f7e67ae9
parentea392df771cf9aa7acd7ec8b38dad404fd72bfa9 (diff)
downloadscilab2c-20945137a590cc67b2a7475e2dfbc6f6890352aa.tar.gz
scilab2c-20945137a590cc67b2a7475e2dfbc6f6890352aa.tar.bz2
scilab2c-20945137a590cc67b2a7475e2dfbc6f6890352aa.zip
updated test and functions for complex matrix division , but they're still not working
-rw-r--r--src/matrixOperations/division/cldiva.c65
-rw-r--r--src/matrixOperations/division/crdiva.c56
-rw-r--r--src/matrixOperations/division/testMatrixLDivision.c59
-rw-r--r--src/matrixOperations/division/testMatrixRDivision.c44
4 files changed, 210 insertions, 14 deletions
diff --git a/src/matrixOperations/division/cldiva.c b/src/matrixOperations/division/cldiva.c
new file mode 100644
index 00000000..021ebf4a
--- /dev/null
+++ b/src/matrixOperations/division/cldiva.c
@@ -0,0 +1,65 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2008-2008 - INRIA - Allan SIMON
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+
+/**** WARNING NOT WORK AT ALL FOR THE MOMENT ***/
+/**** Because of problem of conversion float-> double ****/
+#include "matrixDivision.h"
+#include "lapack.h"
+#include <string.h>
+#include <stdio.h>
+void cldiva ( floatComplex* in1, int lines1, int columns1 ,
+ floatComplex* in2, int lines2, int columns2 ,
+ floatComplex* out ){
+
+ int i = 0 ;
+ /* these 3 variable are created to permit to use the value in the fortran functions
+ because they need doubleComplex matrix as arguments and we can't cast directly the pointers
+ without having problems , i know that's ugly */
+ doubleComplex *dblin1 = NULL;
+ doubleComplex *dblin2 = NULL;
+ doubleComplex *dblout = NULL;
+
+
+
+ /* Array allocations*/
+ dblin1 = (doubleComplex*)malloc(sizeof(doubleComplex) * (unsigned int)columns1 * (unsigned int)lines1);
+ dblin2 = (doubleComplex*)malloc(sizeof(doubleComplex) * (unsigned int)columns2 * (unsigned int)lines2);
+ dblout = (doubleComplex*)malloc(sizeof(doubleComplex) * (unsigned int)lines1 * (unsigned int)lines2);
+
+
+
+ /*copy and cast all the floatComplex value into doubleComplex value */
+ for ( i = 0 ; i < lines1 * columns1 ; i ++ )
+ {
+ dblin1[i] = DoubleComplex ( (double) creals( in1[i]) , double cimags ( in1[i])) ;
+ }
+
+ for ( i = 0 ; i < lines2 * columns2 ; i ++ )
+ {
+ dblin2[i] = DoubleComplex ( (double) creals( in2[i]) , double cimags ( in2[i])) ;
+ }
+
+ zldiva( dblin1 , lines1 , columns1 , dblin2 , lines2 , columns2 , dblout );
+
+
+ for ( i = 0 ; i < Min(lines2,columns2) * lines1 ; i++ )
+ {
+ out[i] = FloatComplex ((float) zreals ( dblout[i]) , (float) zimags ( dblout[i])) ;
+
+ }
+
+ free ( dblin1);
+ free ( dblin2);
+ free ( dblout);
+
+}
diff --git a/src/matrixOperations/division/crdiva.c b/src/matrixOperations/division/crdiva.c
index a3e528df..974a87c7 100644
--- a/src/matrixOperations/division/crdiva.c
+++ b/src/matrixOperations/division/crdiva.c
@@ -10,12 +10,56 @@
*
*/
+
/**** WARNING NOT WORK AT ALL FOR THE MOMENT ***/
-/*
+/**** Because of problem of conversion float-> double ****/
+#include "matrixDivision.h"
+#include "lapack.h"
+#include <string.h>
+#include <stdio.h>
+void cldiva ( floatComplex* in1, int lines1, int columns1 ,
+ floatComplex* in2, int lines2, int columns2 ,
+ floatComplex* out ){
+
+ int i = 0 ;
+ /* these 3 variable are created to permit to use the value in the fortran functions
+ because they need doubleComplex matrix as arguments and we can't cast directly the pointers
+ without having problems , i know that's ugly */
+ doubleComplex *dblin1 = NULL;
+ doubleComplex *dblin2 = NULL;
+ doubleComplex *dblout = NULL;
+
+
+
+ /* Array allocations*/
+ dblin1 = (doubleComplex*)malloc(sizeof(doubleComplex) * (unsigned int)columns1 * (unsigned int)lines1);
+ dblin2 = (doubleComplex*)malloc(sizeof(doubleComplex) * (unsigned int)columns2 * (unsigned int)lines2);
+ dblout = (doubleComplex*)malloc(sizeof(doubleComplex) * (unsigned int)lines1 * (unsigned int)lines2);
+
+
+
+ /*copy and cast all the floatComplex value into doubleComplex value */
+ for ( i = 0 ; i < lines1 * columns1 ; i ++ )
+ {
+ dblin1[i] = DoubleComplex ( (double) creals( in1[i]) , double cimags ( in1[i])) ;
+ }
+
+ for ( i = 0 ; i < lines2 * columns2 ; i ++ )
+ {
+ dblin2[i] = DoubleComplex ( (double) creals( in2[i]) , double cimags ( in2[i])) ;
+ }
+
+ zrdiva( dblin1 , lines1 , columns1 , dblin2 , lines2 , columns2 , dblout );
+
+
+ for ( i = 0 ; i < Min(lines2,columns2) * lines1 ; i++ )
+ {
+ out[i] = FloatComplex ((float) zreals ( dblout[i]) , (float) zimags ( dblout[i])) ;
+
+ }
- void crdiva ( floatComplex * in1, int it1, floatComplex * in2, int it2, floatComplex * out) {
+ free ( dblin1);
+ free ( dblin2);
+ free ( dblout);
-
-
-
-}*/
+}
diff --git a/src/matrixOperations/division/testMatrixLDivision.c b/src/matrixOperations/division/testMatrixLDivision.c
index 808b9595..6404e191 100644
--- a/src/matrixOperations/division/testMatrixLDivision.c
+++ b/src/matrixOperations/division/testMatrixLDivision.c
@@ -293,6 +293,50 @@ static void dldivaTest ( void )
}
+
+static void cldivaTest (void )
+{
+ int i = 0 ;
+
+ float tin1[] = { 10.0f , 9.0f , 2.0f ,4.0f};
+ float tin2[] = { 1.0f , 2.0f};
+
+
+ floatComplex* in1 ;
+ floatComplex* in2 ;
+ floatComplex* out ;
+ floatComplex Result[ZLINES*ZLINES] ;
+
+ in1 = FloatComplexMatrix ( tin1 , tin1 , ZLINES*ZCOLUMNS1 );
+ in2 = FloatComplexMatrix ( tin2 , tin2 , ZLINES*ZCOLUMNS2 );
+ out = FloatComplexMatrix ( tin2 , tin2 , ZLINES*ZLINES );
+
+ Result[0] = FloatComplex ( 0 , 0 );
+ Result[1] = FloatComplex ( 0.5f , 0 );
+
+ cldiva ( in1 , ZLINES , ZCOLUMNS1 , in2 ,ZLINES , ZCOLUMNS2 , out) ;
+
+ for ( i = 0 ; i < (ZCOLUMNS1*ZCOLUMNS2 ) ; i++ )
+ {
+ printf ( "\t\t %d out : %e + %e * i result : %e + %e * i assert : %e + %e \n" ,
+ i ,creals(out[i]) , cimags(out[i]) , creals (Result[i]) , cimags (Result[i]),
+ fabs( creals(out[i]) - creals (Result[i]) ) / fabs (creals (out[i])) ,
+ fabs( cimags(out[i]) - cimags (Result[i]) ) / fabs (cimags (out[i])));
+
+ assert ( fabs( creals(out[i]) - creals (Result[i]) ) / fabs (creals (out[i])) < 1e-06 );
+ assert ( fabs( cimags(out[i]) - cimags (Result[i]) ) / fabs (cimags (out[i])) < 1e-06 ) ;
+ }
+
+}
+
+
+
+
+
+
+
+
+
static void zldivaTest (void )
{
int i = 0 ;
@@ -315,16 +359,15 @@ static void zldivaTest (void )
zldiva ( in1 , ZLINES , ZCOLUMNS1 , in2 ,ZLINES , ZCOLUMNS2 , out) ;
- for ( i = 0 ; i < (ZCOLUMNS1*ZCOLUMNS2 ) ; i++ )
+ for ( i = 0 ; i < (ZCOLUMNS1*ZCOLUMNS2 ) ; i++ )
{
printf ( "\t\t %d out : %e + %e * i result : %e + %e * i assert : %e + %e \n" ,
i ,zreals(out[i]) , zimags(out[i]) , zreals (Result[i]) , zimags (Result[i]),
fabs( zreals(out[i]) - zreals (Result[i]) ) / fabs (zreals (out[i])) ,
fabs( zimags(out[i]) - zimags (Result[i]) ) / fabs (zimags (out[i])));
- /*assert ( fabs( zreals(out[i]) - zreals (Result[i]) ) / fabs (zreals (out[i])) < 1e-17 );
- assert ( fabs( zimags(out[i]) - zimags (Result[i]) ) / fabs (zimags (out[i])) < 1e-17 ) ;
- */
+ assert ( fabs( zreals(out[i]) - zreals (Result[i]) ) / fabs (zreals (out[i])) < 1e-17 );
+ assert ( fabs( zimags(out[i]) - zimags (Result[i]) ) / fabs (zimags (out[i])) < 1e-17 ) ;
}
}
@@ -332,6 +375,8 @@ static void zldivaTest (void )
static int testLDiva (void) {
+ printf "&&&& WARNING , TESTS FOR COMPLEX ARE STILL WRONG &&&&&&\n\n" ) ;
+
printf("\n\n\n\n*********************\n");
printf("***** Left Tests ****\n");
printf("*********************\n");
@@ -341,7 +386,11 @@ static int testLDiva (void) {
printf("\n\n\n\t>>>> Double real Tests\n");
dldivaTest();
-
+
+ printf("\n\t>>>> Float complex Tests\n");
+ cldivaTest();
+
+
printf("\n\t>>>> Double complex Tests\n");
zldivaTest();
diff --git a/src/matrixOperations/division/testMatrixRDivision.c b/src/matrixOperations/division/testMatrixRDivision.c
index 55542d8e..9b2c7c40 100644
--- a/src/matrixOperations/division/testMatrixRDivision.c
+++ b/src/matrixOperations/division/testMatrixRDivision.c
@@ -262,6 +262,42 @@ static void drdivaTest ( void )
}
+static void crdivaTest (void )
+{
+ int i = 0 ;
+
+ float tin1[] = { 1.0f , 3.0f , 2.0f ,4.0f};
+ float tin2[] = { 1.0f , 2.0f};
+
+
+ floatComplex* in1 ;
+ floatComplex* in2 ;
+ floatComplex* out ;
+ floatComplex Result[ZLINES*ZLINES] ;
+
+ in1 = FloatComplexMatrix ( tin1 , tin1 , ZLINES*ZCOLUMNS1 );
+ in2 = FloatComplexMatrix ( tin2 , tin2 , ZLINES*ZCOLUMNS2 );
+ out = FloatComplexMatrix ( tin2 , tin2 , ZLINES*ZLINES );
+
+ Result[0] = FloatComplex ( 1.0f , 0 );
+ Result[1] = FloatComplex ( 2.2f , 0 );
+
+ crdiva ( in1 , ZLINES , ZCOLUMNS1 , in2 ,ZLINES , ZCOLUMNS2 , out) ;
+
+ for ( i = 0 ; i < (ZCOLUMNS1*ZCOLUMNS2 ) ; i++ )
+ {
+ printf ( "\t\t %d out : %e + %e * i result : %e + %e * i assert : %e + %e \n" ,
+ i ,creals(out[i]) , cimags(out[i]) , creals (Result[i]) , cimags (Result[i]),
+ fabs( creals(out[i]) - creals (Result[i]) ) / fabs (creals (out[i])) ,
+ fabs( cimags(out[i]) - cimags (Result[i]) ) / fabs (cimags (out[i])));
+
+ assert ( fabs( creals(out[i]) - creals (Result[i]) ) / fabs (creals (out[i])) < 1e-06 );
+ assert ( fabs( cimags(out[i]) - cimags (Result[i]) ) / fabs (cimags (out[i])) < 1e-06 ) ;
+ }
+
+}
+
+
@@ -387,8 +423,8 @@ static void zrdivaTest ( void ){
fabs( zreals(out[i]) - zreals (Result[i]) ) / fabs (zreals (out[i])) ,
fabs( zimags(out[i]) - zimags (Result[i]) ) / fabs (zimags (out[i])));
- /*assert ( fabs( zreals(out[i]) - zreals (Result[i]) ) / fabs (zreals (out[i])) < 1e-17 );
- assert ( fabs( zimags(out[i]) - zimags (Result[i]) ) / fabs (zimags (out[i])) < 1e-17 ) ;*/
+ assert ( fabs( zreals(out[i]) - zreals (Result[i]) ) / fabs (zreals (out[i])) < 1e-17 );
+ assert ( fabs( zimags(out[i]) - zimags (Result[i]) ) / fabs (zimags (out[i])) < 1e-17 ) ;
}
}
@@ -404,7 +440,9 @@ static int testRDiva (void) {
printf("\n\n\n\n\t>>>> Double real Tests\n");
drdivaTest();
-
+
+ printf("\n\t>>>> Double complex Tests\n");
+ crdivaTest();
printf("\n\t>>>> Double complex Tests\n");
zrdivaTest();