vnl_complex_generalized_schur.h
Go to the documentation of this file.
1 // This is core/vnl/algo/vnl_complex_generalized_schur.h
2 #ifndef vnl_complex_generalized_schur_h_
3 #define vnl_complex_generalized_schur_h_
4 //:
5 // \file
6 // \brief Solves the generalized eigenproblem det(t A - s B) = 0.
7 // \author Peter Vanroose, ABIS Leuven
8 // \date 9 Jan 2011
9 // Adapted from vnl_generalized_schur.h/.cxx
10 
11 #include <complex>
12 #include <algorithm>
13 #include <vnl/vnl_matrix.h>
14 #include <vnl/vnl_vector.h>
15 #include <vnl/algo/vnl_algo_export.h>
16 
17 
18 //:
19 // For a scalar type T, this function uses orthogonal matrices L, R
20 // over complex<T> to reduce the (square) matrices A, B to generalized
21 // (complex) Schur form. This means that A and B become upper triangular,
22 // A <-- L^* A R, and B <-- L^* B R.
23 // Of course, A and B should be of the same size.
24 //
25 // In addition, the function computes the (complex) generalized eigenvalues
26 // alpha(k) : beta(k) for k = 0, 1, 2,...
27 //
28 // To pass in scalar type T matrices A and B, you'll have to first convert them
29 // to complex matrices since they will be overwritten by they (complex) upper
30 // triangular decomposition.
31 template <class T>
32 bool vnl_generalized_schur(vnl_matrix<std::complex<T> > *A,
33  vnl_matrix<std::complex<T> > *B,
34  vnl_vector<std::complex<T> > *alpha,
35  vnl_vector<std::complex<T> > *beta,
36  vnl_matrix<std::complex<T> > *L,
37  vnl_matrix<std::complex<T> > *R);
38 
39 template <>
40 VNL_ALGO_EXPORT bool vnl_generalized_schur(vnl_matrix<std::complex<double> > *A,
41  vnl_matrix<std::complex<double> > *B,
42  vnl_vector<std::complex<double> > *alpha,
43  vnl_vector<std::complex<double> > *beta,
44  vnl_matrix<std::complex<double> > *L,
45  vnl_matrix<std::complex<double> > *R);
46 
47 #ifdef _MSC_VER
48 # include <vcl_msvc_warnings.h>
49 #endif
50 
51 template <class T>
52 std::complex<T> vnl_complex_generalized_schur_convert_cast(std::complex<double> a) { return static_cast<std::complex<T> >(a); }
53 
54 template <class T>
55 inline bool vnl_generalized_schur(vnl_matrix<std::complex<T> > *A,
56  vnl_matrix<std::complex<T> > *B,
57  vnl_vector<std::complex<T> > *alpha,
58  vnl_vector<std::complex<T> > *beta,
59  vnl_matrix<std::complex<T> > *L,
60  vnl_matrix<std::complex<T> > *R)
61 {
62  vnl_matrix<std::complex<double> > A_(A->rows(), A->cols());
63  vnl_matrix<std::complex<double> > B_(B->rows(), B->cols());
64  std::copy(A->begin(), A->end(), A_.begin());
65  std::copy(B->begin(), B->end(), B_.begin());
66 
71 
72  if (! vnl_generalized_schur/*<std::complex<double> >*/(&A_, &B_, &alpha_, &beta_, &L_, &R_))
73  return false;
74 
75  std::transform(A_.begin(), A_.end(), A->begin(), vnl_complex_generalized_schur_convert_cast<T>);
76  std::transform(B_.begin(), B_.end(), B->begin(), vnl_complex_generalized_schur_convert_cast<T>);
77 
78  alpha->set_size(alpha_.size());
79  std::transform(alpha_.begin(), alpha_.end(), alpha->begin(), vnl_complex_generalized_schur_convert_cast<T>);
80 
81  beta->set_size(beta_.size());
82  std::transform(beta_.begin(), beta_.end(), beta->begin(), vnl_complex_generalized_schur_convert_cast<T>);
83 
84  L->set_size(L_.rows(), L_.cols());
85  std::transform(L_.begin(), L_.end(), L->begin(), vnl_complex_generalized_schur_convert_cast<T>);
86 
87  R->set_size(R_.rows(), R_.cols());
88  std::transform(R_.begin(), R_.end(), R->begin(), vnl_complex_generalized_schur_convert_cast<T>);
89 
90  return true;
91 }
92 
93 #endif // vnl_complex_generalized_schur_h_
unsigned int cols() const
Return the number of columns.
Definition: vnl_matrix.h:183
bool vnl_generalized_schur(vnl_matrix< std::complex< T > > *A, vnl_matrix< std::complex< T > > *B, vnl_vector< std::complex< T > > *alpha, vnl_vector< std::complex< T > > *beta, vnl_matrix< std::complex< T > > *L, vnl_matrix< std::complex< T > > *R)
For a scalar type T, this function uses orthogonal matrices L, R over complex<T> to reduce the (squar...
iterator end()
Iterator pointing to element beyond end of data.
Definition: vnl_matrix.h:622
An ordinary mathematical matrix.
size_t size() const
Return the length, number of elements, dimension of this vector.
Definition: vnl_vector.h:126
iterator begin()
Iterator pointing to start of data.
Definition: vnl_matrix.h:620
iterator end()
Iterator pointing to element beyond end of data.
Definition: vnl_vector.h:246
std::complex< T > vnl_complex_generalized_schur_convert_cast(std::complex< double > a)
iterator begin()
Iterator pointing to start of data.
Definition: vnl_vector.h:243
An ordinary mathematical matrix.
Definition: vnl_adjugate.h:22
Mathematical vector class, templated by type of element.
Definition: vnl_fwd.h:16
unsigned int size() const
Return the total number of elements stored by the matrix.
Definition: vnl_matrix.h:176
unsigned int rows() const
Return the number of rows.
Definition: vnl_matrix.h:179
bool set_size(unsigned r, unsigned c)
Resize to r rows by c columns. Old data lost.
Definition: vnl_matrix.hxx:390