Mercurial > octave
annotate libinterp/corefcn/svd.cc @ 27923:bd51beb6205e
update formatting of copyright notices
* Use <https://octave.org/copyright/> instead of
<https://octave.org/COPYRIGHT.html/>.
* For consistency with other comments in the Octave sources, use
C++-style comments for copyright blocks in C and C++ files.
* Use delimiters above and below copyright blocks that are appropriate
for the language used in the file.
* Eliminate extra spacing inside copyright blocks.
* lex.ll (looks_like_copyright): Also allow newlines and carriage
returns before the word "Copyright".
* scripts/mk-doc.pl (gethelp): Also skip empty comment lines.
* bp-table.cc, type.m: Adjust tests.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 08 Jan 2020 11:59:41 -0500 |
parents | 1891570abac8 |
children | 09c071328135 0a5b15007766 |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 //////////////////////////////////////////////////////////////////////// |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
3 // Copyright (C) 1996-2020 The Octave Project Developers |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
4 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 // See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 // distribution or <https://octave.org/copyright/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
7 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
8 // This file is part of Octave. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
9 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
10 // Octave is free software: you can redistribute it and/or modify it |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
11 // under the terms of the GNU General Public License as published by |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
12 // the Free Software Foundation, either version 3 of the License, or |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
13 // (at your option) any later version. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
14 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
15 // Octave is distributed in the hope that it will be useful, but |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
16 // WITHOUT ANY WARRANTY; without even the implied warranty of |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
18 // GNU General Public License for more details. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
19 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
20 // You should have received a copy of the GNU General Public License |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
21 // along with Octave; see the file COPYING. If not, see |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
22 // <https://www.gnu.org/licenses/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 //////////////////////////////////////////////////////////////////////// |
2928 | 25 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
26 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21273
diff
changeset
|
27 # include "config.h" |
2928 | 28 #endif |
29 | |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
30 #include "svd.h" |
2928 | 31 |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14501
diff
changeset
|
32 #include "defun.h" |
2928 | 33 #include "error.h" |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
34 #include "errwarn.h" |
20940
48b2ad5ee801
maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents:
20939
diff
changeset
|
35 #include "ovl.h" |
2928 | 36 #include "pr-output.h" |
37 #include "utils.h" | |
10638
e1559a8a60b4
general mechanism for string enum variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10601
diff
changeset
|
38 #include "variables.h" |
2928 | 39 |
26630
1212568010a8
Use 'gesvd' as default svd_driver (bug #55564).
Rik <rik@octave.org>
parents:
26614
diff
changeset
|
40 static std::string Vsvd_driver = "gesvd"; |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
41 |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
42 template <typename T> |
22317
6ca3acf5fad8
move some new numeric classes to namespace octave::math
John W. Eaton <jwe@octave.org>
parents:
22204
diff
changeset
|
43 static typename octave::math::svd<T>::Type |
22615
68e9bdb7cde3
Accept second input '0' to svd (bug #49309).
Rik <rik@octave.org>
parents:
22592
diff
changeset
|
44 svd_type (int nargin, int nargout, const octave_value_list & args, const T & A) |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
45 { |
22615
68e9bdb7cde3
Accept second input '0' to svd (bug #49309).
Rik <rik@octave.org>
parents:
22592
diff
changeset
|
46 if (nargout == 0 || nargout == 1) |
68e9bdb7cde3
Accept second input '0' to svd (bug #49309).
Rik <rik@octave.org>
parents:
22592
diff
changeset
|
47 return octave::math::svd<T>::Type::sigma_only; |
68e9bdb7cde3
Accept second input '0' to svd (bug #49309).
Rik <rik@octave.org>
parents:
22592
diff
changeset
|
48 else if (nargin == 1) |
68e9bdb7cde3
Accept second input '0' to svd (bug #49309).
Rik <rik@octave.org>
parents:
22592
diff
changeset
|
49 return octave::math::svd<T>::Type::std; |
25103
078b795c5219
maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
50 else if (! args(1).is_real_scalar ()) |
078b795c5219
maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
51 return octave::math::svd<T>::Type::economy; |
22615
68e9bdb7cde3
Accept second input '0' to svd (bug #49309).
Rik <rik@octave.org>
parents:
22592
diff
changeset
|
52 else |
25103
078b795c5219
maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
53 { |
078b795c5219
maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
54 if (A.rows () > A.columns ()) |
078b795c5219
maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
55 return octave::math::svd<T>::Type::economy; |
078b795c5219
maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
56 else |
078b795c5219
maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
57 return octave::math::svd<T>::Type::std; |
078b795c5219
maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
58 } |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
59 } |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
60 |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
61 template <typename T> |
22317
6ca3acf5fad8
move some new numeric classes to namespace octave::math
John W. Eaton <jwe@octave.org>
parents:
22204
diff
changeset
|
62 static typename octave::math::svd<T>::Driver |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
63 svd_driver (void) |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
64 { |
22317
6ca3acf5fad8
move some new numeric classes to namespace octave::math
John W. Eaton <jwe@octave.org>
parents:
22204
diff
changeset
|
65 return (Vsvd_driver == "gesvd" |
6ca3acf5fad8
move some new numeric classes to namespace octave::math
John W. Eaton <jwe@octave.org>
parents:
22204
diff
changeset
|
66 ? octave::math::svd<T>::Driver::GESVD |
6ca3acf5fad8
move some new numeric classes to namespace octave::math
John W. Eaton <jwe@octave.org>
parents:
22204
diff
changeset
|
67 : octave::math::svd<T>::Driver::GESDD); |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
68 } |
10601 | 69 |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14501
diff
changeset
|
70 DEFUN (svd, args, nargout, |
22893
5ff6716cf157
allow dispatch types to be declared for built-in functions
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
71 classes: double single |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
72 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
73 @deftypefn {} {@var{s} =} svd (@var{A}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
74 @deftypefnx {} {[@var{U}, @var{S}, @var{V}] =} svd (@var{A}) |
22615
68e9bdb7cde3
Accept second input '0' to svd (bug #49309).
Rik <rik@octave.org>
parents:
22592
diff
changeset
|
75 @deftypefnx {} {[@var{U}, @var{S}, @var{V}] =} svd (@var{A}, "econ") |
68e9bdb7cde3
Accept second input '0' to svd (bug #49309).
Rik <rik@octave.org>
parents:
22592
diff
changeset
|
76 @deftypefnx {} {[@var{U}, @var{S}, @var{V}] =} svd (@var{A}, 0) |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
77 @cindex singular value decomposition |
25106
d7ad543255c5
doc: Shorten very long first sentences of docstrings (bug #53388).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
78 Compute the singular value decomposition of @var{A}. |
d7ad543255c5
doc: Shorten very long first sentences of docstrings (bug #53388).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
79 |
d7ad543255c5
doc: Shorten very long first sentences of docstrings (bug #53388).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
80 The singular value decomposition is defined by the relation |
d7ad543255c5
doc: Shorten very long first sentences of docstrings (bug #53388).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
81 |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
82 @tex |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
83 $$ |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
84 A = U S V^{\dagger} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
85 $$ |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
86 @end tex |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
87 @ifnottex |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
88 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
89 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
90 A = U*S*V' |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
91 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
92 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
93 @end ifnottex |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
94 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
95 The function @code{svd} normally returns only the vector of singular values. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
96 When called with three return values, it computes |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
97 @tex |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
98 $U$, $S$, and $V$. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
99 @end tex |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
100 @ifnottex |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
101 @var{U}, @var{S}, and @var{V}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
102 @end ifnottex |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
103 For example, |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
104 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
105 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
106 svd (hilb (3)) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
107 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
108 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
109 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
110 returns |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
111 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
112 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
113 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
114 ans = |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
115 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
116 1.4083189 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
117 0.1223271 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
118 0.0026873 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
119 @end group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
120 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
121 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
122 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
123 and |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
124 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
125 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
126 [u, s, v] = svd (hilb (3)) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
127 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
128 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
129 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
130 returns |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
131 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
132 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
133 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
134 u = |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
135 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
136 -0.82704 0.54745 0.12766 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
137 -0.45986 -0.52829 -0.71375 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
138 -0.32330 -0.64901 0.68867 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
139 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
140 s = |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
141 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
142 1.40832 0.00000 0.00000 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
143 0.00000 0.12233 0.00000 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
144 0.00000 0.00000 0.00269 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
145 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
146 v = |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
147 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
148 -0.82704 0.54745 0.12766 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
149 -0.45986 -0.52829 -0.71375 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
150 -0.32330 -0.64901 0.68867 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
151 @end group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
152 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
153 |
22615
68e9bdb7cde3
Accept second input '0' to svd (bug #49309).
Rik <rik@octave.org>
parents:
22592
diff
changeset
|
154 When given a second argument that is not 0, @code{svd} returns an economy-sized |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
155 decomposition, eliminating the unnecessary rows or columns of @var{U} or |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
156 @var{V}. |
22615
68e9bdb7cde3
Accept second input '0' to svd (bug #49309).
Rik <rik@octave.org>
parents:
22592
diff
changeset
|
157 |
68e9bdb7cde3
Accept second input '0' to svd (bug #49309).
Rik <rik@octave.org>
parents:
22592
diff
changeset
|
158 If the second argument is exactly 0, then the choice of decomposition is based |
68e9bdb7cde3
Accept second input '0' to svd (bug #49309).
Rik <rik@octave.org>
parents:
22592
diff
changeset
|
159 on the matrix @var{A}. If @var{A} has more rows than columns then an |
22709
5c04055aa767
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22615
diff
changeset
|
160 economy-sized decomposition is returned, otherwise a regular decomposition |
22615
68e9bdb7cde3
Accept second input '0' to svd (bug #49309).
Rik <rik@octave.org>
parents:
22592
diff
changeset
|
161 is calculated. |
22977
750c8b4b7164
Switch svd_driver to gesdd for performance (bug #49940).
Rik <rik@octave.org>
parents:
22893
diff
changeset
|
162 |
750c8b4b7164
Switch svd_driver to gesdd for performance (bug #49940).
Rik <rik@octave.org>
parents:
22893
diff
changeset
|
163 Algorithm Notes: When calculating the full decomposition (left and right |
750c8b4b7164
Switch svd_driver to gesdd for performance (bug #49940).
Rik <rik@octave.org>
parents:
22893
diff
changeset
|
164 singular matrices in addition to singular values) there is a choice of two |
26733
da8ebed6d56e
doc: Update docstring for svd to state that gesvd is default driver.
Rik <rik@octave.org>
parents:
26630
diff
changeset
|
165 routines in @sc{lapack}. The default routine used by Octave is @code{gesvd}. |
da8ebed6d56e
doc: Update docstring for svd to state that gesvd is default driver.
Rik <rik@octave.org>
parents:
26630
diff
changeset
|
166 The alternative is @code{gesdd} which is 5X faster, but may use more memory |
da8ebed6d56e
doc: Update docstring for svd to state that gesvd is default driver.
Rik <rik@octave.org>
parents:
26630
diff
changeset
|
167 and may be inaccurate for some input matrices. See the documentation for |
da8ebed6d56e
doc: Update docstring for svd to state that gesvd is default driver.
Rik <rik@octave.org>
parents:
26630
diff
changeset
|
168 @code{svd_driver} for more information on choosing a driver. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
169 @seealso{svd_driver, svds, eig, lu, chol, hess, qr, qz} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
170 @end deftypefn */) |
2928 | 171 { |
172 int nargin = args.length (); | |
173 | |
25699
825e1d0dfa8e
Allow svd to return two output arguments (bug #53356).
Marco Caliari <marco.caliari@univr.it>
parents:
25106
diff
changeset
|
174 if (nargin < 1 || nargin > 2 || nargout > 3) |
20535
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20172
diff
changeset
|
175 print_usage (); |
2928 | 176 |
177 octave_value arg = args(0); | |
178 | |
10185
455759a5fcbe
fix norm and svd on empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10155
diff
changeset
|
179 if (arg.ndims () != 2) |
20535
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20172
diff
changeset
|
180 error ("svd: A must be a 2-D matrix"); |
10185
455759a5fcbe
fix norm and svd on empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10155
diff
changeset
|
181 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20873
diff
changeset
|
182 octave_value_list retval; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20873
diff
changeset
|
183 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
184 bool isfloat = arg.is_single_type (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
185 |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
186 if (isfloat) |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
187 { |
23582
0cc2011d800e
maint: Deprecate is_real_type and replace with isreal.
Rik <rik@octave.org>
parents:
23581
diff
changeset
|
188 if (arg.isreal ()) |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
189 { |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
190 FloatMatrix tmp = arg.float_matrix_value (); |
10638
e1559a8a60b4
general mechanism for string enum variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10601
diff
changeset
|
191 |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
192 if (tmp.any_element_is_inf_or_nan ()) |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
193 error ("svd: cannot take SVD of matrix containing Inf or NaN values"); |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
194 |
22317
6ca3acf5fad8
move some new numeric classes to namespace octave::math
John W. Eaton <jwe@octave.org>
parents:
22204
diff
changeset
|
195 octave::math::svd<FloatMatrix> result |
22615
68e9bdb7cde3
Accept second input '0' to svd (bug #49309).
Rik <rik@octave.org>
parents:
22592
diff
changeset
|
196 (tmp, |
68e9bdb7cde3
Accept second input '0' to svd (bug #49309).
Rik <rik@octave.org>
parents:
22592
diff
changeset
|
197 svd_type<FloatMatrix> (nargin, nargout, args, tmp), |
22317
6ca3acf5fad8
move some new numeric classes to namespace octave::math
John W. Eaton <jwe@octave.org>
parents:
22204
diff
changeset
|
198 svd_driver<FloatMatrix> ()); |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
199 |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
200 FloatDiagMatrix sigma = result.singular_values (); |
20535
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20172
diff
changeset
|
201 |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
202 if (nargout == 0 || nargout == 1) |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
203 retval(0) = sigma.extract_diag (); |
25699
825e1d0dfa8e
Allow svd to return two output arguments (bug #53356).
Marco Caliari <marco.caliari@univr.it>
parents:
25106
diff
changeset
|
204 else if (nargout == 2) |
825e1d0dfa8e
Allow svd to return two output arguments (bug #53356).
Marco Caliari <marco.caliari@univr.it>
parents:
25106
diff
changeset
|
205 retval = ovl (result.left_singular_matrix (), |
825e1d0dfa8e
Allow svd to return two output arguments (bug #53356).
Marco Caliari <marco.caliari@univr.it>
parents:
25106
diff
changeset
|
206 sigma); |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
207 else |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
208 retval = ovl (result.left_singular_matrix (), |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
209 sigma, |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
210 result.right_singular_matrix ()); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
211 } |
23581
c3075ae020e1
maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents:
23573
diff
changeset
|
212 else if (arg.iscomplex ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
213 { |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
214 FloatComplexMatrix ctmp = arg.float_complex_matrix_value (); |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
215 |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
216 if (ctmp.any_element_is_inf_or_nan ()) |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
217 error ("svd: cannot take SVD of matrix containing Inf or NaN values"); |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
218 |
22317
6ca3acf5fad8
move some new numeric classes to namespace octave::math
John W. Eaton <jwe@octave.org>
parents:
22204
diff
changeset
|
219 octave::math::svd<FloatComplexMatrix> result |
22615
68e9bdb7cde3
Accept second input '0' to svd (bug #49309).
Rik <rik@octave.org>
parents:
22592
diff
changeset
|
220 (ctmp, |
68e9bdb7cde3
Accept second input '0' to svd (bug #49309).
Rik <rik@octave.org>
parents:
22592
diff
changeset
|
221 svd_type<FloatComplexMatrix> (nargin, nargout, args, ctmp), |
22317
6ca3acf5fad8
move some new numeric classes to namespace octave::math
John W. Eaton <jwe@octave.org>
parents:
22204
diff
changeset
|
222 svd_driver<FloatComplexMatrix> ()); |
20535
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20172
diff
changeset
|
223 |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
224 FloatDiagMatrix sigma = result.singular_values (); |
20535
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20172
diff
changeset
|
225 |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
226 if (nargout == 0 || nargout == 1) |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
227 retval(0) = sigma.extract_diag (); |
25699
825e1d0dfa8e
Allow svd to return two output arguments (bug #53356).
Marco Caliari <marco.caliari@univr.it>
parents:
25106
diff
changeset
|
228 else if (nargout == 2) |
825e1d0dfa8e
Allow svd to return two output arguments (bug #53356).
Marco Caliari <marco.caliari@univr.it>
parents:
25106
diff
changeset
|
229 retval = ovl (result.left_singular_matrix (), |
825e1d0dfa8e
Allow svd to return two output arguments (bug #53356).
Marco Caliari <marco.caliari@univr.it>
parents:
25106
diff
changeset
|
230 sigma); |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
231 else |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
232 retval = ovl (result.left_singular_matrix (), |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
233 sigma, |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
234 result.right_singular_matrix ()); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
235 } |
2928 | 236 } |
237 else | |
238 { | |
23582
0cc2011d800e
maint: Deprecate is_real_type and replace with isreal.
Rik <rik@octave.org>
parents:
23581
diff
changeset
|
239 if (arg.isreal ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
240 { |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
241 Matrix tmp = arg.matrix_value (); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
242 |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
243 if (tmp.any_element_is_inf_or_nan ()) |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
244 error ("svd: cannot take SVD of matrix containing Inf or NaN values"); |
4478 | 245 |
22317
6ca3acf5fad8
move some new numeric classes to namespace octave::math
John W. Eaton <jwe@octave.org>
parents:
22204
diff
changeset
|
246 octave::math::svd<Matrix> result |
22615
68e9bdb7cde3
Accept second input '0' to svd (bug #49309).
Rik <rik@octave.org>
parents:
22592
diff
changeset
|
247 (tmp, |
68e9bdb7cde3
Accept second input '0' to svd (bug #49309).
Rik <rik@octave.org>
parents:
22592
diff
changeset
|
248 svd_type<Matrix> (nargin, nargout, args, tmp), |
22317
6ca3acf5fad8
move some new numeric classes to namespace octave::math
John W. Eaton <jwe@octave.org>
parents:
22204
diff
changeset
|
249 svd_driver<Matrix> ()); |
20535
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20172
diff
changeset
|
250 |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
251 DiagMatrix sigma = result.singular_values (); |
4478 | 252 |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
253 if (nargout == 0 || nargout == 1) |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
254 retval(0) = sigma.extract_diag (); |
25699
825e1d0dfa8e
Allow svd to return two output arguments (bug #53356).
Marco Caliari <marco.caliari@univr.it>
parents:
25106
diff
changeset
|
255 else if (nargout == 2) |
825e1d0dfa8e
Allow svd to return two output arguments (bug #53356).
Marco Caliari <marco.caliari@univr.it>
parents:
25106
diff
changeset
|
256 retval = ovl (result.left_singular_matrix (), |
825e1d0dfa8e
Allow svd to return two output arguments (bug #53356).
Marco Caliari <marco.caliari@univr.it>
parents:
25106
diff
changeset
|
257 sigma); |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
258 else |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
259 retval = ovl (result.left_singular_matrix (), |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
260 sigma, |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
261 result.right_singular_matrix ()); |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
262 } |
23581
c3075ae020e1
maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents:
23573
diff
changeset
|
263 else if (arg.iscomplex ()) |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
264 { |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
265 ComplexMatrix ctmp = arg.complex_matrix_value (); |
4478 | 266 |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
267 if (ctmp.any_element_is_inf_or_nan ()) |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
268 error ("svd: cannot take SVD of matrix containing Inf or NaN values"); |
4478 | 269 |
22317
6ca3acf5fad8
move some new numeric classes to namespace octave::math
John W. Eaton <jwe@octave.org>
parents:
22204
diff
changeset
|
270 octave::math::svd<ComplexMatrix> result |
22615
68e9bdb7cde3
Accept second input '0' to svd (bug #49309).
Rik <rik@octave.org>
parents:
22592
diff
changeset
|
271 (ctmp, |
68e9bdb7cde3
Accept second input '0' to svd (bug #49309).
Rik <rik@octave.org>
parents:
22592
diff
changeset
|
272 svd_type<ComplexMatrix> (nargin, nargout, args, ctmp), |
22317
6ca3acf5fad8
move some new numeric classes to namespace octave::math
John W. Eaton <jwe@octave.org>
parents:
22204
diff
changeset
|
273 svd_driver<ComplexMatrix> ()); |
4478 | 274 |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
275 DiagMatrix sigma = result.singular_values (); |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
276 |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
277 if (nargout == 0 || nargout == 1) |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
278 retval(0) = sigma.extract_diag (); |
25699
825e1d0dfa8e
Allow svd to return two output arguments (bug #53356).
Marco Caliari <marco.caliari@univr.it>
parents:
25106
diff
changeset
|
279 else if (nargout == 2) |
825e1d0dfa8e
Allow svd to return two output arguments (bug #53356).
Marco Caliari <marco.caliari@univr.it>
parents:
25106
diff
changeset
|
280 retval = ovl (result.left_singular_matrix (), |
825e1d0dfa8e
Allow svd to return two output arguments (bug #53356).
Marco Caliari <marco.caliari@univr.it>
parents:
25106
diff
changeset
|
281 sigma); |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
282 else |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
283 retval = ovl (result.left_singular_matrix (), |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
284 sigma, |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
285 result.right_singular_matrix ()); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
286 } |
4478 | 287 else |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
288 err_wrong_type_arg ("svd", arg); |
2928 | 289 } |
290 | |
291 return retval; | |
292 } | |
293 | |
294 /* | |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
295 %!assert (svd ([1, 2; 2, 1]), [3; 1], sqrt (eps)) |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
296 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
297 %!test |
25699
825e1d0dfa8e
Allow svd to return two output arguments (bug #53356).
Marco Caliari <marco.caliari@univr.it>
parents:
25106
diff
changeset
|
298 %! a = [1, 2; 3, 4] + [5, 6; 7, 8]*i; |
825e1d0dfa8e
Allow svd to return two output arguments (bug #53356).
Marco Caliari <marco.caliari@univr.it>
parents:
25106
diff
changeset
|
299 %! [u,s,v] = svd (a); |
825e1d0dfa8e
Allow svd to return two output arguments (bug #53356).
Marco Caliari <marco.caliari@univr.it>
parents:
25106
diff
changeset
|
300 %! assert (a, u * s * v', 128 * eps); |
22592
ee0df00e12d6
fix complex svd (bug #49232)
John W. Eaton <jwe@octave.org>
parents:
22407
diff
changeset
|
301 |
ee0df00e12d6
fix complex svd (bug #49232)
John W. Eaton <jwe@octave.org>
parents:
22407
diff
changeset
|
302 %!test |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
303 %! [u, s, v] = svd ([1, 2; 2, 1]); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
304 %! x = 1 / sqrt (2); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
305 %! assert (u, [-x, -x; -x, x], sqrt (eps)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
306 %! assert (s, [3, 0; 0, 1], sqrt (eps)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
307 %! assert (v, [-x, x; -x, -x], sqrt (eps)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
308 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
309 %!test |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
310 %! a = [1, 2, 3; 4, 5, 6]; |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
311 %! [u, s, v] = svd (a); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
312 %! assert (u * s * v', a, sqrt (eps)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
313 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
314 %!test |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
315 %! a = [1, 2; 3, 4; 5, 6]; |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
316 %! [u, s, v] = svd (a); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
317 %! assert (u * s * v', a, sqrt (eps)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
318 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
319 %!test |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
320 %! a = [1, 2, 3; 4, 5, 6]; |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
321 %! [u, s, v] = svd (a, 1); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
322 %! assert (u * s * v', a, sqrt (eps)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
323 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
324 %!test |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
325 %! a = [1, 2; 3, 4; 5, 6]; |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
326 %! [u, s, v] = svd (a, 1); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
327 %! assert (u * s * v', a, sqrt (eps)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
328 |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
329 %!assert (svd (single ([1, 2; 2, 1])), single ([3; 1]), sqrt (eps ("single"))) |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
330 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
331 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
332 %! [u, s, v] = svd (single ([1, 2; 2, 1])); |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
333 %! x = single (1 / sqrt (2)); |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
334 %! assert (u, [-x, -x; -x, x], sqrt (eps ("single"))); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
335 %! assert (s, single ([3, 0; 0, 1]), sqrt (eps ("single"))); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
336 %! assert (v, [-x, x; -x, -x], sqrt (eps ("single"))); |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
337 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
338 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
339 %! a = single ([1, 2, 3; 4, 5, 6]); |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
340 %! [u, s, v] = svd (a); |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
341 %! assert (u * s * v', a, sqrt (eps ("single"))); |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
342 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
343 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
344 %! a = single ([1, 2; 3, 4; 5, 6]); |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
345 %! [u, s, v] = svd (a); |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
346 %! assert (u * s * v', a, sqrt (eps ("single"))); |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
347 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
348 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
349 %! a = single ([1, 2, 3; 4, 5, 6]); |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
350 %! [u, s, v] = svd (a, 1); |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
351 %! assert (u * s * v', a, sqrt (eps ("single"))); |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
352 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
353 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
354 %! a = single ([1, 2; 3, 4; 5, 6]); |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
355 %! [u, s, v] = svd (a, 1); |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
356 %! assert (u * s * v', a, sqrt (eps ("single"))); |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
357 |
10185
455759a5fcbe
fix norm and svd on empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10155
diff
changeset
|
358 %!test |
455759a5fcbe
fix norm and svd on empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10155
diff
changeset
|
359 %! a = zeros (0, 5); |
455759a5fcbe
fix norm and svd on empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10155
diff
changeset
|
360 %! [u, s, v] = svd (a); |
455759a5fcbe
fix norm and svd on empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10155
diff
changeset
|
361 %! assert (size (u), [0, 0]); |
455759a5fcbe
fix norm and svd on empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10155
diff
changeset
|
362 %! assert (size (s), [0, 5]); |
455759a5fcbe
fix norm and svd on empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10155
diff
changeset
|
363 %! assert (size (v), [5, 5]); |
455759a5fcbe
fix norm and svd on empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10155
diff
changeset
|
364 |
455759a5fcbe
fix norm and svd on empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10155
diff
changeset
|
365 %!test |
455759a5fcbe
fix norm and svd on empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10155
diff
changeset
|
366 %! a = zeros (5, 0); |
455759a5fcbe
fix norm and svd on empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10155
diff
changeset
|
367 %! [u, s, v] = svd (a, 1); |
455759a5fcbe
fix norm and svd on empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10155
diff
changeset
|
368 %! assert (size (u), [5, 0]); |
455759a5fcbe
fix norm and svd on empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10155
diff
changeset
|
369 %! assert (size (s), [0, 0]); |
455759a5fcbe
fix norm and svd on empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10155
diff
changeset
|
370 %! assert (size (v), [0, 0]); |
455759a5fcbe
fix norm and svd on empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10155
diff
changeset
|
371 |
23573
1b4f4ec53b4a
use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents:
23572
diff
changeset
|
372 %!test <*49309> |
22615
68e9bdb7cde3
Accept second input '0' to svd (bug #49309).
Rik <rik@octave.org>
parents:
22592
diff
changeset
|
373 %! [~,~,v] = svd ([1, 1, 1], 0); |
68e9bdb7cde3
Accept second input '0' to svd (bug #49309).
Rik <rik@octave.org>
parents:
22592
diff
changeset
|
374 %! assert (size (v), [3 3]); |
68e9bdb7cde3
Accept second input '0' to svd (bug #49309).
Rik <rik@octave.org>
parents:
22592
diff
changeset
|
375 %! [~,~,v] = svd ([1, 1, 1], "econ"); |
68e9bdb7cde3
Accept second input '0' to svd (bug #49309).
Rik <rik@octave.org>
parents:
22592
diff
changeset
|
376 %! assert (size (v), [3 1]); |
68e9bdb7cde3
Accept second input '0' to svd (bug #49309).
Rik <rik@octave.org>
parents:
22592
diff
changeset
|
377 |
26731
75d79c39ac92
Replace '-0' in sigma matrix from svd() with '+0' (bug #55710).
Rik <rik@octave.org>
parents:
26630
diff
changeset
|
378 %!assert <*55710> (1 / svd (-0), Inf) |
75d79c39ac92
Replace '-0' in sigma matrix from svd() with '+0' (bug #55710).
Rik <rik@octave.org>
parents:
26630
diff
changeset
|
379 |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
380 %!error svd () |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
381 %!error svd ([1, 2; 4, 5], 2, 3) |
2928 | 382 */ |
10601 | 383 |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14501
diff
changeset
|
384 DEFUN (svd_driver, args, nargout, |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
385 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
386 @deftypefn {} {@var{val} =} svd_driver () |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
387 @deftypefnx {} {@var{old_val} =} svd_driver (@var{new_val}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
388 @deftypefnx {} {} svd_driver (@var{new_val}, "local") |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
389 Query or set the underlying @sc{lapack} driver used by @code{svd}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
390 |
22977
750c8b4b7164
Switch svd_driver to gesdd for performance (bug #49940).
Rik <rik@octave.org>
parents:
22893
diff
changeset
|
391 Currently recognized values are @qcode{"gesdd"} and @qcode{"gesvd"}. |
26630
1212568010a8
Use 'gesvd' as default svd_driver (bug #55564).
Rik <rik@octave.org>
parents:
26614
diff
changeset
|
392 The default is @qcode{"gesvd"}. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
393 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
394 When called from inside a function with the @qcode{"local"} option, the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
395 variable is changed locally for the function and any subroutines it calls. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
396 The original variable value is restored when exiting the function. |
22977
750c8b4b7164
Switch svd_driver to gesdd for performance (bug #49940).
Rik <rik@octave.org>
parents:
22893
diff
changeset
|
397 |
750c8b4b7164
Switch svd_driver to gesdd for performance (bug #49940).
Rik <rik@octave.org>
parents:
22893
diff
changeset
|
398 Algorithm Notes: The @sc{lapack} library provides two routines for calculating |
750c8b4b7164
Switch svd_driver to gesdd for performance (bug #49940).
Rik <rik@octave.org>
parents:
22893
diff
changeset
|
399 the full singular value decomposition (left and right singular matrices as |
750c8b4b7164
Switch svd_driver to gesdd for performance (bug #49940).
Rik <rik@octave.org>
parents:
22893
diff
changeset
|
400 well as singular values). When calculating just the singular values the |
750c8b4b7164
Switch svd_driver to gesdd for performance (bug #49940).
Rik <rik@octave.org>
parents:
22893
diff
changeset
|
401 following discussion is not relevant. |
750c8b4b7164
Switch svd_driver to gesdd for performance (bug #49940).
Rik <rik@octave.org>
parents:
22893
diff
changeset
|
402 |
26630
1212568010a8
Use 'gesvd' as default svd_driver (bug #55564).
Rik <rik@octave.org>
parents:
26614
diff
changeset
|
403 The newer @code{gesdd} routine is based on a Divide-and-Conquer algorithm that |
1212568010a8
Use 'gesvd' as default svd_driver (bug #55564).
Rik <rik@octave.org>
parents:
26614
diff
changeset
|
404 is 5X faster than the alternative @code{gesvd}, which is based on QR |
1212568010a8
Use 'gesvd' as default svd_driver (bug #55564).
Rik <rik@octave.org>
parents:
26614
diff
changeset
|
405 factorization. However, the new algorithm can use significantly more memory. |
1212568010a8
Use 'gesvd' as default svd_driver (bug #55564).
Rik <rik@octave.org>
parents:
26614
diff
changeset
|
406 For an @nospell{MxN} input matrix the memory usage is of order O(min(M,N) ^ 2), |
1212568010a8
Use 'gesvd' as default svd_driver (bug #55564).
Rik <rik@octave.org>
parents:
26614
diff
changeset
|
407 whereas the alternative is of order O(max(M,N)). |
22977
750c8b4b7164
Switch svd_driver to gesdd for performance (bug #49940).
Rik <rik@octave.org>
parents:
22893
diff
changeset
|
408 |
26630
1212568010a8
Use 'gesvd' as default svd_driver (bug #55564).
Rik <rik@octave.org>
parents:
26614
diff
changeset
|
409 Beyond speed and memory issues, there have been instances where some input |
1212568010a8
Use 'gesvd' as default svd_driver (bug #55564).
Rik <rik@octave.org>
parents:
26614
diff
changeset
|
410 matrices were not accurately decomposed by @code{gesdd}. See currently active |
1212568010a8
Use 'gesvd' as default svd_driver (bug #55564).
Rik <rik@octave.org>
parents:
26614
diff
changeset
|
411 bug @url{https://savannah.gnu.org/bugs/?55564}. Until these accuracy issues |
1212568010a8
Use 'gesvd' as default svd_driver (bug #55564).
Rik <rik@octave.org>
parents:
26614
diff
changeset
|
412 are resolved in a new version of the @sc{lapack} library, the default driver |
1212568010a8
Use 'gesvd' as default svd_driver (bug #55564).
Rik <rik@octave.org>
parents:
26614
diff
changeset
|
413 in Octave has been set to @qcode{"gesvd"}. |
22977
750c8b4b7164
Switch svd_driver to gesdd for performance (bug #49940).
Rik <rik@octave.org>
parents:
22893
diff
changeset
|
414 |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
415 @seealso{svd} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
416 @end deftypefn */) |
10601 | 417 { |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23582
diff
changeset
|
418 static const char *driver_names[] = { "gesvd", "gesdd", nullptr }; |
10601 | 419 |
10638
e1559a8a60b4
general mechanism for string enum variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10601
diff
changeset
|
420 return SET_INTERNAL_VARIABLE_CHOICES (svd_driver, driver_names); |
10601 | 421 } |
15887
8ced82e96b48
Fix segfaults with gesdd driver for svd (bug #37998).
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
422 |
8ced82e96b48
Fix segfaults with gesdd driver for svd (bug #37998).
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
423 /* |
8ced82e96b48
Fix segfaults with gesdd driver for svd (bug #37998).
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
424 %!test |
8ced82e96b48
Fix segfaults with gesdd driver for svd (bug #37998).
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
425 %! A = [1+1i, 1-1i, 0; 0, 2, 0; 1i, 1i, 1+2i]; |
8ced82e96b48
Fix segfaults with gesdd driver for svd (bug #37998).
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
426 %! old_driver = svd_driver ("gesvd"); |
8ced82e96b48
Fix segfaults with gesdd driver for svd (bug #37998).
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
427 %! [U1, S1, V1] = svd (A); |
8ced82e96b48
Fix segfaults with gesdd driver for svd (bug #37998).
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
428 %! svd_driver ("gesdd"); |
8ced82e96b48
Fix segfaults with gesdd driver for svd (bug #37998).
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
429 %! [U2, S2, V2] = svd (A); |
22977
750c8b4b7164
Switch svd_driver to gesdd for performance (bug #49940).
Rik <rik@octave.org>
parents:
22893
diff
changeset
|
430 %! svd_driver (old_driver); |
15887
8ced82e96b48
Fix segfaults with gesdd driver for svd (bug #37998).
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
431 %! assert (U1, U2, 5*eps); |
8ced82e96b48
Fix segfaults with gesdd driver for svd (bug #37998).
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
432 %! assert (S1, S2, 5*eps); |
8ced82e96b48
Fix segfaults with gesdd driver for svd (bug #37998).
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
433 %! assert (V1, V2, 5*eps); |
8ced82e96b48
Fix segfaults with gesdd driver for svd (bug #37998).
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
434 */ |