33 #define BOOST_UBLAS_NDEBUG
39 #include <boost/numeric/ublas/io.hpp>
40 #include <boost/numeric/ublas/triangular.hpp>
41 #include <boost/numeric/ublas/matrix_sparse.hpp>
42 #include <boost/numeric/ublas/matrix.hpp>
43 #include <boost/numeric/ublas/matrix_proxy.hpp>
44 #include <boost/numeric/ublas/lu.hpp>
45 #include <boost/numeric/ublas/io.hpp>
52 #define VIENNACL_WITH_UBLAS 1
68 template<
typename ScalarType>
73 return (s1 - s2) /
std::max(fabs(s1), fabs(s2));
77 template<
typename ScalarType>
80 ublas::vector<ScalarType> v2_cpu(v2.
size());
85 for (std::size_t i=0;i<v1.size(); ++i)
87 if (
std::max( fabs(v2_cpu[i]), fabs(v1[i]) ) > 0 )
88 v2_cpu[i] = fabs(v2_cpu[i] - v1[i]) /
std::max( fabs(v2_cpu[i]), fabs(v1[i]) );
97 template<
typename ScalarType,
typename VCLMatrixType>
100 ublas::matrix<ScalarType> mat2_cpu(mat2.size1(), mat2.size2());
106 for (
unsigned int i = 0; i < mat2_cpu.size1(); ++i)
108 for (
unsigned int j = 0; j < mat2_cpu.size2(); ++j)
110 act = std::fabs(mat2_cpu(i,j) - mat1(i,j)) /
std::max( std::fabs(mat2_cpu(i, j)), std::fabs(mat1(i,j)) );
127 template<
typename RHSTypeRef,
typename RHSTypeCheck,
typename Epsilon >
128 void run_solver_check(RHSTypeRef & B_ref, RHSTypeCheck & B_check,
int & retval, Epsilon
const & epsilon)
130 double act_diff = fabs(
diff(B_ref, B_check));
131 if ( act_diff > epsilon )
133 std::cout <<
" FAILED!" << std::endl;
134 std::cout <<
"# Error at operation: matrix-matrix solve" << std::endl;
135 std::cout <<
" diff: " << act_diff << std::endl;
136 retval = EXIT_FAILURE;
139 std::cout <<
" passed! " << act_diff << std::endl;
144 template<
typename NumericT,
typename Epsilon,
145 typename ReferenceMatrixTypeA,
typename ReferenceMatrixTypeB,
typename ReferenceMatrixTypeC,
146 typename MatrixTypeA,
typename MatrixTypeB,
typename MatrixTypeC,
typename MatrixTypeResult>
149 ReferenceMatrixTypeA
const & A,
150 ReferenceMatrixTypeB
const & B_start,
151 ReferenceMatrixTypeC
const & C_start,
153 MatrixTypeA
const & vcl_A,
156 MatrixTypeResult
const &
159 int retval = EXIT_SUCCESS;
163 ReferenceMatrixTypeA result;
164 ReferenceMatrixTypeC C_trans;
166 ReferenceMatrixTypeB B = B_start;
167 ReferenceMatrixTypeC C = C_start;
169 MatrixTypeResult vcl_result;
172 std::cout <<
"Testing A \\ B: " << std::endl;
173 std::cout <<
" * upper_tag: ";
178 std::cout <<
" * unit_upper_tag: ";
183 std::cout <<
" * lower_tag: ";
188 std::cout <<
" * unit_lower_tag: ";
193 if (retval == EXIT_SUCCESS)
194 std::cout <<
"Test A \\ B passed!" << std::endl;
200 std::cout <<
"Testing A \\ B^T: " << std::endl;
201 std::cout <<
" * upper_tag: ";
208 std::cout <<
" * upper_tag: ";
213 std::cout <<
" * unit_upper_tag: ";
219 std::cout <<
" * lower_tag: ";
225 std::cout <<
" * unit_lower_tag: ";
231 if (retval == EXIT_SUCCESS)
232 std::cout <<
"Test A \\ B^T passed!" << std::endl;
238 std::cout <<
"Testing A^T \\ B: " << std::endl;
239 std::cout <<
" * upper_tag: ";
245 std::cout <<
" * unit_upper_tag: ";
251 std::cout <<
" * lower_tag: ";
257 std::cout <<
" * unit_lower_tag: ";
263 if (retval == EXIT_SUCCESS)
264 std::cout <<
"Test A^T \\ B passed!" << std::endl;
270 std::cout <<
"Testing A^T \\ B^T: " << std::endl;
271 std::cout <<
" * upper_tag: ";
278 std::cout <<
" * upper_tag: ";
283 std::cout <<
" * unit_upper_tag: ";
289 std::cout <<
" * lower_tag: ";
295 std::cout <<
" * unit_lower_tag: ";
301 if (retval == EXIT_SUCCESS)
302 std::cout <<
"Test A^T \\ B^T passed!" << std::endl;
308 template<
typename NumericT,
typename F_A,
typename F_B,
typename Epsilon >
313 int ret = EXIT_SUCCESS;
314 std::size_t matrix_size = 135;
315 std::size_t rhs_num = 67;
317 std::cout <<
"--- Part 2: Testing matrix-matrix solver ---" << std::endl;
320 ublas::matrix<NumericT> A(matrix_size, matrix_size);
321 ublas::matrix<NumericT> B_start(matrix_size, rhs_num);
322 ublas::matrix<NumericT> C_start(rhs_num, matrix_size);
324 for (std::size_t i = 0; i < A.size1(); ++i)
326 for (std::size_t j = 0; j < A.size2(); ++j)
327 A(i,j) =
static_cast<NumericT>(-0.5) * randomNumber();
331 for (std::size_t i = 0; i < B_start.size1(); ++i)
332 for (std::size_t j = 0; j < B_start.size2(); ++j)
333 B_start(i,j) = randomNumber();
335 for (std::size_t i = 0; i < C_start.size1(); ++i)
336 for (std::size_t j = 0; j < C_start.size2(); ++j)
337 C_start(i,j) = randomNumber();
394 std::cout <<
"Now using A=matrix, B=matrix" << std::endl;
395 ret = test_solve<NumericT>(epsilon,
397 vcl_A, vcl_B, vcl_C, vcl_B
399 if (ret != EXIT_SUCCESS)
402 std::cout <<
"Now using A=matrix, B=range" << std::endl;
403 ret = test_solve<NumericT>(epsilon,
405 vcl_A, vcl_range_B, vcl_range_C, vcl_B
407 if (ret != EXIT_SUCCESS)
410 std::cout <<
"Now using A=matrix, B=slice" << std::endl;
411 ret = test_solve<NumericT>(epsilon,
413 vcl_A, vcl_slice_B, vcl_slice_C, vcl_B
415 if (ret != EXIT_SUCCESS)
420 std::cout <<
"Now using A=range, B=matrix" << std::endl;
421 ret = test_solve<NumericT>(epsilon,
423 vcl_range_A, vcl_B, vcl_C, vcl_B
425 if (ret != EXIT_SUCCESS)
428 std::cout <<
"Now using A=range, B=range" << std::endl;
429 ret = test_solve<NumericT>(epsilon,
431 vcl_range_A, vcl_range_B, vcl_range_C, vcl_B
433 if (ret != EXIT_SUCCESS)
436 std::cout <<
"Now using A=range, B=slice" << std::endl;
437 ret = test_solve<NumericT>(epsilon,
439 vcl_range_A, vcl_slice_B, vcl_slice_C, vcl_B
441 if (ret != EXIT_SUCCESS)
447 std::cout <<
"Now using A=slice, B=matrix" << std::endl;
448 ret = test_solve<NumericT>(epsilon,
450 vcl_slice_A, vcl_B, vcl_C, vcl_B
452 if (ret != EXIT_SUCCESS)
455 std::cout <<
"Now using A=slice, B=range" << std::endl;
456 ret = test_solve<NumericT>(epsilon,
458 vcl_slice_A, vcl_range_B, vcl_range_C, vcl_B
460 if (ret != EXIT_SUCCESS)
463 std::cout <<
"Now using A=slice, B=slice" << std::endl;
464 ret = test_solve<NumericT>(epsilon,
466 vcl_slice_A, vcl_slice_B, vcl_slice_C, vcl_B
468 if (ret != EXIT_SUCCESS)
485 template<
typename NumericT,
typename Epsilon >
486 int test(Epsilon
const& epsilon)
490 std::cout <<
"////////////////////////////////" << std::endl;
491 std::cout <<
"/// Now testing A=row, B=row ///" << std::endl;
492 std::cout <<
"////////////////////////////////" << std::endl;
493 ret = test_solve<NumericT, viennacl::row_major, viennacl::row_major>(epsilon);
494 if (ret != EXIT_SUCCESS)
498 std::cout <<
"////////////////////////////////" << std::endl;
499 std::cout <<
"/// Now testing A=row, B=col ///" << std::endl;
500 std::cout <<
"////////////////////////////////" << std::endl;
501 ret = test_solve<NumericT, viennacl::row_major, viennacl::column_major>(epsilon);
502 if (ret != EXIT_SUCCESS)
505 std::cout <<
"////////////////////////////////" << std::endl;
506 std::cout <<
"/// Now testing A=col, B=row ///" << std::endl;
507 std::cout <<
"////////////////////////////////" << std::endl;
508 ret = test_solve<NumericT, viennacl::column_major, viennacl::row_major>(epsilon);
509 if (ret != EXIT_SUCCESS)
512 std::cout <<
"////////////////////////////////" << std::endl;
513 std::cout <<
"/// Now testing A=col, B=col ///" << std::endl;
514 std::cout <<
"////////////////////////////////" << std::endl;
515 ret = test_solve<NumericT, viennacl::column_major, viennacl::column_major>(epsilon);
516 if (ret != EXIT_SUCCESS)
529 std::cout << std::endl;
530 std::cout <<
"----------------------------------------------" << std::endl;
531 std::cout <<
"----------------------------------------------" << std::endl;
532 std::cout <<
"## Test :: BLAS 3 routines" << std::endl;
533 std::cout <<
"----------------------------------------------" << std::endl;
534 std::cout <<
"----------------------------------------------" << std::endl;
535 std::cout << std::endl;
537 int retval = EXIT_SUCCESS;
539 std::cout << std::endl;
540 std::cout <<
"----------------------------------------------" << std::endl;
541 std::cout << std::endl;
544 NumericT epsilon =
NumericT(1.0E-3);
545 std::cout <<
"# Testing setup:" << std::endl;
546 std::cout <<
" eps: " << epsilon << std::endl;
547 std::cout <<
" numeric: float" << std::endl;
548 retval = test<NumericT>(epsilon);
549 if ( retval == EXIT_SUCCESS )
550 std::cout <<
"# Test passed" << std::endl;
554 std::cout << std::endl;
555 std::cout <<
"----------------------------------------------" << std::endl;
556 std::cout << std::endl;
557 #ifdef VIENNACL_WITH_OPENCL
563 NumericT epsilon = 1.0E-11;
564 std::cout <<
"# Testing setup:" << std::endl;
565 std::cout <<
" eps: " << epsilon << std::endl;
566 std::cout <<
" numeric: double" << std::endl;
567 retval = test<NumericT>(epsilon);
568 if ( retval == EXIT_SUCCESS )
569 std::cout <<
"# Test passed" << std::endl;
573 std::cout << std::endl;
574 std::cout <<
"----------------------------------------------" << std::endl;
575 std::cout << std::endl;
578 std::cout << std::endl;
579 std::cout <<
"------- Test completed --------" << std::endl;
580 std::cout << std::endl;
void inplace_solve(matrix_base< NumericT > const &A, matrix_base< NumericT > &B, SolverTagT tag)
Direct inplace solver for triangular systems with multiple right hand sides, i.e. A \ B (MATLAB notat...
void inplace_solve(const matrix_base< NumericT > &A, matrix_base< NumericT > &B, SolverTagT)
Direct inplace solver for triangular systems with multiple right hand sides, i.e. A \ B (MATLAB notat...
This class represents a single scalar value on the GPU and behaves mostly like a built-in scalar type...
Generic interface for the l^2-norm. See viennacl/linalg/vector_operations.hpp for implementations...
Class for representing strided submatrices of a bigger matrix A.
void trans(matrix_expression< const matrix_base< NumericT, SizeT, DistanceT >, const matrix_base< NumericT, SizeT, DistanceT >, op_trans > const &proxy, matrix_base< NumericT > &temp_trans)
Generic interface for matrix-vector and matrix-matrix products. See viennacl/linalg/vector_operations...
Implementation of the dense matrix class.
A tag class representing a lower triangular matrix.
void finish()
Synchronizes the execution. finish() will only return after all compute kernels (CUDA, OpenCL) have completed.
viennacl::scalar< int > s2
viennacl::scalar< float > s1
T max(const T &lhs, const T &rhs)
Maximum.
viennacl::ocl::device const & current_device()
Convenience function for returning the active device in the current context.
VectorT solve(MatrixT const &matrix, VectorT const &rhs, bicgstab_tag const &tag, PreconditionerT const &precond)
viennacl::vector< float > v1
iterator begin()
Returns an iterator pointing to the beginning of the vector (STL like)
A tag class representing an upper triangular matrix.
bool double_support() const
ViennaCL convenience function: Returns true if the device supports double precision.
Implementations of dense direct solvers are found here.
Proxy classes for matrices.
int test_solve(Epsilon const &epsilon, ReferenceMatrixTypeA const &A, ReferenceMatrixTypeB const &B_start, ReferenceMatrixTypeC const &C_start, MatrixTypeA const &vcl_A, MatrixTypeB &vcl_B, MatrixTypeC &vcl_C, MatrixTypeResult const &)
viennacl::vector< int > v2
The vector type with operator-overloads and proxy classes is defined here. Linear algebra operations ...
T norm_inf(std::vector< T, A > const &v1)
void copy(std::vector< NumericT > &cpu_vec, circulant_matrix< NumericT, AlignmentV > &gpu_mat)
Copies a circulant matrix from the std::vector to the OpenCL device (either GPU or multi-core CPU) ...
A small collection of sequential random number generators.
size_type size() const
Returns the length of the vector (cf. std::vector)
A range class that refers to an interval [start, stop), where 'start' is included, and 'stop' is excluded.
A tag class representing a lower triangular matrix with unit diagonal.
int test(Epsilon const &epsilon)
Class for representing non-strided submatrices of a bigger matrix A.
void run_solver_check(RHSTypeRef &B_ref, RHSTypeCheck &B_check, int &retval, Epsilon const &epsilon)
iterator end()
Returns an iterator pointing to the end of the vector (STL like)
A slice class that refers to an interval [start, stop), where 'start' is included, and 'stop' is excluded.
ScalarType diff(ScalarType &s1, viennacl::scalar< ScalarType > &s2)
Implementation of the ViennaCL scalar class.
A tag class representing an upper triangular matrix with unit diagonal.