annotate liboctave/numeric/dbleSVD.cc @ 17769:49a5a4be04a1

maint: Use GNU style coding conventions for code in liboctave/ * liboctave/array/Array-C.cc, liboctave/array/Array-b.cc, liboctave/array/Array-ch.cc, liboctave/array/Array-d.cc, liboctave/array/Array-f.cc, liboctave/array/Array-fC.cc, liboctave/array/Array-util.cc, liboctave/array/Array-util.h, liboctave/array/Array.cc, liboctave/array/Array.h, liboctave/array/Array3.h, liboctave/array/CColVector.cc, liboctave/array/CColVector.h, liboctave/array/CDiagMatrix.cc, liboctave/array/CDiagMatrix.h, liboctave/array/CMatrix.cc, liboctave/array/CMatrix.h, liboctave/array/CNDArray.cc, liboctave/array/CNDArray.h, liboctave/array/CRowVector.cc, liboctave/array/CRowVector.h, liboctave/array/CSparse.cc, liboctave/array/CSparse.h, liboctave/array/DiagArray2.h, liboctave/array/MArray.cc, liboctave/array/MArray.h, liboctave/array/MDiagArray2.cc, liboctave/array/MDiagArray2.h, liboctave/array/MSparse.cc, liboctave/array/MSparse.h, liboctave/array/MatrixType.cc, liboctave/array/MatrixType.h, liboctave/array/PermMatrix.h, liboctave/array/Range.cc, liboctave/array/Range.h, liboctave/array/Sparse.cc, liboctave/array/Sparse.h, liboctave/array/boolMatrix.cc, liboctave/array/boolMatrix.h, liboctave/array/boolNDArray.cc, liboctave/array/boolNDArray.h, liboctave/array/boolSparse.cc, liboctave/array/boolSparse.h, liboctave/array/chMatrix.cc, liboctave/array/chMatrix.h, liboctave/array/chNDArray.cc, liboctave/array/chNDArray.h, liboctave/array/dColVector.h, liboctave/array/dDiagMatrix.cc, liboctave/array/dDiagMatrix.h, liboctave/array/dMatrix.cc, liboctave/array/dMatrix.h, liboctave/array/dNDArray.cc, liboctave/array/dNDArray.h, liboctave/array/dRowVector.h, liboctave/array/dSparse.cc, liboctave/array/dSparse.h, liboctave/array/dim-vector.cc, liboctave/array/dim-vector.h, liboctave/array/fCColVector.cc, liboctave/array/fCColVector.h, liboctave/array/fCDiagMatrix.cc, liboctave/array/fCDiagMatrix.h, liboctave/array/fCMatrix.cc, liboctave/array/fCMatrix.h, liboctave/array/fCNDArray.cc, liboctave/array/fCNDArray.h, liboctave/array/fCRowVector.cc, liboctave/array/fCRowVector.h, liboctave/array/fColVector.h, liboctave/array/fDiagMatrix.cc, liboctave/array/fDiagMatrix.h, liboctave/array/fMatrix.cc, liboctave/array/fMatrix.h, liboctave/array/fNDArray.cc, liboctave/array/fNDArray.h, liboctave/array/fRowVector.h, liboctave/array/idx-vector.cc, liboctave/array/idx-vector.h, liboctave/array/intNDArray.cc, liboctave/array/intNDArray.h, liboctave/cruft/misc/blaswrap.c, liboctave/cruft/misc/quit.cc, liboctave/numeric/CmplxCHOL.cc, liboctave/numeric/CmplxCHOL.h, liboctave/numeric/CmplxGEPBAL.cc, liboctave/numeric/CmplxGEPBAL.h, liboctave/numeric/CmplxHESS.h, liboctave/numeric/CmplxLU.cc, liboctave/numeric/CmplxLU.h, liboctave/numeric/CmplxQR.cc, liboctave/numeric/CmplxQRP.cc, liboctave/numeric/CmplxQRP.h, liboctave/numeric/CmplxSCHUR.h, liboctave/numeric/CmplxSVD.cc, liboctave/numeric/CmplxSVD.h, liboctave/numeric/CollocWt.h, liboctave/numeric/DAE.h, liboctave/numeric/DAEFunc.h, liboctave/numeric/DAERT.h, liboctave/numeric/DAERTFunc.h, liboctave/numeric/DASPK.cc, liboctave/numeric/DASRT.cc, liboctave/numeric/DASRT.h, liboctave/numeric/DASSL.cc, liboctave/numeric/DET.h, liboctave/numeric/EIG.cc, liboctave/numeric/EIG.h, liboctave/numeric/LSODE.cc, liboctave/numeric/ODE.h, liboctave/numeric/ODEFunc.h, liboctave/numeric/ODES.h, liboctave/numeric/ODESFunc.h, liboctave/numeric/Quad.cc, liboctave/numeric/Quad.h, liboctave/numeric/SparseCmplxCHOL.h, liboctave/numeric/SparseCmplxLU.cc, liboctave/numeric/SparseCmplxLU.h, liboctave/numeric/SparseCmplxQR.cc, liboctave/numeric/SparseCmplxQR.h, liboctave/numeric/SparseQR.cc, liboctave/numeric/SparseQR.h, liboctave/numeric/SparsedbleCHOL.h, liboctave/numeric/SparsedbleLU.cc, liboctave/numeric/SparsedbleLU.h, liboctave/numeric/base-aepbal.h, liboctave/numeric/base-dae.h, liboctave/numeric/base-de.h, liboctave/numeric/base-lu.cc, liboctave/numeric/base-lu.h, liboctave/numeric/base-min.h, liboctave/numeric/base-qr.h, liboctave/numeric/bsxfun.h, liboctave/numeric/dbleCHOL.cc, liboctave/numeric/dbleCHOL.h, liboctave/numeric/dbleGEPBAL.h, liboctave/numeric/dbleHESS.h, liboctave/numeric/dbleLU.cc, liboctave/numeric/dbleLU.h, liboctave/numeric/dbleQR.cc, liboctave/numeric/dbleQRP.cc, liboctave/numeric/dbleQRP.h, liboctave/numeric/dbleSCHUR.cc, liboctave/numeric/dbleSCHUR.h, liboctave/numeric/dbleSVD.cc, liboctave/numeric/dbleSVD.h, liboctave/numeric/eigs-base.cc, liboctave/numeric/fCmplxAEPBAL.cc, liboctave/numeric/fCmplxAEPBAL.h, liboctave/numeric/fCmplxCHOL.cc, liboctave/numeric/fCmplxCHOL.h, liboctave/numeric/fCmplxGEPBAL.cc, liboctave/numeric/fCmplxGEPBAL.h, liboctave/numeric/fCmplxHESS.h, liboctave/numeric/fCmplxLU.cc, liboctave/numeric/fCmplxLU.h, liboctave/numeric/fCmplxQR.cc, liboctave/numeric/fCmplxQR.h, liboctave/numeric/fCmplxQRP.cc, liboctave/numeric/fCmplxQRP.h, liboctave/numeric/fCmplxSCHUR.cc, liboctave/numeric/fCmplxSCHUR.h, liboctave/numeric/fCmplxSVD.h, liboctave/numeric/fEIG.cc, liboctave/numeric/fEIG.h, liboctave/numeric/floatCHOL.cc, liboctave/numeric/floatCHOL.h, liboctave/numeric/floatGEPBAL.cc, liboctave/numeric/floatGEPBAL.h, liboctave/numeric/floatHESS.h, liboctave/numeric/floatLU.cc, liboctave/numeric/floatLU.h, liboctave/numeric/floatQR.cc, liboctave/numeric/floatQRP.cc, liboctave/numeric/floatQRP.h, liboctave/numeric/floatSCHUR.cc, liboctave/numeric/floatSCHUR.h, liboctave/numeric/floatSVD.cc, liboctave/numeric/floatSVD.h, liboctave/numeric/lo-mappers.cc, liboctave/numeric/lo-mappers.h, liboctave/numeric/lo-specfun.cc, liboctave/numeric/lo-specfun.h, liboctave/numeric/oct-convn.cc, liboctave/numeric/oct-fftw.cc, liboctave/numeric/oct-fftw.h, liboctave/numeric/oct-norm.cc, liboctave/numeric/oct-rand.cc, liboctave/numeric/oct-rand.h, liboctave/numeric/randgamma.c, liboctave/numeric/randgamma.h, liboctave/numeric/randmtzig.c, liboctave/numeric/randpoisson.c, liboctave/numeric/randpoisson.h, liboctave/numeric/sparse-base-chol.h, liboctave/numeric/sparse-base-lu.h, liboctave/numeric/sparse-dmsolve.cc, liboctave/operators/Sparse-diag-op-defs.h, liboctave/operators/Sparse-op-defs.h, liboctave/operators/mx-inlines.cc, liboctave/system/dir-ops.h, liboctave/system/file-ops.cc, liboctave/system/file-stat.cc, liboctave/system/file-stat.h, liboctave/system/lo-sysdep.cc, liboctave/system/lo-sysdep.h, liboctave/system/mach-info.cc, liboctave/system/mach-info.h, liboctave/system/oct-env.cc, liboctave/system/oct-group.cc, liboctave/system/oct-syscalls.cc, liboctave/system/oct-syscalls.h, liboctave/system/oct-time.h, liboctave/system/tempname.c, liboctave/util/action-container.h, liboctave/util/base-list.h, liboctave/util/cmd-edit.cc, liboctave/util/cmd-edit.h, liboctave/util/cmd-hist.cc, liboctave/util/cmd-hist.h, liboctave/util/data-conv.cc, liboctave/util/data-conv.h, liboctave/util/kpse.cc, liboctave/util/lo-array-gripes.cc, liboctave/util/lo-cieee.c, liboctave/util/lo-regexp.cc, liboctave/util/lo-utils.cc, liboctave/util/oct-alloc.cc, liboctave/util/oct-base64.cc, liboctave/util/oct-binmap.h, liboctave/util/oct-cmplx.h, liboctave/util/oct-glob.cc, liboctave/util/oct-inttypes.cc, liboctave/util/oct-inttypes.h, liboctave/util/oct-locbuf.cc, liboctave/util/oct-locbuf.h, liboctave/util/oct-mem.h, liboctave/util/oct-mutex.cc, liboctave/util/oct-refcount.h, liboctave/util/oct-shlib.cc, liboctave/util/oct-shlib.h, liboctave/util/oct-sort.cc, liboctave/util/oct-sort.h, liboctave/util/pathsearch.cc, liboctave/util/pathsearch.h, liboctave/util/sparse-util.cc, liboctave/util/str-vec.cc, liboctave/util/str-vec.h, liboctave/util/unwind-prot.h, liboctave/util/url-transfer.cc, liboctave/util/url-transfer.h: Use GNU style coding conventions.
author Rik <rik@octave.org>
date Sat, 26 Oct 2013 18:57:05 -0700
parents d63878346099
children 4197fc428c7d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
457
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
1 /*
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
2
17744
d63878346099 maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents: 15888
diff changeset
3 Copyright (C) 1994-2013 John W. Eaton
457
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
4
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
5 This file is part of Octave.
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
6
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
3d4b4f0fa5ba [project @ 1994-06-06 00:33: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: 5307
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: 5307
diff changeset
10 option) any later version.
457
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
11
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
15 for more details.
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
16
3d4b4f0fa5ba [project @ 1994-06-06 00:33: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: 5307
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: 5307
diff changeset
19 <http://www.gnu.org/licenses/>.
457
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
20
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
21 */
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
22
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
23 #ifdef HAVE_CONFIG_H
1192
b6360f2d4fa6 [project @ 1995-03-30 21:38:35 by jwe]
jwe
parents: 1011
diff changeset
24 #include <config.h>
457
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
25 #endif
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
26
3503
d14c483b3c12 [project @ 2000-02-01 04:06:07 by jwe]
jwe
parents: 3336
diff changeset
27 #include <iostream>
1631
b0b22b6ce22f [project @ 1995-11-14 20:24:15 by jwe]
jwe
parents: 1545
diff changeset
28
457
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
29 #include "dbleSVD.h"
1847
2ffe49eb95a5 [project @ 1996-02-03 12:47:55 by jwe]
jwe
parents: 1631
diff changeset
30 #include "f77-fcn.h"
10601
3ce0c530a9c9 implement svd_driver
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
31 #include "oct-locbuf.h"
457
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
32
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
33 extern "C"
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
34 {
4552
6f3382e08a52 [project @ 2003-10-27 20:38:02 by jwe]
jwe
parents: 4192
diff changeset
35 F77_RET_T
6f3382e08a52 [project @ 2003-10-27 20:38:02 by jwe]
jwe
parents: 4192
diff changeset
36 F77_FUNC (dgesvd, DGESVD) (F77_CONST_CHAR_ARG_DECL,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10258
diff changeset
37 F77_CONST_CHAR_ARG_DECL,
11495
8a5e980da6aa style fixes
John W. Eaton <jwe@octave.org>
parents: 10601
diff changeset
38 const octave_idx_type&, const octave_idx_type&,
8a5e980da6aa style fixes
John W. Eaton <jwe@octave.org>
parents: 10601
diff changeset
39 double*, const octave_idx_type&, double*,
8a5e980da6aa style fixes
John W. Eaton <jwe@octave.org>
parents: 10601
diff changeset
40 double*, const octave_idx_type&, double*,
8a5e980da6aa style fixes
John W. Eaton <jwe@octave.org>
parents: 10601
diff changeset
41 const octave_idx_type&, double*,
8a5e980da6aa style fixes
John W. Eaton <jwe@octave.org>
parents: 10601
diff changeset
42 const octave_idx_type&, octave_idx_type&
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10258
diff changeset
43 F77_CHAR_ARG_LEN_DECL
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10258
diff changeset
44 F77_CHAR_ARG_LEN_DECL);
10601
3ce0c530a9c9 implement svd_driver
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
45
3ce0c530a9c9 implement svd_driver
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
46 F77_RET_T
3ce0c530a9c9 implement svd_driver
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
47 F77_FUNC (dgesdd, DGESDD) (F77_CONST_CHAR_ARG_DECL,
11495
8a5e980da6aa style fixes
John W. Eaton <jwe@octave.org>
parents: 10601
diff changeset
48 const octave_idx_type&, const octave_idx_type&,
8a5e980da6aa style fixes
John W. Eaton <jwe@octave.org>
parents: 10601
diff changeset
49 double*, const octave_idx_type&, double*,
8a5e980da6aa style fixes
John W. Eaton <jwe@octave.org>
parents: 10601
diff changeset
50 double*, const octave_idx_type&, double*,
8a5e980da6aa style fixes
John W. Eaton <jwe@octave.org>
parents: 10601
diff changeset
51 const octave_idx_type&, double*,
8a5e980da6aa style fixes
John W. Eaton <jwe@octave.org>
parents: 10601
diff changeset
52 const octave_idx_type&, octave_idx_type *,
8a5e980da6aa style fixes
John W. Eaton <jwe@octave.org>
parents: 10601
diff changeset
53 octave_idx_type&
10601
3ce0c530a9c9 implement svd_driver
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
54 F77_CHAR_ARG_LEN_DECL);
457
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
55 }
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
56
1543
d6e96e0bc681 [project @ 1995-10-06 05:49:21 by jwe]
jwe
parents: 1368
diff changeset
57 Matrix
1545
8bdfa6fe5d69 [project @ 1995-10-06 06:13:28 by jwe]
jwe
parents: 1544
diff changeset
58 SVD::left_singular_matrix (void) const
1543
d6e96e0bc681 [project @ 1995-10-06 05:49:21 by jwe]
jwe
parents: 1368
diff changeset
59 {
1544
f1931fc63ce9 [project @ 1995-10-06 05:57:56 by jwe]
jwe
parents: 1543
diff changeset
60 if (type_computed == SVD::sigma_only)
1543
d6e96e0bc681 [project @ 1995-10-06 05:49:21 by jwe]
jwe
parents: 1368
diff changeset
61 {
d6e96e0bc681 [project @ 1995-10-06 05:49:21 by jwe]
jwe
parents: 1368
diff changeset
62 (*current_liboctave_error_handler)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10258
diff changeset
63 ("SVD: U not computed because type == SVD::sigma_only");
1543
d6e96e0bc681 [project @ 1995-10-06 05:49:21 by jwe]
jwe
parents: 1368
diff changeset
64 return Matrix ();
d6e96e0bc681 [project @ 1995-10-06 05:49:21 by jwe]
jwe
parents: 1368
diff changeset
65 }
d6e96e0bc681 [project @ 1995-10-06 05:49:21 by jwe]
jwe
parents: 1368
diff changeset
66 else
d6e96e0bc681 [project @ 1995-10-06 05:49:21 by jwe]
jwe
parents: 1368
diff changeset
67 return left_sm;
d6e96e0bc681 [project @ 1995-10-06 05:49:21 by jwe]
jwe
parents: 1368
diff changeset
68 }
d6e96e0bc681 [project @ 1995-10-06 05:49:21 by jwe]
jwe
parents: 1368
diff changeset
69
d6e96e0bc681 [project @ 1995-10-06 05:49:21 by jwe]
jwe
parents: 1368
diff changeset
70 Matrix
1545
8bdfa6fe5d69 [project @ 1995-10-06 06:13:28 by jwe]
jwe
parents: 1544
diff changeset
71 SVD::right_singular_matrix (void) const
1543
d6e96e0bc681 [project @ 1995-10-06 05:49:21 by jwe]
jwe
parents: 1368
diff changeset
72 {
1544
f1931fc63ce9 [project @ 1995-10-06 05:57:56 by jwe]
jwe
parents: 1543
diff changeset
73 if (type_computed == SVD::sigma_only)
1543
d6e96e0bc681 [project @ 1995-10-06 05:49:21 by jwe]
jwe
parents: 1368
diff changeset
74 {
d6e96e0bc681 [project @ 1995-10-06 05:49:21 by jwe]
jwe
parents: 1368
diff changeset
75 (*current_liboctave_error_handler)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10258
diff changeset
76 ("SVD: V not computed because type == SVD::sigma_only");
1543
d6e96e0bc681 [project @ 1995-10-06 05:49:21 by jwe]
jwe
parents: 1368
diff changeset
77 return Matrix ();
d6e96e0bc681 [project @ 1995-10-06 05:49:21 by jwe]
jwe
parents: 1368
diff changeset
78 }
d6e96e0bc681 [project @ 1995-10-06 05:49:21 by jwe]
jwe
parents: 1368
diff changeset
79 else
d6e96e0bc681 [project @ 1995-10-06 05:49:21 by jwe]
jwe
parents: 1368
diff changeset
80 return right_sm;
d6e96e0bc681 [project @ 1995-10-06 05:49:21 by jwe]
jwe
parents: 1368
diff changeset
81 }
d6e96e0bc681 [project @ 1995-10-06 05:49:21 by jwe]
jwe
parents: 1368
diff changeset
82
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
83 octave_idx_type
10601
3ce0c530a9c9 implement svd_driver
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
84 SVD::init (const Matrix& a, SVD::type svd_type, SVD::driver svd_driver)
457
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
85 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
86 octave_idx_type info;
457
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
87
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
88 octave_idx_type m = a.rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
89 octave_idx_type n = a.cols ();
457
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
90
1930
d20ab06301e8 [project @ 1996-02-11 22:30:18 by jwe]
jwe
parents: 1882
diff changeset
91 Matrix atmp = a;
d20ab06301e8 [project @ 1996-02-11 22:30:18 by jwe]
jwe
parents: 1882
diff changeset
92 double *tmp_data = atmp.fortran_vec ();
457
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
93
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
94 octave_idx_type min_mn = m < n ? m : n;
457
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
95
1930
d20ab06301e8 [project @ 1996-02-11 22:30:18 by jwe]
jwe
parents: 1882
diff changeset
96 char jobu = 'A';
d20ab06301e8 [project @ 1996-02-11 22:30:18 by jwe]
jwe
parents: 1882
diff changeset
97 char jobv = 'A';
537
4ecbfd3c3710 [project @ 1994-07-21 22:30:34 by jwe]
jwe
parents: 457
diff changeset
98
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
99 octave_idx_type ncol_u = m;
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
100 octave_idx_type nrow_vt = n;
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
101 octave_idx_type nrow_s = m;
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
102 octave_idx_type ncol_s = n;
537
4ecbfd3c3710 [project @ 1994-07-21 22:30:34 by jwe]
jwe
parents: 457
diff changeset
103
1543
d6e96e0bc681 [project @ 1995-10-06 05:49:21 by jwe]
jwe
parents: 1368
diff changeset
104 switch (svd_type)
537
4ecbfd3c3710 [project @ 1994-07-21 22:30:34 by jwe]
jwe
parents: 457
diff changeset
105 {
1543
d6e96e0bc681 [project @ 1995-10-06 05:49:21 by jwe]
jwe
parents: 1368
diff changeset
106 case SVD::economy:
1930
d20ab06301e8 [project @ 1996-02-11 22:30:18 by jwe]
jwe
parents: 1882
diff changeset
107 jobu = jobv = 'S';
537
4ecbfd3c3710 [project @ 1994-07-21 22:30:34 by jwe]
jwe
parents: 457
diff changeset
108 ncol_u = nrow_vt = nrow_s = ncol_s = min_mn;
1543
d6e96e0bc681 [project @ 1995-10-06 05:49:21 by jwe]
jwe
parents: 1368
diff changeset
109 break;
d6e96e0bc681 [project @ 1995-10-06 05:49:21 by jwe]
jwe
parents: 1368
diff changeset
110
d6e96e0bc681 [project @ 1995-10-06 05:49:21 by jwe]
jwe
parents: 1368
diff changeset
111 case SVD::sigma_only:
2621
337a09dd1c06 [project @ 1997-01-24 21:49:41 by jwe]
jwe
parents: 1993
diff changeset
112
337a09dd1c06 [project @ 1997-01-24 21:49:41 by jwe]
jwe
parents: 1993
diff changeset
113 // Note: for this case, both jobu and jobv should be 'N', but
337a09dd1c06 [project @ 1997-01-24 21:49:41 by jwe]
jwe
parents: 1993
diff changeset
114 // there seems to be a bug in dgesvd from Lapack V2.0. To
337a09dd1c06 [project @ 1997-01-24 21:49:41 by jwe]
jwe
parents: 1993
diff changeset
115 // demonstrate the bug, set both jobu and jobv to 'N' and find
337a09dd1c06 [project @ 1997-01-24 21:49:41 by jwe]
jwe
parents: 1993
diff changeset
116 // the singular values of [eye(3), eye(3)]. The result is
337a09dd1c06 [project @ 1997-01-24 21:49:41 by jwe]
jwe
parents: 1993
diff changeset
117 // [-sqrt(2), -sqrt(2), -sqrt(2)].
3335
f39b97e13cf2 [project @ 1999-11-03 21:05:01 by jwe]
jwe
parents: 2847
diff changeset
118 //
f39b97e13cf2 [project @ 1999-11-03 21:05:01 by jwe]
jwe
parents: 2847
diff changeset
119 // For Lapack 3.0, this problem seems to be fixed.
2621
337a09dd1c06 [project @ 1997-01-24 21:49:41 by jwe]
jwe
parents: 1993
diff changeset
120
15887
8ced82e96b48 Fix segfaults with gesdd driver for svd (bug #37998).
Rik <rik@octave.org>
parents: 14138
diff changeset
121 jobu = jobv = 'N';
1545
8bdfa6fe5d69 [project @ 1995-10-06 06:13:28 by jwe]
jwe
parents: 1544
diff changeset
122 ncol_u = nrow_vt = 1;
1543
d6e96e0bc681 [project @ 1995-10-06 05:49:21 by jwe]
jwe
parents: 1368
diff changeset
123 break;
d6e96e0bc681 [project @ 1995-10-06 05:49:21 by jwe]
jwe
parents: 1368
diff changeset
124
d6e96e0bc681 [project @ 1995-10-06 05:49:21 by jwe]
jwe
parents: 1368
diff changeset
125 default:
d6e96e0bc681 [project @ 1995-10-06 05:49:21 by jwe]
jwe
parents: 1368
diff changeset
126 break;
537
4ecbfd3c3710 [project @ 1994-07-21 22:30:34 by jwe]
jwe
parents: 457
diff changeset
127 }
4ecbfd3c3710 [project @ 1994-07-21 22:30:34 by jwe]
jwe
parents: 457
diff changeset
128
1544
f1931fc63ce9 [project @ 1995-10-06 05:57:56 by jwe]
jwe
parents: 1543
diff changeset
129 type_computed = svd_type;
f1931fc63ce9 [project @ 1995-10-06 05:57:56 by jwe]
jwe
parents: 1543
diff changeset
130
2621
337a09dd1c06 [project @ 1997-01-24 21:49:41 by jwe]
jwe
parents: 1993
diff changeset
131 if (! (jobu == 'N' || jobu == 'O'))
1931
c91f81d5f72c [project @ 1996-02-11 23:02:16 by jwe]
jwe
parents: 1930
diff changeset
132 left_sm.resize (m, ncol_u);
1930
d20ab06301e8 [project @ 1996-02-11 22:30:18 by jwe]
jwe
parents: 1882
diff changeset
133
d20ab06301e8 [project @ 1996-02-11 22:30:18 by jwe]
jwe
parents: 1882
diff changeset
134 double *u = left_sm.fortran_vec ();
d20ab06301e8 [project @ 1996-02-11 22:30:18 by jwe]
jwe
parents: 1882
diff changeset
135
d20ab06301e8 [project @ 1996-02-11 22:30:18 by jwe]
jwe
parents: 1882
diff changeset
136 sigma.resize (nrow_s, ncol_s);
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14138
diff changeset
137 double *s_vec = sigma.fortran_vec ();
1930
d20ab06301e8 [project @ 1996-02-11 22:30:18 by jwe]
jwe
parents: 1882
diff changeset
138
2621
337a09dd1c06 [project @ 1997-01-24 21:49:41 by jwe]
jwe
parents: 1993
diff changeset
139 if (! (jobv == 'N' || jobv == 'O'))
1930
d20ab06301e8 [project @ 1996-02-11 22:30:18 by jwe]
jwe
parents: 1882
diff changeset
140 right_sm.resize (nrow_vt, n);
d20ab06301e8 [project @ 1996-02-11 22:30:18 by jwe]
jwe
parents: 1882
diff changeset
141
d20ab06301e8 [project @ 1996-02-11 22:30:18 by jwe]
jwe
parents: 1882
diff changeset
142 double *vt = right_sm.fortran_vec ();
457
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
143
15887
8ced82e96b48 Fix segfaults with gesdd driver for svd (bug #37998).
Rik <rik@octave.org>
parents: 14138
diff changeset
144 // Query DGESVD for the correct dimension of WORK.
1930
d20ab06301e8 [project @ 1996-02-11 22:30:18 by jwe]
jwe
parents: 1882
diff changeset
145
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
146 octave_idx_type lwork = -1;
3336
08ad797989f8 [project @ 1999-11-03 21:41:34 by jwe]
jwe
parents: 3335
diff changeset
147
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
148 Array<double> work (dim_vector (1, 1));
457
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
149
10258
e317791645c4 64-bit fixes
John W. Eaton <jwe@octave.org>
parents: 10185
diff changeset
150 octave_idx_type one = 1;
15887
8ced82e96b48 Fix segfaults with gesdd driver for svd (bug #37998).
Rik <rik@octave.org>
parents: 14138
diff changeset
151 octave_idx_type m1 = std::max (m, one);
8ced82e96b48 Fix segfaults with gesdd driver for svd (bug #37998).
Rik <rik@octave.org>
parents: 14138
diff changeset
152 octave_idx_type nrow_vt1 = std::max (nrow_vt, one);
10185
455759a5fcbe fix norm and svd on empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 10158
diff changeset
153
10601
3ce0c530a9c9 implement svd_driver
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
154 if (svd_driver == SVD::GESVD)
3ce0c530a9c9 implement svd_driver
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
155 {
3ce0c530a9c9 implement svd_driver
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
156 F77_XFCN (dgesvd, DGESVD, (F77_CONST_CHAR_ARG2 (&jobu, 1),
3ce0c530a9c9 implement svd_driver
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
157 F77_CONST_CHAR_ARG2 (&jobv, 1),
3ce0c530a9c9 implement svd_driver
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
158 m, n, tmp_data, m1, s_vec, u, m1, vt,
3ce0c530a9c9 implement svd_driver
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
159 nrow_vt1, work.fortran_vec (), lwork, info
3ce0c530a9c9 implement svd_driver
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
160 F77_CHAR_ARG_LEN (1)
3ce0c530a9c9 implement svd_driver
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
161 F77_CHAR_ARG_LEN (1)));
3ce0c530a9c9 implement svd_driver
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
162
3ce0c530a9c9 implement svd_driver
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
163 lwork = static_cast<octave_idx_type> (work(0));
11574
a83bad07f7e3 attempt better backward compatibility for Array resize functions
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
164 work.resize (dim_vector (lwork, 1));
10601
3ce0c530a9c9 implement svd_driver
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
165
3ce0c530a9c9 implement svd_driver
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
166 F77_XFCN (dgesvd, DGESVD, (F77_CONST_CHAR_ARG2 (&jobu, 1),
3ce0c530a9c9 implement svd_driver
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
167 F77_CONST_CHAR_ARG2 (&jobv, 1),
3ce0c530a9c9 implement svd_driver
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
168 m, n, tmp_data, m1, s_vec, u, m1, vt,
3ce0c530a9c9 implement svd_driver
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
169 nrow_vt1, work.fortran_vec (), lwork, info
3ce0c530a9c9 implement svd_driver
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
170 F77_CHAR_ARG_LEN (1)
3ce0c530a9c9 implement svd_driver
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
171 F77_CHAR_ARG_LEN (1)));
1543
d6e96e0bc681 [project @ 1995-10-06 05:49:21 by jwe]
jwe
parents: 1368
diff changeset
172
10601
3ce0c530a9c9 implement svd_driver
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
173 }
3ce0c530a9c9 implement svd_driver
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
174 else if (svd_driver == SVD::GESDD)
3ce0c530a9c9 implement svd_driver
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
175 {
3ce0c530a9c9 implement svd_driver
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
176 assert (jobu == jobv);
3ce0c530a9c9 implement svd_driver
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
177 char jobz = jobu;
3ce0c530a9c9 implement svd_driver
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
178 OCTAVE_LOCAL_BUFFER (octave_idx_type, iwork, 8*min_mn);
3ce0c530a9c9 implement svd_driver
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
179
3ce0c530a9c9 implement svd_driver
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
180 F77_XFCN (dgesdd, DGESDD, (F77_CONST_CHAR_ARG2 (&jobz, 1),
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
181 m, n, tmp_data, m1, s_vec, u, m1, vt, nrow_vt1,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
182 work.fortran_vec (), lwork, iwork, info
10601
3ce0c530a9c9 implement svd_driver
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
183 F77_CHAR_ARG_LEN (1)));
3336
08ad797989f8 [project @ 1999-11-03 21:41:34 by jwe]
jwe
parents: 3335
diff changeset
184
10601
3ce0c530a9c9 implement svd_driver
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
185 lwork = static_cast<octave_idx_type> (work(0));
11574
a83bad07f7e3 attempt better backward compatibility for Array resize functions
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
186 work.resize (dim_vector (lwork, 1));
10601
3ce0c530a9c9 implement svd_driver
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
187
3ce0c530a9c9 implement svd_driver
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
188 F77_XFCN (dgesdd, DGESDD, (F77_CONST_CHAR_ARG2 (&jobz, 1),
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
189 m, n, tmp_data, m1, s_vec, u, m1, vt, nrow_vt1,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
190 work.fortran_vec (), lwork, iwork, info
10601
3ce0c530a9c9 implement svd_driver
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
191 F77_CHAR_ARG_LEN (1)));
3ce0c530a9c9 implement svd_driver
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
192
3ce0c530a9c9 implement svd_driver
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
193 }
3ce0c530a9c9 implement svd_driver
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
194 else
3ce0c530a9c9 implement svd_driver
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
195 assert (0); // impossible
3336
08ad797989f8 [project @ 1999-11-03 21:41:34 by jwe]
jwe
parents: 3335
diff changeset
196
7482
29980c6b8604 don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
197 if (! (jobv == 'N' || jobv == 'O'))
29980c6b8604 don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
198 right_sm = right_sm.transpose ();
457
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
199
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
200 return info;
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
201 }
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
202
3504
5eef8a2294bd [project @ 2000-02-01 10:06:51 by jwe]
jwe
parents: 3503
diff changeset
203 std::ostream&
5eef8a2294bd [project @ 2000-02-01 10:06:51 by jwe]
jwe
parents: 3503
diff changeset
204 operator << (std::ostream& os, const SVD& a)
457
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
205 {
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
206 os << a.left_singular_matrix () << "\n";
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
207 os << a.singular_values () << "\n";
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
208 os << a.right_singular_matrix () << "\n";
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
209
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
210 return os;
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
211 }