annotate libinterp/corefcn/svd.cc @ 18840:4a4edf0f2077 nkf-ready

fix LLVM 3.4 build (bug #41061) * configure.ac: Call new functions OCTAVE_LLVM_RAW_FD_OSTREAM_API and OCTAVE_LLVM_LEGACY_PASSMANAGER_API, check for Verifier.h header file * m4/acinclude.m4 (OCTAVE_LLVM_RAW_FD_OSTREAM_API): New function to detect correct raw_fd_ostream API * m4/acinclude.m4 (OCTAVE_LLVM_LEGACY_PASSMANAGER_API): New function to detect legacy passmanager API * libinterp/corefcn/jit-util.h: Use legacy passmanager namespace if necessary * libinterp/corefcn/pt-jit.h (class tree_jit): Use legacy passmanager class if necessary * libinterp/corefcn/pt-jit.cc: Include appropriate header files * libinterp/corefcn/pt-jit.cc (tree_jit::initialize): Use legacy passmanager if necessary * libinterp/corefcn/pt-jit.cc (tree_jit::optimize): Use correct API * libinterp/corefcn/jit-typeinfo.cc: Include appropriate header file
author Stefan Mahr <dac922@gmx.de>
date Sun, 11 May 2014 02:28:33 +0200
parents 175b392e91fe
children 4197fc428c7d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
1 /*
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
2
17744
d63878346099 maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents: 17281
diff changeset
3 Copyright (C) 1996-2013 John W. Eaton
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
4
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
5 This file is part of Octave.
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
6
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6620
diff changeset
9 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6620
diff changeset
10 option) any later version.
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
11
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
15 for more details.
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
16
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6620
diff changeset
18 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6620
diff changeset
19 <http://www.gnu.org/licenses/>.
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
20
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
21 */
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
22
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
23 #ifdef HAVE_CONFIG_H
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
24 #include <config.h>
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
25 #endif
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
26
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
27 #include "CmplxSVD.h"
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
28 #include "dbleSVD.h"
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
29 #include "fCmplxSVD.h"
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
30 #include "floatSVD.h"
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
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
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
33 #include "error.h"
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
34 #include "gripes.h"
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
35 #include "oct-obj.h"
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
36 #include "pr-output.h"
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
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
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
39
10638
e1559a8a60b4 general mechanism for string enum variables
Jaroslav Hajek <highegg@gmail.com>
parents: 10601
diff changeset
40 static int Vsvd_driver = SVD::GESVD;
10601
3ce0c530a9c9 implement svd_driver
Jaroslav Hajek <highegg@gmail.com>
parents: 10185
diff changeset
41
15039
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14501
diff changeset
42 DEFUN (svd, args, nargout,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
43 "-*- texinfo -*-\n\
15039
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14501
diff changeset
44 @deftypefn {Built-in Function} {@var{s} =} svd (@var{A})\n\
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14501
diff changeset
45 @deftypefnx {Built-in Function} {[@var{U}, @var{S}, @var{V}] =} svd (@var{A})\n\
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14501
diff changeset
46 @deftypefnx {Built-in Function} {[@var{U}, @var{S}, @var{V}] =} svd (@var{A}, @var{econ})\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3014
diff changeset
47 @cindex singular value decomposition\n\
11553
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11533
diff changeset
48 Compute the singular value decomposition of @var{A}\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3014
diff changeset
49 @tex\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3014
diff changeset
50 $$\n\
12584
7ef7e20057fa Improve documentation strings in Linear Algebra chapter.
Rik <octave@nomad.inbox5.com>
parents: 11586
diff changeset
51 A = U S V^{\\dagger}\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3014
diff changeset
52 $$\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3014
diff changeset
53 @end tex\n\
8517
81d6ab3ac93c Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents: 7814
diff changeset
54 @ifnottex\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3014
diff changeset
55 \n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3014
diff changeset
56 @example\n\
6620
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 5823
diff changeset
57 A = U*S*V'\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3014
diff changeset
58 @end example\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10711
diff changeset
59 \n\
8517
81d6ab3ac93c Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents: 7814
diff changeset
60 @end ifnottex\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3014
diff changeset
61 \n\
10687
a8ce6bdecce5 Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents: 10640
diff changeset
62 The function @code{svd} normally returns only the vector of singular values.\n\
a8ce6bdecce5 Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents: 10640
diff changeset
63 When called with three return values, it computes\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3014
diff changeset
64 @tex\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3014
diff changeset
65 $U$, $S$, and $V$.\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3014
diff changeset
66 @end tex\n\
8517
81d6ab3ac93c Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents: 7814
diff changeset
67 @ifnottex\n\
11553
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11533
diff changeset
68 @var{U}, @var{S}, and @var{V}.\n\
8517
81d6ab3ac93c Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents: 7814
diff changeset
69 @end ifnottex\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3014
diff changeset
70 For example,\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3014
diff changeset
71 \n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3014
diff changeset
72 @example\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3014
diff changeset
73 svd (hilb (3))\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3014
diff changeset
74 @end example\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3014
diff changeset
75 \n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3014
diff changeset
76 @noindent\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3014
diff changeset
77 returns\n\
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
78 \n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3014
diff changeset
79 @example\n\
9064
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
80 @group\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3014
diff changeset
81 ans =\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3014
diff changeset
82 \n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3014
diff changeset
83 1.4083189\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3014
diff changeset
84 0.1223271\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3014
diff changeset
85 0.0026873\n\
9064
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
86 @end group\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3014
diff changeset
87 @end example\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3014
diff changeset
88 \n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3014
diff changeset
89 @noindent\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3014
diff changeset
90 and\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3014
diff changeset
91 \n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3014
diff changeset
92 @example\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3014
diff changeset
93 [u, s, v] = svd (hilb (3))\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3014
diff changeset
94 @end example\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3014
diff changeset
95 \n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3014
diff changeset
96 @noindent\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3014
diff changeset
97 returns\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3014
diff changeset
98 \n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3014
diff changeset
99 @example\n\
9064
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
100 @group\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3014
diff changeset
101 u =\n\
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
102 \n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3014
diff changeset
103 -0.82704 0.54745 0.12766\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3014
diff changeset
104 -0.45986 -0.52829 -0.71375\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3014
diff changeset
105 -0.32330 -0.64901 0.68867\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3014
diff changeset
106 \n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3014
diff changeset
107 s =\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3014
diff changeset
108 \n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3014
diff changeset
109 1.40832 0.00000 0.00000\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3014
diff changeset
110 0.00000 0.12233 0.00000\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3014
diff changeset
111 0.00000 0.00000 0.00269\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3014
diff changeset
112 \n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3014
diff changeset
113 v =\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3014
diff changeset
114 \n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3014
diff changeset
115 -0.82704 0.54745 0.12766\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3014
diff changeset
116 -0.45986 -0.52829 -0.71375\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3014
diff changeset
117 -0.32330 -0.64901 0.68867\n\
9064
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
118 @end group\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3014
diff changeset
119 @end example\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3014
diff changeset
120 \n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3014
diff changeset
121 If given a second argument, @code{svd} returns an economy-sized\n\
11553
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11533
diff changeset
122 decomposition, eliminating the unnecessary rows or columns of @var{U} or\n\
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11533
diff changeset
123 @var{V}.\n\
16920
53eaa83e4181 doc: Add seealso links between various factorization forms.
Rik <rik@octave.org>
parents: 15888
diff changeset
124 @seealso{svd_driver, svds, eig, lu, chol, hess, qr, qz}\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3014
diff changeset
125 @end deftypefn")
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
126 {
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
127 octave_value_list retval;
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
128
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
129 int nargin = args.length ();
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
130
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
131 if (nargin < 1 || nargin > 2 || nargout == 2 || nargout > 3)
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
132 {
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5307
diff changeset
133 print_usage ();
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
134 return retval;
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
135 }
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
136
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
137 octave_value arg = args(0);
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
138
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 4478
diff changeset
139 octave_idx_type nr = arg.rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 4478
diff changeset
140 octave_idx_type nc = arg.columns ();
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
141
10185
455759a5fcbe fix norm and svd on empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
142 if (arg.ndims () != 2)
455759a5fcbe fix norm and svd on empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
143 {
11553
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11533
diff changeset
144 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
145 return retval;
455759a5fcbe fix norm and svd on empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
146 }
455759a5fcbe fix norm and svd on empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
147
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
148 bool isfloat = arg.is_single_type ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
149
10185
455759a5fcbe fix norm and svd on empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
150 SVD::type type = ((nargout == 0 || nargout == 1)
455759a5fcbe fix norm and svd on empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
151 ? SVD::sigma_only
455759a5fcbe fix norm and svd on empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
152 : (nargin == 2) ? SVD::economy : SVD::std);
455759a5fcbe fix norm and svd on empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
153
10638
e1559a8a60b4 general mechanism for string enum variables
Jaroslav Hajek <highegg@gmail.com>
parents: 10601
diff changeset
154 SVD::driver driver = static_cast<SVD::driver> (Vsvd_driver);
e1559a8a60b4 general mechanism for string enum variables
Jaroslav Hajek <highegg@gmail.com>
parents: 10601
diff changeset
155
4478
7afd4bf05aa8 [project @ 2003-07-30 19:15:31 by jwe]
jwe
parents: 3548
diff changeset
156 if (nr == 0 || nc == 0)
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
157 {
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
158 if (isfloat)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
159 {
10185
455759a5fcbe fix norm and svd on empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
160 switch (type)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
161 {
10185
455759a5fcbe fix norm and svd on empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
162 case SVD::std:
455759a5fcbe fix norm and svd on empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
163 retval(2) = FloatDiagMatrix (nc, nc, 1.0f);
455759a5fcbe fix norm and svd on empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
164 retval(1) = FloatMatrix (nr, nc);
455759a5fcbe fix norm and svd on empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
165 retval(0) = FloatDiagMatrix (nr, nr, 1.0f);
455759a5fcbe fix norm and svd on empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
166 break;
455759a5fcbe fix norm and svd on empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
167 case SVD::economy:
455759a5fcbe fix norm and svd on empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
168 retval(2) = FloatDiagMatrix (0, nc, 1.0f);
455759a5fcbe fix norm and svd on empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
169 retval(1) = FloatMatrix (0, 0);
455759a5fcbe fix norm and svd on empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
170 retval(0) = FloatDiagMatrix (nr, 0, 1.0f);
455759a5fcbe fix norm and svd on empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
171 break;
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
172 case SVD::sigma_only: default:
10185
455759a5fcbe fix norm and svd on empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
173 retval(0) = FloatMatrix (0, 1);
455759a5fcbe fix norm and svd on empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
174 break;
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
175 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
176 }
4478
7afd4bf05aa8 [project @ 2003-07-30 19:15:31 by jwe]
jwe
parents: 3548
diff changeset
177 else
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
178 {
10185
455759a5fcbe fix norm and svd on empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
179 switch (type)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
180 {
10185
455759a5fcbe fix norm and svd on empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
181 case SVD::std:
455759a5fcbe fix norm and svd on empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
182 retval(2) = DiagMatrix (nc, nc, 1.0);
455759a5fcbe fix norm and svd on empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
183 retval(1) = Matrix (nr, nc);
455759a5fcbe fix norm and svd on empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
184 retval(0) = DiagMatrix (nr, nr, 1.0);
455759a5fcbe fix norm and svd on empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
185 break;
455759a5fcbe fix norm and svd on empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
186 case SVD::economy:
455759a5fcbe fix norm and svd on empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
187 retval(2) = DiagMatrix (0, nc, 1.0);
455759a5fcbe fix norm and svd on empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
188 retval(1) = Matrix (0, 0);
455759a5fcbe fix norm and svd on empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
189 retval(0) = DiagMatrix (nr, 0, 1.0);
455759a5fcbe fix norm and svd on empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
190 break;
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
191 case SVD::sigma_only: default:
10185
455759a5fcbe fix norm and svd on empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
192 retval(0) = Matrix (0, 1);
455759a5fcbe fix norm and svd on empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
193 break;
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
194 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
195 }
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
196 }
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
197 else
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
198 {
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
199 if (isfloat)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
200 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
201 if (arg.is_real_type ())
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
202 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
203 FloatMatrix tmp = arg.float_matrix_value ();
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
204
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
205 if (! error_state)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
206 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
207 if (tmp.any_element_is_inf_or_nan ())
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
208 {
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
209 error ("svd: cannot take SVD of matrix containing Inf or NaN values");
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
210 return retval;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
211 }
4478
7afd4bf05aa8 [project @ 2003-07-30 19:15:31 by jwe]
jwe
parents: 3548
diff changeset
212
10601
3ce0c530a9c9 implement svd_driver
Jaroslav Hajek <highegg@gmail.com>
parents: 10185
diff changeset
213 FloatSVD result (tmp, type, driver);
4478
7afd4bf05aa8 [project @ 2003-07-30 19:15:31 by jwe]
jwe
parents: 3548
diff changeset
214
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
215 FloatDiagMatrix sigma = result.singular_values ();
4478
7afd4bf05aa8 [project @ 2003-07-30 19:15:31 by jwe]
jwe
parents: 3548
diff changeset
216
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
217 if (nargout == 0 || nargout == 1)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
218 {
15448
0a0912a9ab6e Replace deprecated DiagArray2<T>::diag calls with DiagArray2<T>::extract_diag
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 15195
diff changeset
219 retval(0) = sigma.extract_diag ();
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
220 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
221 else
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
222 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
223 retval(2) = result.right_singular_matrix ();
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
224 retval(1) = sigma;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
225 retval(0) = result.left_singular_matrix ();
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
226 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
227 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
228 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
229 else if (arg.is_complex_type ())
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
230 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
231 FloatComplexMatrix ctmp = arg.float_complex_matrix_value ();
4478
7afd4bf05aa8 [project @ 2003-07-30 19:15:31 by jwe]
jwe
parents: 3548
diff changeset
232
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
233 if (! error_state)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
234 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
235 if (ctmp.any_element_is_inf_or_nan ())
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
236 {
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
237 error ("svd: cannot take SVD of matrix containing Inf or NaN values");
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
238 return retval;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
239 }
4478
7afd4bf05aa8 [project @ 2003-07-30 19:15:31 by jwe]
jwe
parents: 3548
diff changeset
240
10601
3ce0c530a9c9 implement svd_driver
Jaroslav Hajek <highegg@gmail.com>
parents: 10185
diff changeset
241 FloatComplexSVD result (ctmp, type, driver);
4478
7afd4bf05aa8 [project @ 2003-07-30 19:15:31 by jwe]
jwe
parents: 3548
diff changeset
242
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
243 FloatDiagMatrix sigma = result.singular_values ();
4478
7afd4bf05aa8 [project @ 2003-07-30 19:15:31 by jwe]
jwe
parents: 3548
diff changeset
244
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
245 if (nargout == 0 || nargout == 1)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
246 {
15448
0a0912a9ab6e Replace deprecated DiagArray2<T>::diag calls with DiagArray2<T>::extract_diag
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 15195
diff changeset
247 retval(0) = sigma.extract_diag ();
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
248 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
249 else
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
250 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
251 retval(2) = result.right_singular_matrix ();
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
252 retval(1) = sigma;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
253 retval(0) = result.left_singular_matrix ();
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
254 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
255 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
256 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
257 }
4478
7afd4bf05aa8 [project @ 2003-07-30 19:15:31 by jwe]
jwe
parents: 3548
diff changeset
258 else
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
259 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
260 if (arg.is_real_type ())
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
261 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
262 Matrix tmp = arg.matrix_value ();
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
263
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
264 if (! error_state)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
265 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
266 if (tmp.any_element_is_inf_or_nan ())
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
267 {
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
268 error ("svd: cannot take SVD of matrix containing Inf or NaN values");
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
269 return retval;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
270 }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
271
10601
3ce0c530a9c9 implement svd_driver
Jaroslav Hajek <highegg@gmail.com>
parents: 10185
diff changeset
272 SVD result (tmp, type, driver);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
273
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
274 DiagMatrix sigma = result.singular_values ();
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
275
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
276 if (nargout == 0 || nargout == 1)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
277 {
15448
0a0912a9ab6e Replace deprecated DiagArray2<T>::diag calls with DiagArray2<T>::extract_diag
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 15195
diff changeset
278 retval(0) = sigma.extract_diag ();
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
279 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
280 else
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
281 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
282 retval(2) = result.right_singular_matrix ();
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
283 retval(1) = sigma;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
284 retval(0) = result.left_singular_matrix ();
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
285 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
286 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
287 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
288 else if (arg.is_complex_type ())
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
289 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
290 ComplexMatrix ctmp = arg.complex_matrix_value ();
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
291
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
292 if (! error_state)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
293 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
294 if (ctmp.any_element_is_inf_or_nan ())
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
295 {
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
296 error ("svd: cannot take SVD of matrix containing Inf or NaN values");
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
297 return retval;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
298 }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
299
10601
3ce0c530a9c9 implement svd_driver
Jaroslav Hajek <highegg@gmail.com>
parents: 10185
diff changeset
300 ComplexSVD result (ctmp, type, driver);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
301
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
302 DiagMatrix sigma = result.singular_values ();
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
303
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
304 if (nargout == 0 || nargout == 1)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
305 {
15448
0a0912a9ab6e Replace deprecated DiagArray2<T>::diag calls with DiagArray2<T>::extract_diag
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 15195
diff changeset
306 retval(0) = sigma.extract_diag ();
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
307 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
308 else
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
309 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
310 retval(2) = result.right_singular_matrix ();
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
311 retval(1) = sigma;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
312 retval(0) = result.left_singular_matrix ();
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
313 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
314 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
315 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
316 else
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
317 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
318 gripe_wrong_type_arg ("svd", arg);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
319 return retval;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
320 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
321 }
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
322 }
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
323
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
324 return retval;
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
325 }
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
326
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
327 /*
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
328 %!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
329
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
330 %!test
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
331 %! [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
332 %! 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
333 %! 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
334 %! 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
335 %! 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
336
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
337 %!test
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
338 %! 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
339 %! [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
340 %! 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
341
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
342 %!test
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
343 %! 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
344 %! [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
345 %! 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
346
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
347 %!test
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
348 %! 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
349 %! [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
350 %! 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
351
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
352 %!test
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
353 %! 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
354 %! [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
355 %! 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
356
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
357 %!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
358
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
359 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
360 %! [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
361 %! 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
362 %! 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
363 %! 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
364 %! 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
365
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
366 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
367 %! 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
368 %! [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
369 %! 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
370
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
371 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
372 %! 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
373 %! [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
374 %! 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
375
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
376 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
377 %! 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
378 %! [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
379 %! 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
380
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
381 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
382 %! 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
383 %! [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
384 %! 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
385
10185
455759a5fcbe fix norm and svd on empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
386 %!test
455759a5fcbe fix norm and svd on empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
387 %! a = zeros (0, 5);
455759a5fcbe fix norm and svd on empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
388 %! [u, s, v] = svd (a);
455759a5fcbe fix norm and svd on empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
389 %! assert (size (u), [0, 0]);
455759a5fcbe fix norm and svd on empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
390 %! assert (size (s), [0, 5]);
455759a5fcbe fix norm and svd on empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
391 %! assert (size (v), [5, 5]);
455759a5fcbe fix norm and svd on empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
392
455759a5fcbe fix norm and svd on empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
393 %!test
455759a5fcbe fix norm and svd on empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
394 %! a = zeros (5, 0);
455759a5fcbe fix norm and svd on empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
395 %! [u, s, v] = svd (a, 1);
455759a5fcbe fix norm and svd on empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
396 %! assert (size (u), [5, 0]);
455759a5fcbe fix norm and svd on empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
397 %! assert (size (s), [0, 0]);
455759a5fcbe fix norm and svd on empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
398 %! assert (size (v), [0, 0]);
455759a5fcbe fix norm and svd on empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
399
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
400 %!error svd ()
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
401 %!error svd ([1, 2; 4, 5], 2, 3)
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
402 %!error [u, v] = svd ([1, 2; 3, 4])
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
403 */
10601
3ce0c530a9c9 implement svd_driver
Jaroslav Hajek <highegg@gmail.com>
parents: 10185
diff changeset
404
15039
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14501
diff changeset
405 DEFUN (svd_driver, args, nargout,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
406 "-*- texinfo -*-\n\
15039
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14501
diff changeset
407 @deftypefn {Built-in Function} {@var{val} =} svd_driver ()\n\
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14501
diff changeset
408 @deftypefnx {Built-in Function} {@var{old_val} =} svd_driver (@var{new_val})\n\
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14501
diff changeset
409 @deftypefnx {Built-in Function} {} svd_driver (@var{new_val}, \"local\")\n\
12584
7ef7e20057fa Improve documentation strings in Linear Algebra chapter.
Rik <octave@nomad.inbox5.com>
parents: 11586
diff changeset
410 Query or set the underlying @sc{lapack} driver used by @code{svd}.\n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 16920
diff changeset
411 Currently recognized values are @qcode{\"gesvd\"} and @qcode{\"gesdd\"}. \n\
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 16920
diff changeset
412 The default is @qcode{\"gesvd\"}.\n\
13951
79aa00a94e9e doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
413 \n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 16920
diff changeset
414 When called from inside a function with the @qcode{\"local\"} option, the\n\
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 16920
diff changeset
415 variable is changed locally for the function and any subroutines it calls. \n\
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 16920
diff changeset
416 The original variable value is restored when exiting the function.\n\
10601
3ce0c530a9c9 implement svd_driver
Jaroslav Hajek <highegg@gmail.com>
parents: 10185
diff changeset
417 @seealso{svd}\n\
3ce0c530a9c9 implement svd_driver
Jaroslav Hajek <highegg@gmail.com>
parents: 10185
diff changeset
418 @end deftypefn")
3ce0c530a9c9 implement svd_driver
Jaroslav Hajek <highegg@gmail.com>
parents: 10185
diff changeset
419 {
10640
5c594472f75e determine string enum length by trailing null rather than sizeof
Jaroslav Hajek <highegg@gmail.com>
parents: 10638
diff changeset
420 static const char *driver_names[] = { "gesvd", "gesdd", 0 };
10601
3ce0c530a9c9 implement svd_driver
Jaroslav Hajek <highegg@gmail.com>
parents: 10185
diff changeset
421
10638
e1559a8a60b4 general mechanism for string enum variables
Jaroslav Hajek <highegg@gmail.com>
parents: 10601
diff changeset
422 return SET_INTERNAL_VARIABLE_CHOICES (svd_driver, driver_names);
10601
3ce0c530a9c9 implement svd_driver
Jaroslav Hajek <highegg@gmail.com>
parents: 10185
diff changeset
423 }
15887
8ced82e96b48 Fix segfaults with gesdd driver for svd (bug #37998).
Rik <rik@octave.org>
parents: 14138
diff changeset
424
8ced82e96b48 Fix segfaults with gesdd driver for svd (bug #37998).
Rik <rik@octave.org>
parents: 14138
diff changeset
425 /*
8ced82e96b48 Fix segfaults with gesdd driver for svd (bug #37998).
Rik <rik@octave.org>
parents: 14138
diff changeset
426 %!test
8ced82e96b48 Fix segfaults with gesdd driver for svd (bug #37998).
Rik <rik@octave.org>
parents: 14138
diff changeset
427 %! 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
428 %! old_driver = svd_driver ("gesvd");
8ced82e96b48 Fix segfaults with gesdd driver for svd (bug #37998).
Rik <rik@octave.org>
parents: 14138
diff changeset
429 %! [U1, S1, V1] = svd (A);
8ced82e96b48 Fix segfaults with gesdd driver for svd (bug #37998).
Rik <rik@octave.org>
parents: 14138
diff changeset
430 %! svd_driver ("gesdd");
8ced82e96b48 Fix segfaults with gesdd driver for svd (bug #37998).
Rik <rik@octave.org>
parents: 14138
diff changeset
431 %! [U2, S2, V2] = svd (A);
8ced82e96b48 Fix segfaults with gesdd driver for svd (bug #37998).
Rik <rik@octave.org>
parents: 14138
diff changeset
432 %! assert (U1, U2, 5*eps);
8ced82e96b48 Fix segfaults with gesdd driver for svd (bug #37998).
Rik <rik@octave.org>
parents: 14138
diff changeset
433 %! assert (S1, S2, 5*eps);
8ced82e96b48 Fix segfaults with gesdd driver for svd (bug #37998).
Rik <rik@octave.org>
parents: 14138
diff changeset
434 %! assert (V1, V2, 5*eps);
8ced82e96b48 Fix segfaults with gesdd driver for svd (bug #37998).
Rik <rik@octave.org>
parents: 14138
diff changeset
435 %! svd_driver (old_driver);
8ced82e96b48 Fix segfaults with gesdd driver for svd (bug #37998).
Rik <rik@octave.org>
parents: 14138
diff changeset
436 */