comparison liboctave/numeric/gsvd.h @ 22236:065a44375723

gsvd: reduce code duplication with templates. * CmplxGSVD.cc, CmplxGSVD.h, dbleGSVD.cc, dbleGSVD.h: Remove files for no longer existing classes. Replaced by gsvd template class. This classes never existed in an Octave release, this was freshly imported from Octave Forge so backwards compatibility is not an issue. * liboctave/numeric/gsvd.h, liboctave/numeric/gsvd.cc: New files for gsvd class template generated from CmplxGSVD.cc, CmplxGSVD.h, dbleGSVD.cc, and dbleGSVD.h and converted to template. Removed unused << operator, unused constructor with &info, and commented code. Only instantiated for Matrix and ComplexMatrix, providing interface to DGGSVD and ZGGSVD. * liboctave/numeric/module.mk: Update. * mx-defs.h, mx-ext.h: Use new classes.
author Barbara Locsi <locsi.barbara@gmail.com>
date Tue, 09 Aug 2016 18:02:11 +0200
parents
children bac0d6f07a3e
comparison
equal deleted inserted replaced
22235:63b41167ef1e 22236:065a44375723
1 // Copyright (C) 1996, 1997 John W. Eaton
2 // Copyright (C) 2006 Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
3 // Copyright (C) 2016 Barbara Lócsi
4 //
5 // This program is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free Software
7 // Foundation; either version 3 of the License, or (at your option) any later
8 // version.
9 //
10 // This program is distributed in the hope that it will be useful, but WITHOUT
11 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 // details.
14 //
15 // You should have received a copy of the GNU General Public License along with
16 // this program; if not, see <http://www.gnu.org/licenses/>.
17
18 #if !defined (octave_gsvd_h)
19 #define octave_gsvd_h 1
20
21 #include "octave-config.h"
22
23 #include "dDiagMatrix.h"
24 #include "dMatrix.h"
25
26 template <typename T>
27 class
28 gsvd
29 {
30 public:
31
32 enum class Type
33 {
34 std,
35 economy,
36 sigma_only
37 };
38
39 gsvd (void) : sigmaA (), sigmaB (), left_smA (), left_smB (), right_sm () { }
40
41 gsvd (const T& a, const T& b, gsvd::Type gsvd_type = gsvd<T>::Type::economy);
42
43 gsvd (const gsvd& a)
44 : type (a.type),
45 sigmaA (a.sigmaA), sigmaB (a.sigmaB),
46 left_smA (a.left_smA), left_smB (a.left_smB), right_sm (a.right_sm),
47 R(a.R) { }
48
49 gsvd& operator = (const gsvd& a)
50 {
51 if (this != &a)
52 {
53 type = a.type;
54 sigmaA = a.sigmaA;
55 sigmaB = a.sigmaB;
56 left_smA = a.left_smA;
57 left_smB = a.left_smB;
58 right_sm = a.right_sm;
59 R = a.R;
60 }
61
62 return *this;
63 }
64
65 ~gsvd (void) { }
66
67 DiagMatrix singular_values_A (void) const { return sigmaA; }
68 DiagMatrix singular_values_B (void) const { return sigmaB; }
69
70 T left_singular_matrix_A (void) const;
71 T left_singular_matrix_B (void) const;
72
73 T right_singular_matrix (void) const;
74 T R_matrix (void) const;
75
76 private:
77
78 gsvd::Type type;
79
80 typedef typename T::element_type P;
81
82 DiagMatrix sigmaA, sigmaB;
83 T left_smA, left_smB;
84 T right_sm, R;
85
86 void ggsvd (char& jobu, char& jobv, char& jobq, octave_idx_type m,
87 octave_idx_type n, octave_idx_type p, octave_idx_type& k,
88 octave_idx_type& l, P *tmp_dataA, octave_idx_type m1,
89 P *tmp_dataB, octave_idx_type p1, Matrix& alpha, Matrix& beta,
90 P *u, octave_idx_type nrow_u, P *v, octave_idx_type nrow_v, P *q,
91 octave_idx_type nrow_q, T& work, octave_idx_type* iwork,
92 octave_idx_type& info);
93 };
94
95 #endif