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