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 } |
150
|
714 |
1
|
715 if (columns () == 2 && is_zero_one (rj) && rhs_nc == 1) |
|
716 { |
|
717 do_matrix_assignment (rhs, i, 1); |
|
718 } |
|
719 else |
|
720 { |
|
721 int jmax; |
143
|
722 if (index_check (rj, jmax, "column") < 0) |
|
723 return; |
1
|
724 maybe_resize (i, jmax); |
|
725 do_matrix_assignment (rhs, i, rj); |
|
726 } |
|
727 } |
|
728 break; |
|
729 case magic_colon: |
|
730 { |
|
731 int nc = columns (); |
|
732 if (nc == 0 && rows () == 0 && rhs_nr == 1) |
|
733 { |
|
734 if (rhs.is_complex_type ()) |
|
735 { |
|
736 complex_matrix = new ComplexMatrix (); |
|
737 type_tag = complex_matrix_constant; |
|
738 } |
|
739 else |
|
740 { |
|
741 matrix = new Matrix (); |
|
742 type_tag = matrix_constant; |
|
743 } |
|
744 maybe_resize (i, rhs_nc-1); |
|
745 } |
|
746 else if (indexed_assign_conforms (1, nc, rhs_nr, rhs_nc)) |
|
747 maybe_resize (i, nc-1); |
|
748 else |
|
749 { |
|
750 error ("A(int,:) = X: X must be a row vector with the\ |
|
751 same number of columns as A"); |
143
|
752 return; |
1
|
753 } |
|
754 |
|
755 do_matrix_assignment (rhs, i, magic_colon); |
|
756 } |
|
757 break; |
|
758 default: |
|
759 panic_impossible (); |
|
760 break; |
|
761 } |
|
762 } |
|
763 |
|
764 void |
|
765 tree_constant_rep::do_matrix_assignment (tree_constant& rhs, idx_vector& iv, |
|
766 tree_constant& j_arg) |
|
767 { |
|
768 tree_constant tmp_j = j_arg.make_numeric_or_range_or_magic (); |
|
769 |
|
770 tree_constant_rep::constant_type jtype = tmp_j.const_type (); |
|
771 |
|
772 int rhs_nr = rhs.rows (); |
|
773 int rhs_nc = rhs.columns (); |
|
774 |
|
775 switch (jtype) |
|
776 { |
|
777 case complex_scalar_constant: |
|
778 case scalar_constant: |
|
779 { |
|
780 int j = tree_to_mat_idx (tmp_j.double_value ()); |
143
|
781 if (index_check (j, "column") < 0) |
|
782 return; |
1
|
783 if (! indexed_assign_conforms (iv.capacity (), 1, rhs_nr, rhs_nc)) |
|
784 { |
|
785 error ("A(matrix,int) = X: X must be a column vector with\ |
|
786 the same number of elements as matrix"); |
143
|
787 return; |
1
|
788 } |
|
789 maybe_resize (iv.max (), j); |
|
790 do_matrix_assignment (rhs, iv, j); |
|
791 } |
|
792 break; |
|
793 case complex_matrix_constant: |
|
794 case matrix_constant: |
|
795 { |
|
796 Matrix mj = tmp_j.matrix_value (); |
|
797 idx_vector jv (mj, user_pref.do_fortran_indexing, "column", |
|
798 columns ()); |
|
799 if (! indexed_assign_conforms (iv.capacity (), jv.capacity (), |
|
800 rhs_nr, rhs_nc)) |
|
801 { |
|
802 error ("A(r_matrix,c_matrix) = X: the number of rows in X\ |
|
803 must match the number of elements in r_matrix and the number of\ |
|
804 columns in X must match the number of elements in c_matrix"); |
143
|
805 return; |
1
|
806 } |
|
807 maybe_resize (iv.max (), jv.max ()); |
|
808 do_matrix_assignment (rhs, iv, jv); |
|
809 } |
|
810 break; |
|
811 case string_constant: |
|
812 gripe_string_invalid (); |
|
813 break; |
|
814 case range_constant: |
|
815 { |
|
816 Range rj = tmp_j.range_value (); |
|
817 if (! indexed_assign_conforms (iv.capacity (), rj.nelem (), |
|
818 rhs_nr, rhs_nc)) |
|
819 { |
|
820 error ("A(matrix,range) = X: the number of rows in X must\ |
|
821 match the number of elements in matrix and the number of columns in X\ |
|
822 must match the number of elements in range"); |
143
|
823 return; |
1
|
824 } |
150
|
825 |
1
|
826 if (columns () == 2 && is_zero_one (rj) && rhs_nc == 1) |
|
827 { |
|
828 do_matrix_assignment (rhs, iv, 1); |
|
829 } |
|
830 else |
|
831 { |
|
832 int jmax; |
143
|
833 if (index_check (rj, jmax, "column") < 0) |
|
834 return; |
1
|
835 maybe_resize (iv.max (), jmax); |
|
836 do_matrix_assignment (rhs, iv, rj); |
|
837 } |
|
838 } |
|
839 break; |
|
840 case magic_colon: |
|
841 { |
|
842 int nc = columns (); |
150
|
843 int new_nc = nc; |
|
844 if (nc == 0 || rows () == 0) |
|
845 new_nc = rhs_nc; |
|
846 |
|
847 if (! indexed_assign_conforms (iv.capacity (), new_nc, |
|
848 rhs_nr, rhs_nc)) |
1
|
849 { |
|
850 error ("A(matrix,:) = X: the number of rows in X must\ |
|
851 match the number of elements in matrix, and the number of columns in\ |
|
852 X must match the number of columns in A"); |
143
|
853 return; |
1
|
854 } |
150
|
855 maybe_resize (iv.max (), new_nc-1); |
1
|
856 do_matrix_assignment (rhs, iv, magic_colon); |
|
857 } |
|
858 break; |
|
859 default: |
|
860 panic_impossible (); |
|
861 break; |
|
862 } |
|
863 } |
|
864 |
|
865 void |
|
866 tree_constant_rep::do_matrix_assignment (tree_constant& rhs, |
|
867 Range& ri, int imax, |
|
868 tree_constant& j_arg) |
|
869 { |
|
870 tree_constant tmp_j = j_arg.make_numeric_or_range_or_magic (); |
|
871 |
|
872 tree_constant_rep::constant_type jtype = tmp_j.const_type (); |
|
873 |
|
874 int rhs_nr = rhs.rows (); |
|
875 int rhs_nc = rhs.columns (); |
|
876 |
|
877 switch (jtype) |
|
878 { |
|
879 case complex_scalar_constant: |
|
880 case scalar_constant: |
|
881 { |
|
882 int j = tree_to_mat_idx (tmp_j.double_value ()); |
143
|
883 if (index_check (j, "column") < 0) |
|
884 return; |
1
|
885 if (! indexed_assign_conforms (ri.nelem (), 1, rhs_nr, rhs_nc)) |
|
886 { |
|
887 error ("A(range,int) = X: X must be a column vector with\ |
|
888 the same number of elements as range"); |
143
|
889 return; |
1
|
890 } |
|
891 maybe_resize (imax, j); |
|
892 do_matrix_assignment (rhs, ri, j); |
|
893 } |
|
894 break; |
|
895 case complex_matrix_constant: |
|
896 case matrix_constant: |
|
897 { |
|
898 Matrix mj = tmp_j.matrix_value (); |
|
899 idx_vector jv (mj, user_pref.do_fortran_indexing, "column", |
|
900 columns ()); |
|
901 if (! indexed_assign_conforms (ri.nelem (), jv.capacity (), |
|
902 rhs_nr, rhs_nc)) |
|
903 { |
|
904 error ("A(range,matrix) = X: the number of rows in X must\ |
|
905 match the number of elements in range and the number of columns in X\ |
|
906 must match the number of elements in matrix"); |
143
|
907 return; |
1
|
908 } |
|
909 maybe_resize (imax, jv.max ()); |
|
910 do_matrix_assignment (rhs, ri, jv); |
|
911 } |
|
912 break; |
|
913 case string_constant: |
|
914 gripe_string_invalid (); |
|
915 break; |
|
916 case range_constant: |
|
917 { |
|
918 Range rj = tmp_j.range_value (); |
|
919 if (! indexed_assign_conforms (ri.nelem (), rj.nelem (), |
|
920 rhs_nr, rhs_nc)) |
|
921 { |
|
922 error ("A(r_range,c_range) = X: the number of rows in X\ |
|
923 must match the number of elements in r_range and the number of\ |
|
924 columns in X must match the number of elements in c_range\n"); |
143
|
925 return; |
1
|
926 } |
150
|
927 |
1
|
928 if (columns () == 2 && is_zero_one (rj) && rhs_nc == 1) |
|
929 { |
|
930 do_matrix_assignment (rhs, ri, 1); |
|
931 } |
|
932 else |
|
933 { |
|
934 int jmax; |
143
|
935 if (index_check (rj, jmax, "column") < 0) |
|
936 return; |
1
|
937 maybe_resize (imax, jmax); |
|
938 do_matrix_assignment (rhs, ri, rj); |
|
939 } |
|
940 } |
|
941 break; |
|
942 case magic_colon: |
|
943 { |
|
944 int nc = columns (); |
150
|
945 int new_nc = nc; |
|
946 if (nc == 0 || rows () == 0) |
|
947 new_nc = rhs_nc; |
|
948 |
|
949 if (! indexed_assign_conforms (ri.nelem (), new_nc, rhs_nr, rhs_nc)) |
1
|
950 { |
|
951 error ("A(range,:) = X: the number of rows in X must match\ |
|
952 the number of elements in range, and the number of columns in X must\ |
|
953 match the number of columns in A"); |
143
|
954 return; |
1
|
955 } |
150
|
956 maybe_resize (imax, new_nc-1); |
1
|
957 do_matrix_assignment (rhs, ri, magic_colon); |
|
958 } |
|
959 break; |
|
960 default: |
|
961 panic_impossible (); |
|
962 break; |
|
963 } |
|
964 } |
|
965 |
|
966 void |
|
967 tree_constant_rep::do_matrix_assignment (tree_constant& rhs, |
|
968 tree_constant_rep::constant_type i, |
|
969 tree_constant& j_arg) |
|
970 { |
|
971 tree_constant tmp_j = j_arg.make_numeric_or_range_or_magic (); |
|
972 |
|
973 tree_constant_rep::constant_type jtype = tmp_j.const_type (); |
|
974 |
|
975 int rhs_nr = rhs.rows (); |
|
976 int rhs_nc = rhs.columns (); |
|
977 |
|
978 switch (jtype) |
|
979 { |
|
980 case complex_scalar_constant: |
|
981 case scalar_constant: |
|
982 { |
|
983 int j = tree_to_mat_idx (tmp_j.double_value ()); |
143
|
984 if (index_check (j, "column") < 0) |
|
985 return; |
1
|
986 int nr = rows (); |
|
987 if (nr == 0 && columns () == 0 && rhs_nc == 1) |
|
988 { |
|
989 if (rhs.is_complex_type ()) |
|
990 { |
|
991 complex_matrix = new ComplexMatrix (); |
|
992 type_tag = complex_matrix_constant; |
|
993 } |
|
994 else |
|
995 { |
|
996 matrix = new Matrix (); |
|
997 type_tag = matrix_constant; |
|
998 } |
|
999 maybe_resize (rhs_nr-1, j); |
|
1000 } |
|
1001 else if (indexed_assign_conforms (nr, 1, rhs_nr, rhs_nc)) |
|
1002 maybe_resize (nr-1, j); |
|
1003 else |
|
1004 { |
|
1005 error ("A(:,int) = X: X must be a column vector with the\ |
|
1006 same number of rows as A"); |
143
|
1007 return; |
1
|
1008 } |
|
1009 |
|
1010 do_matrix_assignment (rhs, magic_colon, j); |
|
1011 } |
|
1012 break; |
|
1013 case complex_matrix_constant: |
|
1014 case matrix_constant: |
|
1015 { |
|
1016 Matrix mj = tmp_j.matrix_value (); |
|
1017 idx_vector jv (mj, user_pref.do_fortran_indexing, "column", |
|
1018 columns ()); |
|
1019 int nr = rows (); |
150
|
1020 int new_nr = nr; |
|
1021 if (nr == 0 || columns () == 0) |
|
1022 new_nr = rhs_nr; |
|
1023 |
|
1024 if (! indexed_assign_conforms (new_nr, jv.capacity (), |
|
1025 rhs_nr, rhs_nc)) |
1
|
1026 { |
|
1027 error ("A(:,matrix) = X: the number of rows in X must\ |
|
1028 match the number of rows in A, and the number of columns in X must\ |
|
1029 match the number of elements in matrix"); |
143
|
1030 return; |
1
|
1031 } |
150
|
1032 maybe_resize (new_nr-1, jv.max ()); |
1
|
1033 do_matrix_assignment (rhs, magic_colon, jv); |
|
1034 } |
|
1035 break; |
|
1036 case string_constant: |
|
1037 gripe_string_invalid (); |
|
1038 break; |
|
1039 case range_constant: |
|
1040 { |
|
1041 Range rj = tmp_j.range_value (); |
|
1042 int nr = rows (); |
150
|
1043 int new_nr = nr; |
|
1044 if (nr == 0 || columns () == 0) |
|
1045 new_nr = rhs_nr; |
|
1046 |
|
1047 if (! indexed_assign_conforms (new_nr, rj.nelem (), rhs_nr, rhs_nc)) |
1
|
1048 { |
|
1049 error ("A(:,range) = X: the number of rows in X must match\ |
|
1050 the number of rows in A, and the number of columns in X must match\ |
|
1051 the number of elements in range"); |
143
|
1052 return; |
1
|
1053 } |
150
|
1054 |
1
|
1055 if (columns () == 2 && is_zero_one (rj) && rhs_nc == 1) |
|
1056 { |
|
1057 do_matrix_assignment (rhs, magic_colon, 1); |
|
1058 } |
|
1059 else |
|
1060 { |
|
1061 int jmax; |
143
|
1062 if (index_check (rj, jmax, "column") < 0) |
|
1063 return; |
150
|
1064 maybe_resize (new_nr-1, jmax); |
1
|
1065 do_matrix_assignment (rhs, magic_colon, rj); |
|
1066 } |
|
1067 } |
|
1068 break; |
|
1069 case magic_colon: |
|
1070 // a(:,:) = foo is equivalent to a = foo. |
|
1071 do_matrix_assignment (rhs, magic_colon, magic_colon); |
|
1072 break; |
|
1073 default: |
|
1074 panic_impossible (); |
|
1075 break; |
|
1076 } |
|
1077 } |
|
1078 |
|
1079 void |
|
1080 tree_constant_rep::do_matrix_assignment (tree_constant& rhs, int i, int j) |
|
1081 { |
|
1082 REP_ELEM_ASSIGN (i, j, rhs.double_value (), rhs.complex_value (), |
|
1083 rhs.is_real_type ()); |
|
1084 } |
|
1085 |
|
1086 void |
|
1087 tree_constant_rep::do_matrix_assignment (tree_constant& rhs, int i, |
|
1088 idx_vector& jv) |
|
1089 { |
|
1090 REP_RHS_MATRIX (rhs, rhs_m, rhs_cm, rhs_nr, rhs_nc); |
|
1091 for (int j = 0; j < jv.capacity (); j++) |
|
1092 REP_ELEM_ASSIGN (i, jv.elem (j), rhs_m.elem (0, j), |
|
1093 rhs_cm.elem (0, j), rhs.is_real_type ()); |
|
1094 } |
|
1095 |
|
1096 void |
|
1097 tree_constant_rep::do_matrix_assignment (tree_constant& rhs, int i, Range& rj) |
|
1098 { |
|
1099 REP_RHS_MATRIX (rhs, rhs_m, rhs_cm, rhs_nr, rhs_nc); |
|
1100 |
|
1101 double b = rj.base (); |
|
1102 double increment = rj.inc (); |
|
1103 |
|
1104 for (int j = 0; j < rj.nelem (); j++) |
|
1105 { |
|
1106 double tmp = b + j * increment; |
|
1107 int col = tree_to_mat_idx (tmp); |
|
1108 REP_ELEM_ASSIGN (i, col, rhs_m.elem (0, j), rhs_cm.elem (0, j), |
|
1109 rhs.is_real_type ()); |
|
1110 } |
|
1111 } |
|
1112 |
|
1113 void |
|
1114 tree_constant_rep::do_matrix_assignment (tree_constant& rhs, int i, |
|
1115 tree_constant_rep::constant_type mcj) |
|
1116 { |
|
1117 assert (mcj == magic_colon); |
|
1118 |
|
1119 int nc = columns (); |
|
1120 |
|
1121 if (rhs.is_matrix_type ()) |
|
1122 { |
|
1123 REP_RHS_MATRIX (rhs, rhs_m, rhs_cm, rhs_nr, rhs_nc); |
|
1124 |
|
1125 for (int j = 0; j < nc; j++) |
|
1126 REP_ELEM_ASSIGN (i, j, rhs_m.elem (0, j), rhs_cm.elem (0, j), |
|
1127 rhs.is_real_type ()); |
|
1128 } |
|
1129 else if (rhs.const_type () == scalar_constant && nc == 1) |
|
1130 { |
|
1131 REP_ELEM_ASSIGN (i, 0, rhs.double_value (), |
|
1132 rhs.complex_value (), rhs.is_real_type ()); |
|
1133 } |
|
1134 else |
|
1135 panic_impossible (); |
|
1136 } |
|
1137 |
|
1138 void |
|
1139 tree_constant_rep::do_matrix_assignment (tree_constant& rhs, |
|
1140 idx_vector& iv, int j) |
|
1141 { |
|
1142 REP_RHS_MATRIX (rhs, rhs_m, rhs_cm, rhs_nr, rhs_nc); |
|
1143 |
|
1144 for (int i = 0; i < iv.capacity (); i++) |
|
1145 { |
|
1146 int row = iv.elem (i); |
|
1147 REP_ELEM_ASSIGN (row, j, rhs_m.elem (i, 0), |
|
1148 rhs_cm.elem (i, 0), rhs.is_real_type ()); |
|
1149 } |
|
1150 } |
|
1151 |
|
1152 void |
|
1153 tree_constant_rep::do_matrix_assignment (tree_constant& rhs, |
|
1154 idx_vector& iv, idx_vector& jv) |
|
1155 { |
|
1156 REP_RHS_MATRIX (rhs, rhs_m, rhs_cm, rhs_nr, rhs_nc); |
|
1157 |
|
1158 for (int i = 0; i < iv.capacity (); i++) |
|
1159 { |
|
1160 int row = iv.elem (i); |
|
1161 for (int j = 0; j < jv.capacity (); j++) |
|
1162 { |
|
1163 int col = jv.elem (j); |
|
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, |
|
1172 idx_vector& iv, Range& rj) |
|
1173 { |
|
1174 REP_RHS_MATRIX (rhs, rhs_m, rhs_cm, rhs_nr, rhs_nc); |
|
1175 |
|
1176 double b = rj.base (); |
|
1177 double increment = rj.inc (); |
|
1178 |
|
1179 for (int i = 0; i < iv.capacity (); i++) |
|
1180 { |
|
1181 int row = iv.elem (i); |
|
1182 for (int j = 0; j < rj.nelem (); j++) |
|
1183 { |
|
1184 double tmp = b + j * increment; |
|
1185 int col = tree_to_mat_idx (tmp); |
|
1186 REP_ELEM_ASSIGN (row, col, rhs_m.elem (i, j), |
|
1187 rhs_cm.elem (i, j), rhs.is_real_type ()); |
|
1188 } |
|
1189 } |
|
1190 } |
|
1191 |
|
1192 void |
|
1193 tree_constant_rep::do_matrix_assignment (tree_constant& rhs, idx_vector& iv, |
|
1194 tree_constant_rep::constant_type mcj) |
|
1195 { |
|
1196 assert (mcj == magic_colon); |
|
1197 |
|
1198 REP_RHS_MATRIX (rhs, rhs_m, rhs_cm, rhs_nr, rhs_nc); |
|
1199 |
|
1200 int nc = columns (); |
|
1201 |
|
1202 for (int j = 0; j < nc; j++) |
|
1203 { |
|
1204 for (int i = 0; i < iv.capacity (); i++) |
|
1205 { |
|
1206 int row = iv.elem (i); |
|
1207 REP_ELEM_ASSIGN (row, j, rhs_m.elem (i, j), |
|
1208 rhs_cm.elem (i, j), rhs.is_real_type ()); |
|
1209 } |
|
1210 } |
|
1211 } |
|
1212 |
|
1213 void |
|
1214 tree_constant_rep::do_matrix_assignment (tree_constant& rhs, Range& ri, int j) |
|
1215 { |
|
1216 REP_RHS_MATRIX (rhs, rhs_m, rhs_cm, rhs_nr, rhs_nc); |
|
1217 |
|
1218 double b = ri.base (); |
|
1219 double increment = ri.inc (); |
|
1220 |
|
1221 for (int i = 0; i < ri.nelem (); i++) |
|
1222 { |
|
1223 double tmp = b + i * increment; |
|
1224 int row = tree_to_mat_idx (tmp); |
|
1225 REP_ELEM_ASSIGN (row, j, rhs_m.elem (i, 0), |
|
1226 rhs_cm.elem (i, 0), rhs.is_real_type ()); |
|
1227 } |
|
1228 } |
|
1229 |
|
1230 void |
|
1231 tree_constant_rep::do_matrix_assignment (tree_constant& rhs, Range& ri, |
|
1232 idx_vector& jv) |
|
1233 { |
|
1234 REP_RHS_MATRIX (rhs, rhs_m, rhs_cm, rhs_nr, rhs_nc); |
|
1235 |
|
1236 double b = ri.base (); |
|
1237 double increment = ri.inc (); |
|
1238 |
|
1239 for (int j = 0; j < jv.capacity (); j++) |
|
1240 { |
|
1241 int col = jv.elem (j); |
|
1242 for (int i = 0; i < ri.nelem (); i++) |
|
1243 { |
|
1244 double tmp = b + i * increment; |
|
1245 int row = tree_to_mat_idx (tmp); |
|
1246 REP_ELEM_ASSIGN (row, col, rhs_m.elem (i, j), |
|
1247 rhs_m.elem (i, j), rhs.is_real_type ()); |
|
1248 } |
|
1249 } |
|
1250 } |
|
1251 |
|
1252 void |
|
1253 tree_constant_rep::do_matrix_assignment (tree_constant& rhs, Range& ri, |
|
1254 Range& rj) |
|
1255 { |
|
1256 double ib = ri.base (); |
|
1257 double iinc = ri.inc (); |
|
1258 double jb = rj.base (); |
|
1259 double jinc = rj.inc (); |
|
1260 |
|
1261 REP_RHS_MATRIX (rhs, rhs_m, rhs_cm, rhs_nr, rhs_nc); |
|
1262 |
|
1263 for (int i = 0; i < ri.nelem (); i++) |
|
1264 { |
|
1265 double itmp = ib + i * iinc; |
|
1266 int row = tree_to_mat_idx (itmp); |
|
1267 for (int j = 0; j < rj.nelem (); j++) |
|
1268 { |
|
1269 double jtmp = jb + j * jinc; |
|
1270 int col = tree_to_mat_idx (jtmp); |
|
1271 REP_ELEM_ASSIGN (row, col, rhs_m.elem (i, j), |
|
1272 rhs_cm.elem (i, j), rhs.is_real_type ()); |
|
1273 } |
|
1274 } |
|
1275 } |
|
1276 |
|
1277 void |
|
1278 tree_constant_rep::do_matrix_assignment (tree_constant& rhs, Range& ri, |
|
1279 tree_constant_rep::constant_type mcj) |
|
1280 { |
|
1281 assert (mcj == magic_colon); |
|
1282 |
|
1283 REP_RHS_MATRIX (rhs, rhs_m, rhs_cm, rhs_nr, rhs_nc); |
|
1284 |
|
1285 double ib = ri.base (); |
|
1286 double iinc = ri.inc (); |
|
1287 |
|
1288 int nc = columns (); |
|
1289 |
|
1290 for (int i = 0; i < ri.nelem (); i++) |
|
1291 { |
|
1292 double itmp = ib + i * iinc; |
|
1293 int row = tree_to_mat_idx (itmp); |
|
1294 for (int j = 0; j < nc; j++) |
|
1295 REP_ELEM_ASSIGN (row, j, rhs_m.elem (i, j), |
|
1296 rhs_cm.elem (i, j), rhs.is_real_type ()); |
|
1297 } |
|
1298 } |
|
1299 |
|
1300 void |
|
1301 tree_constant_rep::do_matrix_assignment (tree_constant& rhs, |
|
1302 tree_constant_rep::constant_type mci, |
|
1303 int j) |
|
1304 { |
|
1305 assert (mci == magic_colon); |
|
1306 |
|
1307 int nr = rows (); |
|
1308 |
|
1309 if (rhs.is_matrix_type ()) |
|
1310 { |
|
1311 REP_RHS_MATRIX (rhs, rhs_m, rhs_cm, rhs_nr, rhs_nc); |
|
1312 |
|
1313 for (int i = 0; i < nr; i++) |
|
1314 REP_ELEM_ASSIGN (i, j, rhs_m.elem (i, 0), |
|
1315 rhs_cm.elem (i, 0), rhs.is_real_type ()); |
|
1316 } |
|
1317 else if (rhs.const_type () == scalar_constant && nr == 1) |
|
1318 { |
|
1319 REP_ELEM_ASSIGN (0, j, rhs.double_value (), |
|
1320 rhs.complex_value (), rhs.is_real_type ()); |
|
1321 } |
|
1322 else |
|
1323 panic_impossible (); |
|
1324 } |
|
1325 |
|
1326 void |
|
1327 tree_constant_rep::do_matrix_assignment (tree_constant& rhs, |
|
1328 tree_constant_rep::constant_type mci, |
|
1329 idx_vector& jv) |
|
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 for (int i = 0; i < nr; i++) |
|
1338 { |
|
1339 for (int j = 0; j < jv.capacity (); j++) |
|
1340 { |
|
1341 int col = jv.elem (j); |
|
1342 REP_ELEM_ASSIGN (i, col, rhs_m.elem (i, j), |
|
1343 rhs_cm.elem (i, j), rhs.is_real_type ()); |
|
1344 } |
|
1345 } |
|
1346 } |
|
1347 |
|
1348 void |
|
1349 tree_constant_rep::do_matrix_assignment (tree_constant& rhs, |
|
1350 tree_constant_rep::constant_type mci, |
|
1351 Range& rj) |
|
1352 { |
|
1353 assert (mci == magic_colon); |
|
1354 |
|
1355 REP_RHS_MATRIX (rhs, rhs_m, rhs_cm, rhs_nr, rhs_nc); |
|
1356 |
|
1357 int nr = rows (); |
|
1358 |
|
1359 double jb = rj.base (); |
|
1360 double jinc = rj.inc (); |
|
1361 |
|
1362 for (int j = 0; j < rj.nelem (); j++) |
|
1363 { |
|
1364 double jtmp = jb + j * jinc; |
|
1365 int col = tree_to_mat_idx (jtmp); |
|
1366 for (int i = 0; i < nr; i++) |
|
1367 { |
|
1368 REP_ELEM_ASSIGN (i, col, rhs_m.elem (i, j), |
|
1369 rhs_cm.elem (i, j), rhs.is_real_type ()); |
|
1370 } |
|
1371 } |
|
1372 } |
|
1373 |
|
1374 void |
|
1375 tree_constant_rep::do_matrix_assignment (tree_constant& rhs, |
|
1376 tree_constant_rep::constant_type mci, |
|
1377 tree_constant_rep::constant_type mcj) |
|
1378 { |
|
1379 assert (mci == magic_colon && mcj == magic_colon); |
|
1380 |
|
1381 switch (type_tag) |
|
1382 { |
|
1383 case scalar_constant: |
|
1384 break; |
|
1385 case matrix_constant: |
|
1386 delete matrix; |
|
1387 break; |
|
1388 case complex_scalar_constant: |
|
1389 delete complex_scalar; |
|
1390 break; |
|
1391 case complex_matrix_constant: |
|
1392 delete complex_matrix; |
|
1393 break; |
|
1394 case string_constant: |
|
1395 delete [] string; |
|
1396 break; |
|
1397 case range_constant: |
|
1398 delete range; |
|
1399 break; |
|
1400 case magic_colon: |
|
1401 default: |
|
1402 panic_impossible (); |
|
1403 break; |
|
1404 } |
|
1405 |
|
1406 type_tag = rhs.const_type (); |
|
1407 |
|
1408 switch (type_tag) |
|
1409 { |
|
1410 case scalar_constant: |
|
1411 scalar = rhs.double_value (); |
|
1412 break; |
|
1413 case matrix_constant: |
|
1414 matrix = new Matrix (rhs.matrix_value ()); |
|
1415 break; |
|
1416 case string_constant: |
|
1417 string = strsave (rhs.string_value ()); |
|
1418 break; |
|
1419 case complex_matrix_constant: |
|
1420 complex_matrix = new ComplexMatrix (rhs.complex_matrix_value ()); |
|
1421 break; |
|
1422 case complex_scalar_constant: |
|
1423 complex_scalar = new Complex (rhs.complex_value ()); |
|
1424 break; |
|
1425 case range_constant: |
|
1426 range = new Range (rhs.range_value ()); |
|
1427 break; |
|
1428 case magic_colon: |
|
1429 default: |
|
1430 panic_impossible (); |
|
1431 break; |
|
1432 } |
|
1433 } |
|
1434 |
|
1435 /* |
|
1436 ;;; Local Variables: *** |
|
1437 ;;; mode: C++ *** |
|
1438 ;;; page-delimiter: "^/\\*" *** |
|
1439 ;;; End: *** |
|
1440 */ |