1
|
1 // tc-assign.cc -*- C++ -*- |
|
2 /* |
|
3 |
|
4 Copyright (C) 1992, 1993 John W. Eaton |
|
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 |
|
10 Free Software Foundation; either version 2, or (at your option) any |
|
11 later version. |
|
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 |
|
19 along with Octave; see the file COPYING. If not, write to the Free |
|
20 Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
|
21 |
|
22 */ |
|
23 |
|
24 #ifdef __GNUG__ |
|
25 #pragma implementation |
|
26 #endif |
|
27 |
|
28 #include "user-prefs.h" |
|
29 #include "error.h" |
|
30 #include "gripes.h" |
|
31 #include "utils.h" |
|
32 #include "tree-const.h" |
|
33 |
|
34 #include "tc-inlines.cc" |
|
35 |
|
36 void |
|
37 tree_constant_rep::assign (tree_constant& rhs, tree_constant *args, int nargs) |
|
38 { |
|
39 tree_constant rhs_tmp = rhs.make_numeric (); |
|
40 |
|
41 if (type_tag == string_constant || type_tag == range_constant) |
|
42 force_numeric (); |
|
43 |
|
44 switch (type_tag) |
|
45 { |
|
46 case complex_scalar_constant: |
|
47 case scalar_constant: |
|
48 case unknown_constant: |
|
49 do_scalar_assignment (rhs_tmp, args, nargs); |
|
50 break; |
|
51 case complex_matrix_constant: |
|
52 case matrix_constant: |
|
53 do_matrix_assignment (rhs_tmp, args, nargs); |
|
54 break; |
|
55 case string_constant: |
|
56 error ("invalid assignment to string type"); |
|
57 break; |
|
58 case range_constant: |
|
59 case magic_colon: |
|
60 default: |
|
61 panic_impossible (); |
|
62 break; |
|
63 } |
|
64 } |
|
65 |
|
66 void |
|
67 tree_constant_rep::do_scalar_assignment (tree_constant& rhs, |
|
68 tree_constant *args, int nargs) |
|
69 { |
|
70 assert (type_tag == unknown_constant |
|
71 || type_tag == scalar_constant |
|
72 || type_tag == complex_scalar_constant); |
|
73 |
|
74 if (rhs.is_scalar_type () && valid_scalar_indices (args, nargs)) |
|
75 { |
|
76 if (type_tag == unknown_constant || type_tag == scalar_constant) |
|
77 { |
|
78 if (rhs.const_type () == scalar_constant) |
|
79 { |
|
80 scalar = rhs.double_value (); |
|
81 type_tag = scalar_constant; |
|
82 } |
|
83 else if (rhs.const_type () == complex_scalar_constant) |
|
84 { |
|
85 complex_scalar = new Complex (rhs.complex_value ()); |
|
86 type_tag = complex_scalar_constant; |
|
87 } |
|
88 else |
|
89 { |
|
90 error ("invalid assignment to scalar"); |
143
|
91 return; |
1
|
92 } |
|
93 } |
|
94 else |
|
95 { |
|
96 if (rhs.const_type () == scalar_constant) |
|
97 { |
|
98 scalar = rhs.double_value (); |
|
99 type_tag = scalar_constant; |
|
100 } |
|
101 else if (rhs.const_type () == complex_scalar_constant) |
|
102 { |
|
103 *complex_scalar = rhs.complex_value (); |
|
104 type_tag = complex_scalar_constant; |
|
105 } |
|
106 else |
|
107 { |
|
108 error ("invalid assignment to scalar"); |
143
|
109 return; |
1
|
110 } |
|
111 } |
|
112 } |
|
113 else if (user_pref.resize_on_range_error) |
|
114 { |
143
|
115 tree_constant_rep::constant_type old_type_tag = type_tag; |
|
116 |
1
|
117 if (type_tag == complex_scalar_constant) |
|
118 { |
|
119 Complex *old_complex = complex_scalar; |
|
120 complex_matrix = new ComplexMatrix (1, 1, *complex_scalar); |
|
121 type_tag = complex_matrix_constant; |
|
122 delete old_complex; |
|
123 } |
|
124 else if (type_tag == scalar_constant) |
|
125 { |
|
126 matrix = new Matrix (1, 1, scalar); |
|
127 type_tag = matrix_constant; |
|
128 } |
143
|
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 |
1
|
134 do_matrix_assignment (rhs, args, nargs); |
143
|
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 } |
1
|
148 } |
|
149 else if (nargs > 3 || nargs < 2) |
143
|
150 error ("invalid index expression for scalar type"); |
1
|
151 else |
143
|
152 error ("index invalid or out of range for scalar type"); |
1
|
153 } |
|
154 |
|
155 void |
|
156 tree_constant_rep::do_matrix_assignment (tree_constant& rhs, |
|
157 tree_constant *args, int nargs) |
|
158 { |
|
159 assert (type_tag == unknown_constant |
|
160 || type_tag == matrix_constant |
|
161 || type_tag == complex_matrix_constant); |
|
162 |
|
163 if (type_tag == matrix_constant && rhs.is_complex_type ()) |
|
164 { |
|
165 Matrix *old_matrix = matrix; |
|
166 complex_matrix = new ComplexMatrix (*matrix); |
|
167 type_tag = complex_matrix_constant; |
|
168 delete old_matrix; |
|
169 } |
|
170 else if (type_tag == unknown_constant) |
|
171 { |
|
172 if (rhs.is_complex_type ()) |
|
173 { |
|
174 complex_matrix = new ComplexMatrix (); |
|
175 type_tag = complex_matrix_constant; |
|
176 } |
|
177 else |
|
178 { |
|
179 matrix = new Matrix (); |
|
180 type_tag = matrix_constant; |
|
181 } |
|
182 } |
|
183 |
|
184 switch (nargs) |
|
185 { |
|
186 case 2: |
|
187 if (args == NULL_TREE_CONST) |
|
188 error ("matrix index is null"); |
|
189 else if (args[1].is_undefined ()) |
|
190 error ("matrix index is a null expression"); |
|
191 else |
|
192 do_matrix_assignment (rhs, args[1]); |
|
193 break; |
|
194 case 3: |
|
195 if (args == NULL_TREE_CONST) |
|
196 error ("matrix indices are null"); |
|
197 else if (args[1].is_undefined ()) |
|
198 error ("first matrix index is a null expression"); |
|
199 else if (args[2].is_undefined ()) |
|
200 error ("second matrix index is a null expression"); |
|
201 else |
|
202 do_matrix_assignment (rhs, args[1], args[2]); |
|
203 break; |
|
204 default: |
|
205 error ("too many indices for matrix expression"); |
|
206 break; |
|
207 } |
|
208 } |
|
209 |
|
210 void |
|
211 tree_constant_rep::do_matrix_assignment (tree_constant& rhs, |
|
212 tree_constant& i_arg) |
|
213 { |
|
214 int nr = rows (); |
|
215 int nc = columns (); |
|
216 |
|
217 if (user_pref.do_fortran_indexing) |
|
218 fortran_style_matrix_assignment (rhs, i_arg); |
|
219 else if (nr <= 1 || nc <= 1) |
|
220 vector_assignment (rhs, i_arg); |
|
221 else |
|
222 error ("single index only valid for row or column vector"); |
|
223 } |
|
224 |
|
225 void |
|
226 tree_constant_rep::fortran_style_matrix_assignment (tree_constant& rhs, |
|
227 tree_constant& i_arg) |
|
228 { |
|
229 tree_constant tmp_i = i_arg.make_numeric_or_magic (); |
|
230 |
|
231 tree_constant_rep::constant_type itype = tmp_i.const_type (); |
|
232 |
|
233 int nr = rows (); |
|
234 int nc = columns (); |
|
235 |
|
236 int rhs_nr = rhs.rows (); |
|
237 int rhs_nc = rhs.columns (); |
|
238 |
|
239 switch (itype) |
|
240 { |
|
241 case complex_scalar_constant: |
|
242 case scalar_constant: |
|
243 { |
|
244 int i = NINT (tmp_i.double_value ()); |
143
|
245 if (index_check (i-1, "") < 0) |
|
246 return; |
1
|
247 if (nr <= 1 || nc <= 1) |
|
248 maybe_resize (i-1); |
143
|
249 else if (range_max_check (i-1, nr * nc) < 0) |
|
250 return; |
1
|
251 |
|
252 nr = rows (); |
|
253 nc = columns (); |
|
254 |
|
255 if (! indexed_assign_conforms (1, 1, rhs_nr, rhs_nc)) |
|
256 { |
|
257 error ("for A(int) = X: X must be a scalar"); |
143
|
258 return; |
1
|
259 } |
|
260 int ii = fortran_row (i, nr) - 1; |
|
261 int jj = fortran_column (i, nr) - 1; |
|
262 do_matrix_assignment (rhs, ii, jj); |
|
263 } |
|
264 break; |
|
265 case complex_matrix_constant: |
|
266 case matrix_constant: |
|
267 { |
|
268 Matrix mi = tmp_i.matrix_value (); |
|
269 int len = nr * nc; |
|
270 idx_vector ii (mi, 1, "", len); // Always do fortran indexing here... |
|
271 int imax = ii.max (); |
|
272 |
|
273 if (nr <= 1 || nc <= 1) |
|
274 maybe_resize (imax-1); |
143
|
275 else if (range_max_check (imax-1, len) < 0) |
|
276 return; |
1
|
277 |
|
278 if (ii.capacity () != rhs_nr * rhs_nc) |
|
279 { |
|
280 error ("A(matrix) = X: X and matrix must have the same\ |
|
281 number of elements"); |
143
|
282 return; |
1
|
283 } |
|
284 fortran_style_matrix_assignment (rhs, ii); |
|
285 } |
|
286 break; |
|
287 case string_constant: |
|
288 gripe_string_invalid (); |
|
289 break; |
|
290 case range_constant: |
|
291 gripe_range_invalid (); |
|
292 break; |
|
293 case magic_colon: |
|
294 fortran_style_matrix_assignment (rhs, magic_colon); |
|
295 break; |
|
296 default: |
|
297 panic_impossible (); |
|
298 break; |
|
299 } |
|
300 } |
|
301 |
|
302 void |
|
303 tree_constant_rep::vector_assignment (tree_constant& rhs, tree_constant& i_arg) |
|
304 { |
|
305 int nr = rows (); |
|
306 int nc = columns (); |
|
307 |
|
308 assert ((nr == 1 || nc == 1 || (nr == 0 && nc == 0)) |
|
309 && ! user_pref.do_fortran_indexing); |
|
310 |
|
311 tree_constant tmp_i = i_arg.make_numeric_or_range_or_magic (); |
|
312 |
|
313 tree_constant_rep::constant_type itype = tmp_i.const_type (); |
|
314 |
|
315 switch (itype) |
|
316 { |
|
317 case complex_scalar_constant: |
|
318 case scalar_constant: |
|
319 { |
|
320 int i = tree_to_mat_idx (tmp_i.double_value ()); |
143
|
321 if (index_check (i, "") < 0) |
|
322 return; |
1
|
323 do_vector_assign (rhs, i); |
|
324 } |
|
325 break; |
|
326 case complex_matrix_constant: |
|
327 case matrix_constant: |
|
328 { |
|
329 Matrix mi = tmp_i.matrix_value (); |
|
330 int len = nr * nc; |
|
331 idx_vector iv (mi, user_pref.do_fortran_indexing, "", len); |
|
332 do_vector_assign (rhs, iv); |
|
333 } |
|
334 break; |
|
335 case string_constant: |
|
336 gripe_string_invalid (); |
|
337 break; |
|
338 case range_constant: |
|
339 { |
|
340 Range ri = tmp_i.range_value (); |
|
341 if (rows () == 2 && is_zero_one (ri)) |
|
342 { |
|
343 do_vector_assign (rhs, 1); |
|
344 } |
|
345 else |
|
346 { |
|
347 int imax; |
143
|
348 if (index_check (ri, imax, "") < 0) |
|
349 return; |
1
|
350 do_vector_assign (rhs, ri, imax); |
|
351 } |
|
352 } |
|
353 break; |
|
354 case magic_colon: |
|
355 { |
|
356 int rhs_nr = rhs.rows (); |
|
357 int rhs_nc = rhs.columns (); |
|
358 |
|
359 if (! indexed_assign_conforms (nr, nc, rhs_nr, rhs_nc)) |
|
360 { |
|
361 error ("A(:) = X: X and A must have the same dimensions"); |
143
|
362 return; |
1
|
363 } |
|
364 do_matrix_assignment (rhs, magic_colon, magic_colon); |
|
365 } |
|
366 break; |
|
367 default: |
|
368 panic_impossible (); |
|
369 break; |
|
370 } |
|
371 } |
|
372 |
|
373 void |
|
374 tree_constant_rep::check_vector_assign (int rhs_nr, int rhs_nc, |
|
375 int ilen, char *rm) |
|
376 { |
|
377 int nr = rows (); |
|
378 int nc = columns (); |
|
379 |
|
380 if (nr == 1 && nc == 1) // No orientation to preserve |
|
381 { |
|
382 if (! ( ilen == rhs_nr || ilen == rhs_nc)) |
143
|
383 error ("A(%s) = X: X and %s must have the same number of\ |
1
|
384 elements", rm, rm); |
|
385 } |
|
386 else if (nr == 1) // Preserve current row orientation |
|
387 { |
|
388 if (! (rhs_nr == 1 && rhs_nc == ilen)) |
143
|
389 error ("A(%s) = X: where A is a row vector, X must also be a\ |
1
|
390 row vector with the same number of elements as %s", rm, rm); |
|
391 } |
|
392 else if (nc == 1) // Preserve current column orientation |
|
393 { |
|
394 if (! (rhs_nc == 1 && rhs_nr == ilen)) |
143
|
395 error ("A(%s) = X: where A is a column vector, X must also\ |
1
|
396 be a column vector with the same number of elements as %s", rm, rm); |
|
397 } |
|
398 else |
|
399 panic_impossible (); |
|
400 } |
|
401 |
|
402 void |
|
403 tree_constant_rep::do_vector_assign (tree_constant& rhs, int i) |
|
404 { |
|
405 int rhs_nr = rhs.rows (); |
|
406 int rhs_nc = rhs.columns (); |
|
407 |
|
408 if (! indexed_assign_conforms (1, 1, rhs_nr, rhs_nc)) |
|
409 { |
|
410 error ("for A(int) = X: X must be a scalar"); |
143
|
411 return; |
1
|
412 } |
|
413 |
|
414 maybe_resize (i); |
|
415 |
|
416 int nr = rows (); |
|
417 int nc = columns (); |
|
418 |
|
419 if (nr == 1) |
|
420 { |
|
421 REP_ELEM_ASSIGN (0, i, rhs.double_value (), rhs.complex_value (), |
|
422 rhs.is_real_type ()); |
|
423 } |
|
424 else if (nc == 1) |
|
425 { |
|
426 REP_ELEM_ASSIGN (i, 0, rhs.double_value (), rhs.complex_value (), |
|
427 rhs.is_real_type ()); |
|
428 } |
|
429 else |
|
430 panic_impossible (); |
|
431 } |
|
432 |
|
433 void |
|
434 tree_constant_rep::do_vector_assign (tree_constant& rhs, idx_vector& iv) |
|
435 { |
|
436 REP_RHS_MATRIX (rhs, rhs_m, rhs_cm, rhs_nr, rhs_nc); |
|
437 |
|
438 int ilen = iv.capacity (); |
|
439 check_vector_assign (rhs_nr, rhs_nc, ilen, "matrix"); |
|
440 |
|
441 force_orient f_orient = no_orient; |
|
442 if (rhs_nr == 1 && rhs_nc != 1) |
|
443 f_orient = row_orient; |
|
444 else if (rhs_nc == 1 && rhs_nr != 1) |
|
445 f_orient = column_orient; |
|
446 |
|
447 maybe_resize (iv.max (), f_orient); |
|
448 |
|
449 int nr = rows (); |
|
450 int nc = columns (); |
|
451 |
|
452 if (nr == 1) |
|
453 { |
|
454 for (int i = 0; i < iv.capacity (); i++) |
|
455 REP_ELEM_ASSIGN (0, iv.elem (i), rhs_m.elem (0, i), |
|
456 rhs_cm.elem (0, i), rhs.is_real_type ()); |
|
457 } |
|
458 else if (nc == 1) |
|
459 { |
|
460 for (int i = 0; i < iv.capacity (); i++) |
|
461 REP_ELEM_ASSIGN (iv.elem (i), 0, rhs_m.elem (i, 0), |
|
462 rhs_cm.elem (i, 0), rhs.is_real_type ()); |
|
463 } |
|
464 else |
|
465 panic_impossible (); |
|
466 } |
|
467 |
|
468 void |
|
469 tree_constant_rep::do_vector_assign (tree_constant& rhs, Range& ri, int imax) |
|
470 { |
|
471 REP_RHS_MATRIX (rhs, rhs_m, rhs_cm, rhs_nr, rhs_nc); |
|
472 |
|
473 int ilen = ri.nelem (); |
|
474 check_vector_assign (rhs_nr, rhs_nc, ilen, "range"); |
|
475 |
|
476 force_orient f_orient = no_orient; |
|
477 if (rhs_nr == 1 && rhs_nc != 1) |
|
478 f_orient = row_orient; |
|
479 else if (rhs_nc == 1 && rhs_nr != 1) |
|
480 f_orient = column_orient; |
|
481 |
|
482 maybe_resize (imax, f_orient); |
|
483 |
|
484 int nr = rows (); |
|
485 int nc = columns (); |
|
486 |
|
487 double b = ri.base (); |
|
488 double increment = ri.inc (); |
|
489 |
|
490 if (nr == 1) |
|
491 { |
|
492 for (int i = 0; i < ri.nelem (); i++) |
|
493 { |
|
494 double tmp = b + i * increment; |
|
495 int col = tree_to_mat_idx (tmp); |
|
496 REP_ELEM_ASSIGN (0, col, rhs_m.elem (0, i), rhs_cm.elem (0, i), |
|
497 rhs.is_real_type ()); |
|
498 } |
|
499 } |
|
500 else if (nc == 1) |
|
501 { |
|
502 for (int i = 0; i < ri.nelem (); i++) |
|
503 { |
|
504 double tmp = b + i * increment; |
|
505 int row = tree_to_mat_idx (tmp); |
|
506 REP_ELEM_ASSIGN (row, 0, rhs_m.elem (i, 0), rhs_cm.elem (i, 0), |
|
507 rhs.is_real_type ()); |
|
508 } |
|
509 } |
|
510 else |
|
511 panic_impossible (); |
|
512 } |
|
513 |
|
514 void |
|
515 tree_constant_rep::fortran_style_matrix_assignment |
|
516 (tree_constant& rhs, tree_constant_rep::constant_type mci) |
|
517 { |
|
518 assert (rhs.is_matrix_type ()); |
|
519 assert (mci == tree_constant_rep::magic_colon); |
|
520 |
|
521 int nr = rows (); |
|
522 int nc = columns (); |
|
523 |
|
524 REP_RHS_MATRIX (rhs, rhs_m, rhs_cm, rhs_nr, rhs_nc); |
|
525 |
|
526 int rhs_size = rhs_nr * rhs_nc; |
|
527 if (rhs_size == 0) |
|
528 { |
|
529 if (rhs.const_type () == matrix_constant) |
|
530 { |
|
531 delete matrix; |
|
532 matrix = new Matrix (0, 0); |
|
533 return; |
|
534 } |
|
535 else |
|
536 panic_impossible (); |
|
537 } |
|
538 else if (nr*nc != rhs_size) |
|
539 { |
|
540 error ("A(:) = X: X and A must have the same number of elements"); |
143
|
541 return; |
1
|
542 } |
|
543 |
|
544 if (rhs.const_type () == matrix_constant) |
|
545 { |
|
546 double *cop_out = rhs_m.fortran_vec (); |
|
547 for (int j = 0; j < nc; j++) |
|
548 for (int i = 0; i < nr; i++) |
|
549 matrix->elem (i, j) = *cop_out++; |
|
550 } |
|
551 else |
|
552 { |
|
553 Complex *cop_out = rhs_cm.fortran_vec (); |
|
554 for (int j = 0; j < nc; j++) |
|
555 for (int i = 0; i < nr; i++) |
|
556 complex_matrix->elem (i, j) = *cop_out++; |
|
557 } |
|
558 } |
|
559 |
|
560 void |
|
561 tree_constant_rep::fortran_style_matrix_assignment (tree_constant& rhs, |
|
562 idx_vector& i) |
|
563 { |
|
564 assert (rhs.is_matrix_type ()); |
|
565 |
|
566 int ilen = i.capacity (); |
|
567 |
|
568 REP_RHS_MATRIX (rhs, rhs_m, rhs_cm, rhs_nr, rhs_nc); |
|
569 |
|
570 int len = rhs_nr * rhs_nc; |
|
571 |
|
572 if (len == ilen) |
|
573 { |
|
574 int nr = rows (); |
|
575 if (rhs.const_type () == matrix_constant) |
|
576 { |
|
577 double *cop_out = rhs_m.fortran_vec (); |
|
578 for (int k = 0; k < len; k++) |
|
579 { |
|
580 int ii = fortran_row (i.elem (k) + 1, nr) - 1; |
|
581 int jj = fortran_column (i.elem (k) + 1, nr) - 1; |
|
582 |
|
583 matrix->elem (ii, jj) = *cop_out++; |
|
584 } |
|
585 } |
|
586 else |
|
587 { |
|
588 Complex *cop_out = rhs_cm.fortran_vec (); |
|
589 for (int k = 0; k < len; k++) |
|
590 { |
|
591 int ii = fortran_row (i.elem (k) + 1, nr) - 1; |
|
592 int jj = fortran_column (i.elem (k) + 1, nr) - 1; |
|
593 |
|
594 complex_matrix->elem (ii, jj) = *cop_out++; |
|
595 } |
|
596 } |
|
597 } |
|
598 else |
143
|
599 error ("number of rows and columns must match for indexed assignment"); |
1
|
600 } |
|
601 |
|
602 void |
|
603 tree_constant_rep::do_matrix_assignment (tree_constant& rhs, |
|
604 tree_constant& i_arg, |
|
605 tree_constant& j_arg) |
|
606 { |
|
607 tree_constant tmp_i = i_arg.make_numeric_or_range_or_magic (); |
|
608 |
|
609 tree_constant_rep::constant_type itype = tmp_i.const_type (); |
|
610 |
|
611 switch (itype) |
|
612 { |
|
613 case complex_scalar_constant: |
|
614 case scalar_constant: |
|
615 { |
|
616 int i = tree_to_mat_idx (tmp_i.double_value ()); |
143
|
617 if (index_check (i, "row") < 0) |
|
618 return; |
1
|
619 do_matrix_assignment (rhs, i, j_arg); |
|
620 } |
|
621 break; |
|
622 case complex_matrix_constant: |
|
623 case matrix_constant: |
|
624 { |
|
625 Matrix mi = tmp_i.matrix_value (); |
|
626 idx_vector iv (mi, user_pref.do_fortran_indexing, "row", rows ()); |
|
627 do_matrix_assignment (rhs, iv, j_arg); |
|
628 } |
|
629 break; |
|
630 case string_constant: |
|
631 gripe_string_invalid (); |
|
632 break; |
|
633 case range_constant: |
|
634 { |
|
635 Range ri = tmp_i.range_value (); |
|
636 if (rows () == 2 && is_zero_one (ri)) |
|
637 { |
|
638 do_matrix_assignment (rhs, 1, j_arg); |
|
639 } |
|
640 else |
|
641 { |
|
642 int imax; |
143
|
643 if (index_check (ri, imax, "row") < 0) |
|
644 return; |
1
|
645 do_matrix_assignment (rhs, ri, imax, j_arg); |
|
646 } |
|
647 } |
|
648 break; |
|
649 case magic_colon: |
|
650 do_matrix_assignment (rhs, magic_colon, j_arg); |
|
651 break; |
|
652 default: |
|
653 panic_impossible (); |
|
654 break; |
|
655 } |
|
656 } |
|
657 |
|
658 void |
|
659 tree_constant_rep::do_matrix_assignment (tree_constant& rhs, int i, |
|
660 tree_constant& j_arg) |
|
661 { |
|
662 tree_constant tmp_j = j_arg.make_numeric_or_range_or_magic (); |
|
663 |
|
664 tree_constant_rep::constant_type jtype = tmp_j.const_type (); |
|
665 |
|
666 int rhs_nr = rhs.rows (); |
|
667 int rhs_nc = rhs.columns (); |
|
668 |
|
669 switch (jtype) |
|
670 { |
|
671 case complex_scalar_constant: |
|
672 case scalar_constant: |
|
673 { |
|
674 int j = tree_to_mat_idx (tmp_j.double_value ()); |
143
|
675 if (index_check (j, "column") < 0) |
|
676 return; |
1
|
677 if (! indexed_assign_conforms (1, 1, rhs_nr, rhs_nc)) |
|
678 { |
|
679 error ("A(int,int) = X, X must be a scalar"); |
143
|
680 return; |
1
|
681 } |
|
682 maybe_resize (i, j); |
|
683 do_matrix_assignment (rhs, i, j); |
|
684 } |
|
685 break; |
|
686 case complex_matrix_constant: |
|
687 case matrix_constant: |
|
688 { |
|
689 Matrix mj = tmp_j.matrix_value (); |
|
690 idx_vector jv (mj, user_pref.do_fortran_indexing, "column", |
|
691 columns ()); |
|
692 if (! indexed_assign_conforms (1, jv.capacity (), rhs_nr, rhs_nc)) |
|
693 { |
|
694 error ("A(int,matrix) = X: X must be a row vector with the\ |
|
695 same number of elements as matrix"); |
143
|
696 return; |
1
|
697 } |
|
698 maybe_resize (i, jv.max ()); |
|
699 do_matrix_assignment (rhs, i, jv); |
|
700 } |
|
701 break; |
|
702 case string_constant: |
|
703 gripe_string_invalid (); |
|
704 break; |
|
705 case range_constant: |
|
706 { |
|
707 Range rj = tmp_j.range_value (); |
|
708 if (! indexed_assign_conforms (1, rj.nelem (), rhs_nr, rhs_nc)) |
|
709 { |
|
710 error ("A(int,range) = X: X must be a row vector with the\ |
|
711 same number of elements as range"); |
143
|
712 return; |
1
|
713 } |
|
714 if (columns () == 2 && is_zero_one (rj) && rhs_nc == 1) |
|
715 { |
|
716 do_matrix_assignment (rhs, i, 1); |
|
717 } |
|
718 else |
|
719 { |
|
720 int jmax; |
143
|
721 if (index_check (rj, jmax, "column") < 0) |
|
722 return; |
1
|
723 maybe_resize (i, jmax); |
|
724 do_matrix_assignment (rhs, i, rj); |
|
725 } |
|
726 } |
|
727 break; |
|
728 case magic_colon: |
|
729 { |
|
730 int nc = columns (); |
|
731 if (nc == 0 && rows () == 0 && rhs_nr == 1) |
|
732 { |
|
733 if (rhs.is_complex_type ()) |
|
734 { |
|
735 complex_matrix = new ComplexMatrix (); |
|
736 type_tag = complex_matrix_constant; |
|
737 } |
|
738 else |
|
739 { |
|
740 matrix = new Matrix (); |
|
741 type_tag = matrix_constant; |
|
742 } |
|
743 maybe_resize (i, rhs_nc-1); |
|
744 } |
|
745 else if (indexed_assign_conforms (1, nc, rhs_nr, rhs_nc)) |
|
746 maybe_resize (i, nc-1); |
|
747 else |
|
748 { |
|
749 error ("A(int,:) = X: X must be a row vector with the\ |
|
750 same number of columns as A"); |
143
|
751 return; |
1
|
752 } |
|
753 |
|
754 do_matrix_assignment (rhs, i, magic_colon); |
|
755 } |
|
756 break; |
|
757 default: |
|
758 panic_impossible (); |
|
759 break; |
|
760 } |
|
761 } |
|
762 |
|
763 void |
|
764 tree_constant_rep::do_matrix_assignment (tree_constant& rhs, idx_vector& iv, |
|
765 tree_constant& j_arg) |
|
766 { |
|
767 tree_constant tmp_j = j_arg.make_numeric_or_range_or_magic (); |
|
768 |
|
769 tree_constant_rep::constant_type jtype = tmp_j.const_type (); |
|
770 |
|
771 int rhs_nr = rhs.rows (); |
|
772 int rhs_nc = rhs.columns (); |
|
773 |
|
774 switch (jtype) |
|
775 { |
|
776 case complex_scalar_constant: |
|
777 case scalar_constant: |
|
778 { |
|
779 int j = tree_to_mat_idx (tmp_j.double_value ()); |
143
|
780 if (index_check (j, "column") < 0) |
|
781 return; |
1
|
782 if (! indexed_assign_conforms (iv.capacity (), 1, rhs_nr, rhs_nc)) |
|
783 { |
|
784 error ("A(matrix,int) = X: X must be a column vector with\ |
|
785 the same number of elements as matrix"); |
143
|
786 return; |
1
|
787 } |
|
788 maybe_resize (iv.max (), j); |
|
789 do_matrix_assignment (rhs, iv, j); |
|
790 } |
|
791 break; |
|
792 case complex_matrix_constant: |
|
793 case matrix_constant: |
|
794 { |
|
795 Matrix mj = tmp_j.matrix_value (); |
|
796 idx_vector jv (mj, user_pref.do_fortran_indexing, "column", |
|
797 columns ()); |
|
798 if (! indexed_assign_conforms (iv.capacity (), jv.capacity (), |
|
799 rhs_nr, rhs_nc)) |
|
800 { |
|
801 error ("A(r_matrix,c_matrix) = X: the number of rows in X\ |
|
802 must match the number of elements in r_matrix and the number of\ |
|
803 columns in X must match the number of elements in c_matrix"); |
143
|
804 return; |
1
|
805 } |
|
806 maybe_resize (iv.max (), jv.max ()); |
|
807 do_matrix_assignment (rhs, iv, jv); |
|
808 } |
|
809 break; |
|
810 case string_constant: |
|
811 gripe_string_invalid (); |
|
812 break; |
|
813 case range_constant: |
|
814 { |
|
815 Range rj = tmp_j.range_value (); |
|
816 if (! indexed_assign_conforms (iv.capacity (), rj.nelem (), |
|
817 rhs_nr, rhs_nc)) |
|
818 { |
|
819 error ("A(matrix,range) = X: the number of rows in X must\ |
|
820 match the number of elements in matrix and the number of columns in X\ |
|
821 must match the number of elements in range"); |
143
|
822 return; |
1
|
823 } |
|
824 if (columns () == 2 && is_zero_one (rj) && rhs_nc == 1) |
|
825 { |
|
826 do_matrix_assignment (rhs, iv, 1); |
|
827 } |
|
828 else |
|
829 { |
|
830 int jmax; |
143
|
831 if (index_check (rj, jmax, "column") < 0) |
|
832 return; |
1
|
833 maybe_resize (iv.max (), jmax); |
|
834 do_matrix_assignment (rhs, iv, rj); |
|
835 } |
|
836 } |
|
837 break; |
|
838 case magic_colon: |
|
839 { |
|
840 int nc = columns (); |
|
841 if (! indexed_assign_conforms (iv.capacity (), nc, rhs_nr, rhs_nc)) |
|
842 { |
|
843 error ("A(matrix,:) = X: the number of rows in X must\ |
|
844 match the number of elements in matrix, and the number of columns in\ |
|
845 X must match the number of columns in A"); |
143
|
846 return; |
1
|
847 } |
|
848 maybe_resize (iv.max (), nc-1); |
|
849 do_matrix_assignment (rhs, iv, magic_colon); |
|
850 } |
|
851 break; |
|
852 default: |
|
853 panic_impossible (); |
|
854 break; |
|
855 } |
|
856 } |
|
857 |
|
858 void |
|
859 tree_constant_rep::do_matrix_assignment (tree_constant& rhs, |
|
860 Range& ri, int imax, |
|
861 tree_constant& j_arg) |
|
862 { |
|
863 tree_constant tmp_j = j_arg.make_numeric_or_range_or_magic (); |
|
864 |
|
865 tree_constant_rep::constant_type jtype = tmp_j.const_type (); |
|
866 |
|
867 int rhs_nr = rhs.rows (); |
|
868 int rhs_nc = rhs.columns (); |
|
869 |
|
870 switch (jtype) |
|
871 { |
|
872 case complex_scalar_constant: |
|
873 case scalar_constant: |
|
874 { |
|
875 int j = tree_to_mat_idx (tmp_j.double_value ()); |
143
|
876 if (index_check (j, "column") < 0) |
|
877 return; |
1
|
878 if (! indexed_assign_conforms (ri.nelem (), 1, rhs_nr, rhs_nc)) |
|
879 { |
|
880 error ("A(range,int) = X: X must be a column vector with\ |
|
881 the same number of elements as range"); |
143
|
882 return; |
1
|
883 } |
|
884 maybe_resize (imax, j); |
|
885 do_matrix_assignment (rhs, ri, j); |
|
886 } |
|
887 break; |
|
888 case complex_matrix_constant: |
|
889 case matrix_constant: |
|
890 { |
|
891 Matrix mj = tmp_j.matrix_value (); |
|
892 idx_vector jv (mj, user_pref.do_fortran_indexing, "column", |
|
893 columns ()); |
|
894 if (! indexed_assign_conforms (ri.nelem (), jv.capacity (), |
|
895 rhs_nr, rhs_nc)) |
|
896 { |
|
897 error ("A(range,matrix) = X: the number of rows in X must\ |
|
898 match the number of elements in range and the number of columns in X\ |
|
899 must match the number of elements in matrix"); |
143
|
900 return; |
1
|
901 } |
|
902 maybe_resize (imax, jv.max ()); |
|
903 do_matrix_assignment (rhs, ri, jv); |
|
904 } |
|
905 break; |
|
906 case string_constant: |
|
907 gripe_string_invalid (); |
|
908 break; |
|
909 case range_constant: |
|
910 { |
|
911 Range rj = tmp_j.range_value (); |
|
912 if (! indexed_assign_conforms (ri.nelem (), rj.nelem (), |
|
913 rhs_nr, rhs_nc)) |
|
914 { |
|
915 error ("A(r_range,c_range) = X: the number of rows in X\ |
|
916 must match the number of elements in r_range and the number of\ |
|
917 columns in X must match the number of elements in c_range\n"); |
143
|
918 return; |
1
|
919 } |
|
920 if (columns () == 2 && is_zero_one (rj) && rhs_nc == 1) |
|
921 { |
|
922 do_matrix_assignment (rhs, ri, 1); |
|
923 } |
|
924 else |
|
925 { |
|
926 int jmax; |
143
|
927 if (index_check (rj, jmax, "column") < 0) |
|
928 return; |
1
|
929 maybe_resize (imax, jmax); |
|
930 do_matrix_assignment (rhs, ri, rj); |
|
931 } |
|
932 } |
|
933 break; |
|
934 case magic_colon: |
|
935 { |
|
936 int nc = columns (); |
|
937 if (! indexed_assign_conforms (ri.nelem (), nc, rhs_nr, rhs_nc)) |
|
938 { |
|
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\ |
|
941 match the number of columns in A"); |
143
|
942 return; |
1
|
943 } |
|
944 maybe_resize (imax, nc-1); |
|
945 do_matrix_assignment (rhs, ri, magic_colon); |
|
946 } |
|
947 break; |
|
948 default: |
|
949 panic_impossible (); |
|
950 break; |
|
951 } |
|
952 } |
|
953 |
|
954 void |
|
955 tree_constant_rep::do_matrix_assignment (tree_constant& rhs, |
|
956 tree_constant_rep::constant_type i, |
|
957 tree_constant& j_arg) |
|
958 { |
|
959 tree_constant tmp_j = j_arg.make_numeric_or_range_or_magic (); |
|
960 |
|
961 tree_constant_rep::constant_type jtype = tmp_j.const_type (); |
|
962 |
|
963 int rhs_nr = rhs.rows (); |
|
964 int rhs_nc = rhs.columns (); |
|
965 |
|
966 switch (jtype) |
|
967 { |
|
968 case complex_scalar_constant: |
|
969 case scalar_constant: |
|
970 { |
|
971 int j = tree_to_mat_idx (tmp_j.double_value ()); |
143
|
972 if (index_check (j, "column") < 0) |
|
973 return; |
1
|
974 int nr = rows (); |
|
975 if (nr == 0 && columns () == 0 && rhs_nc == 1) |
|
976 { |
|
977 if (rhs.is_complex_type ()) |
|
978 { |
|
979 complex_matrix = new ComplexMatrix (); |
|
980 type_tag = complex_matrix_constant; |
|
981 } |
|
982 else |
|
983 { |
|
984 matrix = new Matrix (); |
|
985 type_tag = matrix_constant; |
|
986 } |
|
987 maybe_resize (rhs_nr-1, j); |
|
988 } |
|
989 else if (indexed_assign_conforms (nr, 1, rhs_nr, rhs_nc)) |
|
990 maybe_resize (nr-1, j); |
|
991 else |
|
992 { |
|
993 error ("A(:,int) = X: X must be a column vector with the\ |
|
994 same number of rows as A"); |
143
|
995 return; |
1
|
996 } |
|
997 |
|
998 do_matrix_assignment (rhs, magic_colon, j); |
|
999 } |
|
1000 break; |
|
1001 case complex_matrix_constant: |
|
1002 case matrix_constant: |
|
1003 { |
|
1004 Matrix mj = tmp_j.matrix_value (); |
|
1005 idx_vector jv (mj, user_pref.do_fortran_indexing, "column", |
|
1006 columns ()); |
|
1007 int nr = rows (); |
|
1008 if (! indexed_assign_conforms (nr, jv.capacity (), rhs_nr, rhs_nc)) |
|
1009 { |
|
1010 error ("A(:,matrix) = X: the number of rows in X must\ |
|
1011 match the number of rows in A, and the number of columns in X must\ |
|
1012 match the number of elements in matrix"); |
143
|
1013 return; |
1
|
1014 } |
|
1015 maybe_resize (nr-1, jv.max ()); |
|
1016 do_matrix_assignment (rhs, magic_colon, jv); |
|
1017 } |
|
1018 break; |
|
1019 case string_constant: |
|
1020 gripe_string_invalid (); |
|
1021 break; |
|
1022 case range_constant: |
|
1023 { |
|
1024 Range rj = tmp_j.range_value (); |
|
1025 int nr = rows (); |
|
1026 if (! indexed_assign_conforms (nr, rj.nelem (), rhs_nr, rhs_nc)) |
|
1027 { |
|
1028 error ("A(:,range) = X: the number of rows in X must match\ |
|
1029 the number of rows in A, and the number of columns in X must match\ |
|
1030 the number of elements in range"); |
143
|
1031 return; |
1
|
1032 } |
|
1033 if (columns () == 2 && is_zero_one (rj) && rhs_nc == 1) |
|
1034 { |
|
1035 do_matrix_assignment (rhs, magic_colon, 1); |
|
1036 } |
|
1037 else |
|
1038 { |
|
1039 int jmax; |
143
|
1040 if (index_check (rj, jmax, "column") < 0) |
|
1041 return; |
1
|
1042 maybe_resize (nr-1, jmax); |
|
1043 do_matrix_assignment (rhs, magic_colon, rj); |
|
1044 } |
|
1045 } |
|
1046 break; |
|
1047 case magic_colon: |
|
1048 // a(:,:) = foo is equivalent to a = foo. |
|
1049 do_matrix_assignment (rhs, magic_colon, magic_colon); |
|
1050 break; |
|
1051 default: |
|
1052 panic_impossible (); |
|
1053 break; |
|
1054 } |
|
1055 } |
|
1056 |
|
1057 void |
|
1058 tree_constant_rep::do_matrix_assignment (tree_constant& rhs, int i, int j) |
|
1059 { |
|
1060 REP_ELEM_ASSIGN (i, j, rhs.double_value (), rhs.complex_value (), |
|
1061 rhs.is_real_type ()); |
|
1062 } |
|
1063 |
|
1064 void |
|
1065 tree_constant_rep::do_matrix_assignment (tree_constant& rhs, int i, |
|
1066 idx_vector& jv) |
|
1067 { |
|
1068 REP_RHS_MATRIX (rhs, rhs_m, rhs_cm, rhs_nr, rhs_nc); |
|
1069 for (int j = 0; j < jv.capacity (); j++) |
|
1070 REP_ELEM_ASSIGN (i, jv.elem (j), rhs_m.elem (0, j), |
|
1071 rhs_cm.elem (0, j), rhs.is_real_type ()); |
|
1072 } |
|
1073 |
|
1074 void |
|
1075 tree_constant_rep::do_matrix_assignment (tree_constant& rhs, int i, Range& rj) |
|
1076 { |
|
1077 REP_RHS_MATRIX (rhs, rhs_m, rhs_cm, rhs_nr, rhs_nc); |
|
1078 |
|
1079 double b = rj.base (); |
|
1080 double increment = rj.inc (); |
|
1081 |
|
1082 for (int j = 0; j < rj.nelem (); j++) |
|
1083 { |
|
1084 double tmp = b + j * increment; |
|
1085 int col = tree_to_mat_idx (tmp); |
|
1086 REP_ELEM_ASSIGN (i, col, rhs_m.elem (0, j), rhs_cm.elem (0, j), |
|
1087 rhs.is_real_type ()); |
|
1088 } |
|
1089 } |
|
1090 |
|
1091 void |
|
1092 tree_constant_rep::do_matrix_assignment (tree_constant& rhs, int i, |
|
1093 tree_constant_rep::constant_type mcj) |
|
1094 { |
|
1095 assert (mcj == magic_colon); |
|
1096 |
|
1097 int nc = columns (); |
|
1098 |
|
1099 if (rhs.is_matrix_type ()) |
|
1100 { |
|
1101 REP_RHS_MATRIX (rhs, rhs_m, rhs_cm, rhs_nr, rhs_nc); |
|
1102 |
|
1103 for (int j = 0; j < nc; j++) |
|
1104 REP_ELEM_ASSIGN (i, j, rhs_m.elem (0, j), rhs_cm.elem (0, j), |
|
1105 rhs.is_real_type ()); |
|
1106 } |
|
1107 else if (rhs.const_type () == scalar_constant && nc == 1) |
|
1108 { |
|
1109 REP_ELEM_ASSIGN (i, 0, rhs.double_value (), |
|
1110 rhs.complex_value (), rhs.is_real_type ()); |
|
1111 } |
|
1112 else |
|
1113 panic_impossible (); |
|
1114 } |
|
1115 |
|
1116 void |
|
1117 tree_constant_rep::do_matrix_assignment (tree_constant& rhs, |
|
1118 idx_vector& iv, int j) |
|
1119 { |
|
1120 REP_RHS_MATRIX (rhs, rhs_m, rhs_cm, rhs_nr, rhs_nc); |
|
1121 |
|
1122 for (int i = 0; i < iv.capacity (); i++) |
|
1123 { |
|
1124 int row = iv.elem (i); |
|
1125 REP_ELEM_ASSIGN (row, j, rhs_m.elem (i, 0), |
|
1126 rhs_cm.elem (i, 0), rhs.is_real_type ()); |
|
1127 } |
|
1128 } |
|
1129 |
|
1130 void |
|
1131 tree_constant_rep::do_matrix_assignment (tree_constant& rhs, |
|
1132 idx_vector& iv, idx_vector& jv) |
|
1133 { |
|
1134 REP_RHS_MATRIX (rhs, rhs_m, rhs_cm, rhs_nr, rhs_nc); |
|
1135 |
|
1136 for (int i = 0; i < iv.capacity (); i++) |
|
1137 { |
|
1138 int row = iv.elem (i); |
|
1139 for (int j = 0; j < jv.capacity (); j++) |
|
1140 { |
|
1141 int col = jv.elem (j); |
|
1142 REP_ELEM_ASSIGN (row, col, rhs_m.elem (i, j), |
|
1143 rhs_cm.elem (i, j), rhs.is_real_type ()); |
|
1144 } |
|
1145 } |
|
1146 } |
|
1147 |
|
1148 void |
|
1149 tree_constant_rep::do_matrix_assignment (tree_constant& rhs, |
|
1150 idx_vector& iv, Range& rj) |
|
1151 { |
|
1152 REP_RHS_MATRIX (rhs, rhs_m, rhs_cm, rhs_nr, rhs_nc); |
|
1153 |
|
1154 double b = rj.base (); |
|
1155 double increment = rj.inc (); |
|
1156 |
|
1157 for (int i = 0; i < iv.capacity (); i++) |
|
1158 { |
|
1159 int row = iv.elem (i); |
|
1160 for (int j = 0; j < rj.nelem (); j++) |
|
1161 { |
|
1162 double tmp = b + j * increment; |
|
1163 int col = tree_to_mat_idx (tmp); |
|
1164 REP_ELEM_ASSIGN (row, col, rhs_m.elem (i, j), |
|
1165 rhs_cm.elem (i, j), rhs.is_real_type ()); |
|
1166 } |
|
1167 } |
|
1168 } |
|
1169 |
|
1170 void |
|
1171 tree_constant_rep::do_matrix_assignment (tree_constant& rhs, idx_vector& iv, |
|
1172 tree_constant_rep::constant_type mcj) |
|
1173 { |
|
1174 assert (mcj == magic_colon); |
|
1175 |
|
1176 REP_RHS_MATRIX (rhs, rhs_m, rhs_cm, rhs_nr, rhs_nc); |
|
1177 |
|
1178 int nc = columns (); |
|
1179 |
|
1180 for (int j = 0; j < nc; j++) |
|
1181 { |
|
1182 for (int i = 0; i < iv.capacity (); i++) |
|
1183 { |
|
1184 int row = iv.elem (i); |
|
1185 REP_ELEM_ASSIGN (row, j, rhs_m.elem (i, j), |
|
1186 rhs_cm.elem (i, j), rhs.is_real_type ()); |
|
1187 } |
|
1188 } |
|
1189 } |
|
1190 |
|
1191 void |
|
1192 tree_constant_rep::do_matrix_assignment (tree_constant& rhs, Range& ri, int j) |
|
1193 { |
|
1194 REP_RHS_MATRIX (rhs, rhs_m, rhs_cm, rhs_nr, rhs_nc); |
|
1195 |
|
1196 double b = ri.base (); |
|
1197 double increment = ri.inc (); |
|
1198 |
|
1199 for (int i = 0; i < ri.nelem (); i++) |
|
1200 { |
|
1201 double tmp = b + i * increment; |
|
1202 int row = tree_to_mat_idx (tmp); |
|
1203 REP_ELEM_ASSIGN (row, j, rhs_m.elem (i, 0), |
|
1204 rhs_cm.elem (i, 0), rhs.is_real_type ()); |
|
1205 } |
|
1206 } |
|
1207 |
|
1208 void |
|
1209 tree_constant_rep::do_matrix_assignment (tree_constant& rhs, Range& ri, |
|
1210 idx_vector& jv) |
|
1211 { |
|
1212 REP_RHS_MATRIX (rhs, rhs_m, rhs_cm, rhs_nr, rhs_nc); |
|
1213 |
|
1214 double b = ri.base (); |
|
1215 double increment = ri.inc (); |
|
1216 |
|
1217 for (int j = 0; j < jv.capacity (); j++) |
|
1218 { |
|
1219 int col = jv.elem (j); |
|
1220 for (int i = 0; i < ri.nelem (); i++) |
|
1221 { |
|
1222 double tmp = b + i * increment; |
|
1223 int row = tree_to_mat_idx (tmp); |
|
1224 REP_ELEM_ASSIGN (row, col, rhs_m.elem (i, j), |
|
1225 rhs_m.elem (i, j), rhs.is_real_type ()); |
|
1226 } |
|
1227 } |
|
1228 } |
|
1229 |
|
1230 void |
|
1231 tree_constant_rep::do_matrix_assignment (tree_constant& rhs, Range& ri, |
|
1232 Range& rj) |
|
1233 { |
|
1234 double ib = ri.base (); |
|
1235 double iinc = ri.inc (); |
|
1236 double jb = rj.base (); |
|
1237 double jinc = rj.inc (); |
|
1238 |
|
1239 REP_RHS_MATRIX (rhs, rhs_m, rhs_cm, rhs_nr, rhs_nc); |
|
1240 |
|
1241 for (int i = 0; i < ri.nelem (); i++) |
|
1242 { |
|
1243 double itmp = ib + i * iinc; |
|
1244 int row = tree_to_mat_idx (itmp); |
|
1245 for (int j = 0; j < rj.nelem (); j++) |
|
1246 { |
|
1247 double jtmp = jb + j * jinc; |
|
1248 int col = tree_to_mat_idx (jtmp); |
|
1249 REP_ELEM_ASSIGN (row, col, rhs_m.elem (i, j), |
|
1250 rhs_cm.elem (i, j), rhs.is_real_type ()); |
|
1251 } |
|
1252 } |
|
1253 } |
|
1254 |
|
1255 void |
|
1256 tree_constant_rep::do_matrix_assignment (tree_constant& rhs, Range& ri, |
|
1257 tree_constant_rep::constant_type mcj) |
|
1258 { |
|
1259 assert (mcj == magic_colon); |
|
1260 |
|
1261 REP_RHS_MATRIX (rhs, rhs_m, rhs_cm, rhs_nr, rhs_nc); |
|
1262 |
|
1263 double ib = ri.base (); |
|
1264 double iinc = ri.inc (); |
|
1265 |
|
1266 int nc = columns (); |
|
1267 |
|
1268 for (int i = 0; i < ri.nelem (); i++) |
|
1269 { |
|
1270 double itmp = ib + i * iinc; |
|
1271 int row = tree_to_mat_idx (itmp); |
|
1272 for (int j = 0; j < nc; j++) |
|
1273 REP_ELEM_ASSIGN (row, j, rhs_m.elem (i, j), |
|
1274 rhs_cm.elem (i, j), rhs.is_real_type ()); |
|
1275 } |
|
1276 } |
|
1277 |
|
1278 void |
|
1279 tree_constant_rep::do_matrix_assignment (tree_constant& rhs, |
|
1280 tree_constant_rep::constant_type mci, |
|
1281 int j) |
|
1282 { |
|
1283 assert (mci == magic_colon); |
|
1284 |
|
1285 int nr = rows (); |
|
1286 |
|
1287 if (rhs.is_matrix_type ()) |
|
1288 { |
|
1289 REP_RHS_MATRIX (rhs, rhs_m, rhs_cm, rhs_nr, rhs_nc); |
|
1290 |
|
1291 for (int i = 0; i < nr; i++) |
|
1292 REP_ELEM_ASSIGN (i, j, rhs_m.elem (i, 0), |
|
1293 rhs_cm.elem (i, 0), rhs.is_real_type ()); |
|
1294 } |
|
1295 else if (rhs.const_type () == scalar_constant && nr == 1) |
|
1296 { |
|
1297 REP_ELEM_ASSIGN (0, j, rhs.double_value (), |
|
1298 rhs.complex_value (), rhs.is_real_type ()); |
|
1299 } |
|
1300 else |
|
1301 panic_impossible (); |
|
1302 } |
|
1303 |
|
1304 void |
|
1305 tree_constant_rep::do_matrix_assignment (tree_constant& rhs, |
|
1306 tree_constant_rep::constant_type mci, |
|
1307 idx_vector& jv) |
|
1308 { |
|
1309 assert (mci == magic_colon); |
|
1310 |
|
1311 REP_RHS_MATRIX (rhs, rhs_m, rhs_cm, rhs_nr, rhs_nc); |
|
1312 |
|
1313 int nr = rows (); |
|
1314 |
|
1315 for (int i = 0; i < nr; i++) |
|
1316 { |
|
1317 for (int j = 0; j < jv.capacity (); j++) |
|
1318 { |
|
1319 int col = jv.elem (j); |
|
1320 REP_ELEM_ASSIGN (i, col, rhs_m.elem (i, j), |
|
1321 rhs_cm.elem (i, j), rhs.is_real_type ()); |
|
1322 } |
|
1323 } |
|
1324 } |
|
1325 |
|
1326 void |
|
1327 tree_constant_rep::do_matrix_assignment (tree_constant& rhs, |
|
1328 tree_constant_rep::constant_type mci, |
|
1329 Range& rj) |
|
1330 { |
|
1331 assert (mci == magic_colon); |
|
1332 |
|
1333 REP_RHS_MATRIX (rhs, rhs_m, rhs_cm, rhs_nr, rhs_nc); |
|
1334 |
|
1335 int nr = rows (); |
|
1336 |
|
1337 double jb = rj.base (); |
|
1338 double jinc = rj.inc (); |
|
1339 |
|
1340 for (int j = 0; j < rj.nelem (); j++) |
|
1341 { |
|
1342 double jtmp = jb + j * jinc; |
|
1343 int col = tree_to_mat_idx (jtmp); |
|
1344 for (int i = 0; i < nr; i++) |
|
1345 { |
|
1346 REP_ELEM_ASSIGN (i, col, rhs_m.elem (i, j), |
|
1347 rhs_cm.elem (i, j), rhs.is_real_type ()); |
|
1348 } |
|
1349 } |
|
1350 } |
|
1351 |
|
1352 void |
|
1353 tree_constant_rep::do_matrix_assignment (tree_constant& rhs, |
|
1354 tree_constant_rep::constant_type mci, |
|
1355 tree_constant_rep::constant_type mcj) |
|
1356 { |
|
1357 assert (mci == magic_colon && mcj == magic_colon); |
|
1358 |
|
1359 switch (type_tag) |
|
1360 { |
|
1361 case scalar_constant: |
|
1362 break; |
|
1363 case matrix_constant: |
|
1364 delete matrix; |
|
1365 break; |
|
1366 case complex_scalar_constant: |
|
1367 delete complex_scalar; |
|
1368 break; |
|
1369 case complex_matrix_constant: |
|
1370 delete complex_matrix; |
|
1371 break; |
|
1372 case string_constant: |
|
1373 delete [] string; |
|
1374 break; |
|
1375 case range_constant: |
|
1376 delete range; |
|
1377 break; |
|
1378 case magic_colon: |
|
1379 default: |
|
1380 panic_impossible (); |
|
1381 break; |
|
1382 } |
|
1383 |
|
1384 type_tag = rhs.const_type (); |
|
1385 |
|
1386 switch (type_tag) |
|
1387 { |
|
1388 case scalar_constant: |
|
1389 scalar = rhs.double_value (); |
|
1390 break; |
|
1391 case matrix_constant: |
|
1392 matrix = new Matrix (rhs.matrix_value ()); |
|
1393 break; |
|
1394 case string_constant: |
|
1395 string = strsave (rhs.string_value ()); |
|
1396 break; |
|
1397 case complex_matrix_constant: |
|
1398 complex_matrix = new ComplexMatrix (rhs.complex_matrix_value ()); |
|
1399 break; |
|
1400 case complex_scalar_constant: |
|
1401 complex_scalar = new Complex (rhs.complex_value ()); |
|
1402 break; |
|
1403 case range_constant: |
|
1404 range = new Range (rhs.range_value ()); |
|
1405 break; |
|
1406 case magic_colon: |
|
1407 default: |
|
1408 panic_impossible (); |
|
1409 break; |
|
1410 } |
|
1411 } |
|
1412 |
|
1413 /* |
|
1414 ;;; Local Variables: *** |
|
1415 ;;; mode: C++ *** |
|
1416 ;;; page-delimiter: "^/\\*" *** |
|
1417 ;;; End: *** |
|
1418 */ |
|
1419 |