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
71 template<
typename ScalarType >
75 size1 = ref_mat.size1(); size2 = ref_mat.size2();
76 if ( (size1 != mat.size1()) || (size2 != mat.size2()) )
79 for (
unsigned int i = 0; i <
size1; i++)
80 for (
unsigned int j = 0; j <
size2; j++)
82 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)));
83 if ( rel_error > eps ) {
84 std::cout <<
"ERROR: Verification failed at (" << i <<
", "<< j <<
"): "
85 <<
" Expected: " << ref_mat(i,j) <<
", got: " << mat(i,j) <<
" (relative error: " << rel_error <<
")" << std::endl;
90 std::cout <<
"Everything went well!" << std::endl;
94 template<
typename NumericT,
typename ResultLayoutT,
typename FactorLayoutT>
97 int retVal = EXIT_SUCCESS;
99 ublas::compressed_matrix<NumericT> ublas_lhs;
103 std::cout <<
"Error reading Matrix file" << std::endl;
108 for (std::size_t i=0; i<ublas_lhs.size1(); ++i)
109 ublas_lhs(i,i) *= NumericT(1.5);
111 std::size_t cols_rhs = 1;
118 ublas::matrix<NumericT> ublas_result;
126 ublas::matrix<NumericT> ublas_rhs1(ublas_lhs.size2(), cols_rhs);
129 ublas::matrix<NumericT> ublas_rhs2;
132 ublas::matrix<NumericT> temp(ublas_rhs1.size1(), cols_rhs);
134 for (
unsigned int i = 0; i < ublas_rhs1.size1(); i++)
135 for (
unsigned int j = 0; j < ublas_rhs1.size2(); j++)
136 ublas_rhs1(i,j) = NumericT(0.5) + NumericT(0.1) * random<NumericT>();
143 ublas_result =
ublas::prod( ublas_lhs, ublas_rhs1);
146 std::cout <<
"Testing compressed(CSR) lhs * dense rhs" << std::endl;
154 std::cout <<
"Testing compressed(ELL) lhs * dense rhs" << std::endl;
164 std::cout <<
"Testing compressed(COO) lhs * dense rhs" << std::endl;
174 std::cout <<
"Testing compressed(HYB) lhs * dense rhs" << std::endl;
188 std::cout << std::endl <<
"Testing compressed(CSR) lhs * transposed dense rhs:" << std::endl;
197 std::cout <<
"Testing compressed(ELL) lhs * transposed dense rhs" << std::endl;
206 std::cout <<
"Testing compressed(COO) lhs * transposed dense rhs" << std::endl;
216 std::cout <<
"Testing compressed(HYB) lhs * transposed dense rhs" << std::endl;
225 if (retVal == EXIT_SUCCESS) {
226 std::cout <<
"Tests passed successfully" << std::endl;
237 std::cout << std::endl;
238 std::cout <<
"----------------------------------------------" << std::endl;
239 std::cout <<
"----------------------------------------------" << std::endl;
240 std::cout <<
"## Test :: Sparse-Dense Matrix Multiplication" << std::endl;
241 std::cout <<
"----------------------------------------------" << std::endl;
242 std::cout <<
"----------------------------------------------" << std::endl;
243 std::cout << std::endl;
245 int retval = EXIT_SUCCESS;
247 std::cout << std::endl;
248 std::cout <<
"----------------------------------------------" << std::endl;
249 std::cout << std::endl;
251 typedef float NumericT;
252 NumericT epsilon =
static_cast<NumericT
>(1E-4);
253 std::cout <<
"# Testing setup:" << std::endl;
254 std::cout <<
" eps: " << epsilon << std::endl;
255 std::cout <<
" numeric: float" << std::endl;
256 std::cout <<
" layout: row-major, row-major" << std::endl;
257 retval = test<NumericT, viennacl::row_major, viennacl::row_major>(epsilon);
258 if ( retval == EXIT_SUCCESS )
259 std::cout <<
"# Test passed" << std::endl;
263 std::cout <<
"# Testing setup:" << std::endl;
264 std::cout <<
" eps: " << epsilon << std::endl;
265 std::cout <<
" numeric: float" << std::endl;
266 std::cout <<
" layout: row-major, column-major" << std::endl;
267 retval = test<NumericT, viennacl::row_major, viennacl::column_major>(epsilon);
268 if ( retval == EXIT_SUCCESS )
269 std::cout <<
"# Test passed" << std::endl;
273 std::cout <<
"# Testing setup:" << std::endl;
274 std::cout <<
" eps: " << epsilon << std::endl;
275 std::cout <<
" numeric: float" << std::endl;
276 std::cout <<
" layout: column-major, row-major" << std::endl;
277 retval = test<NumericT, viennacl::column_major, viennacl::row_major>(epsilon);
278 if ( retval == EXIT_SUCCESS )
279 std::cout <<
"# Test passed" << std::endl;
283 std::cout <<
"# Testing setup:" << std::endl;
284 std::cout <<
" eps: " << epsilon << std::endl;
285 std::cout <<
" numeric: float" << std::endl;
286 std::cout <<
" layout: column-major, column-major" << std::endl;
287 retval = test<NumericT, viennacl::column_major, viennacl::column_major>(epsilon);
288 if ( retval == EXIT_SUCCESS )
289 std::cout <<
"# Test passed" << std::endl;
294 std::cout << std::endl;
295 std::cout <<
"----------------------------------------------" << std::endl;
296 std::cout << std::endl;
298 #ifdef VIENNACL_WITH_OPENCL
303 typedef double NumericT;
304 NumericT epsilon = 1.0E-12;
305 std::cout <<
"# Testing setup:" << std::endl;
306 std::cout <<
" eps: " << epsilon << std::endl;
307 std::cout <<
" numeric: double" << std::endl;
308 std::cout <<
" layout: row-major, row-major" << std::endl;
309 retval = test<NumericT, viennacl::row_major, viennacl::row_major>(epsilon);
310 if ( retval == EXIT_SUCCESS )
311 std::cout <<
"# Test passed" << std::endl;
315 std::cout <<
"# Testing setup:" << std::endl;
316 std::cout <<
" eps: " << epsilon << std::endl;
317 std::cout <<
" numeric: double" << std::endl;
318 std::cout <<
" layout: row-major, column-major" << std::endl;
319 retval = test<NumericT, viennacl::row_major, viennacl::column_major>(epsilon);
320 if ( retval == EXIT_SUCCESS )
321 std::cout <<
"# Test passed" << std::endl;
325 std::cout <<
"# Testing setup:" << std::endl;
326 std::cout <<
" eps: " << epsilon << std::endl;
327 std::cout <<
" numeric: double" << std::endl;
328 std::cout <<
" layout: column-major, row-major" << std::endl;
329 retval = test<NumericT, viennacl::column_major, viennacl::row_major>(epsilon);
330 if ( retval == EXIT_SUCCESS )
331 std::cout <<
"# Test passed" << std::endl;
335 std::cout <<
"# Testing setup:" << std::endl;
336 std::cout <<
" eps: " << epsilon << std::endl;
337 std::cout <<
" numeric: double" << std::endl;
338 std::cout <<
" layout: column-major, column-major" << std::endl;
339 retval = test<NumericT, viennacl::column_major, viennacl::column_major>(epsilon);
340 if ( retval == EXIT_SUCCESS )
341 std::cout <<
"# Test passed" << std::endl;
345 std::cout << std::endl;
346 std::cout <<
"----------------------------------------------" << std::endl;
347 std::cout << std::endl;
349 #ifdef VIENNACL_WITH_OPENCL
351 std::cout <<
"No double precision support, skipping test..." << std::endl;
355 std::cout << std::endl;
356 std::cout <<
"------- Test completed --------" << std::endl;
357 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.
void prod(const MatrixT1 &A, bool transposed_A, const MatrixT2 &B, bool transposed_B, MatrixT3 &C, ScalarT alpha, ScalarT beta)
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) ...
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...