20 #include <tensor/linalg.h>
21 #include <tensor/arpack_d.h>
26 using namespace tensor;
30 const RTensor::elt_t *initial_guess)
35 if ((A.
rank() != 2) || (A.
rows() != n)) {
36 std::cerr <<
"In eigs(): Can only compute eigenvalues of square matrices.";
40 if (neig > n || neig == 0) {
41 std::cerr <<
"In eigs(): Can only compute up to " << n <<
" eigenvalues\n"
42 <<
"in a matrix that has " << n <<
" times " << n <<
" elements.";
52 CTensor values =
eig(A, NULL, eigenvectors? &vectors : 0);
53 Indices ndx = RArpack::sort_values(values, t);
55 std::copy(ndx.begin(), ndx.begin() + neig, ndx_out.begin());
57 *eigenvectors = tensor::real(vectors(range(), range(ndx_out)));
59 return tensor::real(values(range(ndx_out)));
64 RArpack data(n, t, neig);
67 data.set_start_vector(initial_guess);
69 while (data.update() < RArpack::Finished) {
70 blas::gemv(
'N', n, n, 1.0, A.
begin(), n, data.get_x_vector(), 1,
71 0.0, data.get_y_vector(), 1);
73 if (data.get_status() != RArpack::Finished) {
74 std::cerr << data.error_message() <<
'\n';
77 output = data.get_data(eigenvectors);
int rank() const
Number of Tensor indices.
const CTensor eig(const RTensor &A, CTensor *R=0, CTensor *L=0)
Eigenvalue decomposition of a real matrix.
index columns() const
Query the size of 2nd index.
index rows() const
Query then size of 1st index.
Real Tensor with elements of type "double".
CTensor eigs(const CTensor &A, int eig_type, size_t neig, CTensor *vectors=NULL, const tensor::cdouble *initial_guess=NULL)
Find out a few eigenvalues and eigenvectors of a complex nonsymmetric matrix.
iterator begin()
Iterator at the beginning.
Complex Tensor with elements of type "cdouble".
Vector of 'index' type, where 'index' fits the indices of a tensor.
EigType
Type of eigenvalues that eigs and Arpack compute.