1741
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
1741
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
1741
|
21 |
|
22 */ |
|
23 |
|
24 #ifdef HAVE_CONFIG_H |
|
25 #include <config.h> |
|
26 #endif |
|
27 |
3503
|
28 #include <iostream> |
1741
|
29 |
2172
|
30 #include "defun.h" |
1741
|
31 #include "error.h" |
|
32 #include "oct-obj.h" |
2982
|
33 #include "pt-arg-list.h" |
3770
|
34 #include "pt-bp.h" |
1741
|
35 #include "pt-exp.h" |
|
36 #include "pt-mat.h" |
2124
|
37 #include "pt-walk.h" |
2201
|
38 #include "utils.h" |
2371
|
39 #include "ov.h" |
|
40 #include "variables.h" |
1741
|
41 |
4460
|
42 // If TRUE, print a warning message for empty elements in a matrix list. |
|
43 static bool Vwarn_empty_list_elements; |
2172
|
44 |
2254
|
45 // The character to fill with when creating string arrays. |
3836
|
46 char Vstring_fill_char = ' '; |
2254
|
47 |
5280
|
48 // Warn if concatenating double and single quoted strings. |
5391
|
49 char Vwarn_string_concat = false; |
5280
|
50 |
1741
|
51 // General matrices. This list type is much more work to handle than |
|
52 // constant matrices, but it allows us to construct matrices from |
|
53 // other matrices, variables, and functions. |
|
54 |
1827
|
55 // But first, some internal classes that make our job much easier. |
1741
|
56 |
1827
|
57 class |
|
58 tm_row_const |
1741
|
59 { |
1827
|
60 private: |
|
61 |
|
62 class |
4219
|
63 tm_row_const_rep : public octave_base_list<octave_value> |
1827
|
64 { |
|
65 public: |
|
66 |
|
67 tm_row_const_rep (void) |
5280
|
68 : count (1), dv (), all_str (false), |
|
69 all_sq_str (false), all_dq_str (false), |
|
70 some_str (false), is_cmplx (false), all_mt (true), ok (false) { } |
1827
|
71 |
2971
|
72 tm_row_const_rep (const tree_argument_list& row) |
5280
|
73 : count (1), dv (), all_str (false), all_sq_str (false), |
|
74 some_str (false), is_cmplx (false), all_mt (true), ok (false) |
3110
|
75 { init (row); } |
1827
|
76 |
|
77 ~tm_row_const_rep (void) { } |
|
78 |
|
79 int count; |
|
80 |
4765
|
81 dim_vector dv; |
1741
|
82 |
1827
|
83 bool all_str; |
5280
|
84 bool all_sq_str; |
|
85 bool all_dq_str; |
3110
|
86 bool some_str; |
1827
|
87 bool is_cmplx; |
2602
|
88 bool all_mt; |
1827
|
89 |
|
90 bool ok; |
|
91 |
4501
|
92 bool do_init_element (tree_expression *, const octave_value&, bool&); |
|
93 |
2971
|
94 void init (const tree_argument_list&); |
1827
|
95 |
|
96 private: |
|
97 |
|
98 tm_row_const_rep (const tm_row_const_rep&); |
|
99 |
2971
|
100 tm_row_const_rep& operator = (const tm_row_const_rep&); |
2419
|
101 |
3661
|
102 void eval_error (const char *msg, int l, int c, |
|
103 int x = -1, int y = -1) const; |
2419
|
104 |
|
105 void eval_warning (const char *msg, int l, int c) const; |
1827
|
106 }; |
|
107 |
|
108 public: |
|
109 |
4219
|
110 typedef tm_row_const_rep::iterator iterator; |
|
111 typedef tm_row_const_rep::const_iterator const_iterator; |
|
112 |
2990
|
113 tm_row_const (void) |
|
114 : rep (0) { } |
1827
|
115 |
2971
|
116 tm_row_const (const tree_argument_list& row) |
|
117 : rep (new tm_row_const_rep (row)) { } |
1827
|
118 |
2990
|
119 tm_row_const (const tm_row_const& x) |
|
120 : rep (x.rep) |
|
121 { |
|
122 if (rep) |
|
123 rep->count++; |
|
124 } |
1827
|
125 |
|
126 tm_row_const& operator = (const tm_row_const& x) |
2990
|
127 { |
|
128 if (this != &x && rep != x.rep) |
|
129 { |
|
130 if (rep && --rep->count == 0) |
|
131 delete rep; |
1741
|
132 |
2990
|
133 rep = x.rep; |
1827
|
134 |
2990
|
135 if (rep) |
|
136 rep->count++; |
|
137 } |
1741
|
138 |
2990
|
139 return *this; |
|
140 } |
1827
|
141 |
|
142 ~tm_row_const (void) |
2990
|
143 { |
|
144 if (rep && --rep->count == 0) |
|
145 delete rep; |
|
146 } |
1741
|
147 |
5275
|
148 octave_idx_type rows (void) |
4765
|
149 { return (rep->dv.length () > 0 ? rep->dv(0) : 0); } |
|
150 |
5275
|
151 octave_idx_type cols (void) |
4765
|
152 { return (rep->dv.length () > 1 ? rep->dv(1) : 0); } |
|
153 |
|
154 dim_vector dims (void) { return rep->dv; } |
1827
|
155 |
2868
|
156 bool all_strings_p (void) const { return rep->all_str; } |
5280
|
157 bool all_sq_strings_p (void) const { return rep->all_sq_str; } |
|
158 bool all_dq_strings_p (void) const { return rep->all_dq_str; } |
3110
|
159 bool some_strings_p (void) const { return rep->some_str; } |
2868
|
160 bool complex_p (void) const { return rep->is_cmplx; } |
|
161 bool all_empty_p (void) const { return rep->all_mt; } |
1827
|
162 |
4219
|
163 operator bool () const { return (rep && rep->ok); } |
1827
|
164 |
4219
|
165 iterator begin (void) { return rep->begin (); } |
|
166 const_iterator begin (void) const { return rep->begin (); } |
|
167 |
|
168 iterator end (void) { return rep->end (); } |
|
169 const_iterator end (void) const { return rep->end (); } |
1827
|
170 |
|
171 private: |
|
172 |
|
173 tm_row_const_rep *rep; |
|
174 }; |
|
175 |
4501
|
176 bool |
|
177 tm_row_const::tm_row_const_rep::do_init_element (tree_expression *elt, |
|
178 const octave_value& val, |
|
179 bool& first_elem) |
|
180 { |
5275
|
181 octave_idx_type this_elt_nr = val.rows (); |
|
182 octave_idx_type this_elt_nc = val.columns (); |
4501
|
183 |
4765
|
184 dim_vector this_elt_dv = val.dims (); |
|
185 |
|
186 if (!this_elt_dv.all_zero ()) |
4501
|
187 { |
|
188 all_mt = false; |
|
189 |
|
190 if (first_elem) |
|
191 { |
|
192 first_elem = false; |
|
193 |
4765
|
194 dv.resize (this_elt_dv.length ()); |
|
195 for (int i = 2; i < dv.length (); i++) |
|
196 dv.elem (i) = this_elt_dv.elem (i); |
|
197 |
|
198 dv.elem (0) = this_elt_nr; |
|
199 |
|
200 dv.elem (1) = 0; |
4501
|
201 } |
4765
|
202 else |
4501
|
203 { |
5045
|
204 int len = (this_elt_dv.length () < dv.length () |
|
205 ? this_elt_dv.length () : dv.length ()); |
|
206 |
4765
|
207 if (this_elt_nr != dv (0)) |
|
208 { |
|
209 eval_error ("number of rows must match", |
|
210 elt->line (), elt->column (), this_elt_nr, dv (0)); |
|
211 return false; |
|
212 } |
5045
|
213 for (int i = 2; i < len; i++) |
4765
|
214 { |
|
215 if (this_elt_dv (i) != dv (i)) |
|
216 { |
|
217 eval_error ("dimensions mismatch", elt->line (), elt->column (), this_elt_dv (i), dv (i)); |
|
218 return false; |
|
219 } |
|
220 } |
5045
|
221 |
|
222 if (this_elt_dv.length () > len) |
|
223 for (int i = len; i < this_elt_dv.length (); i++) |
|
224 if (this_elt_dv (i) != 1) |
|
225 { |
|
226 eval_error ("dimensions mismatch", elt->line (), elt->column (), this_elt_dv (i), 1); |
|
227 return false; |
|
228 } |
|
229 |
|
230 if (dv.length () > len) |
|
231 for (int i = len; i < dv.length (); i++) |
|
232 if (dv (i) != 1) |
|
233 { |
|
234 eval_error ("dimensions mismatch", elt->line (), elt->column (), 1, dv (i)); |
|
235 return false; |
|
236 } |
4501
|
237 } |
4765
|
238 dv.elem (1) = dv.elem (1) + this_elt_nc; |
4501
|
239 |
|
240 } |
|
241 else if (Vwarn_empty_list_elements) |
|
242 eval_warning ("empty matrix found in matrix list", |
|
243 elt->line (), elt->column ()); |
|
244 |
4915
|
245 append (val); |
|
246 |
4501
|
247 if (all_str && ! val.is_string ()) |
|
248 all_str = false; |
|
249 |
5280
|
250 if (all_sq_str && ! val.is_sq_string ()) |
|
251 all_sq_str = false; |
|
252 |
|
253 if (all_dq_str && ! val.is_dq_string ()) |
|
254 all_dq_str = false; |
|
255 |
4501
|
256 if (! some_str && val.is_string ()) |
|
257 some_str = true; |
|
258 |
|
259 if (! is_cmplx && val.is_complex_type ()) |
|
260 is_cmplx = true; |
|
261 |
|
262 return true; |
|
263 } |
|
264 |
1827
|
265 void |
2971
|
266 tm_row_const::tm_row_const_rep::init (const tree_argument_list& row) |
1827
|
267 { |
|
268 all_str = true; |
5280
|
269 all_sq_str = true; |
|
270 all_dq_str = true; |
1827
|
271 |
|
272 bool first_elem = true; |
|
273 |
4219
|
274 for (tree_argument_list::const_iterator p = row.begin (); |
|
275 p != row.end (); |
|
276 p++) |
1827
|
277 { |
4219
|
278 tree_expression *elt = *p; |
1827
|
279 |
2971
|
280 octave_value tmp = elt->rvalue (); |
1827
|
281 |
|
282 if (error_state || tmp.is_undefined ()) |
|
283 break; |
|
284 else |
|
285 { |
4501
|
286 if (tmp.is_cs_list ()) |
1827
|
287 { |
4587
|
288 octave_value_list tlst = tmp.list_value (); |
2602
|
289 |
5275
|
290 for (octave_idx_type i = 0; i < tlst.length (); i++) |
1827
|
291 { |
4587
|
292 if (! do_init_element (elt, tlst(i), first_elem)) |
4501
|
293 goto done; |
1827
|
294 } |
|
295 } |
4501
|
296 else |
|
297 { |
|
298 if (! do_init_element (elt, tmp, first_elem)) |
|
299 goto done; |
|
300 } |
1827
|
301 } |
|
302 } |
|
303 |
4501
|
304 done: |
|
305 |
1827
|
306 ok = ! error_state; |
1741
|
307 } |
|
308 |
2419
|
309 void |
|
310 tm_row_const::tm_row_const_rep::eval_error (const char *msg, int l, |
3661
|
311 int c, int x, int y) const |
2419
|
312 { |
|
313 if (l == -1 && c == -1) |
3661
|
314 { |
|
315 if (x == -1 || y == -1) |
|
316 ::error ("%s", msg); |
|
317 else |
|
318 ::error ("%s (%d != %d)", msg, x, y); |
|
319 } |
2419
|
320 else |
3661
|
321 { |
|
322 if (x == -1 || y == -1) |
|
323 ::error ("%s near line %d, column %d", msg, l, c); |
|
324 else |
|
325 ::error ("%s (%d != %d) near line %d, column %d", msg, x, y, l, c); |
|
326 } |
2419
|
327 } |
|
328 |
|
329 void |
|
330 tm_row_const::tm_row_const_rep::eval_warning (const char *msg, int l, |
|
331 int c) const |
|
332 { |
|
333 if (l == -1 && c == -1) |
|
334 ::warning ("%s", msg); |
|
335 else |
|
336 ::warning ("%s near line %d, column %d", msg, l, c); |
|
337 } |
|
338 |
1827
|
339 class |
4219
|
340 tm_const : public octave_base_list<tm_row_const> |
1827
|
341 { |
|
342 public: |
|
343 |
|
344 tm_const (const tree_matrix& tm) |
5280
|
345 : dv (), all_str (false), all_sq_str (false), all_dq_str (false), |
|
346 some_str (false), is_cmplx (false), all_mt (true), ok (false) |
1827
|
347 { init (tm); } |
|
348 |
|
349 ~tm_const (void) { } |
|
350 |
5275
|
351 octave_idx_type rows (void) const { return (dv.length () > 0 ? dv.elem (0) : 0); } |
|
352 octave_idx_type cols (void) const { return (dv.length () > 1 ? dv.elem (1) : 0); } |
4765
|
353 |
|
354 dim_vector dims (void) const { return dv; } |
1827
|
355 |
2868
|
356 bool all_strings_p (void) const { return all_str; } |
5280
|
357 bool all_sq_strings_p (void) const { return all_sq_str; } |
|
358 bool all_dq_strings_p (void) const { return all_dq_str; } |
3110
|
359 bool some_strings_p (void) const { return some_str; } |
2868
|
360 bool complex_p (void) const { return is_cmplx; } |
|
361 bool all_empty_p (void) const { return all_mt; } |
1827
|
362 |
3145
|
363 operator bool () const { return ok; } |
1827
|
364 |
|
365 private: |
|
366 |
4765
|
367 dim_vector dv; |
1827
|
368 |
|
369 bool all_str; |
5280
|
370 bool all_sq_str; |
|
371 bool all_dq_str; |
3110
|
372 bool some_str; |
1827
|
373 bool is_cmplx; |
2602
|
374 bool all_mt; |
1827
|
375 |
|
376 bool ok; |
|
377 |
|
378 tm_const (void); |
|
379 |
|
380 tm_const (const tm_const&); |
|
381 |
|
382 tm_const& operator = (const tm_const&); |
|
383 |
|
384 void init (const tree_matrix& tm); |
|
385 }; |
|
386 |
|
387 void |
|
388 tm_const::init (const tree_matrix& tm) |
1741
|
389 { |
1827
|
390 all_str = true; |
5280
|
391 all_sq_str = true; |
|
392 all_dq_str = true; |
1827
|
393 |
|
394 bool first_elem = true; |
|
395 |
|
396 // Just eval and figure out if what we have is complex or all |
|
397 // strings. We can't check columns until we know that this is a |
|
398 // numeric matrix -- collections of strings can have elements of |
|
399 // different lengths. |
|
400 |
4219
|
401 for (tree_matrix::const_iterator p = tm.begin (); p != tm.end (); p++) |
1827
|
402 { |
4219
|
403 tree_argument_list *elt = *p; |
1827
|
404 |
|
405 tm_row_const tmp (*elt); |
|
406 |
|
407 if (tmp) |
|
408 { |
2868
|
409 if (all_str && ! tmp.all_strings_p ()) |
1827
|
410 all_str = false; |
|
411 |
5280
|
412 if (all_sq_str && ! tmp.all_sq_strings_p ()) |
|
413 all_sq_str = false; |
|
414 |
|
415 if (all_dq_str && ! tmp.all_dq_strings_p ()) |
|
416 all_dq_str = false; |
|
417 |
3110
|
418 if (! some_str && tmp.some_strings_p ()) |
|
419 some_str = true; |
|
420 |
2868
|
421 if (! is_cmplx && tmp.complex_p ()) |
1827
|
422 is_cmplx = true; |
|
423 |
2868
|
424 if (all_mt && ! tmp.all_empty_p ()) |
2602
|
425 all_mt = false; |
|
426 |
1827
|
427 append (tmp); |
|
428 } |
|
429 else |
|
430 break; |
|
431 } |
|
432 |
|
433 if (! error_state) |
|
434 { |
4219
|
435 for (iterator p = begin (); p != end (); p++) |
1827
|
436 { |
4219
|
437 tm_row_const elt = *p; |
1827
|
438 |
5275
|
439 octave_idx_type this_elt_nr = elt.rows (); |
|
440 octave_idx_type this_elt_nc = elt.cols (); |
1827
|
441 |
4765
|
442 dim_vector this_elt_dv = elt.dims (); |
|
443 |
|
444 if (!this_elt_dv.all_zero ()) |
1827
|
445 { |
2602
|
446 all_mt = false; |
|
447 |
1827
|
448 if (first_elem) |
|
449 { |
|
450 first_elem = false; |
|
451 |
4765
|
452 dv.resize (this_elt_dv.length ()); |
|
453 for (int i = 2; i < dv.length (); i++) |
|
454 dv.elem (i) = this_elt_dv.elem (i); |
|
455 |
|
456 dv.elem (0) = 0; |
|
457 |
|
458 dv.elem (1) = this_elt_nc; |
1827
|
459 } |
|
460 else if (all_str) |
|
461 { |
4765
|
462 if (this_elt_nc > cols ()) |
|
463 dv.elem (1) = this_elt_nc; |
1827
|
464 } |
4765
|
465 else |
1827
|
466 { |
4765
|
467 bool get_out = false; |
5045
|
468 int len = (this_elt_dv.length () < dv.length () |
|
469 ? this_elt_dv.length () : dv.length ()); |
4765
|
470 |
5045
|
471 for (int i = 1; i < len; i++) |
4765
|
472 { |
|
473 if (i == 1 && this_elt_nc != dv (1)) |
|
474 { |
|
475 ::error ("number of columns must match (%d != %d)", |
|
476 this_elt_nc, dv (1)); |
|
477 get_out = true; |
|
478 break; |
|
479 } |
|
480 else if (this_elt_dv (i) != dv (i)) |
|
481 { |
|
482 ::error ("dimensions mismatch (dim = %i, %d != %d)", i+1, this_elt_dv (i), dv (i)); |
|
483 get_out = true; |
|
484 break; |
|
485 } |
|
486 } |
|
487 |
5045
|
488 if (this_elt_dv.length () > len) |
|
489 for (int i = len; i < this_elt_dv.length (); i++) |
|
490 if (this_elt_dv (i) != 1) |
|
491 { |
|
492 ::error ("dimensions mismatch (dim = %i, %d != %d)", i+1, this_elt_dv (i), 1); |
|
493 get_out = true; |
|
494 break; |
|
495 } |
|
496 |
|
497 if (dv.length () > len) |
|
498 for (int i = len; i < dv.length (); i++) |
|
499 if (dv (i) != 1) |
|
500 { |
|
501 ::error ("dimensions mismatch (dim = %i, %d != %d)", i+1, 1, dv(i)); |
|
502 get_out = true; |
|
503 break; |
|
504 } |
|
505 |
4765
|
506 if (get_out) |
|
507 break; |
1827
|
508 } |
4765
|
509 dv.elem (0) = dv.elem (0) + this_elt_nr; |
1827
|
510 } |
4460
|
511 else if (Vwarn_empty_list_elements) |
|
512 warning ("empty matrix found in matrix list"); |
1827
|
513 } |
|
514 } |
|
515 |
|
516 ok = ! error_state; |
1741
|
517 } |
|
518 |
2990
|
519 tree_matrix::~tree_matrix (void) |
|
520 { |
4219
|
521 while (! empty ()) |
2990
|
522 { |
4219
|
523 iterator p = begin (); |
|
524 delete *p; |
|
525 erase (p); |
2990
|
526 } |
|
527 } |
|
528 |
1827
|
529 bool |
4267
|
530 tree_matrix::has_magic_end (void) const |
|
531 { |
|
532 for (const_iterator p = begin (); p != end (); p++) |
|
533 { |
|
534 tree_argument_list *elt = *p; |
|
535 |
|
536 if (elt && elt->has_magic_end ()) |
|
537 return true; |
|
538 } |
|
539 |
|
540 return false; |
|
541 } |
|
542 |
|
543 bool |
2529
|
544 tree_matrix::all_elements_are_constant (void) const |
1827
|
545 { |
4219
|
546 for (const_iterator p = begin (); p != end (); p++) |
1827
|
547 { |
4219
|
548 tree_argument_list *elt = *p; |
1827
|
549 |
2529
|
550 if (! elt->all_elements_are_constant ()) |
1827
|
551 return false; |
|
552 } |
|
553 |
|
554 return true; |
|
555 } |
|
556 |
2971
|
557 octave_value_list |
|
558 tree_matrix::rvalue (int nargout) |
|
559 { |
|
560 octave_value_list retval; |
|
561 |
3770
|
562 MAYBE_DO_BREAKPOINT; |
|
563 |
2971
|
564 if (nargout > 1) |
|
565 error ("invalid number of output arguments for matrix list"); |
|
566 else |
|
567 retval = rvalue (); |
|
568 |
|
569 return retval; |
|
570 } |
|
571 |
5280
|
572 static void |
|
573 maybe_warn_string_concat (bool all_dq_strings_p, bool all_sq_strings_p) |
|
574 { |
|
575 if (Vwarn_string_concat && ! (all_dq_strings_p || all_sq_strings_p)) |
|
576 ::warning ("concatenation of different character string types may have unintended consequences"); |
|
577 } |
|
578 |
2086
|
579 octave_value |
2971
|
580 tree_matrix::rvalue (void) |
1741
|
581 { |
2086
|
582 octave_value retval; |
1741
|
583 |
4915
|
584 bool all_strings_p = false; |
5280
|
585 bool all_sq_strings_p = false; |
|
586 bool all_dq_strings_p = false; |
4915
|
587 bool all_empty_p = false; |
|
588 bool frc_str_conv = false; |
1741
|
589 |
4915
|
590 tm_const tmp (*this); |
3110
|
591 |
1827
|
592 if (tmp) |
|
593 { |
4765
|
594 dim_vector dv = tmp.dims (); |
4915
|
595 all_strings_p = tmp.all_strings_p (); |
5280
|
596 all_sq_strings_p = tmp.all_sq_strings_p (); |
|
597 all_dq_strings_p = tmp.all_dq_strings_p (); |
4915
|
598 all_empty_p = tmp.all_empty_p (); |
|
599 frc_str_conv = tmp.some_strings_p (); |
1741
|
600 |
4915
|
601 // XXX FIXME XX |
|
602 // The previous version of this code obtained the return type and |
|
603 // initialized an array of the correct type. However the return type |
|
604 // is now built-up from the return types of do_cat_op. Should we special |
|
605 // case the situation where there are only NDArray and ComplexNDArray |
|
606 // elements, or things like boolMatrix that widen to them, and do the |
|
607 // correct initialization? How to do this? Will it be faster? Check against |
|
608 // version 2.1.57 |
|
609 |
|
610 |
|
611 // The line below might seem crazy, since we take a copy |
|
612 // of the first argument, resize it to be empty and then resize |
|
613 // it to be full. This is done since it means that there is no |
|
614 // recopying of data, as would happen if we used a single resize. |
|
615 // It should be noted that resize operation is also significantly |
|
616 // slower than the do_cat_op function, so it makes sense to have an |
|
617 // empty matrix and copy all data. |
|
618 // |
|
619 // We might also start with a empty octave_value using |
|
620 // ctmp = octave_value_typeinfo::lookup_type |
|
621 // (tmp.begin() -> begin() -> type_name()); |
|
622 // and then directly resize. However, for some types there might be |
|
623 // some additional setup needed, and so this should be avoided. |
|
624 |
|
625 octave_value ctmp; |
|
626 if (all_strings_p) |
5280
|
627 { |
|
628 char type = all_sq_strings_p ? '\'' : '"'; |
|
629 |
|
630 maybe_warn_string_concat (all_dq_strings_p, all_sq_strings_p); |
|
631 |
|
632 if (all_empty_p) |
|
633 ctmp = octave_value (charNDArray (), true, type); |
|
634 else |
|
635 ctmp = octave_value (charNDArray (dv, Vstring_fill_char), |
|
636 true, type); |
|
637 } |
4915
|
638 else |
|
639 { |
5164
|
640 // Find the first non-empty object |
|
641 for (tm_const::iterator p = tmp.begin (); p != tmp.end (); p++) |
|
642 { |
|
643 tm_row_const row = *p; |
|
644 for (tm_row_const::iterator q = row.begin (); |
|
645 q != row.end (); q++) |
|
646 { |
|
647 ctmp = *q; |
|
648 if (! ctmp.all_zero_dims ()) |
|
649 goto found_non_empty; |
|
650 } |
|
651 } |
|
652 |
|
653 ctmp = (*(tmp.begin() -> begin())); |
|
654 |
|
655 found_non_empty: |
|
656 if (! all_empty_p) |
|
657 ctmp = ctmp.resize (dim_vector (0,0)).resize (dv); |
4915
|
658 } |
|
659 |
|
660 if (error_state) |
|
661 goto done; |
1741
|
662 |
1827
|
663 // Now, extract the values from the individual elements and |
|
664 // insert them in the result matrix. |
5144
|
665 int dv_len = dv.length (); |
|
666 Array<int> ra_idx (dv_len > 1 ? dv_len : 2, 0); |
4219
|
667 for (tm_const::iterator p = tmp.begin (); p != tmp.end (); p++) |
1827
|
668 { |
4219
|
669 tm_row_const row = *p; |
|
670 for (tm_row_const::iterator q = row.begin (); q != row.end (); q++) |
1827
|
671 { |
4219
|
672 octave_value elt = *q; |
1741
|
673 |
4915
|
674 ctmp = do_cat_op (ctmp, elt, ra_idx); |
|
675 if (error_state) |
|
676 goto done; |
|
677 ra_idx (1) += elt.columns (); |
1741
|
678 } |
4915
|
679 ra_idx (0) += row.rows (); |
|
680 ra_idx (1) = 0; |
1741
|
681 } |
4915
|
682 retval = ctmp; |
|
683 if (frc_str_conv && ! retval.is_string ()) |
|
684 retval = retval.convert_to_str (); |
1741
|
685 } |
|
686 |
1827
|
687 done: |
1741
|
688 return retval; |
|
689 } |
|
690 |
|
691 void |
2124
|
692 tree_matrix::accept (tree_walker& tw) |
1741
|
693 { |
2124
|
694 tw.visit_matrix (*this); |
1741
|
695 } |
|
696 |
2172
|
697 static int |
4460
|
698 warn_empty_list_elements (void) |
2172
|
699 { |
4460
|
700 Vwarn_empty_list_elements = check_preference ("warn_empty_list_elements"); |
2172
|
701 |
|
702 return 0; |
|
703 } |
|
704 |
2254
|
705 static int |
5280
|
706 warn_string_concat (void) |
|
707 { |
|
708 Vwarn_string_concat = check_preference ("warn_string_concat"); |
|
709 |
|
710 return 0; |
|
711 } |
|
712 |
|
713 static int |
2254
|
714 string_fill_char (void) |
|
715 { |
|
716 int status = 0; |
|
717 |
3523
|
718 std::string s = builtin_string_variable ("string_fill_char"); |
2254
|
719 |
|
720 switch (s.length ()) |
|
721 { |
|
722 case 1: |
|
723 Vstring_fill_char = s[0]; |
|
724 break; |
|
725 |
|
726 case 0: |
|
727 Vstring_fill_char = '\0'; |
|
728 break; |
|
729 |
|
730 default: |
|
731 warning ("string_fill_char must be a single character"); |
|
732 status = -1; |
|
733 break; |
|
734 } |
|
735 |
|
736 return status; |
|
737 } |
|
738 |
2172
|
739 void |
|
740 symbols_of_pt_mat (void) |
|
741 { |
3258
|
742 DEFVAR (string_fill_char, " ", string_fill_char, |
3361
|
743 "-*- texinfo -*-\n\ |
|
744 @defvr {Built-in Variable} string_fill_char\n\ |
|
745 The value of this variable is used to pad all strings in a string matrix\n\ |
|
746 to the same length. It should be a single character. The default value\n\ |
|
747 is @code{\" \"} (a single space). For example,\n\ |
|
748 \n\ |
|
749 @example\n\ |
|
750 @group\n\ |
|
751 string_fill_char = \"X\";\n\ |
|
752 [ \"these\"; \"are\"; \"strings\" ]\n\ |
|
753 @result{} \"theseXX\"\n\ |
|
754 \"areXXXX\"\n\ |
|
755 \"strings\"\n\ |
|
756 @end group\n\ |
|
757 @end example\n\ |
3363
|
758 @end defvr"); |
4460
|
759 |
|
760 DEFVAR (warn_empty_list_elements, false, warn_empty_list_elements, |
|
761 "-*- texinfo -*-\n\ |
|
762 @defvr {Built-in Variable} warn_empty_list_elements\n\ |
|
763 If the value of @code{warn_empty_list_elements} is nonzero, print a\n\ |
|
764 warning when an empty matrix is found in a matrix list. For example,\n\ |
|
765 \n\ |
|
766 @example\n\ |
|
767 a = [1, [], 3, [], 5]\n\ |
|
768 @end example\n\ |
|
769 \n\ |
|
770 @noindent\n\ |
|
771 The default value is 0.\n\ |
|
772 @end defvr"); |
|
773 |
5391
|
774 DEFVAR (warn_string_concat, false, warn_string_concat, |
5280
|
775 "-*- texinfo -*-\n\ |
|
776 @defvr {Built-in Variable} warn_string_concat\n\ |
|
777 If the value of @code{warn_string_concat} is nonzero, print a\n\ |
|
778 warning when concatenating a mixture of double and single quoted strings.\n\ |
|
779 The default value is 1.\n\ |
|
780 @end defvr"); |
|
781 |
2172
|
782 } |
|
783 |
1741
|
784 /* |
|
785 ;;; Local Variables: *** |
|
786 ;;; mode: C++ *** |
|
787 ;;; End: *** |
|
788 */ |