schur.cpp
Go to the documentation of this file.
#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
it_error
#define it_error(s)
Abort unconditionally.
Definition itassert.h:126
it_assert_debug
#define it_assert_debug(t, s)
Abort if t is not true and NDEBUG is not defined.
Definition itassert.h:107
itpp::schur
bool schur(const mat &A, mat &U, mat &T)
Schur decomposition of a real matrix.
Definition schur.cpp:104
itpp
itpp namespace
Definition itmex.h:37
schur.h
Definitions of Schur decomposition functions.

Generated on Mon Jun 10 2024 11:49:16 for IT++ by Doxygen 1.9.8