458
|
1 // ColumnVector manipulations. -*- C++ -*- |
|
2 /* |
|
3 |
1011
|
4 Copyright (C) 1992, 1993, 1994, 1995 John W. Eaton |
458
|
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 |
1315
|
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
458
|
21 |
|
22 */ |
|
23 |
1296
|
24 #if defined (__GNUG__) |
|
25 #pragma implementation |
|
26 #endif |
|
27 |
458
|
28 #ifdef HAVE_CONFIG_H |
1192
|
29 #include <config.h> |
458
|
30 #endif |
|
31 |
|
32 #include <iostream.h> |
|
33 |
1368
|
34 #include "f77-uscore.h" |
|
35 #include "lo-error.h" |
458
|
36 #include "mx-base.h" |
|
37 #include "mx-inlines.cc" |
1650
|
38 #include "oct-cmplx.h" |
458
|
39 |
|
40 // Fortran functions we call. |
|
41 |
|
42 extern "C" |
|
43 { |
1253
|
44 int F77_FCN (zgemv, ZGEMV) (const char*, const int&, const int&, |
|
45 const Complex&, const Complex*, |
|
46 const int&, const Complex*, const int&, |
|
47 const Complex&, Complex*, const int&, |
|
48 long); |
458
|
49 } |
|
50 |
1360
|
51 // Complex Column Vector class |
458
|
52 |
|
53 ComplexColumnVector::ComplexColumnVector (const ColumnVector& a) |
1214
|
54 : MArray<Complex> (a.length ()) |
458
|
55 { |
|
56 for (int i = 0; i < length (); i++) |
|
57 elem (i) = a.elem (i); |
|
58 } |
|
59 |
|
60 int |
|
61 ComplexColumnVector::operator == (const ComplexColumnVector& a) const |
|
62 { |
|
63 int len = length (); |
|
64 if (len != a.length ()) |
|
65 return 0; |
|
66 return equal (data (), a.data (), len); |
|
67 } |
|
68 |
|
69 int |
|
70 ComplexColumnVector::operator != (const ComplexColumnVector& a) const |
|
71 { |
|
72 return !(*this == a); |
|
73 } |
|
74 |
|
75 // destructive insert/delete/reorder operations |
|
76 |
|
77 ComplexColumnVector& |
|
78 ComplexColumnVector::insert (const ColumnVector& a, int r) |
|
79 { |
|
80 int a_len = a.length (); |
1699
|
81 if (r < 0 || r + a_len > length ()) |
458
|
82 { |
|
83 (*current_liboctave_error_handler) ("range error for insert"); |
|
84 return *this; |
|
85 } |
|
86 |
|
87 for (int i = 0; i < a_len; i++) |
|
88 elem (r+i) = a.elem (i); |
|
89 |
|
90 return *this; |
|
91 } |
|
92 |
|
93 ComplexColumnVector& |
|
94 ComplexColumnVector::insert (const ComplexColumnVector& a, int r) |
|
95 { |
|
96 int a_len = a.length (); |
1699
|
97 if (r < 0 || r + a_len > length ()) |
458
|
98 { |
|
99 (*current_liboctave_error_handler) ("range error for insert"); |
|
100 return *this; |
|
101 } |
|
102 |
|
103 for (int i = 0; i < a_len; i++) |
|
104 elem (r+i) = a.elem (i); |
|
105 |
|
106 return *this; |
|
107 } |
|
108 |
|
109 ComplexColumnVector& |
|
110 ComplexColumnVector::fill (double val) |
|
111 { |
|
112 int len = length (); |
|
113 if (len > 0) |
|
114 for (int i = 0; i < len; i++) |
|
115 elem (i) = val; |
|
116 return *this; |
|
117 } |
|
118 |
|
119 ComplexColumnVector& |
|
120 ComplexColumnVector::fill (const Complex& val) |
|
121 { |
|
122 int len = length (); |
|
123 if (len > 0) |
|
124 for (int i = 0; i < len; i++) |
|
125 elem (i) = val; |
|
126 return *this; |
|
127 } |
|
128 |
|
129 ComplexColumnVector& |
|
130 ComplexColumnVector::fill (double val, int r1, int r2) |
|
131 { |
|
132 int len = length (); |
|
133 if (r1 < 0 || r2 < 0 || r1 >= len || r2 >= len) |
|
134 { |
|
135 (*current_liboctave_error_handler) ("range error for fill"); |
|
136 return *this; |
|
137 } |
|
138 |
|
139 if (r1 > r2) { int tmp = r1; r1 = r2; r2 = tmp; } |
|
140 |
|
141 for (int i = r1; i <= r2; i++) |
|
142 elem (i) = val; |
|
143 |
|
144 return *this; |
|
145 } |
|
146 |
|
147 ComplexColumnVector& |
|
148 ComplexColumnVector::fill (const Complex& val, int r1, int r2) |
|
149 { |
|
150 int len = length (); |
|
151 if (r1 < 0 || r2 < 0 || r1 >= len || r2 >= len) |
|
152 { |
|
153 (*current_liboctave_error_handler) ("range error for fill"); |
|
154 return *this; |
|
155 } |
|
156 |
|
157 if (r1 > r2) { int tmp = r1; r1 = r2; r2 = tmp; } |
|
158 |
|
159 for (int i = r1; i <= r2; i++) |
|
160 elem (i) = val; |
|
161 |
|
162 return *this; |
|
163 } |
|
164 |
|
165 ComplexColumnVector |
|
166 ComplexColumnVector::stack (const ColumnVector& a) const |
|
167 { |
|
168 int len = length (); |
|
169 int nr_insert = len; |
|
170 ComplexColumnVector retval (len + a.length ()); |
|
171 retval.insert (*this, 0); |
|
172 retval.insert (a, nr_insert); |
|
173 return retval; |
|
174 } |
|
175 |
|
176 ComplexColumnVector |
|
177 ComplexColumnVector::stack (const ComplexColumnVector& a) const |
|
178 { |
|
179 int len = length (); |
|
180 int nr_insert = len; |
|
181 ComplexColumnVector retval (len + a.length ()); |
|
182 retval.insert (*this, 0); |
|
183 retval.insert (a, nr_insert); |
|
184 return retval; |
|
185 } |
|
186 |
|
187 ComplexRowVector |
|
188 ComplexColumnVector::hermitian (void) const |
|
189 { |
|
190 int len = length (); |
|
191 return ComplexRowVector (conj_dup (data (), len), len); |
|
192 } |
|
193 |
|
194 ComplexRowVector |
|
195 ComplexColumnVector::transpose (void) const |
|
196 { |
|
197 int len = length (); |
|
198 return ComplexRowVector (dup (data (), len), len); |
|
199 } |
|
200 |
|
201 ComplexColumnVector |
|
202 conj (const ComplexColumnVector& a) |
|
203 { |
|
204 int a_len = a.length (); |
|
205 ComplexColumnVector retval; |
|
206 if (a_len > 0) |
|
207 retval = ComplexColumnVector (conj_dup (a.data (), a_len), a_len); |
|
208 return retval; |
|
209 } |
|
210 |
|
211 // resize is the destructive equivalent for this one |
|
212 |
|
213 ComplexColumnVector |
|
214 ComplexColumnVector::extract (int r1, int r2) const |
|
215 { |
|
216 if (r1 > r2) { int tmp = r1; r1 = r2; r2 = tmp; } |
|
217 |
|
218 int new_r = r2 - r1 + 1; |
|
219 |
|
220 ComplexColumnVector result (new_r); |
|
221 |
|
222 for (int i = 0; i < new_r; i++) |
|
223 result.elem (i) = elem (r1+i); |
|
224 |
|
225 return result; |
|
226 } |
|
227 |
|
228 // column vector by column vector -> column vector operations |
|
229 |
|
230 ComplexColumnVector& |
|
231 ComplexColumnVector::operator += (const ColumnVector& a) |
|
232 { |
|
233 int len = length (); |
|
234 if (len != a.length ()) |
|
235 { |
|
236 (*current_liboctave_error_handler) |
|
237 ("nonconformant vector += operation attempted"); |
|
238 return *this; |
|
239 } |
|
240 |
|
241 if (len == 0) |
|
242 return *this; |
|
243 |
|
244 Complex *d = fortran_vec (); // Ensures only one reference to my privates! |
|
245 |
|
246 add2 (d, a.data (), len); |
|
247 return *this; |
|
248 } |
|
249 |
|
250 ComplexColumnVector& |
|
251 ComplexColumnVector::operator -= (const ColumnVector& a) |
|
252 { |
|
253 int len = length (); |
|
254 if (len != a.length ()) |
|
255 { |
|
256 (*current_liboctave_error_handler) |
|
257 ("nonconformant vector -= operation attempted"); |
|
258 return *this; |
|
259 } |
|
260 |
|
261 if (len == 0) |
|
262 return *this; |
|
263 |
|
264 Complex *d = fortran_vec (); // Ensures only one reference to my privates! |
|
265 |
|
266 subtract2 (d, a.data (), len); |
|
267 return *this; |
|
268 } |
|
269 |
|
270 ComplexColumnVector& |
|
271 ComplexColumnVector::operator += (const ComplexColumnVector& a) |
|
272 { |
|
273 int len = length (); |
|
274 |
|
275 if (len != a.length ()) |
|
276 { |
|
277 (*current_liboctave_error_handler) |
|
278 ("nonconformant vector += operation attempted"); |
|
279 return *this; |
|
280 } |
|
281 |
|
282 if (len == 0) |
|
283 return *this; |
|
284 |
|
285 Complex *d = fortran_vec (); // Ensures only one reference to my privates! |
|
286 |
|
287 add2 (d, a.data (), len); |
|
288 return *this; |
|
289 } |
|
290 |
|
291 ComplexColumnVector& |
|
292 ComplexColumnVector::operator -= (const ComplexColumnVector& a) |
|
293 { |
|
294 int len = length (); |
|
295 if (len != a.length ()) |
|
296 { |
|
297 (*current_liboctave_error_handler) |
|
298 ("nonconformant vector -= operation attempted"); |
|
299 return *this; |
|
300 } |
|
301 |
|
302 if (len == 0) |
|
303 return *this; |
|
304 |
|
305 Complex *d = fortran_vec (); // Ensures only one reference to my privates! |
|
306 |
|
307 subtract2 (d, a.data (), len); |
|
308 return *this; |
|
309 } |
|
310 |
|
311 // column vector by scalar -> column vector operations |
|
312 |
|
313 ComplexColumnVector |
|
314 operator + (const ComplexColumnVector& v, double s) |
|
315 { |
|
316 int len = v.length (); |
|
317 return ComplexColumnVector (add (v.data (), len, s), len); |
|
318 } |
|
319 |
|
320 ComplexColumnVector |
|
321 operator - (const ComplexColumnVector& v, double s) |
|
322 { |
|
323 int len = v.length (); |
|
324 return ComplexColumnVector (subtract (v.data (), len, s), len); |
|
325 } |
|
326 |
|
327 ComplexColumnVector |
|
328 operator * (const ComplexColumnVector& v, double s) |
|
329 { |
|
330 int len = v.length (); |
|
331 return ComplexColumnVector (multiply (v.data (), len, s), len); |
|
332 } |
|
333 |
|
334 ComplexColumnVector |
|
335 operator / (const ComplexColumnVector& v, double s) |
|
336 { |
|
337 int len = v.length (); |
|
338 return ComplexColumnVector (divide (v.data (), len, s), len); |
|
339 } |
|
340 |
1205
|
341 ComplexColumnVector |
|
342 operator + (const ColumnVector& a, const Complex& s) |
|
343 { |
|
344 int len = a.length (); |
|
345 return ComplexColumnVector (add (a.data (), len, s), len); |
|
346 } |
|
347 |
|
348 ComplexColumnVector |
|
349 operator - (const ColumnVector& a, const Complex& s) |
|
350 { |
|
351 int len = a.length (); |
|
352 return ComplexColumnVector (subtract (a.data (), len, s), len); |
|
353 } |
|
354 |
|
355 ComplexColumnVector |
|
356 operator * (const ColumnVector& a, const Complex& s) |
|
357 { |
|
358 int len = a.length (); |
|
359 return ComplexColumnVector (multiply (a.data (), len, s), len); |
|
360 } |
|
361 |
|
362 ComplexColumnVector |
|
363 operator / (const ColumnVector& a, const Complex& s) |
|
364 { |
|
365 int len = a.length (); |
|
366 return ComplexColumnVector (divide (a.data (), len, s), len); |
|
367 } |
|
368 |
458
|
369 // scalar by column vector -> column vector operations |
|
370 |
|
371 ComplexColumnVector |
|
372 operator + (double s, const ComplexColumnVector& a) |
|
373 { |
|
374 int a_len = a.length (); |
|
375 return ComplexColumnVector (add (a.data (), a_len, s), a_len); |
|
376 } |
|
377 |
|
378 ComplexColumnVector |
|
379 operator - (double s, const ComplexColumnVector& a) |
|
380 { |
|
381 int a_len = a.length (); |
|
382 return ComplexColumnVector (subtract (s, a.data (), a_len), a_len); |
|
383 } |
|
384 |
|
385 ComplexColumnVector |
|
386 operator * (double s, const ComplexColumnVector& a) |
|
387 { |
|
388 int a_len = a.length (); |
|
389 return ComplexColumnVector (multiply (a.data (), a_len, s), a_len); |
|
390 } |
|
391 |
|
392 ComplexColumnVector |
|
393 operator / (double s, const ComplexColumnVector& a) |
|
394 { |
|
395 int a_len = a.length (); |
|
396 return ComplexColumnVector (divide (s, a.data (), a_len), a_len); |
|
397 } |
|
398 |
1205
|
399 ComplexColumnVector |
|
400 operator + (const Complex& s, const ColumnVector& a) |
|
401 { |
|
402 int a_len = a.length (); |
|
403 return ComplexColumnVector (add (a.data (), a_len, s), a_len); |
|
404 } |
|
405 |
|
406 ComplexColumnVector |
|
407 operator - (const Complex& s, const ColumnVector& a) |
|
408 { |
|
409 int a_len = a.length (); |
|
410 return ComplexColumnVector (subtract (s, a.data (), a_len), a_len); |
|
411 } |
|
412 |
|
413 ComplexColumnVector |
|
414 operator * (const Complex& s, const ColumnVector& a) |
|
415 { |
|
416 int a_len = a.length (); |
|
417 return ComplexColumnVector (multiply (a.data (), a_len, s), a_len); |
|
418 } |
458
|
419 |
1205
|
420 ComplexColumnVector |
|
421 operator / (const Complex& s, const ColumnVector& a) |
458
|
422 { |
|
423 int a_len = a.length (); |
1205
|
424 return ComplexColumnVector (divide (s, a.data (), a_len), a_len); |
|
425 } |
|
426 |
|
427 // matrix by column vector -> column vector operations |
|
428 |
|
429 ComplexColumnVector |
|
430 operator * (const ComplexMatrix& m, const ColumnVector& a) |
|
431 { |
|
432 ComplexColumnVector tmp (a); |
|
433 return m * tmp; |
|
434 } |
|
435 |
|
436 ComplexColumnVector |
|
437 operator * (const ComplexMatrix& m, const ComplexColumnVector& a) |
|
438 { |
|
439 int nr = m.rows (); |
|
440 int nc = m.cols (); |
|
441 if (nc != a.length ()) |
458
|
442 { |
|
443 (*current_liboctave_error_handler) |
1205
|
444 ("nonconformant matrix multiplication attempted"); |
|
445 return ComplexColumnVector (); |
458
|
446 } |
|
447 |
1205
|
448 if (nc == 0 || nr == 0) |
|
449 return ComplexColumnVector (0); |
458
|
450 |
1205
|
451 int ld = nr; |
458
|
452 |
1205
|
453 Complex *y = new Complex [nr]; |
458
|
454 |
1253
|
455 F77_FCN (zgemv, ZGEMV) ("N", nr, nc, 1.0, m.data (), ld, a.data (), |
|
456 1, 0.0, y, 1, 1L); |
458
|
457 |
1205
|
458 return ComplexColumnVector (y, nr); |
458
|
459 } |
|
460 |
|
461 // column vector by column vector -> column vector operations |
|
462 |
|
463 ComplexColumnVector |
|
464 operator + (const ComplexColumnVector& v, const ColumnVector& a) |
|
465 { |
|
466 int len = v.length (); |
|
467 if (len != a.length ()) |
|
468 { |
|
469 (*current_liboctave_error_handler) |
|
470 ("nonconformant vector addition attempted"); |
|
471 return ComplexColumnVector (); |
|
472 } |
|
473 |
|
474 if (len == 0) |
|
475 return ComplexColumnVector (0); |
|
476 |
|
477 return ComplexColumnVector (add (v.data (), a.data (), len), len); |
|
478 } |
|
479 |
|
480 ComplexColumnVector |
|
481 operator - (const ComplexColumnVector& v, const ColumnVector& a) |
|
482 { |
|
483 int len = v.length (); |
|
484 if (len != a.length ()) |
|
485 { |
|
486 (*current_liboctave_error_handler) |
|
487 ("nonconformant vector subtraction attempted"); |
|
488 return ComplexColumnVector (); |
|
489 } |
|
490 |
|
491 if (len == 0) |
|
492 return ComplexColumnVector (0); |
|
493 |
|
494 return ComplexColumnVector (subtract (v.data (), a.data (), len), len); |
|
495 } |
|
496 |
|
497 ComplexColumnVector |
1205
|
498 operator + (const ColumnVector& v, const ComplexColumnVector& a) |
|
499 { |
|
500 int len = v.length (); |
|
501 if (len != a.length ()) |
|
502 { |
|
503 (*current_liboctave_error_handler) |
|
504 ("nonconformant vector subtraction attempted"); |
|
505 return ComplexColumnVector (); |
|
506 } |
|
507 |
|
508 if (len == 0) |
|
509 return ComplexColumnVector (0); |
|
510 |
|
511 return ComplexColumnVector (add (v.data (), a.data (), len), len); |
|
512 } |
|
513 |
|
514 ComplexColumnVector |
|
515 operator - (const ColumnVector& v, const ComplexColumnVector& a) |
|
516 { |
|
517 int len = v.length (); |
|
518 if (len != a.length ()) |
|
519 { |
|
520 (*current_liboctave_error_handler) |
|
521 ("nonconformant vector subtraction attempted"); |
|
522 return ComplexColumnVector (); |
|
523 } |
|
524 |
|
525 if (len == 0) |
|
526 return ComplexColumnVector (0); |
|
527 |
|
528 return ComplexColumnVector (subtract (v.data (), a.data (), len), len); |
|
529 } |
|
530 |
|
531 ComplexColumnVector |
458
|
532 product (const ComplexColumnVector& v, const ColumnVector& a) |
|
533 { |
|
534 int len = v.length (); |
|
535 if (len != a.length ()) |
|
536 { |
|
537 (*current_liboctave_error_handler) |
|
538 ("nonconformant vector product attempted"); |
|
539 return ComplexColumnVector (); |
|
540 } |
|
541 |
|
542 if (len == 0) |
|
543 return ComplexColumnVector (0); |
|
544 |
|
545 return ComplexColumnVector (multiply (v.data (), a.data (), len), len); |
|
546 } |
|
547 |
|
548 ComplexColumnVector |
|
549 quotient (const ComplexColumnVector& v, const ColumnVector& a) |
|
550 { |
|
551 int len = v.length (); |
|
552 if (len != a.length ()) |
|
553 { |
|
554 (*current_liboctave_error_handler) |
|
555 ("nonconformant vector quotient attempted"); |
|
556 return ComplexColumnVector (); |
|
557 } |
|
558 |
|
559 if (len == 0) |
|
560 return ComplexColumnVector (0); |
|
561 |
|
562 return ComplexColumnVector (divide (v.data (), a.data (), len), len); |
|
563 } |
|
564 |
1205
|
565 ComplexColumnVector |
|
566 product (const ColumnVector& v, const ComplexColumnVector& a) |
|
567 { |
|
568 int len = v.length (); |
|
569 if (len != a.length ()) |
|
570 { |
|
571 (*current_liboctave_error_handler) |
|
572 ("nonconformant vector product attempted"); |
|
573 return ColumnVector (); |
|
574 } |
|
575 |
|
576 if (len == 0) |
|
577 return ComplexColumnVector (0); |
|
578 |
|
579 return ComplexColumnVector (multiply (v.data (), a.data (), len), len); |
|
580 } |
|
581 |
|
582 ComplexColumnVector |
|
583 quotient (const ColumnVector& v, const ComplexColumnVector& a) |
|
584 { |
|
585 int len = v.length (); |
|
586 if (len != a.length ()) |
|
587 { |
|
588 (*current_liboctave_error_handler) |
|
589 ("nonconformant vector quotient attempted"); |
|
590 return ColumnVector (); |
|
591 } |
|
592 |
|
593 if (len == 0) |
|
594 return ComplexColumnVector (0); |
|
595 |
|
596 return ComplexColumnVector (divide (v.data (), a.data (), len), len); |
|
597 } |
|
598 |
|
599 // matrix by column vector -> column vector operations |
|
600 |
|
601 ComplexColumnVector |
|
602 operator * (const Matrix& m, const ComplexColumnVector& a) |
|
603 { |
|
604 ComplexMatrix tmp (m); |
|
605 return tmp * a; |
|
606 } |
|
607 |
|
608 // diagonal matrix by column vector -> column vector operations |
|
609 |
|
610 ComplexColumnVector |
|
611 operator * (const DiagMatrix& m, const ComplexColumnVector& a) |
|
612 { |
|
613 int nr = m.rows (); |
|
614 int nc = m.cols (); |
|
615 int a_len = a.length (); |
|
616 if (nc != a_len) |
|
617 { |
|
618 (*current_liboctave_error_handler) |
|
619 ("nonconformant matrix multiplication attempted"); |
|
620 return ColumnVector (); |
|
621 } |
|
622 |
|
623 if (nc == 0 || nr == 0) |
|
624 return ComplexColumnVector (0); |
|
625 |
|
626 ComplexColumnVector result (nr); |
|
627 |
|
628 for (int i = 0; i < a_len; i++) |
|
629 result.elem (i) = a.elem (i) * m.elem (i, i); |
|
630 |
1321
|
631 for (int i = a_len; i < nr; i++) |
1205
|
632 result.elem (i) = 0.0; |
|
633 |
|
634 return result; |
|
635 } |
|
636 |
|
637 ComplexColumnVector |
|
638 operator * (const ComplexDiagMatrix& m, const ColumnVector& a) |
|
639 { |
|
640 int nr = m.rows (); |
|
641 int nc = m.cols (); |
|
642 int a_len = a.length (); |
|
643 if (nc != a_len) |
|
644 { |
|
645 (*current_liboctave_error_handler) |
|
646 ("nonconformant matrix muliplication attempted"); |
|
647 return ComplexColumnVector (); |
|
648 } |
|
649 |
|
650 if (nc == 0 || nr == 0) |
|
651 return ComplexColumnVector (0); |
|
652 |
|
653 ComplexColumnVector result (nr); |
|
654 |
|
655 for (int i = 0; i < a_len; i++) |
|
656 result.elem (i) = a.elem (i) * m.elem (i, i); |
|
657 |
1321
|
658 for (int i = a_len; i < nr; i++) |
1205
|
659 result.elem (i) = 0.0; |
|
660 |
|
661 return result; |
|
662 } |
|
663 |
|
664 ComplexColumnVector |
|
665 operator * (const ComplexDiagMatrix& m, const ComplexColumnVector& a) |
|
666 { |
|
667 int nr = m.rows (); |
|
668 int nc = m.cols (); |
|
669 int a_len = a.length (); |
|
670 if (nc != a_len) |
|
671 { |
|
672 (*current_liboctave_error_handler) |
|
673 ("nonconformant matrix muliplication attempted"); |
|
674 return ComplexColumnVector (); |
|
675 } |
|
676 |
|
677 if (nc == 0 || nr == 0) |
|
678 return ComplexColumnVector (0); |
|
679 |
|
680 ComplexColumnVector result (nr); |
|
681 |
|
682 for (int i = 0; i < a_len; i++) |
|
683 result.elem (i) = a.elem (i) * m.elem (i, i); |
|
684 |
1321
|
685 for (int i = a_len; i < nr; i++) |
1205
|
686 result.elem (i) = 0.0; |
|
687 |
|
688 return result; |
|
689 } |
|
690 |
458
|
691 // other operations |
|
692 |
|
693 ComplexColumnVector |
|
694 map (c_c_Mapper f, const ComplexColumnVector& a) |
|
695 { |
|
696 ComplexColumnVector b (a); |
|
697 b.map (f); |
|
698 return b; |
|
699 } |
|
700 |
|
701 void |
|
702 ComplexColumnVector::map (c_c_Mapper f) |
|
703 { |
|
704 for (int i = 0; i < length (); i++) |
|
705 elem (i) = f (elem (i)); |
|
706 } |
|
707 |
|
708 Complex |
|
709 ComplexColumnVector::min (void) const |
|
710 { |
|
711 int len = length (); |
|
712 if (len == 0) |
|
713 return 0.0; |
|
714 |
|
715 Complex res = elem (0); |
|
716 double absres = abs (res); |
|
717 |
|
718 for (int i = 1; i < len; i++) |
|
719 if (abs (elem (i)) < absres) |
|
720 { |
|
721 res = elem (i); |
|
722 absres = abs (res); |
|
723 } |
|
724 |
|
725 return res; |
|
726 } |
|
727 |
|
728 Complex |
|
729 ComplexColumnVector::max (void) const |
|
730 { |
|
731 int len = length (); |
|
732 if (len == 0) |
|
733 return 0.0; |
|
734 |
|
735 Complex res = elem (0); |
|
736 double absres = abs (res); |
|
737 |
|
738 for (int i = 1; i < len; i++) |
|
739 if (abs (elem (i)) > absres) |
|
740 { |
|
741 res = elem (i); |
|
742 absres = abs (res); |
|
743 } |
|
744 |
|
745 return res; |
|
746 } |
|
747 |
|
748 // i/o |
|
749 |
|
750 ostream& |
|
751 operator << (ostream& os, const ComplexColumnVector& a) |
|
752 { |
|
753 // int field_width = os.precision () + 7; |
|
754 for (int i = 0; i < a.length (); i++) |
|
755 os << /* setw (field_width) << */ a.elem (i) << "\n"; |
|
756 return os; |
|
757 } |
|
758 |
|
759 istream& |
|
760 operator >> (istream& is, ComplexColumnVector& a) |
|
761 { |
|
762 int len = a.length(); |
|
763 |
|
764 if (len < 1) |
|
765 is.clear (ios::badbit); |
|
766 else |
|
767 { |
|
768 double tmp; |
|
769 for (int i = 0; i < len; i++) |
|
770 { |
|
771 is >> tmp; |
|
772 if (is) |
|
773 a.elem (i) = tmp; |
|
774 else |
|
775 break; |
|
776 } |
|
777 } |
532
|
778 return is; |
458
|
779 } |
|
780 |
|
781 /* |
|
782 ;;; Local Variables: *** |
|
783 ;;; mode: C++ *** |
|
784 ;;; page-delimiter: "^/\\*" *** |
|
785 ;;; End: *** |
|
786 */ |