annotate libinterp/dldfcn/qr.cc @ 22209:cfa684a0539d

qr.cc: make use of Texinfo macro @dots instead of ... (bug #46912)
author Carnë Draug <carandraug@octave.org>
date Fri, 05 Aug 2016 20:09:09 +0100
parents 99454a60bf5e
children 1c840b2fd337
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
19697
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 18515
diff changeset
3 Copyright (C) 1996-2015 John W. Eaton
11523
fd0a3ac60b0e update copyright notices
John W. Eaton <jwe@octave.org>
parents: 10846
diff changeset
4 Copyright (C) 2008-2009 Jaroslav Hajek
fd0a3ac60b0e update copyright notices
John W. Eaton <jwe@octave.org>
parents: 10846
diff changeset
5 Copyright (C) 2008-2009 VZLU Prague
2928
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 This file is part of Octave.
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
8
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
9 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
10 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: 6484
diff changeset
11 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6484
diff changeset
12 option) any later version.
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
13
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
14 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
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
16 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
17 for more details.
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
18
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
19 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: 6484
diff changeset
20 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6484
diff changeset
21 <http://www.gnu.org/licenses/>.
2928
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 */
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
24
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21580
diff changeset
25 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21280
diff changeset
26 # include "config.h"
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
27 #endif
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
28
21279
eb1524b07fe3 better use of templates for qr classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
29 #include "qr.h"
21280
ebdf74c15722 better use of templates for qrp classes
John W. Eaton <jwe@octave.org>
parents: 21279
diff changeset
30 #include "qrp.h"
21176
791dcb32b657 revamp sparse QR factorizatino classes
John W. Eaton <jwe@octave.org>
parents: 21139
diff changeset
31 #include "sparse-qr.h"
7505
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7491
diff changeset
32
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
33 #include "defun-dld.h"
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
34 #include "error.h"
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21041
diff changeset
35 #include "errwarn.h"
20940
48b2ad5ee801 maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents: 20939
diff changeset
36 #include "ovl.h"
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
37 #include "utils.h"
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
38
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21100
diff changeset
39 template <typename MT>
8869
c3b743b1b1c6 preset triangular type if possible for lu and qr outputs
Jaroslav Hajek <highegg@gmail.com>
parents: 8811
diff changeset
40 static octave_value
21279
eb1524b07fe3 better use of templates for qr classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
41 get_qr_r (const qr<MT>& fact)
8869
c3b743b1b1c6 preset triangular type if possible for lu and qr outputs
Jaroslav Hajek <highegg@gmail.com>
parents: 8811
diff changeset
42 {
9715
9f27172fbd1e auto-set MatrixType from certain functions
Jaroslav Hajek <highegg@gmail.com>
parents: 9209
diff changeset
43 MT R = fact.R ();
9f27172fbd1e auto-set MatrixType from certain functions
Jaroslav Hajek <highegg@gmail.com>
parents: 9209
diff changeset
44 if (R.is_square () && fact.regular ())
9f27172fbd1e auto-set MatrixType from certain functions
Jaroslav Hajek <highegg@gmail.com>
parents: 9209
diff changeset
45 return octave_value (R, MatrixType (MatrixType::Upper));
8869
c3b743b1b1c6 preset triangular type if possible for lu and qr outputs
Jaroslav Hajek <highegg@gmail.com>
parents: 8811
diff changeset
46 else
9715
9f27172fbd1e auto-set MatrixType from certain functions
Jaroslav Hajek <highegg@gmail.com>
parents: 9209
diff changeset
47 return R;
8869
c3b743b1b1c6 preset triangular type if possible for lu and qr outputs
Jaroslav Hajek <highegg@gmail.com>
parents: 8811
diff changeset
48 }
c3b743b1b1c6 preset triangular type if possible for lu and qr outputs
Jaroslav Hajek <highegg@gmail.com>
parents: 8811
diff changeset
49
21279
eb1524b07fe3 better use of templates for qr classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
50 template <typename T>
eb1524b07fe3 better use of templates for qr classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
51 static typename qr<T>::type
eb1524b07fe3 better use of templates for qr classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
52 qr_type (int nargin, int nargout)
eb1524b07fe3 better use of templates for qr classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
53 {
eb1524b07fe3 better use of templates for qr classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
54 return ((nargout == 0 || nargout == 1)
eb1524b07fe3 better use of templates for qr classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
55 ? qr<T>::raw
eb1524b07fe3 better use of templates for qr classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
56 : (nargin == 2) ? qr<T>::economy : qr<T>::std);
eb1524b07fe3 better use of templates for qr classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
57 }
eb1524b07fe3 better use of templates for qr classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
58
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3069
diff changeset
59 // [Q, R] = qr (X): form Q unitary and R upper triangular such
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3069
diff changeset
60 // that Q * R = X
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3069
diff changeset
61 //
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3069
diff changeset
62 // [Q, R] = qr (X, 0): form the economy decomposition such that if X is
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3069
diff changeset
63 // m by n then only the first n columns of Q are
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3069
diff changeset
64 // computed.
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3069
diff changeset
65 //
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3069
diff changeset
66 // [Q, R, P] = qr (X): form QRP factorization of X where
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3069
diff changeset
67 // P is a permutation matrix such that
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3069
diff changeset
68 // A * P = Q * R
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3069
diff changeset
69 //
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3069
diff changeset
70 // [Q, R, P] = qr (X, 0): form the economy decomposition with
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3069
diff changeset
71 // permutation vector P such that Q * R = X (:, P)
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3069
diff changeset
72 //
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3069
diff changeset
73 // qr (X) alone returns the output of the LAPACK routine dgeqrf, such
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3069
diff changeset
74 // that R = triu (qr (X))
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3069
diff changeset
75
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
76 DEFUN_DLD (qr, args, nargout,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
77 doc: /* -*- texinfo -*-
22207
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
78 @deftypefn {} {[@var{Q}, @var{R}] =} qr (@var{A})
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
79 @deftypefnx {} {[@var{Q}, @var{R}, @var{P}] =} qr (@var{A}) # non-sparse A
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
80 @deftypefnx {} {@var{X} =} qr (@var{A})
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
81 @deftypefnx {} {@var{R} =} qr (@var{A}) # sparse A
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
82 @deftypefnx {} {[@var{C}, @var{R}] =} qr (@var{A}, @var{B})
22209
cfa684a0539d qr.cc: make use of Texinfo macro @dots instead of ... (bug #46912)
Carnë Draug <carandraug@octave.org>
parents: 22207
diff changeset
83 @deftypefnx {} {[@dots{}] =} qr (@dots{}, 0)
cfa684a0539d qr.cc: make use of Texinfo macro @dots instead of ... (bug #46912)
Carnë Draug <carandraug@octave.org>
parents: 22207
diff changeset
84 @deftypefnx {} {[@dots{}] =} qr (@dots{}, 'vector')
cfa684a0539d qr.cc: make use of Texinfo macro @dots instead of ... (bug #46912)
Carnë Draug <carandraug@octave.org>
parents: 22207
diff changeset
85 @deftypefnx {} {[@dots{}] =} qr (@dots{}, 'matrix')
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
86 @cindex QR factorization
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
87 Compute the QR@tie{}factorization of @var{A}, using standard @sc{lapack}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
88 subroutines.
22207
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
89 The QR@tie{}factorization is
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
90 @tex
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
91 $QR = A$ where $Q$ is an orthogonal matrix and $R$ is upper triangular.
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
92 @end tex
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
93 @ifnottex
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
94 @code{@var{Q} * @var{R} = @var{A}} where @var{Q} is an orthogonal matrix and
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
95 @var{R} is upper triangular.
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
96 @end ifnottex
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
97
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
98 For example, given the matrix @code{@var{A} = [1, 2; 3, 4]},
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
99
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
100 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
101 [@var{Q}, @var{R}] = qr (@var{A})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
102 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
103
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
104 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
105 returns
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
106
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
107 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
108 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
109 @var{Q} =
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
110
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
111 -0.31623 -0.94868
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
112 -0.94868 0.31623
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
113
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
114 @var{R} =
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
115
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
116 -3.16228 -4.42719
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
117 0.00000 -0.63246
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
118 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
119 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
120
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
121 The @code{qr} factorization has applications in the solution of least
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
122 squares problems
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
123 @tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
124 $$
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
125 \min_x \left\Vert A x - b \right\Vert_2
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
126 $$
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
127 @end tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
128 @ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
129
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
130 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
131 min norm(A x - b)
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
132 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
133
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
134 @end ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
135 for overdetermined systems of equations (i.e.,
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
136 @tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
137 $A$
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
138 @end tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
139 @ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
140 @var{A}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
141 @end ifnottex
22207
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
142 is a tall, thin matrix).
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
143
22207
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
144 If only a single return value is requested, then it is either @var{R} if
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
145 @var{A} is sparse, or @var{X} such that @code{@var{R} = triu (@var{X})} if
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
146 @var{A} is full.
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
147 (Note: Unlike most commands, the single return value is not
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
148 the first return value when multiple are requested.)
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
149
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
150
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
151 If the matrix @var{A} is full, the permuted QR@tie{}factorization
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
152 @code{[@var{Q}, @var{R}, @var{P}] = qr (@var{A})} forms the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
153 QR@tie{}factorization such that the diagonal entries of @var{R} are
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
154 decreasing in magnitude order. For example, given the matrix
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
155 @code{a = [1, 2; 3, 4]},
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
156
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
157 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
158 [@var{Q}, @var{R}, @var{P}] = qr (@var{A})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
159 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
160
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
161 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
162 returns
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
163
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
164 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
165 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
166 @var{Q} =
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
167
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
168 -0.44721 -0.89443
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
169 -0.89443 0.44721
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
170
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
171 @var{R} =
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
172
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
173 -4.47214 -3.13050
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
174 0.00000 0.44721
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
175
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
176 @var{P} =
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
177
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
178 0 1
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
179 1 0
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
180 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
181 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
182
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
183 The permuted @code{qr} factorization
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
184 @code{[@var{Q}, @var{R}, @var{P}] = qr (@var{A})} factorization allows the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
185 construction of an orthogonal basis of @code{span (A)}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
186
22207
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
187 If the matrix @var{A} is sparse, then the sparse QR@tie{}factorization
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
188 of @var{A} is computed using @sc{CSparse}.
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
189 As the matrix @var{Q} is in general a full matrix,
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
190 it is recommended to request only one return value,
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
191 which is the @var{Q}-less factorization @var{R} of @var{A}, such that
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
192 @code{@var{R} = chol (@var{A}' * @var{A})}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
193
22207
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
194 If an additional matrix @var{B} is supplied and two return values are
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
195 requested, then @code{qr} returns
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
196 @var{C}, where @code{@var{C} = @var{Q}' * @var{B}}. This allows the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
197 least squares approximation of @code{@var{A} \ @var{B}} to be calculated
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
198 as
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
199
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
200 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
201 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
202 [@var{C}, @var{R}] = qr (@var{A}, @var{B})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
203 x = @var{R} \ @var{C}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
204 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
205 @end example
22207
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
206
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
207 If the final argument is the scalar 0 and the number of rows is larger
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
208 than the number of columns, then an 'economy' factorization is returned,
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
209 omitting zeroes of @var{R} and the corresponding columns of @var{Q}.
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
210 That is, @var{R} will have only @code{size (@var{A},1)} rows.
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
211 In this case, @var{P} is a vector rather than a matrix.
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
212
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
213 If the final argument is the string 'vector' then @var{P} is a permutation
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
214 vector instead of a permutation matrix.
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
215
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
216 @seealso{chol, hess, lu, qz, schur, svd, qrupdate, qrinsert, qrdelete, qrshift}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
217 @end deftypefn */)
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
218 {
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
219 int nargin = args.length ();
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
220
22207
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
221 if (nargin < 1 || nargin > 3)
20790
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20678
diff changeset
222 print_usage ();
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
223
20898
8da80da1ac37 maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents: 20859
diff changeset
224 octave_value_list retval;
8da80da1ac37 maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents: 20859
diff changeset
225
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
226 octave_value arg = args(0);
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
227
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
228 int arg_is_empty = empty_arg ("qr", arg.rows (), arg.columns ());
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
229
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
230 if (arg_is_empty < 0)
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
231 return retval;
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
232
22206
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
233 bool economy = false;
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
234 bool is_cmplx = false;
22207
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
235 bool have_b = 0;
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
236 bool vector_p = 0;
22206
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
237
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
238 if (arg.is_complex_type ())
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
239 is_cmplx = true;
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
240 if (nargin > 1)
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
241 {
22207
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
242 have_b = true;
22206
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
243 if (args(nargin-1).is_scalar_type ())
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
244 {
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
245 int val = args(nargin-1).int_value ();
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
246 if (val == 0)
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
247 {
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
248 economy = true;
22207
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
249 have_b = (nargin > 2);
22206
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
250 }
22207
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
251 else if (nargin == 3) // argument 3 should be 0 or a string
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
252 print_usage ();
22206
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
253 }
22207
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
254 else if (args(nargin-1).is_string ())
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
255 {
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
256 if (args(nargin-1).string_value () == "vector")
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
257 vector_p = true;
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
258 else if (args(nargin-1).string_value () != "matrix")
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
259 error ("qr: type for P must be 'matrix' or 'vector', not %s",
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
260 args(nargin-1).string_value ().c_str ());
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
261 have_b = (nargin > 2);
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
262 }
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
263 else if (! args(nargin-1).is_matrix_type ())
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
264 err_wrong_type_arg ("qr", args(nargin-1));
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
265 else if (nargin == 3) // should be caught by is_scalar_type or is_string
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
266 print_usage ();
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
267
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
268 if (have_b && args(1).is_complex_type ())
22206
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
269 is_cmplx = true;
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
270 }
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
271
7505
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7491
diff changeset
272 if (arg.is_sparse_type ())
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
273 {
22207
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
274 if (nargout > 2)
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
275 error ("qr: Permutation output is not supported for sparse input");
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
276
20909
03e4ddd49396 omit unnecessary nargout checks
John W. Eaton <jwe@octave.org>
parents: 20898
diff changeset
277 if (is_cmplx)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
278 {
21176
791dcb32b657 revamp sparse QR factorizatino classes
John W. Eaton <jwe@octave.org>
parents: 21139
diff changeset
279 sparse_qr<SparseComplexMatrix> q (arg.sparse_complex_matrix_value ());
20678
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
280
22207
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
281 if (have_b)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
282 {
22207
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
283 retval = ovl (q.C (args(1).complex_matrix_value ()),
20859
1f4d6b1f50c1 2015 Code Sprint: qr.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
284 q.R (economy));
20678
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
285 if (arg.rows () < arg.columns ())
22207
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
286 warning ("qr: non minimum norm solution for under-determined "
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
287 "problem %dx%d", arg.rows (), arg.columns ());
20678
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
288 }
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
289 else if (nargout > 1)
20909
03e4ddd49396 omit unnecessary nargout checks
John W. Eaton <jwe@octave.org>
parents: 20898
diff changeset
290 retval = ovl (q.Q (), q.R (economy));
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
291 else
20859
1f4d6b1f50c1 2015 Code Sprint: qr.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
292 retval = ovl (q.R (economy));
20678
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
293 }
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
294 else
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
295 {
21176
791dcb32b657 revamp sparse QR factorizatino classes
John W. Eaton <jwe@octave.org>
parents: 21139
diff changeset
296 sparse_qr<SparseMatrix> q (arg.sparse_matrix_value ());
20678
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
297
22207
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
298 if (have_b)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
299 {
22207
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
300 retval = ovl (q.C (args(1).matrix_value ()), q.R (economy));
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
301 if (arg.rows () < arg.columns ())
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
302 warning ("qr: non minimum norm solution for under-determined "
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
303 "problem %dx%d", arg.rows (), arg.columns ());
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
304 }
20678
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
305 else if (nargout > 1)
20909
03e4ddd49396 omit unnecessary nargout checks
John W. Eaton <jwe@octave.org>
parents: 20898
diff changeset
306 retval = ovl (q.Q (), q.R (economy));
20678
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
307 else
20859
1f4d6b1f50c1 2015 Code Sprint: qr.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
308 retval = ovl (q.R (economy));
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
309 }
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
310 }
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
311 else
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
312 {
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7700
diff changeset
313 if (arg.is_single_type ())
10154
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 if (arg.is_real_type ())
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
316 {
21279
eb1524b07fe3 better use of templates for qr classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
317 qr<FloatMatrix>::type type
eb1524b07fe3 better use of templates for qr classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
318 = qr_type<FloatMatrix> (nargin, nargout);
eb1524b07fe3 better use of templates for qr classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
319
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
320 FloatMatrix m = arg.float_matrix_value ();
7505
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7491
diff changeset
321
20678
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
322 switch (nargout)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
323 {
20678
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
324 case 0:
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
325 case 1:
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
326 {
21279
eb1524b07fe3 better use of templates for qr classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
327 qr<FloatMatrix> fact (m, type);
20859
1f4d6b1f50c1 2015 Code Sprint: qr.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
328 retval = ovl (fact.R ());
20678
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
329 }
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
330 break;
7505
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7491
diff changeset
331
20678
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
332 case 2:
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
333 {
21279
eb1524b07fe3 better use of templates for qr classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
334 qr<FloatMatrix> fact (m, type);
20859
1f4d6b1f50c1 2015 Code Sprint: qr.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
335 retval = ovl (fact.Q (), get_qr_r (fact));
22207
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
336 if (have_b)
22206
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
337 {
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
338 if (is_cmplx)
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
339 retval(0) = fact.Q ().transpose ()
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
340 * args(1).float_complex_matrix_value ();
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
341 else
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
342 retval(0) = fact.Q ().transpose ()
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
343 * args(1).float_matrix_value ();
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
344 }
20678
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
345 }
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
346 break;
7505
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7491
diff changeset
347
20678
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
348 default:
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
349 {
21280
ebdf74c15722 better use of templates for qrp classes
John W. Eaton <jwe@octave.org>
parents: 21279
diff changeset
350 qrp<FloatMatrix> fact (m, type);
20898
8da80da1ac37 maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents: 20859
diff changeset
351
22207
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
352 if (type == qr<FloatMatrix>::economy || vector_p)
20898
8da80da1ac37 maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents: 20859
diff changeset
353 retval = ovl (fact.Q (), get_qr_r (fact), fact.Pvec ());
20678
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
354 else
20898
8da80da1ac37 maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents: 20859
diff changeset
355 retval = ovl (fact.Q (), get_qr_r (fact), fact.P ());
20678
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
356 }
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
357 break;
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
358 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
359 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
360 else if (arg.is_complex_type ())
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
361 {
21279
eb1524b07fe3 better use of templates for qr classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
362 qr<FloatComplexMatrix>::type type
eb1524b07fe3 better use of templates for qr classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
363 = qr_type<FloatComplexMatrix> (nargin, nargout);
eb1524b07fe3 better use of templates for qr classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
364
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
365 FloatComplexMatrix m = arg.float_complex_matrix_value ();
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7700
diff changeset
366
20678
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
367 switch (nargout)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
368 {
20678
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
369 case 0:
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
370 case 1:
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
371 {
21279
eb1524b07fe3 better use of templates for qr classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
372 qr<FloatComplexMatrix> fact (m, type);
20859
1f4d6b1f50c1 2015 Code Sprint: qr.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
373 retval = ovl (fact.R ());
20678
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
374 }
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
375 break;
7505
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7491
diff changeset
376
20678
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
377 case 2:
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
378 {
21279
eb1524b07fe3 better use of templates for qr classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
379 qr<FloatComplexMatrix> fact (m, type);
20859
1f4d6b1f50c1 2015 Code Sprint: qr.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
380 retval = ovl (fact.Q (), get_qr_r (fact));
22207
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
381 if (have_b)
22206
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
382 retval (0) = conj (fact.Q ().transpose ())
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
383 * args(1).float_complex_matrix_value ();
20678
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
384 }
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
385 break;
7505
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7491
diff changeset
386
20678
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
387 default:
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
388 {
21280
ebdf74c15722 better use of templates for qrp classes
John W. Eaton <jwe@octave.org>
parents: 21279
diff changeset
389 qrp<FloatComplexMatrix> fact (m, type);
22207
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
390 if (type == qr<FloatComplexMatrix>::economy || vector_p)
20898
8da80da1ac37 maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents: 20859
diff changeset
391 retval = ovl (fact.Q (), get_qr_r (fact), fact.Pvec ());
20678
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
392 else
20898
8da80da1ac37 maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents: 20859
diff changeset
393 retval = ovl (fact.Q (), get_qr_r (fact), fact.P ());
20678
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
394 }
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
395 break;
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
396 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
397 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
398 }
7505
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7491
diff changeset
399 else
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
400 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
401 if (arg.is_real_type ())
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
402 {
21279
eb1524b07fe3 better use of templates for qr classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
403 qr<Matrix>::type type = qr_type<Matrix> (nargin, nargout);
eb1524b07fe3 better use of templates for qr classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
404
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
405 Matrix m = arg.matrix_value ();
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7700
diff changeset
406
20678
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
407 switch (nargout)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
408 {
20678
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
409 case 0:
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
410 case 1:
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
411 {
21279
eb1524b07fe3 better use of templates for qr classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
412 qr<Matrix> fact (m, type);
20859
1f4d6b1f50c1 2015 Code Sprint: qr.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
413 retval = ovl (fact.R ());
20678
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
414 }
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
415 break;
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7700
diff changeset
416
20678
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
417 case 2:
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
418 {
21279
eb1524b07fe3 better use of templates for qr classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
419 qr<Matrix> fact (m, type);
20859
1f4d6b1f50c1 2015 Code Sprint: qr.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
420 retval = ovl (fact.Q (), get_qr_r (fact));
22207
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
421 if (have_b)
22206
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
422 {
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
423 if (is_cmplx)
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
424 retval(0) = fact.Q ().transpose ()
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
425 * args(1).complex_matrix_value ();
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
426 else
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
427 retval(0) = fact.Q ().transpose ()
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
428 * args(1).matrix_value ();
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
429 }
20678
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
430 }
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
431 break;
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7700
diff changeset
432
20678
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
433 default:
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
434 {
21280
ebdf74c15722 better use of templates for qrp classes
John W. Eaton <jwe@octave.org>
parents: 21279
diff changeset
435 qrp<Matrix> fact (m, type);
22207
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
436 if (type == qr<Matrix>::economy || vector_p)
20898
8da80da1ac37 maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents: 20859
diff changeset
437 retval = ovl (fact.Q (), get_qr_r (fact), fact.Pvec ());
20678
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
438 else
20898
8da80da1ac37 maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents: 20859
diff changeset
439 retval = ovl (fact.Q (), get_qr_r (fact), fact.P ());
20678
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
440 }
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
441 break;
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
442 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
443 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
444 else if (arg.is_complex_type ())
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
445 {
21279
eb1524b07fe3 better use of templates for qr classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
446 qr<ComplexMatrix>::type type
eb1524b07fe3 better use of templates for qr classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
447 = qr_type<ComplexMatrix> (nargin, nargout);
eb1524b07fe3 better use of templates for qr classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
448
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
449 ComplexMatrix m = arg.complex_matrix_value ();
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7700
diff changeset
450
20678
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
451 switch (nargout)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
452 {
20678
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
453 case 0:
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
454 case 1:
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
455 {
21279
eb1524b07fe3 better use of templates for qr classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
456 qr<ComplexMatrix> fact (m, type);
20859
1f4d6b1f50c1 2015 Code Sprint: qr.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
457 retval = ovl (fact.R ());
20678
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
458 }
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
459 break;
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7700
diff changeset
460
20678
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
461 case 2:
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
462 {
21279
eb1524b07fe3 better use of templates for qr classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
463 qr<ComplexMatrix> fact (m, type);
20859
1f4d6b1f50c1 2015 Code Sprint: qr.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
464 retval = ovl (fact.Q (), get_qr_r (fact));
22207
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
465 if (have_b)
22206
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
466 retval (0) = conj (fact.Q ().transpose ())
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
467 * args(1).complex_matrix_value ();
20678
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
468 }
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
469 break;
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7700
diff changeset
470
20678
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
471 default:
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
472 {
21280
ebdf74c15722 better use of templates for qrp classes
John W. Eaton <jwe@octave.org>
parents: 21279
diff changeset
473 qrp<ComplexMatrix> fact (m, type);
22207
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
474 if (type == qr<ComplexMatrix>::economy || vector_p)
20898
8da80da1ac37 maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents: 20859
diff changeset
475 retval = ovl (fact.Q (), get_qr_r (fact), fact.Pvec ());
20678
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
476 else
20898
8da80da1ac37 maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents: 20859
diff changeset
477 retval = ovl (fact.Q (), get_qr_r (fact), fact.P ());
20678
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
478 }
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
479 break;
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
480 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
481 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
482 else
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21041
diff changeset
483 err_wrong_type_arg ("qr", arg);
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
484 }
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
485 }
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
486
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
487 return retval;
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
488 }
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
489
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
490 /*
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
491 %!test
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
492 %! a = [0, 2, 1; 2, 1, 2];
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
493 %!
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
494 %! [q, r] = qr (a);
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
495 %! [qe, re] = qr (a, 0);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
496 %!
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
497 %! assert (q * r, 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
498 %! assert (qe * re, 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
499
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
500 %!test
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
501 %! a = [0, 2, 1; 2, 1, 2];
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
502 %!
22206
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
503 %! [q, r] = qr (a);
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
504 %! [qe, re] = qr (a, 0);
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
505 %!
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
506 %! assert (q * r, a, sqrt (eps));
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
507 %! assert (qe * re, a, sqrt (eps));
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
508
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
509 %!test
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
510 %! a = [0, 2, 1; 2, 1, 2];
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
511 %!
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
512 %! [q, r, p] = qr (a); # FIXME: not giving right dimensions.
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
513 %! [qe, re, pe] = qr (a, 0);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
514 %!
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
515 %! assert (q * r, a * p, sqrt (eps));
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
516 %! assert (qe * re, a(:, pe), sqrt (eps));
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
517
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
518 %!test
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
519 %! a = [0, 2; 2, 1; 1, 2];
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
520 %!
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
521 %! [q, r] = qr (a);
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
522 %! [qe, re] = qr (a, 0);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
523 %!
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
524 %! assert (q * r, 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
525 %! assert (qe * re, 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
526
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
527 %!test
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
528 %! a = [0, 2; 2, 1; 1, 2];
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
529 %!
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
530 %! [q, r, p] = qr (a);
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
531 %! [qe, re, pe] = qr (a, 0);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
532 %!
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
533 %! assert (q * r, a * p, sqrt (eps));
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
534 %! assert (qe * re, a(:, pe), sqrt (eps));
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
535
22206
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
536 %!test
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
537 %! a = [0, 2, 1; 2, 1, 2; 3, 1, 2];
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
538 %! b = [1, 3, 2; 1, 1, 0; 3, 0, 2];
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
539 %!
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
540 %! [q, r] = qr (a);
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
541 %! [c, re] = qr (a, b);
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
542 %!
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
543 %! assert (r, re, sqrt (eps));
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
544 %! assert (q'*b, c, sqrt (eps));
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
545
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
546 %!test
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
547 %! a = [0, 2, i; 2, 1, 2; 3, 1, 2];
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
548 %! b = [1, 3, 2; 1, i, 0; 3, 0, 2];
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
549 %!
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
550 %! [q, r] = qr (a);
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
551 %! [c, re] = qr (a, b);
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
552 %!
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
553 %! assert (r, re, sqrt (eps));
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
554 %! assert (q'*b, c, sqrt (eps));
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
555
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
556 %!test
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
557 %! a = [0, 2, i; 2, 1, 2; 3, 1, 2];
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
558 %! b = [1, 3, 2; 1, 1, 0; 3, 0, 2];
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
559 %!
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
560 %! [q, r] = qr (a);
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
561 %! [c, re] = qr (a, b);
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
562 %!
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
563 %! assert (r, re, sqrt (eps));
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
564 %! assert (q'*b, c, sqrt (eps));
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
565
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
566 %!test
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
567 %! a = [0, 2, 1; 2, 1, 2; 3, 1, 2];
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
568 %! b = [1, 3, 2; 1, i, 0; 3, 0, 2];
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
569 %!
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
570 %! [q, r] = qr (a);
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
571 %! [c, re] = qr (a, b);
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
572 %!
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
573 %! assert (r, re, sqrt (eps));
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
574 %! assert (q'*b, c, sqrt (eps));
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
575
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
576 %!error qr ()
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
577 %!error qr ([1, 2; 3, 4], 0, 2)
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
578
14085
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 13971
diff changeset
579 %!function retval = __testqr (q, r, a, p)
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
580 %! tol = 100*eps (class (q));
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
581 %! retval = 0;
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
582 %! if (nargin == 3)
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
583 %! n1 = norm (q*r - a);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
584 %! n2 = norm (q'*q - eye (columns (q)));
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
585 %! retval = (n1 < tol && n2 < tol);
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
586 %! else
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
587 %! n1 = norm (q'*q - eye (columns (q)));
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
588 %! retval = (n1 < tol);
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
589 %! if (isvector (p))
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
590 %! n2 = norm (q*r - a(:,p));
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
591 %! retval = (retval && n2 < tol);
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
592 %! else
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
593 %! n2 = norm (q*r - a*p);
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
594 %! retval = (retval && n2 < tol);
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
595 %! endif
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
596 %! endif
14085
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 13971
diff changeset
597 %!endfunction
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 13971
diff changeset
598
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
599 %!test
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
600 %! t = ones (24, 1);
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
601 %! j = 1;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
602 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
603 %! if (false) # eliminate big matrix tests
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
604 %! a = rand (5000, 20);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
605 %! [q,r] = qr (a, 0); t(j++) = __testqr (q, r, a);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
606 %! [q,r] = qr (a',0); t(j++) = __testqr (q, r, a');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
607 %! [q,r,p] = qr (a, 0); t(j++) = __testqr (q, r, a, p);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
608 %! [q,r,p] = qr (a',0); t(j++) = __testqr (q, r, a', p);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
609 %!
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
610 %! a = a+1i*eps;
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
611 %! [q,r] = qr (a, 0); t(j++) = __testqr (q, r, a);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
612 %! [q,r] = qr (a',0); t(j++) = __testqr (q, r, a');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
613 %! [q,r,p] = qr (a, 0); t(j++) = __testqr (q, r, a, p);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
614 %! [q,r,p] = qr (a',0); t(j++) = __testqr (q, r, a', p);
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
615 %! endif
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
616 %!
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
617 %! a = [ ones(1,15); sqrt(eps)*eye(15) ];
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
618 %! [q,r] = qr (a); t(j++) = __testqr (q, r, a);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
619 %! [q,r] = qr (a'); t(j++) = __testqr (q, r, a');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
620 %! [q,r,p] = qr (a); t(j++) = __testqr (q, r, a, p);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
621 %! [q,r,p] = qr (a'); t(j++) = __testqr (q, r, a', p);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
622 %!
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
623 %! a = a+1i*eps;
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
624 %! [q,r] = qr (a); t(j++) = __testqr (q, r, a);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
625 %! [q,r] = qr (a'); t(j++) = __testqr (q, r, a');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
626 %! [q,r,p] = qr (a); t(j++) = __testqr (q, r, a, p);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
627 %! [q,r,p] = qr (a'); t(j++) = __testqr (q, r, a', p);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
628 %!
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
629 %! a = [ ones(1,15); sqrt(eps)*eye(15) ];
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
630 %! [q,r] = qr (a, 0); t(j++) = __testqr (q, r, a);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
631 %! [q,r] = qr (a',0); t(j++) = __testqr (q, r, a');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
632 %! [q,r,p] = qr (a, 0); t(j++) = __testqr (q, r, a, p);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
633 %! [q,r,p] = qr (a',0); t(j++) = __testqr (q, r, a', p);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
634 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
635 %! a = a+1i*eps;
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
636 %! [q,r] = qr (a, 0); t(j++) = __testqr (q, r, a);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
637 %! [q,r] = qr (a',0); t(j++) = __testqr (q, r, a');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
638 %! [q,r,p] = qr (a, 0); t(j++) = __testqr (q, r, a, p);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
639 %! [q,r,p] = qr (a',0); t(j++) = __testqr (q, r, a', p);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
640 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
641 %! a = [ 611 196 -192 407 -8 -52 -49 29
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
642 %! 196 899 113 -192 -71 -43 -8 -44
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
643 %! -192 113 899 196 61 49 8 52
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
644 %! 407 -192 196 611 8 44 59 -23
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
645 %! -8 -71 61 8 411 -599 208 208
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
646 %! -52 -43 49 44 -599 411 208 208
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
647 %! -49 -8 8 59 208 208 99 -911
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
648 %! 29 -44 52 -23 208 208 -911 99 ];
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
649 %! [q,r] = qr (a);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
650 %!
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
651 %! assert (all (t) && norm (q*r - a) < 5000*eps);
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
652
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
653 %!test
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
654 %! a = single ([0, 2, 1; 2, 1, 2]);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
655 %!
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
656 %! [q, r] = qr (a);
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
657 %! [qe, re] = qr (a, 0);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
658 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
659 %! assert (q * r, a, sqrt (eps ("single")));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
660 %! assert (qe * re, 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
661
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
662 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
663 %! a = single ([0, 2, 1; 2, 1, 2]);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
664 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
665 %! [q, r, p] = qr (a); # FIXME: not giving right dimensions.
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
666 %! [qe, re, pe] = qr (a, 0);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
667 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
668 %! assert (q * r, a * p, sqrt (eps ("single")));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
669 %! assert (qe * re, a(:, pe), 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
670
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
671 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
672 %! a = single ([0, 2; 2, 1; 1, 2]);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
673 %!
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
674 %! [q, r] = qr (a);
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
675 %! [qe, re] = qr (a, 0);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
676 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
677 %! assert (q * r, a, sqrt (eps ("single")));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
678 %! assert (qe * re, 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
679
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
680 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
681 %! a = single ([0, 2; 2, 1; 1, 2]);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
682 %!
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
683 %! [q, r, p] = qr (a);
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
684 %! [qe, re, pe] = qr (a, 0);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
685 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
686 %! assert (q * r, a * p, sqrt (eps ("single")));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
687 %! assert (qe * re, a(:, pe), 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
688
22206
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
689 %!test
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
690 %! a = single([0, 2, 1; 2, 1, 2; 3, 1, 2]);
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
691 %! b = single([1, 3, 2; 1, 1, 0; 3, 0, 2]);
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
692 %!
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
693 %! [q, r] = qr (a);
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
694 %! [c, re] = qr (a, b);
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
695 %!
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
696 %! assert (r, re, sqrt (eps ("single")));
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
697 %! assert (q'*b, c, sqrt (eps ("single")));
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
698
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
699 %!test
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
700 %! a = single([0, 2, i; 2, 1, 2; 3, 1, 2]);
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
701 %! b = single([1, 3, 2; 1, i, 0; 3, 0, 2]);
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
702 %!
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
703 %! [q, r] = qr (a);
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
704 %! [c, re] = qr (a, b);
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
705 %!
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
706 %! assert (r, re, sqrt (eps ("single")));
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
707 %! assert (q'*b, c, sqrt (eps ("single")));
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
708
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
709 %!test
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
710 %! a = single([0, 2, i; 2, 1, 2; 3, 1, 2]);
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
711 %! b = single([1, 3, 2; 1, 1, 0; 3, 0, 2]);
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
712 %!
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
713 %! [q, r] = qr (a);
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
714 %! [c, re] = qr (a, b);
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
715 %!
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
716 %! assert (r, re, sqrt (eps));
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
717 %! assert (q'*b, c, sqrt (eps));
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
718
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
719 %!test
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
720 %! a = single([0, 2, 1; 2, 1, 2; 3, 1, 2]);
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
721 %! b = single([1, 3, 2; 1, i, 0; 3, 0, 2]);
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
722 %!
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
723 %! [q, r] = qr (a);
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
724 %! [c, re] = qr (a, b);
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
725 %!
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
726 %! assert (r, re, sqrt (eps ("single")));
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
727 %! assert (q'*b, c, sqrt (eps ("single")));
21684fa513ce Return C = Q'*B not Q when qr has two arguments (bug #41567, bug #46912)
mfasi <mogrob.sanit@gmail.com>
parents: 22022
diff changeset
728
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
729 %!error qr ()
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
730 %!error qr ([1, 2; 3, 4], 0, 2)
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
731
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
732 %!test
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
733 %! t = ones (24, 1);
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
734 %! j = 1;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
735 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
736 %! if (false) # eliminate big matrix tests
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
737 %! a = rand (5000,20);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
738 %! [q,r] = qr (a, 0); t(j++) = __testqr (q, r, a);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
739 %! [q,r] = qr (a',0); t(j++) = __testqr (q, r, a');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
740 %! [q,r,p] = qr (a, 0); t(j++) = __testqr (q, r, a, p);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
741 %! [q,r,p] = qr (a',0); t(j++) = __testqr (q, r, a', p);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
742 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
743 %! a = a+1i*eps ("single");
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
744 %! [q,r] = qr (a, 0); t(j++) = __testqr (q, r, a);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
745 %! [q,r] = qr (a',0); t(j++) = __testqr (q, r, a');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
746 %! [q,r,p] = qr (a, 0); t(j++) = __testqr (q, r, a, p);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
747 %! [q,r,p] = qr (a',0); t(j++) = __testqr (q, r, a', p);
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
748 %! endif
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
749 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
750 %! a = [ ones(1,15); sqrt(eps("single"))*eye(15) ];
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
751 %! [q,r] = qr (a); t(j++) = __testqr (q, r, a);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
752 %! [q,r] = qr (a'); t(j++) = __testqr (q, r, a');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
753 %! [q,r,p] = qr (a); t(j++) = __testqr (q, r, a, p);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
754 %! [q,r,p] = qr (a'); t(j++) = __testqr (q, r, a', p);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
755 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
756 %! a = a+1i*eps ("single");
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
757 %! [q,r] = qr (a); t(j++) = __testqr (q, r, a);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
758 %! [q,r] = qr (a'); t(j++) = __testqr (q, r, a');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
759 %! [q,r,p] = qr (a); t(j++) = __testqr (q, r, a, p);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
760 %! [q,r,p] = qr (a'); t(j++) = __testqr (q, r, a', p);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
761 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
762 %! a = [ ones(1,15); sqrt(eps("single"))*eye(15) ];
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
763 %! [q,r] = qr (a, 0); t(j++) = __testqr (q, r, a);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
764 %! [q,r] = qr (a',0); t(j++) = __testqr (q, r, a');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
765 %! [q,r,p] = qr (a, 0); t(j++) = __testqr (q, r, a, p);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
766 %! [q,r,p] = qr (a',0); t(j++) = __testqr (q, r, a', p);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
767 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
768 %! a = a+1i*eps ("single");
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
769 %! [q,r] = qr (a, 0); t(j++) = __testqr (q, r, a);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
770 %! [q,r] = qr (a',0); t(j++) = __testqr (q, r, a');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
771 %! [q,r,p] = qr (a, 0); t(j++) = __testqr (q, r, a, p);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
772 %! [q,r,p] = qr (a',0); t(j++) = __testqr (q, r, a',p);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
773 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
774 %! a = [ 611 196 -192 407 -8 -52 -49 29
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
775 %! 196 899 113 -192 -71 -43 -8 -44
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
776 %! -192 113 899 196 61 49 8 52
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
777 %! 407 -192 196 611 8 44 59 -23
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
778 %! -8 -71 61 8 411 -599 208 208
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
779 %! -52 -43 49 44 -599 411 208 208
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
780 %! -49 -8 8 59 208 208 99 -911
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
781 %! 29 -44 52 -23 208 208 -911 99 ];
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
782 %! [q,r] = qr (a);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
783 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
784 %! assert (all (t) && norm (q*r-a) < 5000*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
785
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
786 ## The deactivated tests below can't be tested till rectangular back-subs is
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
787 ## implemented for sparse matrices.
7505
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7491
diff changeset
788
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7491
diff changeset
789 %!testif HAVE_CXSPARSE
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
790 %! n = 20; d = 0.2;
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
791 %! a = sprandn (n,n,d) + speye (n,n);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
792 %! r = qr (a);
21580
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 21547
diff changeset
793 %! assert (r'*r, a'*a, 1e-10);
7505
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7491
diff changeset
794
12329
5f203b5bbf98 Use testif to only run some sparse tests when necessary libraries are installed.
Rik <octave@nomad.inbox5.com>
parents: 11586
diff changeset
795 %!testif HAVE_COLAMD
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
796 %! n = 20; d = 0.2;
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
797 %! a = sprandn (n,n,d) + speye (n,n);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
798 %! q = symamd (a);
7505
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7491
diff changeset
799 %! a = a(q,q);
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
800 %! r = qr (a);
21580
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 21547
diff changeset
801 %! assert (r'*r, a'*a, 1e-10);
7505
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7491
diff changeset
802
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7491
diff changeset
803 %!testif HAVE_CXSPARSE
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
804 %! n = 20; d = 0.2;
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
805 %! a = sprandn (n,n,d) + speye (n,n);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
806 %! [c,r] = qr (a, ones (n,1));
21580
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 21547
diff changeset
807 %! assert (r\c, full (a)\ones (n,1), 10e-10);
7505
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7491
diff changeset
808
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7491
diff changeset
809 %!testif HAVE_CXSPARSE
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
810 %! n = 20; d = 0.2;
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
811 %! a = sprandn (n,n,d) + speye (n,n);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
812 %! b = randn (n,2);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
813 %! [c,r] = qr (a, b);
21580
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 21547
diff changeset
814 %! assert (r\c, full (a)\b, 10e-10);
7505
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7491
diff changeset
815
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7491
diff changeset
816 %% Test under-determined systems!!
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7491
diff changeset
817 %!#testif HAVE_CXSPARSE
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
818 %! n = 20; d = 0.2;
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
819 %! a = sprandn (n,n+1,d) + speye (n,n+1);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
820 %! b = randn (n,2);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
821 %! [c,r] = qr (a, b);
21580
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 21547
diff changeset
822 %! assert (r\c, full (a)\b, 10e-10);
7505
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7491
diff changeset
823
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7491
diff changeset
824 %!testif HAVE_CXSPARSE
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
825 %! n = 20; d = 0.2;
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
826 %! a = 1i*sprandn (n,n,d) + speye (n,n);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
827 %! r = qr (a);
21580
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 21547
diff changeset
828 %! assert (r'*r,a'*a,1e-10);
7505
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7491
diff changeset
829
12329
5f203b5bbf98 Use testif to only run some sparse tests when necessary libraries are installed.
Rik <octave@nomad.inbox5.com>
parents: 11586
diff changeset
830 %!testif HAVE_COLAMD
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
831 %! n = 20; d = 0.2;
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
832 %! a = 1i*sprandn (n,n,d) + speye (n,n);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
833 %! q = symamd (a);
7505
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7491
diff changeset
834 %! a = a(q,q);
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
835 %! r = qr (a);
21580
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 21547
diff changeset
836 %! assert (r'*r, a'*a, 1e-10);
7505
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7491
diff changeset
837
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7491
diff changeset
838 %!testif HAVE_CXSPARSE
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
839 %! n = 20; d = 0.2;
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
840 %! a = 1i*sprandn (n,n,d) + speye (n,n);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
841 %! [c,r] = qr (a, ones (n,1));
21580
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 21547
diff changeset
842 %! assert (r\c, full (a)\ones (n,1), 10e-10);
7505
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7491
diff changeset
843
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7491
diff changeset
844 %!testif HAVE_CXSPARSE
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
845 %! n = 20; d = 0.2;
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
846 %! a = 1i*sprandn (n,n,d) + speye (n,n);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
847 %! b = randn (n,2);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
848 %! [c,r] = qr (a, b);
21580
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 21547
diff changeset
849 %! assert (r\c, full (a)\b, 10e-10);
7505
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7491
diff changeset
850
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7491
diff changeset
851 %% Test under-determined systems!!
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7491
diff changeset
852 %!#testif HAVE_CXSPARSE
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
853 %! n = 20; d = 0.2;
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
854 %! a = 1i*sprandn (n,n+1,d) + speye (n,n+1);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
855 %! b = randn (n,2);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
856 %! [c,r] = qr (a, b);
21580
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 21547
diff changeset
857 %! assert (r\c, full (a)\b, 10e-10);
7505
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7491
diff changeset
858
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7491
diff changeset
859 */
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7491
diff changeset
860
8547
d66c9b6e506a imported patch qrupdate.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8517
diff changeset
861 static
d66c9b6e506a imported patch qrupdate.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8517
diff changeset
862 bool check_qr_dims (const octave_value& q, const octave_value& r,
d66c9b6e506a imported patch qrupdate.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8517
diff changeset
863 bool allow_ecf = false)
d66c9b6e506a imported patch qrupdate.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8517
diff changeset
864 {
18100
6a71e5030df5 Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents: 17787
diff changeset
865 octave_idx_type m = q.rows ();
6a71e5030df5 Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents: 17787
diff changeset
866 octave_idx_type k = r.rows ();
6a71e5030df5 Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents: 17787
diff changeset
867 octave_idx_type n = r.columns ();
8798
53f8fca6dd69 fix typo in qr.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 8597
diff changeset
868 return ((q.ndims () == 2 && r.ndims () == 2 && k == q.columns ())
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
869 && (m == k || (allow_ecf && k == n && k < m)));
8547
d66c9b6e506a imported patch qrupdate.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8517
diff changeset
870 }
d66c9b6e506a imported patch qrupdate.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8517
diff changeset
871
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
872 static
8547
d66c9b6e506a imported patch qrupdate.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8517
diff changeset
873 bool check_index (const octave_value& i, bool vector_allowed = false)
d66c9b6e506a imported patch qrupdate.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8517
diff changeset
874 {
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
875 return ((i.is_real_type () || i.is_integer_type ())
8547
d66c9b6e506a imported patch qrupdate.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8517
diff changeset
876 && (i.is_scalar_type () || vector_allowed));
d66c9b6e506a imported patch qrupdate.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8517
diff changeset
877 }
d66c9b6e506a imported patch qrupdate.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8517
diff changeset
878
7553
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
879 DEFUN_DLD (qrupdate, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
880 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
881 @deftypefn {} {[@var{Q1}, @var{R1}] =} qrupdate (@var{Q}, @var{R}, @var{u}, @var{v})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
882 Given a QR@tie{}factorization of a real or complex matrix
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
883 @w{@var{A} = @var{Q}*@var{R}}, @var{Q}@tie{}unitary and
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
884 @var{R}@tie{}upper trapezoidal, return the QR@tie{}factorization of
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
885 @w{@var{A} + @var{u}*@var{v}'}, where @var{u} and @var{v} are column vectors
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
886 (rank-1 update) or matrices with equal number of columns
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
887 (rank-k update). Notice that the latter case is done as a sequence of
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
888 rank-1 updates; thus, for k large enough, it will be both faster and more
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
889 accurate to recompute the factorization from scratch.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
890
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
891 The QR@tie{}factorization supplied may be either full (Q is square) or
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
892 economized (R is square).
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
893
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
894 @seealso{qr, qrinsert, qrdelete, qrshift}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
895 @end deftypefn */)
7553
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
896 {
20812
d9ca869ca124 maint: Clean-up more instances of print_usage().
Rik <rik@octave.org>
parents: 20790
diff changeset
897 octave_value_list retval;
d9ca869ca124 maint: Clean-up more instances of print_usage().
Rik <rik@octave.org>
parents: 20790
diff changeset
898
20818
cef0448a6ed2 eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents: 20816
diff changeset
899 if (args.length () != 4)
20790
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20678
diff changeset
900 print_usage ();
7553
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
901
7559
07522d7dcdf8 fixes to QR and Cholesky updating code
Jaroslav Hajek <highegg@gmail.com>
parents: 7554
diff changeset
902 octave_value argq = args(0);
07522d7dcdf8 fixes to QR and Cholesky updating code
Jaroslav Hajek <highegg@gmail.com>
parents: 7554
diff changeset
903 octave_value argr = args(1);
07522d7dcdf8 fixes to QR and Cholesky updating code
Jaroslav Hajek <highegg@gmail.com>
parents: 7554
diff changeset
904 octave_value argu = args(2);
07522d7dcdf8 fixes to QR and Cholesky updating code
Jaroslav Hajek <highegg@gmail.com>
parents: 7554
diff changeset
905 octave_value argv = args(3);
07522d7dcdf8 fixes to QR and Cholesky updating code
Jaroslav Hajek <highegg@gmail.com>
parents: 7554
diff changeset
906
20851
0828bf20d105 maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20818
diff changeset
907 if (! argq.is_numeric_type () || ! argr.is_numeric_type ()
0828bf20d105 maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20818
diff changeset
908 || ! argu.is_numeric_type () || ! argv.is_numeric_type ())
0828bf20d105 maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20818
diff changeset
909 print_usage ();
0828bf20d105 maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20818
diff changeset
910
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
911 if (! check_qr_dims (argq, argr, true))
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
912 error ("qrupdate: Q and R dimensions don't match");
7553
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
913
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
914 if (argq.is_real_type () && argr.is_real_type () && argu.is_real_type ()
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
915 && argv.is_real_type ())
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
916 {
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
917 // all real case
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
918 if (argq.is_single_type () || argr.is_single_type ()
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
919 || argu.is_single_type () || argv.is_single_type ())
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
920 {
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
921 FloatMatrix Q = argq.float_matrix_value ();
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
922 FloatMatrix R = argr.float_matrix_value ();
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
923 FloatMatrix u = argu.float_matrix_value ();
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
924 FloatMatrix v = argv.float_matrix_value ();
7553
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
925
21279
eb1524b07fe3 better use of templates for qr classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
926 qr<FloatMatrix> fact (Q, R);
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
927 fact.update (u, v);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
928
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
929 retval = ovl (fact.Q (), get_qr_r (fact));
7553
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
930 }
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
931 else
20851
0828bf20d105 maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20818
diff changeset
932 {
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
933 Matrix Q = argq.matrix_value ();
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
934 Matrix R = argr.matrix_value ();
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
935 Matrix u = argu.matrix_value ();
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
936 Matrix v = argv.matrix_value ();
20851
0828bf20d105 maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20818
diff changeset
937
21279
eb1524b07fe3 better use of templates for qr classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
938 qr<Matrix> fact (Q, R);
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
939 fact.update (u, v);
20851
0828bf20d105 maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20818
diff changeset
940
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
941 retval = ovl (fact.Q (), get_qr_r (fact));
20851
0828bf20d105 maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20818
diff changeset
942 }
7553
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
943 }
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
944 else
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
945 {
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
946 // complex case
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
947 if (argq.is_single_type () || argr.is_single_type ()
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
948 || argu.is_single_type () || argv.is_single_type ())
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
949 {
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
950 FloatComplexMatrix Q = argq.float_complex_matrix_value ();
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
951 FloatComplexMatrix R = argr.float_complex_matrix_value ();
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
952 FloatComplexMatrix u = argu.float_complex_matrix_value ();
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
953 FloatComplexMatrix v = argv.float_complex_matrix_value ();
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
954
21279
eb1524b07fe3 better use of templates for qr classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
955 qr<FloatComplexMatrix> fact (Q, R);
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
956 fact.update (u, v);
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
957
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
958 retval = ovl (fact.Q (), get_qr_r (fact));
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
959 }
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
960 else
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
961 {
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
962 ComplexMatrix Q = argq.complex_matrix_value ();
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
963 ComplexMatrix R = argr.complex_matrix_value ();
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
964 ComplexMatrix u = argu.complex_matrix_value ();
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
965 ComplexMatrix v = argv.complex_matrix_value ();
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
966
21279
eb1524b07fe3 better use of templates for qr classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
967 qr<ComplexMatrix> fact (Q, R);
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
968 fact.update (u, v);
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
969
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
970 retval = ovl (fact.Q (), get_qr_r (fact));
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
971 }
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
972 }
7553
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
973
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
974 return retval;
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
975 }
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
976
7553
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
977 /*
7886
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
978 %!shared A, u, v, Ac, uc, vc
7553
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
979 %! A = [0.091364 0.613038 0.999083;
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
980 %! 0.594638 0.425302 0.603537;
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
981 %! 0.383594 0.291238 0.085574;
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
982 %! 0.265712 0.268003 0.238409;
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
983 %! 0.669966 0.743851 0.445057 ];
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
984 %!
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
985 %! u = [0.85082;
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
986 %! 0.76426;
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
987 %! 0.42883;
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
988 %! 0.53010;
7553
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
989 %! 0.80683 ];
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
990 %!
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
991 %! v = [0.98810;
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
992 %! 0.24295;
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
993 %! 0.43167 ];
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
994 %!
7886
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
995 %! Ac = [0.620405 + 0.956953i 0.480013 + 0.048806i 0.402627 + 0.338171i;
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
996 %! 0.589077 + 0.658457i 0.013205 + 0.279323i 0.229284 + 0.721929i;
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
997 %! 0.092758 + 0.345687i 0.928679 + 0.241052i 0.764536 + 0.832406i;
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
998 %! 0.912098 + 0.721024i 0.049018 + 0.269452i 0.730029 + 0.796517i;
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
999 %! 0.112849 + 0.603871i 0.486352 + 0.142337i 0.355646 + 0.151496i ];
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1000 %!
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1001 %! uc = [0.20351 + 0.05401i;
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1002 %! 0.13141 + 0.43708i;
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1003 %! 0.29808 + 0.08789i;
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1004 %! 0.69821 + 0.38844i;
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1005 %! 0.74871 + 0.25821i ];
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1006 %!
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1007 %! vc = [0.85839 + 0.29468i;
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1008 %! 0.20820 + 0.93090i;
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1009 %! 0.86184 + 0.34689i ];
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1010 %!
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1011
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1012 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1013 %! [Q,R] = qr (A);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1014 %! [Q,R] = qrupdate (Q, R, u, v);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1015 %! assert (norm (vec (Q'*Q - eye (5)), Inf) < 1e1*eps);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1016 %! assert (norm (vec (triu (R)-R), Inf) == 0);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1017 %! assert (norm (vec (Q*R - A - u*v'), Inf) < norm (A)*1e1*eps);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
1018 %!
7553
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
1019 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1020 %! [Q,R] = qr (Ac);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1021 %! [Q,R] = qrupdate (Q, R, uc, vc);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1022 %! assert (norm (vec (Q'*Q - eye (5)), Inf) < 1e1*eps);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1023 %! assert (norm (vec (triu (R)-R), Inf) == 0);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1024 %! assert (norm (vec (Q*R - Ac - uc*vc'), Inf) < norm (Ac)*1e1*eps);
7886
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1025
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1026 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1027 %! [Q,R] = qr (single (A));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1028 %! [Q,R] = qrupdate (Q, R, single (u), single (v));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1029 %! assert (norm (vec (Q'*Q - eye (5,"single")), Inf) < 1e1*eps ("single"));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1030 %! assert (norm (vec (triu (R)-R), Inf) == 0);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1031 %! assert (norm (vec (Q*R - single (A) - single (u)*single (v)'), Inf) < norm (single (A))*1e1*eps ("single"));
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
1032 %!
7886
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1033 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1034 %! [Q,R] = qr (single (Ac));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1035 %! [Q,R] = qrupdate (Q, R, single (uc), single (vc));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1036 %! assert (norm (vec (Q'*Q - eye (5,"single")), Inf) < 1e1*eps ("single"));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1037 %! assert (norm (vec (triu (R)-R), Inf) == 0);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1038 %! assert (norm (vec (Q*R - single (Ac) - single (uc)*single (vc)'), Inf) < norm (single (Ac))*1e1*eps ("single"));
7553
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
1039 */
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
1040
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
1041 DEFUN_DLD (qrinsert, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1042 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1043 @deftypefn {} {[@var{Q1}, @var{R1}] =} qrinsert (@var{Q}, @var{R}, @var{j}, @var{x}, @var{orient})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1044 Given a QR@tie{}factorization of a real or complex matrix
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1045 @w{@var{A} = @var{Q}*@var{R}}, @var{Q}@tie{}unitary and
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1046 @var{R}@tie{}upper trapezoidal, return the QR@tie{}factorization of
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1047 @w{[A(:,1:j-1) x A(:,j:n)]}, where @var{u} is a column vector to be inserted
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1048 into @var{A} (if @var{orient} is @qcode{"col"}), or the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1049 QR@tie{}factorization of @w{[A(1:j-1,:);x;A(:,j:n)]}, where @var{x} is a row
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1050 vector to be inserted into @var{A} (if @var{orient} is @qcode{"row"}).
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1051
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1052 The default value of @var{orient} is @qcode{"col"}. If @var{orient} is
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1053 @qcode{"col"}, @var{u} may be a matrix and @var{j} an index vector
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1054 resulting in the QR@tie{}factorization of a matrix @var{B} such that
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1055 @w{B(:,@var{j})} gives @var{u} and @w{B(:,@var{j}) = []} gives @var{A}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1056 Notice that the latter case is done as a sequence of k insertions;
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1057 thus, for k large enough, it will be both faster and more accurate to
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1058 recompute the factorization from scratch.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1059
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1060 If @var{orient} is @qcode{"col"}, the QR@tie{}factorization supplied may
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1061 be either full (Q is square) or economized (R is square).
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1062
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1063 If @var{orient} is @qcode{"row"}, full factorization is needed.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1064 @seealso{qr, qrupdate, qrdelete, qrshift}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1065 @end deftypefn */)
7553
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
1066 {
20816
b16bcd7a2a33 Use int rather than octave_idx_type for nargin data type.
Rik <rik@octave.org>
parents: 20812
diff changeset
1067 int nargin = args.length ();
7553
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
1068
7559
07522d7dcdf8 fixes to QR and Cholesky updating code
Jaroslav Hajek <highegg@gmail.com>
parents: 7554
diff changeset
1069 if (nargin < 4 || nargin > 5)
20790
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20678
diff changeset
1070 print_usage ();
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
1071
7559
07522d7dcdf8 fixes to QR and Cholesky updating code
Jaroslav Hajek <highegg@gmail.com>
parents: 7554
diff changeset
1072 octave_value argq = args(0);
07522d7dcdf8 fixes to QR and Cholesky updating code
Jaroslav Hajek <highegg@gmail.com>
parents: 7554
diff changeset
1073 octave_value argr = args(1);
07522d7dcdf8 fixes to QR and Cholesky updating code
Jaroslav Hajek <highegg@gmail.com>
parents: 7554
diff changeset
1074 octave_value argj = args(2);
07522d7dcdf8 fixes to QR and Cholesky updating code
Jaroslav Hajek <highegg@gmail.com>
parents: 7554
diff changeset
1075 octave_value argx = args(3);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
1076
20851
0828bf20d105 maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20818
diff changeset
1077 if (! argq.is_numeric_type () || ! argr.is_numeric_type ()
0828bf20d105 maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20818
diff changeset
1078 || ! argx.is_numeric_type ()
0828bf20d105 maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20818
diff changeset
1079 || (nargin > 4 && ! args(4).is_string ()))
0828bf20d105 maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20818
diff changeset
1080 print_usage ();
7553
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
1081
20851
0828bf20d105 maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20818
diff changeset
1082 std::string orient = (nargin < 5) ? "col" : args(4).string_value ();
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1083 bool col = (orient == "col");
20851
0828bf20d105 maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20818
diff changeset
1084
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1085 if (! col && orient != "row")
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1086 error ("qrinsert: ORIENT must be \"col\" or \"row\"");
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1087
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1088 if (! check_qr_dims (argq, argr, col) || (! col && argx.rows () != 1))
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1089 error ("qrinsert: dimension mismatch");
7553
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
1090
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1091 if (! check_index (argj, col))
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1092 error ("qrinsert: invalid index J");
20851
0828bf20d105 maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20818
diff changeset
1093
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1094 octave_value_list retval;
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1095
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1096 MArray<octave_idx_type> j = argj.octave_idx_type_vector_value ();
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1097
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1098 octave_idx_type one = 1;
20851
0828bf20d105 maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20818
diff changeset
1099
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1100 if (argq.is_real_type () && argr.is_real_type () && argx.is_real_type ())
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1101 {
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1102 // real case
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1103 if (argq.is_single_type () || argr.is_single_type ()
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1104 || argx.is_single_type ())
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1105 {
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1106 FloatMatrix Q = argq.float_matrix_value ();
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1107 FloatMatrix R = argr.float_matrix_value ();
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1108 FloatMatrix x = argx.float_matrix_value ();
7553
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
1109
21279
eb1524b07fe3 better use of templates for qr classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1110 qr<FloatMatrix> fact (Q, R);
7553
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
1111
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1112 if (col)
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1113 fact.insert_col (x, j-one);
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1114 else
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1115 fact.insert_row (x.row (0), j(0)-one);
7553
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
1116
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1117 retval = ovl (fact.Q (), get_qr_r (fact));
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1118 }
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1119 else
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1120 {
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1121 Matrix Q = argq.matrix_value ();
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1122 Matrix R = argr.matrix_value ();
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1123 Matrix x = argx.matrix_value ();
7553
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
1124
21279
eb1524b07fe3 better use of templates for qr classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1125 qr<Matrix> fact (Q, R);
7886
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1126
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1127 if (col)
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1128 fact.insert_col (x, j-one);
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1129 else
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1130 fact.insert_row (x.row (0), j(0)-one);
20851
0828bf20d105 maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20818
diff changeset
1131
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1132 retval = ovl (fact.Q (), get_qr_r (fact));
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1133 }
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1134 }
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1135 else
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1136 {
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1137 // complex case
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1138 if (argq.is_single_type () || argr.is_single_type ()
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1139 || argx.is_single_type ())
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1140 {
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1141 FloatComplexMatrix Q =
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1142 argq.float_complex_matrix_value ();
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1143 FloatComplexMatrix R =
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1144 argr.float_complex_matrix_value ();
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1145 FloatComplexMatrix x =
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1146 argx.float_complex_matrix_value ();
20851
0828bf20d105 maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20818
diff changeset
1147
21279
eb1524b07fe3 better use of templates for qr classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1148 qr<FloatComplexMatrix> fact (Q, R);
20851
0828bf20d105 maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20818
diff changeset
1149
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1150 if (col)
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1151 fact.insert_col (x, j-one);
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1152 else
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1153 fact.insert_row (x.row (0), j(0)-one);
20851
0828bf20d105 maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20818
diff changeset
1154
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1155 retval = ovl (fact.Q (), get_qr_r (fact));
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1156 }
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1157 else
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1158 {
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1159 ComplexMatrix Q = argq.complex_matrix_value ();
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1160 ComplexMatrix R = argr.complex_matrix_value ();
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1161 ComplexMatrix x = argx.complex_matrix_value ();
20851
0828bf20d105 maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20818
diff changeset
1162
21279
eb1524b07fe3 better use of templates for qr classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1163 qr<ComplexMatrix> fact (Q, R);
7553
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
1164
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1165 if (col)
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1166 fact.insert_col (x, j-one);
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1167 else
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1168 fact.insert_row (x.row (0), j(0)-one);
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1169
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1170 retval = ovl (fact.Q (), get_qr_r (fact));
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1171 }
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1172 }
7553
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
1173
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
1174 return retval;
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
1175 }
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
1176
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
1177 /*
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
1178 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1179 %! [Q,R] = qr (A);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1180 %! [Q,R] = qrinsert (Q, R, 3, u);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1181 %! assert (norm (vec (Q'*Q - eye (5)), Inf) < 1e1*eps);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1182 %! assert (norm (vec (triu (R) - R), Inf) == 0);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1183 %! assert (norm (vec (Q*R - [A(:,1:2) u A(:,3)]), Inf) < norm (A)*1e1*eps);
7553
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
1184 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1185 %! [Q,R] = qr (Ac);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1186 %! [Q,R] = qrinsert (Q, R, 3, uc);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1187 %! assert (norm (vec (Q'*Q - eye (5)), Inf) < 1e1*eps);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1188 %! assert (norm (vec (triu (R) - R), Inf) == 0);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1189 %! assert (norm (vec (Q*R - [Ac(:,1:2) uc Ac(:,3)]), Inf) < norm (Ac)*1e1*eps);
7553
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
1190 %!test
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
1191 %! x = [0.85082 0.76426 0.42883 ];
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
1192 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1193 %! [Q,R] = qr (A);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1194 %! [Q,R] = qrinsert (Q, R, 3, x, "row");
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1195 %! assert (norm (vec (Q'*Q - eye (6)), Inf) < 1e1*eps);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1196 %! assert (norm (vec (triu (R) - R), Inf) == 0);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1197 %! assert (norm (vec (Q*R - [A(1:2,:);x;A(3:5,:)]), Inf) < norm (A)*1e1*eps);
7553
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
1198 %!test
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
1199 %! x = [0.20351 + 0.05401i 0.13141 + 0.43708i 0.29808 + 0.08789i ];
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
1200 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1201 %! [Q,R] = qr (Ac);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1202 %! [Q,R] = qrinsert (Q, R, 3, x, "row");
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1203 %! assert (norm (vec (Q'*Q - eye (6)), Inf) < 1e1*eps);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1204 %! assert (norm (vec (triu (R) - R), Inf) == 0);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1205 %! assert (norm (vec (Q*R - [Ac(1:2,:);x;Ac(3:5,:)]), Inf) < norm (Ac)*1e1*eps);
7886
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1206
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1207 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1208 %! [Q,R] = qr (single (A));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1209 %! [Q,R] = qrinsert (Q, R, 3, single (u));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1210 %! assert (norm (vec (Q'*Q - eye (5,"single")), Inf) < 1e1*eps ("single"));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1211 %! assert (norm (vec (triu (R) - R), Inf) == 0);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1212 %! assert (norm (vec (Q*R - single ([A(:,1:2) u A(:,3)])), Inf) < norm (single (A))*1e1*eps ("single"));
7886
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1213 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1214 %! [Q,R] = qr (single (Ac));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1215 %! [Q,R] = qrinsert (Q, R, 3, single (uc));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1216 %! assert (norm (vec (Q'*Q - eye (5,"single")), Inf) < 1e1*eps ("single"));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1217 %! assert (norm (vec (triu (R) - R), Inf) == 0);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1218 %! assert (norm (vec (Q*R - single ([Ac(:,1:2) uc Ac(:,3)])), Inf) < norm (single (Ac))*1e1*eps ("single"));
7886
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1219 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1220 %! x = single ([0.85082 0.76426 0.42883 ]);
7886
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1221 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1222 %! [Q,R] = qr (single (A));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1223 %! [Q,R] = qrinsert (Q, R, 3, x, "row");
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1224 %! assert (norm (vec (Q'*Q - eye (6,"single")), Inf) < 1e1*eps ("single"));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1225 %! assert (norm (vec (triu (R) - R), Inf) == 0);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1226 %! assert (norm (vec (Q*R - single ([A(1:2,:);x;A(3:5,:)])), Inf) < norm (single (A))*1e1*eps ("single"));
7886
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1227 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1228 %! x = single ([0.20351 + 0.05401i 0.13141 + 0.43708i 0.29808 + 0.08789i ]);
7886
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1229 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1230 %! [Q,R] = qr (single (Ac));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1231 %! [Q,R] = qrinsert (Q, R, 3, x, "row");
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1232 %! assert (norm (vec (Q'*Q - eye (6,"single")), Inf) < 1e1*eps ("single"));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1233 %! assert (norm (vec (triu (R) - R), Inf) == 0);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1234 %! assert (norm (vec (Q*R - single ([Ac(1:2,:);x;Ac(3:5,:)])), Inf) < norm (single (Ac))*1e1*eps ("single"));
7553
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
1235 */
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
1236
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
1237 DEFUN_DLD (qrdelete, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1238 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1239 @deftypefn {} {[@var{Q1}, @var{R1}] =} qrdelete (@var{Q}, @var{R}, @var{j}, @var{orient})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1240 Given a QR@tie{}factorization of a real or complex matrix
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1241 @w{@var{A} = @var{Q}*@var{R}}, @var{Q}@tie{}unitary and
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1242 @var{R}@tie{}upper trapezoidal, return the QR@tie{}factorization of
22207
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
1243 @w{[A(:,1:j-1), U, A(:,j:n)]},
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
1244 where @var{u} is a column vector to be inserted into @var{A}
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
1245 (if @var{orient} is @qcode{\"col\"}),
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
1246 or the QR@tie{}factorization of @w{[A(1:j-1,:);X;A(:,j:n)]},
99454a60bf5e Reconcile qr docs with behaviour. Fix qr(A,B,complex(0)). (bug #46912)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22206
diff changeset
1247 where @var{x} is a row @var{orient} is @qcode{"row"}).
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1248 The default value of @var{orient} is @qcode{"col"}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1249
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1250 If @var{orient} is @qcode{"col"}, @var{j} may be an index vector
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1251 resulting in the QR@tie{}factorization of a matrix @var{B} such that
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1252 @w{A(:,@var{j}) = []} gives @var{B}. Notice that the latter case is done as
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1253 a sequence of k deletions; thus, for k large enough, it will be both faster
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1254 and more accurate to recompute the factorization from scratch.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1255
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1256 If @var{orient} is @qcode{"col"}, the QR@tie{}factorization supplied may
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1257 be either full (Q is square) or economized (R is square).
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1258
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1259 If @var{orient} is @qcode{"row"}, full factorization is needed.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1260 @seealso{qr, qrupdate, qrinsert, qrshift}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1261 @end deftypefn */)
7553
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
1262 {
20816
b16bcd7a2a33 Use int rather than octave_idx_type for nargin data type.
Rik <rik@octave.org>
parents: 20812
diff changeset
1263 int nargin = args.length ();
7553
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
1264
7559
07522d7dcdf8 fixes to QR and Cholesky updating code
Jaroslav Hajek <highegg@gmail.com>
parents: 7554
diff changeset
1265 if (nargin < 3 || nargin > 4)
20790
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20678
diff changeset
1266 print_usage ();
7553
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
1267
7559
07522d7dcdf8 fixes to QR and Cholesky updating code
Jaroslav Hajek <highegg@gmail.com>
parents: 7554
diff changeset
1268 octave_value argq = args(0);
07522d7dcdf8 fixes to QR and Cholesky updating code
Jaroslav Hajek <highegg@gmail.com>
parents: 7554
diff changeset
1269 octave_value argr = args(1);
07522d7dcdf8 fixes to QR and Cholesky updating code
Jaroslav Hajek <highegg@gmail.com>
parents: 7554
diff changeset
1270 octave_value argj = args(2);
7553
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
1271
20851
0828bf20d105 maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20818
diff changeset
1272 if (! argq.is_numeric_type () || ! argr.is_numeric_type ()
0828bf20d105 maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20818
diff changeset
1273 || (nargin > 3 && ! args(3).is_string ()))
0828bf20d105 maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20818
diff changeset
1274 print_usage ();
0828bf20d105 maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20818
diff changeset
1275
0828bf20d105 maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20818
diff changeset
1276 std::string orient = (nargin < 4) ? "col" : args(3).string_value ();
0828bf20d105 maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20818
diff changeset
1277 bool col = orient == "col";
7559
07522d7dcdf8 fixes to QR and Cholesky updating code
Jaroslav Hajek <highegg@gmail.com>
parents: 7554
diff changeset
1278
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1279 if (! col && orient != "row")
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1280 error ("qrdelete: ORIENT must be \"col\" or \"row\"");
20851
0828bf20d105 maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20818
diff changeset
1281
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1282 if (! check_qr_dims (argq, argr, col))
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1283 error ("qrdelete: dimension mismatch");
8547
d66c9b6e506a imported patch qrupdate.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8517
diff changeset
1284
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1285 MArray<octave_idx_type> j = argj.octave_idx_type_vector_value ();
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1286 if (! check_index (argj, col))
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1287 error ("qrdelete: invalid index J");
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1288
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1289 octave_value_list retval;
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1290
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1291 octave_idx_type one = 1;
7886
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1292
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1293 if (argq.is_real_type () && argr.is_real_type ())
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1294 {
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1295 // real case
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1296 if (argq.is_single_type () || argr.is_single_type ())
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1297 {
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1298 FloatMatrix Q = argq.float_matrix_value ();
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1299 FloatMatrix R = argr.float_matrix_value ();
7553
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
1300
21279
eb1524b07fe3 better use of templates for qr classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1301 qr<FloatMatrix> fact (Q, R);
7886
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1302
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1303 if (col)
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1304 fact.delete_col (j-one);
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1305 else
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1306 fact.delete_row (j(0)-one);
7886
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1307
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1308 retval = ovl (fact.Q (), get_qr_r (fact));
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1309 }
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1310 else
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1311 {
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1312 Matrix Q = argq.matrix_value ();
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1313 Matrix R = argr.matrix_value ();
7553
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
1314
21279
eb1524b07fe3 better use of templates for qr classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1315 qr<Matrix> fact (Q, R);
7886
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1316
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1317 if (col)
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1318 fact.delete_col (j-one);
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1319 else
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1320 fact.delete_row (j(0)-one);
20851
0828bf20d105 maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20818
diff changeset
1321
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1322 retval = ovl (fact.Q (), get_qr_r (fact));
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1323 }
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1324 }
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1325 else
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1326 {
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1327 // complex case
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1328 if (argq.is_single_type () || argr.is_single_type ())
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1329 {
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1330 FloatComplexMatrix Q =
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1331 argq.float_complex_matrix_value ();
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1332 FloatComplexMatrix R =
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1333 argr.float_complex_matrix_value ();
20851
0828bf20d105 maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20818
diff changeset
1334
21279
eb1524b07fe3 better use of templates for qr classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1335 qr<FloatComplexMatrix> fact (Q, R);
20851
0828bf20d105 maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20818
diff changeset
1336
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1337 if (col)
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1338 fact.delete_col (j-one);
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1339 else
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1340 fact.delete_row (j(0)-one);
20851
0828bf20d105 maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20818
diff changeset
1341
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1342 retval = ovl (fact.Q (), get_qr_r (fact));
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1343 }
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1344 else
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1345 {
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1346 ComplexMatrix Q = argq.complex_matrix_value ();
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1347 ComplexMatrix R = argr.complex_matrix_value ();
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1348
21279
eb1524b07fe3 better use of templates for qr classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1349 qr<ComplexMatrix> fact (Q, R);
20851
0828bf20d105 maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20818
diff changeset
1350
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1351 if (col)
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1352 fact.delete_col (j-one);
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1353 else
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1354 fact.delete_row (j(0)-one);
7553
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
1355
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1356 retval = ovl (fact.Q (), get_qr_r (fact));
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1357 }
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1358 }
7553
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
1359
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
1360 return retval;
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
1361 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
1362
7553
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
1363 /*
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
1364 %!test
7886
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1365 %! AA = [0.091364 0.613038 0.027504 0.999083;
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1366 %! 0.594638 0.425302 0.562834 0.603537;
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1367 %! 0.383594 0.291238 0.742073 0.085574;
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1368 %! 0.265712 0.268003 0.783553 0.238409;
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1369 %! 0.669966 0.743851 0.457255 0.445057 ];
7553
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
1370 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1371 %! [Q,R] = qr (AA);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1372 %! [Q,R] = qrdelete (Q, R, 3);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1373 %! assert (norm (vec (Q'*Q - eye (5)), Inf) < 16*eps);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1374 %! assert (norm (vec (triu (R) - R), Inf) == 0);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1375 %! assert (norm (vec (Q*R - [AA(:,1:2) AA(:,4)]), Inf) < norm (AA)*1e1*eps);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
1376 %!
7553
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
1377 %!test
7886
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1378 %! AA = [0.364554 + 0.993117i 0.669818 + 0.510234i 0.426568 + 0.041337i 0.847051 + 0.233291i;
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1379 %! 0.049600 + 0.242783i 0.448946 + 0.484022i 0.141155 + 0.074420i 0.446746 + 0.392706i;
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1380 %! 0.581922 + 0.657416i 0.581460 + 0.030016i 0.219909 + 0.447288i 0.201144 + 0.069132i;
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1381 %! 0.694986 + 0.000571i 0.682327 + 0.841712i 0.807537 + 0.166086i 0.192767 + 0.358098i;
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1382 %! 0.945002 + 0.066788i 0.350492 + 0.642638i 0.579629 + 0.048102i 0.600170 + 0.636938i ] * I;
7553
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
1383 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1384 %! [Q,R] = qr (AA);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1385 %! [Q,R] = qrdelete (Q, R, 3);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1386 %! assert (norm (vec (Q'*Q - eye (5)), Inf) < 16*eps);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1387 %! assert (norm (vec (triu (R) - R), Inf) == 0);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1388 %! assert (norm (vec (Q*R - [AA(:,1:2) AA(:,4)]), Inf) < norm (AA)*1e1*eps);
7553
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
1389 %!
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
1390 %!test
7886
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1391 %! AA = [0.091364 0.613038 0.027504 0.999083;
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1392 %! 0.594638 0.425302 0.562834 0.603537;
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1393 %! 0.383594 0.291238 0.742073 0.085574;
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1394 %! 0.265712 0.268003 0.783553 0.238409;
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1395 %! 0.669966 0.743851 0.457255 0.445057 ];
7553
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
1396 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1397 %! [Q,R] = qr (AA);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1398 %! [Q,R] = qrdelete (Q, R, 3, "row");
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1399 %! assert (norm (vec (Q'*Q - eye (4)), Inf) < 1e1*eps);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1400 %! assert (norm (vec (triu (R) - R), Inf) == 0);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1401 %! assert (norm (vec (Q*R - [AA(1:2,:);AA(4:5,:)]), Inf) < norm (AA)*1e1*eps);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
1402 %!
7886
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1403 %!test
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1404 %! AA = [0.364554 + 0.993117i 0.669818 + 0.510234i 0.426568 + 0.041337i 0.847051 + 0.233291i;
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1405 %! 0.049600 + 0.242783i 0.448946 + 0.484022i 0.141155 + 0.074420i 0.446746 + 0.392706i;
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1406 %! 0.581922 + 0.657416i 0.581460 + 0.030016i 0.219909 + 0.447288i 0.201144 + 0.069132i;
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1407 %! 0.694986 + 0.000571i 0.682327 + 0.841712i 0.807537 + 0.166086i 0.192767 + 0.358098i;
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1408 %! 0.945002 + 0.066788i 0.350492 + 0.642638i 0.579629 + 0.048102i 0.600170 + 0.636938i ] * I;
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1409 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1410 %! [Q,R] = qr (AA);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1411 %! [Q,R] = qrdelete (Q, R, 3, "row");
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1412 %! assert (norm (vec (Q'*Q - eye (4)), Inf) < 1e1*eps);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1413 %! assert (norm (vec (triu (R) - R), Inf) == 0);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1414 %! assert (norm (vec (Q*R - [AA(1:2,:);AA(4:5,:)]), Inf) < norm (AA)*1e1*eps);
7886
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1415
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1416 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1417 %! AA = single ([0.091364 0.613038 0.027504 0.999083;
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1418 %! 0.594638 0.425302 0.562834 0.603537;
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1419 %! 0.383594 0.291238 0.742073 0.085574;
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1420 %! 0.265712 0.268003 0.783553 0.238409;
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1421 %! 0.669966 0.743851 0.457255 0.445057 ]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1422 %!
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1423 %! [Q,R] = qr (AA);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1424 %! [Q,R] = qrdelete (Q, R, 3);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1425 %! assert (norm (vec (Q'*Q - eye (5,"single")), Inf) < 1e1*eps ("single"));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1426 %! assert (norm (vec (triu (R) - R), Inf) == 0);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1427 %! assert (norm (vec (Q*R - [AA(:,1:2) AA(:,4)]), Inf) < norm (AA)*1e1*eps ("single"));
7886
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1428 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1429 %!test
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1430 %! AA = single ([0.364554 + 0.993117i 0.669818 + 0.510234i 0.426568 + 0.041337i 0.847051 + 0.233291i;
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1431 %! 0.049600 + 0.242783i 0.448946 + 0.484022i 0.141155 + 0.074420i 0.446746 + 0.392706i;
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1432 %! 0.581922 + 0.657416i 0.581460 + 0.030016i 0.219909 + 0.447288i 0.201144 + 0.069132i;
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1433 %! 0.694986 + 0.000571i 0.682327 + 0.841712i 0.807537 + 0.166086i 0.192767 + 0.358098i;
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1434 %! 0.945002 + 0.066788i 0.350492 + 0.642638i 0.579629 + 0.048102i 0.600170 + 0.636938i ]) * I;
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1435 %!
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1436 %! [Q,R] = qr (AA);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1437 %! [Q,R] = qrdelete (Q, R, 3);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1438 %! assert (norm (vec (Q'*Q - eye (5,"single")), Inf) < 1e1*eps ("single"));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1439 %! assert (norm (vec (triu (R) - R), Inf) == 0);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1440 %! assert (norm (vec (Q*R - [AA(:,1:2) AA(:,4)]), Inf) < norm (AA)*1e1*eps ("single"));
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
1441 %!
7553
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
1442 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1443 %! AA = single ([0.091364 0.613038 0.027504 0.999083;
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1444 %! 0.594638 0.425302 0.562834 0.603537;
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1445 %! 0.383594 0.291238 0.742073 0.085574;
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1446 %! 0.265712 0.268003 0.783553 0.238409;
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1447 %! 0.669966 0.743851 0.457255 0.445057 ]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1448 %!
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1449 %! [Q,R] = qr (AA);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1450 %! [Q,R] = qrdelete (Q, R, 3, "row");
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1451 %! assert (norm (vec (Q'*Q - eye (4,"single")), Inf) < 1.5e1*eps ("single"));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1452 %! assert (norm (vec (triu (R) - R), Inf) == 0);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1453 %! assert (norm (vec (Q*R - [AA(1:2,:);AA(4:5,:)]), Inf) < norm (AA)*1e1*eps ("single"));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1454 %!testif HAVE_QRUPDATE
17336
b81b9d079515 Use '##' for comments which stand alone on a line.
Rik <rik@octave.org>
parents: 17281
diff changeset
1455 %! ## Same test as above but with more precicision
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1456 %! AA = single ([0.091364 0.613038 0.027504 0.999083;
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1457 %! 0.594638 0.425302 0.562834 0.603537;
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1458 %! 0.383594 0.291238 0.742073 0.085574;
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1459 %! 0.265712 0.268003 0.783553 0.238409;
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1460 %! 0.669966 0.743851 0.457255 0.445057 ]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1461 %!
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1462 %! [Q,R] = qr (AA);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1463 %! [Q,R] = qrdelete (Q, R, 3, "row");
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1464 %! assert (norm (vec (Q'*Q - eye (4,"single")), Inf) < 1e1*eps ("single"));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1465 %! assert (norm (vec (triu (R) - R), Inf) == 0);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1466 %! assert (norm (vec (Q*R - [AA(1:2,:);AA(4:5,:)]), Inf) < norm (AA)*1e1*eps ("single"));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1467 %!
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1468 %!test
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1469 %! AA = single ([0.364554 + 0.993117i 0.669818 + 0.510234i 0.426568 + 0.041337i 0.847051 + 0.233291i;
7886
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1470 %! 0.049600 + 0.242783i 0.448946 + 0.484022i 0.141155 + 0.074420i 0.446746 + 0.392706i;
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1471 %! 0.581922 + 0.657416i 0.581460 + 0.030016i 0.219909 + 0.447288i 0.201144 + 0.069132i;
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1472 %! 0.694986 + 0.000571i 0.682327 + 0.841712i 0.807537 + 0.166086i 0.192767 + 0.358098i;
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1473 %! 0.945002 + 0.066788i 0.350492 + 0.642638i 0.579629 + 0.048102i 0.600170 + 0.636938i ]) * I;
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1474 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1475 %! [Q,R] = qr (AA);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1476 %! [Q,R] = qrdelete (Q, R, 3, "row");
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1477 %! assert (norm (vec (Q'*Q - eye (4,"single")), Inf) < 1e1*eps ("single"));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1478 %! assert (norm (vec (triu (R) - R), Inf) == 0);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1479 %! assert (norm (vec (Q*R - [AA(1:2,:);AA(4:5,:)]), Inf) < norm (AA)*1e1*eps ("single"));
7553
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7505
diff changeset
1480 */
7505
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7491
diff changeset
1481
7700
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
1482 DEFUN_DLD (qrshift, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1483 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1484 @deftypefn {} {[@var{Q1}, @var{R1}] =} qrshift (@var{Q}, @var{R}, @var{i}, @var{j})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1485 Given a QR@tie{}factorization of a real or complex matrix
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1486 @w{@var{A} = @var{Q}*@var{R}}, @var{Q}@tie{}unitary and
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1487 @var{R}@tie{}upper trapezoidal, return the QR@tie{}factorization
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1488 of @w{@var{A}(:,p)}, where @w{p} is the permutation @*
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1489 @code{p = [1:i-1, shift(i:j, 1), j+1:n]} if @w{@var{i} < @var{j}} @*
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1490 or @*
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1491 @code{p = [1:j-1, shift(j:i,-1), i+1:n]} if @w{@var{j} < @var{i}}. @*
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1492
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1493 @seealso{qr, qrupdate, qrinsert, qrdelete}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1494 @end deftypefn */)
7700
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
1495 {
20818
cef0448a6ed2 eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents: 20816
diff changeset
1496 if (args.length () != 4)
20790
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20678
diff changeset
1497 print_usage ();
7700
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
1498
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
1499 octave_value argq = args(0);
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
1500 octave_value argr = args(1);
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
1501 octave_value argi = args(2);
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
1502 octave_value argj = args(3);
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
1503
20851
0828bf20d105 maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20818
diff changeset
1504 if (! argq.is_numeric_type () || ! argr.is_numeric_type ())
0828bf20d105 maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20818
diff changeset
1505 print_usage ();
0828bf20d105 maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20818
diff changeset
1506
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1507 if (! check_qr_dims (argq, argr, true))
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1508 error ("qrshift: dimensions mismatch");
20851
0828bf20d105 maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20818
diff changeset
1509
21041
63374982750b Usage of corresponding value extractor for octave_idx_type. Improves support
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 20940
diff changeset
1510 octave_idx_type i = argi.idx_type_value ();
63374982750b Usage of corresponding value extractor for octave_idx_type. Improves support
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 20940
diff changeset
1511 octave_idx_type j = argj.idx_type_value ();
7700
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
1512
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1513 if (! check_index (argi) || ! check_index (argj))
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1514 error ("qrshift: invalid index I or J");
7700
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
1515
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1516 octave_value_list retval;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
1517
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1518 if (argq.is_real_type () && argr.is_real_type ())
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1519 {
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1520 // all real case
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1521 if (argq.is_single_type ()
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1522 && argr.is_single_type ())
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1523 {
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1524 FloatMatrix Q = argq.float_matrix_value ();
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1525 FloatMatrix R = argr.float_matrix_value ();
20851
0828bf20d105 maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20818
diff changeset
1526
21279
eb1524b07fe3 better use of templates for qr classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1527 qr<FloatMatrix> fact (Q, R);
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1528 fact.shift_cols (i-1, j-1);
20851
0828bf20d105 maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20818
diff changeset
1529
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1530 retval = ovl (fact.Q (), get_qr_r (fact));
7700
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
1531 }
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
1532 else
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1533 {
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1534 Matrix Q = argq.matrix_value ();
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1535 Matrix R = argr.matrix_value ();
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1536
21279
eb1524b07fe3 better use of templates for qr classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1537 qr<Matrix> fact (Q, R);
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1538 fact.shift_cols (i-1, j-1);
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1539
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1540 retval = ovl (fact.Q (), get_qr_r (fact));
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1541 }
7700
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
1542 }
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
1543 else
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1544 {
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1545 // complex case
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1546 if (argq.is_single_type ()
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1547 && argr.is_single_type ())
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1548 {
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1549 FloatComplexMatrix Q = argq.float_complex_matrix_value ();
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1550 FloatComplexMatrix R = argr.float_complex_matrix_value ();
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1551
21279
eb1524b07fe3 better use of templates for qr classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1552 qr<FloatComplexMatrix> fact (Q, R);
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1553 fact.shift_cols (i-1, j-1);
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1554
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1555 retval = ovl (fact.Q (), get_qr_r (fact));
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1556 }
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1557 else
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1558 {
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1559 ComplexMatrix Q = argq.complex_matrix_value ();
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1560 ComplexMatrix R = argr.complex_matrix_value ();
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1561
21279
eb1524b07fe3 better use of templates for qr classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1562 qr<ComplexMatrix> fact (Q, R);
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1563 fact.shift_cols (i-1, j-1);
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1564
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1565 retval = ovl (fact.Q (), get_qr_r (fact));
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1566 }
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20909
diff changeset
1567 }
7700
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
1568
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
1569 return retval;
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
1570 }
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1571
7700
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
1572 /*
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
1573 %!test
7886
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1574 %! AA = A.';
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1575 %! i = 2; j = 4; p = [1:i-1, shift(i:j,-1), j+1:5];
7700
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
1576 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1577 %! [Q,R] = qr (AA);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1578 %! [Q,R] = qrshift (Q, R, i, j);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1579 %! assert (norm (vec (Q'*Q - eye (3)), Inf) < 1e1*eps);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1580 %! assert (norm (vec (triu (R) - R), Inf) == 0);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1581 %! assert (norm (vec (Q*R - AA(:,p)), Inf) < norm (AA)*1e1*eps);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
1582 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1583 %! j = 2; i = 4; p = [1:j-1, shift(j:i,+1), i+1:5];
7886
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1584 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1585 %! [Q,R] = qr (AA);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1586 %! [Q,R] = qrshift (Q, R, i, j);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1587 %! assert (norm (vec (Q'*Q - eye (3)), Inf) < 1e1*eps);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1588 %! assert (norm (vec (triu (R) - R), Inf) == 0);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1589 %! assert (norm (vec (Q*R - AA(:,p)), Inf) < norm (AA)*1e1*eps);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
1590 %!
7886
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1591 %!test
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1592 %! AA = Ac.';
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1593 %! i = 2; j = 4; p = [1:i-1, shift(i:j,-1), j+1:5];
7886
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1594 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1595 %! [Q,R] = qr (AA);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1596 %! [Q,R] = qrshift (Q, R, i, j);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1597 %! assert (norm (vec (Q'*Q - eye (3)), Inf) < 1e1*eps);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1598 %! assert (norm (vec (triu (R) - R), Inf) == 0);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1599 %! assert (norm (vec (Q*R - AA(:,p)), Inf) < norm (AA)*1e1*eps);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
1600 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1601 %! j = 2; i = 4; p = [1:j-1, shift(j:i,+1), i+1:5];
7700
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
1602 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1603 %! [Q,R] = qr (AA);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1604 %! [Q,R] = qrshift (Q, R, i, j);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1605 %! assert (norm (vec (Q'*Q - eye (3)), Inf) < 1e1*eps);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1606 %! assert (norm (vec (triu (R) - R), Inf) == 0);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1607 %! assert (norm (vec (Q*R - AA(:,p)), Inf) < norm (AA)*1e1*eps);
7886
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1608
7700
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
1609 %!test
7886
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1610 %! AA = single (A).';
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1611 %! i = 2; j = 4; p = [1:i-1, shift(i:j,-1), j+1:5];
7700
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
1612 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1613 %! [Q,R] = qr (AA);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1614 %! [Q,R] = qrshift (Q, R, i, j);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1615 %! assert (norm (vec (Q'*Q - eye (3,"single")), Inf) < 1e1*eps ("single"));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1616 %! assert (norm (vec (triu (R) - R), Inf) == 0);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1617 %! assert (norm (vec (Q*R - AA(:,p)), Inf) < norm (AA)*1e1*eps ("single"));
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
1618 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1619 %! j = 2; i = 4; p = [1:j-1, shift(j:i,+1), i+1:5];
7700
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
1620 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1621 %! [Q,R] = qr (AA);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1622 %! [Q,R] = qrshift (Q, R, i, j);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1623 %! assert (norm (vec (Q'*Q - eye (3,"single")), Inf) < 1e1*eps ("single"));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1624 %! assert (norm (vec (triu (R) - R), Inf) == 0);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1625 %! assert (norm (vec (Q*R - AA(:,p)), Inf) < norm (AA)*1e1*eps ("single"));
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
1626 %!
7886
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1627 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1628 %! AA = single (Ac).';
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1629 %! i = 2; j = 4; p = [1:i-1, shift(i:j,-1), j+1:5];
7886
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1630 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1631 %! [Q,R] = qr (AA);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1632 %! [Q,R] = qrshift (Q, R, i, j);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1633 %! assert (norm (vec (Q'*Q - eye (3,"single")), Inf) < 1e1*eps ("single"));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1634 %! assert (norm (vec (triu (R) - R), Inf) == 0);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1635 %! assert (norm (vec (Q*R - AA(:,p)), Inf) < norm (AA)*1e1*eps ("single"));
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
1636 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1637 %! j = 2; i = 4; p = [1:j-1, shift(j:i,+1), i+1:5];
7886
e3e94982dfd4 Convert qrshift, qrinsert, qrdelete, qrupdate to allow single precision arguments
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1638 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1639 %! [Q,R] = qr (AA);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1640 %! [Q,R] = qrshift (Q, R, i, j);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1641 %! assert (norm (vec (Q'*Q - eye (3,"single")), Inf) < 1e1*eps ("single"));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1642 %! assert (norm (vec (triu (R) - R), Inf) == 0);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1643 %! assert (norm (vec (Q*R - AA(:,p)), Inf) < norm (AA)*1e1*eps ("single"));
7700
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
1644 */