Mercurial > hg > octave-nkf
annotate src/pt-mat.cc @ 10715:53253f796351
make [] (hopefully) more Matlab compatible
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Fri, 18 Jun 2010 14:12:24 +0200 |
parents | 3f973f6c841c |
children | f3892d8eea9f |
rev | line source |
---|---|
1741 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, |
8920 | 4 2005, 2006, 2007, 2008, 2009 John W. Eaton |
1741 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
1741 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
1741 | 21 |
22 */ | |
23 | |
24 #ifdef HAVE_CONFIG_H | |
25 #include <config.h> | |
26 #endif | |
27 | |
3503 | 28 #include <iostream> |
1741 | 29 |
5502 | 30 #include "quit.h" |
31 | |
2172 | 32 #include "defun.h" |
1741 | 33 #include "error.h" |
34 #include "oct-obj.h" | |
2982 | 35 #include "pt-arg-list.h" |
3770 | 36 #include "pt-bp.h" |
1741 | 37 #include "pt-exp.h" |
38 #include "pt-mat.h" | |
2124 | 39 #include "pt-walk.h" |
2201 | 40 #include "utils.h" |
2371 | 41 #include "ov.h" |
42 #include "variables.h" | |
1741 | 43 |
9460
1fddcf651559
avoid complex -> real conversion when constructing arrays with []
John W. Eaton <jwe@octave.org>
parents:
9389
diff
changeset
|
44 #include "ov-cx-mat.h" |
1fddcf651559
avoid complex -> real conversion when constructing arrays with []
John W. Eaton <jwe@octave.org>
parents:
9389
diff
changeset
|
45 #include "ov-flt-cx-mat.h" |
5630 | 46 #include "ov-re-sparse.h" |
47 #include "ov-cx-sparse.h" | |
48 | |
2254 | 49 // The character to fill with when creating string arrays. |
3836 | 50 char Vstring_fill_char = ' '; |
2254 | 51 |
1741 | 52 // General matrices. This list type is much more work to handle than |
53 // constant matrices, but it allows us to construct matrices from | |
54 // other matrices, variables, and functions. | |
55 | |
1827 | 56 // But first, some internal classes that make our job much easier. |
1741 | 57 |
1827 | 58 class |
59 tm_row_const | |
1741 | 60 { |
1827 | 61 private: |
62 | |
63 class | |
4219 | 64 tm_row_const_rep : public octave_base_list<octave_value> |
1827 | 65 { |
66 public: | |
67 | |
68 tm_row_const_rep (void) | |
5514 | 69 : count (1), dv (0, 0), all_str (false), |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
70 all_sq_str (false), all_dq_str (false), |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
71 some_str (false), all_real (false), all_cmplx (false), |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
72 all_mt (true), any_sparse (false), any_class (false), |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
73 class_nm (), ok (false) |
5533 | 74 { } |
1827 | 75 |
2971 | 76 tm_row_const_rep (const tree_argument_list& row) |
5514 | 77 : count (1), dv (0, 0), all_str (false), all_sq_str (false), |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
78 some_str (false), all_real (false), all_cmplx (false), |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
79 all_mt (true), any_sparse (false), any_class (false), |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
80 class_nm (), ok (false) |
3110 | 81 { init (row); } |
1827 | 82 |
83 ~tm_row_const_rep (void) { } | |
84 | |
85 int count; | |
86 | |
4765 | 87 dim_vector dv; |
1741 | 88 |
1827 | 89 bool all_str; |
5280 | 90 bool all_sq_str; |
91 bool all_dq_str; | |
3110 | 92 bool some_str; |
5502 | 93 bool all_real; |
94 bool all_cmplx; | |
2602 | 95 bool all_mt; |
5630 | 96 bool any_sparse; |
8147
9a5ef4f632a3
Add class dispatch for [] operator to vertcat/horzcat methods
David Bateman <dbateman@free.fr>
parents:
8107
diff
changeset
|
97 bool any_class; |
1827 | 98 |
5533 | 99 std::string class_nm; |
100 | |
1827 | 101 bool ok; |
102 | |
4501 | 103 bool do_init_element (tree_expression *, const octave_value&, bool&); |
104 | |
2971 | 105 void init (const tree_argument_list&); |
1827 | 106 |
107 private: | |
108 | |
109 tm_row_const_rep (const tm_row_const_rep&); | |
110 | |
2971 | 111 tm_row_const_rep& operator = (const tm_row_const_rep&); |
2419 | 112 |
113 void eval_warning (const char *msg, int l, int c) const; | |
1827 | 114 }; |
115 | |
116 public: | |
117 | |
4219 | 118 typedef tm_row_const_rep::iterator iterator; |
119 typedef tm_row_const_rep::const_iterator const_iterator; | |
120 | |
2990 | 121 tm_row_const (void) |
122 : rep (0) { } | |
1827 | 123 |
2971 | 124 tm_row_const (const tree_argument_list& row) |
125 : rep (new tm_row_const_rep (row)) { } | |
1827 | 126 |
2990 | 127 tm_row_const (const tm_row_const& x) |
128 : rep (x.rep) | |
129 { | |
130 if (rep) | |
131 rep->count++; | |
132 } | |
1827 | 133 |
134 tm_row_const& operator = (const tm_row_const& x) | |
2990 | 135 { |
136 if (this != &x && rep != x.rep) | |
137 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
138 if (rep && --rep->count == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
139 delete rep; |
1741 | 140 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
141 rep = x.rep; |
1827 | 142 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
143 if (rep) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
144 rep->count++; |
2990 | 145 } |
1741 | 146 |
2990 | 147 return *this; |
148 } | |
1827 | 149 |
150 ~tm_row_const (void) | |
2990 | 151 { |
152 if (rep && --rep->count == 0) | |
153 delete rep; | |
154 } | |
1741 | 155 |
5514 | 156 octave_idx_type rows (void) { return rep->dv(0); } |
157 octave_idx_type cols (void) { return rep->dv(1); } | |
4765 | 158 |
6200 | 159 bool empty (void) const { return rep->empty (); } |
160 | |
8147
9a5ef4f632a3
Add class dispatch for [] operator to vertcat/horzcat methods
David Bateman <dbateman@free.fr>
parents:
8107
diff
changeset
|
161 size_t length (void) const { return rep->length (); } |
9a5ef4f632a3
Add class dispatch for [] operator to vertcat/horzcat methods
David Bateman <dbateman@free.fr>
parents:
8107
diff
changeset
|
162 |
4765 | 163 dim_vector dims (void) { return rep->dv; } |
1827 | 164 |
2868 | 165 bool all_strings_p (void) const { return rep->all_str; } |
5280 | 166 bool all_sq_strings_p (void) const { return rep->all_sq_str; } |
167 bool all_dq_strings_p (void) const { return rep->all_dq_str; } | |
3110 | 168 bool some_strings_p (void) const { return rep->some_str; } |
5502 | 169 bool all_real_p (void) const { return rep->all_real; } |
170 bool all_complex_p (void) const { return rep->all_cmplx; } | |
2868 | 171 bool all_empty_p (void) const { return rep->all_mt; } |
5630 | 172 bool any_sparse_p (void) const { return rep->any_sparse; } |
8147
9a5ef4f632a3
Add class dispatch for [] operator to vertcat/horzcat methods
David Bateman <dbateman@free.fr>
parents:
8107
diff
changeset
|
173 bool any_class_p (void) const { return rep->any_class; } |
1827 | 174 |
5533 | 175 std::string class_name (void) const { return rep->class_nm; } |
176 | |
4219 | 177 operator bool () const { return (rep && rep->ok); } |
1827 | 178 |
4219 | 179 iterator begin (void) { return rep->begin (); } |
180 const_iterator begin (void) const { return rep->begin (); } | |
181 | |
182 iterator end (void) { return rep->end (); } | |
183 const_iterator end (void) const { return rep->end (); } | |
1827 | 184 |
185 private: | |
186 | |
187 tm_row_const_rep *rep; | |
188 }; | |
189 | |
8107
8655dc0906e6
Special case single type conacation in Fcat. Rework cell2mat to take advantage
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
190 std::string |
5533 | 191 get_concat_class (const std::string& c1, const std::string& c2) |
192 { | |
193 std::string retval = octave_base_value::static_class_name (); | |
194 | |
195 if (c1 == c2) | |
196 retval = c1; | |
9389
0f85d9564057
fix result class calculation in pt-mat.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9145
diff
changeset
|
197 else if (c1.empty ()) |
9145
53364bb317d4
fix concatenation with all-zero matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
198 retval = c2; |
9389
0f85d9564057
fix result class calculation in pt-mat.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9145
diff
changeset
|
199 else if (c2.empty ()) |
0f85d9564057
fix result class calculation in pt-mat.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9145
diff
changeset
|
200 retval = c1; |
5533 | 201 else |
202 { | |
203 bool c1_is_int = (c1 == "int8" || c1 == "uint8" | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
204 || c1 == "int16" || c1 == "uint16" |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
205 || c1 == "int32" || c1 == "uint32" |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
206 || c1 == "int64" || c1 == "uint64"); |
5533 | 207 bool c2_is_int = (c2 == "int8" || c2 == "uint8" |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
208 || c2 == "int16" || c2 == "uint16" |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
209 || c2 == "int32" || c2 == "uint32" |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
210 || c2 == "int64" || c2 == "uint64"); |
5533 | 211 |
212 bool c1_is_char = (c1 == "char"); | |
213 bool c2_is_char = (c2 == "char"); | |
214 | |
215 bool c1_is_double = (c1 == "double"); | |
216 bool c2_is_double = (c2 == "double"); | |
217 | |
218 bool c1_is_single = (c1 == "single"); | |
219 bool c2_is_single = (c2 == "single"); | |
220 | |
221 bool c1_is_logical = (c1 == "logical"); | |
222 bool c2_is_logical = (c2 == "logical"); | |
223 | |
224 bool c1_is_built_in_type | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
225 = (c1_is_int || c1_is_char || c1_is_double || c1_is_single |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
226 || c1_is_logical); |
5533 | 227 |
228 bool c2_is_built_in_type | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
229 = (c2_is_int || c2_is_char || c2_is_double || c2_is_single |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
230 || c2_is_logical); |
5533 | 231 |
232 // Order is important here... | |
233 | |
234 if (c1_is_char && c2_is_built_in_type) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
235 retval = c1; |
5533 | 236 else if (c2_is_char && c1_is_built_in_type) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
237 retval = c2; |
5533 | 238 else if (c1_is_int && c2_is_built_in_type) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
239 retval = c1; |
5533 | 240 else if (c2_is_int && c1_is_built_in_type) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
241 retval = c2; |
5533 | 242 else if (c1_is_single && c2_is_built_in_type) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
243 retval = c1; |
5533 | 244 else if (c2_is_single && c1_is_built_in_type) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
245 retval = c2; |
5533 | 246 else if (c1_is_double && c2_is_built_in_type) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
247 retval = c1; |
5533 | 248 else if (c2_is_double && c1_is_built_in_type) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
249 retval = c2; |
5533 | 250 else if (c1_is_logical && c2_is_logical) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
251 retval = c1; |
5533 | 252 } |
253 | |
254 return retval; | |
255 } | |
256 | |
10715
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
257 static void |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
258 eval_error (const char *msg, int l, int c, |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
259 const dim_vector& x, const dim_vector& y) |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
260 { |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
261 if (l == -1 && c == -1) |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
262 { |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
263 ::error ("%s (%s vs %s)", msg, x.str ().c_str (), y.str ().c_str ()); |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
264 } |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
265 else |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
266 { |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
267 ::error ("%s (%s vs %s) near line %d, column %d", msg, |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
268 x.str ().c_str (), y.str ().c_str (), l, c); |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
269 } |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
270 } |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
271 |
4501 | 272 bool |
273 tm_row_const::tm_row_const_rep::do_init_element (tree_expression *elt, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
274 const octave_value& val, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
275 bool& first_elem) |
4501 | 276 { |
5533 | 277 std::string this_elt_class_nm = val.class_name (); |
278 | |
4765 | 279 dim_vector this_elt_dv = val.dims (); |
280 | |
9145
53364bb317d4
fix concatenation with all-zero matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
281 class_nm = get_concat_class (class_nm, this_elt_class_nm); |
53364bb317d4
fix concatenation with all-zero matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
282 |
10715
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
283 if (! this_elt_dv.zero_by_zero ()) |
4501 | 284 { |
285 all_mt = false; | |
286 | |
287 if (first_elem) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
288 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
289 first_elem = false; |
10715
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
290 dv = this_elt_dv; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
291 } |
10715
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
292 else if (! dv.hvcat (this_elt_dv, 1)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
293 { |
10715
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
294 eval_error ("horizontal dimensions mismatch", elt->line (), elt->column (), dv, this_elt_dv); |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
295 return false; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
296 } |
4501 | 297 } |
298 | |
4915 | 299 append (val); |
300 | |
4501 | 301 if (all_str && ! val.is_string ()) |
302 all_str = false; | |
303 | |
5280 | 304 if (all_sq_str && ! val.is_sq_string ()) |
305 all_sq_str = false; | |
306 | |
307 if (all_dq_str && ! val.is_dq_string ()) | |
308 all_dq_str = false; | |
309 | |
4501 | 310 if (! some_str && val.is_string ()) |
311 some_str = true; | |
312 | |
5502 | 313 if (all_real && ! val.is_real_type ()) |
314 all_real = false; | |
315 | |
316 if (all_cmplx && ! (val.is_complex_type () || val.is_real_type ())) | |
317 all_cmplx = false; | |
4501 | 318 |
5631 | 319 if (!any_sparse && val.is_sparse_type ()) |
5630 | 320 any_sparse = true; |
321 | |
8147
9a5ef4f632a3
Add class dispatch for [] operator to vertcat/horzcat methods
David Bateman <dbateman@free.fr>
parents:
8107
diff
changeset
|
322 if (!any_class && val.is_object ()) |
9a5ef4f632a3
Add class dispatch for [] operator to vertcat/horzcat methods
David Bateman <dbateman@free.fr>
parents:
8107
diff
changeset
|
323 any_class = true; |
9a5ef4f632a3
Add class dispatch for [] operator to vertcat/horzcat methods
David Bateman <dbateman@free.fr>
parents:
8107
diff
changeset
|
324 |
4501 | 325 return true; |
326 } | |
327 | |
1827 | 328 void |
2971 | 329 tm_row_const::tm_row_const_rep::init (const tree_argument_list& row) |
1827 | 330 { |
331 all_str = true; | |
5280 | 332 all_sq_str = true; |
333 all_dq_str = true; | |
5502 | 334 all_real = true; |
335 all_cmplx = true; | |
5630 | 336 any_sparse = false; |
8147
9a5ef4f632a3
Add class dispatch for [] operator to vertcat/horzcat methods
David Bateman <dbateman@free.fr>
parents:
8107
diff
changeset
|
337 any_class = false; |
1827 | 338 |
339 bool first_elem = true; | |
340 | |
4219 | 341 for (tree_argument_list::const_iterator p = row.begin (); |
342 p != row.end (); | |
343 p++) | |
1827 | 344 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
10116
diff
changeset
|
345 octave_quit (); |
5502 | 346 |
4219 | 347 tree_expression *elt = *p; |
1827 | 348 |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8147
diff
changeset
|
349 octave_value tmp = elt->rvalue1 (); |
1827 | 350 |
351 if (error_state || tmp.is_undefined ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
352 break; |
1827 | 353 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
354 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
355 if (tmp.is_cs_list ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
356 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
357 octave_value_list tlst = tmp.list_value (); |
2602 | 358 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
359 for (octave_idx_type i = 0; i < tlst.length (); i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
360 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
361 octave_quit (); |
5502 | 362 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
363 if (! do_init_element (elt, tlst(i), first_elem)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
364 goto done; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
365 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
366 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
367 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
368 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
369 if (! do_init_element (elt, tmp, first_elem)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
370 goto done; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
371 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
372 } |
1827 | 373 } |
374 | |
4501 | 375 done: |
376 | |
1827 | 377 ok = ! error_state; |
1741 | 378 } |
379 | |
2419 | 380 void |
381 tm_row_const::tm_row_const_rep::eval_warning (const char *msg, int l, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
382 int c) const |
2419 | 383 { |
384 if (l == -1 && c == -1) | |
5781 | 385 warning_with_id ("Octave:empty-list-elements", "%s", msg); |
2419 | 386 else |
5781 | 387 warning_with_id ("Octave:empty-list-elements", |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
388 "%s near line %d, column %d", msg, l, c); |
2419 | 389 } |
390 | |
1827 | 391 class |
4219 | 392 tm_const : public octave_base_list<tm_row_const> |
1827 | 393 { |
394 public: | |
395 | |
396 tm_const (const tree_matrix& tm) | |
5514 | 397 : dv (0, 0), all_str (false), all_sq_str (false), all_dq_str (false), |
5502 | 398 some_str (false), all_real (false), all_cmplx (false), |
8147
9a5ef4f632a3
Add class dispatch for [] operator to vertcat/horzcat methods
David Bateman <dbateman@free.fr>
parents:
8107
diff
changeset
|
399 all_mt (true), any_sparse (false), any_class (false), |
9389
0f85d9564057
fix result class calculation in pt-mat.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9145
diff
changeset
|
400 class_nm (), ok (false) |
5533 | 401 { init (tm); } |
1827 | 402 |
403 ~tm_const (void) { } | |
404 | |
5514 | 405 octave_idx_type rows (void) const { return dv.elem (0); } |
406 octave_idx_type cols (void) const { return dv.elem (1); } | |
4765 | 407 |
408 dim_vector dims (void) const { return dv; } | |
1827 | 409 |
2868 | 410 bool all_strings_p (void) const { return all_str; } |
5280 | 411 bool all_sq_strings_p (void) const { return all_sq_str; } |
412 bool all_dq_strings_p (void) const { return all_dq_str; } | |
3110 | 413 bool some_strings_p (void) const { return some_str; } |
5502 | 414 bool all_real_p (void) const { return all_real; } |
415 bool all_complex_p (void) const { return all_cmplx; } | |
2868 | 416 bool all_empty_p (void) const { return all_mt; } |
5630 | 417 bool any_sparse_p (void) const { return any_sparse; } |
8147
9a5ef4f632a3
Add class dispatch for [] operator to vertcat/horzcat methods
David Bateman <dbateman@free.fr>
parents:
8107
diff
changeset
|
418 bool any_class_p (void) const { return any_class; } |
1827 | 419 |
5533 | 420 std::string class_name (void) const { return class_nm; } |
421 | |
3145 | 422 operator bool () const { return ok; } |
1827 | 423 |
424 private: | |
425 | |
4765 | 426 dim_vector dv; |
1827 | 427 |
428 bool all_str; | |
5280 | 429 bool all_sq_str; |
430 bool all_dq_str; | |
3110 | 431 bool some_str; |
5502 | 432 bool all_real; |
433 bool all_cmplx; | |
2602 | 434 bool all_mt; |
5630 | 435 bool any_sparse; |
8147
9a5ef4f632a3
Add class dispatch for [] operator to vertcat/horzcat methods
David Bateman <dbateman@free.fr>
parents:
8107
diff
changeset
|
436 bool any_class; |
1827 | 437 |
5533 | 438 std::string class_nm; |
439 | |
1827 | 440 bool ok; |
441 | |
442 tm_const (void); | |
443 | |
444 tm_const (const tm_const&); | |
445 | |
446 tm_const& operator = (const tm_const&); | |
447 | |
448 void init (const tree_matrix& tm); | |
449 }; | |
450 | |
451 void | |
452 tm_const::init (const tree_matrix& tm) | |
1741 | 453 { |
1827 | 454 all_str = true; |
5280 | 455 all_sq_str = true; |
456 all_dq_str = true; | |
5502 | 457 all_real = true; |
458 all_cmplx = true; | |
5630 | 459 any_sparse = false; |
8147
9a5ef4f632a3
Add class dispatch for [] operator to vertcat/horzcat methods
David Bateman <dbateman@free.fr>
parents:
8107
diff
changeset
|
460 any_class = false; |
1827 | 461 |
462 bool first_elem = true; | |
463 | |
464 // Just eval and figure out if what we have is complex or all | |
465 // strings. We can't check columns until we know that this is a | |
466 // numeric matrix -- collections of strings can have elements of | |
467 // different lengths. | |
468 | |
4219 | 469 for (tree_matrix::const_iterator p = tm.begin (); p != tm.end (); p++) |
1827 | 470 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
10116
diff
changeset
|
471 octave_quit (); |
5502 | 472 |
4219 | 473 tree_argument_list *elt = *p; |
1827 | 474 |
475 tm_row_const tmp (*elt); | |
476 | |
6200 | 477 if (tmp && ! tmp.empty ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
478 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
479 if (all_str && ! tmp.all_strings_p ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
480 all_str = false; |
1827 | 481 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
482 if (all_sq_str && ! tmp.all_sq_strings_p ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
483 all_sq_str = false; |
5280 | 484 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
485 if (all_dq_str && ! tmp.all_dq_strings_p ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
486 all_dq_str = false; |
5280 | 487 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
488 if (! some_str && tmp.some_strings_p ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
489 some_str = true; |
3110 | 490 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
491 if (all_real && ! tmp.all_real_p ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
492 all_real = false; |
5502 | 493 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
494 if (all_cmplx && ! tmp.all_complex_p ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
495 all_cmplx = false; |
1827 | 496 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
497 if (all_mt && ! tmp.all_empty_p ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
498 all_mt = false; |
2602 | 499 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
500 if (!any_sparse && tmp.any_sparse_p ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
501 any_sparse = true; |
5630 | 502 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
503 if (!any_class && tmp.any_class_p ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
504 any_class = true; |
8147
9a5ef4f632a3
Add class dispatch for [] operator to vertcat/horzcat methods
David Bateman <dbateman@free.fr>
parents:
8107
diff
changeset
|
505 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
506 append (tmp); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
507 } |
1827 | 508 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
509 break; |
1827 | 510 } |
511 | |
512 if (! error_state) | |
513 { | |
4219 | 514 for (iterator p = begin (); p != end (); p++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
515 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
516 octave_quit (); |
5502 | 517 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
518 tm_row_const elt = *p; |
1827 | 519 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
520 octave_idx_type this_elt_nr = elt.rows (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
521 octave_idx_type this_elt_nc = elt.cols (); |
1827 | 522 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
523 std::string this_elt_class_nm = elt.class_name (); |
10715
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
524 class_nm = get_concat_class (class_nm, this_elt_class_nm); |
5533 | 525 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
526 dim_vector this_elt_dv = elt.dims (); |
4765 | 527 |
10715
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
528 all_mt = false; |
4765 | 529 |
10715
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
530 if (first_elem) |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
531 { |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
532 first_elem = false; |
4765 | 533 |
10715
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
534 dv = this_elt_dv; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
535 } |
10715
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
536 else if (all_str && dv.length () == 2 |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
537 && this_elt_dv.length () == 2) |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
538 { |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
539 // FIXME: this is Octave's specialty. Character matrices allow |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
540 // rows of unequal length. |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
541 if (this_elt_nc > cols ()) |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
542 dv(1) = this_elt_nc; |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
543 dv(0) += this_elt_nr; |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
544 } |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
545 else if (! dv.hvcat (this_elt_dv, 0)) |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
546 { |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
547 eval_error ("vertical dimensions mismatch", -1, -1, |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
548 dv, this_elt_dv); |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
549 return; |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
550 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
551 } |
1827 | 552 } |
553 | |
554 ok = ! error_state; | |
1741 | 555 } |
556 | |
2990 | 557 tree_matrix::~tree_matrix (void) |
558 { | |
4219 | 559 while (! empty ()) |
2990 | 560 { |
4219 | 561 iterator p = begin (); |
562 delete *p; | |
563 erase (p); | |
2990 | 564 } |
565 } | |
566 | |
1827 | 567 bool |
4267 | 568 tree_matrix::has_magic_end (void) const |
569 { | |
570 for (const_iterator p = begin (); p != end (); p++) | |
571 { | |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
10116
diff
changeset
|
572 octave_quit (); |
5502 | 573 |
4267 | 574 tree_argument_list *elt = *p; |
575 | |
576 if (elt && elt->has_magic_end ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
577 return true; |
4267 | 578 } |
579 | |
580 return false; | |
581 } | |
582 | |
583 bool | |
2529 | 584 tree_matrix::all_elements_are_constant (void) const |
1827 | 585 { |
4219 | 586 for (const_iterator p = begin (); p != end (); p++) |
1827 | 587 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
10116
diff
changeset
|
588 octave_quit (); |
5502 | 589 |
4219 | 590 tree_argument_list *elt = *p; |
1827 | 591 |
2529 | 592 if (! elt->all_elements_are_constant ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
593 return false; |
1827 | 594 } |
595 | |
596 return true; | |
597 } | |
598 | |
2971 | 599 octave_value_list |
600 tree_matrix::rvalue (int nargout) | |
601 { | |
602 octave_value_list retval; | |
603 | |
604 if (nargout > 1) | |
605 error ("invalid number of output arguments for matrix list"); | |
606 else | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8147
diff
changeset
|
607 retval = rvalue1 (nargout); |
2971 | 608 |
609 return retval; | |
610 } | |
611 | |
8107
8655dc0906e6
Special case single type conacation in Fcat. Rework cell2mat to take advantage
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
612 void |
5280 | 613 maybe_warn_string_concat (bool all_dq_strings_p, bool all_sq_strings_p) |
614 { | |
5781 | 615 if (! (all_dq_strings_p || all_sq_strings_p)) |
616 warning_with_id ("Octave:string-concat", | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
617 "concatenation of different character string types may have unintended consequences"); |
5280 | 618 } |
619 | |
10535
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
620 template<class TYPE, class T> |
10116
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
621 static void |
10535
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
622 single_type_concat (Array<T>& result, |
10116
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
623 tm_const& tmp) |
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
624 { |
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
625 octave_idx_type r = 0, c = 0; |
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
626 |
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
627 for (tm_const::iterator p = tmp.begin (); p != tmp.end (); p++) |
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
628 { |
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
629 tm_row_const row = *p; |
10715
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
630 // Skip empty arrays to allow looser rules. |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
631 if (row.dims ().any_zero ()) |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
632 continue; |
10116
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
633 |
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
634 for (tm_row_const::iterator q = row.begin (); |
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
635 q != row.end (); |
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
636 q++) |
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
637 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
10116
diff
changeset
|
638 octave_quit (); |
10116
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
639 |
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
640 TYPE ra = octave_value_extract<TYPE> (*q); |
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
641 |
10715
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
642 // Skip empty arrays to allow looser rules. |
10116
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
643 if (! error_state) |
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
644 { |
10715
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
645 if (! ra.is_empty ()) |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
646 { |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
647 result.insert (ra, r, c); |
5502 | 648 |
10715
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
649 if (! error_state) |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
650 c += ra.columns (); |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
651 else |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
652 return; |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
653 } |
10116
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
654 } |
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
655 else |
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
656 return; |
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
657 } |
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
658 |
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
659 r += row.rows (); |
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
660 c = 0; |
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
661 } |
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
662 } |
5533 | 663 |
10535
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
664 template<class TYPE, class T> |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
665 static void |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
666 single_type_concat (Array<T>& result, |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
667 const dim_vector& dv, |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
668 tm_const& tmp) |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
669 { |
10715
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
670 if (dv.any_zero ()) |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
671 { |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
672 result = Array<T> (dv); |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
673 return; |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
674 } |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
675 |
10535
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
676 if (tmp.length () == 1) |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
677 { |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
678 // If possible, forward the operation to liboctave. |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
679 // Single row. |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
680 tm_row_const& row = tmp.front (); |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
681 octave_idx_type ncols = row.length (), i = 0; |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
682 OCTAVE_LOCAL_BUFFER (Array<T>, array_list, ncols); |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
683 |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
684 for (tm_row_const::iterator q = row.begin (); |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
685 q != row.end () && ! error_state; |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
686 q++) |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
687 { |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
688 octave_quit (); |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
689 |
10715
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
690 // Use 0x0 in place of all empty arrays to allow looser rules. |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
691 if (! q->is_empty ()) |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
692 array_list[i] = octave_value_extract<TYPE> (*q); |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
693 i++; |
10535
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
694 } |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
695 |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
696 if (! error_state) |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
697 result = Array<T>::cat (1, ncols, array_list); |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
698 } |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
699 else |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
700 { |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
701 result = Array<T> (dv); |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
702 single_type_concat<TYPE> (result, tmp); |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
703 } |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
704 } |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
705 |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
706 template<class TYPE, class T> |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
707 static void |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
708 single_type_concat (Sparse<T>& result, |
10715
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
709 const dim_vector& dv, |
10535
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
710 tm_const& tmp) |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
711 { |
10715
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
712 if (dv.any_zero ()) |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
713 { |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
714 result = Sparse<T> (dv); |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
715 return; |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
716 } |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
717 |
10535
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
718 // Sparse matrices require preallocation for efficient indexing; besides, |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
719 // only horizontal concatenation can be efficiently handled by indexing. |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
720 // So we just cat all rows through liboctave, then cat the final column. |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
721 octave_idx_type nrows = tmp.length (), j = 0; |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
722 OCTAVE_LOCAL_BUFFER (Sparse<T>, sparse_row_list, nrows); |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
723 for (tm_const::iterator p = tmp.begin (); p != tmp.end (); p++) |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
724 { |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
725 tm_row_const row = *p; |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
726 octave_idx_type ncols = row.length (), i = 0; |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
727 OCTAVE_LOCAL_BUFFER (Sparse<T>, sparse_list, ncols); |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
728 |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
729 for (tm_row_const::iterator q = row.begin (); |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
730 q != row.end () && ! error_state; |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
731 q++) |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
732 { |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
733 octave_quit (); |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
734 |
10715
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
735 // Use 0x0 in place of all empty arrays to allow looser rules. |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
736 if (! q->is_empty ()) |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
737 sparse_list[i] = octave_value_extract<TYPE> (*q); |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
738 i++; |
10535
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
739 } |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
740 |
10715
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
741 Sparse<T> stmp = Sparse<T>::cat (1, ncols, sparse_list); |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
742 // Use 0x0 in place of all empty arrays to allow looser rules. |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
743 if (! stmp.is_empty ()) |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
744 sparse_row_list[j] = stmp; |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
745 j++; |
10535
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
746 } |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
747 |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
748 result = Sparse<T>::cat (0, nrows, sparse_row_list); |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
749 } |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
750 |
10116
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
751 template<class TYPE> |
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
752 static octave_value |
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
753 do_single_type_concat (const dim_vector& dv, |
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
754 tm_const& tmp) |
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
755 { |
10535
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
756 TYPE result; |
10116
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
757 |
10535
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
758 single_type_concat<TYPE> (result, dv, tmp); |
10116
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
759 |
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
760 return result; |
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
761 } |
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
762 |
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
763 template<class TYPE, class OV_TYPE> |
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
764 static octave_value |
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
765 do_single_type_concat_no_mutate (const dim_vector& dv, |
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
766 tm_const& tmp) |
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
767 { |
10535
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
768 TYPE result; |
10116
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
769 |
10535
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
770 single_type_concat<TYPE> (result, dv, tmp); |
10116
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
771 |
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
772 return new OV_TYPE (result); |
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
773 } |
9460
1fddcf651559
avoid complex -> real conversion when constructing arrays with []
John W. Eaton <jwe@octave.org>
parents:
9389
diff
changeset
|
774 |
2086 | 775 octave_value |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8147
diff
changeset
|
776 tree_matrix::rvalue1 (int) |
1741 | 777 { |
6200 | 778 octave_value retval = Matrix (); |
1741 | 779 |
4915 | 780 bool all_strings_p = false; |
5280 | 781 bool all_sq_strings_p = false; |
782 bool all_dq_strings_p = false; | |
4915 | 783 bool all_empty_p = false; |
5502 | 784 bool all_real_p = false; |
785 bool all_complex_p = false; | |
5630 | 786 bool any_sparse_p = false; |
8147
9a5ef4f632a3
Add class dispatch for [] operator to vertcat/horzcat methods
David Bateman <dbateman@free.fr>
parents:
8107
diff
changeset
|
787 bool any_class_p = false; |
4915 | 788 bool frc_str_conv = false; |
1741 | 789 |
4915 | 790 tm_const tmp (*this); |
3110 | 791 |
6200 | 792 if (tmp && ! tmp.empty ()) |
1827 | 793 { |
4765 | 794 dim_vector dv = tmp.dims (); |
4915 | 795 all_strings_p = tmp.all_strings_p (); |
5280 | 796 all_sq_strings_p = tmp.all_sq_strings_p (); |
797 all_dq_strings_p = tmp.all_dq_strings_p (); | |
4915 | 798 all_empty_p = tmp.all_empty_p (); |
5502 | 799 all_real_p = tmp.all_real_p (); |
800 all_complex_p = tmp.all_complex_p (); | |
5630 | 801 any_sparse_p = tmp.any_sparse_p (); |
8147
9a5ef4f632a3
Add class dispatch for [] operator to vertcat/horzcat methods
David Bateman <dbateman@free.fr>
parents:
8107
diff
changeset
|
802 any_class_p = tmp.any_class_p (); |
4915 | 803 frc_str_conv = tmp.some_strings_p (); |
1741 | 804 |
5502 | 805 // Try to speed up the common cases. |
4915 | 806 |
5533 | 807 std::string result_type = tmp.class_name (); |
808 | |
8147
9a5ef4f632a3
Add class dispatch for [] operator to vertcat/horzcat methods
David Bateman <dbateman@free.fr>
parents:
8107
diff
changeset
|
809 if (any_class_p) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
810 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
811 octave_value_list tmp3 (tmp.length (), octave_value ()); |
8147
9a5ef4f632a3
Add class dispatch for [] operator to vertcat/horzcat methods
David Bateman <dbateman@free.fr>
parents:
8107
diff
changeset
|
812 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
813 int j = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
814 for (tm_const::iterator p = tmp.begin (); p != tmp.end (); p++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
815 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
816 octave_quit (); |
8147
9a5ef4f632a3
Add class dispatch for [] operator to vertcat/horzcat methods
David Bateman <dbateman@free.fr>
parents:
8107
diff
changeset
|
817 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
818 tm_row_const row = *p; |
8147
9a5ef4f632a3
Add class dispatch for [] operator to vertcat/horzcat methods
David Bateman <dbateman@free.fr>
parents:
8107
diff
changeset
|
819 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
820 if (row.length () == 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
821 tmp3 (j++) = *(row.begin ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
822 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
823 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
824 octave_value_list tmp1 (row.length (), octave_value ()); |
8147
9a5ef4f632a3
Add class dispatch for [] operator to vertcat/horzcat methods
David Bateman <dbateman@free.fr>
parents:
8107
diff
changeset
|
825 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
826 int i = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
827 for (tm_row_const::iterator q = row.begin (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
828 q != row.end (); q++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
829 tmp1 (i++) = *q; |
8147
9a5ef4f632a3
Add class dispatch for [] operator to vertcat/horzcat methods
David Bateman <dbateman@free.fr>
parents:
8107
diff
changeset
|
830 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
831 octave_value_list tmp2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
832 octave_value fcn = |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
833 symbol_table::find_function ("horzcat", tmp1); |
8147
9a5ef4f632a3
Add class dispatch for [] operator to vertcat/horzcat methods
David Bateman <dbateman@free.fr>
parents:
8107
diff
changeset
|
834 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
835 if (fcn.is_defined ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
836 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
837 tmp2 = fcn.do_multi_index_op (1, tmp1); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
838 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
839 if (error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
840 goto done; |
8147
9a5ef4f632a3
Add class dispatch for [] operator to vertcat/horzcat methods
David Bateman <dbateman@free.fr>
parents:
8107
diff
changeset
|
841 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
842 tmp3 (j++) = tmp2 (0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
843 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
844 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
845 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
846 ::error ("cat not find overloaded horzcat function"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
847 goto done; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
848 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
849 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
850 } |
8147
9a5ef4f632a3
Add class dispatch for [] operator to vertcat/horzcat methods
David Bateman <dbateman@free.fr>
parents:
8107
diff
changeset
|
851 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
852 if (tmp.length () == 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
853 retval = tmp3 (0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
854 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
855 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
856 octave_value_list tmp2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
857 octave_value fcn = symbol_table::find_function ("vertcat", tmp3); |
8147
9a5ef4f632a3
Add class dispatch for [] operator to vertcat/horzcat methods
David Bateman <dbateman@free.fr>
parents:
8107
diff
changeset
|
858 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
859 if (fcn.is_defined ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
860 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
861 tmp2 = fcn.do_multi_index_op (1, tmp3); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
862 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
863 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
864 retval = tmp2 (0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
865 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
866 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
867 ::error ("cat not find overloaded vertcat function"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
868 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
869 } |
8147
9a5ef4f632a3
Add class dispatch for [] operator to vertcat/horzcat methods
David Bateman <dbateman@free.fr>
parents:
8107
diff
changeset
|
870 else if (result_type == "double") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
871 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
872 if (any_sparse_p) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
873 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
874 if (all_real_p) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
875 retval = do_single_type_concat<SparseMatrix> (dv, tmp); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
876 else |
10116
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
877 retval = do_single_type_concat_no_mutate<SparseComplexMatrix, |
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
878 octave_sparse_complex_matrix> (dv, tmp); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
879 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
880 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
881 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
882 if (all_real_p) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
883 retval = do_single_type_concat<NDArray> (dv, tmp); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
884 else |
10116
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
885 retval = do_single_type_concat_no_mutate<ComplexNDArray, |
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
886 octave_complex_matrix> (dv, tmp); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
887 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
888 } |
5533 | 889 else if (result_type == "single") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
890 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
891 if (all_real_p) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
892 retval = do_single_type_concat<FloatNDArray> (dv, tmp); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
893 else |
10116
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
894 retval = do_single_type_concat_no_mutate<FloatComplexNDArray, |
fecebef27388
improve concatenation code using templates instead of macros
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
895 octave_float_complex_matrix> (dv, tmp); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
896 } |
5533 | 897 else if (result_type == "char") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
898 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
899 char type = all_dq_strings_p ? '"' : '\''; |
5280 | 900 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
901 maybe_warn_string_concat (all_dq_strings_p, all_sq_strings_p); |
5280 | 902 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
903 charNDArray result (dv, Vstring_fill_char); |
5502 | 904 |
10535
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
905 single_type_concat<charNDArray> (result, tmp); |
5502 | 906 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
907 retval = octave_value (result, type); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
908 } |
5533 | 909 else if (result_type == "logical") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
910 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
911 if (any_sparse_p) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
912 retval = do_single_type_concat<SparseBoolMatrix> (dv, tmp); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
913 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
914 retval = do_single_type_concat<boolNDArray> (dv, tmp); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
915 } |
5533 | 916 else if (result_type == "int8") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
917 retval = do_single_type_concat<int8NDArray> (dv, tmp); |
5533 | 918 else if (result_type == "int16") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
919 retval = do_single_type_concat<int16NDArray> (dv, tmp); |
5533 | 920 else if (result_type == "int32") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
921 retval = do_single_type_concat<int32NDArray> (dv, tmp); |
5533 | 922 else if (result_type == "int64") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
923 retval = do_single_type_concat<int64NDArray> (dv, tmp); |
5533 | 924 else if (result_type == "uint8") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
925 retval = do_single_type_concat<uint8NDArray> (dv, tmp); |
5533 | 926 else if (result_type == "uint16") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
927 retval = do_single_type_concat<uint16NDArray> (dv, tmp); |
5533 | 928 else if (result_type == "uint32") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
929 retval = do_single_type_concat<uint32NDArray> (dv, tmp); |
5533 | 930 else if (result_type == "uint64") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
931 retval = do_single_type_concat<uint64NDArray> (dv, tmp); |
4915 | 932 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
933 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
934 // The line below might seem crazy, since we take a copy of |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
935 // the first argument, resize it to be empty and then resize |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
936 // it to be full. This is done since it means that there is |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
937 // no recopying of data, as would happen if we used a single |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
938 // resize. It should be noted that resize operation is also |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
939 // significantly slower than the do_cat_op function, so it |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
940 // makes sense to have an empty matrix and copy all data. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
941 // |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
942 // We might also start with a empty octave_value using |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
943 // |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
944 // ctmp = octave_value_typeinfo::lookup_type |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
945 // (tmp.begin() -> begin() -> type_name()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
946 // |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
947 // and then directly resize. However, for some types there |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
948 // might be some additional setup needed, and so this should |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
949 // be avoided. |
5502 | 950 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
951 octave_value ctmp; |
5502 | 952 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
953 // Find the first non-empty object |
5502 | 954 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
955 if (any_sparse_p) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
956 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
957 // Start with sparse matrix to avoid issues memory issues |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
958 // with things like [ones(1,4),sprandn(1e8,4,1e-4)] |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
959 if (all_real_p) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
960 ctmp = octave_sparse_matrix ().resize (dv); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
961 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
962 ctmp = octave_sparse_complex_matrix ().resize (dv); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
963 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
964 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
965 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
966 for (tm_const::iterator p = tmp.begin (); p != tmp.end (); p++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
967 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
968 octave_quit (); |
5502 | 969 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
970 tm_row_const row = *p; |
5502 | 971 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
972 for (tm_row_const::iterator q = row.begin (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
973 q != row.end (); q++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
974 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
975 octave_quit (); |
5630 | 976 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
977 ctmp = *q; |
5164 | 978 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
979 if (! ctmp.all_zero_dims ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
980 goto found_non_empty; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
981 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
982 } |
5164 | 983 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
984 ctmp = (*(tmp.begin() -> begin())); |
5630 | 985 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
986 found_non_empty: |
5502 | 987 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
988 if (! all_empty_p) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
989 ctmp = ctmp.resize (dim_vector (0,0)).resize (dv); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
990 } |
4915 | 991 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
992 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
993 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
994 // Now, extract the values from the individual elements and |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
995 // insert them in the result matrix. |
5502 | 996 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
997 int dv_len = dv.length (); |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
998 Array<octave_idx_type> ra_idx (dv_len > 1 ? dv_len : 2, 1, 0); |
5502 | 999 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1000 for (tm_const::iterator p = tmp.begin (); p != tmp.end (); p++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1001 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1002 octave_quit (); |
5502 | 1003 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1004 tm_row_const row = *p; |
5502 | 1005 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1006 for (tm_row_const::iterator q = row.begin (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1007 q != row.end (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1008 q++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1009 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1010 octave_quit (); |
1741 | 1011 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1012 octave_value elt = *q; |
5502 | 1013 |
10715
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
1014 if (elt.is_empty ()) |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
1015 continue; |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10535
diff
changeset
|
1016 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1017 ctmp = do_cat_op (ctmp, elt, ra_idx); |
5502 | 1018 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1019 if (error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1020 goto done; |
5502 | 1021 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1022 ra_idx (1) += elt.columns (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1023 } |
5502 | 1024 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1025 ra_idx (0) += row.rows (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1026 ra_idx (1) = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1027 } |
5502 | 1028 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1029 retval = ctmp; |
5502 | 1030 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1031 if (frc_str_conv && ! retval.is_string ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1032 retval = retval.convert_to_str (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1033 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1034 } |
1741 | 1035 } |
1036 | |
1827 | 1037 done: |
1741 | 1038 return retval; |
1039 } | |
1040 | |
5861 | 1041 tree_expression * |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
1042 tree_matrix::dup (symbol_table::scope_id scope, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1043 symbol_table::context_id context) const |
5861 | 1044 { |
1045 tree_matrix *new_matrix = new tree_matrix (0, line (), column ()); | |
1046 | |
8913
35cd375d4bb3
make tree::dup functions const
John W. Eaton <jwe@octave.org>
parents:
8658
diff
changeset
|
1047 for (const_iterator p = begin (); p != end (); p++) |
5861 | 1048 { |
8913
35cd375d4bb3
make tree::dup functions const
John W. Eaton <jwe@octave.org>
parents:
8658
diff
changeset
|
1049 const tree_argument_list *elt = *p; |
5861 | 1050 |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
1051 new_matrix->append (elt ? elt->dup (scope, context) : 0); |
5861 | 1052 } |
1053 | |
1054 new_matrix->copy_base (*this); | |
1055 | |
1056 return new_matrix; | |
1057 } | |
1058 | |
1741 | 1059 void |
2124 | 1060 tree_matrix::accept (tree_walker& tw) |
1741 | 1061 { |
2124 | 1062 tw.visit_matrix (*this); |
1741 | 1063 } |
1064 | |
5794 | 1065 DEFUN (string_fill_char, args, nargout, |
1066 "-*- texinfo -*-\n\ | |
1067 @deftypefn {Built-in Function} {@var{val} =} string_fill_char ()\n\ | |
1068 @deftypefnx {Built-in Function} {@var{old_val} =} string_fill_char (@var{new_val})\n\ | |
1069 Query or set the internal variable used to pad all rows of a character\n\ | |
1070 matrix to the same length. It must be a single character. The default\n\ | |
1071 value is @code{\" \"} (a single space). For example,\n\ | |
3361 | 1072 \n\ |
1073 @example\n\ | |
1074 @group\n\ | |
5794 | 1075 string_fill_char (\"X\");\n\ |
3361 | 1076 [ \"these\"; \"are\"; \"strings\" ]\n\ |
1077 @result{} \"theseXX\"\n\ | |
1078 \"areXXXX\"\n\ | |
1079 \"strings\"\n\ | |
1080 @end group\n\ | |
1081 @end example\n\ | |
5794 | 1082 @end deftypefn") |
1083 { | |
1084 return SET_INTERNAL_VARIABLE (string_fill_char); | |
2172 | 1085 } |