49 template<
typename ScalarType>
 
   54       return (s1 - s2) / 
std::max(fabs(s1), fabs(s2));
 
   58 template<
typename ScalarType>
 
   61    std::vector<ScalarType> v2_cpu(v2.
size());
 
   66    for (std::size_t i=0;i<v1.size(); ++i)
 
   68       if ( 
std::max( fabs(v2_cpu[i]), fabs(v1[i]) ) > 0 )
 
   69          v2_cpu[i] = fabs(v2_cpu[i] - v1[i]) / 
std::max( fabs(v2_cpu[i]), fabs(v1[i]) );
 
   78 template<
typename ScalarType, 
typename VCLMatrixType>
 
   79 ScalarType diff(std::vector<std::vector<ScalarType> > & mat1, VCLMatrixType & mat2)
 
   81    std::vector<std::vector<ScalarType> > mat2_cpu(mat2.size1(), std::vector<ScalarType>(mat2.size2()));
 
   87     for (
unsigned int i = 0; i < mat2_cpu.size(); ++i)
 
   89       for (
unsigned int j = 0; j < mat2_cpu[i].size(); ++j)
 
   91         act = std::fabs(mat2_cpu[i][j] - mat1[i][j]) / 
std::max( std::fabs(mat2_cpu[i][j]), std::fabs(mat1[i][j]) );
 
  106 template<
typename NumericT>
 
  107 void inplace_solve_lower(std::vector<std::vector<NumericT> > 
const & A, std::vector<std::vector<NumericT> > & B, 
bool unit_diagonal)
 
  109   for (std::size_t i=0; i<A.size(); ++i)
 
  111     for (std::size_t j=0; j < i; ++j)
 
  114       for (std::size_t k=0; k<B[i].size(); ++k)
 
  115         B[i][k] -= val_A * B[j][k];
 
  120     for (std::size_t k=0; k<B[i].size(); ++k)
 
  125 template<
typename NumericT>
 
  131 template<
typename NumericT>
 
  137 template<
typename NumericT>
 
  138 void inplace_solve_upper(std::vector<std::vector<NumericT> > 
const & A, std::vector<std::vector<NumericT> > & B, 
bool unit_diagonal)
 
  140   for (std::size_t i2=0; i2<A.size(); ++i2)
 
  142     std::size_t i = A.size() - i2 - 1;
 
  143     for (std::size_t j=i+1; j < A[0].size(); ++j)
 
  146       for (std::size_t k=0; k<B[i].size(); ++k)
 
  147         B[i][k] -= val_A * B[j][k];
 
  152     for (std::size_t k=0; k<B[i].size(); ++k)
 
  157 template<
typename NumericT>
 
  163 template<
typename NumericT>
 
  169 template<
typename NumericT, 
typename SolverTagT>
 
  170 std::vector<std::vector<NumericT> > 
solve(std::vector<std::vector<NumericT> > 
const & A, std::vector<std::vector<NumericT> > 
const & B, SolverTagT)
 
  172   std::vector<std::vector<NumericT> > C(B);
 
  178 template<
typename RHSTypeRef, 
typename RHSTypeCheck, 
typename Epsilon >
 
  179 void run_solver_check(RHSTypeRef & B_ref, RHSTypeCheck & B_check, 
int & retval, Epsilon 
const & epsilon)
 
  181    double act_diff = fabs(
diff(B_ref, B_check));
 
  182    if ( act_diff > epsilon )
 
  184      std::cout << 
" FAILED!" << std::endl;
 
  185      std::cout << 
"# Error at operation: matrix-matrix solve" << std::endl;
 
  186      std::cout << 
"  diff: " << act_diff << std::endl;
 
  187      retval = EXIT_FAILURE;
 
  190      std::cout << 
" passed! " << act_diff << std::endl;
 
  194 template<
typename NumericT>
 
  195 std::vector<std::vector<NumericT> > 
trans(std::vector<std::vector<NumericT> > 
const & A)
 
  197   std::vector<std::vector<NumericT> > A_trans(A[0].
size(), std::vector<NumericT>(A.size()));
 
  199   for (std::size_t i=0; i<A.size(); ++i)
 
  200     for (std::size_t j=0; j<A[i].size(); ++j)
 
  201       A_trans[j][i] = A[i][j];
 
  207 template< 
typename NumericT, 
typename Epsilon,
 
  208           typename ReferenceMatrixTypeA, 
typename ReferenceMatrixTypeB, 
typename ReferenceMatrixTypeC,
 
  209           typename MatrixTypeA, 
typename MatrixTypeB, 
typename MatrixTypeC, 
typename MatrixTypeResult>
 
  212               ReferenceMatrixTypeA 
const & A,
 
  213               ReferenceMatrixTypeB 
const & B_start,
 
  214               ReferenceMatrixTypeC 
const & C_start,
 
  216               MatrixTypeA 
const & vcl_A,
 
  219               MatrixTypeResult 
const &
 
  222    int retval = EXIT_SUCCESS;
 
  226    ReferenceMatrixTypeA result;
 
  227    ReferenceMatrixTypeC C_trans;
 
  229    ReferenceMatrixTypeB B = B_start;
 
  230    ReferenceMatrixTypeC C = C_start;
 
  232    MatrixTypeResult vcl_result;
 
  235    std::cout << 
"Testing A \\ B: " << std::endl;
 
  236    std::cout << 
" * upper_tag:      ";
 
  241    std::cout << 
" * unit_upper_tag: ";
 
  246    std::cout << 
" * lower_tag:      ";
 
  251    std::cout << 
" * unit_lower_tag: ";
 
  256    if (retval == EXIT_SUCCESS)
 
  257      std::cout << 
"Test A \\ B passed!" << std::endl;
 
  263    std::cout << 
"Testing A \\ B^T: " << std::endl;
 
  264    std::cout << 
" * upper_tag:      ";
 
  271    std::cout << 
" * upper_tag:      ";
 
  276    std::cout << 
" * unit_upper_tag: ";
 
  282    std::cout << 
" * lower_tag:      ";
 
  288    std::cout << 
" * unit_lower_tag: ";
 
  294    if (retval == EXIT_SUCCESS)
 
  295      std::cout << 
"Test A \\ B^T passed!" << std::endl;
 
  301    std::cout << 
"Testing A^T \\ B: " << std::endl;
 
  302    std::cout << 
" * upper_tag:      ";
 
  308    std::cout << 
" * unit_upper_tag: ";
 
  314    std::cout << 
" * lower_tag:      ";
 
  320    std::cout << 
" * unit_lower_tag: ";
 
  326    if (retval == EXIT_SUCCESS)
 
  327      std::cout << 
"Test A^T \\ B passed!" << std::endl;
 
  333    std::cout << 
"Testing A^T \\ B^T: " << std::endl;
 
  334    std::cout << 
" * upper_tag:      ";
 
  341    std::cout << 
" * upper_tag:      ";
 
  346    std::cout << 
" * unit_upper_tag: ";
 
  352    std::cout << 
" * lower_tag:      ";
 
  358    std::cout << 
" * unit_lower_tag: ";
 
  364    if (retval == EXIT_SUCCESS)
 
  365      std::cout << 
"Test A^T \\ B^T passed!" << std::endl;
 
  371 template< 
typename NumericT, 
typename F_A, 
typename F_B, 
typename Epsilon >
 
  376   int ret = EXIT_SUCCESS;
 
  377   std::size_t matrix_size = 135;  
 
  378   std::size_t rhs_num = 67;
 
  380   std::cout << 
"--- Part 2: Testing matrix-matrix solver ---" << std::endl;
 
  383   std::vector<std::vector<NumericT> > A(matrix_size, std::vector<NumericT>(matrix_size));
 
  384   std::vector<std::vector<NumericT> > B_start(matrix_size,  std::vector<NumericT>(rhs_num));
 
  385   std::vector<std::vector<NumericT> > C_start(rhs_num,  std::vector<NumericT>(matrix_size));
 
  387   for (std::size_t i = 0; i < A.size(); ++i)
 
  389     for (std::size_t j = 0; j < A[i].size(); ++j)
 
  390         A[i][j] = static_cast<NumericT>(-0.5) * randomNumber();
 
  394   for (std::size_t i = 0; i < B_start.size(); ++i)
 
  395     for (std::size_t j = 0; j < B_start[i].size(); ++j)
 
  396       B_start[i][j] = randomNumber();
 
  398   for (std::size_t i = 0; i < C_start.size(); ++i)
 
  399     for (std::size_t j = 0; j < C_start[i].size(); ++j)
 
  400       C_start[i][j] = randomNumber();
 
  457   std::cout << 
"Now using A=matrix, B=matrix" << std::endl;
 
  458   ret = test_solve<NumericT>(epsilon,
 
  460                              vcl_A, vcl_B, vcl_C, vcl_B
 
  462   if (ret != EXIT_SUCCESS)
 
  465   std::cout << 
"Now using A=matrix, B=range" << std::endl;
 
  466   ret = test_solve<NumericT>(epsilon,
 
  468                              vcl_A, vcl_range_B, vcl_range_C, vcl_B
 
  470   if (ret != EXIT_SUCCESS)
 
  473   std::cout << 
"Now using A=matrix, B=slice" << std::endl;
 
  474   ret = test_solve<NumericT>(epsilon,
 
  476                              vcl_A, vcl_slice_B, vcl_slice_C, vcl_B
 
  478   if (ret != EXIT_SUCCESS)
 
  483   std::cout << 
"Now using A=range, B=matrix" << std::endl;
 
  484   ret = test_solve<NumericT>(epsilon,
 
  486                              vcl_range_A, vcl_B, vcl_C, vcl_B
 
  488   if (ret != EXIT_SUCCESS)
 
  491   std::cout << 
"Now using A=range, B=range" << std::endl;
 
  492   ret = test_solve<NumericT>(epsilon,
 
  494                              vcl_range_A, vcl_range_B, vcl_range_C, vcl_B
 
  496   if (ret != EXIT_SUCCESS)
 
  499   std::cout << 
"Now using A=range, B=slice" << std::endl;
 
  500   ret = test_solve<NumericT>(epsilon,
 
  502                              vcl_range_A, vcl_slice_B, vcl_slice_C, vcl_B
 
  504   if (ret != EXIT_SUCCESS)
 
  510   std::cout << 
"Now using A=slice, B=matrix" << std::endl;
 
  511   ret = test_solve<NumericT>(epsilon,
 
  513                              vcl_slice_A, vcl_B, vcl_C, vcl_B
 
  515   if (ret != EXIT_SUCCESS)
 
  518   std::cout << 
"Now using A=slice, B=range" << std::endl;
 
  519   ret = test_solve<NumericT>(epsilon,
 
  521                              vcl_slice_A, vcl_range_B, vcl_range_C, vcl_B
 
  523   if (ret != EXIT_SUCCESS)
 
  526   std::cout << 
"Now using A=slice, B=slice" << std::endl;
 
  527   ret = test_solve<NumericT>(epsilon,
 
  529                              vcl_slice_A, vcl_slice_B, vcl_slice_C, vcl_B
 
  531   if (ret != EXIT_SUCCESS)
 
  548 template< 
typename NumericT, 
typename Epsilon >
 
  549 int test(Epsilon 
const& epsilon)
 
  553   std::cout << 
"////////////////////////////////" << std::endl;
 
  554   std::cout << 
"/// Now testing A=row, B=row ///" << std::endl;
 
  555   std::cout << 
"////////////////////////////////" << std::endl;
 
  556   ret = test_solve<NumericT, viennacl::row_major, viennacl::row_major>(epsilon);
 
  557   if (ret != EXIT_SUCCESS)
 
  561   std::cout << 
"////////////////////////////////" << std::endl;
 
  562   std::cout << 
"/// Now testing A=row, B=col ///" << std::endl;
 
  563   std::cout << 
"////////////////////////////////" << std::endl;
 
  564   ret = test_solve<NumericT, viennacl::row_major, viennacl::column_major>(epsilon);
 
  565   if (ret != EXIT_SUCCESS)
 
  568   std::cout << 
"////////////////////////////////" << std::endl;
 
  569   std::cout << 
"/// Now testing A=col, B=row ///" << std::endl;
 
  570   std::cout << 
"////////////////////////////////" << std::endl;
 
  571   ret = test_solve<NumericT, viennacl::column_major, viennacl::row_major>(epsilon);
 
  572   if (ret != EXIT_SUCCESS)
 
  575   std::cout << 
"////////////////////////////////" << std::endl;
 
  576   std::cout << 
"/// Now testing A=col, B=col ///" << std::endl;
 
  577   std::cout << 
"////////////////////////////////" << std::endl;
 
  578   ret = test_solve<NumericT, viennacl::column_major, viennacl::column_major>(epsilon);
 
  579   if (ret != EXIT_SUCCESS)
 
  592    std::cout << std::endl;
 
  593    std::cout << 
"----------------------------------------------" << std::endl;
 
  594    std::cout << 
"----------------------------------------------" << std::endl;
 
  595    std::cout << 
"## Test :: BLAS 3 routines" << std::endl;
 
  596    std::cout << 
"----------------------------------------------" << std::endl;
 
  597    std::cout << 
"----------------------------------------------" << std::endl;
 
  598    std::cout << std::endl;
 
  600    int retval = EXIT_SUCCESS;
 
  602    std::cout << std::endl;
 
  603    std::cout << 
"----------------------------------------------" << std::endl;
 
  604    std::cout << std::endl;
 
  607       NumericT epsilon = 
NumericT(1.0E-3);
 
  608       std::cout << 
"# Testing setup:" << std::endl;
 
  609       std::cout << 
"  eps:     " << epsilon << std::endl;
 
  610       std::cout << 
"  numeric: float" << std::endl;
 
  611       retval = test<NumericT>(epsilon);
 
  612       if ( retval == EXIT_SUCCESS )
 
  613         std::cout << 
"# Test passed" << std::endl;
 
  617    std::cout << std::endl;
 
  618    std::cout << 
"----------------------------------------------" << std::endl;
 
  619    std::cout << std::endl;
 
  620 #ifdef VIENNACL_WITH_OPENCL 
  626         NumericT epsilon = 1.0E-11;
 
  627         std::cout << 
"# Testing setup:" << std::endl;
 
  628         std::cout << 
"  eps:     " << epsilon << std::endl;
 
  629         std::cout << 
"  numeric: double" << std::endl;
 
  630         retval = test<NumericT>(epsilon);
 
  631         if ( retval == EXIT_SUCCESS )
 
  632           std::cout << 
"# Test passed" << std::endl;
 
  636       std::cout << std::endl;
 
  637       std::cout << 
"----------------------------------------------" << std::endl;
 
  638       std::cout << std::endl;
 
  641    std::cout << std::endl;
 
  642    std::cout << 
"------- Test completed --------" << std::endl;
 
  643    std::cout << std::endl;
 
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. 
std::vector< std::vector< NumericT > > trans(std::vector< std::vector< NumericT > > const &A)
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)
void inplace_solve_upper(std::vector< std::vector< NumericT > > const &A, std::vector< std::vector< NumericT > > &B, bool unit_diagonal)
viennacl::vector< float > v1
vcl_size_t size(VectorType const &vec)
Generic routine for obtaining the size of a vector (ViennaCL, uBLAS, etc.) 
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. 
void inplace_solve(std::vector< std::vector< NumericT > > const &A, std::vector< std::vector< NumericT > > &B, viennacl::linalg::lower_tag)
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. 
void inplace_solve_lower(std::vector< std::vector< NumericT > > const &A, std::vector< std::vector< NumericT > > &B, bool unit_diagonal)
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. 
std::vector< std::vector< NumericT > > solve(std::vector< std::vector< NumericT > > const &A, std::vector< std::vector< NumericT > > const &B, SolverTagT)