GNU Octave  3.8.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
base-qr.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2009-2013 Jaroslav Hajek
4 
5 This file is part of Octave.
6 
7 Octave is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26 
27 #include "base-qr.h"
28 
29 template <class qr_type>
30 base_qr<qr_type>::base_qr (const qr_type& q_arg, const qr_type& r_arg)
31  : q (q_arg), r (r_arg)
32 {
33  octave_idx_type q_nr = q.rows (), q_nc = q.columns ();
34  octave_idx_type r_nr = r.rows (), r_nc = r.columns ();
35 
36  if (! (q_nc == r_nr && (q_nr == q_nc || (q_nr > q_nc && r_nr == r_nc))))
37  {
38  q = qr_type ();
39  r = qr_type ();
40 
41  (*current_liboctave_error_handler) ("QR dimensions mismatch");
42  }
43 }
44 
45 template <class qr_type>
48 {
49  qr_type_t retval;
50 
51  if (!q.is_empty () && q.is_square ())
52  retval = qr_type_std;
53  else if (q.rows () > q.columns () && r.is_square ())
54  retval = qr_type_economy;
55  else
56  retval = qr_type_raw;
57 
58  return retval;
59 }
60 
61 template <class qr_type>
62 bool
64 {
65  bool retval = true;
66 
67  octave_idx_type k = std::min (r.rows (), r.columns ());
68 
69  for (octave_idx_type i = 0; i < k; i++)
70  {
71  if (r(i, i) == qr_elt_type ())
72  {
73  retval = false;
74  break;
75  }
76  }
77 
78  return retval;
79 }
80