Mercurial > hg > octave-lyh
comparison src/tc-assign.cc @ 143:7849db4b6dbc
[project @ 1993-10-04 02:36:45 by jwe]
author | jwe |
---|---|
date | Mon, 04 Oct 1993 02:36:58 +0000 |
parents | 78fd87e624cb |
children | 5167d307c1c9 |
comparison
equal
deleted
inserted
replaced
142:6906d6591452 | 143:7849db4b6dbc |
---|---|
86 type_tag = complex_scalar_constant; | 86 type_tag = complex_scalar_constant; |
87 } | 87 } |
88 else | 88 else |
89 { | 89 { |
90 error ("invalid assignment to scalar"); | 90 error ("invalid assignment to scalar"); |
91 jump_to_top_level (); | 91 return; |
92 } | 92 } |
93 } | 93 } |
94 else | 94 else |
95 { | 95 { |
96 if (rhs.const_type () == scalar_constant) | 96 if (rhs.const_type () == scalar_constant) |
104 type_tag = complex_scalar_constant; | 104 type_tag = complex_scalar_constant; |
105 } | 105 } |
106 else | 106 else |
107 { | 107 { |
108 error ("invalid assignment to scalar"); | 108 error ("invalid assignment to scalar"); |
109 jump_to_top_level (); | 109 return; |
110 } | 110 } |
111 } | 111 } |
112 } | 112 } |
113 else if (user_pref.resize_on_range_error) | 113 else if (user_pref.resize_on_range_error) |
114 { | 114 { |
115 tree_constant_rep::constant_type old_type_tag = type_tag; | |
116 | |
115 if (type_tag == complex_scalar_constant) | 117 if (type_tag == complex_scalar_constant) |
116 { | 118 { |
117 Complex *old_complex = complex_scalar; | 119 Complex *old_complex = complex_scalar; |
118 complex_matrix = new ComplexMatrix (1, 1, *complex_scalar); | 120 complex_matrix = new ComplexMatrix (1, 1, *complex_scalar); |
119 type_tag = complex_matrix_constant; | 121 type_tag = complex_matrix_constant; |
122 else if (type_tag == scalar_constant) | 124 else if (type_tag == scalar_constant) |
123 { | 125 { |
124 matrix = new Matrix (1, 1, scalar); | 126 matrix = new Matrix (1, 1, scalar); |
125 type_tag = matrix_constant; | 127 type_tag = matrix_constant; |
126 } | 128 } |
129 | |
130 // If there is an error, the call to do_matrix_assignment should not | |
131 // destroy the current value. tree_constant_rep::eval(int) will take | |
132 // care of converting single element matrices back to scalars. | |
133 | |
127 do_matrix_assignment (rhs, args, nargs); | 134 do_matrix_assignment (rhs, args, nargs); |
135 | |
136 // I don't think there's any other way to revert back to unknown | |
137 // constant types, so here it is. | |
138 | |
139 if (old_type_tag == unknown_constant && error_state) | |
140 { | |
141 if (type_tag == matrix_constant) | |
142 delete matrix; | |
143 else if (type_tag == complex_matrix_constant) | |
144 delete complex_matrix; | |
145 | |
146 type_tag = unknown_constant; | |
147 } | |
128 } | 148 } |
129 else if (nargs > 3 || nargs < 2) | 149 else if (nargs > 3 || nargs < 2) |
130 { | 150 error ("invalid index expression for scalar type"); |
131 error ("invalid index expression for scalar type"); | |
132 jump_to_top_level (); | |
133 } | |
134 else | 151 else |
135 { | 152 error ("index invalid or out of range for scalar type"); |
136 error ("index invalid or out of range for scalar type"); | |
137 jump_to_top_level (); | |
138 } | |
139 } | 153 } |
140 | 154 |
141 void | 155 void |
142 tree_constant_rep::do_matrix_assignment (tree_constant& rhs, | 156 tree_constant_rep::do_matrix_assignment (tree_constant& rhs, |
143 tree_constant *args, int nargs) | 157 tree_constant *args, int nargs) |
226 { | 240 { |
227 case complex_scalar_constant: | 241 case complex_scalar_constant: |
228 case scalar_constant: | 242 case scalar_constant: |
229 { | 243 { |
230 int i = NINT (tmp_i.double_value ()); | 244 int i = NINT (tmp_i.double_value ()); |
231 index_check (i-1, ""); | 245 if (index_check (i-1, "") < 0) |
246 return; | |
232 if (nr <= 1 || nc <= 1) | 247 if (nr <= 1 || nc <= 1) |
233 maybe_resize (i-1); | 248 maybe_resize (i-1); |
234 else | 249 else if (range_max_check (i-1, nr * nc) < 0) |
235 range_max_check (i-1, nr * nc); | 250 return; |
236 | 251 |
237 nr = rows (); | 252 nr = rows (); |
238 nc = columns (); | 253 nc = columns (); |
239 | 254 |
240 if (! indexed_assign_conforms (1, 1, rhs_nr, rhs_nc)) | 255 if (! indexed_assign_conforms (1, 1, rhs_nr, rhs_nc)) |
241 { | 256 { |
242 error ("for A(int) = X: X must be a scalar"); | 257 error ("for A(int) = X: X must be a scalar"); |
243 jump_to_top_level (); | 258 return; |
244 } | 259 } |
245 int ii = fortran_row (i, nr) - 1; | 260 int ii = fortran_row (i, nr) - 1; |
246 int jj = fortran_column (i, nr) - 1; | 261 int jj = fortran_column (i, nr) - 1; |
247 do_matrix_assignment (rhs, ii, jj); | 262 do_matrix_assignment (rhs, ii, jj); |
248 } | 263 } |
255 idx_vector ii (mi, 1, "", len); // Always do fortran indexing here... | 270 idx_vector ii (mi, 1, "", len); // Always do fortran indexing here... |
256 int imax = ii.max (); | 271 int imax = ii.max (); |
257 | 272 |
258 if (nr <= 1 || nc <= 1) | 273 if (nr <= 1 || nc <= 1) |
259 maybe_resize (imax-1); | 274 maybe_resize (imax-1); |
260 else | 275 else if (range_max_check (imax-1, len) < 0) |
261 range_max_check (imax-1, len); | 276 return; |
262 | 277 |
263 if (ii.capacity () != rhs_nr * rhs_nc) | 278 if (ii.capacity () != rhs_nr * rhs_nc) |
264 { | 279 { |
265 error ("A(matrix) = X: X and matrix must have the same\ | 280 error ("A(matrix) = X: X and matrix must have the same\ |
266 number of elements"); | 281 number of elements"); |
267 jump_to_top_level (); | 282 return; |
268 } | 283 } |
269 fortran_style_matrix_assignment (rhs, ii); | 284 fortran_style_matrix_assignment (rhs, ii); |
270 } | 285 } |
271 break; | 286 break; |
272 case string_constant: | 287 case string_constant: |
301 { | 316 { |
302 case complex_scalar_constant: | 317 case complex_scalar_constant: |
303 case scalar_constant: | 318 case scalar_constant: |
304 { | 319 { |
305 int i = tree_to_mat_idx (tmp_i.double_value ()); | 320 int i = tree_to_mat_idx (tmp_i.double_value ()); |
306 index_check (i, ""); | 321 if (index_check (i, "") < 0) |
322 return; | |
307 do_vector_assign (rhs, i); | 323 do_vector_assign (rhs, i); |
308 } | 324 } |
309 break; | 325 break; |
310 case complex_matrix_constant: | 326 case complex_matrix_constant: |
311 case matrix_constant: | 327 case matrix_constant: |
327 do_vector_assign (rhs, 1); | 343 do_vector_assign (rhs, 1); |
328 } | 344 } |
329 else | 345 else |
330 { | 346 { |
331 int imax; | 347 int imax; |
332 index_check (ri, imax, ""); | 348 if (index_check (ri, imax, "") < 0) |
349 return; | |
333 do_vector_assign (rhs, ri, imax); | 350 do_vector_assign (rhs, ri, imax); |
334 } | 351 } |
335 } | 352 } |
336 break; | 353 break; |
337 case magic_colon: | 354 case magic_colon: |
340 int rhs_nc = rhs.columns (); | 357 int rhs_nc = rhs.columns (); |
341 | 358 |
342 if (! indexed_assign_conforms (nr, nc, rhs_nr, rhs_nc)) | 359 if (! indexed_assign_conforms (nr, nc, rhs_nr, rhs_nc)) |
343 { | 360 { |
344 error ("A(:) = X: X and A must have the same dimensions"); | 361 error ("A(:) = X: X and A must have the same dimensions"); |
345 jump_to_top_level (); | 362 return; |
346 } | 363 } |
347 do_matrix_assignment (rhs, magic_colon, magic_colon); | 364 do_matrix_assignment (rhs, magic_colon, magic_colon); |
348 } | 365 } |
349 break; | 366 break; |
350 default: | 367 default: |
361 int nc = columns (); | 378 int nc = columns (); |
362 | 379 |
363 if (nr == 1 && nc == 1) // No orientation to preserve | 380 if (nr == 1 && nc == 1) // No orientation to preserve |
364 { | 381 { |
365 if (! ( ilen == rhs_nr || ilen == rhs_nc)) | 382 if (! ( ilen == rhs_nr || ilen == rhs_nc)) |
366 { | 383 error ("A(%s) = X: X and %s must have the same number of\ |
367 error ("A(%s) = X: X and %s must have the same number of\ | |
368 elements", rm, rm); | 384 elements", rm, rm); |
369 jump_to_top_level (); | |
370 } | |
371 } | 385 } |
372 else if (nr == 1) // Preserve current row orientation | 386 else if (nr == 1) // Preserve current row orientation |
373 { | 387 { |
374 if (! (rhs_nr == 1 && rhs_nc == ilen)) | 388 if (! (rhs_nr == 1 && rhs_nc == ilen)) |
375 { | 389 error ("A(%s) = X: where A is a row vector, X must also be a\ |
376 error ("A(%s) = X: where A is a row vector, X must also be a\ | |
377 row vector with the same number of elements as %s", rm, rm); | 390 row vector with the same number of elements as %s", rm, rm); |
378 jump_to_top_level (); | |
379 } | |
380 } | 391 } |
381 else if (nc == 1) // Preserve current column orientation | 392 else if (nc == 1) // Preserve current column orientation |
382 { | 393 { |
383 if (! (rhs_nc == 1 && rhs_nr == ilen)) | 394 if (! (rhs_nc == 1 && rhs_nr == ilen)) |
384 { | 395 error ("A(%s) = X: where A is a column vector, X must also\ |
385 error ("A(%s) = X: where A is a column vector, X must also\ | |
386 be a column vector with the same number of elements as %s", rm, rm); | 396 be a column vector with the same number of elements as %s", rm, rm); |
387 jump_to_top_level (); | |
388 } | |
389 } | 397 } |
390 else | 398 else |
391 panic_impossible (); | 399 panic_impossible (); |
392 } | 400 } |
393 | 401 |
398 int rhs_nc = rhs.columns (); | 406 int rhs_nc = rhs.columns (); |
399 | 407 |
400 if (! indexed_assign_conforms (1, 1, rhs_nr, rhs_nc)) | 408 if (! indexed_assign_conforms (1, 1, rhs_nr, rhs_nc)) |
401 { | 409 { |
402 error ("for A(int) = X: X must be a scalar"); | 410 error ("for A(int) = X: X must be a scalar"); |
403 jump_to_top_level (); | 411 return; |
404 } | 412 } |
405 | 413 |
406 maybe_resize (i); | 414 maybe_resize (i); |
407 | 415 |
408 int nr = rows (); | 416 int nr = rows (); |
528 panic_impossible (); | 536 panic_impossible (); |
529 } | 537 } |
530 else if (nr*nc != rhs_size) | 538 else if (nr*nc != rhs_size) |
531 { | 539 { |
532 error ("A(:) = X: X and A must have the same number of elements"); | 540 error ("A(:) = X: X and A must have the same number of elements"); |
533 jump_to_top_level (); | 541 return; |
534 } | 542 } |
535 | 543 |
536 if (rhs.const_type () == matrix_constant) | 544 if (rhs.const_type () == matrix_constant) |
537 { | 545 { |
538 double *cop_out = rhs_m.fortran_vec (); | 546 double *cop_out = rhs_m.fortran_vec (); |
586 complex_matrix->elem (ii, jj) = *cop_out++; | 594 complex_matrix->elem (ii, jj) = *cop_out++; |
587 } | 595 } |
588 } | 596 } |
589 } | 597 } |
590 else | 598 else |
591 { | 599 error ("number of rows and columns must match for indexed assignment"); |
592 error ("number of rows and columns must match for indexed assignment"); | |
593 jump_to_top_level (); | |
594 } | |
595 } | 600 } |
596 | 601 |
597 void | 602 void |
598 tree_constant_rep::do_matrix_assignment (tree_constant& rhs, | 603 tree_constant_rep::do_matrix_assignment (tree_constant& rhs, |
599 tree_constant& i_arg, | 604 tree_constant& i_arg, |
601 { | 606 { |
602 tree_constant tmp_i = i_arg.make_numeric_or_range_or_magic (); | 607 tree_constant tmp_i = i_arg.make_numeric_or_range_or_magic (); |
603 | 608 |
604 tree_constant_rep::constant_type itype = tmp_i.const_type (); | 609 tree_constant_rep::constant_type itype = tmp_i.const_type (); |
605 | 610 |
606 // index_check() and matrix_to_index_vector() jump to the top level on | |
607 // errors. | |
608 | |
609 switch (itype) | 611 switch (itype) |
610 { | 612 { |
611 case complex_scalar_constant: | 613 case complex_scalar_constant: |
612 case scalar_constant: | 614 case scalar_constant: |
613 { | 615 { |
614 int i = tree_to_mat_idx (tmp_i.double_value ()); | 616 int i = tree_to_mat_idx (tmp_i.double_value ()); |
615 index_check (i, "row"); | 617 if (index_check (i, "row") < 0) |
618 return; | |
616 do_matrix_assignment (rhs, i, j_arg); | 619 do_matrix_assignment (rhs, i, j_arg); |
617 } | 620 } |
618 break; | 621 break; |
619 case complex_matrix_constant: | 622 case complex_matrix_constant: |
620 case matrix_constant: | 623 case matrix_constant: |
635 do_matrix_assignment (rhs, 1, j_arg); | 638 do_matrix_assignment (rhs, 1, j_arg); |
636 } | 639 } |
637 else | 640 else |
638 { | 641 { |
639 int imax; | 642 int imax; |
640 index_check (ri, imax, "row"); | 643 if (index_check (ri, imax, "row") < 0) |
644 return; | |
641 do_matrix_assignment (rhs, ri, imax, j_arg); | 645 do_matrix_assignment (rhs, ri, imax, j_arg); |
642 } | 646 } |
643 } | 647 } |
644 break; | 648 break; |
645 case magic_colon: | 649 case magic_colon: |
660 tree_constant_rep::constant_type jtype = tmp_j.const_type (); | 664 tree_constant_rep::constant_type jtype = tmp_j.const_type (); |
661 | 665 |
662 int rhs_nr = rhs.rows (); | 666 int rhs_nr = rhs.rows (); |
663 int rhs_nc = rhs.columns (); | 667 int rhs_nc = rhs.columns (); |
664 | 668 |
665 // index_check() and matrix_to_index_vector() jump to the top level on | |
666 // errors. | |
667 | |
668 switch (jtype) | 669 switch (jtype) |
669 { | 670 { |
670 case complex_scalar_constant: | 671 case complex_scalar_constant: |
671 case scalar_constant: | 672 case scalar_constant: |
672 { | 673 { |
673 int j = tree_to_mat_idx (tmp_j.double_value ()); | 674 int j = tree_to_mat_idx (tmp_j.double_value ()); |
674 index_check (j, "column"); | 675 if (index_check (j, "column") < 0) |
676 return; | |
675 if (! indexed_assign_conforms (1, 1, rhs_nr, rhs_nc)) | 677 if (! indexed_assign_conforms (1, 1, rhs_nr, rhs_nc)) |
676 { | 678 { |
677 error ("A(int,int) = X, X must be a scalar"); | 679 error ("A(int,int) = X, X must be a scalar"); |
678 jump_to_top_level (); | 680 return; |
679 } | 681 } |
680 maybe_resize (i, j); | 682 maybe_resize (i, j); |
681 do_matrix_assignment (rhs, i, j); | 683 do_matrix_assignment (rhs, i, j); |
682 } | 684 } |
683 break; | 685 break; |
689 columns ()); | 691 columns ()); |
690 if (! indexed_assign_conforms (1, jv.capacity (), rhs_nr, rhs_nc)) | 692 if (! indexed_assign_conforms (1, jv.capacity (), rhs_nr, rhs_nc)) |
691 { | 693 { |
692 error ("A(int,matrix) = X: X must be a row vector with the\ | 694 error ("A(int,matrix) = X: X must be a row vector with the\ |
693 same number of elements as matrix"); | 695 same number of elements as matrix"); |
694 jump_to_top_level (); | 696 return; |
695 } | 697 } |
696 maybe_resize (i, jv.max ()); | 698 maybe_resize (i, jv.max ()); |
697 do_matrix_assignment (rhs, i, jv); | 699 do_matrix_assignment (rhs, i, jv); |
698 } | 700 } |
699 break; | 701 break; |
705 Range rj = tmp_j.range_value (); | 707 Range rj = tmp_j.range_value (); |
706 if (! indexed_assign_conforms (1, rj.nelem (), rhs_nr, rhs_nc)) | 708 if (! indexed_assign_conforms (1, rj.nelem (), rhs_nr, rhs_nc)) |
707 { | 709 { |
708 error ("A(int,range) = X: X must be a row vector with the\ | 710 error ("A(int,range) = X: X must be a row vector with the\ |
709 same number of elements as range"); | 711 same number of elements as range"); |
710 jump_to_top_level (); | 712 return; |
711 } | 713 } |
712 if (columns () == 2 && is_zero_one (rj) && rhs_nc == 1) | 714 if (columns () == 2 && is_zero_one (rj) && rhs_nc == 1) |
713 { | 715 { |
714 do_matrix_assignment (rhs, i, 1); | 716 do_matrix_assignment (rhs, i, 1); |
715 } | 717 } |
716 else | 718 else |
717 { | 719 { |
718 int jmax; | 720 int jmax; |
719 index_check (rj, jmax, "column"); | 721 if (index_check (rj, jmax, "column") < 0) |
722 return; | |
720 maybe_resize (i, jmax); | 723 maybe_resize (i, jmax); |
721 do_matrix_assignment (rhs, i, rj); | 724 do_matrix_assignment (rhs, i, rj); |
722 } | 725 } |
723 } | 726 } |
724 break; | 727 break; |
743 maybe_resize (i, nc-1); | 746 maybe_resize (i, nc-1); |
744 else | 747 else |
745 { | 748 { |
746 error ("A(int,:) = X: X must be a row vector with the\ | 749 error ("A(int,:) = X: X must be a row vector with the\ |
747 same number of columns as A"); | 750 same number of columns as A"); |
748 jump_to_top_level (); | 751 return; |
749 } | 752 } |
750 | 753 |
751 do_matrix_assignment (rhs, i, magic_colon); | 754 do_matrix_assignment (rhs, i, magic_colon); |
752 } | 755 } |
753 break; | 756 break; |
766 tree_constant_rep::constant_type jtype = tmp_j.const_type (); | 769 tree_constant_rep::constant_type jtype = tmp_j.const_type (); |
767 | 770 |
768 int rhs_nr = rhs.rows (); | 771 int rhs_nr = rhs.rows (); |
769 int rhs_nc = rhs.columns (); | 772 int rhs_nc = rhs.columns (); |
770 | 773 |
771 // index_check() and matrix_to_index_vector() jump to the top level on | |
772 // errors. | |
773 | |
774 switch (jtype) | 774 switch (jtype) |
775 { | 775 { |
776 case complex_scalar_constant: | 776 case complex_scalar_constant: |
777 case scalar_constant: | 777 case scalar_constant: |
778 { | 778 { |
779 int j = tree_to_mat_idx (tmp_j.double_value ()); | 779 int j = tree_to_mat_idx (tmp_j.double_value ()); |
780 index_check (j, "column"); | 780 if (index_check (j, "column") < 0) |
781 return; | |
781 if (! indexed_assign_conforms (iv.capacity (), 1, rhs_nr, rhs_nc)) | 782 if (! indexed_assign_conforms (iv.capacity (), 1, rhs_nr, rhs_nc)) |
782 { | 783 { |
783 error ("A(matrix,int) = X: X must be a column vector with\ | 784 error ("A(matrix,int) = X: X must be a column vector with\ |
784 the same number of elements as matrix"); | 785 the same number of elements as matrix"); |
785 jump_to_top_level (); | 786 return; |
786 } | 787 } |
787 maybe_resize (iv.max (), j); | 788 maybe_resize (iv.max (), j); |
788 do_matrix_assignment (rhs, iv, j); | 789 do_matrix_assignment (rhs, iv, j); |
789 } | 790 } |
790 break; | 791 break; |
798 rhs_nr, rhs_nc)) | 799 rhs_nr, rhs_nc)) |
799 { | 800 { |
800 error ("A(r_matrix,c_matrix) = X: the number of rows in X\ | 801 error ("A(r_matrix,c_matrix) = X: the number of rows in X\ |
801 must match the number of elements in r_matrix and the number of\ | 802 must match the number of elements in r_matrix and the number of\ |
802 columns in X must match the number of elements in c_matrix"); | 803 columns in X must match the number of elements in c_matrix"); |
803 jump_to_top_level (); | 804 return; |
804 } | 805 } |
805 maybe_resize (iv.max (), jv.max ()); | 806 maybe_resize (iv.max (), jv.max ()); |
806 do_matrix_assignment (rhs, iv, jv); | 807 do_matrix_assignment (rhs, iv, jv); |
807 } | 808 } |
808 break; | 809 break; |
816 rhs_nr, rhs_nc)) | 817 rhs_nr, rhs_nc)) |
817 { | 818 { |
818 error ("A(matrix,range) = X: the number of rows in X must\ | 819 error ("A(matrix,range) = X: the number of rows in X must\ |
819 match the number of elements in matrix and the number of columns in X\ | 820 match the number of elements in matrix and the number of columns in X\ |
820 must match the number of elements in range"); | 821 must match the number of elements in range"); |
821 jump_to_top_level (); | 822 return; |
822 } | 823 } |
823 if (columns () == 2 && is_zero_one (rj) && rhs_nc == 1) | 824 if (columns () == 2 && is_zero_one (rj) && rhs_nc == 1) |
824 { | 825 { |
825 do_matrix_assignment (rhs, iv, 1); | 826 do_matrix_assignment (rhs, iv, 1); |
826 } | 827 } |
827 else | 828 else |
828 { | 829 { |
829 int jmax; | 830 int jmax; |
830 index_check (rj, jmax, "column"); | 831 if (index_check (rj, jmax, "column") < 0) |
832 return; | |
831 maybe_resize (iv.max (), jmax); | 833 maybe_resize (iv.max (), jmax); |
832 do_matrix_assignment (rhs, iv, rj); | 834 do_matrix_assignment (rhs, iv, rj); |
833 } | 835 } |
834 } | 836 } |
835 break; | 837 break; |
839 if (! indexed_assign_conforms (iv.capacity (), nc, rhs_nr, rhs_nc)) | 841 if (! indexed_assign_conforms (iv.capacity (), nc, rhs_nr, rhs_nc)) |
840 { | 842 { |
841 error ("A(matrix,:) = X: the number of rows in X must\ | 843 error ("A(matrix,:) = X: the number of rows in X must\ |
842 match the number of elements in matrix, and the number of columns in\ | 844 match the number of elements in matrix, and the number of columns in\ |
843 X must match the number of columns in A"); | 845 X must match the number of columns in A"); |
844 jump_to_top_level (); | 846 return; |
845 } | 847 } |
846 maybe_resize (iv.max (), nc-1); | 848 maybe_resize (iv.max (), nc-1); |
847 do_matrix_assignment (rhs, iv, magic_colon); | 849 do_matrix_assignment (rhs, iv, magic_colon); |
848 } | 850 } |
849 break; | 851 break; |
863 tree_constant_rep::constant_type jtype = tmp_j.const_type (); | 865 tree_constant_rep::constant_type jtype = tmp_j.const_type (); |
864 | 866 |
865 int rhs_nr = rhs.rows (); | 867 int rhs_nr = rhs.rows (); |
866 int rhs_nc = rhs.columns (); | 868 int rhs_nc = rhs.columns (); |
867 | 869 |
868 // index_check() and matrix_to_index_vector() jump to the top level on | |
869 // errors. | |
870 | |
871 switch (jtype) | 870 switch (jtype) |
872 { | 871 { |
873 case complex_scalar_constant: | 872 case complex_scalar_constant: |
874 case scalar_constant: | 873 case scalar_constant: |
875 { | 874 { |
876 int j = tree_to_mat_idx (tmp_j.double_value ()); | 875 int j = tree_to_mat_idx (tmp_j.double_value ()); |
877 index_check (j, "column"); | 876 if (index_check (j, "column") < 0) |
877 return; | |
878 if (! indexed_assign_conforms (ri.nelem (), 1, rhs_nr, rhs_nc)) | 878 if (! indexed_assign_conforms (ri.nelem (), 1, rhs_nr, rhs_nc)) |
879 { | 879 { |
880 error ("A(range,int) = X: X must be a column vector with\ | 880 error ("A(range,int) = X: X must be a column vector with\ |
881 the same number of elements as range"); | 881 the same number of elements as range"); |
882 jump_to_top_level (); | 882 return; |
883 jump_to_top_level (); | |
884 } | 883 } |
885 maybe_resize (imax, j); | 884 maybe_resize (imax, j); |
886 do_matrix_assignment (rhs, ri, j); | 885 do_matrix_assignment (rhs, ri, j); |
887 } | 886 } |
888 break; | 887 break; |
896 rhs_nr, rhs_nc)) | 895 rhs_nr, rhs_nc)) |
897 { | 896 { |
898 error ("A(range,matrix) = X: the number of rows in X must\ | 897 error ("A(range,matrix) = X: the number of rows in X must\ |
899 match the number of elements in range and the number of columns in X\ | 898 match the number of elements in range and the number of columns in X\ |
900 must match the number of elements in matrix"); | 899 must match the number of elements in matrix"); |
901 jump_to_top_level (); | 900 return; |
902 } | 901 } |
903 maybe_resize (imax, jv.max ()); | 902 maybe_resize (imax, jv.max ()); |
904 do_matrix_assignment (rhs, ri, jv); | 903 do_matrix_assignment (rhs, ri, jv); |
905 } | 904 } |
906 break; | 905 break; |
914 rhs_nr, rhs_nc)) | 913 rhs_nr, rhs_nc)) |
915 { | 914 { |
916 error ("A(r_range,c_range) = X: the number of rows in X\ | 915 error ("A(r_range,c_range) = X: the number of rows in X\ |
917 must match the number of elements in r_range and the number of\ | 916 must match the number of elements in r_range and the number of\ |
918 columns in X must match the number of elements in c_range\n"); | 917 columns in X must match the number of elements in c_range\n"); |
919 jump_to_top_level (); | 918 return; |
920 } | 919 } |
921 if (columns () == 2 && is_zero_one (rj) && rhs_nc == 1) | 920 if (columns () == 2 && is_zero_one (rj) && rhs_nc == 1) |
922 { | 921 { |
923 do_matrix_assignment (rhs, ri, 1); | 922 do_matrix_assignment (rhs, ri, 1); |
924 } | 923 } |
925 else | 924 else |
926 { | 925 { |
927 int jmax; | 926 int jmax; |
928 index_check (rj, jmax, "column"); | 927 if (index_check (rj, jmax, "column") < 0) |
928 return; | |
929 maybe_resize (imax, jmax); | 929 maybe_resize (imax, jmax); |
930 do_matrix_assignment (rhs, ri, rj); | 930 do_matrix_assignment (rhs, ri, rj); |
931 } | 931 } |
932 } | 932 } |
933 break; | 933 break; |
937 if (! indexed_assign_conforms (ri.nelem (), nc, rhs_nr, rhs_nc)) | 937 if (! indexed_assign_conforms (ri.nelem (), nc, rhs_nr, rhs_nc)) |
938 { | 938 { |
939 error ("A(range,:) = X: the number of rows in X must match\ | 939 error ("A(range,:) = X: the number of rows in X must match\ |
940 the number of elements in range, and the number of columns in X must\ | 940 the number of elements in range, and the number of columns in X must\ |
941 match the number of columns in A"); | 941 match the number of columns in A"); |
942 jump_to_top_level (); | 942 return; |
943 } | 943 } |
944 maybe_resize (imax, nc-1); | 944 maybe_resize (imax, nc-1); |
945 do_matrix_assignment (rhs, ri, magic_colon); | 945 do_matrix_assignment (rhs, ri, magic_colon); |
946 } | 946 } |
947 break; | 947 break; |
961 tree_constant_rep::constant_type jtype = tmp_j.const_type (); | 961 tree_constant_rep::constant_type jtype = tmp_j.const_type (); |
962 | 962 |
963 int rhs_nr = rhs.rows (); | 963 int rhs_nr = rhs.rows (); |
964 int rhs_nc = rhs.columns (); | 964 int rhs_nc = rhs.columns (); |
965 | 965 |
966 // index_check() and matrix_to_index_vector() jump to the top level on | |
967 // errors. | |
968 | |
969 switch (jtype) | 966 switch (jtype) |
970 { | 967 { |
971 case complex_scalar_constant: | 968 case complex_scalar_constant: |
972 case scalar_constant: | 969 case scalar_constant: |
973 { | 970 { |
974 int j = tree_to_mat_idx (tmp_j.double_value ()); | 971 int j = tree_to_mat_idx (tmp_j.double_value ()); |
975 index_check (j, "column"); | 972 if (index_check (j, "column") < 0) |
973 return; | |
976 int nr = rows (); | 974 int nr = rows (); |
977 if (nr == 0 && columns () == 0 && rhs_nc == 1) | 975 if (nr == 0 && columns () == 0 && rhs_nc == 1) |
978 { | 976 { |
979 if (rhs.is_complex_type ()) | 977 if (rhs.is_complex_type ()) |
980 { | 978 { |
992 maybe_resize (nr-1, j); | 990 maybe_resize (nr-1, j); |
993 else | 991 else |
994 { | 992 { |
995 error ("A(:,int) = X: X must be a column vector with the\ | 993 error ("A(:,int) = X: X must be a column vector with the\ |
996 same number of rows as A"); | 994 same number of rows as A"); |
997 jump_to_top_level (); | 995 return; |
998 } | 996 } |
999 | 997 |
1000 do_matrix_assignment (rhs, magic_colon, j); | 998 do_matrix_assignment (rhs, magic_colon, j); |
1001 } | 999 } |
1002 break; | 1000 break; |
1010 if (! indexed_assign_conforms (nr, jv.capacity (), rhs_nr, rhs_nc)) | 1008 if (! indexed_assign_conforms (nr, jv.capacity (), rhs_nr, rhs_nc)) |
1011 { | 1009 { |
1012 error ("A(:,matrix) = X: the number of rows in X must\ | 1010 error ("A(:,matrix) = X: the number of rows in X must\ |
1013 match the number of rows in A, and the number of columns in X must\ | 1011 match the number of rows in A, and the number of columns in X must\ |
1014 match the number of elements in matrix"); | 1012 match the number of elements in matrix"); |
1015 jump_to_top_level (); | 1013 return; |
1016 } | 1014 } |
1017 maybe_resize (nr-1, jv.max ()); | 1015 maybe_resize (nr-1, jv.max ()); |
1018 do_matrix_assignment (rhs, magic_colon, jv); | 1016 do_matrix_assignment (rhs, magic_colon, jv); |
1019 } | 1017 } |
1020 break; | 1018 break; |
1028 if (! indexed_assign_conforms (nr, rj.nelem (), rhs_nr, rhs_nc)) | 1026 if (! indexed_assign_conforms (nr, rj.nelem (), rhs_nr, rhs_nc)) |
1029 { | 1027 { |
1030 error ("A(:,range) = X: the number of rows in X must match\ | 1028 error ("A(:,range) = X: the number of rows in X must match\ |
1031 the number of rows in A, and the number of columns in X must match\ | 1029 the number of rows in A, and the number of columns in X must match\ |
1032 the number of elements in range"); | 1030 the number of elements in range"); |
1033 jump_to_top_level (); | 1031 return; |
1034 } | 1032 } |
1035 if (columns () == 2 && is_zero_one (rj) && rhs_nc == 1) | 1033 if (columns () == 2 && is_zero_one (rj) && rhs_nc == 1) |
1036 { | 1034 { |
1037 do_matrix_assignment (rhs, magic_colon, 1); | 1035 do_matrix_assignment (rhs, magic_colon, 1); |
1038 } | 1036 } |
1039 else | 1037 else |
1040 { | 1038 { |
1041 int jmax; | 1039 int jmax; |
1042 index_check (rj, jmax, "column"); | 1040 if (index_check (rj, jmax, "column") < 0) |
1041 return; | |
1043 maybe_resize (nr-1, jmax); | 1042 maybe_resize (nr-1, jmax); |
1044 do_matrix_assignment (rhs, magic_colon, rj); | 1043 do_matrix_assignment (rhs, magic_colon, rj); |
1045 } | 1044 } |
1046 } | 1045 } |
1047 break; | 1046 break; |