source: trunk/yat/utility/SVD.cc @ 703

Last change on this file since 703 was 703, checked in by Jari Häkkinen, 16 years ago

Addresses #65 and #170.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 1.9 KB
Line 
1// $Id: SVD.cc 703 2006-12-18 00:47:44Z jari $
2
3/*
4  Copyright (C) The authors contributing to this file.
5
6  This file is part of the yat library, http://lev.thep.lu.se/trac/yat
7
8  The yat library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License as
10  published by the Free Software Foundation; either version 2 of the
11  License, or (at your option) any later version.
12
13  The yat library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21  02111-1307, USA.
22*/
23
24#include "SVD.h"
25
26namespace theplu {
27namespace yat {
28namespace utility {
29
30
31  SVD::SVD(const utility::matrix& Ain)
32    : U_(Ain), V_(Ain.columns(),Ain.columns()), s_(Ain.columns())
33  {
34  }
35
36
37  SVD::~SVD(void)
38  {
39  }
40
41
42  int SVD::decompose(SVDalgorithm algo)
43  {
44    switch (algo) {
45        case GolubReinsch:
46          return golub_reinsch();
47        case ModifiedGolubReinsch:
48          return modified_golub_reinsch();
49        case Jacobi:
50          return jacobi();
51    }
52    // the program should never end up here, return values should be
53    // something different from normal GSL return values, or maybe
54    // throw an exception.
55    return 0;
56  }
57
58
59
60  int SVD::golub_reinsch(void)
61  {
62    utility::vector w(U_.columns());
63    return gsl_linalg_SV_decomp(U_.gsl_matrix_p(), V_.gsl_matrix_p(),
64                                s_.gsl_vector_p(), w.gsl_vector_p());
65  }
66
67
68
69  int SVD::modified_golub_reinsch(void)
70  {
71    utility::vector w(U_.columns());
72    utility::matrix X(U_.columns(),U_.columns());
73    return gsl_linalg_SV_decomp_mod(U_.gsl_matrix_p(), X.gsl_matrix_p(), 
74                                    V_.gsl_matrix_p(), s_.gsl_vector_p(),
75                                    w.gsl_vector_p());
76  }
77
78
79}}} // of namespace utility, yat, and theplu
Note: See TracBrowser for help on using the repository browser.