41 #include <boost/numeric/ublas/vector.hpp>
42 #include <boost/numeric/ublas/matrix.hpp>
44 namespace ublas = boost::numeric::ublas;
52 throw std::invalid_argument(
"File is not opened");
58 template <
typename NumericT,
typename MatrixLayout>
63 throw std::invalid_argument(
"File is not opened");
66 boost::numeric::ublas::matrix<NumericT> h_A(A.
size1(), A.
size2());
68 for(std::size_t i = 0; i < h_A.size1(); i++) {
69 for(std::size_t j = 0; j < h_A.size2(); j++) {
79 template<
typename NumericT>
82 throw std::invalid_argument(
"File is not opened");
84 for(std::size_t i = 0; i < v.size(); i++)
92 template<
typename NumericT,
typename MatrixLayout>
95 ublas::matrix<NumericT> A(A_orig.
size1(), A_orig.
size2());
98 for (
unsigned int i = 0; i < A.size1(); i++) {
99 for (
unsigned int j = 0; j < A.size2(); j++) {
100 if ((std::abs(A(i, j)) > EPS) && ((i - 1) != j) && (i != j) && ((i + 1) != j))
110 template <
typename NumericT,
typename MatrixLayout>
113 ublas::matrix<NumericT> A(A_orig.
size1(), A_orig.
size2());
116 for (std::size_t i = 0; i < A.size1(); i++) {
117 for (std::size_t j = 0; j < A.size2(); j++) {
118 if ((std::abs(A(i, j)) > EPS) && (i > (j + 1)))
128 template<
typename NumericT>
130 ublas::matrix<NumericT>& ref)
135 for(std::size_t i = 0; i < res.size1(); i++)
137 for(std::size_t j = 0; j < res.size2(); j++)
139 diff =
std::max(diff, std::abs(res(i, j) - ref(i, j)));
147 template<
typename NumericT>
149 std::vector<NumericT> & ref)
151 std::sort(ref.begin(), ref.end());
152 std::sort(res.begin(), res.end());
156 for(
size_t i = 0; i < res.size(); i++)
158 diff =
std::max(diff, std::abs(res[i] - ref[i]));
165 template <
typename NumericT,
typename MatrixLayout>
168 for (
unsigned int i = 0; i < A.
size1(); i++) {
169 for (
unsigned int j = 0; j < A.
size2(); j++)
170 std::cout << std::fixed << A(i, j) <<
"\t";
175 template <
typename NumericT,
typename MatrixLayout>
178 std::cout <<
"Reading..." <<
"\n";
181 std::fstream f(fn.c_str(), std::fstream::in);
187 std::cout <<
"Testing row-major matrix of size " << sz <<
"-by-" << sz << std::endl;
189 std::cout <<
"Testing column-major matrix of size " << sz <<
"-by-" << sz << std::endl;
193 std::vector<NumericT> eigen_ref_re(sz);
195 std::vector<NumericT> eigen_re(sz);
197 std::vector<NumericT> eigen_im(sz);
209 std::cout <<
"Calculation..." <<
"\n";
229 double time_spend = timer.
get();
231 std::cout <<
"Verification..." <<
"\n";
236 ublas::matrix<NumericT> A_ref_ublas(sz, sz), A_input_ublas(sz, sz), Q_ublas(sz, sz), result1(sz, sz), result2(sz, sz);
242 for (std::size_t i=0; i<result1.size1(); ++i)
243 for (std::size_t j=0; j<result1.size2(); ++j)
246 for (std::size_t k=0; k<Q_ublas.size2(); ++k)
247 value += Q_ublas(i, k) * A_input_ublas(k, j);
248 result1(i,j) = value;
251 for (std::size_t i=0; i<result2.size1(); ++i)
252 for (std::size_t j=0; j<result2.size2(); ++j)
255 for (std::size_t k=0; k<A_ref_ublas.size2(); ++k)
256 value += A_ref_ublas(i, k) * Q_ublas(k, j);
257 result2(i,j) = value;
265 bool is_ok = is_hessenberg;
268 is_ok = is_ok && is_tridiag;
270 is_ok = is_ok && (eigen_diff <
EPS);
271 is_ok = is_ok && (prods_diff <
EPS);
286 printf(
"%6s [%dx%d] %40s time = %.4f\n", is_ok?
"[[OK]]":
"[FAIL]", (
int)A_ref.size1(), (int)A_ref.size2(), fn.c_str(), time_spend);
287 printf(
"tridiagonal = %d, hessenberg = %d prod-diff = %f eigen-diff = %f\n", is_tridiag, is_hessenberg, prods_diff, eigen_diff);
288 std::cout << std::endl << std::endl;
297 float epsilon1 = 0.0001f;
299 std::cout <<
"# Testing setup:" << std::endl;
300 std::cout <<
" eps: " << epsilon1 << std::endl;
301 std::cout <<
" numeric: double" << std::endl;
302 std::cout << std::endl;
303 test_eigen<float, viennacl::row_major >(
"../examples/testdata/eigen/symm5.example",
true, epsilon1);
304 test_eigen<float, viennacl::column_major>(
"../examples/testdata/eigen/symm5.example",
true, epsilon1);
306 #ifdef VIENNACL_WITH_OPENCL
310 double epsilon2 = 1e-5;
312 std::cout <<
"# Testing setup:" << std::endl;
313 std::cout <<
" eps: " << epsilon2 << std::endl;
314 std::cout <<
" numeric: double" << std::endl;
315 std::cout << std::endl;
316 test_eigen<double, viennacl::row_major >(
"../examples/testdata/eigen/symm5.example",
true, epsilon2);
317 test_eigen<double, viennacl::column_major>(
"../examples/testdata/eigen/symm5.example",
true, epsilon2);
328 std::cout << std::endl;
329 std::cout <<
"------- Test completed --------" << std::endl;
330 std::cout << std::endl;
void read_matrix_body(std::fstream &f, viennacl::matrix< NumericT, MatrixLayout > &A)
Helper class for checking whether a matrix has a row-major layout.
Generic interface for matrix-vector and matrix-matrix products. See viennacl/linalg/vector_operations...
bool check_tridiag(viennacl::matrix< NumericT, MatrixLayout > &A_orig, 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.
NumericT vector_compare(std::vector< NumericT > &res, std::vector< NumericT > &ref)
void read_matrix_size(std::fstream &f, std::size_t &sz)
void qr_method_nsm(viennacl::matrix< SCALARTYPE > &A, viennacl::matrix< SCALARTYPE > &Q, std::vector< SCALARTYPE > &D, std::vector< SCALARTYPE > &E)
bool check_hessenberg(viennacl::matrix< NumericT, MatrixLayout > &A_orig, NumericT EPS)
bool double_support() const
ViennaCL convenience function: Returns true if the device supports double precision.
size_type size2() const
Returns the number of columns.
size_type size1() const
Returns the number of rows.
A simple, yet (mostly) sufficiently accurate timer for benchmarking and profiling.
Implementation of the QR method for eigenvalue computations. Experimental.
void test_eigen(const std::string &fn, bool is_symm, NumericT EPS)
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) ...
ScalarType diff(ScalarType &s1, viennacl::scalar< ScalarType > &s2)
void read_vector_body(std::fstream &f, std::vector< NumericT > &v)
void matrix_print(viennacl::matrix< NumericT, MatrixLayout > &A)
NumericT matrix_compare(ublas::matrix< NumericT > &res, ublas::matrix< NumericT > &ref)
void qr_method_sym(viennacl::matrix< SCALARTYPE > &A, viennacl::matrix< SCALARTYPE > &Q, std::vector< SCALARTYPE > &D)