51 template<
typename NumericT>
52 void initInputData(std::vector<NumericT> &diagonal, std::vector<NumericT> &superdiagonal, std::size_t mat_size)
56 bool randomValues =
false;
59 if (randomValues ==
true)
62 for (std::size_t i = 0; i < mat_size; ++i)
64 diagonal[i] =
static_cast<NumericT
>(2.0 * (((double)rand()
65 / (double) RAND_MAX) - 0.5));
66 superdiagonal[i] =
static_cast<NumericT
>(2.0 * (((double)rand()
67 / (double) RAND_MAX) - 0.5));
74 for (std::size_t i = 0; i < mat_size; ++i)
76 diagonal[i] = ((NumericT)(i % 8)) - 4.5f;
77 superdiagonal[i] = ((NumericT)(i % 5)) - 4.5f;
83 superdiagonal[0] = 0.0f;
90 template<
typename NumericT>
95 std::vector<NumericT> diagonal(mat_size);
96 std::vector<NumericT> superdiagonal(mat_size);
97 std::vector<NumericT> eigenvalues_bisect(mat_size);
105 std::cout <<
"Start the bisection algorithm" << std::endl;
106 std::cout <<
"Matrix size: " << mat_size << std::endl;
109 if (bResult ==
false)
117 std::vector<NumericT> diagonal_tql(mat_size);
118 std::vector<NumericT> superdiagonal_tql(mat_size);
119 diagonal_tql = diagonal;
120 superdiagonal_tql = superdiagonal;
123 std::cout <<
"Start the tql2 algorithm..." << std::endl;
127 std::sort(diagonal_tql.begin(), diagonal_tql.end());
132 std::cout <<
"Start comparison..." << std::endl;
133 for (std::size_t i = 0; i < mat_size; i++)
135 if (std::abs(eigenvalues_bisect[i] - diagonal_tql[i]) >
EPS)
137 std::cout << std::setprecision(8) << eigenvalues_bisect[i] <<
" != " << diagonal_tql[i] <<
"\n";
162 bool test_result =
false;
165 test_result = runTest<float>(520);
166 if(test_result ==
true)
168 std::cout <<
"First Test Succeeded!" << std::endl << std::endl;
172 std::cout <<
"---TEST FAILED---" << std::endl;
177 test_result = runTest<float>(230);
178 if(test_result ==
true)
180 std::cout << std::endl <<
"---TEST SUCCESSFULLY COMPLETED---" << std::endl;
185 std::cout <<
"---TEST FAILED---" << std::endl;
void initInputData(std::vector< NumericT > &diagonal, std::vector< NumericT > &superdiagonal, std::size_t mat_size)
initInputData Initialize the diagonal and superdiagonal elements of the matrix
Implementation of the dense matrix class.
void tql2(matrix_base< SCALARTYPE, F > &Q, VectorType &d, VectorType &e)
Implementation of the tql2-algorithm for eigenvalue computations.
Represents a vector consisting of 1 at a given index and zeros otherwise. To be used as an initialize...
Implementation of an bisection algorithm for eigenvalues.
std::vector< typename viennacl::result_of::cpu_value_type< typename VectorT::value_type >::type > bisect(VectorT const &alphas, VectorT const &betas)
Implementation of the bisect-algorithm for the calculation of the eigenvalues of a tridiagonal matrix...
bool runTest(std::size_t mat_size)
Run a simple test.
The vector type with operator-overloads and proxy classes is defined here. Linear algebra operations ...
Implementation of the ViennaCL scalar class.