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