annotate liboctave/array/DiagArray2.cc @ 21136:7cac4e7458f2

maint: clean up code around calls to current_liboctave_error_handler. Remove statements after call to handler that are no longer reachable. Place input validation first and immediately call handler if necessary. Change if/error_handler/else to if/error_handler and re-indent code. * Array-util.cc, Array.cc, CColVector.cc, CDiagMatrix.cc, CMatrix.cc, CNDArray.cc, CRowVector.cc, CSparse.cc, DiagArray2.cc, MArray.cc, PermMatrix.cc, Sparse.cc, Sparse.h, chMatrix.cc, chNDArray.cc, dColVector.cc, dDiagMatrix.cc, dMatrix.cc, dNDArray.cc, dRowVector.cc, dSparse.cc, fCColVector.cc, fCDiagMatrix.cc, fCMatrix.cc, fCNDArray.cc, fCRowVector.cc, fColVector.cc, fDiagMatrix.cc, fMatrix.cc, fNDArray.cc, fRowVector.cc, idx-vector.cc, CmplxAEPBAL.cc, CmplxCHOL.cc, CmplxGEPBAL.cc, CmplxHESS.cc, CmplxLU.cc, CmplxQR.cc, CmplxSCHUR.cc, CmplxSVD.cc, DASPK.cc, EIG.cc, LSODE.cc, Quad.cc, SparseCmplxCHOL.cc, SparseCmplxLU.cc, SparseCmplxQR.cc, SparseQR.cc, SparsedbleCHOL.cc, SparsedbleLU.cc, base-lu.cc, bsxfun-defs.cc, dbleAEPBAL.cc, dbleCHOL.cc, dbleGEPBAL.cc, dbleHESS.cc, dbleLU.cc, dbleQR.cc, dbleSCHUR.cc, dbleSVD.cc, eigs-base.cc, fCmplxAEPBAL.cc, fCmplxCHOL.cc, fCmplxLU.cc, fCmplxQR.cc, fCmplxSCHUR.cc, fEIG.cc, floatAEPBAL.cc, floatCHOL.cc, floatGEPBAL.cc, floatHESS.cc, floatLU.cc, floatQR.cc, floatSCHUR.cc, floatSVD.cc, lo-specfun.cc, oct-fftw.cc, oct-rand.cc, oct-spparms.cc, sparse-base-chol.cc, sparse-dmsolve.cc, file-ops.cc, lo-sysdep.cc, mach-info.cc, oct-env.cc, oct-syscalls.cc, cmd-edit.cc, cmd-hist.cc, data-conv.cc, lo-ieee.cc, lo-regexp.cc, oct-base64.cc, oct-shlib.cc, pathsearch.cc, singleton-cleanup.cc, sparse-util.cc, unwind-prot.cc: Remove statements after call to handler that are no longer reachable. Place input validation first and immediately call handler if necessary. Change if/error_handler/else to if/error_handler and re-indent code.
author Rik <rik@octave.org>
date Sat, 23 Jan 2016 13:52:03 -0800
parents 228b65504557
children 538b57866b90
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1993
1b57120c997b [project @ 1996-03-03 01:16:15 by jwe]
jwe
parents: 1988
diff changeset
1 // Template array classes
1988
7b56630a1e05 [project @ 1996-03-02 00:33:22 by jwe]
jwe
parents:
diff changeset
2 /*
7b56630a1e05 [project @ 1996-03-02 00:33:22 by jwe]
jwe
parents:
diff changeset
3
19697
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 18146
diff changeset
4 Copyright (C) 1996-2015 John W. Eaton
10521
4d1fc073fbb7 add some missing copyright stmts
Jaroslav Hajek <highegg@gmail.com>
parents: 10366
diff changeset
5 Copyright (C) 2010 VZLU Prague
1988
7b56630a1e05 [project @ 1996-03-02 00:33:22 by jwe]
jwe
parents:
diff changeset
6
7b56630a1e05 [project @ 1996-03-02 00:33:22 by jwe]
jwe
parents:
diff changeset
7 This file is part of Octave.
7b56630a1e05 [project @ 1996-03-02 00:33:22 by jwe]
jwe
parents:
diff changeset
8
7b56630a1e05 [project @ 1996-03-02 00:33:22 by jwe]
jwe
parents:
diff changeset
9 Octave is free software; you can redistribute it and/or modify it
7b56630a1e05 [project @ 1996-03-02 00:33:22 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: 5307
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: 5307
diff changeset
12 option) any later version.
1988
7b56630a1e05 [project @ 1996-03-02 00:33:22 by jwe]
jwe
parents:
diff changeset
13
7b56630a1e05 [project @ 1996-03-02 00:33:22 by jwe]
jwe
parents:
diff changeset
14 Octave is distributed in the hope that it will be useful, but WITHOUT
7b56630a1e05 [project @ 1996-03-02 00:33:22 by jwe]
jwe
parents:
diff changeset
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
7b56630a1e05 [project @ 1996-03-02 00:33:22 by jwe]
jwe
parents:
diff changeset
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
7b56630a1e05 [project @ 1996-03-02 00:33:22 by jwe]
jwe
parents:
diff changeset
17 for more details.
7b56630a1e05 [project @ 1996-03-02 00:33:22 by jwe]
jwe
parents:
diff changeset
18
7b56630a1e05 [project @ 1996-03-02 00:33:22 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: 5307
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: 5307
diff changeset
21 <http://www.gnu.org/licenses/>.
1988
7b56630a1e05 [project @ 1996-03-02 00:33:22 by jwe]
jwe
parents:
diff changeset
22
7b56630a1e05 [project @ 1996-03-02 00:33:22 by jwe]
jwe
parents:
diff changeset
23 */
7b56630a1e05 [project @ 1996-03-02 00:33:22 by jwe]
jwe
parents:
diff changeset
24
7b56630a1e05 [project @ 1996-03-02 00:33:22 by jwe]
jwe
parents:
diff changeset
25 #ifdef HAVE_CONFIG_H
7b56630a1e05 [project @ 1996-03-02 00:33:22 by jwe]
jwe
parents:
diff changeset
26 #include <config.h>
7b56630a1e05 [project @ 1996-03-02 00:33:22 by jwe]
jwe
parents:
diff changeset
27 #endif
7b56630a1e05 [project @ 1996-03-02 00:33:22 by jwe]
jwe
parents:
diff changeset
28
7b56630a1e05 [project @ 1996-03-02 00:33:22 by jwe]
jwe
parents:
diff changeset
29 #include <cassert>
7b56630a1e05 [project @ 1996-03-02 00:33:22 by jwe]
jwe
parents:
diff changeset
30
3503
d14c483b3c12 [project @ 2000-02-01 04:06:07 by jwe]
jwe
parents: 3333
diff changeset
31 #include <iostream>
1988
7b56630a1e05 [project @ 1996-03-02 00:33:22 by jwe]
jwe
parents:
diff changeset
32
8375
e3c9102431a9 fix design problems of diag & perm matrix classes
Jaroslav Hajek <highegg@gmail.com>
parents: 8366
diff changeset
33 #include <algorithm>
e3c9102431a9 fix design problems of diag & perm matrix classes
Jaroslav Hajek <highegg@gmail.com>
parents: 8366
diff changeset
34
1988
7b56630a1e05 [project @ 1996-03-02 00:33:22 by jwe]
jwe
parents:
diff changeset
35 #include "DiagArray2.h"
7b56630a1e05 [project @ 1996-03-02 00:33:22 by jwe]
jwe
parents:
diff changeset
36
7b56630a1e05 [project @ 1996-03-02 00:33:22 by jwe]
jwe
parents:
diff changeset
37 #include "lo-error.h"
7b56630a1e05 [project @ 1996-03-02 00:33:22 by jwe]
jwe
parents:
diff changeset
38
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
39 template <class T>
11574
a83bad07f7e3 attempt better backward compatibility for Array resize functions
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
40 DiagArray2<T>::DiagArray2 (const Array<T>& a, octave_idx_type r,
a83bad07f7e3 attempt better backward compatibility for Array resize functions
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
41 octave_idx_type c)
10363
a0728e81ed25 improve diag matrix interface & implementation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
42 : Array<T> (a.as_column ()), d1 (r), d2 (c)
8524
937921654627 clean up Array and DiagArray2
Jaroslav Hajek <highegg@gmail.com>
parents: 8523
diff changeset
43 {
10363
a0728e81ed25 improve diag matrix interface & implementation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
44 octave_idx_type rcmin = std::min (r, c);
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 19697
diff changeset
45 if (rcmin != a.numel ())
11574
a83bad07f7e3 attempt better backward compatibility for Array resize functions
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
46 Array<T>::resize (dim_vector (rcmin, 1));
8524
937921654627 clean up Array and DiagArray2
Jaroslav Hajek <highegg@gmail.com>
parents: 8523
diff changeset
47 }
937921654627 clean up Array and DiagArray2
Jaroslav Hajek <highegg@gmail.com>
parents: 8523
diff changeset
48
937921654627 clean up Array and DiagArray2
Jaroslav Hajek <highegg@gmail.com>
parents: 8523
diff changeset
49 template <class T>
8375
e3c9102431a9 fix design problems of diag & perm matrix classes
Jaroslav Hajek <highegg@gmail.com>
parents: 8366
diff changeset
50 Array<T>
15430
21467c7fc08f Deprecate DiagArray2<T>::diag
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 15429
diff changeset
51 DiagArray2<T>::diag (octave_idx_type k) const
15428
fd5c0159b588 Fix diag handling of diagvectors (bug #37411)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14628
diff changeset
52 {
15430
21467c7fc08f Deprecate DiagArray2<T>::diag
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 15429
diff changeset
53 return extract_diag (k);
15428
fd5c0159b588 Fix diag handling of diagvectors (bug #37411)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14628
diff changeset
54 }
fd5c0159b588 Fix diag handling of diagvectors (bug #37411)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14628
diff changeset
55
fd5c0159b588 Fix diag handling of diagvectors (bug #37411)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14628
diff changeset
56 template <class T>
fd5c0159b588 Fix diag handling of diagvectors (bug #37411)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14628
diff changeset
57 Array<T>
15430
21467c7fc08f Deprecate DiagArray2<T>::diag
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 15429
diff changeset
58 DiagArray2<T>::extract_diag (octave_idx_type k) const
8375
e3c9102431a9 fix design problems of diag & perm matrix classes
Jaroslav Hajek <highegg@gmail.com>
parents: 8366
diff changeset
59 {
e3c9102431a9 fix design problems of diag & perm matrix classes
Jaroslav Hajek <highegg@gmail.com>
parents: 8366
diff changeset
60 Array<T> d;
e3c9102431a9 fix design problems of diag & perm matrix classes
Jaroslav Hajek <highegg@gmail.com>
parents: 8366
diff changeset
61
e3c9102431a9 fix design problems of diag & perm matrix classes
Jaroslav Hajek <highegg@gmail.com>
parents: 8366
diff changeset
62 if (k == 0)
8524
937921654627 clean up Array and DiagArray2
Jaroslav Hajek <highegg@gmail.com>
parents: 8523
diff changeset
63 // The main diagonal is shallow-copied.
937921654627 clean up Array and DiagArray2
Jaroslav Hajek <highegg@gmail.com>
parents: 8523
diff changeset
64 d = *this;
8375
e3c9102431a9 fix design problems of diag & perm matrix classes
Jaroslav Hajek <highegg@gmail.com>
parents: 8366
diff changeset
65 else if (k > 0 && k < cols ())
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
66 d = Array<T> (dim_vector (std::min (cols () - k, rows ()), 1), T ());
8375
e3c9102431a9 fix design problems of diag & perm matrix classes
Jaroslav Hajek <highegg@gmail.com>
parents: 8366
diff changeset
67 else if (k < 0 && -k < rows ())
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
68 d = Array<T> (dim_vector (std::min (rows () + k, cols ()), 1), T ());
18146
a86d608c413c Return empty matrix rather than issuing error when requested diagonal is out of range.
Marco Caliari <marco.caliari@univr.it>
parents: 17744
diff changeset
69 else // Matlab returns [] 0x1 for out-of-range diagonal
a86d608c413c Return empty matrix rather than issuing error when requested diagonal is out of range.
Marco Caliari <marco.caliari@univr.it>
parents: 17744
diff changeset
70 d.resize (dim_vector (0, 1));
8375
e3c9102431a9 fix design problems of diag & perm matrix classes
Jaroslav Hajek <highegg@gmail.com>
parents: 8366
diff changeset
71
e3c9102431a9 fix design problems of diag & perm matrix classes
Jaroslav Hajek <highegg@gmail.com>
parents: 8366
diff changeset
72 return d;
e3c9102431a9 fix design problems of diag & perm matrix classes
Jaroslav Hajek <highegg@gmail.com>
parents: 8366
diff changeset
73 }
e3c9102431a9 fix design problems of diag & perm matrix classes
Jaroslav Hajek <highegg@gmail.com>
parents: 8366
diff changeset
74
e3c9102431a9 fix design problems of diag & perm matrix classes
Jaroslav Hajek <highegg@gmail.com>
parents: 8366
diff changeset
75 template <class T>
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
76 DiagArray2<T>
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
77 DiagArray2<T>::transpose (void) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
78 {
10363
a0728e81ed25 improve diag matrix interface & implementation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
79 return DiagArray2<T> (*this, d2, d1);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
80 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
81
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
82 template <class T>
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
83 DiagArray2<T>
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
84 DiagArray2<T>::hermitian (T (* fcn) (const T&)) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
85 {
10363
a0728e81ed25 improve diag matrix interface & implementation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
86 return DiagArray2<T> (Array<T>::template map<T> (fcn), d2, d1);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
87 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
88
1988
7b56630a1e05 [project @ 1996-03-02 00:33:22 by jwe]
jwe
parents:
diff changeset
89 // A two-dimensional array with diagonal elements only.
7b56630a1e05 [project @ 1996-03-02 00:33:22 by jwe]
jwe
parents:
diff changeset
90
7b56630a1e05 [project @ 1996-03-02 00:33:22 by jwe]
jwe
parents:
diff changeset
91 template <class T>
7b56630a1e05 [project @ 1996-03-02 00:33:22 by jwe]
jwe
parents:
diff changeset
92 void
10350
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10158
diff changeset
93 DiagArray2<T>::resize (octave_idx_type r, octave_idx_type c,
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10158
diff changeset
94 const T& rfv)
1988
7b56630a1e05 [project @ 1996-03-02 00:33:22 by jwe]
jwe
parents:
diff changeset
95 {
7b56630a1e05 [project @ 1996-03-02 00:33:22 by jwe]
jwe
parents:
diff changeset
96 if (r < 0 || c < 0)
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
97 (*current_liboctave_error_handler) ("can't resize to negative dimensions");
1988
7b56630a1e05 [project @ 1996-03-02 00:33:22 by jwe]
jwe
parents:
diff changeset
98
8524
937921654627 clean up Array and DiagArray2
Jaroslav Hajek <highegg@gmail.com>
parents: 8523
diff changeset
99 if (r != dim1 () || c != dim2 ())
1988
7b56630a1e05 [project @ 1996-03-02 00:33:22 by jwe]
jwe
parents:
diff changeset
100 {
11574
a83bad07f7e3 attempt better backward compatibility for Array resize functions
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
101 Array<T>::resize (dim_vector (std::min (r, c), 1), rfv);
8524
937921654627 clean up Array and DiagArray2
Jaroslav Hajek <highegg@gmail.com>
parents: 8523
diff changeset
102 d1 = r; d2 = c;
937921654627 clean up Array and DiagArray2
Jaroslav Hajek <highegg@gmail.com>
parents: 8523
diff changeset
103 }
937921654627 clean up Array and DiagArray2
Jaroslav Hajek <highegg@gmail.com>
parents: 8523
diff changeset
104 }
1988
7b56630a1e05 [project @ 1996-03-02 00:33:22 by jwe]
jwe
parents:
diff changeset
105
8524
937921654627 clean up Array and DiagArray2
Jaroslav Hajek <highegg@gmail.com>
parents: 8523
diff changeset
106 template <class T>
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
107 Array<T>
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
108 DiagArray2<T>::array_value (void) const
8524
937921654627 clean up Array and DiagArray2
Jaroslav Hajek <highegg@gmail.com>
parents: 8523
diff changeset
109 {
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
110 Array<T> result (dims (), T (0));
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
111
8524
937921654627 clean up Array and DiagArray2
Jaroslav Hajek <highegg@gmail.com>
parents: 8523
diff changeset
112 for (octave_idx_type i = 0, len = length (); i < len; i++)
937921654627 clean up Array and DiagArray2
Jaroslav Hajek <highegg@gmail.com>
parents: 8523
diff changeset
113 result.xelem (i, i) = dgelem (i);
1988
7b56630a1e05 [project @ 1996-03-02 00:33:22 by jwe]
jwe
parents:
diff changeset
114
8524
937921654627 clean up Array and DiagArray2
Jaroslav Hajek <highegg@gmail.com>
parents: 8523
diff changeset
115 return result;
1988
7b56630a1e05 [project @ 1996-03-02 00:33:22 by jwe]
jwe
parents:
diff changeset
116 }
14628
63ae976ac2e7 preserve DiagArray2 interface for stable release series
John W. Eaton <jwe@octave.org>
parents: 14590
diff changeset
117
63ae976ac2e7 preserve DiagArray2 interface for stable release series
John W. Eaton <jwe@octave.org>
parents: 14590
diff changeset
118 template <typename T>
63ae976ac2e7 preserve DiagArray2 interface for stable release series
John W. Eaton <jwe@octave.org>
parents: 14590
diff changeset
119 bool
63ae976ac2e7 preserve DiagArray2 interface for stable release series
John W. Eaton <jwe@octave.org>
parents: 14590
diff changeset
120 DiagArray2<T>::check_idx (octave_idx_type r, octave_idx_type c) const
63ae976ac2e7 preserve DiagArray2 interface for stable release series
John W. Eaton <jwe@octave.org>
parents: 14590
diff changeset
121 {
63ae976ac2e7 preserve DiagArray2 interface for stable release series
John W. Eaton <jwe@octave.org>
parents: 14590
diff changeset
122 bool ok = true;
63ae976ac2e7 preserve DiagArray2 interface for stable release series
John W. Eaton <jwe@octave.org>
parents: 14590
diff changeset
123
63ae976ac2e7 preserve DiagArray2 interface for stable release series
John W. Eaton <jwe@octave.org>
parents: 14590
diff changeset
124 if (r < 0 || r >= dim1 ())
21129
228b65504557 maint: Eliminate useless statements after err_XXX.
Rik <rik@octave.org>
parents: 21100
diff changeset
125 err_index_out_of_range (2, 1, r+1, dim1 (), dims ());
14628
63ae976ac2e7 preserve DiagArray2 interface for stable release series
John W. Eaton <jwe@octave.org>
parents: 14590
diff changeset
126
63ae976ac2e7 preserve DiagArray2 interface for stable release series
John W. Eaton <jwe@octave.org>
parents: 14590
diff changeset
127 if (c < 0 || c >= dim2 ())
21129
228b65504557 maint: Eliminate useless statements after err_XXX.
Rik <rik@octave.org>
parents: 21100
diff changeset
128 err_index_out_of_range (2, 2, c+1, dim2 (), dims ());
14628
63ae976ac2e7 preserve DiagArray2 interface for stable release series
John W. Eaton <jwe@octave.org>
parents: 14590
diff changeset
129
63ae976ac2e7 preserve DiagArray2 interface for stable release series
John W. Eaton <jwe@octave.org>
parents: 14590
diff changeset
130 return ok;
63ae976ac2e7 preserve DiagArray2 interface for stable release series
John W. Eaton <jwe@octave.org>
parents: 14590
diff changeset
131 }