add test for accelerate framework
This commit is contained in:
		
							
								
								
									
										15
									
								
								test/cxx_accelerate/cmake/autocmake.cfg
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								test/cxx_accelerate/cmake/autocmake.cfg
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,15 @@ | ||||
| [project] | ||||
| name: example | ||||
| min_cmake_version: 2.8 | ||||
|  | ||||
| [cxx] | ||||
| source: ../../../modules/cxx.cmake | ||||
|  | ||||
| [math] | ||||
| source: ../../../modules/math/accelerate.cmake | ||||
|  | ||||
| [default_build_paths] | ||||
| source: ../../../modules/default_build_paths.cmake | ||||
|  | ||||
| [src] | ||||
| source: ../../../modules/src.cmake | ||||
							
								
								
									
										7
									
								
								test/cxx_accelerate/src/CMakeLists.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								test/cxx_accelerate/src/CMakeLists.txt
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,7 @@ | ||||
| if(ACCELERATE_FOUND) | ||||
|     include_directories(${ACCELERATE_INCLUDE_DIR}) | ||||
|     add_executable(example example.cpp) | ||||
|     target_link_libraries(example ${ACCELERATE_LIBRARIES}) | ||||
| else() | ||||
|     message(FATAL_ERROR "ACCELERATE library not found") | ||||
| endif() | ||||
							
								
								
									
										77
									
								
								test/cxx_accelerate/src/example.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										77
									
								
								test/cxx_accelerate/src/example.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,77 @@ | ||||
| #include <stdio.h> | ||||
| #include <stdlib.h> | ||||
|  | ||||
| #include "Accelerate/Accelerate.h" | ||||
|  | ||||
| bool test_lapack() | ||||
| { | ||||
|     const int n = 3; | ||||
|  | ||||
|     double a[n*n]; | ||||
|     double b[n]; | ||||
|  | ||||
|     a[0] =  2.00; | ||||
|     a[1] =  1.00; | ||||
|     a[2] =  3.00; | ||||
|     a[3] =  2.00; | ||||
|     a[4] =  6.00; | ||||
|     a[5] =  8.00; | ||||
|     a[6] =  6.00; | ||||
|     a[7] =  8.00; | ||||
|     a[8] = 18.00; | ||||
|  | ||||
|     b[0] = 1.00; | ||||
|     b[1] = 3.00; | ||||
|     b[2] = 5.00; | ||||
|  | ||||
|     int ierr; | ||||
|     int ipiv[n]; | ||||
|  | ||||
|     ierr = LAPACKE_dgesv(CblasColMajor, n, 1, a,  n, ipiv, b, n); | ||||
|     if (ierr != 0) | ||||
|     { | ||||
|         fprintf(stderr, "\ndgesv failure with error %i\n", ierr); | ||||
|     } | ||||
|  | ||||
|     const double small = 1.0e-12; | ||||
|  | ||||
|     if (abs(b[0] + 0.50) <= small && | ||||
|         abs(b[1] - 0.25) <= small && | ||||
|         abs(b[2] - 0.25) <= small) | ||||
|     { | ||||
|         return true; | ||||
|     } | ||||
|  | ||||
|     return false; | ||||
| } | ||||
|  | ||||
| bool test_blas() | ||||
| { | ||||
|     const int n = 10; | ||||
|  | ||||
|     double a[n*n]; | ||||
|     double b[n*n]; | ||||
|     double c[n*n]; | ||||
|  | ||||
|     for (int i = 0; i < n*n; i++) | ||||
|     { | ||||
|         a[i] = 1.0; | ||||
|         b[i] = 2.0; | ||||
|         c[i] = 0.0; | ||||
|     } | ||||
|  | ||||
|     cblas_dgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, n, n, n, 1.0, a, n, b, n, 0.0, c, n); | ||||
|  | ||||
|     bool passed = true; | ||||
|     for (int i = 0; i < n*n; i++) | ||||
|     { | ||||
|         if (abs(c[i]) - 20.00 > 0.0) passed = false; | ||||
|     } | ||||
|  | ||||
|     return passed; | ||||
| } | ||||
|  | ||||
| int main() | ||||
| { | ||||
|     if (test_lapack() and test_blas()) printf("PASSED"); | ||||
| } | ||||
		Reference in New Issue
	
	Block a user