annotate libinterp/octave-value/ov-base-mat.cc @ 31143:b3ca7f891750

maint: use "m_" prefix for member variables in class octave_base_matrix. * ov-base-int.cc, ov-base-mat.cc, ov-base-mat.h, ov-base.h, ov-bool-mat.cc, ov-bool-mat.h, ov-cell.cc, ov-cell.h, ov-ch-mat.cc, ov-ch-mat.h, ov-cx-mat.cc, ov-cx-mat.h, ov-flt-cx-mat.cc, ov-flt-cx-mat.h, ov-flt-re-mat.cc, ov-flt-re-mat.h, ov-intx.h, ov-re-mat.cc, ov-re-mat.h, ov-str-mat.cc, ov-str-mat.h: use "m_" prefix for member variables in class octave_base_matrix.
author Rik <rik@octave.org>
date Sun, 10 Jul 2022 18:26:24 -0700
parents 796f54d4ddbf
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27928
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27924
diff changeset
1 ////////////////////////////////////////////////////////////////////////
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27924
diff changeset
2 //
30569
796f54d4ddbf update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 30395
diff changeset
3 // Copyright (C) 1996-2022 The Octave Project Developers
27928
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27924
diff changeset
4 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27924
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: 27924
diff changeset
6 // distribution or <https://octave.org/copyright/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27924
diff changeset
7 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27924
diff changeset
8 // This file is part of Octave.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27924
diff changeset
9 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27924
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: 27924
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: 27924
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: 27924
diff changeset
13 // (at your option) any later version.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27924
diff changeset
14 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27924
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: 27924
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: 27924
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: 27924
diff changeset
18 // GNU General Public License for more details.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27924
diff changeset
19 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27924
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: 27924
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: 27924
diff changeset
22 // <https://www.gnu.org/licenses/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27924
diff changeset
23 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27924
diff changeset
24 ////////////////////////////////////////////////////////////////////////
3219
30770ba4457a [project @ 1998-11-13 03:44:31 by jwe]
jwe
parents:
diff changeset
25
21690
b6a686543080 Only include config.h in files that are compiled separately.
John W. Eaton <jwe@octave.org>
parents: 21301
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: 21301
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: 21301
diff changeset
28 // this file.
3219
30770ba4457a [project @ 1998-11-13 03:44:31 by jwe]
jwe
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 <ostream>
cb1606f78f6b prefer <istream>, <ostream>, or <iosfwd> to <iostream> where possible
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
31 #include <sstream>
3219
30770ba4457a [project @ 1998-11-13 03:44:31 by jwe]
jwe
parents:
diff changeset
32
19269
65554f5847ac don't include oct-locbuf.h in header files unnecessarily
John W. Eaton <jwe@octave.org>
parents: 19220
diff changeset
33 #include "Array-util.h"
65554f5847ac don't include oct-locbuf.h in header files unnecessarily
John W. Eaton <jwe@octave.org>
parents: 19220
diff changeset
34
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3928
diff changeset
35 #include "Cell.h"
21990
efce657ceb86 Provide a warning when an array is used in an if/while/until (bug #43098).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21751
diff changeset
36 #include "errwarn.h"
20940
48b2ad5ee801 maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents: 20715
diff changeset
37 #include "ovl.h"
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3928
diff changeset
38 #include "oct-map.h"
3219
30770ba4457a [project @ 1998-11-13 03:44:31 by jwe]
jwe
parents:
diff changeset
39 #include "ov-base.h"
30770ba4457a [project @ 1998-11-13 03:44:31 by jwe]
jwe
parents:
diff changeset
40 #include "ov-base-mat.h"
10670
654fbde5dceb make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents: 10521
diff changeset
41 #include "ov-base-scalar.h"
3572
8d641545e006 [project @ 2000-02-03 21:39:48 by jwe]
jwe
parents: 3523
diff changeset
42 #include "pr-output.h"
20715
5b7643257978 Remove trailing whitespace at end of lines.
Rik <rik@octave.org>
parents: 20652
diff changeset
43
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21118
diff changeset
44 template <typename MT>
3220
3deb1105fbc1 [project @ 1998-11-19 00:06:30 by jwe]
jwe
parents: 3219
diff changeset
45 octave_value
4247
fc9a075d10fb [project @ 2002-12-30 23:05:27 by jwe]
jwe
parents: 4219
diff changeset
46 octave_base_matrix<MT>::subsref (const std::string& type,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
47 const std::list<octave_value_list>& idx)
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3928
diff changeset
48 {
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3928
diff changeset
49 octave_value retval;
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3928
diff changeset
50
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3928
diff changeset
51 switch (type[0])
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3928
diff changeset
52 {
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3928
diff changeset
53 case '(':
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3928
diff changeset
54 retval = do_index_op (idx.front ());
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3928
diff changeset
55 break;
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3928
diff changeset
56
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3928
diff changeset
57 case '{':
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3928
diff changeset
58 case '.':
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3928
diff changeset
59 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
60 std::string nm = type_name ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
61 error ("%s cannot be indexed with %c", nm.c_str (), type[0]);
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3928
diff changeset
62 }
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3928
diff changeset
63 break;
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3928
diff changeset
64
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3928
diff changeset
65 default:
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3928
diff changeset
66 panic_impossible ();
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3928
diff changeset
67 }
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3928
diff changeset
68
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3928
diff changeset
69 return retval.next_subsref (type, idx);
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3928
diff changeset
70 }
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3928
diff changeset
71
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21118
diff changeset
72 template <typename MT>
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3928
diff changeset
73 octave_value
4247
fc9a075d10fb [project @ 2002-12-30 23:05:27 by jwe]
jwe
parents: 4219
diff changeset
74 octave_base_matrix<MT>::subsasgn (const std::string& type,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
75 const std::list<octave_value_list>& idx,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
76 const octave_value& rhs)
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3928
diff changeset
77 {
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3928
diff changeset
78 octave_value retval;
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3928
diff changeset
79
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3928
diff changeset
80 switch (type[0])
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3928
diff changeset
81 {
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3928
diff changeset
82 case '(':
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3928
diff changeset
83 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
84 if (type.length () == 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
85 retval = numeric_assign (type, idx, rhs);
23577
80c42f4cca13 maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents: 23220
diff changeset
86 else if (isempty ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
87 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
88 // Allow conversion of empty matrix to some other type in
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
89 // cases like
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
90 //
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
91 // x = []; x(i).f = rhs
4436
689f730954b3 [project @ 2003-06-24 13:00:12 by jwe]
jwe
parents: 4247
diff changeset
92
20978
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
93 if (type[1] != '.')
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
94 error ("invalid assignment expression");
4436
689f730954b3 [project @ 2003-06-24 13:00:12 by jwe]
jwe
parents: 4247
diff changeset
95
20978
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
96 octave_value tmp = octave_value::empty_conv (type, rhs);
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
97
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
98 retval = tmp.subsasgn (type, idx, rhs);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
99 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
100 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
101 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
102 std::string nm = type_name ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
103 error ("in indexed assignment of %s, last lhs index must be ()",
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
104 nm.c_str ());
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
105 }
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3928
diff changeset
106 }
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3928
diff changeset
107 break;
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3928
diff changeset
108
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3928
diff changeset
109 case '{':
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3928
diff changeset
110 case '.':
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3928
diff changeset
111 {
23577
80c42f4cca13 maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents: 23220
diff changeset
112 if (! isempty ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
113 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
114 std::string nm = type_name ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
115 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: 10160
diff changeset
116 }
20978
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
117
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
118 octave_value tmp = octave_value::empty_conv (type, rhs);
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
119
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
120 retval = tmp.subsasgn (type, idx, rhs);
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3928
diff changeset
121 }
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3928
diff changeset
122 break;
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3928
diff changeset
123
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3928
diff changeset
124 default:
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3928
diff changeset
125 panic_impossible ();
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3928
diff changeset
126 }
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3928
diff changeset
127
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3928
diff changeset
128 return retval;
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3928
diff changeset
129 }
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3928
diff changeset
130
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21118
diff changeset
131 template <typename MT>
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3928
diff changeset
132 octave_value
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3928
diff changeset
133 octave_base_matrix<MT>::do_index_op (const octave_value_list& idx,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
134 bool resize_ok)
3220
3deb1105fbc1 [project @ 1998-11-19 00:06:30 by jwe]
jwe
parents: 3219
diff changeset
135 {
3deb1105fbc1 [project @ 1998-11-19 00:06:30 by jwe]
jwe
parents: 3219
diff changeset
136 octave_value retval;
3deb1105fbc1 [project @ 1998-11-19 00:06:30 by jwe]
jwe
parents: 3219
diff changeset
137
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
138 octave_idx_type n_idx = idx.length ();
3220
3deb1105fbc1 [project @ 1998-11-19 00:06:30 by jwe]
jwe
parents: 3219
diff changeset
139
31143
b3ca7f891750 maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents: 30569
diff changeset
140 int nd = m_matrix.ndims ();
b3ca7f891750 maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents: 30569
diff changeset
141 const MT& cmatrix = m_matrix;
3220
3deb1105fbc1 [project @ 1998-11-19 00:06:30 by jwe]
jwe
parents: 3219
diff changeset
142
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
143 // If we catch an indexing error in index_vector, we flag an error in
27961
2310164737b3 fix many spelling errors (bug #57613)
John W. Eaton <jwe@octave.org>
parents: 26379
diff changeset
144 // index k. Ensure it is the right value before each idx_vector call.
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
145 // Same variable as used in the for loop in the default case.
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
146
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
147 octave_idx_type k = 0;
3220
3deb1105fbc1 [project @ 1998-11-19 00:06:30 by jwe]
jwe
parents: 3219
diff changeset
148
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
149 try
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
150 {
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
151 switch (n_idx)
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
152 {
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
153 case 0:
27064
d61825e693f2 warn about indexing values with () (bug #56167)
John W. Eaton <jwe@octave.org>
parents: 27063
diff changeset
154 warn_empty_index (type_name ());
31143
b3ca7f891750 maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents: 30569
diff changeset
155 retval = m_matrix;
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
156 break;
3220
3deb1105fbc1 [project @ 1998-11-19 00:06:30 by jwe]
jwe
parents: 3219
diff changeset
157
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
158 case 1:
8679
280fae940bb0 optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8626
diff changeset
159 {
29574
29a1f8fd8ee6 move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29364
diff changeset
160 octave::idx_vector i = idx (0).index_vector ();
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
161
20558
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
162 // optimize single scalar index.
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
163 if (! resize_ok && i.is_scalar ())
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
164 retval = cmatrix.checkelem (i(0));
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
165 else
31143
b3ca7f891750 maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents: 30569
diff changeset
166 retval = MT (m_matrix.index (i, resize_ok));
8679
280fae940bb0 optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8626
diff changeset
167 }
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
168 break;
8679
280fae940bb0 optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8626
diff changeset
169
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
170 case 2:
8679
280fae940bb0 optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8626
diff changeset
171 {
29574
29a1f8fd8ee6 move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29364
diff changeset
172 octave::idx_vector i = idx (0).index_vector ();
8679
280fae940bb0 optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8626
diff changeset
173
20558
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
174 k=1;
29574
29a1f8fd8ee6 move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29364
diff changeset
175 octave::idx_vector j = idx (1).index_vector ();
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
176
20558
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
177 // optimize two scalar indices.
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
178 if (! resize_ok && i.is_scalar () && j.is_scalar ())
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
179 retval = cmatrix.checkelem (i(0), j(0));
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
180 else
31143
b3ca7f891750 maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents: 30569
diff changeset
181 retval = MT (m_matrix.index (i, j, resize_ok));
8679
280fae940bb0 optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8626
diff changeset
182 }
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
183 break;
3220
3deb1105fbc1 [project @ 1998-11-19 00:06:30 by jwe]
jwe
parents: 3219
diff changeset
184
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
185 default:
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
186 {
29574
29a1f8fd8ee6 move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29364
diff changeset
187 Array<octave::idx_vector> idx_vec (dim_vector (n_idx, 1));
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
188 bool scalar_opt = n_idx == nd && ! resize_ok;
31143
b3ca7f891750 maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents: 30569
diff changeset
189 const dim_vector dv = m_matrix.dims ();
4858
499d2ca46982 [project @ 2004-04-08 18:00:43 by jwe]
jwe
parents: 4846
diff changeset
190
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
191 for (k = 0; k < n_idx; k++)
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
192 {
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
193 idx_vec(k) = idx(k).index_vector ();
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
194
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
195 scalar_opt = (scalar_opt && idx_vec(k).is_scalar ());
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
196 }
3220
3deb1105fbc1 [project @ 1998-11-19 00:06:30 by jwe]
jwe
parents: 3219
diff changeset
197
20558
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
198 if (scalar_opt)
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
199 retval = cmatrix.checkelem (conv_to_int_array (idx_vec));
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
200 else
31143
b3ca7f891750 maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents: 30569
diff changeset
201 retval = MT (m_matrix.index (idx_vec, resize_ok));
8679
280fae940bb0 optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8626
diff changeset
202 }
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
203 break;
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
204 }
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
205 }
29168
8f67ad8b3103 maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents: 28017
diff changeset
206 catch (octave::index_exception& ie)
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
207 {
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
208 // Rethrow to allow more info to be reported later.
29168
8f67ad8b3103 maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents: 28017
diff changeset
209 ie.set_pos_if_unset (n_idx, k+1);
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
210 throw;
3220
3deb1105fbc1 [project @ 1998-11-19 00:06:30 by jwe]
jwe
parents: 3219
diff changeset
211 }
3deb1105fbc1 [project @ 1998-11-19 00:06:30 by jwe]
jwe
parents: 3219
diff changeset
212
3deb1105fbc1 [project @ 1998-11-19 00:06:30 by jwe]
jwe
parents: 3219
diff changeset
213 return retval;
3deb1105fbc1 [project @ 1998-11-19 00:06:30 by jwe]
jwe
parents: 3219
diff changeset
214 }
3deb1105fbc1 [project @ 1998-11-19 00:06:30 by jwe]
jwe
parents: 3219
diff changeset
215
27063
3140380861ce error for x{} for cell array objects (bug #56167)
John W. Eaton <jwe@octave.org>
parents: 26379
diff changeset
216 /*
3140380861ce error for x{} for cell array objects (bug #56167)
John W. Eaton <jwe@octave.org>
parents: 26379
diff changeset
217 %% This behavior is required for Matlab compatibility.
3140380861ce error for x{} for cell array objects (bug #56167)
John W. Eaton <jwe@octave.org>
parents: 26379
diff changeset
218 %!test
3140380861ce error for x{} for cell array objects (bug #56167)
John W. Eaton <jwe@octave.org>
parents: 26379
diff changeset
219 %! a = [1, 2; 3, 4];
3140380861ce error for x{} for cell array objects (bug #56167)
John W. Eaton <jwe@octave.org>
parents: 26379
diff changeset
220 %! assert (a(), a);
3140380861ce error for x{} for cell array objects (bug #56167)
John W. Eaton <jwe@octave.org>
parents: 26379
diff changeset
221 */
3140380861ce error for x{} for cell array objects (bug #56167)
John W. Eaton <jwe@octave.org>
parents: 26379
diff changeset
222
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21118
diff changeset
223 template <typename MT>
3928
e8627dc4bdf2 [project @ 2002-05-03 19:56:01 by jwe]
jwe
parents: 3572
diff changeset
224 void
e8627dc4bdf2 [project @ 2002-05-03 19:56:01 by jwe]
jwe
parents: 3572
diff changeset
225 octave_base_matrix<MT>::assign (const octave_value_list& idx, const MT& rhs)
e8627dc4bdf2 [project @ 2002-05-03 19:56:01 by jwe]
jwe
parents: 3572
diff changeset
226 {
8679
280fae940bb0 optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8626
diff changeset
227 octave_idx_type n_idx = idx.length ();
280fae940bb0 optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8626
diff changeset
228
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
229 // If we catch an indexing error in index_vector, we flag an error in
27961
2310164737b3 fix many spelling errors (bug #57613)
John W. Eaton <jwe@octave.org>
parents: 26379
diff changeset
230 // index k. Ensure it is the right value before each idx_vector call.
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
231 // Same variable as used in the for loop in the default case.
8679
280fae940bb0 optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8626
diff changeset
232
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
233 octave_idx_type k = 0;
8679
280fae940bb0 optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8626
diff changeset
234
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
235 try
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
236 {
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
237 switch (n_idx)
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
238 {
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
239 case 0:
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
240 panic_impossible ();
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
241 break;
8679
280fae940bb0 optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8626
diff changeset
242
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
243 case 1:
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
244 {
29574
29a1f8fd8ee6 move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29364
diff changeset
245 octave::idx_vector i = idx (0).index_vector ();
8679
280fae940bb0 optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8626
diff changeset
246
31143
b3ca7f891750 maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents: 30569
diff changeset
247 m_matrix.assign (i, rhs);
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
248 }
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
249 break;
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
250
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
251 case 2:
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
252 {
29574
29a1f8fd8ee6 move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29364
diff changeset
253 octave::idx_vector i = idx (0).index_vector ();
8679
280fae940bb0 optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8626
diff changeset
254
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
255 k = 1;
29574
29a1f8fd8ee6 move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29364
diff changeset
256 octave::idx_vector j = idx (1).index_vector ();
8679
280fae940bb0 optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8626
diff changeset
257
31143
b3ca7f891750 maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents: 30569
diff changeset
258 m_matrix.assign (i, j, rhs);
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
259 }
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
260 break;
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
261
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
262 default:
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
263 {
29574
29a1f8fd8ee6 move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29364
diff changeset
264 Array<octave::idx_vector> idx_vec (dim_vector (n_idx, 1));
3928
e8627dc4bdf2 [project @ 2002-05-03 19:56:01 by jwe]
jwe
parents: 3572
diff changeset
265
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
266 for (k = 0; k < n_idx; k++)
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
267 idx_vec(k) = idx(k).index_vector ();
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
268
31143
b3ca7f891750 maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents: 30569
diff changeset
269 m_matrix.assign (idx_vec, rhs);
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
270 }
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
271 break;
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
272 }
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
273 }
29168
8f67ad8b3103 maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents: 28017
diff changeset
274 catch (octave::index_exception& ie)
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
275 {
28017
9a965fec21c1 refactor index_exception classes to accommodate std::exception::what method
John W. Eaton <jwe@octave.org>
parents: 27962
diff changeset
276 // Rethrow to allow more info to be reported later.
29168
8f67ad8b3103 maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents: 28017
diff changeset
277 ie.set_pos_if_unset (n_idx, k+1);
28017
9a965fec21c1 refactor index_exception classes to accommodate std::exception::what method
John W. Eaton <jwe@octave.org>
parents: 27962
diff changeset
278 throw;
8679
280fae940bb0 optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8626
diff changeset
279 }
280fae940bb0 optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8626
diff changeset
280
9350
16a5f9e1fdb3 cache idx_vector result in matrices once used for indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 9239
diff changeset
281 // Clear cache.
16a5f9e1fdb3 cache idx_vector result in matrices once used for indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 9239
diff changeset
282 clear_cached_info ();
16a5f9e1fdb3 cache idx_vector result in matrices once used for indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 9239
diff changeset
283 }
16a5f9e1fdb3 cache idx_vector result in matrices once used for indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 9239
diff changeset
284
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21118
diff changeset
285 template <typename MT>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
286 MatrixType
31143
b3ca7f891750 maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents: 30569
diff changeset
287 octave_base_matrix<MT>::matrix_type (const MatrixType& typ) const
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
288 {
31143
b3ca7f891750 maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents: 30569
diff changeset
289 delete m_typ;
b3ca7f891750 maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents: 30569
diff changeset
290 m_typ = new MatrixType (typ);
b3ca7f891750 maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents: 30569
diff changeset
291 return *m_typ;
8679
280fae940bb0 optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8626
diff changeset
292 }
280fae940bb0 optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8626
diff changeset
293
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21118
diff changeset
294 template <typename MT>
8679
280fae940bb0 optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8626
diff changeset
295 void
280fae940bb0 optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8626
diff changeset
296 octave_base_matrix<MT>::assign (const octave_value_list& idx,
280fae940bb0 optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8626
diff changeset
297 typename MT::element_type rhs)
280fae940bb0 optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8626
diff changeset
298 {
280fae940bb0 optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8626
diff changeset
299 octave_idx_type n_idx = idx.length ();
280fae940bb0 optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8626
diff changeset
300
31143
b3ca7f891750 maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents: 30569
diff changeset
301 int nd = m_matrix.ndims ();
8679
280fae940bb0 optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8626
diff changeset
302
10350
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
303 MT mrhs (dim_vector (1, 1), rhs);
8679
280fae940bb0 optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8626
diff changeset
304
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
305 // If we catch an indexing error in index_vector, we flag an error in
27961
2310164737b3 fix many spelling errors (bug #57613)
John W. Eaton <jwe@octave.org>
parents: 26379
diff changeset
306 // index k. Ensure it is the right value before each idx_vector call.
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
307 // Same variable as used in the for loop in the default case.
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
308
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
309 octave_idx_type k = 0;
3928
e8627dc4bdf2 [project @ 2002-05-03 19:56:01 by jwe]
jwe
parents: 3572
diff changeset
310
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
311 try
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
312 {
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
313 switch (n_idx)
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
314 {
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
315 case 0:
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
316 panic_impossible ();
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
317 break;
8679
280fae940bb0 optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8626
diff changeset
318
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
319 case 1:
8679
280fae940bb0 optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8626
diff changeset
320 {
29574
29a1f8fd8ee6 move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29364
diff changeset
321 octave::idx_vector i = idx (0).index_vector ();
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
322
20558
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
323 // optimize single scalar index.
31143
b3ca7f891750 maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents: 30569
diff changeset
324 if (i.is_scalar () && i(0) < m_matrix.numel ())
b3ca7f891750 maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents: 30569
diff changeset
325 m_matrix(i(0)) = rhs;
20558
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
326 else
31143
b3ca7f891750 maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents: 30569
diff changeset
327 m_matrix.assign (i, mrhs);
8679
280fae940bb0 optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8626
diff changeset
328 }
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
329 break;
8679
280fae940bb0 optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8626
diff changeset
330
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
331 case 2:
8679
280fae940bb0 optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8626
diff changeset
332 {
29574
29a1f8fd8ee6 move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29364
diff changeset
333 octave::idx_vector i = idx (0).index_vector ();
8679
280fae940bb0 optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8626
diff changeset
334
20558
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
335 k = 1;
29574
29a1f8fd8ee6 move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29364
diff changeset
336 octave::idx_vector j = idx (1).index_vector ();
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
337
20558
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
338 // optimize two scalar indices.
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
339 if (i.is_scalar () && j.is_scalar () && nd == 2
31143
b3ca7f891750 maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents: 30569
diff changeset
340 && i(0) < m_matrix.rows () && j(0) < m_matrix.columns ())
b3ca7f891750 maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents: 30569
diff changeset
341 m_matrix(i(0), j(0)) = rhs;
20558
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
342 else
31143
b3ca7f891750 maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents: 30569
diff changeset
343 m_matrix.assign (i, j, mrhs);
8679
280fae940bb0 optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8626
diff changeset
344 }
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
345 break;
6195
c50a125a6c81 [project @ 2006-12-04 09:25:08 by dbateman]
dbateman
parents: 5885
diff changeset
346
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
347 default:
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
348 {
29574
29a1f8fd8ee6 move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29364
diff changeset
349 Array<octave::idx_vector> idx_vec (dim_vector (n_idx, 1));
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
350 bool scalar_opt = n_idx == nd;
31143
b3ca7f891750 maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents: 30569
diff changeset
351 const dim_vector dv = m_matrix.dims ().redim (n_idx);
8679
280fae940bb0 optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8626
diff changeset
352
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
353 for (k = 0; k < n_idx; k++)
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
354 {
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
355 idx_vec(k) = idx(k).index_vector ();
8679
280fae940bb0 optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8626
diff changeset
356
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
357 scalar_opt = (scalar_opt && idx_vec(k).is_scalar ()
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
358 && idx_vec(k)(0) < dv(k));
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
359 }
8679
280fae940bb0 optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8626
diff changeset
360
20558
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
361 if (scalar_opt)
8679
280fae940bb0 optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8626
diff changeset
362 {
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21690
diff changeset
363 // optimize all scalar indices. Don't construct
20558
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
364 // an index array, but rather calc a scalar index directly.
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
365 octave_idx_type n = 1;
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
366 octave_idx_type j = 0;
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
367 for (octave_idx_type i = 0; i < n_idx; i++)
8679
280fae940bb0 optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8626
diff changeset
368 {
20558
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
369 j += idx_vec(i)(0) * n;
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
370 n *= dv (i);
8679
280fae940bb0 optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8626
diff changeset
371 }
31143
b3ca7f891750 maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents: 30569
diff changeset
372 m_matrix(j) = rhs;
8679
280fae940bb0 optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8626
diff changeset
373 }
20558
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
374 else
31143
b3ca7f891750 maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents: 30569
diff changeset
375 m_matrix.assign (idx_vec, mrhs);
8679
280fae940bb0 optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8626
diff changeset
376 }
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
377 break;
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
378 }
8679
280fae940bb0 optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8626
diff changeset
379 }
29168
8f67ad8b3103 maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents: 28017
diff changeset
380 catch (octave::index_exception& ie)
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20218
diff changeset
381 {
28017
9a965fec21c1 refactor index_exception classes to accommodate std::exception::what method
John W. Eaton <jwe@octave.org>
parents: 27962
diff changeset
382 // Rethrow to allow more info to be reported later.
29168
8f67ad8b3103 maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents: 28017
diff changeset
383 ie.set_pos_if_unset (n_idx, k+1);
28017
9a965fec21c1 refactor index_exception classes to accommodate std::exception::what method
John W. Eaton <jwe@octave.org>
parents: 27962
diff changeset
384 throw;
20652
7a8096f8df5d more cleanup of indexing exceptions
John W. Eaton <jwe@octave.org>
parents: 20651
diff changeset
385 }
6195
c50a125a6c81 [project @ 2006-12-04 09:25:08 by dbateman]
dbateman
parents: 5885
diff changeset
386
9350
16a5f9e1fdb3 cache idx_vector result in matrices once used for indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 9239
diff changeset
387 // Clear cache.
16a5f9e1fdb3 cache idx_vector result in matrices once used for indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 9239
diff changeset
388 clear_cached_info ();
3928
e8627dc4bdf2 [project @ 2002-05-03 19:56:01 by jwe]
jwe
parents: 3572
diff changeset
389 }
e8627dc4bdf2 [project @ 2002-05-03 19:56:01 by jwe]
jwe
parents: 3572
diff changeset
390
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21118
diff changeset
391 template <typename MT>
8150
283989f2da9b make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 7017
diff changeset
392 void
283989f2da9b make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 7017
diff changeset
393 octave_base_matrix<MT>::delete_elements (const octave_value_list& idx)
283989f2da9b make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 7017
diff changeset
394 {
283989f2da9b make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 7017
diff changeset
395 octave_idx_type len = idx.length ();
283989f2da9b make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 7017
diff changeset
396
29574
29a1f8fd8ee6 move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29364
diff changeset
397 Array<octave::idx_vector> ra_idx (dim_vector (len, 1));
8150
283989f2da9b make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 7017
diff changeset
398
283989f2da9b make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 7017
diff changeset
399 for (octave_idx_type i = 0; i < len; i++)
283989f2da9b make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 7017
diff changeset
400 ra_idx(i) = idx(i).index_vector ();
283989f2da9b make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 7017
diff changeset
401
31143
b3ca7f891750 maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents: 30569
diff changeset
402 m_matrix.delete_elements (ra_idx);
8150
283989f2da9b make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 7017
diff changeset
403
9350
16a5f9e1fdb3 cache idx_vector result in matrices once used for indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 9239
diff changeset
404 // Clear cache.
16a5f9e1fdb3 cache idx_vector result in matrices once used for indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 9239
diff changeset
405 clear_cached_info ();
8150
283989f2da9b make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 7017
diff changeset
406 }
283989f2da9b make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 7017
diff changeset
407
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21118
diff changeset
408 template <typename MT>
5731
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5539
diff changeset
409 octave_value
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5539
diff changeset
410 octave_base_matrix<MT>::resize (const dim_vector& dv, bool fill) const
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5539
diff changeset
411 {
31143
b3ca7f891750 maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents: 30569
diff changeset
412 MT retval (m_matrix);
5731
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5539
diff changeset
413 if (fill)
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5539
diff changeset
414 retval.resize (dv, 0);
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5539
diff changeset
415 else
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
416 retval.resize (dv);
5731
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5539
diff changeset
417 return retval;
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5539
diff changeset
418 }
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5539
diff changeset
419
21990
efce657ceb86 Provide a warning when an array is used in an if/while/until (bug #43098).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21751
diff changeset
420 // Return true if this matrix has all true elements (non-zero, not NA/NaN).
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21118
diff changeset
421 template <typename MT>
3220
3deb1105fbc1 [project @ 1998-11-19 00:06:30 by jwe]
jwe
parents: 3219
diff changeset
422 bool
3deb1105fbc1 [project @ 1998-11-19 00:06:30 by jwe]
jwe
parents: 3219
diff changeset
423 octave_base_matrix<MT>::is_true (void) const
3deb1105fbc1 [project @ 1998-11-19 00:06:30 by jwe]
jwe
parents: 3219
diff changeset
424 {
3deb1105fbc1 [project @ 1998-11-19 00:06:30 by jwe]
jwe
parents: 3219
diff changeset
425 bool retval = false;
31143
b3ca7f891750 maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents: 30569
diff changeset
426 dim_vector dv = m_matrix.dims ();
4875
e674c7111b88 [project @ 2004-04-22 18:12:31 by jwe]
jwe
parents: 4858
diff changeset
427 int nel = dv.numel ();
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4875
diff changeset
428
4875
e674c7111b88 [project @ 2004-04-22 18:12:31 by jwe]
jwe
parents: 4858
diff changeset
429 if (nel > 0)
3220
3deb1105fbc1 [project @ 1998-11-19 00:06:30 by jwe]
jwe
parents: 3219
diff changeset
430 {
31143
b3ca7f891750 maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents: 30569
diff changeset
431 MT t1 (m_matrix.reshape (dim_vector (nel, 1)));
4875
e674c7111b88 [project @ 2004-04-22 18:12:31 by jwe]
jwe
parents: 4858
diff changeset
432
8626
1dce30ab0e72 don't convert NaN to logical in bool expressions
John W. Eaton <jwe@octave.org>
parents: 8290
diff changeset
433 if (t1.any_element_is_nan ())
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
434 octave::err_nan_to_logical_conversion ();
4875
e674c7111b88 [project @ 2004-04-22 18:12:31 by jwe]
jwe
parents: 4858
diff changeset
435
21990
efce657ceb86 Provide a warning when an array is used in an if/while/until (bug #43098).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21751
diff changeset
436 if (nel > 1)
efce657ceb86 Provide a warning when an array is used in an if/while/until (bug #43098).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21751
diff changeset
437 warn_array_as_logical (dv);
efce657ceb86 Provide a warning when an array is used in an if/while/until (bug #43098).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21751
diff changeset
438
21118
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
439 boolNDArray t2 = t1.all ();
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
440
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
441 retval = t2(0);
3220
3deb1105fbc1 [project @ 1998-11-19 00:06:30 by jwe]
jwe
parents: 3219
diff changeset
442 }
4875
e674c7111b88 [project @ 2004-04-22 18:12:31 by jwe]
jwe
parents: 4858
diff changeset
443
3220
3deb1105fbc1 [project @ 1998-11-19 00:06:30 by jwe]
jwe
parents: 3219
diff changeset
444 return retval;
3deb1105fbc1 [project @ 1998-11-19 00:06:30 by jwe]
jwe
parents: 3219
diff changeset
445 }
3deb1105fbc1 [project @ 1998-11-19 00:06:30 by jwe]
jwe
parents: 3219
diff changeset
446
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21118
diff changeset
447 template <typename MT>
3219
30770ba4457a [project @ 1998-11-13 03:44:31 by jwe]
jwe
parents:
diff changeset
448 bool
30770ba4457a [project @ 1998-11-13 03:44:31 by jwe]
jwe
parents:
diff changeset
449 octave_base_matrix<MT>::print_as_scalar (void) const
30770ba4457a [project @ 1998-11-13 03:44:31 by jwe]
jwe
parents:
diff changeset
450 {
4654
a9b22513b7a6 [project @ 2003-11-24 18:56:35 by jwe]
jwe
parents: 4643
diff changeset
451 dim_vector dv = dims ();
3219
30770ba4457a [project @ 1998-11-13 03:44:31 by jwe]
jwe
parents:
diff changeset
452
4654
a9b22513b7a6 [project @ 2003-11-24 18:56:35 by jwe]
jwe
parents: 4643
diff changeset
453 return (dv.all_ones () || dv.any_zero ());
3219
30770ba4457a [project @ 1998-11-13 03:44:31 by jwe]
jwe
parents:
diff changeset
454 }
30770ba4457a [project @ 1998-11-13 03:44:31 by jwe]
jwe
parents:
diff changeset
455
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21118
diff changeset
456 template <typename MT>
3219
30770ba4457a [project @ 1998-11-13 03:44:31 by jwe]
jwe
parents:
diff changeset
457 void
18416
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18100
diff changeset
458 octave_base_matrix<MT>::print (std::ostream& os, bool pr_as_read_syntax)
3219
30770ba4457a [project @ 1998-11-13 03:44:31 by jwe]
jwe
parents:
diff changeset
459 {
30770ba4457a [project @ 1998-11-13 03:44:31 by jwe]
jwe
parents:
diff changeset
460 print_raw (os, pr_as_read_syntax);
30770ba4457a [project @ 1998-11-13 03:44:31 by jwe]
jwe
parents:
diff changeset
461 newline (os);
30770ba4457a [project @ 1998-11-13 03:44:31 by jwe]
jwe
parents:
diff changeset
462 }
30770ba4457a [project @ 1998-11-13 03:44:31 by jwe]
jwe
parents:
diff changeset
463
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21118
diff changeset
464 template <typename MT>
3219
30770ba4457a [project @ 1998-11-13 03:44:31 by jwe]
jwe
parents:
diff changeset
465 void
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3928
diff changeset
466 octave_base_matrix<MT>::print_info (std::ostream& os,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
467 const std::string& prefix) const
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3928
diff changeset
468 {
31143
b3ca7f891750 maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents: 30569
diff changeset
469 m_matrix.print_info (os, prefix);
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3928
diff changeset
470 }
10670
654fbde5dceb make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents: 10521
diff changeset
471
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21118
diff changeset
472 template <typename MT>
17870
1d2e709bbbda rework short_disp methods
John W. Eaton <jwe@octave.org>
parents: 17866
diff changeset
473 void
1d2e709bbbda rework short_disp methods
John W. Eaton <jwe@octave.org>
parents: 17866
diff changeset
474 octave_base_matrix<MT>::short_disp (std::ostream& os) const
17866
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
475 {
31143
b3ca7f891750 maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents: 30569
diff changeset
476 if (m_matrix.isempty ())
17870
1d2e709bbbda rework short_disp methods
John W. Eaton <jwe@octave.org>
parents: 17866
diff changeset
477 os << "[]";
31143
b3ca7f891750 maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents: 30569
diff changeset
478 else if (m_matrix.ndims () == 2)
17866
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
479 {
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
480 // FIXME: should this be configurable?
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
481 octave_idx_type max_elts = 10;
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
482 octave_idx_type elts = 0;
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
483
31143
b3ca7f891750 maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents: 30569
diff changeset
484 octave_idx_type nel = m_matrix.numel ();
17866
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
485
31143
b3ca7f891750 maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents: 30569
diff changeset
486 octave_idx_type nr = m_matrix.rows ();
b3ca7f891750 maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents: 30569
diff changeset
487 octave_idx_type nc = m_matrix.columns ();
17866
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
488
23807
336f89b6208b Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents: 23577
diff changeset
489 os << '[';
17866
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
490
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
491 for (octave_idx_type i = 0; i < nr; i++)
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
492 {
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
493 for (octave_idx_type j = 0; j < nc; j++)
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
494 {
17870
1d2e709bbbda rework short_disp methods
John W. Eaton <jwe@octave.org>
parents: 17866
diff changeset
495 std::ostringstream buf;
31143
b3ca7f891750 maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents: 30569
diff changeset
496 octave_print_internal (buf, m_matrix(j*nr+i));
17870
1d2e709bbbda rework short_disp methods
John W. Eaton <jwe@octave.org>
parents: 17866
diff changeset
497 std::string tmp = buf.str ();
29659
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29363
diff changeset
498 std::size_t pos = tmp.find_first_not_of (' ');
19216
4b6f87c6739f Fix out_of_range from substr in short_disp for GUI symtab (bug #43351)
Andreas Weber <andy.weber.aw@gmail.com>
parents: 17875
diff changeset
499 if (pos != std::string::npos)
4b6f87c6739f Fix out_of_range from substr in short_disp for GUI symtab (bug #43351)
Andreas Weber <andy.weber.aw@gmail.com>
parents: 17875
diff changeset
500 os << tmp.substr (pos);
4b6f87c6739f Fix out_of_range from substr in short_disp for GUI symtab (bug #43351)
Andreas Weber <andy.weber.aw@gmail.com>
parents: 17875
diff changeset
501 else if (! tmp.empty ())
4b6f87c6739f Fix out_of_range from substr in short_disp for GUI symtab (bug #43351)
Andreas Weber <andy.weber.aw@gmail.com>
parents: 17875
diff changeset
502 os << tmp[0];
17866
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
503
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
504 if (++elts >= max_elts)
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
505 goto done;
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
506
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
507 if (j < nc - 1)
17870
1d2e709bbbda rework short_disp methods
John W. Eaton <jwe@octave.org>
parents: 17866
diff changeset
508 os << ", ";
17866
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
509 }
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
510
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
511 if (i < nr - 1 && elts < max_elts)
17870
1d2e709bbbda rework short_disp methods
John W. Eaton <jwe@octave.org>
parents: 17866
diff changeset
512 os << "; ";
17866
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
513 }
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
514
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
515 done:
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
516
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
517 if (nel <= max_elts)
23807
336f89b6208b Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents: 23577
diff changeset
518 os << ']';
17866
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
519 }
17875
8fde5edabedd Display '...' for ND-arrays in GUI Variable window.
Rik <rik@octave.org>
parents: 17870
diff changeset
520 else
8fde5edabedd Display '...' for ND-arrays in GUI Variable window.
Rik <rik@octave.org>
parents: 17870
diff changeset
521 os << "...";
17866
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
522 }
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
523
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21118
diff changeset
524 template <typename MT>
24668
d4dd741b2794 new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents: 24643
diff changeset
525 float_display_format
d4dd741b2794 new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents: 24643
diff changeset
526 octave_base_matrix<MT>::get_edit_display_format (void) const
d4dd741b2794 new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents: 24643
diff changeset
527 {
31143
b3ca7f891750 maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents: 30569
diff changeset
528 return make_format (m_matrix);
24668
d4dd741b2794 new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents: 24643
diff changeset
529 }
d4dd741b2794 new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents: 24643
diff changeset
530
d4dd741b2794 new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents: 24643
diff changeset
531 template <typename MT>
24643
78aff6f14227 more variable editor improvements; allow more variable types to be edited
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
532 std::string
24668
d4dd741b2794 new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents: 24643
diff changeset
533 octave_base_matrix<MT>::edit_display (const float_display_format& fmt,
d4dd741b2794 new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents: 24643
diff changeset
534 octave_idx_type i,
24643
78aff6f14227 more variable editor improvements; allow more variable types to be edited
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
535 octave_idx_type j) const
78aff6f14227 more variable editor improvements; allow more variable types to be edited
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
536 {
78aff6f14227 more variable editor improvements; allow more variable types to be edited
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
537 std::ostringstream buf;
31143
b3ca7f891750 maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents: 30569
diff changeset
538 octave_print_internal (buf, fmt, m_matrix(i, j));
24643
78aff6f14227 more variable editor improvements; allow more variable types to be edited
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
539 return buf.str ();
78aff6f14227 more variable editor improvements; allow more variable types to be edited
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
540 }
78aff6f14227 more variable editor improvements; allow more variable types to be edited
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
541
78aff6f14227 more variable editor improvements; allow more variable types to be edited
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
542 template <typename MT>
10670
654fbde5dceb make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents: 10521
diff changeset
543 octave_value
654fbde5dceb make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents: 10521
diff changeset
544 octave_base_matrix<MT>::fast_elem_extract (octave_idx_type n) const
654fbde5dceb make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents: 10521
diff changeset
545 {
31143
b3ca7f891750 maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents: 30569
diff changeset
546 if (n < m_matrix.numel ())
b3ca7f891750 maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents: 30569
diff changeset
547 return m_matrix(n);
10670
654fbde5dceb make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents: 10521
diff changeset
548 else
654fbde5dceb make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents: 10521
diff changeset
549 return octave_value ();
654fbde5dceb make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents: 10521
diff changeset
550 }
654fbde5dceb make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents: 10521
diff changeset
551
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21118
diff changeset
552 template <typename MT>
10670
654fbde5dceb make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents: 10521
diff changeset
553 bool
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
554 octave_base_matrix<MT>::fast_elem_insert (octave_idx_type n,
10670
654fbde5dceb make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents: 10521
diff changeset
555 const octave_value& x)
654fbde5dceb make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents: 10521
diff changeset
556 {
31143
b3ca7f891750 maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents: 30569
diff changeset
557 if (n < m_matrix.numel ())
10670
654fbde5dceb make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents: 10521
diff changeset
558 {
654fbde5dceb make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents: 10521
diff changeset
559 // Don't use builtin_type () here to avoid an extra VM call.
654fbde5dceb make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents: 10521
diff changeset
560 typedef typename MT::element_type ET;
654fbde5dceb make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents: 10521
diff changeset
561 const builtin_type_t btyp = class_to_btyp<ET>::btyp;
654fbde5dceb make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents: 10521
diff changeset
562 if (btyp == btyp_unknown) // Dead branch?
654fbde5dceb make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents: 10521
diff changeset
563 return false;
654fbde5dceb make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents: 10521
diff changeset
564
654fbde5dceb make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents: 10521
diff changeset
565 // Set up the pointer to the proper place.
31143
b3ca7f891750 maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents: 30569
diff changeset
566 void *here = reinterpret_cast<void *> (&m_matrix(n));
10670
654fbde5dceb make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents: 10521
diff changeset
567 // Ask x to store there if it can.
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
568 return x.get_rep ().fast_elem_insert_self (here, btyp);
10670
654fbde5dceb make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents: 10521
diff changeset
569 }
654fbde5dceb make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents: 10521
diff changeset
570 else
654fbde5dceb make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents: 10521
diff changeset
571 return false;
654fbde5dceb make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents: 10521
diff changeset
572 }