48 template<
typename NumericT>
50 std::vector<std::vector<NumericT> >
const & mat,
53 if ( (ref_mat.size() != mat.size()) || (ref_mat[0].
size() != mat[0].size()) )
56 for (std::size_t i = 0; i < ref_mat.size(); i++)
57 for (std::size_t j = 0; j < ref_mat[0].size(); j++)
59 NumericT rel_error = std::abs(ref_mat[i][j] - mat[i][j]) /
std::max(std::abs(ref_mat[i][j]), std::abs(mat[i][j]));
62 std::cout <<
"ERROR: Verification failed at (" << i <<
", "<< j <<
"): "
63 <<
" Expected: " << ref_mat[i][j] <<
", got: " << mat[i][j] <<
" (relative error: " << rel_error <<
")" << std::endl;
68 std::cout <<
"Everything went well!" << std::endl;
75 template<
typename IndexT,
typename NumericT>
77 std::vector<std::vector<NumericT> >
const & B,
78 std::vector<std::vector<NumericT> > & C)
80 typedef typename std::map<IndexT, NumericT>::const_iterator RowIterator;
82 for (std::size_t i=0; i<C.size(); ++i)
83 for (RowIterator it = A[i].begin(); it != A[i].end(); ++it)
85 IndexT col_A = it->first;
88 for (std::size_t j=0; j<C[i].size(); ++j)
89 C[i][j] += val_A * B[col_A][j];
94 template<
typename NumericT,
typename ResultLayoutT,
typename FactorLayoutT>
97 int retVal = EXIT_SUCCESS;
101 std::vector<std::map<unsigned int, NumericT> > std_A;
104 std::cout <<
"Error reading Matrix file" << std::endl;
109 for (std::size_t i=0; i<std_A.size(); ++i)
110 std_A[i][static_cast<unsigned int>(i)] *=
NumericT(1.5);
112 std::size_t cols_rhs = 5;
119 std::vector<std::vector<NumericT> > std_C(std_A.size(), std::vector<NumericT>(cols_rhs));
127 std::vector<std::vector<NumericT> > std_B(std_A.size(), std::vector<NumericT>(cols_rhs));
131 std::vector<std::vector<NumericT> > temp(std_A.size(), std::vector<NumericT>(cols_rhs));
133 for (
unsigned int i = 0; i < std_B.size(); i++)
134 for (
unsigned int j = 0; j < std_B[i].size(); j++)
143 std::cout <<
"Testing compressed(CSR) lhs * dense rhs" << std::endl;
146 for (std::size_t i=0; i<temp.size(); ++i)
147 for (std::size_t j=0; j<temp[i].size(); ++j)
151 if (retVal != EXIT_SUCCESS)
153 std::cerr <<
"Test failed!" << std::endl;
158 std::cout <<
"Testing compressed(ELL) lhs * dense rhs" << std::endl;
162 for (std::size_t i=0; i<temp.size(); ++i)
163 for (std::size_t j=0; j<temp[i].size(); ++j)
167 if (retVal != EXIT_SUCCESS)
169 std::cerr <<
"Test failed!" << std::endl;
175 std::cout <<
"Testing compressed(COO) lhs * dense rhs" << std::endl;
179 for (std::size_t i=0; i<temp.size(); ++i)
180 for (std::size_t j=0; j<temp[i].size(); ++j)
184 if (retVal != EXIT_SUCCESS)
186 std::cerr <<
"Test failed!" << std::endl;
192 std::cout <<
"Testing compressed(HYB) lhs * dense rhs" << std::endl;
196 for (std::size_t i=0; i<temp.size(); ++i)
197 for (std::size_t j=0; j<temp[i].size(); ++j)
201 if (retVal != EXIT_SUCCESS)
203 std::cerr <<
"Test failed!" << std::endl;
215 std::cout << std::endl <<
"Testing compressed(CSR) lhs * transposed dense rhs:" << std::endl;
219 for (std::size_t i=0; i<temp.size(); ++i)
220 for (std::size_t j=0; j<temp[i].size(); ++j)
224 if (retVal != EXIT_SUCCESS)
226 std::cerr <<
"Test failed!" << std::endl;
231 std::cout <<
"Testing compressed(ELL) lhs * transposed dense rhs" << std::endl;
235 for (std::size_t i=0; i<temp.size(); ++i)
236 for (std::size_t j=0; j<temp[i].size(); ++j)
240 if (retVal != EXIT_SUCCESS)
242 std::cerr <<
"Test failed!" << std::endl;
247 std::cout <<
"Testing compressed(COO) lhs * transposed dense rhs" << std::endl;
251 for (std::size_t i=0; i<temp.size(); ++i)
252 for (std::size_t j=0; j<temp[i].size(); ++j)
256 if (retVal != EXIT_SUCCESS)
258 std::cerr <<
"Test failed!" << std::endl;
264 std::cout <<
"Testing compressed(HYB) lhs * transposed dense rhs" << std::endl;
268 for (std::size_t i=0; i<temp.size(); ++i)
269 for (std::size_t j=0; j<temp[i].size(); ++j)
273 if (retVal != EXIT_SUCCESS)
275 std::cerr <<
"Test failed!" << std::endl;
280 if (retVal == EXIT_SUCCESS) {
281 std::cout <<
"Tests passed successfully" << std::endl;
292 std::cout << std::endl;
293 std::cout <<
"----------------------------------------------" << std::endl;
294 std::cout <<
"----------------------------------------------" << std::endl;
295 std::cout <<
"## Test :: Sparse-Dense Matrix Multiplication" << std::endl;
296 std::cout <<
"----------------------------------------------" << std::endl;
297 std::cout <<
"----------------------------------------------" << std::endl;
298 std::cout << std::endl;
300 int retval = EXIT_SUCCESS;
302 std::cout << std::endl;
303 std::cout <<
"----------------------------------------------" << std::endl;
304 std::cout << std::endl;
307 NumericT epsilon =
static_cast<NumericT
>(1E-4);
308 std::cout <<
"# Testing setup:" << std::endl;
309 std::cout <<
" eps: " << epsilon << std::endl;
310 std::cout <<
" numeric: float" << std::endl;
311 std::cout <<
" layout: row-major, row-major" << std::endl;
312 retval = test<NumericT, viennacl::row_major, viennacl::row_major>(epsilon);
313 if ( retval == EXIT_SUCCESS )
314 std::cout <<
"# Test passed" << std::endl;
318 std::cout <<
"# Testing setup:" << std::endl;
319 std::cout <<
" eps: " << epsilon << std::endl;
320 std::cout <<
" numeric: float" << std::endl;
321 std::cout <<
" layout: row-major, column-major" << std::endl;
322 retval = test<NumericT, viennacl::row_major, viennacl::column_major>(epsilon);
323 if ( retval == EXIT_SUCCESS )
324 std::cout <<
"# Test passed" << std::endl;
328 std::cout <<
"# Testing setup:" << std::endl;
329 std::cout <<
" eps: " << epsilon << std::endl;
330 std::cout <<
" numeric: float" << std::endl;
331 std::cout <<
" layout: column-major, row-major" << std::endl;
332 retval = test<NumericT, viennacl::column_major, viennacl::row_major>(epsilon);
333 if ( retval == EXIT_SUCCESS )
334 std::cout <<
"# Test passed" << std::endl;
338 std::cout <<
"# Testing setup:" << std::endl;
339 std::cout <<
" eps: " << epsilon << std::endl;
340 std::cout <<
" numeric: float" << std::endl;
341 std::cout <<
" layout: column-major, column-major" << std::endl;
342 retval = test<NumericT, viennacl::column_major, viennacl::column_major>(epsilon);
343 if ( retval == EXIT_SUCCESS )
344 std::cout <<
"# Test passed" << std::endl;
349 std::cout << std::endl;
350 std::cout <<
"----------------------------------------------" << std::endl;
351 std::cout << std::endl;
353 #ifdef VIENNACL_WITH_OPENCL
359 NumericT epsilon = 1.0E-12;
360 std::cout <<
"# Testing setup:" << std::endl;
361 std::cout <<
" eps: " << epsilon << std::endl;
362 std::cout <<
" numeric: double" << std::endl;
363 std::cout <<
" layout: row-major, row-major" << std::endl;
364 retval = test<NumericT, viennacl::row_major, viennacl::row_major>(epsilon);
365 if ( retval == EXIT_SUCCESS )
366 std::cout <<
"# Test passed" << std::endl;
370 std::cout <<
"# Testing setup:" << std::endl;
371 std::cout <<
" eps: " << epsilon << std::endl;
372 std::cout <<
" numeric: double" << std::endl;
373 std::cout <<
" layout: row-major, column-major" << std::endl;
374 retval = test<NumericT, viennacl::row_major, viennacl::column_major>(epsilon);
375 if ( retval == EXIT_SUCCESS )
376 std::cout <<
"# Test passed" << std::endl;
380 std::cout <<
"# Testing setup:" << std::endl;
381 std::cout <<
" eps: " << epsilon << std::endl;
382 std::cout <<
" numeric: double" << std::endl;
383 std::cout <<
" layout: column-major, row-major" << std::endl;
384 retval = test<NumericT, viennacl::column_major, viennacl::row_major>(epsilon);
385 if ( retval == EXIT_SUCCESS )
386 std::cout <<
"# Test passed" << std::endl;
390 std::cout <<
"# Testing setup:" << std::endl;
391 std::cout <<
" eps: " << epsilon << std::endl;
392 std::cout <<
" numeric: double" << std::endl;
393 std::cout <<
" layout: column-major, column-major" << std::endl;
394 retval = test<NumericT, viennacl::column_major, viennacl::column_major>(epsilon);
395 if ( retval == EXIT_SUCCESS )
396 std::cout <<
"# Test passed" << std::endl;
400 std::cout << std::endl;
401 std::cout <<
"----------------------------------------------" << std::endl;
402 std::cout << std::endl;
404 #ifdef VIENNACL_WITH_OPENCL
406 std::cout <<
"No double precision support, skipping test..." << std::endl;
410 std::cout << std::endl;
411 std::cout <<
"------- Test completed --------" << std::endl;
412 std::cout << std::endl;
Sparse matrix class using a hybrid format composed of the ELL and CSR format for storing the nonzeros...
A reader and writer for the matrix market format is implemented here.
Generic interface for the l^2-norm. See viennacl/linalg/vector_operations.hpp for implementations...
viennacl::enable_if< viennacl::is_any_sparse_matrix< M1 >::value, matrix_expression< const M1, const M1, op_trans > >::type trans(const M1 &mat)
Returns an expression template class representing a transposed matrix.
Generic interface for matrix-vector and matrix-matrix products. See viennacl/linalg/vector_operations...
Implementation of the dense matrix class.
int check_matrices(std::vector< std::vector< NumericT > > const &ref_mat, std::vector< std::vector< NumericT > > const &mat, NumericT eps)
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.
Implementation of the coordinate_matrix class.
int test(NumericT epsilon)
Implementation of the hyb_matrix class.
VectorT prod(std::vector< std::vector< T, A1 >, A2 > const &matrix, VectorT const &vector)
vcl_size_t size(VectorType const &vec)
Generic routine for obtaining the size of a vector (ViennaCL, uBLAS, etc.)
Sparse matrix class using the ELLPACK format for storing the nonzeros.
void clear()
Resets all entries to zero.
Implementation of the compressed_matrix class.
void compute_reference_result(std::vector< std::map< IndexT, NumericT > > const &A, std::vector< std::vector< NumericT > > const &B, std::vector< std::vector< NumericT > > &C)
bool double_support() const
ViennaCL convenience function: Returns true if the device supports double precision.
Implementation of the ell_matrix class.
Implementations of dense direct solvers are found here.
The vector type with operator-overloads and proxy classes is defined here. Linear algebra operations ...
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.
long read_matrix_market_file(MatrixT &mat, const char *file, long index_base=1)
Reads a sparse matrix from a file (MatrixMarket format)
Implementation of the ViennaCL scalar class.
A sparse square matrix, where entries are stored as triplets (i,j, val), where i and j are the row an...