annotate libinterp/octave-value/ov-base-diag.cc @ 33362:2949b89f9711

replace most uses of panic_impossible with error in octave_value classes * ov-base-diag.cc, ov-base-mat.cc, ov-base-scalar.cc, ov-base-sparse.cc, ov-base.cc, ov-bool-mat.cc, ov-cell.cc, ov-class.cc, ov-cx-mat.cc, ov-fcn-handle.cc, ov-flt-cx-mat.cc, ov-flt-re-mat.cc, ov-perm.cc, ov-range.cc, ov-re-mat.cc, ov-str-mat.cc, ov-struct.cc, ov-usr-fcn.cc: Replace all uses of panic_impossible with error.
author John W. Eaton <jwe@octave.org>
date Mon, 08 Apr 2024 19:39:34 -0400
parents 4b601ca024d5
children 976638dd9021
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ////////////////////////////////////////////////////////////////////////
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 //
32632
2e484f9f1f18 maint: update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 31898
diff changeset
3 // Copyright (C) 2008-2024 The Octave Project Developers
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
4 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 // See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 // distribution or <https://octave.org/copyright/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
7 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
8 // This file is part of Octave.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
9 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
10 // Octave is free software: you can redistribute it and/or modify it
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
11 // under the terms of the GNU General Public License as published by
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
12 // the Free Software Foundation, either version 3 of the License, or
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
13 // (at your option) any later version.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
14 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
15 // Octave is distributed in the hope that it will be useful, but
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
18 // GNU General Public License for more details.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
19 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
20 // You should have received a copy of the GNU General Public License
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
21 // along with Octave; see the file COPYING. If not, see
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
22 // <https://www.gnu.org/licenses/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ////////////////////////////////////////////////////////////////////////
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
25
21690
b6a686543080 Only include config.h in files that are compiled separately.
John W. Eaton <jwe@octave.org>
parents: 21660
diff changeset
26 // This file should not include config.h. It is only included in other
b6a686543080 Only include config.h in files that are compiled separately.
John W. Eaton <jwe@octave.org>
parents: 21660
diff changeset
27 // C++ source files that should have included config.h before including
b6a686543080 Only include config.h in files that are compiled separately.
John W. Eaton <jwe@octave.org>
parents: 21660
diff changeset
28 // this file.
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
29
25438
cb1606f78f6b prefer <istream>, <ostream>, or <iosfwd> to <iostream> where possible
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
30 #include <istream>
cb1606f78f6b prefer <istream>, <ostream>, or <iosfwd> to <iostream> where possible
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
31 #include <ostream>
cb1606f78f6b prefer <istream>, <ostream>, or <iosfwd> to <iostream> where possible
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
32 #include <sstream>
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
33
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
34 #include "mach-info.h"
9003
0631d397fbe0 replace lo_ieee_isnan by xisnan, add missing includes
Jaroslav Hajek <highegg@gmail.com>
parents: 8960
diff changeset
35 #include "lo-ieee.h"
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
36
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20447
diff changeset
37 #include "ov-base-diag.h"
15149
62a35ae7d6a2 use forward decls for mxArray in ov.h and ov-base.h
John W. Eaton <jwe@octave.org>
parents: 15057
diff changeset
38 #include "mxarray.h"
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
39 #include "ov-base.h"
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
40 #include "ov-base-mat.h"
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
41 #include "pr-output.h"
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
42 #include "error.h"
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 20978
diff changeset
43 #include "errwarn.h"
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
44 #include "oct-stream.h"
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
45 #include "ops.h"
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
46
20447
c6224b4e7774 maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents: 19697
diff changeset
47 #include "ls-oct-text.h"
8376
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
48
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21124
diff changeset
49 template <typename DMT, typename MT>
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
50 octave_value
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
51 octave_base_diag<DMT, MT>::subsref (const std::string& type,
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
52 const std::list<octave_value_list>& idx)
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
53 {
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
54 octave_value retval;
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
55
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
56 switch (type[0])
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
57 {
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
58 case '(':
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
59 retval = do_index_op (idx.front ());
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
60 break;
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
61
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
62 case '{':
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
63 case '.':
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
64 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9812
diff changeset
65 std::string nm = type_name ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9812
diff changeset
66 error ("%s cannot be indexed with %c", nm.c_str (), type[0]);
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
67 }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
68 break;
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
69
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
70 default:
33362
2949b89f9711 replace most uses of panic_impossible with error in octave_value classes
John W. Eaton <jwe@octave.org>
parents: 32633
diff changeset
71 error ("unexpected: index not '(', '{', or '.' in octave_base_diag<DMT,MT>::subsref - please report this bug");
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
72 }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
73
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
74 return retval.next_subsref (type, idx);
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
75 }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
76
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21124
diff changeset
77 template <typename DMT, typename MT>
15428
fd5c0159b588 Fix diag handling of diagvectors (bug #37411)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14590
diff changeset
78 octave_value
30390
a61e1a0f6024 maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 30139
diff changeset
79 octave_base_diag<DMT, MT>::diag (octave_idx_type k) const
15428
fd5c0159b588 Fix diag handling of diagvectors (bug #37411)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14590
diff changeset
80 {
fd5c0159b588 Fix diag handling of diagvectors (bug #37411)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14590
diff changeset
81 octave_value retval;
30135
606652e9f446 maint: use "m_" prefix for member variables in class octave_base_diag.
Rik <rik@octave.org>
parents: 30133
diff changeset
82 if (m_matrix.rows () == 1 || m_matrix.cols () == 1)
15428
fd5c0159b588 Fix diag handling of diagvectors (bug #37411)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14590
diff changeset
83 {
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21739
diff changeset
84 // Rather odd special case. This is a row or column vector
15428
fd5c0159b588 Fix diag handling of diagvectors (bug #37411)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14590
diff changeset
85 // represented as a diagonal matrix with a single nonzero entry, but
fd5c0159b588 Fix diag handling of diagvectors (bug #37411)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14590
diff changeset
86 // Fdiag semantics are to product a diagonal matrix for vector
fd5c0159b588 Fix diag handling of diagvectors (bug #37411)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14590
diff changeset
87 // inputs.
fd5c0159b588 Fix diag handling of diagvectors (bug #37411)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14590
diff changeset
88 if (k == 0)
fd5c0159b588 Fix diag handling of diagvectors (bug #37411)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14590
diff changeset
89 // Returns Diag2Array<T> with nnz <= 1.
30135
606652e9f446 maint: use "m_" prefix for member variables in class octave_base_diag.
Rik <rik@octave.org>
parents: 30133
diff changeset
90 retval = m_matrix.build_diag_matrix ();
15428
fd5c0159b588 Fix diag handling of diagvectors (bug #37411)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14590
diff changeset
91 else
fd5c0159b588 Fix diag handling of diagvectors (bug #37411)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14590
diff changeset
92 // Returns Array<T> matrix
30135
606652e9f446 maint: use "m_" prefix for member variables in class octave_base_diag.
Rik <rik@octave.org>
parents: 30133
diff changeset
93 retval = m_matrix.array_value ().diag (k);
15428
fd5c0159b588 Fix diag handling of diagvectors (bug #37411)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14590
diff changeset
94 }
fd5c0159b588 Fix diag handling of diagvectors (bug #37411)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14590
diff changeset
95 else
fd5c0159b588 Fix diag handling of diagvectors (bug #37411)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14590
diff changeset
96 // Returns Array<T> vector
30135
606652e9f446 maint: use "m_" prefix for member variables in class octave_base_diag.
Rik <rik@octave.org>
parents: 30133
diff changeset
97 retval = m_matrix.extract_diag (k);
15428
fd5c0159b588 Fix diag handling of diagvectors (bug #37411)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14590
diff changeset
98 return retval;
fd5c0159b588 Fix diag handling of diagvectors (bug #37411)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14590
diff changeset
99 }
fd5c0159b588 Fix diag handling of diagvectors (bug #37411)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14590
diff changeset
100
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21124
diff changeset
101 template <typename DMT, typename MT>
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
102 octave_value
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
103 octave_base_diag<DMT, MT>::do_index_op (const octave_value_list& idx,
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
104 bool resize_ok)
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
105 {
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
106 octave_value retval;
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8366
diff changeset
107
8960
93f18f166aba remove float perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
108 if (idx.length () == 2 && ! resize_ok)
93f18f166aba remove float perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
109 {
27956
2310164737b3 fix many spelling errors (bug #57613)
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
110 int k = 0; // index we're accessing when index_vector throws
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20447
diff changeset
111 try
8459
d17874a6f161 improve indexing of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8437
diff changeset
112 {
29569
29a1f8fd8ee6 move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
113 octave::idx_vector idx0 = idx(0).index_vector ();
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20447
diff changeset
114 k = 1;
29569
29a1f8fd8ee6 move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
115 octave::idx_vector idx1 = idx(1).index_vector ();
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20447
diff changeset
116
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20447
diff changeset
117 if (idx0.is_scalar () && idx1.is_scalar ())
8459
d17874a6f161 improve indexing of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8437
diff changeset
118 {
30135
606652e9f446 maint: use "m_" prefix for member variables in class octave_base_diag.
Rik <rik@octave.org>
parents: 30133
diff changeset
119 retval = m_matrix.checkelem (idx0(0), idx1(0));
8459
d17874a6f161 improve indexing of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8437
diff changeset
120 }
d17874a6f161 improve indexing of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8437
diff changeset
121 else
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20447
diff changeset
122 {
30135
606652e9f446 maint: use "m_" prefix for member variables in class octave_base_diag.
Rik <rik@octave.org>
parents: 30133
diff changeset
123 octave_idx_type m = idx0.length (m_matrix.rows ());
606652e9f446 maint: use "m_" prefix for member variables in class octave_base_diag.
Rik <rik@octave.org>
parents: 30133
diff changeset
124 octave_idx_type n = idx1.length (m_matrix.columns ());
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20447
diff changeset
125 if (idx0.is_colon_equiv (m) && idx1.is_colon_equiv (n)
30135
606652e9f446 maint: use "m_" prefix for member variables in class octave_base_diag.
Rik <rik@octave.org>
parents: 30133
diff changeset
126 && m <= m_matrix.rows () && n <= m_matrix.rows ())
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20447
diff changeset
127 {
30135
606652e9f446 maint: use "m_" prefix for member variables in class octave_base_diag.
Rik <rik@octave.org>
parents: 30133
diff changeset
128 DMT rm (m_matrix);
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20447
diff changeset
129 rm.resize (m, n);
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20447
diff changeset
130 retval = rm;
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20447
diff changeset
131 }
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20447
diff changeset
132 else
28631
70cdf8de553d move non-member octave_value operator functions to octave namespace
John W. Eaton <jwe@octave.org>
parents: 28126
diff changeset
133 retval = to_dense ().index_op (idx, resize_ok);
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20447
diff changeset
134 }
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20447
diff changeset
135 }
29163
8f67ad8b3103 maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents: 28631
diff changeset
136 catch (octave::index_exception& ie)
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20447
diff changeset
137 {
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20447
diff changeset
138 // Rethrow to allow more info to be reported later.
29163
8f67ad8b3103 maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents: 28631
diff changeset
139 ie.set_pos_if_unset (2, k+1);
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20447
diff changeset
140 throw;
8459
d17874a6f161 improve indexing of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8437
diff changeset
141 }
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8366
diff changeset
142 }
8960
93f18f166aba remove float perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
143 else
28631
70cdf8de553d move non-member octave_value operator functions to octave namespace
John W. Eaton <jwe@octave.org>
parents: 28126
diff changeset
144 retval = to_dense ().index_op (idx, resize_ok);
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8366
diff changeset
145
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
146 return retval;
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
147 }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
148
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21124
diff changeset
149 template <typename DMT, typename MT>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
150 octave_value
8398
d95282fa0579 allow element assignment to diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
151 octave_base_diag<DMT, MT>::subsasgn (const std::string& type,
d95282fa0579 allow element assignment to diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
152 const std::list<octave_value_list>& idx,
d95282fa0579 allow element assignment to diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
153 const octave_value& rhs)
d95282fa0579 allow element assignment to diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
154 {
d95282fa0579 allow element assignment to diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
155 octave_value retval;
d95282fa0579 allow element assignment to diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
156
d95282fa0579 allow element assignment to diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
157 switch (type[0])
d95282fa0579 allow element assignment to diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
158 {
d95282fa0579 allow element assignment to diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
159 case '(':
d95282fa0579 allow element assignment to diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
160 {
20978
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
161 if (type.length () != 1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9812
diff changeset
162 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9812
diff changeset
163 std::string nm = type_name ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9812
diff changeset
164 error ("in indexed assignment of %s, last lhs index must be ()",
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9812
diff changeset
165 nm.c_str ());
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9812
diff changeset
166 }
20978
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
167
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
168 octave_value_list jdx = idx.front ();
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
169
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
170 // FIXME: Mostly repeated code for cases 1 and 2 could be
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
171 // consolidated for DRY (Don't Repeat Yourself).
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
172 // Check for assignments to diagonal elements which should not
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
173 // destroy the diagonal property of the matrix.
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
174 // If D is a diagonal matrix then the assignment can be
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
175 // 1) linear, D(i) = x, where ind2sub results in case #2 below
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
176 // 2) subscript D(i,i) = x, where both indices are equal.
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
177 if (jdx.length () == 1 && jdx(0).is_scalar_type ())
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
178 {
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
179 typename DMT::element_type val;
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
180 int k = 0;
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
181 try
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
182 {
29569
29a1f8fd8ee6 move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
183 octave::idx_vector ind = jdx(0).index_vector ();
20978
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
184 k = 1;
30135
606652e9f446 maint: use "m_" prefix for member variables in class octave_base_diag.
Rik <rik@octave.org>
parents: 30133
diff changeset
185 dim_vector dv (m_matrix.rows (), m_matrix.cols ());
29569
29a1f8fd8ee6 move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
186 Array<octave::idx_vector> ivec = ind2sub (dv, ind);
29a1f8fd8ee6 move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
187 octave::idx_vector i0 = ivec(0);
29a1f8fd8ee6 move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
188 octave::idx_vector i1 = ivec(1);
20978
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
189
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
190 if (i0(0) == i1(0)
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
191 && chk_valid_scalar (rhs, val))
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
192 {
30135
606652e9f446 maint: use "m_" prefix for member variables in class octave_base_diag.
Rik <rik@octave.org>
parents: 30133
diff changeset
193 m_matrix.dgelem (i0(0)) = val;
20978
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
194 retval = this;
31814
53c10d69a9be maint: use "m_" prefix for member variables in class octave_value.
Rik <rik@octave.org>
parents: 31771
diff changeset
195 this->m_count++;
20978
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
196 // invalidate cache
30135
606652e9f446 maint: use "m_" prefix for member variables in class octave_base_diag.
Rik <rik@octave.org>
parents: 30133
diff changeset
197 m_dense_cache = octave_value ();
20978
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
198 }
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
199 }
29163
8f67ad8b3103 maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents: 28631
diff changeset
200 catch (octave::index_exception& ie)
20978
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
201 {
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
202 // Rethrow to allow more info to be reported later.
29163
8f67ad8b3103 maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents: 28631
diff changeset
203 ie.set_pos_if_unset (2, k+1);
20978
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
204 throw;
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
205 }
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
206 }
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
207 else if (jdx.length () == 2
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
208 && jdx(0).is_scalar_type () && jdx(1).is_scalar_type ())
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
209 {
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
210 typename DMT::element_type val;
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
211 int k = 0;
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
212 try
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
213 {
29569
29a1f8fd8ee6 move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
214 octave::idx_vector i0 = jdx(0).index_vector ();
20978
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
215 k = 1;
29569
29a1f8fd8ee6 move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
216 octave::idx_vector i1 = jdx(1).index_vector ();
20978
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
217 if (i0(0) == i1(0)
30135
606652e9f446 maint: use "m_" prefix for member variables in class octave_base_diag.
Rik <rik@octave.org>
parents: 30133
diff changeset
218 && i0(0) < m_matrix.rows () && i1(0) < m_matrix.cols ()
20978
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
219 && chk_valid_scalar (rhs, val))
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
220 {
30135
606652e9f446 maint: use "m_" prefix for member variables in class octave_base_diag.
Rik <rik@octave.org>
parents: 30133
diff changeset
221 m_matrix.dgelem (i0(0)) = val;
20978
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
222 retval = this;
31814
53c10d69a9be maint: use "m_" prefix for member variables in class octave_value.
Rik <rik@octave.org>
parents: 31771
diff changeset
223 this->m_count++;
20978
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
224 // invalidate cache
30135
606652e9f446 maint: use "m_" prefix for member variables in class octave_base_diag.
Rik <rik@octave.org>
parents: 30133
diff changeset
225 m_dense_cache = octave_value ();
20978
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
226 }
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
227 }
29163
8f67ad8b3103 maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents: 28631
diff changeset
228 catch (octave::index_exception& ie)
20978
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
229 {
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
230 // Rethrow to allow more info to be reported later.
29163
8f67ad8b3103 maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents: 28631
diff changeset
231 ie.set_pos_if_unset (2, k+1);
20978
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
232 throw;
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
233 }
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
234 }
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
235
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
236 if (! retval.is_defined ())
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
237 retval = numeric_assign (type, idx, rhs);
8398
d95282fa0579 allow element assignment to diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
238 }
d95282fa0579 allow element assignment to diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
239 break;
d95282fa0579 allow element assignment to diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
240
d95282fa0579 allow element assignment to diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
241 case '{':
d95282fa0579 allow element assignment to diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
242 case '.':
d95282fa0579 allow element assignment to diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
243 {
23577
80c42f4cca13 maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents: 23450
diff changeset
244 if (! isempty ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9812
diff changeset
245 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9812
diff changeset
246 std::string nm = type_name ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9812
diff changeset
247 error ("%s cannot be indexed with %c", nm.c_str (), type[0]);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9812
diff changeset
248 }
20978
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
249
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
250 octave_value tmp = octave_value::empty_conv (type, rhs);
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
251
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
252 retval = tmp.subsasgn (type, idx, rhs);
8398
d95282fa0579 allow element assignment to diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
253 }
d95282fa0579 allow element assignment to diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
254 break;
d95282fa0579 allow element assignment to diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
255
d95282fa0579 allow element assignment to diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
256 default:
33362
2949b89f9711 replace most uses of panic_impossible with error in octave_value classes
John W. Eaton <jwe@octave.org>
parents: 32633
diff changeset
257 error ("unexpected: index not '(', '{', or '.' in octave_base_diag<DMT,MT>::subsasgn - please report this bug");
8398
d95282fa0579 allow element assignment to diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
258 }
d95282fa0579 allow element assignment to diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
259
d95282fa0579 allow element assignment to diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
260 return retval;
d95282fa0579 allow element assignment to diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
261 }
d95282fa0579 allow element assignment to diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
262
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21124
diff changeset
263 template <typename DMT, typename MT>
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
264 octave_value
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
265 octave_base_diag<DMT, MT>::resize (const dim_vector& dv, bool fill) const
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
266 {
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
267 octave_value retval;
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21301
diff changeset
268 if (dv.ndims () == 2)
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
269 {
30135
606652e9f446 maint: use "m_" prefix for member variables in class octave_base_diag.
Rik <rik@octave.org>
parents: 30133
diff changeset
270 DMT rm (m_matrix);
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
271 rm.resize (dv(0), dv(1));
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
272 retval = rm;
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
273 }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
274 else
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
275 retval = to_dense ().resize (dv, fill);
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
276 return retval;
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
277 }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
278
31898
0db880f38b1f maint: Use "nonzero" rather than "non-zero" in code base.
Rik <rik@octave.org>
parents: 31814
diff changeset
279 // Return true if this matrix has all true elements (nonzero, not NA/NaN).
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21124
diff changeset
280 template <typename DMT, typename MT>
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
281 bool
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31706
diff changeset
282 octave_base_diag<DMT, MT>::is_true () const
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
283 {
21990
efce657ceb86 Provide a warning when an array is used in an if/while/until (bug #43098).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21885
diff changeset
284 if (dims ().numel () > 1)
efce657ceb86 Provide a warning when an array is used in an if/while/until (bug #43098).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21885
diff changeset
285 {
efce657ceb86 Provide a warning when an array is used in an if/while/until (bug #43098).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21885
diff changeset
286 warn_array_as_logical (dims ());
efce657ceb86 Provide a warning when an array is used in an if/while/until (bug #43098).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21885
diff changeset
287 // Throw error if any NaN or NA by calling is_true().
30135
606652e9f446 maint: use "m_" prefix for member variables in class octave_base_diag.
Rik <rik@octave.org>
parents: 30133
diff changeset
288 octave_value (m_matrix.extract_diag ()).is_true ();
21990
efce657ceb86 Provide a warning when an array is used in an if/while/until (bug #43098).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21885
diff changeset
289 return false; // > 1x1 diagonal always has zeros
efce657ceb86 Provide a warning when an array is used in an if/while/until (bug #43098).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21885
diff changeset
290 }
efce657ceb86 Provide a warning when an array is used in an if/while/until (bug #43098).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21885
diff changeset
291 else
efce657ceb86 Provide a warning when an array is used in an if/while/until (bug #43098).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21885
diff changeset
292 return to_dense ().is_true (); // 0x0 or 1x1, handle NaN etc.
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
293 }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
294
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
295 // FIXME: This should be achieveable using ::real
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21124
diff changeset
296 template <typename T> inline T helper_getreal (T x) { return x; }
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21124
diff changeset
297 template <typename T> inline T helper_getreal (std::complex<T> x)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
298 { return x.real (); }
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
299 // FIXME: We really need some traits so that ad hoc hooks like this
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
300 // are not necessary.
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21124
diff changeset
301 template <typename T> inline T helper_iscomplex (T) { return false; }
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30139
diff changeset
302 template <typename T> inline T helper_iscomplex (std::complex<T>)
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30139
diff changeset
303 { return true; }
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
304
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21124
diff changeset
305 template <typename DMT, typename MT>
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
306 double
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
307 octave_base_diag<DMT, MT>::double_value (bool force_conversion) const
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
308 {
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
309 typedef typename DMT::element_type el_type;
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
310
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
311 if (helper_iscomplex (el_type ()) && ! force_conversion)
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 20978
diff changeset
312 warn_implicit_conversion ("Octave:imag-to-real",
30138
2dca5c25237d undo matrix -> m_matrix changes in type names and error messages
John W. Eaton <jwe@octave.org>
parents: 30135
diff changeset
313 "complex matrix", "real scalar");
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
314
23577
80c42f4cca13 maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents: 23450
diff changeset
315 if (isempty ())
21118
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
316 err_invalid_conversion (type_name (), "real scalar");
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
317
21118
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
318 warn_implicit_conversion ("Octave:array-to-scalar",
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
319 type_name (), "real scalar");
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
320
30135
606652e9f446 maint: use "m_" prefix for member variables in class octave_base_diag.
Rik <rik@octave.org>
parents: 30133
diff changeset
321 return helper_getreal (el_type (m_matrix (0, 0)));
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
322 }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
323
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21124
diff changeset
324 template <typename DMT, typename MT>
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
325 float
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
326 octave_base_diag<DMT, MT>::float_value (bool force_conversion) const
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
327 {
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
328 typedef typename DMT::element_type el_type;
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
329
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
330 if (helper_iscomplex (el_type ()) && ! force_conversion)
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 20978
diff changeset
331 warn_implicit_conversion ("Octave:imag-to-real",
30138
2dca5c25237d undo matrix -> m_matrix changes in type names and error messages
John W. Eaton <jwe@octave.org>
parents: 30135
diff changeset
332 "complex matrix", "real scalar");
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
333
22477
6bf1cbb90705 Remove unnecessary initializations in float_value and double_value methods
Julien Bect <julien.bect@centralesupelec.fr>
parents: 22327
diff changeset
334 if (! (numel () > 0))
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 20978
diff changeset
335 err_invalid_conversion (type_name (), "real scalar");
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
336
22477
6bf1cbb90705 Remove unnecessary initializations in float_value and double_value methods
Julien Bect <julien.bect@centralesupelec.fr>
parents: 22327
diff changeset
337 warn_implicit_conversion ("Octave:array-to-scalar",
6bf1cbb90705 Remove unnecessary initializations in float_value and double_value methods
Julien Bect <julien.bect@centralesupelec.fr>
parents: 22327
diff changeset
338 type_name (), "real scalar");
6bf1cbb90705 Remove unnecessary initializations in float_value and double_value methods
Julien Bect <julien.bect@centralesupelec.fr>
parents: 22327
diff changeset
339
30135
606652e9f446 maint: use "m_" prefix for member variables in class octave_base_diag.
Rik <rik@octave.org>
parents: 30133
diff changeset
340 return helper_getreal (el_type (m_matrix (0, 0)));
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
341 }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
342
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21124
diff changeset
343 template <typename DMT, typename MT>
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
344 Complex
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
345 octave_base_diag<DMT, MT>::complex_value (bool) const
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
346 {
21118
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
347 if (rows () == 0 || columns () == 0)
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
348 err_invalid_conversion (type_name (), "complex scalar");
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
349
21118
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
350 warn_implicit_conversion ("Octave:array-to-scalar",
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
351 type_name (), "complex scalar");
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
352
30135
606652e9f446 maint: use "m_" prefix for member variables in class octave_base_diag.
Rik <rik@octave.org>
parents: 30133
diff changeset
353 return m_matrix(0, 0);
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
354 }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
355
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21124
diff changeset
356 template <typename DMT, typename MT>
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
357 FloatComplex
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
358 octave_base_diag<DMT, MT>::float_complex_value (bool) const
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
359 {
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
360 float tmp = lo_ieee_float_nan_value ();
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
361
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
362 FloatComplex retval (tmp, tmp);
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
363
21118
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
364 if (rows () == 0 || columns () == 0)
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
365 err_invalid_conversion (type_name (), "complex scalar");
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
366
21118
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
367 warn_implicit_conversion ("Octave:array-to-scalar",
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
368 type_name (), "complex scalar");
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
369
30135
606652e9f446 maint: use "m_" prefix for member variables in class octave_base_diag.
Rik <rik@octave.org>
parents: 30133
diff changeset
370 retval = m_matrix (0, 0);
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
371
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
372 return retval;
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
373 }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
374
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21124
diff changeset
375 template <typename DMT, typename MT>
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
376 Matrix
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
377 octave_base_diag<DMT, MT>::matrix_value (bool) const
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
378 {
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
379 return Matrix (diag_matrix_value ());
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
380 }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
381
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21124
diff changeset
382 template <typename DMT, typename MT>
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
383 FloatMatrix
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
384 octave_base_diag<DMT, MT>::float_matrix_value (bool) const
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
385 {
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
386 return FloatMatrix (float_diag_matrix_value ());
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
387 }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
388
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21124
diff changeset
389 template <typename DMT, typename MT>
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
390 ComplexMatrix
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
391 octave_base_diag<DMT, MT>::complex_matrix_value (bool) const
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
392 {
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
393 return ComplexMatrix (complex_diag_matrix_value ());
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
394 }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
395
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21124
diff changeset
396 template <typename DMT, typename MT>
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
397 FloatComplexMatrix
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
398 octave_base_diag<DMT, MT>::float_complex_matrix_value (bool) const
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
399 {
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
400 return FloatComplexMatrix (float_complex_diag_matrix_value ());
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
401 }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
402
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21124
diff changeset
403 template <typename DMT, typename MT>
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
404 NDArray
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
405 octave_base_diag<DMT, MT>::array_value (bool) const
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
406 {
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
407 return NDArray (matrix_value ());
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
408 }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
409
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21124
diff changeset
410 template <typename DMT, typename MT>
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
411 FloatNDArray
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
412 octave_base_diag<DMT, MT>::float_array_value (bool) const
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
413 {
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
414 return FloatNDArray (float_matrix_value ());
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
415 }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
416
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21124
diff changeset
417 template <typename DMT, typename MT>
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
418 ComplexNDArray
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
419 octave_base_diag<DMT, MT>::complex_array_value (bool) const
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
420 {
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
421 return ComplexNDArray (complex_matrix_value ());
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
422 }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
423
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21124
diff changeset
424 template <typename DMT, typename MT>
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
425 FloatComplexNDArray
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
426 octave_base_diag<DMT, MT>::float_complex_array_value (bool) const
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
427 {
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
428 return FloatComplexNDArray (float_complex_matrix_value ());
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
429 }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
430
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21124
diff changeset
431 template <typename DMT, typename MT>
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
432 boolNDArray
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
433 octave_base_diag<DMT, MT>::bool_array_value (bool warn) const
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
434 {
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
435 return to_dense ().bool_array_value (warn);
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
436 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
437
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21124
diff changeset
438 template <typename DMT, typename MT>
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
439 charNDArray
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
440 octave_base_diag<DMT, MT>::char_array_value (bool warn) const
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
441 {
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
442 return to_dense ().char_array_value (warn);
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
443 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
444
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21124
diff changeset
445 template <typename DMT, typename MT>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
446 SparseMatrix
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
447 octave_base_diag<DMT, MT>::sparse_matrix_value (bool) const
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
448 {
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
449 return SparseMatrix (diag_matrix_value ());
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
450 }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
451
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21124
diff changeset
452 template <typename DMT, typename MT>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
453 SparseComplexMatrix
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
454 octave_base_diag<DMT, MT>::sparse_complex_matrix_value (bool) const
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
455 {
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
456 return SparseComplexMatrix (complex_diag_matrix_value ());
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
457 }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
458
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21124
diff changeset
459 template <typename DMT, typename MT>
29569
29a1f8fd8ee6 move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
460 octave::idx_vector
18130
e473c4853afc enable non-integer ranges as indices by default and deprecate preference
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
461 octave_base_diag<DMT, MT>::index_vector (bool require_integers) const
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
462 {
18130
e473c4853afc enable non-integer ranges as indices by default and deprecate preference
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
463 return to_dense ().index_vector (require_integers);
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
464 }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
465
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21124
diff changeset
466 template <typename DMT, typename MT>
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
467 octave_value
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
468 octave_base_diag<DMT, MT>::convert_to_str_internal (bool pad, bool force,
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 30565
diff changeset
469 char type) const
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
470 {
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
471 return to_dense ().convert_to_str_internal (pad, force, type);
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
472 }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
473
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21124
diff changeset
474 template <typename DMT, typename MT>
24745
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24700
diff changeset
475 float_display_format
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31706
diff changeset
476 octave_base_diag<DMT, MT>::get_edit_display_format () const
24745
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24700
diff changeset
477 {
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24700
diff changeset
478 // FIXME
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24700
diff changeset
479 return float_display_format ();
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24700
diff changeset
480 }
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24700
diff changeset
481
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24700
diff changeset
482 template <typename DMT, typename MT>
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24700
diff changeset
483 std::string
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24700
diff changeset
484 octave_base_diag<DMT, MT>::edit_display (const float_display_format& fmt,
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 30565
diff changeset
485 octave_idx_type i,
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 30565
diff changeset
486 octave_idx_type j) const
24745
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24700
diff changeset
487 {
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24700
diff changeset
488 std::ostringstream buf;
30390
a61e1a0f6024 maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 30139
diff changeset
489 octave_print_internal (buf, fmt, m_matrix(i, j));
24745
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24700
diff changeset
490 return buf.str ();
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24700
diff changeset
491 }
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24700
diff changeset
492
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24700
diff changeset
493 template <typename DMT, typename MT>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
494 bool
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
495 octave_base_diag<DMT, MT>::save_ascii (std::ostream& os)
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
496 {
30135
606652e9f446 maint: use "m_" prefix for member variables in class octave_base_diag.
Rik <rik@octave.org>
parents: 30133
diff changeset
497 os << "# rows: " << m_matrix.rows () << "\n"
606652e9f446 maint: use "m_" prefix for member variables in class octave_base_diag.
Rik <rik@octave.org>
parents: 30133
diff changeset
498 << "# columns: " << m_matrix.columns () << "\n";
8376
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
499
30135
606652e9f446 maint: use "m_" prefix for member variables in class octave_base_diag.
Rik <rik@octave.org>
parents: 30133
diff changeset
500 os << m_matrix.extract_diag ();
8376
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
501
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
502 return true;
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
503 }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
504
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21124
diff changeset
505 template <typename DMT, typename MT>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
506 bool
8376
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
507 octave_base_diag<DMT, MT>::load_ascii (std::istream& is)
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
508 {
18100
6a71e5030df5 Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents: 17787
diff changeset
509 octave_idx_type r = 0;
6a71e5030df5 Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents: 17787
diff changeset
510 octave_idx_type c = 0;
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
511
20978
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
512 if (! extract_keyword (is, "rows", r, true)
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
513 || ! extract_keyword (is, "columns", c, true))
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
514 error ("load: failed to extract number of rows and columns");
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
515
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23220
diff changeset
516 octave_idx_type l = (r < c ? r : c);
20978
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
517 MT tmp (l, 1);
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
518 is >> tmp;
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
519
20978
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
520 if (! is)
30138
2dca5c25237d undo matrix -> m_matrix changes in type names and error messages
John W. Eaton <jwe@octave.org>
parents: 30135
diff changeset
521 error ("load: failed to load diagonal matrix constant");
8376
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
522
20978
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
523 // This is a little tricky, as we have the Matrix type, but
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21739
diff changeset
524 // not ColumnVector type. We need to help the compiler get
20978
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
525 // through the inheritance tree.
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
526 typedef typename DMT::element_type el_type;
30135
606652e9f446 maint: use "m_" prefix for member variables in class octave_base_diag.
Rik <rik@octave.org>
parents: 30133
diff changeset
527 m_matrix = DMT (MDiagArray2<el_type> (MArray<el_type> (tmp)));
606652e9f446 maint: use "m_" prefix for member variables in class octave_base_diag.
Rik <rik@octave.org>
parents: 30133
diff changeset
528 m_matrix.resize (r, c);
20978
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
529
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21739
diff changeset
530 // Invalidate cache. Probably not necessary, but safe.
30135
606652e9f446 maint: use "m_" prefix for member variables in class octave_base_diag.
Rik <rik@octave.org>
parents: 30133
diff changeset
531 m_dense_cache = octave_value ();
8376
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
532
21124
95f8c8cdbffe maint: Eliminate 'bool success' variable where possible.
Rik <rik@octave.org>
parents: 21118
diff changeset
533 return true;
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
534 }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
535
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21124
diff changeset
536 template <typename DMT, typename MT>
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
537 void
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
538 octave_base_diag<DMT, MT>::print_raw (std::ostream& os,
8376
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
539 bool pr_as_read_syntax) const
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
540 {
30135
606652e9f446 maint: use "m_" prefix for member variables in class octave_base_diag.
Rik <rik@octave.org>
parents: 30133
diff changeset
541 return octave_print_internal (os, m_matrix, pr_as_read_syntax,
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8459
diff changeset
542 current_print_indent_level ());
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
543 }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
544
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21124
diff changeset
545 template <typename DMT, typename MT>
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
546 mxArray *
28126
4c21f99b4ad5 handle interleaved complex data and new typed data access functions for mex
John W. Eaton <jwe@octave.org>
parents: 27957
diff changeset
547 octave_base_diag<DMT, MT>::as_mxArray (bool interleaved) const
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
548 {
28126
4c21f99b4ad5 handle interleaved complex data and new typed data access functions for mex
John W. Eaton <jwe@octave.org>
parents: 27957
diff changeset
549 return to_dense ().as_mxArray (interleaved);
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
550 }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
551
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21124
diff changeset
552 template <typename DMT, typename MT>
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
553 bool
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31706
diff changeset
554 octave_base_diag<DMT, MT>::print_as_scalar () const
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
555 {
32598
2f3b54f81947 avoid dim_vector copies in more places where possible (bug #64962)
John W. Eaton <jwe@octave.org>
parents: 31898
diff changeset
556 const dim_vector& dv = dims ();
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
557
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
558 return (dv.all_ones () || dv.any_zero ());
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
559 }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
560
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21124
diff changeset
561 template <typename DMT, typename MT>
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
562 void
18416
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18132
diff changeset
563 octave_base_diag<DMT, MT>::print (std::ostream& os, bool pr_as_read_syntax)
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
564 {
8376
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
565 print_raw (os, pr_as_read_syntax);
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
566 newline (os);
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
567 }
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21124
diff changeset
568 template <typename DMT, typename MT>
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
569 int
23059
b98ebcd7f11c move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
570 octave_base_diag<DMT, MT>::write (octave::stream& os, int block_size,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
571 oct_data_conv::data_type output_type,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
572 int skip,
21739
c4ab2e54f100 use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
573 octave::mach_info::float_format flt_fmt) const
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
574 {
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
575 return to_dense ().write (os, block_size, output_type, skip, flt_fmt);
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
576 }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
577
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21124
diff changeset
578 template <typename DMT, typename MT>
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
579 void
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
580 octave_base_diag<DMT, MT>::print_info (std::ostream& os,
8376
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
581 const std::string& prefix) const
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
582 {
30135
606652e9f446 maint: use "m_" prefix for member variables in class octave_base_diag.
Rik <rik@octave.org>
parents: 30133
diff changeset
583 m_matrix.print_info (os, prefix);
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
584 }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
585
24646
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
586 // FIXME: this function is duplicated in octave_base_matrix<T>. Could
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
587 // it somehow be shared instead?
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
588
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
589 template <typename DMT, typename MT>
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
590 void
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
591 octave_base_diag<DMT, MT>::short_disp (std::ostream& os) const
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
592 {
30135
606652e9f446 maint: use "m_" prefix for member variables in class octave_base_diag.
Rik <rik@octave.org>
parents: 30133
diff changeset
593 if (m_matrix.isempty ())
24646
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
594 os << "[]";
30135
606652e9f446 maint: use "m_" prefix for member variables in class octave_base_diag.
Rik <rik@octave.org>
parents: 30133
diff changeset
595 else if (m_matrix.ndims () == 2)
24646
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
596 {
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
597 // FIXME: should this be configurable?
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
598 octave_idx_type max_elts = 10;
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
599 octave_idx_type elts = 0;
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
600
30135
606652e9f446 maint: use "m_" prefix for member variables in class octave_base_diag.
Rik <rik@octave.org>
parents: 30133
diff changeset
601 octave_idx_type nel = m_matrix.numel ();
24646
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
602
30135
606652e9f446 maint: use "m_" prefix for member variables in class octave_base_diag.
Rik <rik@octave.org>
parents: 30133
diff changeset
603 octave_idx_type nr = m_matrix.rows ();
606652e9f446 maint: use "m_" prefix for member variables in class octave_base_diag.
Rik <rik@octave.org>
parents: 30133
diff changeset
604 octave_idx_type nc = m_matrix.columns ();
24646
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
605
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
606 os << '[';
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
607
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
608 for (octave_idx_type i = 0; i < nr; i++)
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
609 {
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
610 for (octave_idx_type j = 0; j < nc; j++)
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
611 {
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
612 std::ostringstream buf;
30390
a61e1a0f6024 maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 30139
diff changeset
613 octave_print_internal (buf, m_matrix(i, j));
24646
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
614 std::string tmp = buf.str ();
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
615 std::size_t pos = tmp.find_first_not_of (' ');
24646
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
616 if (pos != std::string::npos)
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
617 os << tmp.substr (pos);
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
618 else if (! tmp.empty ())
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
619 os << tmp[0];
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
620
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
621 if (++elts >= max_elts)
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
622 goto done;
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
623
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
624 if (j < nc - 1)
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
625 os << ", ";
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
626 }
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
627
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
628 if (i < nr - 1 && elts < max_elts)
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
629 os << "; ";
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
630 }
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
631
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
632 done:
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
633
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
634 if (nel <= max_elts)
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
635 os << ']';
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
636 }
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
637 else
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
638 os << "...";
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
639 }
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
640
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
641 template <typename DMT, typename MT>
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
642 octave_value
18650
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18522
diff changeset
643 octave_base_diag<DMT, MT>::fast_elem_extract (octave_idx_type n) const
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18522
diff changeset
644 {
30135
606652e9f446 maint: use "m_" prefix for member variables in class octave_base_diag.
Rik <rik@octave.org>
parents: 30133
diff changeset
645 if (n < m_matrix.numel ())
18650
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18522
diff changeset
646 {
30135
606652e9f446 maint: use "m_" prefix for member variables in class octave_base_diag.
Rik <rik@octave.org>
parents: 30133
diff changeset
647 octave_idx_type nr = m_matrix.rows ();
18650
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18522
diff changeset
648
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18522
diff changeset
649 octave_idx_type r = n % nr;
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18522
diff changeset
650 octave_idx_type c = n / nr;
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18522
diff changeset
651
30135
606652e9f446 maint: use "m_" prefix for member variables in class octave_base_diag.
Rik <rik@octave.org>
parents: 30133
diff changeset
652 return octave_value (m_matrix.elem (r, c));
18650
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18522
diff changeset
653 }
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18522
diff changeset
654 else
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18522
diff changeset
655 return octave_value ();
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18522
diff changeset
656 }
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18522
diff changeset
657
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21124
diff changeset
658 template <typename DMT, typename MT>
18650
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18522
diff changeset
659 octave_value
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31706
diff changeset
660 octave_base_diag<DMT, MT>::to_dense () const
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
661 {
30135
606652e9f446 maint: use "m_" prefix for member variables in class octave_base_diag.
Rik <rik@octave.org>
parents: 30133
diff changeset
662 if (! m_dense_cache.is_defined ())
606652e9f446 maint: use "m_" prefix for member variables in class octave_base_diag.
Rik <rik@octave.org>
parents: 30133
diff changeset
663 m_dense_cache = MT (m_matrix);
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
664
30135
606652e9f446 maint: use "m_" prefix for member variables in class octave_base_diag.
Rik <rik@octave.org>
parents: 30133
diff changeset
665 return m_dense_cache;
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
666 }