GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
svd.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2016-2018 CarnĂ« Draug
4 Copyright (C) 1994-2018 John W. Eaton
5 
6 This file is part of Octave.
7 
8 Octave is free software: you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12 
13 Octave is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with Octave; see the file COPYING. If not, see
20 <https://www.gnu.org/licenses/>.
21 
22 */
23 
24 #if ! defined (octave_svd_h)
25 #define octave_svd_h 1
26 
27 #include "octave-config.h"
28 
29 #include <vector>
30 
31 namespace octave
32 {
33  namespace math
34  {
35  template <typename T>
36  class
37  svd
38  {
39  public:
40 
41  typedef typename T::real_diag_matrix_type DM_T;
42 
43  enum class Type
44  {
45  std,
46  economy,
47  sigma_only
48  };
49 
50  enum class Driver
51  {
52  GESVD,
53  GESDD
54  };
55 
56  svd (void)
57  : m_type (), m_driver (), left_sm (), sigma (), right_sm ()
58  { }
59 
60  svd (const T& a, svd::Type type = svd::Type::std,
62 
63  svd (const svd& a)
64  : m_type (a.m_type), m_driver (a.m_driver), left_sm (a.left_sm),
65  sigma (a.sigma), right_sm (a.right_sm)
66  { }
67 
68  svd& operator = (const svd& a)
69  {
70  if (this != &a)
71  {
72  m_type = a.m_type;
73  left_sm = a.left_sm;
74  sigma = a.sigma;
75  right_sm = a.right_sm;
76  m_driver = a.m_driver;
77  }
78 
79  return *this;
80  }
81 
82  ~svd (void) = default;
83 
84  T left_singular_matrix (void) const;
85 
86  DM_T singular_values (void) const { return sigma; }
87 
88  T right_singular_matrix (void) const;
89 
90  private:
91 
92  typedef typename T::element_type P;
93  typedef typename DM_T::element_type DM_P;
94 
97 
101 
102  void gesvd (char& jobu, char& jobv, octave_f77_int_type m,
103  octave_f77_int_type n, P *tmp_data, octave_f77_int_type m1,
104  DM_P *s_vec, P *u, P *vt, octave_f77_int_type nrow_vt1,
105  std::vector<P>& work, octave_f77_int_type& lwork,
106  octave_f77_int_type& info);
107 
108  void gesdd (char& jobz, octave_f77_int_type m, octave_f77_int_type n,
109  P *tmp_data, octave_f77_int_type m1, DM_P *s_vec, P *u,
110  P *vt, octave_f77_int_type nrow_vt1, std::vector<P>& work,
111  octave_f77_int_type& lwork, octave_f77_int_type *iwork,
112  octave_f77_int_type& info);
113  };
114  }
115 }
116 
117 #endif
svd(const svd &a)
Definition: svd.h:63
DM_T singular_values(void) const
Definition: svd.h:86
DM_T sigma
Definition: svd.h:99
STL namespace.
svd::Type m_type
Definition: svd.h:95
T::element_type P
Definition: svd.h:92
u
Definition: lu.cc:138
svd(void)
Definition: svd.h:56
DM_T::element_type DM_P
Definition: svd.h:93
calling an anonymous function involves an overhead quite comparable to the overhead of an m file function Passing a handle to a built in function is because the interpreter is not involved in the internal loop For a
Definition: cellfun.cc:400
T::real_diag_matrix_type DM_T
Definition: svd.h:41
idx type
Definition: ov.cc:3114
svd::Driver m_driver
Definition: svd.h:96