ViennaCL - The Vienna Computing Library: examples/tutorial/tql2.cpp Source File

ViennaCL - The Vienna Computing Library 1.7.1 Free open-source GPU-accelerated linear algebra and solver library. |

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
tql2.cpp
Go to the documentation of this file.
1 /* =========================================================================
2 Copyright (c) 2010-2016, Institute for Microelectronics,
3 Institute for Analysis and Scientific Computing,
4 TU Wien.
5 Portions of this software are copyright by UChicago Argonne, LLC.
6
7 -----------------
8 ViennaCL - The Vienna Computing Library
9 -----------------
10
11 Project Head: Karl Rupp rupp@iue.tuwien.ac.at
12
13 (A list of authors and contributors can be found in the PDF manual)
14
15 License: MIT (X11), see file LICENSE in the base directory
16 ============================================================================= */
17
25 // include necessary system headers
26 #include <iostream>
27 #include <fstream>
28 #include <limits>
29 #include <string>
30 #include <iomanip>
31
32 #define VIENNACL_WITH_UBLAS
33
34 //include basic scalar and vector types of ViennaCL
35 #include "viennacl/scalar.hpp"
36 #include "viennacl/vector.hpp"
37 #include "viennacl/compressed_matrix.hpp"
38 #include "viennacl/io/matrix_market.hpp"
39
40 #include "viennacl/linalg/qr-method.hpp"
41 #include "viennacl/linalg/qr-method-common.hpp"
42 #include "viennacl/linalg/host_based/matrix_operations.hpp"
43
44 // Use the shortcut 'ublas::' instead of 'boost::numeric::ublas::'
45 namespace ublas = boost::numeric::ublas;
46
47 // Run in single precision. Change to double precision if provided by your GPU.
48 typedef float ScalarType;
49
53 int main()
54 {
55 std::size_t sz = 10;
56 std::cout << "Compute eigenvalues and eigenvectors of matrix of size " << sz << "-by-" << sz << std::endl << std::endl;
57
58 std::vector<ScalarType> d(sz), e(sz);
59 // Initialize diagonal and superdiagonal elements of the tridiagonal matrix
60 d[0] = 1; e[0] = 0;
61 d[1] = 2; e[1] = 4;
62 d[2] =-4; e[2] = 5;
63 d[3] = 6; e[3] = 1;
64 d[4] = 3; e[4] = 2;
65 d[5] = 4; e[5] =-3;
66 d[6] = 7; e[6] = 5;
67 d[7] = 9; e[7] = 1;
68 d[8] = 3; e[8] = 5;
69 d[9] = 8; e[9] = 2;
70
74 viennacl::matrix<ScalarType> Q = viennacl::identity_matrix<ScalarType>(sz);
75
79 viennacl::linalg::tql2(Q, d, e);
80
84 std::cout << "Eigenvalues: " << std::endl;
85 for (unsigned int i = 0; i < d.size(); i++)
86 std::cout << std::setprecision(6) << std::fixed << d[i] << " ";
87 std::cout << std::endl;
88
89 std::cout << std::endl;
90 std::cout << "Eigenvectors corresponding to the eigenvalues above are the columns: " << std::endl << std::endl;
91 std::cout << Q << std::endl;
92
96 std::cout << std::endl <<"--------TUTORIAL COMPLETED----------" << std::endl;
97
98 return EXIT_SUCCESS;
99 }
matrix_operations.hpp
Implementations of dense matrix related operations, including matrix-vector products, using a plain single-threaded or OpenMP-enabled execution on CPU.
matrix_market.hpp
A reader and writer for the matrix market format is implemented here.
main
int main()
Definition: bisect.cpp:91
viennacl::linalg::tql2
void tql2(matrix_base< SCALARTYPE, F > &Q, VectorType &d, VectorType &e)
Definition: tql2.hpp:131
viennacl::matrix
A dense matrix class.
Definition: forwards.h:375
viennacl::identity_matrix
Represents a vector consisting of 1 at a given index and zeros otherwise. To be used as an initialize...
Definition: matrix_def.hpp:69
qr-method-common.hpp
Common routines used for the QR method and SVD. Experimental.
compressed_matrix.hpp
Implementation of the compressed_matrix class.
qr-method.hpp
Implementation of the QR method for eigenvalue computations. Experimental.
vector.hpp
The vector type with operator-overloads and proxy classes is defined here. Linear algebra operations ...
ScalarType
float ScalarType
Definition: fft_1d.cpp:42
scalar.hpp
Implementation of the ViennaCL scalar class.