44 #include <boost/numeric/ublas/vector.hpp>
45 #include <boost/numeric/ublas/matrix.hpp>
59 throw std::invalid_argument(
"File is not opened");
65 template <
typename MatrixLayout>
70 throw std::invalid_argument(
"File is not opened");
73 boost::numeric::ublas::matrix<ScalarType> h_A(A.
size1(), A.
size2());
75 for(std::size_t i = 0; i < h_A.size1(); i++) {
76 for(std::size_t j = 0; j < h_A.size2(); j++) {
90 throw std::invalid_argument(
"File is not opened");
92 for(std::size_t i = 0; i < v.size(); i++)
100 template <
typename MatrixLayout>
103 ublas::matrix<ScalarType> A(A_orig.
size1(), A_orig.
size2());
106 for (
unsigned int i = 0; i < A.size1(); i++) {
107 for (
unsigned int j = 0; j < A.size2(); j++) {
108 if ((std::abs(A(i, j)) >
EPS) && ((i - 1) != j) && (i != j) && ((i + 1) != j))
118 template <
typename MatrixLayout>
121 ublas::matrix<ScalarType> A(A_orig.
size1(), A_orig.
size2());
124 for (std::size_t i = 0; i < A.size1(); i++) {
125 for (std::size_t j = 0; j < A.size2(); j++) {
126 if ((std::abs(A(i, j)) >
EPS) && (i > (j + 1)))
137 ublas::matrix<ScalarType>& ref);
140 ublas::matrix<ScalarType>& ref)
145 for(std::size_t i = 0; i < res.size1(); i++)
147 for(std::size_t j = 0; j < res.size2(); j++)
149 diff =
std::max(diff, std::abs(res(i, j) - ref(i, j)));
158 std::vector<ScalarType> & ref);
161 std::vector<ScalarType> & ref)
163 std::sort(ref.begin(), ref.end());
164 std::sort(res.begin(), res.end());
168 for(
size_t i = 0; i < res.size(); i++)
170 diff =
std::max(diff, std::abs(res[i] - ref[i]));
177 template <
typename MatrixLayout>
180 for (
unsigned int i = 0; i < A.
size1(); i++) {
181 for (
unsigned int j = 0; j < A.
size2(); j++)
182 std::cout << std::fixed << A(i, j) <<
"\t";
187 template <
typename MatrixLayout>
190 std::cout <<
"Reading..." <<
"\n";
193 std::fstream f(fn.c_str(), std::fstream::in);
199 std::cout <<
"Testing row-major matrix of size " << sz <<
"-by-" << sz << std::endl;
201 std::cout <<
"Testing column-major matrix of size " << sz <<
"-by-" << sz << std::endl;
205 std::vector<ScalarType> eigen_ref_re(sz);
207 std::vector<ScalarType> eigen_re(sz);
209 std::vector<ScalarType> eigen_im(sz);
221 std::cout <<
"Calculation..." <<
"\n";
241 double time_spend = timer.
get();
243 std::cout <<
"Verification..." <<
"\n";
248 ublas::matrix<ScalarType> A_ref_ublas(sz, sz), A_input_ublas(sz, sz), Q_ublas(sz, sz), result1(sz, sz), result2(sz, sz);
254 for (std::size_t i=0; i<result1.size1(); ++i)
255 for (std::size_t j=0; j<result1.size2(); ++j)
258 for (std::size_t k=0; k<Q_ublas.size2(); ++k)
259 value += Q_ublas(i, k) * A_input_ublas(k, j);
260 result1(i,j) = value;
263 for (std::size_t i=0; i<result2.size1(); ++i)
264 for (std::size_t j=0; j<result2.size2(); ++j)
267 for (std::size_t k=0; k<A_ref_ublas.size2(); ++k)
268 value += A_ref_ublas(i, k) * Q_ublas(k, j);
269 result2(i,j) = value;
277 bool is_ok = is_hessenberg;
280 is_ok = is_ok && is_tridiag;
282 is_ok = is_ok && (eigen_diff <
EPS);
283 is_ok = is_ok && (prods_diff <
EPS);
298 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);
299 printf(
"tridiagonal = %d, hessenberg = %d prod-diff = %f eigen-diff = %f\n", is_tridiag, is_hessenberg, prods_diff, eigen_diff);
300 std::cout << std::endl << std::endl;
310 test_eigen<viennacl::row_major>(
"../examples/testdata/eigen/symm5.example",
true);
313 test_eigen<viennacl::column_major>(
"../examples/testdata/eigen/symm5.example",
true);
321 std::cout << std::endl;
322 std::cout <<
"------- Test completed --------" << std::endl;
323 std::cout << std::endl;
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...
void matrix_print(viennacl::matrix< ScalarType, MatrixLayout > &A)
bool check_hessenberg(viennacl::matrix< ScalarType, MatrixLayout > &A_orig)
void read_vector_body(std::fstream &f, std::vector< ScalarType > &v)
T max(const T &lhs, const T &rhs)
Maximum.
void test_eigen(const std::string &fn, bool is_symm)
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)
size_type size2() const
Returns the number of columns.
size_type size1() const
Returns the number of rows.
ScalarType matrix_compare(ublas::matrix< ScalarType > &res, ublas::matrix< ScalarType > &ref)
bool check_tridiag(viennacl::matrix< ScalarType, MatrixLayout > &A_orig)
Implementation of the QR method for eigenvalue computations. Experimental.
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 vector_compare(std::vector< ScalarType > &res, std::vector< ScalarType > &ref)
ScalarType diff(ScalarType &s1, viennacl::scalar< ScalarType > &s2)
void read_matrix_body(std::fstream &f, viennacl::matrix< ScalarType, MatrixLayout > &A)
void qr_method_sym(viennacl::matrix< SCALARTYPE > &A, viennacl::matrix< SCALARTYPE > &Q, std::vector< SCALARTYPE > &D)