tensor-0.1.0
 All Data Structures Namespaces Functions Variables Typedefs Enumerations Enumerator Groups Pages
eigs_sp_z.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 <tensor/linalg.h>
25 #include <tensor/arpack_z.h>
26 
27 #define COMPLEX
28 
29 namespace linalg {
30 
31  CTensor
32  eigs(const CSparse &A, int eig_type, size_t neig, CTensor *eigenvectors,
33  const CTensor::elt_t *initial_guess)
34  {
35  EigType t = (EigType)eig_type;
36  size_t n = A.columns();
37 
38  if (n <= 10) {
39  return eigs(full(A), t, neig, eigenvectors, initial_guess);
40  }
41 
42  if (A.rows() != n) {
43  std::cerr << "In eigs(): Can only compute eigenvalues of square matrices.";
44  abort();
45  }
46 
47  CTensor output;
48  {
49  CArpack data(n, t, neig);
50 
51  if (initial_guess)
52  data.set_start_vector(initial_guess);
53 
54  while (data.update() < CArpack::Finished) {
55  data.set_y(mmult(A, data.get_x()));
56  }
57  if (data.get_status() != CArpack::Finished) {
58  std::cerr << data.error_message() << '\n';
59  abort();
60  }
61  output = data.get_data(eigenvectors);
62  }
63  return output;
64  }
65 
66 } // namespace linalg
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.
EigType
Type of eigenvalues that eigs and Arpack compute.
Definition: linalg.h:69