VDVEigDecomposition.cc 1.63 KB
Newer Older
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
/*
 * Copyright (C) 2010 Dynare Team
 *
 * This file is part of Dynare.
 *
 * Dynare 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.
 *
 * Dynare 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 Dynare.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "VDVEigDecomposition.hh"

VDVEigDecomposition::VDVEigDecomposition(const Matrix &m) throw(VDVEigException) :
  lda(m.getLd()), n(m.getCols()), lwork(-1),
  info(0),   converged(false), V(m), D(n)
{
  if (m.getRows() != m.getCols())
    throw(VDVEigException(info, "Matrix is not square in VDVEigDecomposition constructor"));

29
  double tmpwork;
30
  dsyev("V", "U", &n, V.getData(), &lda, D.getData(), &tmpwork, &lwork, &info);
31
  lwork = (lapack_int) tmpwork;
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
  work = new double[lwork];
  if (info < 0)
    throw(VDVEigException(info, "Internal error in VDVEigDecomposition constructor"));
}

VDVEigDecomposition::VDVEigDecomposition(size_t inn) throw(VDVEigException) :
  lda(inn), n(inn), lwork(3*inn-1),
  info(0),   converged(false), V(inn), D(inn)
{
  work = new double[lwork];
};

std::ostream &
operator<<(std::ostream &out, const VDVEigDecomposition::VDVEigException &e)
{
  out << " info " << e.info << ": " << e.message  << "\n";
  return out;
}