tensor-0.1.0
 All Data Structures Namespaces Functions Variables Typedefs Enumerations Enumerator Groups Pages
eigs_sp_t.cc
1 // -*- mode: c++; fill-column: 80; c-basic-offset: 2; indent-tabs-mode: nil -*-
2 /*
3  Copyright (c) 2010 Juan Jose Garcia Ripoll
4 
5  Tensor is free software; you can redistribute it and/or modify it
6  under the terms of the GNU Library General Public License as published
7  by the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Library General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License along
16  with this program; if not, write to the Free Software Foundation, Inc.,
17  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19 
20 //----------------------------------------------------------------------
21 // ARPACK DRIVER FOR NONSYMMETRIC SPARSE EIGENVALUE PROBLEMS
22 //
23 
24 #include "linalg.h"
25 #include "arpack.h"
26 
27 Tensor<ELT_T>
28 eigs(const Sparse<ELT_T> &A, int eig_type, size_t neig,
29  Tensor<ELT_T> *eigenvectors,
30  const Tensor::elt_t *initial_guess)
31 {
32  Arpack::EigType t = (Arpack::EigType)eig_type;
33  size_t n = A.columns();
34 
35  if (n <= 10) {
36  return eigs(full(A), t, neig, eigenvectors, initial_guess);
37  }
38 
39  if (A.rows() != n) {
40  std::cerr << "In eigs(): Can only compute eigenvalues of square matrices.";
41  myabort();
42  }
43 
44  Arpack data(A.columns(), t, neig);
45 
46  if (initial_guess)
47  data.set_start_vector(initial_guess);
48 
49  while (data.update() < Arpack::Finished) {
50  data.set_y(mmult(A, data.get_x()));
51  }
52  if (data.get_status() == Arpack::Finished) {
53  return data.get_data(eigenvectors);
54  } else {
55  std::cerr << data.error_message() << '\n';
56  myabort();
57  }
58  return Tensor<ELT_T>();
59 }
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.