Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

[5cfaaf]: itpp / base / algebra / schur.cpp Maximize Restore History

Download this file

schur.cpp    128 lines (99 with data), 3.2 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*!
* \file
* \brief Schur decomposition functions
* \author Adam Piatyszek
*
* -------------------------------------------------------------------------
*
* Copyright (C) 1995-2008 (see AUTHORS file for a list of contributors)
*
* This file is part of IT++ - a C++ library of mathematical, signal
* processing, speech processing, and communications classes and functions.
*
* IT++ is free software: you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* IT++ is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along
* with IT++. If not, see <http://www.gnu.org/licenses/>.
*
* -------------------------------------------------------------------------
*/
#ifndef _MSC_VER
# include <itpp/config.h>
#else
# include <itpp/config_msvc.h>
#endif
#if defined(HAVE_LAPACK)
# include <itpp/base/algebra/lapack.h>
#endif
#include <itpp/base/algebra/schur.h>
namespace itpp {
#if defined(HAVE_LAPACK)
bool schur(const mat &A, mat &U, mat &T) {
it_assert_debug(A.rows() == A.cols(), "schur(): Matrix is not square");
char jobvs = 'V';
char sort = 'N';
int info;
int n = A.rows();
int lda = n;
int ldvs = n;
int lwork = 3 * n; // This may be choosen better!
int sdim = 0;
vec wr(n);
vec wi(n);
vec work(lwork);
T.set_size(lda, n, false);
U.set_size(ldvs, n, false);
T = A; // The routine overwrites input matrix with eigenvectors
dgees_(&jobvs, &sort, 0, &n, T._data(), &lda, &sdim, wr._data(), wi._data(),
U._data(), &ldvs, work._data(), &lwork, 0, &info);
return (info == 0);
}
bool schur(const cmat &A, cmat &U, cmat &T) {
it_assert_debug(A.rows() == A.cols(), "schur(): Matrix is not square");
char jobvs = 'V';
char sort = 'N';
int info;
int n = A.rows();
int lda = n;
int ldvs = n;
int lwork = 2 * n; // This may be choosen better!
int sdim = 0;
vec rwork(n);
cvec w(n);
cvec work(lwork);
T.set_size(lda, n, false);
U.set_size(ldvs, n, false);
T = A; // The routine overwrites input matrix with eigenvectors
zgees_(&jobvs, &sort, 0, &n, T._data(), &lda, &sdim, w._data(), U._data(),
&ldvs, work._data(), &lwork, rwork._data(), 0, &info);
return (info == 0);
}
#else
bool schur(const mat &A, mat &U, mat &T) {
it_error("LAPACK library is needed to use schur() function");
return false;
}
bool schur(const cmat &A, cmat &U, cmat &T) {
it_error("LAPACK library is needed to use schur() function");
return false;
}
#endif // HAVE_LAPACK
mat schur(const mat &A) {
mat U, T;
schur(A, U, T);
return T;
}
cmat schur(const cmat &A) {
cmat U, T;
schur(A, U, T);
return T;
}
} // namespace itpp