1559
|
1 // Template array classes -*- C++ -*- |
|
2 /* |
|
3 |
1882
|
4 Copyright (C) 1996 John W. Eaton |
1559
|
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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
21 |
|
22 */ |
|
23 |
1906
|
24 #include "Array-flags.h" |
1559
|
25 #include "idx-vector.h" |
|
26 #include "lo-error.h" |
|
27 |
|
28 template <class T> |
|
29 void |
1619
|
30 Array<T>::clear_index (void) |
1559
|
31 { |
|
32 delete [] idx; |
|
33 idx = 0; |
|
34 idx_count = 0; |
|
35 } |
|
36 |
|
37 template <class T> |
|
38 void |
1619
|
39 Array<T>::set_index (const idx_vector& i) |
1559
|
40 { |
|
41 if (! idx) |
|
42 idx = new idx_vector [max_indices]; |
|
43 |
|
44 if (idx_count < max_indices) |
|
45 { |
|
46 idx[idx_count++] = i; |
|
47 } |
|
48 else |
|
49 { |
|
50 (*current_liboctave_error_handler) |
|
51 ("invalid number of indices specified"); |
1619
|
52 |
1559
|
53 clear_index (); |
|
54 } |
|
55 } |
|
56 |
|
57 template <class T> |
|
58 Array<T> |
|
59 Array<T>::value (void) |
|
60 { |
|
61 Array<T> retval; |
|
62 |
|
63 idx_vector *tmp = get_idx (); |
|
64 idx_vector idx = tmp[0]; |
|
65 |
|
66 int len = length (); |
|
67 |
1906
|
68 int n = idx.freeze (len, "vector", liboctave_pzo_flag); |
1559
|
69 |
|
70 if (idx) |
|
71 { |
|
72 if (idx.is_colon_equiv (len)) |
|
73 { |
|
74 retval = *this; |
|
75 } |
|
76 else if (n == 0) |
|
77 { |
|
78 retval.resize (0); |
|
79 } |
|
80 else if (len == 1 && n > 1 |
|
81 && idx.one_zero_only () |
|
82 && idx.ones_count () == n) |
|
83 { |
|
84 retval.resize (n, elem (0)); |
|
85 } |
|
86 else |
|
87 { |
|
88 retval.resize (n); |
|
89 |
|
90 for (int i = 0; i < n; i++) |
|
91 { |
|
92 int ii = idx.elem (i); |
|
93 retval.elem (i) = elem (ii); |
|
94 } |
|
95 } |
|
96 } |
|
97 // idx_vector::freeze() printed an error message for us. |
|
98 |
|
99 clear_index (); |
|
100 |
|
101 return retval; |
|
102 } |
|
103 |
|
104 template <class T> |
|
105 void |
|
106 Array<T>::maybe_delete_elements (idx_vector& idx) |
|
107 { |
|
108 int len = length (); |
|
109 |
|
110 if (len == 0) |
|
111 return; |
|
112 |
|
113 if (idx.is_colon_equiv (len, 1)) |
|
114 resize (0); |
|
115 else |
|
116 { |
|
117 int num_to_delete = idx.length (len); |
|
118 |
|
119 if (num_to_delete != 0) |
|
120 { |
|
121 int new_len = len - num_to_delete; |
|
122 if (new_len > 0) |
|
123 { |
|
124 T *new_data = new T [new_len]; |
|
125 |
|
126 int ii = 0; |
|
127 int iidx = 0; |
|
128 for (int i = 0; i < len; i++) |
|
129 { |
|
130 if (i == idx.elem (iidx)) |
|
131 iidx++; |
|
132 else |
|
133 { |
|
134 new_data[ii] = elem (i); |
|
135 ii++; |
|
136 } |
|
137 } |
|
138 |
|
139 if (--rep->count <= 0) |
|
140 delete rep; |
|
141 |
1735
|
142 rep = new ArrayRep (new_data, new_len); |
1694
|
143 |
1559
|
144 set_max_indices (1); |
|
145 } |
|
146 else |
|
147 (*current_liboctave_error_handler) |
1634
|
148 ("A(idx) = []: index out of range"); |
1559
|
149 } |
|
150 } |
|
151 } |
|
152 |
|
153 // ??? FIXME ??? -- this doesn't handle assignment of empty vectors |
|
154 // to delete elements. Should it? |
|
155 |
|
156 template <class LT, class RT> |
|
157 int |
|
158 assign (Array<LT>& lhs, const Array<RT>& rhs) |
|
159 { |
|
160 int retval = 1; |
|
161 |
|
162 idx_vector *tmp = lhs.get_idx (); |
|
163 |
|
164 idx_vector idx = tmp[0]; |
|
165 |
|
166 int lhs_len = lhs.length (); |
|
167 int rhs_len = rhs.length (); |
|
168 |
1906
|
169 int n = idx.freeze (lhs_len, "vector", liboctave_pzo_flag, |
|
170 liboctave_rre_flag); |
1559
|
171 |
|
172 if (n != 0) |
|
173 { |
1906
|
174 if (liboctave_rre_flag) |
1559
|
175 { |
|
176 int max_idx = idx.max () + 1; |
|
177 if (max_idx > lhs_len) |
|
178 lhs.resize (max_idx, 0.0); |
|
179 } |
|
180 |
|
181 if (rhs_len == n) |
|
182 { |
|
183 for (int i = 0; i < n; i++) |
|
184 { |
|
185 int ii = idx.elem (i); |
|
186 lhs.elem (ii) = rhs.elem (i); |
|
187 } |
|
188 } |
|
189 else if (rhs_len == 1) |
|
190 { |
|
191 RT scalar = rhs.elem (0); |
|
192 |
|
193 for (int i = 0; i < n; i++) |
|
194 { |
|
195 int ii = idx.elem (i); |
|
196 lhs.elem (ii) = scalar; |
|
197 } |
|
198 } |
|
199 else |
|
200 { |
|
201 (*current_liboctave_error_handler) |
|
202 ("A(I) = X: X must be a scalar or a vector with same length as I"); |
|
203 |
|
204 retval = 0; |
|
205 } |
|
206 } |
|
207 else |
|
208 { |
|
209 (*current_liboctave_error_handler) |
|
210 ("A([]) = X: X must also be an empty matrix"); |
|
211 |
|
212 retval = 0; |
|
213 } |
|
214 |
|
215 lhs.clear_index (); |
|
216 |
|
217 return retval; |
|
218 } |
|
219 |
|
220 template <class T> |
|
221 Array2<T> |
|
222 Array2<T>::value (void) |
|
223 { |
|
224 Array2<T> retval; |
|
225 |
|
226 int n_idx = index_count (); |
|
227 |
|
228 int nr = d1; |
|
229 int nc = d2; |
|
230 |
|
231 if (n_idx == 2) |
|
232 { |
|
233 idx_vector *tmp = get_idx (); |
|
234 idx_vector idx_i = tmp[0]; |
|
235 idx_vector idx_j = tmp[1]; |
|
236 |
1906
|
237 int n = idx_i.freeze (nr, "row", liboctave_pzo_flag); |
|
238 int m = idx_j.freeze (nc, "column", liboctave_pzo_flag); |
1559
|
239 |
|
240 if (idx_i && idx_j) |
|
241 { |
|
242 if (n == 0) |
|
243 { |
|
244 if (m == 0 || idx_j.is_colon_equiv (nc, 1)) |
|
245 retval.resize (0, 0); |
|
246 else |
|
247 (*current_liboctave_error_handler) |
|
248 ("invalid row index = 0"); |
|
249 } |
|
250 else if (m == 0) |
|
251 { |
|
252 if (n == 0 || idx_i.is_colon_equiv (nr, 1)) |
|
253 retval.resize (0, 0); |
|
254 else |
|
255 (*current_liboctave_error_handler) |
|
256 ("invalid column index = 0"); |
|
257 } |
|
258 else if (idx_i.is_colon_equiv (nr) && idx_j.is_colon_equiv (nc)) |
|
259 { |
|
260 retval = *this; |
|
261 } |
|
262 else |
|
263 { |
|
264 retval.resize (n, m); |
|
265 |
|
266 for (int j = 0; j < m; j++) |
|
267 { |
|
268 int jj = idx_j.elem (j); |
|
269 for (int i = 0; i < n; i++) |
|
270 { |
|
271 int ii = idx_i.elem (i); |
|
272 retval.elem (i, j) = elem (ii, jj); |
|
273 } |
|
274 } |
|
275 } |
|
276 } |
|
277 // idx_vector::freeze() printed an error message for us. |
|
278 } |
|
279 else if (n_idx == 1) |
|
280 { |
|
281 if (nr == 1 && nc == 1) |
|
282 { |
|
283 Array<T> tmp = Array<T>::value (); |
|
284 |
|
285 int len = tmp.length (); |
|
286 |
1574
|
287 if (len == 0) |
|
288 retval = Array2<T> (0, 0); |
1559
|
289 else |
1574
|
290 { |
1906
|
291 if (liboctave_pcv_flag) |
1574
|
292 retval = Array2<T> (tmp, len, 1); |
|
293 else |
|
294 retval = Array2<T> (tmp, 1, len); |
|
295 } |
1559
|
296 } |
|
297 else if (nr == 1 || nc == 1) |
|
298 { |
|
299 int result_is_column_vector = (nc == 1); |
|
300 |
1906
|
301 if (liboctave_dfi_flag) |
1559
|
302 { |
|
303 idx_vector *tmp = get_idx (); |
|
304 idx_vector idx = tmp[0]; |
|
305 |
1574
|
306 if (idx.is_colon ()) |
|
307 result_is_column_vector = 1; |
1559
|
308 } |
|
309 |
|
310 Array<T> tmp = Array<T>::value (); |
|
311 |
|
312 int len = tmp.length (); |
|
313 |
1574
|
314 if (len == 0) |
|
315 retval = Array2<T> (0, 0); |
1559
|
316 else |
1574
|
317 { |
|
318 if (result_is_column_vector) |
|
319 retval = Array2<T> (tmp, len, 1); |
|
320 else |
|
321 retval = Array2<T> (tmp, 1, len); |
|
322 } |
1559
|
323 } |
1906
|
324 else if (liboctave_dfi_flag) |
1559
|
325 { |
1574
|
326 // This code is only for indexing matrices. The vector |
|
327 // cases are handled above. |
|
328 |
1559
|
329 idx_vector *tmp = get_idx (); |
|
330 idx_vector idx = tmp[0]; |
|
331 |
1906
|
332 idx.freeze (nr * nc, "matrix", liboctave_pzo_flag); |
1559
|
333 |
|
334 if (idx) |
|
335 { |
|
336 int result_nr = idx.orig_rows (); |
|
337 int result_nc = idx.orig_columns (); |
|
338 |
|
339 if (idx.is_colon ()) |
|
340 { |
|
341 result_nr = nr * nc; |
|
342 result_nc = 1; |
|
343 } |
|
344 else if (idx.one_zero_only ()) |
|
345 { |
|
346 result_nr = idx.ones_count (); |
|
347 result_nc = (result_nr > 0 ? 1 : 0); |
|
348 } |
|
349 |
|
350 retval.resize (result_nr, result_nc); |
|
351 |
|
352 int k = 0; |
|
353 for (int j = 0; j < result_nc; j++) |
|
354 { |
|
355 for (int i = 0; i < result_nr; i++) |
|
356 { |
|
357 int ii = idx.elem (k++); |
|
358 int fr = ii % nr; |
|
359 int fc = (ii - fr) / nr; |
|
360 retval.elem (i, j) = elem (fr, fc); |
|
361 } |
|
362 } |
|
363 } |
|
364 // idx_vector::freeze() printed an error message for us. |
|
365 } |
|
366 else |
|
367 (*current_liboctave_error_handler) |
|
368 ("single index only valid for row or column vector"); |
|
369 } |
|
370 else |
|
371 (*current_liboctave_error_handler) |
|
372 ("invalid number of indices for matrix expression"); |
|
373 |
|
374 clear_index (); |
|
375 |
|
376 return retval; |
|
377 } |
|
378 |
|
379 template <class T> |
|
380 void |
|
381 Array2<T>::maybe_delete_elements (idx_vector& idx_i, idx_vector& idx_j) |
|
382 { |
|
383 int nr = d1; |
|
384 int nc = d2; |
|
385 |
|
386 if (nr == 0 && nc == 0) |
|
387 return; |
|
388 |
|
389 if (idx_i.is_colon_equiv (nr, 1)) |
|
390 { |
|
391 if (idx_j.is_colon_equiv (nc, 1)) |
|
392 resize (0, 0); |
|
393 else |
|
394 { |
|
395 int num_to_delete = idx_j.length (nc); |
|
396 |
|
397 if (num_to_delete != 0) |
|
398 { |
|
399 if (nr == 1 && num_to_delete == nc) |
|
400 resize (0, 0); |
|
401 else |
|
402 { |
|
403 int new_nc = nc - num_to_delete; |
|
404 if (new_nc > 0) |
|
405 { |
|
406 T *new_data = new T [nr * new_nc]; |
|
407 |
|
408 int jj = 0; |
|
409 int idx = 0; |
|
410 for (int j = 0; j < nc; j++) |
|
411 { |
|
412 if (j == idx_j.elem (idx)) |
|
413 idx++; |
|
414 else |
|
415 { |
|
416 for (int i = 0; i < nr; i++) |
|
417 new_data[nr*jj+i] = elem (i, j); |
|
418 jj++; |
|
419 } |
|
420 } |
|
421 |
|
422 if (--rep->count <= 0) |
|
423 delete rep; |
|
424 |
1735
|
425 rep = new ArrayRep (new_data, nr * new_nc); |
1694
|
426 |
1559
|
427 d2 = new_nc; |
1694
|
428 |
1559
|
429 set_max_indices (2); |
|
430 } |
|
431 else |
|
432 (*current_liboctave_error_handler) |
1634
|
433 ("A(idx) = []: index out of range"); |
1559
|
434 } |
|
435 } |
|
436 } |
|
437 } |
|
438 else if (idx_j.is_colon_equiv (nr, 1)) |
|
439 { |
|
440 if (idx_i.is_colon_equiv (nc, 1)) |
|
441 resize (0, 0); |
|
442 else |
|
443 { |
|
444 int num_to_delete = idx_i.length (nr); |
|
445 |
|
446 if (num_to_delete != 0) |
|
447 { |
|
448 if (nc == 1 && num_to_delete == nr) |
|
449 resize (0, 0); |
|
450 else |
|
451 { |
|
452 int new_nr = nr - num_to_delete; |
|
453 if (new_nr > 0) |
|
454 { |
|
455 T *new_data = new T [new_nr * nc]; |
|
456 |
|
457 int ii = 0; |
|
458 int idx = 0; |
|
459 for (int i = 0; i < nr; i++) |
|
460 { |
|
461 if (i == idx_i.elem (idx)) |
|
462 idx++; |
|
463 else |
|
464 { |
|
465 for (int j = 0; j < nc; j++) |
|
466 new_data[new_nr*j+ii] = elem (i, j); |
|
467 ii++; |
|
468 } |
|
469 } |
|
470 |
|
471 if (--rep->count <= 0) |
|
472 delete rep; |
|
473 |
1735
|
474 rep = new ArrayRep (new_data, new_nr * nc); |
1694
|
475 |
1559
|
476 d1 = new_nr; |
1694
|
477 |
1559
|
478 set_max_indices (2); |
|
479 } |
|
480 else |
|
481 (*current_liboctave_error_handler) |
1634
|
482 ("A(idx) = []: index out of range"); |
1559
|
483 } |
|
484 } |
|
485 } |
|
486 } |
|
487 } |
|
488 |
|
489 template <class LT, class RT> |
|
490 int |
|
491 assign (Array2<LT>& lhs, const Array2<RT>& rhs) |
|
492 { |
|
493 int retval = 1; |
|
494 |
|
495 int n_idx = lhs.index_count (); |
|
496 |
|
497 int lhs_nr = lhs.rows (); |
|
498 int lhs_nc = lhs.cols (); |
|
499 |
|
500 int rhs_nr = rhs.rows (); |
|
501 int rhs_nc = rhs.cols (); |
|
502 |
|
503 if (n_idx == 2) |
|
504 { |
|
505 idx_vector *tmp = lhs.get_idx (); |
|
506 |
|
507 idx_vector idx_i = tmp[0]; |
|
508 idx_vector idx_j = tmp[1]; |
|
509 |
1906
|
510 int n = idx_i.freeze (lhs_nr, "row", liboctave_pzo_flag, |
|
511 liboctave_rre_flag); |
|
512 |
|
513 int m = idx_j.freeze (lhs_nc, "column", liboctave_pzo_flag, |
|
514 liboctave_rre_flag); |
1559
|
515 |
1614
|
516 int idx_i_is_colon = idx_i.is_colon (); |
|
517 int idx_j_is_colon = idx_j.is_colon (); |
|
518 |
|
519 if (idx_i_is_colon) |
|
520 n = rhs_nr; |
|
521 |
|
522 if (idx_j_is_colon) |
|
523 m = rhs_nc; |
|
524 |
1559
|
525 if (idx_i && idx_j) |
|
526 { |
|
527 if (rhs_nr == 0 && rhs_nc == 0) |
|
528 { |
|
529 lhs.maybe_delete_elements (idx_i, idx_j); |
|
530 } |
|
531 else |
|
532 { |
1906
|
533 if (liboctave_rre_flag) |
1559
|
534 { |
1614
|
535 int max_row_idx = idx_i_is_colon ? rhs_nr : idx_i.max () + 1; |
|
536 int max_col_idx = idx_j_is_colon ? rhs_nc : idx_j.max () + 1; |
1559
|
537 |
|
538 int new_nr = max_row_idx > lhs_nr ? max_row_idx : lhs_nr; |
|
539 int new_nc = max_col_idx > lhs_nc ? max_col_idx : lhs_nc; |
|
540 |
|
541 lhs.resize (new_nr, new_nc, 0.0); |
|
542 } |
|
543 |
|
544 if (n == rhs_nr && m == rhs_nc) |
|
545 { |
|
546 for (int j = 0; j < m; j++) |
|
547 { |
|
548 int jj = idx_j.elem (j); |
|
549 for (int i = 0; i < n; i++) |
|
550 { |
|
551 int ii = idx_i.elem (i); |
|
552 lhs.elem (ii, jj) = rhs.elem (i, j); |
|
553 } |
|
554 } |
|
555 } |
|
556 else if (rhs_nr == 1 && rhs_nc == 1) |
|
557 { |
1561
|
558 RT scalar = rhs.elem (0, 0); |
|
559 |
1559
|
560 for (int j = 0; j < m; j++) |
|
561 { |
|
562 int jj = idx_j.elem (j); |
|
563 for (int i = 0; i < n; i++) |
|
564 { |
|
565 int ii = idx_i.elem (i); |
1561
|
566 lhs.elem (ii, jj) = scalar; |
1559
|
567 } |
|
568 } |
|
569 } |
|
570 else |
|
571 { |
|
572 (*current_liboctave_error_handler) |
|
573 ("A(I, J) = X: X must be a scalar or the number of elements in I must"); |
|
574 (*current_liboctave_error_handler) |
|
575 ("match the number of rows in X and the number of elements in J must"); |
|
576 (*current_liboctave_error_handler) |
|
577 ("match the number of columns in X"); |
|
578 |
|
579 retval = 0; |
|
580 } |
|
581 } |
|
582 } |
|
583 // idx_vector::freeze() printed an error message for us. |
|
584 } |
|
585 else if (n_idx == 1) |
|
586 { |
|
587 if (lhs_nr == 0 || lhs_nc == 0 |
|
588 || (lhs_nr == 1 && lhs_nc == 1)) |
|
589 { |
|
590 idx_vector *tmp = lhs.get_idx (); |
|
591 |
|
592 idx_vector idx = tmp[0]; |
|
593 |
|
594 int lhs_len = lhs.length (); |
|
595 |
1906
|
596 int n = idx.freeze (lhs_len, 0, liboctave_pzo_flag, |
|
597 liboctave_rre_flag); |
1559
|
598 |
|
599 if (idx) |
|
600 { |
|
601 if (rhs_nr == 0 && rhs_nc == 0) |
|
602 { |
|
603 if (n != 0 && (lhs_nr != 0 || lhs_nc != 0)) |
|
604 { |
|
605 idx_vector tmp (':'); |
|
606 lhs.maybe_delete_elements (idx, tmp); |
|
607 } |
|
608 } |
|
609 else |
|
610 { |
|
611 if (assign ((Array<LT>&) lhs, (Array<RT>&) rhs)) |
|
612 { |
|
613 int len = lhs.length (); |
|
614 |
|
615 if (len > 0) |
|
616 { |
1594
|
617 int idx_nr = idx.orig_rows (); |
|
618 int idx_nc = idx.orig_columns (); |
|
619 |
1906
|
620 if (liboctave_dfi_flag |
|
621 || (idx_nr == 1 && idx_nc == 1)) |
1594
|
622 { |
1906
|
623 if (liboctave_pcv_flag) |
1594
|
624 { |
|
625 lhs.d1 = lhs.length (); |
|
626 lhs.d2 = 1; |
|
627 } |
|
628 else |
|
629 { |
|
630 lhs.d1 = 1; |
|
631 lhs.d2 = lhs.length (); |
|
632 } |
|
633 } |
|
634 else if (idx_nr == 1 && rhs_nr == 1) |
|
635 { |
|
636 lhs.d1 = 1; |
|
637 lhs.d2 = lhs.length (); |
|
638 } |
|
639 else if (idx_nc == 1 && rhs_nc == 1) |
1559
|
640 { |
|
641 lhs.d1 = lhs.length (); |
|
642 lhs.d2 = 1; |
|
643 } |
|
644 else |
1594
|
645 (*current_liboctave_error_handler) |
|
646 ("A(I) = X: X must be a scalar or a matrix with the same size as I"); |
1559
|
647 } |
|
648 else |
|
649 { |
|
650 lhs.d1 = 0; |
|
651 lhs.d2 = 0; |
|
652 } |
|
653 } |
|
654 else |
|
655 retval = 0; |
|
656 } |
|
657 } |
|
658 // idx_vector::freeze() printed an error message for us. |
|
659 } |
|
660 else if (lhs_nr == 1) |
|
661 { |
|
662 idx_vector *tmp = lhs.get_idx (); |
|
663 |
|
664 idx_vector idx = tmp[0]; |
|
665 |
1906
|
666 idx.freeze (lhs_nc, "vector", liboctave_pzo_flag, |
|
667 liboctave_rre_flag); |
1559
|
668 |
|
669 if (idx) |
|
670 { |
|
671 if (rhs_nr == 0 && rhs_nc == 0) |
|
672 { |
|
673 idx_vector tmp (':'); |
|
674 lhs.maybe_delete_elements (tmp, idx); |
|
675 } |
|
676 else |
|
677 { |
|
678 if (assign ((Array<LT>&) lhs, (Array<RT>&) rhs)) |
|
679 lhs.d2 = lhs.length (); |
|
680 else |
|
681 retval = 0; |
|
682 } |
|
683 } |
|
684 // idx_vector::freeze() printed an error message for us. |
|
685 } |
|
686 else if (lhs_nc == 1) |
|
687 { |
|
688 idx_vector *tmp = lhs.get_idx (); |
|
689 |
|
690 idx_vector idx = tmp[0]; |
|
691 |
1906
|
692 idx.freeze (lhs_nr, "vector", liboctave_pzo_flag, |
|
693 liboctave_rre_flag); |
1559
|
694 |
|
695 if (idx) |
|
696 { |
|
697 if (rhs_nr == 0 && rhs_nc == 0) |
|
698 { |
|
699 idx_vector tmp (':'); |
|
700 lhs.maybe_delete_elements (idx, tmp); |
|
701 } |
|
702 else |
|
703 { |
|
704 if (assign ((Array<LT>&) lhs, (Array<RT>&) rhs)) |
|
705 lhs.d1 = lhs.length (); |
|
706 else |
|
707 retval = 0; |
|
708 } |
|
709 } |
|
710 // idx_vector::freeze() printed an error message for us. |
|
711 } |
1906
|
712 else if (liboctave_dfi_flag) |
1559
|
713 { |
|
714 idx_vector *tmp = lhs.get_idx (); |
|
715 idx_vector idx = tmp[0]; |
|
716 |
1906
|
717 int len = idx.freeze (lhs_nr * lhs_nc, "matrix", |
|
718 liboctave_pzo_flag); |
1559
|
719 |
|
720 if (idx) |
|
721 { |
|
722 if (len == rhs_nr * rhs_nc) |
|
723 { |
|
724 int k = 0; |
|
725 for (int j = 0; j < rhs_nc; j++) |
|
726 { |
|
727 for (int i = 0; i < rhs_nr; i++) |
|
728 { |
|
729 int ii = idx.elem (k++); |
|
730 int fr = ii % lhs_nr; |
|
731 int fc = (ii - fr) / lhs_nr; |
|
732 lhs.elem (fr, fc) = rhs.elem (i, j); |
|
733 } |
|
734 } |
|
735 } |
|
736 else |
|
737 { |
|
738 (*current_liboctave_error_handler) |
|
739 ("A(I) = X: X must be a scalar or a matrix with the same size as I"); |
|
740 |
|
741 retval = 0; |
|
742 } |
|
743 } |
|
744 // idx_vector::freeze() printed an error message for us. |
|
745 } |
|
746 else |
|
747 { |
|
748 (*current_liboctave_error_handler) |
|
749 ("single index only valid for row or column vector"); |
|
750 |
|
751 retval = 0; |
|
752 } |
|
753 } |
|
754 else |
|
755 { |
|
756 (*current_liboctave_error_handler) |
|
757 ("invalid number of indices for matrix expression"); |
|
758 |
|
759 retval = 0; |
|
760 } |
|
761 |
|
762 lhs.clear_index (); |
|
763 |
|
764 return retval; |
|
765 } |
|
766 |
|
767 template <class T> |
|
768 void |
|
769 Array3<T>::maybe_delete_elements (idx_vector&, idx_vector&, idx_vector&) |
|
770 { |
|
771 assert (0); |
|
772 } |
|
773 |
|
774 template <class T> |
|
775 Array3<T> |
|
776 Array3<T>::value (void) |
|
777 { |
|
778 Array3<T> retval; |
|
779 assert (0); |
|
780 return retval; |
|
781 } |
|
782 |
|
783 template <class LT, class RT> |
|
784 int |
|
785 assign (Array3<LT>&, const Array3<RT>&) |
|
786 { |
|
787 assert (0); |
|
788 return 0; |
|
789 } |
|
790 |
|
791 /* |
|
792 ;;; Local Variables: *** |
|
793 ;;; mode: C++ *** |
|
794 ;;; page-delimiter: "^/\\*" *** |
|
795 ;;; End: *** |
|
796 */ |