24 #include <tensor/linalg.h>
25 #include <tensor/arpack_z.h>
30 using namespace tensor;
34 const CTensor::elt_t *initial_guess)
39 if ((A.
rank() != 2) || (A.
rows() != n)) {
40 std::cerr <<
"In eigs(): Can only compute eigenvalues of square matrices.";
44 if (neig > n || neig == 0) {
45 std::cerr <<
"In eigs(): Can only compute up to " << n <<
" eigenvalues\n"
46 <<
"in a matrix that has " << n <<
" times " << n <<
" elements.";
56 CTensor values =
eig(A, NULL, eigenvectors? &vectors : 0);
57 Indices ndx = CArpack::sort_values(values, t);
59 std::copy(ndx.begin(), ndx.begin() + neig, ndx_out.begin());
61 *eigenvectors = vectors(range(), range(ndx_out));
63 return CTensor(values(range(ndx_out)));
68 CArpack data(n, t, neig);
71 data.set_start_vector(initial_guess);
73 while (data.update() < CArpack::Finished) {
74 blas::gemv(
'N', n, n, number_one<cdouble>(), A.
begin(), n, data.get_x_vector(), 1,
75 number_zero<cdouble>(), data.get_y_vector(), 1);
77 if (data.get_status() != CArpack::Finished) {
78 std::cerr << data.error_message() <<
'\n';
81 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.
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.