Mercurial > hg > octave-lyh
comparison src/pt-mat.cc @ 10315:57a59eae83cc
untabify src C++ source files
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 11 Feb 2010 12:41:46 -0500 |
parents | cd96d29c5efa |
children | 12884915a8e4 |
comparison
equal
deleted
inserted
replaced
10314:07ebe522dac2 | 10315:57a59eae83cc |
---|---|
65 { | 65 { |
66 public: | 66 public: |
67 | 67 |
68 tm_row_const_rep (void) | 68 tm_row_const_rep (void) |
69 : count (1), dv (0, 0), all_str (false), | 69 : count (1), dv (0, 0), all_str (false), |
70 all_sq_str (false), all_dq_str (false), | 70 all_sq_str (false), all_dq_str (false), |
71 some_str (false), all_real (false), all_cmplx (false), | 71 some_str (false), all_real (false), all_cmplx (false), |
72 all_mt (true), any_sparse (false), any_class (false), | 72 all_mt (true), any_sparse (false), any_class (false), |
73 class_nm (), ok (false) | 73 class_nm (), ok (false) |
74 { } | 74 { } |
75 | 75 |
76 tm_row_const_rep (const tree_argument_list& row) | 76 tm_row_const_rep (const tree_argument_list& row) |
77 : count (1), dv (0, 0), all_str (false), all_sq_str (false), | 77 : count (1), dv (0, 0), all_str (false), all_sq_str (false), |
78 some_str (false), all_real (false), all_cmplx (false), | 78 some_str (false), all_real (false), all_cmplx (false), |
79 all_mt (true), any_sparse (false), any_class (false), | 79 all_mt (true), any_sparse (false), any_class (false), |
80 class_nm (), ok (false) | 80 class_nm (), ok (false) |
81 { init (row); } | 81 { init (row); } |
82 | 82 |
83 ~tm_row_const_rep (void) { } | 83 ~tm_row_const_rep (void) { } |
84 | 84 |
85 int count; | 85 int count; |
109 tm_row_const_rep (const tm_row_const_rep&); | 109 tm_row_const_rep (const tm_row_const_rep&); |
110 | 110 |
111 tm_row_const_rep& operator = (const tm_row_const_rep&); | 111 tm_row_const_rep& operator = (const tm_row_const_rep&); |
112 | 112 |
113 void eval_error (const char *msg, int l, int c, | 113 void eval_error (const char *msg, int l, int c, |
114 int x = -1, int y = -1) const; | 114 int x = -1, int y = -1) const; |
115 | 115 |
116 void eval_warning (const char *msg, int l, int c) const; | 116 void eval_warning (const char *msg, int l, int c) const; |
117 }; | 117 }; |
118 | 118 |
119 public: | 119 public: |
136 | 136 |
137 tm_row_const& operator = (const tm_row_const& x) | 137 tm_row_const& operator = (const tm_row_const& x) |
138 { | 138 { |
139 if (this != &x && rep != x.rep) | 139 if (this != &x && rep != x.rep) |
140 { | 140 { |
141 if (rep && --rep->count == 0) | 141 if (rep && --rep->count == 0) |
142 delete rep; | 142 delete rep; |
143 | 143 |
144 rep = x.rep; | 144 rep = x.rep; |
145 | 145 |
146 if (rep) | 146 if (rep) |
147 rep->count++; | 147 rep->count++; |
148 } | 148 } |
149 | 149 |
150 return *this; | 150 return *this; |
151 } | 151 } |
152 | 152 |
202 else if (c2.empty ()) | 202 else if (c2.empty ()) |
203 retval = c1; | 203 retval = c1; |
204 else | 204 else |
205 { | 205 { |
206 bool c1_is_int = (c1 == "int8" || c1 == "uint8" | 206 bool c1_is_int = (c1 == "int8" || c1 == "uint8" |
207 || c1 == "int16" || c1 == "uint16" | 207 || c1 == "int16" || c1 == "uint16" |
208 || c1 == "int32" || c1 == "uint32" | 208 || c1 == "int32" || c1 == "uint32" |
209 || c1 == "int64" || c1 == "uint64"); | 209 || c1 == "int64" || c1 == "uint64"); |
210 bool c2_is_int = (c2 == "int8" || c2 == "uint8" | 210 bool c2_is_int = (c2 == "int8" || c2 == "uint8" |
211 || c2 == "int16" || c2 == "uint16" | 211 || c2 == "int16" || c2 == "uint16" |
212 || c2 == "int32" || c2 == "uint32" | 212 || c2 == "int32" || c2 == "uint32" |
213 || c2 == "int64" || c2 == "uint64"); | 213 || c2 == "int64" || c2 == "uint64"); |
214 | 214 |
215 bool c1_is_char = (c1 == "char"); | 215 bool c1_is_char = (c1 == "char"); |
216 bool c2_is_char = (c2 == "char"); | 216 bool c2_is_char = (c2 == "char"); |
217 | 217 |
218 bool c1_is_double = (c1 == "double"); | 218 bool c1_is_double = (c1 == "double"); |
223 | 223 |
224 bool c1_is_logical = (c1 == "logical"); | 224 bool c1_is_logical = (c1 == "logical"); |
225 bool c2_is_logical = (c2 == "logical"); | 225 bool c2_is_logical = (c2 == "logical"); |
226 | 226 |
227 bool c1_is_built_in_type | 227 bool c1_is_built_in_type |
228 = (c1_is_int || c1_is_char || c1_is_double || c1_is_single | 228 = (c1_is_int || c1_is_char || c1_is_double || c1_is_single |
229 || c1_is_logical); | 229 || c1_is_logical); |
230 | 230 |
231 bool c2_is_built_in_type | 231 bool c2_is_built_in_type |
232 = (c2_is_int || c2_is_char || c2_is_double || c2_is_single | 232 = (c2_is_int || c2_is_char || c2_is_double || c2_is_single |
233 || c2_is_logical); | 233 || c2_is_logical); |
234 | 234 |
235 // Order is important here... | 235 // Order is important here... |
236 | 236 |
237 if (c1_is_char && c2_is_built_in_type) | 237 if (c1_is_char && c2_is_built_in_type) |
238 retval = c1; | 238 retval = c1; |
239 else if (c2_is_char && c1_is_built_in_type) | 239 else if (c2_is_char && c1_is_built_in_type) |
240 retval = c2; | 240 retval = c2; |
241 else if (c1_is_int && c2_is_built_in_type) | 241 else if (c1_is_int && c2_is_built_in_type) |
242 retval = c1; | 242 retval = c1; |
243 else if (c2_is_int && c1_is_built_in_type) | 243 else if (c2_is_int && c1_is_built_in_type) |
244 retval = c2; | 244 retval = c2; |
245 else if (c1_is_single && c2_is_built_in_type) | 245 else if (c1_is_single && c2_is_built_in_type) |
246 retval = c1; | 246 retval = c1; |
247 else if (c2_is_single && c1_is_built_in_type) | 247 else if (c2_is_single && c1_is_built_in_type) |
248 retval = c2; | 248 retval = c2; |
249 else if (c1_is_double && c2_is_built_in_type) | 249 else if (c1_is_double && c2_is_built_in_type) |
250 retval = c1; | 250 retval = c1; |
251 else if (c2_is_double && c1_is_built_in_type) | 251 else if (c2_is_double && c1_is_built_in_type) |
252 retval = c2; | 252 retval = c2; |
253 else if (c1_is_logical && c2_is_logical) | 253 else if (c1_is_logical && c2_is_logical) |
254 retval = c1; | 254 retval = c1; |
255 } | 255 } |
256 | 256 |
257 return retval; | 257 return retval; |
258 } | 258 } |
259 | 259 |
260 bool | 260 bool |
261 tm_row_const::tm_row_const_rep::do_init_element (tree_expression *elt, | 261 tm_row_const::tm_row_const_rep::do_init_element (tree_expression *elt, |
262 const octave_value& val, | 262 const octave_value& val, |
263 bool& first_elem) | 263 bool& first_elem) |
264 { | 264 { |
265 octave_idx_type this_elt_nr = val.rows (); | 265 octave_idx_type this_elt_nr = val.rows (); |
266 octave_idx_type this_elt_nc = val.columns (); | 266 octave_idx_type this_elt_nc = val.columns (); |
267 | 267 |
268 std::string this_elt_class_nm = val.class_name (); | 268 std::string this_elt_class_nm = val.class_name (); |
275 if (! this_elt_dv.all_zero ()) | 275 if (! this_elt_dv.all_zero ()) |
276 { | 276 { |
277 all_mt = false; | 277 all_mt = false; |
278 | 278 |
279 if (first_elem) | 279 if (first_elem) |
280 { | 280 { |
281 first_elem = false; | 281 first_elem = false; |
282 | 282 |
283 dv.resize (this_elt_dv.length ()); | 283 dv.resize (this_elt_dv.length ()); |
284 for (int i = 2; i < dv.length (); i++) | 284 for (int i = 2; i < dv.length (); i++) |
285 dv.elem (i) = this_elt_dv.elem (i); | 285 dv.elem (i) = this_elt_dv.elem (i); |
286 | 286 |
287 dv.elem (0) = this_elt_nr; | 287 dv.elem (0) = this_elt_nr; |
288 | 288 |
289 dv.elem (1) = 0; | 289 dv.elem (1) = 0; |
290 } | 290 } |
291 else | 291 else |
292 { | 292 { |
293 int len = (this_elt_dv.length () < dv.length () | 293 int len = (this_elt_dv.length () < dv.length () |
294 ? this_elt_dv.length () : dv.length ()); | 294 ? this_elt_dv.length () : dv.length ()); |
295 | 295 |
296 if (this_elt_nr != dv (0)) | 296 if (this_elt_nr != dv (0)) |
297 { | 297 { |
298 eval_error ("number of rows must match", | 298 eval_error ("number of rows must match", |
299 elt->line (), elt->column (), this_elt_nr, dv (0)); | 299 elt->line (), elt->column (), this_elt_nr, dv (0)); |
300 return false; | 300 return false; |
301 } | 301 } |
302 for (int i = 2; i < len; i++) | 302 for (int i = 2; i < len; i++) |
303 { | 303 { |
304 if (this_elt_dv (i) != dv (i)) | 304 if (this_elt_dv (i) != dv (i)) |
305 { | 305 { |
306 eval_error ("dimensions mismatch", elt->line (), elt->column (), this_elt_dv (i), dv (i)); | 306 eval_error ("dimensions mismatch", elt->line (), elt->column (), this_elt_dv (i), dv (i)); |
307 return false; | 307 return false; |
308 } | 308 } |
309 } | 309 } |
310 | 310 |
311 if (this_elt_dv.length () > len) | 311 if (this_elt_dv.length () > len) |
312 for (int i = len; i < this_elt_dv.length (); i++) | 312 for (int i = len; i < this_elt_dv.length (); i++) |
313 if (this_elt_dv (i) != 1) | 313 if (this_elt_dv (i) != 1) |
314 { | 314 { |
315 eval_error ("dimensions mismatch", elt->line (), elt->column (), this_elt_dv (i), 1); | 315 eval_error ("dimensions mismatch", elt->line (), elt->column (), this_elt_dv (i), 1); |
316 return false; | 316 return false; |
317 } | 317 } |
318 | 318 |
319 if (dv.length () > len) | 319 if (dv.length () > len) |
320 for (int i = len; i < dv.length (); i++) | 320 for (int i = len; i < dv.length (); i++) |
321 if (dv (i) != 1) | 321 if (dv (i) != 1) |
322 { | 322 { |
323 eval_error ("dimensions mismatch", elt->line (), elt->column (), 1, dv (i)); | 323 eval_error ("dimensions mismatch", elt->line (), elt->column (), 1, dv (i)); |
324 return false; | 324 return false; |
325 } | 325 } |
326 } | 326 } |
327 dv.elem (1) = dv.elem (1) + this_elt_nc; | 327 dv.elem (1) = dv.elem (1) + this_elt_nc; |
328 | 328 |
329 } | 329 } |
330 else | 330 else |
331 eval_warning ("empty matrix found in matrix list", | 331 eval_warning ("empty matrix found in matrix list", |
332 elt->line (), elt->column ()); | 332 elt->line (), elt->column ()); |
333 | 333 |
334 append (val); | 334 append (val); |
335 | 335 |
336 if (all_str && ! val.is_string ()) | 336 if (all_str && ! val.is_string ()) |
337 all_str = false; | 337 all_str = false; |
382 tree_expression *elt = *p; | 382 tree_expression *elt = *p; |
383 | 383 |
384 octave_value tmp = elt->rvalue1 (); | 384 octave_value tmp = elt->rvalue1 (); |
385 | 385 |
386 if (error_state || tmp.is_undefined ()) | 386 if (error_state || tmp.is_undefined ()) |
387 break; | 387 break; |
388 else | 388 else |
389 { | 389 { |
390 if (tmp.is_cs_list ()) | 390 if (tmp.is_cs_list ()) |
391 { | 391 { |
392 octave_value_list tlst = tmp.list_value (); | 392 octave_value_list tlst = tmp.list_value (); |
393 | 393 |
394 for (octave_idx_type i = 0; i < tlst.length (); i++) | 394 for (octave_idx_type i = 0; i < tlst.length (); i++) |
395 { | 395 { |
396 octave_quit (); | 396 octave_quit (); |
397 | 397 |
398 if (! do_init_element (elt, tlst(i), first_elem)) | 398 if (! do_init_element (elt, tlst(i), first_elem)) |
399 goto done; | 399 goto done; |
400 } | 400 } |
401 } | 401 } |
402 else | 402 else |
403 { | 403 { |
404 if (! do_init_element (elt, tmp, first_elem)) | 404 if (! do_init_element (elt, tmp, first_elem)) |
405 goto done; | 405 goto done; |
406 } | 406 } |
407 } | 407 } |
408 } | 408 } |
409 | 409 |
410 done: | 410 done: |
411 | 411 |
412 ok = ! error_state; | 412 ok = ! error_state; |
413 } | 413 } |
414 | 414 |
415 void | 415 void |
416 tm_row_const::tm_row_const_rep::eval_error (const char *msg, int l, | 416 tm_row_const::tm_row_const_rep::eval_error (const char *msg, int l, |
417 int c, int x, int y) const | 417 int c, int x, int y) const |
418 { | 418 { |
419 if (l == -1 && c == -1) | 419 if (l == -1 && c == -1) |
420 { | 420 { |
421 if (x == -1 || y == -1) | 421 if (x == -1 || y == -1) |
422 ::error ("%s", msg); | 422 ::error ("%s", msg); |
423 else | 423 else |
424 ::error ("%s (%d != %d)", msg, x, y); | 424 ::error ("%s (%d != %d)", msg, x, y); |
425 } | 425 } |
426 else | 426 else |
427 { | 427 { |
428 if (x == -1 || y == -1) | 428 if (x == -1 || y == -1) |
429 ::error ("%s near line %d, column %d", msg, l, c); | 429 ::error ("%s near line %d, column %d", msg, l, c); |
430 else | 430 else |
431 ::error ("%s (%d != %d) near line %d, column %d", msg, x, y, l, c); | 431 ::error ("%s (%d != %d) near line %d, column %d", msg, x, y, l, c); |
432 } | 432 } |
433 } | 433 } |
434 | 434 |
435 void | 435 void |
436 tm_row_const::tm_row_const_rep::eval_warning (const char *msg, int l, | 436 tm_row_const::tm_row_const_rep::eval_warning (const char *msg, int l, |
437 int c) const | 437 int c) const |
438 { | 438 { |
439 if (l == -1 && c == -1) | 439 if (l == -1 && c == -1) |
440 warning_with_id ("Octave:empty-list-elements", "%s", msg); | 440 warning_with_id ("Octave:empty-list-elements", "%s", msg); |
441 else | 441 else |
442 warning_with_id ("Octave:empty-list-elements", | 442 warning_with_id ("Octave:empty-list-elements", |
443 "%s near line %d, column %d", msg, l, c); | 443 "%s near line %d, column %d", msg, l, c); |
444 } | 444 } |
445 | 445 |
446 class | 446 class |
447 tm_const : public octave_base_list<tm_row_const> | 447 tm_const : public octave_base_list<tm_row_const> |
448 { | 448 { |
528 tree_argument_list *elt = *p; | 528 tree_argument_list *elt = *p; |
529 | 529 |
530 tm_row_const tmp (*elt); | 530 tm_row_const tmp (*elt); |
531 | 531 |
532 if (tmp && ! tmp.empty ()) | 532 if (tmp && ! tmp.empty ()) |
533 { | 533 { |
534 if (all_str && ! tmp.all_strings_p ()) | 534 if (all_str && ! tmp.all_strings_p ()) |
535 all_str = false; | 535 all_str = false; |
536 | 536 |
537 if (all_sq_str && ! tmp.all_sq_strings_p ()) | 537 if (all_sq_str && ! tmp.all_sq_strings_p ()) |
538 all_sq_str = false; | 538 all_sq_str = false; |
539 | 539 |
540 if (all_dq_str && ! tmp.all_dq_strings_p ()) | 540 if (all_dq_str && ! tmp.all_dq_strings_p ()) |
541 all_dq_str = false; | 541 all_dq_str = false; |
542 | 542 |
543 if (! some_str && tmp.some_strings_p ()) | 543 if (! some_str && tmp.some_strings_p ()) |
544 some_str = true; | 544 some_str = true; |
545 | 545 |
546 if (all_real && ! tmp.all_real_p ()) | 546 if (all_real && ! tmp.all_real_p ()) |
547 all_real = false; | 547 all_real = false; |
548 | 548 |
549 if (all_cmplx && ! tmp.all_complex_p ()) | 549 if (all_cmplx && ! tmp.all_complex_p ()) |
550 all_cmplx = false; | 550 all_cmplx = false; |
551 | 551 |
552 if (all_mt && ! tmp.all_empty_p ()) | 552 if (all_mt && ! tmp.all_empty_p ()) |
553 all_mt = false; | 553 all_mt = false; |
554 | 554 |
555 if (!any_sparse && tmp.any_sparse_p ()) | 555 if (!any_sparse && tmp.any_sparse_p ()) |
556 any_sparse = true; | 556 any_sparse = true; |
557 | 557 |
558 if (!any_class && tmp.any_class_p ()) | 558 if (!any_class && tmp.any_class_p ()) |
559 any_class = true; | 559 any_class = true; |
560 | 560 |
561 append (tmp); | 561 append (tmp); |
562 } | 562 } |
563 else | 563 else |
564 break; | 564 break; |
565 } | 565 } |
566 | 566 |
567 if (! error_state) | 567 if (! error_state) |
568 { | 568 { |
569 for (iterator p = begin (); p != end (); p++) | 569 for (iterator p = begin (); p != end (); p++) |
570 { | 570 { |
571 octave_quit (); | 571 octave_quit (); |
572 | 572 |
573 tm_row_const elt = *p; | 573 tm_row_const elt = *p; |
574 | 574 |
575 octave_idx_type this_elt_nr = elt.rows (); | 575 octave_idx_type this_elt_nr = elt.rows (); |
576 octave_idx_type this_elt_nc = elt.cols (); | 576 octave_idx_type this_elt_nc = elt.cols (); |
577 | 577 |
578 std::string this_elt_class_nm = elt.class_name (); | 578 std::string this_elt_class_nm = elt.class_name (); |
579 | 579 |
580 dim_vector this_elt_dv = elt.dims (); | 580 dim_vector this_elt_dv = elt.dims (); |
581 | 581 |
582 if (!this_elt_dv.all_zero ()) | 582 if (!this_elt_dv.all_zero ()) |
583 { | 583 { |
584 all_mt = false; | 584 all_mt = false; |
585 | 585 |
586 if (first_elem) | 586 if (first_elem) |
587 { | 587 { |
588 first_elem = false; | 588 first_elem = false; |
589 | 589 |
590 class_nm = this_elt_class_nm; | 590 class_nm = this_elt_class_nm; |
591 | 591 |
592 dv.resize (this_elt_dv.length ()); | 592 dv.resize (this_elt_dv.length ()); |
593 for (int i = 2; i < dv.length (); i++) | 593 for (int i = 2; i < dv.length (); i++) |
594 dv.elem (i) = this_elt_dv.elem (i); | 594 dv.elem (i) = this_elt_dv.elem (i); |
595 | 595 |
596 dv.elem (0) = 0; | 596 dv.elem (0) = 0; |
597 | 597 |
598 dv.elem (1) = this_elt_nc; | 598 dv.elem (1) = this_elt_nc; |
599 } | 599 } |
600 else if (all_str) | 600 else if (all_str) |
601 { | 601 { |
602 class_nm = get_concat_class (class_nm, this_elt_class_nm); | 602 class_nm = get_concat_class (class_nm, this_elt_class_nm); |
603 | 603 |
604 if (this_elt_nc > cols ()) | 604 if (this_elt_nc > cols ()) |
605 dv.elem (1) = this_elt_nc; | 605 dv.elem (1) = this_elt_nc; |
606 } | 606 } |
607 else | 607 else |
608 { | 608 { |
609 class_nm = get_concat_class (class_nm, this_elt_class_nm); | 609 class_nm = get_concat_class (class_nm, this_elt_class_nm); |
610 | 610 |
611 bool get_out = false; | 611 bool get_out = false; |
612 int len = (this_elt_dv.length () < dv.length () | 612 int len = (this_elt_dv.length () < dv.length () |
613 ? this_elt_dv.length () : dv.length ()); | 613 ? this_elt_dv.length () : dv.length ()); |
614 | 614 |
615 for (int i = 1; i < len; i++) | 615 for (int i = 1; i < len; i++) |
616 { | 616 { |
617 if (i == 1 && this_elt_nc != dv (1)) | 617 if (i == 1 && this_elt_nc != dv (1)) |
618 { | 618 { |
619 ::error ("number of columns must match (%d != %d)", | 619 ::error ("number of columns must match (%d != %d)", |
620 this_elt_nc, dv (1)); | 620 this_elt_nc, dv (1)); |
621 get_out = true; | 621 get_out = true; |
622 break; | 622 break; |
623 } | 623 } |
624 else if (this_elt_dv (i) != dv (i)) | 624 else if (this_elt_dv (i) != dv (i)) |
625 { | 625 { |
626 ::error ("dimensions mismatch (dim = %i, %d != %d)", i+1, this_elt_dv (i), dv (i)); | 626 ::error ("dimensions mismatch (dim = %i, %d != %d)", i+1, this_elt_dv (i), dv (i)); |
627 get_out = true; | 627 get_out = true; |
628 break; | 628 break; |
629 } | 629 } |
630 } | 630 } |
631 | 631 |
632 if (this_elt_dv.length () > len) | 632 if (this_elt_dv.length () > len) |
633 for (int i = len; i < this_elt_dv.length (); i++) | 633 for (int i = len; i < this_elt_dv.length (); i++) |
634 if (this_elt_dv (i) != 1) | 634 if (this_elt_dv (i) != 1) |
635 { | 635 { |
636 ::error ("dimensions mismatch (dim = %i, %d != %d)", i+1, this_elt_dv (i), 1); | 636 ::error ("dimensions mismatch (dim = %i, %d != %d)", i+1, this_elt_dv (i), 1); |
637 get_out = true; | 637 get_out = true; |
638 break; | 638 break; |
639 } | 639 } |
640 | 640 |
641 if (dv.length () > len) | 641 if (dv.length () > len) |
642 for (int i = len; i < dv.length (); i++) | 642 for (int i = len; i < dv.length (); i++) |
643 if (dv (i) != 1) | 643 if (dv (i) != 1) |
644 { | 644 { |
645 ::error ("dimensions mismatch (dim = %i, %d != %d)", i+1, 1, dv(i)); | 645 ::error ("dimensions mismatch (dim = %i, %d != %d)", i+1, 1, dv(i)); |
646 get_out = true; | 646 get_out = true; |
647 break; | 647 break; |
648 } | 648 } |
649 | 649 |
650 if (get_out) | 650 if (get_out) |
651 break; | 651 break; |
652 } | 652 } |
653 dv.elem (0) = dv.elem (0) + this_elt_nr; | 653 dv.elem (0) = dv.elem (0) + this_elt_nr; |
654 } | 654 } |
655 else | 655 else |
656 warning_with_id ("Octave:empty-list-elements", | 656 warning_with_id ("Octave:empty-list-elements", |
657 "empty matrix found in matrix list"); | 657 "empty matrix found in matrix list"); |
658 } | 658 } |
659 } | 659 } |
660 | 660 |
661 ok = ! error_state; | 661 ok = ! error_state; |
662 } | 662 } |
663 | 663 |
679 octave_quit (); | 679 octave_quit (); |
680 | 680 |
681 tree_argument_list *elt = *p; | 681 tree_argument_list *elt = *p; |
682 | 682 |
683 if (elt && elt->has_magic_end ()) | 683 if (elt && elt->has_magic_end ()) |
684 return true; | 684 return true; |
685 } | 685 } |
686 | 686 |
687 return false; | 687 return false; |
688 } | 688 } |
689 | 689 |
695 octave_quit (); | 695 octave_quit (); |
696 | 696 |
697 tree_argument_list *elt = *p; | 697 tree_argument_list *elt = *p; |
698 | 698 |
699 if (! elt->all_elements_are_constant ()) | 699 if (! elt->all_elements_are_constant ()) |
700 return false; | 700 return false; |
701 } | 701 } |
702 | 702 |
703 return true; | 703 return true; |
704 } | 704 } |
705 | 705 |
719 void | 719 void |
720 maybe_warn_string_concat (bool all_dq_strings_p, bool all_sq_strings_p) | 720 maybe_warn_string_concat (bool all_dq_strings_p, bool all_sq_strings_p) |
721 { | 721 { |
722 if (! (all_dq_strings_p || all_sq_strings_p)) | 722 if (! (all_dq_strings_p || all_sq_strings_p)) |
723 warning_with_id ("Octave:string-concat", | 723 warning_with_id ("Octave:string-concat", |
724 "concatenation of different character string types may have unintended consequences"); | 724 "concatenation of different character string types may have unintended consequences"); |
725 } | 725 } |
726 | 726 |
727 template<class TYPE> | 727 template<class TYPE> |
728 static void | 728 static void |
729 single_type_concat (TYPE& result, | 729 single_type_concat (TYPE& result, |
818 // Try to speed up the common cases. | 818 // Try to speed up the common cases. |
819 | 819 |
820 std::string result_type = tmp.class_name (); | 820 std::string result_type = tmp.class_name (); |
821 | 821 |
822 if (any_class_p) | 822 if (any_class_p) |
823 { | 823 { |
824 octave_value_list tmp3 (tmp.length (), octave_value ()); | 824 octave_value_list tmp3 (tmp.length (), octave_value ()); |
825 | 825 |
826 int j = 0; | 826 int j = 0; |
827 for (tm_const::iterator p = tmp.begin (); p != tmp.end (); p++) | 827 for (tm_const::iterator p = tmp.begin (); p != tmp.end (); p++) |
828 { | 828 { |
829 octave_quit (); | 829 octave_quit (); |
830 | 830 |
831 tm_row_const row = *p; | 831 tm_row_const row = *p; |
832 | 832 |
833 if (row.length () == 1) | 833 if (row.length () == 1) |
834 tmp3 (j++) = *(row.begin ()); | 834 tmp3 (j++) = *(row.begin ()); |
835 else | 835 else |
836 { | 836 { |
837 octave_value_list tmp1 (row.length (), octave_value ()); | 837 octave_value_list tmp1 (row.length (), octave_value ()); |
838 | 838 |
839 int i = 0; | 839 int i = 0; |
840 for (tm_row_const::iterator q = row.begin (); | 840 for (tm_row_const::iterator q = row.begin (); |
841 q != row.end (); q++) | 841 q != row.end (); q++) |
842 tmp1 (i++) = *q; | 842 tmp1 (i++) = *q; |
843 | 843 |
844 octave_value_list tmp2; | 844 octave_value_list tmp2; |
845 octave_value fcn = | 845 octave_value fcn = |
846 symbol_table::find_function ("horzcat", tmp1); | 846 symbol_table::find_function ("horzcat", tmp1); |
847 | 847 |
848 if (fcn.is_defined ()) | 848 if (fcn.is_defined ()) |
849 { | 849 { |
850 tmp2 = fcn.do_multi_index_op (1, tmp1); | 850 tmp2 = fcn.do_multi_index_op (1, tmp1); |
851 | 851 |
852 if (error_state) | 852 if (error_state) |
853 goto done; | 853 goto done; |
854 | 854 |
855 tmp3 (j++) = tmp2 (0); | 855 tmp3 (j++) = tmp2 (0); |
856 } | 856 } |
857 else | 857 else |
858 { | 858 { |
859 ::error ("cat not find overloaded horzcat function"); | 859 ::error ("cat not find overloaded horzcat function"); |
860 goto done; | 860 goto done; |
861 } | 861 } |
862 } | 862 } |
863 } | 863 } |
864 | 864 |
865 if (tmp.length () == 1) | 865 if (tmp.length () == 1) |
866 retval = tmp3 (0); | 866 retval = tmp3 (0); |
867 else | 867 else |
868 { | 868 { |
869 octave_value_list tmp2; | 869 octave_value_list tmp2; |
870 octave_value fcn = symbol_table::find_function ("vertcat", tmp3); | 870 octave_value fcn = symbol_table::find_function ("vertcat", tmp3); |
871 | 871 |
872 if (fcn.is_defined ()) | 872 if (fcn.is_defined ()) |
873 { | 873 { |
874 tmp2 = fcn.do_multi_index_op (1, tmp3); | 874 tmp2 = fcn.do_multi_index_op (1, tmp3); |
875 | 875 |
876 if (! error_state) | 876 if (! error_state) |
877 retval = tmp2 (0); | 877 retval = tmp2 (0); |
878 } | 878 } |
879 else | 879 else |
880 ::error ("cat not find overloaded vertcat function"); | 880 ::error ("cat not find overloaded vertcat function"); |
881 } | 881 } |
882 } | 882 } |
883 else if (result_type == "double") | 883 else if (result_type == "double") |
884 { | 884 { |
885 if (any_sparse_p) | 885 if (any_sparse_p) |
886 { | 886 { |
887 if (all_real_p) | 887 if (all_real_p) |
888 retval = do_single_type_concat<SparseMatrix> (dv, tmp); | 888 retval = do_single_type_concat<SparseMatrix> (dv, tmp); |
889 else | 889 else |
890 retval = do_single_type_concat_no_mutate<SparseComplexMatrix, | 890 retval = do_single_type_concat_no_mutate<SparseComplexMatrix, |
891 octave_sparse_complex_matrix> (dv, tmp); | 891 octave_sparse_complex_matrix> (dv, tmp); |
892 } | 892 } |
893 else | 893 else |
894 { | 894 { |
895 if (all_real_p) | 895 if (all_real_p) |
896 retval = do_single_type_concat<NDArray> (dv, tmp); | 896 retval = do_single_type_concat<NDArray> (dv, tmp); |
897 else | 897 else |
898 retval = do_single_type_concat_no_mutate<ComplexNDArray, | 898 retval = do_single_type_concat_no_mutate<ComplexNDArray, |
899 octave_complex_matrix> (dv, tmp); | 899 octave_complex_matrix> (dv, tmp); |
900 } | 900 } |
901 } | 901 } |
902 else if (result_type == "single") | 902 else if (result_type == "single") |
903 { | 903 { |
904 if (all_real_p) | 904 if (all_real_p) |
905 retval = do_single_type_concat<FloatNDArray> (dv, tmp); | 905 retval = do_single_type_concat<FloatNDArray> (dv, tmp); |
906 else | 906 else |
907 retval = do_single_type_concat_no_mutate<FloatComplexNDArray, | 907 retval = do_single_type_concat_no_mutate<FloatComplexNDArray, |
908 octave_float_complex_matrix> (dv, tmp); | 908 octave_float_complex_matrix> (dv, tmp); |
909 } | 909 } |
910 else if (result_type == "char") | 910 else if (result_type == "char") |
911 { | 911 { |
912 char type = all_dq_strings_p ? '"' : '\''; | 912 char type = all_dq_strings_p ? '"' : '\''; |
913 | 913 |
914 maybe_warn_string_concat (all_dq_strings_p, all_sq_strings_p); | 914 maybe_warn_string_concat (all_dq_strings_p, all_sq_strings_p); |
915 | 915 |
916 charNDArray result (dv, Vstring_fill_char); | 916 charNDArray result (dv, Vstring_fill_char); |
917 | 917 |
918 single_type_concat (result, tmp); | 918 single_type_concat (result, tmp); |
919 | 919 |
920 retval = octave_value (result, type); | 920 retval = octave_value (result, type); |
921 } | 921 } |
922 else if (result_type == "logical") | 922 else if (result_type == "logical") |
923 { | 923 { |
924 if (any_sparse_p) | 924 if (any_sparse_p) |
925 retval = do_single_type_concat<SparseBoolMatrix> (dv, tmp); | 925 retval = do_single_type_concat<SparseBoolMatrix> (dv, tmp); |
926 else | 926 else |
927 retval = do_single_type_concat<boolNDArray> (dv, tmp); | 927 retval = do_single_type_concat<boolNDArray> (dv, tmp); |
928 } | 928 } |
929 else if (result_type == "int8") | 929 else if (result_type == "int8") |
930 retval = do_single_type_concat<int8NDArray> (dv, tmp); | 930 retval = do_single_type_concat<int8NDArray> (dv, tmp); |
931 else if (result_type == "int16") | 931 else if (result_type == "int16") |
932 retval = do_single_type_concat<int16NDArray> (dv, tmp); | 932 retval = do_single_type_concat<int16NDArray> (dv, tmp); |
933 else if (result_type == "int32") | 933 else if (result_type == "int32") |
934 retval = do_single_type_concat<int32NDArray> (dv, tmp); | 934 retval = do_single_type_concat<int32NDArray> (dv, tmp); |
935 else if (result_type == "int64") | 935 else if (result_type == "int64") |
936 retval = do_single_type_concat<int64NDArray> (dv, tmp); | 936 retval = do_single_type_concat<int64NDArray> (dv, tmp); |
937 else if (result_type == "uint8") | 937 else if (result_type == "uint8") |
938 retval = do_single_type_concat<uint8NDArray> (dv, tmp); | 938 retval = do_single_type_concat<uint8NDArray> (dv, tmp); |
939 else if (result_type == "uint16") | 939 else if (result_type == "uint16") |
940 retval = do_single_type_concat<uint16NDArray> (dv, tmp); | 940 retval = do_single_type_concat<uint16NDArray> (dv, tmp); |
941 else if (result_type == "uint32") | 941 else if (result_type == "uint32") |
942 retval = do_single_type_concat<uint32NDArray> (dv, tmp); | 942 retval = do_single_type_concat<uint32NDArray> (dv, tmp); |
943 else if (result_type == "uint64") | 943 else if (result_type == "uint64") |
944 retval = do_single_type_concat<uint64NDArray> (dv, tmp); | 944 retval = do_single_type_concat<uint64NDArray> (dv, tmp); |
945 else | 945 else |
946 { | 946 { |
947 // The line below might seem crazy, since we take a copy of | 947 // The line below might seem crazy, since we take a copy of |
948 // the first argument, resize it to be empty and then resize | 948 // the first argument, resize it to be empty and then resize |
949 // it to be full. This is done since it means that there is | 949 // it to be full. This is done since it means that there is |
950 // no recopying of data, as would happen if we used a single | 950 // no recopying of data, as would happen if we used a single |
951 // resize. It should be noted that resize operation is also | 951 // resize. It should be noted that resize operation is also |
952 // significantly slower than the do_cat_op function, so it | 952 // significantly slower than the do_cat_op function, so it |
953 // makes sense to have an empty matrix and copy all data. | 953 // makes sense to have an empty matrix and copy all data. |
954 // | 954 // |
955 // We might also start with a empty octave_value using | 955 // We might also start with a empty octave_value using |
956 // | 956 // |
957 // ctmp = octave_value_typeinfo::lookup_type | 957 // ctmp = octave_value_typeinfo::lookup_type |
958 // (tmp.begin() -> begin() -> type_name()); | 958 // (tmp.begin() -> begin() -> type_name()); |
959 // | 959 // |
960 // and then directly resize. However, for some types there | 960 // and then directly resize. However, for some types there |
961 // might be some additional setup needed, and so this should | 961 // might be some additional setup needed, and so this should |
962 // be avoided. | 962 // be avoided. |
963 | 963 |
964 octave_value ctmp; | 964 octave_value ctmp; |
965 | 965 |
966 // Find the first non-empty object | 966 // Find the first non-empty object |
967 | 967 |
968 if (any_sparse_p) | 968 if (any_sparse_p) |
969 { | 969 { |
970 // Start with sparse matrix to avoid issues memory issues | 970 // Start with sparse matrix to avoid issues memory issues |
971 // with things like [ones(1,4),sprandn(1e8,4,1e-4)] | 971 // with things like [ones(1,4),sprandn(1e8,4,1e-4)] |
972 if (all_real_p) | 972 if (all_real_p) |
973 ctmp = octave_sparse_matrix ().resize (dv); | 973 ctmp = octave_sparse_matrix ().resize (dv); |
974 else | 974 else |
975 ctmp = octave_sparse_complex_matrix ().resize (dv); | 975 ctmp = octave_sparse_complex_matrix ().resize (dv); |
976 } | 976 } |
977 else | 977 else |
978 { | 978 { |
979 for (tm_const::iterator p = tmp.begin (); p != tmp.end (); p++) | 979 for (tm_const::iterator p = tmp.begin (); p != tmp.end (); p++) |
980 { | 980 { |
981 octave_quit (); | 981 octave_quit (); |
982 | 982 |
983 tm_row_const row = *p; | 983 tm_row_const row = *p; |
984 | 984 |
985 for (tm_row_const::iterator q = row.begin (); | 985 for (tm_row_const::iterator q = row.begin (); |
986 q != row.end (); q++) | 986 q != row.end (); q++) |
987 { | 987 { |
988 octave_quit (); | 988 octave_quit (); |
989 | 989 |
990 ctmp = *q; | 990 ctmp = *q; |
991 | 991 |
992 if (! ctmp.all_zero_dims ()) | 992 if (! ctmp.all_zero_dims ()) |
993 goto found_non_empty; | 993 goto found_non_empty; |
994 } | 994 } |
995 } | 995 } |
996 | 996 |
997 ctmp = (*(tmp.begin() -> begin())); | 997 ctmp = (*(tmp.begin() -> begin())); |
998 | 998 |
999 found_non_empty: | 999 found_non_empty: |
1000 | 1000 |
1001 if (! all_empty_p) | 1001 if (! all_empty_p) |
1002 ctmp = ctmp.resize (dim_vector (0,0)).resize (dv); | 1002 ctmp = ctmp.resize (dim_vector (0,0)).resize (dv); |
1003 } | 1003 } |
1004 | 1004 |
1005 if (! error_state) | 1005 if (! error_state) |
1006 { | 1006 { |
1007 // Now, extract the values from the individual elements and | 1007 // Now, extract the values from the individual elements and |
1008 // insert them in the result matrix. | 1008 // insert them in the result matrix. |
1009 | 1009 |
1010 int dv_len = dv.length (); | 1010 int dv_len = dv.length (); |
1011 Array<octave_idx_type> ra_idx (dv_len > 1 ? dv_len : 2, 0); | 1011 Array<octave_idx_type> ra_idx (dv_len > 1 ? dv_len : 2, 0); |
1012 | 1012 |
1013 for (tm_const::iterator p = tmp.begin (); p != tmp.end (); p++) | 1013 for (tm_const::iterator p = tmp.begin (); p != tmp.end (); p++) |
1014 { | 1014 { |
1015 octave_quit (); | 1015 octave_quit (); |
1016 | 1016 |
1017 tm_row_const row = *p; | 1017 tm_row_const row = *p; |
1018 | 1018 |
1019 for (tm_row_const::iterator q = row.begin (); | 1019 for (tm_row_const::iterator q = row.begin (); |
1020 q != row.end (); | 1020 q != row.end (); |
1021 q++) | 1021 q++) |
1022 { | 1022 { |
1023 octave_quit (); | 1023 octave_quit (); |
1024 | 1024 |
1025 octave_value elt = *q; | 1025 octave_value elt = *q; |
1026 | 1026 |
1027 ctmp = do_cat_op (ctmp, elt, ra_idx); | 1027 ctmp = do_cat_op (ctmp, elt, ra_idx); |
1028 | 1028 |
1029 if (error_state) | 1029 if (error_state) |
1030 goto done; | 1030 goto done; |
1031 | 1031 |
1032 ra_idx (1) += elt.columns (); | 1032 ra_idx (1) += elt.columns (); |
1033 } | 1033 } |
1034 | 1034 |
1035 ra_idx (0) += row.rows (); | 1035 ra_idx (0) += row.rows (); |
1036 ra_idx (1) = 0; | 1036 ra_idx (1) = 0; |
1037 } | 1037 } |
1038 | 1038 |
1039 retval = ctmp; | 1039 retval = ctmp; |
1040 | 1040 |
1041 if (frc_str_conv && ! retval.is_string ()) | 1041 if (frc_str_conv && ! retval.is_string ()) |
1042 retval = retval.convert_to_str (); | 1042 retval = retval.convert_to_str (); |
1043 } | 1043 } |
1044 } | 1044 } |
1045 } | 1045 } |
1046 | 1046 |
1047 done: | 1047 done: |
1048 return retval; | 1048 return retval; |
1049 } | 1049 } |
1050 | 1050 |
1051 tree_expression * | 1051 tree_expression * |
1052 tree_matrix::dup (symbol_table::scope_id scope, | 1052 tree_matrix::dup (symbol_table::scope_id scope, |
1053 symbol_table::context_id context) const | 1053 symbol_table::context_id context) const |
1054 { | 1054 { |
1055 tree_matrix *new_matrix = new tree_matrix (0, line (), column ()); | 1055 tree_matrix *new_matrix = new tree_matrix (0, line (), column ()); |
1056 | 1056 |
1057 for (const_iterator p = begin (); p != end (); p++) | 1057 for (const_iterator p = begin (); p != end (); p++) |
1058 { | 1058 { |