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