[clblas] 34/75: fixed compareMatrices to use GTEST_FLOAT_EQ

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Tue Jan 24 23:30:33 UTC 2017


This is an automated email from the git hooks/post-receive script.

ghisvail-guest pushed a commit to branch debian/master
in repository clblas.

commit 8491085874c29f2fbc4b5a1d8f70bc3e15b1f87a
Author: David Tanner <guacamoleo at gmail.com>
Date:   Thu Mar 24 21:57:36 2016 -0500

    fixed compareMatrices to use GTEST_FLOAT_EQ
---
 src/tests/common.cpp       |  21 +++++
 src/tests/include/common.h |   4 +
 src/tests/include/matrix.h | 217 ++++++---------------------------------------
 3 files changed, 51 insertions(+), 191 deletions(-)

diff --git a/src/tests/common.cpp b/src/tests/common.cpp
index d0f21ba..209a598 100644
--- a/src/tests/common.cpp
+++ b/src/tests/common.cpp
@@ -18,6 +18,7 @@
 #include <iostream>
 #include <string.h>
 #include <clBLAS.h>
+#include <gtest/gtest.h>
 
 #include <common.h>
 
@@ -1016,3 +1017,23 @@ functionBlasLevel(BlasFunctionID funct) {
         return 0;
     }
 }
+
+
+template<>
+void gtestAssertElementsEqual( const float & a, const float & b) {
+  ASSERT_FLOAT_EQ(a, b);
+}
+template<>
+void gtestAssertElementsEqual( const double & a, const double & b) {
+  ASSERT_DOUBLE_EQ(a, b);
+}
+template<>
+void gtestAssertElementsEqual( const FloatComplex & a, const FloatComplex & b) {
+  ASSERT_FLOAT_EQ(CREAL(a), CREAL(b));
+  ASSERT_FLOAT_EQ(CIMAG(a), CIMAG(b));
+}
+template<>
+void gtestAssertElementsEqual( const DoubleComplex & a, const DoubleComplex & b) {
+  ASSERT_DOUBLE_EQ(CREAL(a), CREAL(b));
+  ASSERT_DOUBLE_EQ(CIMAG(a), CIMAG(b));
+}
\ No newline at end of file
diff --git a/src/tests/include/common.h b/src/tests/include/common.h
index edbdb43..52f71b1 100644
--- a/src/tests/include/common.h
+++ b/src/tests/include/common.h
@@ -692,6 +692,10 @@ printTestParams(
     size_t offx,
     int incx);
 
+
+template<typename T>
+void gtestAssertElementsEqual( const T & a, const T & b);
+
 #endif  // __cplusplus
 
 #endif  /* COMMON_H_ */
diff --git a/src/tests/include/matrix.h b/src/tests/include/matrix.h
index 65757ad..ad84994 100644
--- a/src/tests/include/matrix.h
+++ b/src/tests/include/matrix.h
@@ -298,6 +298,7 @@ reorderMatrix(
     }
 }
 
+
 template <typename T>
 static void
 compareMatrices(
@@ -315,208 +316,42 @@ compareMatrices(
 
     if( lda > 0 ) // General case
     {
-    for (m = 0; m < M; m++) {
-        for (n = 0; n < N; n++) {
-            a = getElement<T>(order, clblasNoTrans, m, n, A, lda);
-            b = getElement<T>(order, clblasNoTrans, m, n, B, lda);
-            delta = 0.0;
-            if (absDelta != NULL) {
-                delta = absDelta[m * N + n];
+        for (m = 0; m < M; m++) {
+            for (n = 0; n < N; n++) {
+                a = getElement<T>(order, clblasNoTrans, m, n, A, lda);
+                b = getElement<T>(order, clblasNoTrans, m, n, B, lda);
+                gtestAssertElementsEqual(a, b);
             }
-			if( module(a-b) > delta )		printf("m : %d\t n: %d\n", (int)m, (int)n);
-            ASSERT_NEAR(a, b, delta);
         }
     }
-    }
     else // Packed case
     {
-	if ( order == clblasColumnMajor)
-	{
-		for ( n = 0; n < N; n++)
-		{
-			for( m=n; m < M; m++)
-			{
-            			a = getElement<T>(order, clblasNoTrans, m, n, A, lda);
-			        b = getElement<T>(order, clblasNoTrans, m, n, B, lda);
-            			delta = 0.0;
-            			if (absDelta != NULL) {
-                			//delta = absDelta[m * N + n];
-            			}
-						if( module(a-b) > delta )		printf("m : %d\t n: %d\n", (int)m, (int)n);
-            			ASSERT_NEAR(a, b, delta);
-			}
-		}
-	}
-	else
-	{
-		for ( m = 0; m < M; m++)
-		{
-			for( n = 0; n <= m; n++)
-			{
-            			a = getElement<T>(order, clblasNoTrans, m, n, A, lda);
-			        b = getElement<T>(order, clblasNoTrans, m, n, B, lda);
-            			delta = 0.0;
-            			if (absDelta != NULL) {
-                			//delta = absDelta[m * N + n];
-            			}
-						if( module(a-b) > delta )		printf("m : %d\t n: %d\n", (int)m, (int)n);
-            			ASSERT_NEAR(a, b, delta);
-			}
-		}
-	}
-    }
-}
-
-template<>
-__template_static void
-compareMatrices<FloatComplex>(
-    clblasOrder order,
-    size_t M,
-    size_t N,
-    const FloatComplex *A,
-    const FloatComplex *B,
-    size_t lda,
-    const cl_double *absDelta)
-{
-    size_t m = 0, n = 0;
-    FloatComplex a, b;
-    cl_double delta;
-
-if ( lda > 0 )
-{
-    for (m = 0; m < M; m++) {
-        for (n = 0; n < N; n++) {
-            a = getElement<FloatComplex>(order, clblasNoTrans, m, n, A, lda);
-            b = getElement<FloatComplex>(order, clblasNoTrans, m, n, B, lda);
-            delta = 0.0;
-            if (absDelta != NULL) {
-                delta = absDelta[m * N + n];
+        if ( order == clblasColumnMajor)
+        {
+            for ( n = 0; n < N; n++)
+            {
+                for( m=n; m < M; m++)
+                {
+                    a = getElement<T>(order, clblasNoTrans, m, n, A, lda);
+                    b = getElement<T>(order, clblasNoTrans, m, n, B, lda);
+                    gtestAssertElementsEqual(a, b);
+                }
             }
-			if( (module(CREAL(a) - CREAL(b)) > delta) || (module(CIMAG(a) - CIMAG(b)) > delta) )
-					printf("m : %d\t n: %d\n", (int)m, (int)n);
-            ASSERT_NEAR(CREAL(a), CREAL(b), delta);
-            ASSERT_NEAR(CIMAG(a), CIMAG(b), delta);
         }
-    }
-}
-    else // Packed case
-    {
-	if ( order == clblasColumnMajor)
-	{
-		for ( n = 0; n < N; n++)
-		{
-			for( m=n; m < M; m++)
-			{
-            			a = getElement<FloatComplex>(order, clblasNoTrans, m, n, A, lda);
-				        b = getElement<FloatComplex>(order, clblasNoTrans, m, n, B, lda);
-            			delta = 0.0;
-            			if (absDelta != NULL) {
-                			//delta = absDelta[m * N + n];
-            			}
-            			if( (module(CREAL(a) - CREAL(b)) > delta) || (module(CIMAG(a) - CIMAG(b)) > delta) )
-							printf("m : %d\t n: %d\n", (int)m, (int)n);
-            			ASSERT_NEAR(CREAL(a), CREAL(b), delta);
-		            	ASSERT_NEAR(CIMAG(a), CIMAG(b), delta);
-			}
-		}
-	}
-	else
-	{
-		for ( m = 0; m < M; m++)
-		{
-			for( n = 0; n <= m; n++)
-			{
-            			a = getElement<FloatComplex>(order, clblasNoTrans, m, n, A, lda);
-			        b = getElement<FloatComplex>(order, clblasNoTrans, m, n, B, lda);
-            			delta = 0.0;
-            			if (absDelta != NULL) {
-                			//delta = absDelta[m * N + n];
-            			}
-						if( (module(CREAL(a) - CREAL(b)) > delta) || (module(CIMAG(a) - CIMAG(b)) > delta) )
-							printf("m : %d\t n: %d\n", (int)m, (int)n);
-            			ASSERT_NEAR(CREAL(a), CREAL(b), delta);
-		            	ASSERT_NEAR(CIMAG(a), CIMAG(b), delta);
-			}
-		}
-	}
-    }
-
-}
-
-template<>
-__template_static void
-compareMatrices<DoubleComplex>(
-    clblasOrder order,
-    size_t M,
-    size_t N,
-    const DoubleComplex *A,
-    const DoubleComplex *B,
-    size_t lda,
-    const cl_double *absDelta)
-{
-    size_t m = 0, n = 0;
-    DoubleComplex a, b;
-    cl_double delta;
-if( lda > 0 )
-{
-    for (m = 0; m < M; m++) {
-        for (n = 0; n < N; n++) {
-            a = getElement<DoubleComplex>(order, clblasNoTrans, m, n, A, lda);
-            b = getElement<DoubleComplex>(order, clblasNoTrans, m, n, B, lda);
-            delta = 0.0;
-            if (absDelta != NULL) {
-                delta = absDelta[m * N + n];
+        else
+        {
+            for ( m = 0; m < M; m++)
+            {
+                for( n = 0; n <= m; n++)
+                {
+                    a = getElement<T>(order, clblasNoTrans, m, n, A, lda);
+                    b = getElement<T>(order, clblasNoTrans, m, n, B, lda);
+                    gtestAssertElementsEqual(a, b);
+                }
             }
-			if( (module(CREAL(a) - CREAL(b)) > delta) || (module(CIMAG(a) - CIMAG(b)) > delta) )
-					printf("m : %d\t n: %d\n", (int)m, (int)n);
-            ASSERT_NEAR(CREAL(a), CREAL(b), delta);
-            ASSERT_NEAR(CIMAG(a), CIMAG(b), delta);
         }
     }
 }
-    else // Packed case
-    {
-	if ( order == clblasColumnMajor)
-	{
-		for ( n = 0; n < N; n++)
-		{
-			for( m=n; m < M; m++)
-			{
-            			a = getElement<DoubleComplex>(order, clblasNoTrans, m, n, A, lda);
-			        b = getElement<DoubleComplex>(order, clblasNoTrans, m, n, B, lda);
-            			delta = 0.0;
-            			if (absDelta != NULL) {
-                			//delta = absDelta[m * N + n];
-            			}
-						if( (module(CREAL(a) - CREAL(b)) > delta) || (module(CIMAG(a) - CIMAG(b)) > delta) )
-							printf("m : %d\t n: %d\n", (int)m, (int)n);
-            			ASSERT_NEAR(CREAL(a), CREAL(b), delta);
-		            	ASSERT_NEAR(CIMAG(a), CIMAG(b), delta);
-			}
-		}
-	}
-	else
-	{
-		for ( m = 0; m < M; m++)
-		{
-			for( n = 0; n <= m; n++)
-			{
-            			a = getElement<DoubleComplex>(order, clblasNoTrans, m, n, A, lda);
-			        b = getElement<DoubleComplex>(order, clblasNoTrans, m, n, B, lda);
-            			delta = 0.0;
-            			if (absDelta != NULL) {
-                			//delta = absDelta[m * N + n];
-            			}
-						if( (module(CREAL(a) - CREAL(b)) > delta) || (module(CIMAG(a) - CIMAG(b)) > delta) )
-							printf("m : %d\t n: %d\n", (int)m, (int)n);
-            			ASSERT_NEAR(CREAL(a), CREAL(b), delta);
-		            	ASSERT_NEAR(CIMAG(a), CIMAG(b), delta);
-			}
-		}
-	}
-    }
-
-}
 
 template <typename T>
 static void

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/clblas.git



More information about the debian-science-commits mailing list