32 #include <boost/numeric/ublas/io.hpp>
33 #include <boost/numeric/ublas/triangular.hpp>
34 #include <boost/numeric/ublas/matrix_sparse.hpp>
35 #include <boost/numeric/ublas/matrix.hpp>
36 #include <boost/numeric/ublas/matrix_proxy.hpp>
37 #include <boost/numeric/ublas/operation.hpp>
38 #include <boost/numeric/ublas/operation_sparse.hpp>
39 #include <boost/numeric/ublas/io.hpp>
40 #include <boost/numeric/ublas/lu.hpp>
43 #define VIENNACL_WITH_UBLAS 1
68 template<
typename ScalarType >
72 size1 = ref_mat.size1(); size2 = ref_mat.size2();
73 if ( (size1 != mat.size1()) || (size2 != mat.size2()) )
76 for (
unsigned int i = 0; i <
size1; i++)
77 for (
unsigned int j = 0; j <
size2; j++)
79 ScalarType rel_error = std::abs(ref_mat(i,j) - mat(i,j)) /
std::max(std::abs(ref_mat(i,j)), std::abs(mat(i,j)));
80 if ( rel_error > eps ) {
81 std::cout <<
"ERROR: Verification failed at (" << i <<
", "<< j <<
"): "
82 <<
" Expected: " << ref_mat(i,j) <<
", got: " << mat(i,j) <<
" (relative error: " << rel_error <<
")" << std::endl;
87 std::cout <<
"Everything went well!" << std::endl;
91 template<
typename NumericT,
typename ResultLayoutT,
typename FactorLayoutT>
94 int retVal = EXIT_SUCCESS;
98 ublas::compressed_matrix<NumericT> ublas_lhs;
102 std::cout <<
"Error reading Matrix file" << std::endl;
107 for (std::size_t i=0; i<ublas_lhs.size1(); ++i)
110 std::size_t cols_rhs = 1;
117 ublas::matrix<NumericT> ublas_result;
125 ublas::matrix<NumericT> ublas_rhs1(ublas_lhs.size2(), cols_rhs);
128 ublas::matrix<NumericT> ublas_rhs2;
131 ublas::matrix<NumericT> temp(ublas_rhs1.size1(), cols_rhs);
133 for (
unsigned int i = 0; i < ublas_rhs1.size1(); i++)
134 for (
unsigned int j = 0; j < ublas_rhs1.size2(); j++)
142 ublas_result =
ublas::prod( ublas_lhs, ublas_rhs1);
145 std::cout <<
"Testing compressed(CSR) lhs * dense rhs" << std::endl;
153 std::cout <<
"Testing compressed(ELL) lhs * dense rhs" << std::endl;
163 std::cout <<
"Testing compressed(COO) lhs * dense rhs" << std::endl;
173 std::cout <<
"Testing compressed(HYB) lhs * dense rhs" << std::endl;
187 std::cout << std::endl <<
"Testing compressed(CSR) lhs * transposed dense rhs:" << std::endl;
196 std::cout <<
"Testing compressed(ELL) lhs * transposed dense rhs" << std::endl;
205 std::cout <<
"Testing compressed(COO) lhs * transposed dense rhs" << std::endl;
215 std::cout <<
"Testing compressed(HYB) lhs * transposed dense rhs" << std::endl;
224 if (retVal == EXIT_SUCCESS) {
225 std::cout <<
"Tests passed successfully" << std::endl;
236 std::cout << std::endl;
237 std::cout <<
"----------------------------------------------" << std::endl;
238 std::cout <<
"----------------------------------------------" << std::endl;
239 std::cout <<
"## Test :: Sparse-Dense Matrix Multiplication" << std::endl;
240 std::cout <<
"----------------------------------------------" << std::endl;
241 std::cout <<
"----------------------------------------------" << std::endl;
242 std::cout << std::endl;
244 int retval = EXIT_SUCCESS;
246 std::cout << std::endl;
247 std::cout <<
"----------------------------------------------" << std::endl;
248 std::cout << std::endl;
251 NumericT epsilon =
static_cast<NumericT
>(1E-4);
252 std::cout <<
"# Testing setup:" << std::endl;
253 std::cout <<
" eps: " << epsilon << std::endl;
254 std::cout <<
" numeric: float" << std::endl;
255 std::cout <<
" layout: row-major, row-major" << std::endl;
256 retval = test<NumericT, viennacl::row_major, viennacl::row_major>(epsilon);
257 if ( retval == EXIT_SUCCESS )
258 std::cout <<
"# Test passed" << std::endl;
262 std::cout <<
"# Testing setup:" << std::endl;
263 std::cout <<
" eps: " << epsilon << std::endl;
264 std::cout <<
" numeric: float" << std::endl;
265 std::cout <<
" layout: row-major, column-major" << std::endl;
266 retval = test<NumericT, viennacl::row_major, viennacl::column_major>(epsilon);
267 if ( retval == EXIT_SUCCESS )
268 std::cout <<
"# Test passed" << std::endl;
272 std::cout <<
"# Testing setup:" << std::endl;
273 std::cout <<
" eps: " << epsilon << std::endl;
274 std::cout <<
" numeric: float" << std::endl;
275 std::cout <<
" layout: column-major, row-major" << std::endl;
276 retval = test<NumericT, viennacl::column_major, viennacl::row_major>(epsilon);
277 if ( retval == EXIT_SUCCESS )
278 std::cout <<
"# Test passed" << std::endl;
282 std::cout <<
"# Testing setup:" << std::endl;
283 std::cout <<
" eps: " << epsilon << std::endl;
284 std::cout <<
" numeric: float" << std::endl;
285 std::cout <<
" layout: column-major, column-major" << std::endl;
286 retval = test<NumericT, viennacl::column_major, viennacl::column_major>(epsilon);
287 if ( retval == EXIT_SUCCESS )
288 std::cout <<
"# Test passed" << std::endl;
293 std::cout << std::endl;
294 std::cout <<
"----------------------------------------------" << std::endl;
295 std::cout << std::endl;
297 #ifdef VIENNACL_WITH_OPENCL
303 NumericT epsilon = 1.0E-12;
304 std::cout <<
"# Testing setup:" << std::endl;
305 std::cout <<
" eps: " << epsilon << std::endl;
306 std::cout <<
" numeric: double" << std::endl;
307 std::cout <<
" layout: row-major, row-major" << std::endl;
308 retval = test<NumericT, viennacl::row_major, viennacl::row_major>(epsilon);
309 if ( retval == EXIT_SUCCESS )
310 std::cout <<
"# Test passed" << std::endl;
314 std::cout <<
"# Testing setup:" << std::endl;
315 std::cout <<
" eps: " << epsilon << std::endl;
316 std::cout <<
" numeric: double" << std::endl;
317 std::cout <<
" layout: row-major, column-major" << std::endl;
318 retval = test<NumericT, viennacl::row_major, viennacl::column_major>(epsilon);
319 if ( retval == EXIT_SUCCESS )
320 std::cout <<
"# Test passed" << std::endl;
324 std::cout <<
"# Testing setup:" << std::endl;
325 std::cout <<
" eps: " << epsilon << std::endl;
326 std::cout <<
" numeric: double" << std::endl;
327 std::cout <<
" layout: column-major, row-major" << std::endl;
328 retval = test<NumericT, viennacl::column_major, viennacl::row_major>(epsilon);
329 if ( retval == EXIT_SUCCESS )
330 std::cout <<
"# Test passed" << std::endl;
334 std::cout <<
"# Testing setup:" << std::endl;
335 std::cout <<
" eps: " << epsilon << std::endl;
336 std::cout <<
" numeric: double" << std::endl;
337 std::cout <<
" layout: column-major, column-major" << std::endl;
338 retval = test<NumericT, viennacl::column_major, viennacl::column_major>(epsilon);
339 if ( retval == EXIT_SUCCESS )
340 std::cout <<
"# Test passed" << std::endl;
344 std::cout << std::endl;
345 std::cout <<
"----------------------------------------------" << std::endl;
346 std::cout << std::endl;
348 #ifdef VIENNACL_WITH_OPENCL
350 std::cout <<
"No double precision support, skipping test..." << std::endl;
354 std::cout << std::endl;
355 std::cout <<
"------- Test completed --------" << std::endl;
356 std::cout << std::endl;
Sparse matrix class using a hybrid format composed of the ELL and CSR format for storing the nonzeros...
int check_matrices(const ublas::matrix< ScalarType > &ref_mat, const ublas::matrix< ScalarType > &mat, ScalarType eps)
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.
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.
vcl_size_t size1(MatrixType const &mat)
Generic routine for obtaining the number of rows of a matrix (ViennaCL, uBLAS, etc.)
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.
result_of::size_type< MatrixType >::type size2(MatrixType const &mat)
Generic routine for obtaining the number of columns of a matrix (ViennaCL, uBLAS, etc...
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)
Sparse matrix class using the ELLPACK format for storing the nonzeros.
void clear()
Resets all entries to zero.
Implementation of the compressed_matrix class.
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.
void prod(std::vector< std::map< IndexT, NumericT > > const &stl_A, std::vector< std::map< IndexT, NumericT > > const &stl_B, std::vector< std::map< IndexT, NumericT > > &stl_C)
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...