GNU Octave  9.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
svd.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 1994-2024 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING. If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 #if ! defined (octave_svd_h)
27 #define octave_svd_h 1
28 
29 #include "octave-config.h"
30 
31 #include <vector>
32 
34 
36 
37 template <typename T>
38 class
40 svd
41 {
42 public:
43 
44  typedef typename T::real_diag_matrix_type DM_T;
45 
46  enum class Type
47  {
48  std,
49  economy,
50  sigma_only
51  };
52 
53  enum class Driver
54  {
55  GESVD,
56  GESDD,
57  GEJSV
58  };
59 
60  svd ()
61  : m_type (), m_driver (), m_left_sm (), m_sigma (), m_right_sm ()
62  { }
63 
64  svd (const T& a, svd::Type type = svd::Type::std,
66 
67  svd (const svd& a)
68  : m_type (a.m_type), m_driver (a.m_driver), m_left_sm (a.m_left_sm),
69  m_sigma (a.m_sigma), m_right_sm (a.m_right_sm)
70  { }
71 
72  svd& operator = (const svd& a)
73  {
74  if (this != &a)
75  {
76  m_type = a.m_type;
77  m_left_sm = a.m_left_sm;
78  m_sigma = a.m_sigma;
79  m_right_sm = a.m_right_sm;
80  m_driver = a.m_driver;
81  }
82 
83  return *this;
84  }
85 
86  ~svd () = default;
87 
88  T left_singular_matrix () const;
89 
90  DM_T singular_values () const { return m_sigma; }
91 
92  T right_singular_matrix () const;
93 
94 private:
95 
96  typedef typename T::element_type P;
97  typedef typename DM_T::element_type DM_P;
98 
99  svd::Type m_type;
100  svd::Driver m_driver;
101 
102  T m_left_sm;
103  DM_T m_sigma;
104  T m_right_sm;
105 
106  void gesvd (char& jobu, char& jobv, octave_f77_int_type m,
107  octave_f77_int_type n, P *tmp_data, octave_f77_int_type m1,
108  DM_P *s_vec, P *u, P *vt, octave_f77_int_type nrow_vt1,
109  std::vector<P>& work, octave_f77_int_type& lwork,
110  octave_f77_int_type& info);
111 
112  void gesdd (char& jobz, octave_f77_int_type m, octave_f77_int_type n,
113  P *tmp_data, octave_f77_int_type m1, DM_P *s_vec, P *u,
114  P *vt, octave_f77_int_type nrow_vt1, std::vector<P>& work,
115  octave_f77_int_type& lwork, octave_f77_int_type *iwork,
116  octave_f77_int_type& info);
117 
118  void gejsv (char& joba, char& jobu, char& jobv, char& jobr, char& jobt,
119  char& jobp, octave_f77_int_type m, octave_f77_int_type n,
120  P *tmp_data, octave_f77_int_type m1, DM_P *s_vec, P *u,
121  P *v, octave_f77_int_type nrow_v1, std::vector<P>& work,
122  octave_f77_int_type& lwork,
123  std::vector<octave_f77_int_type>& iwork,
124  octave_f77_int_type& info);
125 };
126 
127 OCTAVE_END_NAMESPACE(math)
128 OCTAVE_END_NAMESPACE(octave)
129 
130 #endif
Definition: svd.h:41
~svd()=default
T::real_diag_matrix_type DM_T
Definition: svd.h:44
svd(const svd &a)
Definition: svd.h:67
Type
Definition: svd.h:47
DM_T singular_values() const
Definition: svd.h:90
Driver
Definition: svd.h:54
svd()
Definition: svd.h:60
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
#define OCTAVE_API
Definition: main.cc:55
T octave_idx_type m
Definition: mx-inlines.cc:781
octave_idx_type n
Definition: mx-inlines.cc:761