458
|
1 // ColumnVector manipulations. -*- C++ -*- |
|
2 /* |
|
3 |
1882
|
4 Copyright (C) 1996 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 |
1847
|
34 #include "f77-fcn.h" |
1368
|
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 { |
1858
|
197 return ComplexRowVector (*this); |
458
|
198 } |
|
199 |
|
200 ComplexColumnVector |
|
201 conj (const ComplexColumnVector& a) |
|
202 { |
|
203 int a_len = a.length (); |
|
204 ComplexColumnVector retval; |
|
205 if (a_len > 0) |
|
206 retval = ComplexColumnVector (conj_dup (a.data (), a_len), a_len); |
|
207 return retval; |
|
208 } |
|
209 |
|
210 // resize is the destructive equivalent for this one |
|
211 |
|
212 ComplexColumnVector |
|
213 ComplexColumnVector::extract (int r1, int r2) const |
|
214 { |
|
215 if (r1 > r2) { int tmp = r1; r1 = r2; r2 = tmp; } |
|
216 |
|
217 int new_r = r2 - r1 + 1; |
|
218 |
|
219 ComplexColumnVector result (new_r); |
|
220 |
|
221 for (int i = 0; i < new_r; i++) |
|
222 result.elem (i) = elem (r1+i); |
|
223 |
|
224 return result; |
|
225 } |
|
226 |
|
227 // column vector by column vector -> column vector operations |
|
228 |
|
229 ComplexColumnVector& |
|
230 ComplexColumnVector::operator += (const ColumnVector& a) |
|
231 { |
|
232 int len = length (); |
|
233 if (len != a.length ()) |
|
234 { |
|
235 (*current_liboctave_error_handler) |
|
236 ("nonconformant vector += operation attempted"); |
|
237 return *this; |
|
238 } |
|
239 |
|
240 if (len == 0) |
|
241 return *this; |
|
242 |
|
243 Complex *d = fortran_vec (); // Ensures only one reference to my privates! |
|
244 |
|
245 add2 (d, a.data (), len); |
|
246 return *this; |
|
247 } |
|
248 |
|
249 ComplexColumnVector& |
|
250 ComplexColumnVector::operator -= (const ColumnVector& a) |
|
251 { |
|
252 int len = length (); |
|
253 if (len != a.length ()) |
|
254 { |
|
255 (*current_liboctave_error_handler) |
|
256 ("nonconformant vector -= operation attempted"); |
|
257 return *this; |
|
258 } |
|
259 |
|
260 if (len == 0) |
|
261 return *this; |
|
262 |
|
263 Complex *d = fortran_vec (); // Ensures only one reference to my privates! |
|
264 |
|
265 subtract2 (d, a.data (), len); |
|
266 return *this; |
|
267 } |
|
268 |
|
269 ComplexColumnVector& |
|
270 ComplexColumnVector::operator += (const ComplexColumnVector& a) |
|
271 { |
|
272 int len = length (); |
|
273 |
|
274 if (len != a.length ()) |
|
275 { |
|
276 (*current_liboctave_error_handler) |
|
277 ("nonconformant vector += operation attempted"); |
|
278 return *this; |
|
279 } |
|
280 |
|
281 if (len == 0) |
|
282 return *this; |
|
283 |
|
284 Complex *d = fortran_vec (); // Ensures only one reference to my privates! |
|
285 |
|
286 add2 (d, a.data (), len); |
|
287 return *this; |
|
288 } |
|
289 |
|
290 ComplexColumnVector& |
|
291 ComplexColumnVector::operator -= (const ComplexColumnVector& a) |
|
292 { |
|
293 int len = length (); |
|
294 if (len != a.length ()) |
|
295 { |
|
296 (*current_liboctave_error_handler) |
|
297 ("nonconformant vector -= operation attempted"); |
|
298 return *this; |
|
299 } |
|
300 |
|
301 if (len == 0) |
|
302 return *this; |
|
303 |
|
304 Complex *d = fortran_vec (); // Ensures only one reference to my privates! |
|
305 |
|
306 subtract2 (d, a.data (), len); |
|
307 return *this; |
|
308 } |
|
309 |
|
310 // column vector by scalar -> column vector operations |
|
311 |
|
312 ComplexColumnVector |
|
313 operator + (const ComplexColumnVector& v, double s) |
|
314 { |
|
315 int len = v.length (); |
|
316 return ComplexColumnVector (add (v.data (), len, s), len); |
|
317 } |
|
318 |
|
319 ComplexColumnVector |
|
320 operator - (const ComplexColumnVector& v, double s) |
|
321 { |
|
322 int len = v.length (); |
|
323 return ComplexColumnVector (subtract (v.data (), len, s), len); |
|
324 } |
|
325 |
|
326 ComplexColumnVector |
|
327 operator * (const ComplexColumnVector& v, double s) |
|
328 { |
|
329 int len = v.length (); |
|
330 return ComplexColumnVector (multiply (v.data (), len, s), len); |
|
331 } |
|
332 |
|
333 ComplexColumnVector |
|
334 operator / (const ComplexColumnVector& v, double s) |
|
335 { |
|
336 int len = v.length (); |
|
337 return ComplexColumnVector (divide (v.data (), len, s), len); |
|
338 } |
|
339 |
1205
|
340 ComplexColumnVector |
|
341 operator + (const ColumnVector& a, const Complex& s) |
|
342 { |
|
343 int len = a.length (); |
|
344 return ComplexColumnVector (add (a.data (), len, s), len); |
|
345 } |
|
346 |
|
347 ComplexColumnVector |
|
348 operator - (const ColumnVector& a, const Complex& s) |
|
349 { |
|
350 int len = a.length (); |
|
351 return ComplexColumnVector (subtract (a.data (), len, s), len); |
|
352 } |
|
353 |
|
354 ComplexColumnVector |
|
355 operator * (const ColumnVector& a, const Complex& s) |
|
356 { |
|
357 int len = a.length (); |
|
358 return ComplexColumnVector (multiply (a.data (), len, s), len); |
|
359 } |
|
360 |
|
361 ComplexColumnVector |
|
362 operator / (const ColumnVector& a, const Complex& s) |
|
363 { |
|
364 int len = a.length (); |
|
365 return ComplexColumnVector (divide (a.data (), len, s), len); |
|
366 } |
|
367 |
458
|
368 // scalar by column vector -> column vector operations |
|
369 |
|
370 ComplexColumnVector |
|
371 operator + (double s, const ComplexColumnVector& a) |
|
372 { |
|
373 int a_len = a.length (); |
|
374 return ComplexColumnVector (add (a.data (), a_len, s), a_len); |
|
375 } |
|
376 |
|
377 ComplexColumnVector |
|
378 operator - (double s, const ComplexColumnVector& a) |
|
379 { |
|
380 int a_len = a.length (); |
|
381 return ComplexColumnVector (subtract (s, a.data (), a_len), a_len); |
|
382 } |
|
383 |
|
384 ComplexColumnVector |
|
385 operator * (double s, const ComplexColumnVector& a) |
|
386 { |
|
387 int a_len = a.length (); |
|
388 return ComplexColumnVector (multiply (a.data (), a_len, s), a_len); |
|
389 } |
|
390 |
|
391 ComplexColumnVector |
|
392 operator / (double s, const ComplexColumnVector& a) |
|
393 { |
|
394 int a_len = a.length (); |
|
395 return ComplexColumnVector (divide (s, a.data (), a_len), a_len); |
|
396 } |
|
397 |
1205
|
398 ComplexColumnVector |
|
399 operator + (const Complex& s, const ColumnVector& a) |
|
400 { |
|
401 int a_len = a.length (); |
|
402 return ComplexColumnVector (add (a.data (), a_len, s), a_len); |
|
403 } |
|
404 |
|
405 ComplexColumnVector |
|
406 operator - (const Complex& s, const ColumnVector& a) |
|
407 { |
|
408 int a_len = a.length (); |
|
409 return ComplexColumnVector (subtract (s, a.data (), a_len), a_len); |
|
410 } |
|
411 |
|
412 ComplexColumnVector |
|
413 operator * (const Complex& s, const ColumnVector& a) |
|
414 { |
|
415 int a_len = a.length (); |
|
416 return ComplexColumnVector (multiply (a.data (), a_len, s), a_len); |
|
417 } |
458
|
418 |
1205
|
419 ComplexColumnVector |
|
420 operator / (const Complex& s, const ColumnVector& a) |
458
|
421 { |
|
422 int a_len = a.length (); |
1205
|
423 return ComplexColumnVector (divide (s, a.data (), a_len), a_len); |
|
424 } |
|
425 |
|
426 // matrix by column vector -> column vector operations |
|
427 |
|
428 ComplexColumnVector |
|
429 operator * (const ComplexMatrix& m, const ColumnVector& a) |
|
430 { |
|
431 ComplexColumnVector tmp (a); |
|
432 return m * tmp; |
|
433 } |
|
434 |
|
435 ComplexColumnVector |
|
436 operator * (const ComplexMatrix& m, const ComplexColumnVector& a) |
|
437 { |
|
438 int nr = m.rows (); |
|
439 int nc = m.cols (); |
|
440 if (nc != a.length ()) |
458
|
441 { |
|
442 (*current_liboctave_error_handler) |
1205
|
443 ("nonconformant matrix multiplication attempted"); |
|
444 return ComplexColumnVector (); |
458
|
445 } |
|
446 |
1205
|
447 if (nc == 0 || nr == 0) |
|
448 return ComplexColumnVector (0); |
458
|
449 |
1205
|
450 int ld = nr; |
458
|
451 |
1205
|
452 Complex *y = new Complex [nr]; |
458
|
453 |
1253
|
454 F77_FCN (zgemv, ZGEMV) ("N", nr, nc, 1.0, m.data (), ld, a.data (), |
|
455 1, 0.0, y, 1, 1L); |
458
|
456 |
1205
|
457 return ComplexColumnVector (y, nr); |
458
|
458 } |
|
459 |
|
460 // column vector by column vector -> column vector operations |
|
461 |
|
462 ComplexColumnVector |
|
463 operator + (const ComplexColumnVector& v, const ColumnVector& a) |
|
464 { |
|
465 int len = v.length (); |
|
466 if (len != a.length ()) |
|
467 { |
|
468 (*current_liboctave_error_handler) |
|
469 ("nonconformant vector addition attempted"); |
|
470 return ComplexColumnVector (); |
|
471 } |
|
472 |
|
473 if (len == 0) |
|
474 return ComplexColumnVector (0); |
|
475 |
|
476 return ComplexColumnVector (add (v.data (), a.data (), len), len); |
|
477 } |
|
478 |
|
479 ComplexColumnVector |
|
480 operator - (const ComplexColumnVector& v, const ColumnVector& a) |
|
481 { |
|
482 int len = v.length (); |
|
483 if (len != a.length ()) |
|
484 { |
|
485 (*current_liboctave_error_handler) |
|
486 ("nonconformant vector subtraction attempted"); |
|
487 return ComplexColumnVector (); |
|
488 } |
|
489 |
|
490 if (len == 0) |
|
491 return ComplexColumnVector (0); |
|
492 |
|
493 return ComplexColumnVector (subtract (v.data (), a.data (), len), len); |
|
494 } |
|
495 |
|
496 ComplexColumnVector |
1205
|
497 operator + (const ColumnVector& v, const ComplexColumnVector& a) |
|
498 { |
|
499 int len = v.length (); |
|
500 if (len != a.length ()) |
|
501 { |
|
502 (*current_liboctave_error_handler) |
|
503 ("nonconformant vector subtraction attempted"); |
|
504 return ComplexColumnVector (); |
|
505 } |
|
506 |
|
507 if (len == 0) |
|
508 return ComplexColumnVector (0); |
|
509 |
|
510 return ComplexColumnVector (add (v.data (), a.data (), len), len); |
|
511 } |
|
512 |
|
513 ComplexColumnVector |
|
514 operator - (const ColumnVector& v, const ComplexColumnVector& a) |
|
515 { |
|
516 int len = v.length (); |
|
517 if (len != a.length ()) |
|
518 { |
|
519 (*current_liboctave_error_handler) |
|
520 ("nonconformant vector subtraction attempted"); |
|
521 return ComplexColumnVector (); |
|
522 } |
|
523 |
|
524 if (len == 0) |
|
525 return ComplexColumnVector (0); |
|
526 |
|
527 return ComplexColumnVector (subtract (v.data (), a.data (), len), len); |
|
528 } |
|
529 |
|
530 ComplexColumnVector |
458
|
531 product (const ComplexColumnVector& v, const ColumnVector& a) |
|
532 { |
|
533 int len = v.length (); |
|
534 if (len != a.length ()) |
|
535 { |
|
536 (*current_liboctave_error_handler) |
|
537 ("nonconformant vector product attempted"); |
|
538 return ComplexColumnVector (); |
|
539 } |
|
540 |
|
541 if (len == 0) |
|
542 return ComplexColumnVector (0); |
|
543 |
|
544 return ComplexColumnVector (multiply (v.data (), a.data (), len), len); |
|
545 } |
|
546 |
|
547 ComplexColumnVector |
|
548 quotient (const ComplexColumnVector& v, const ColumnVector& a) |
|
549 { |
|
550 int len = v.length (); |
|
551 if (len != a.length ()) |
|
552 { |
|
553 (*current_liboctave_error_handler) |
|
554 ("nonconformant vector quotient attempted"); |
|
555 return ComplexColumnVector (); |
|
556 } |
|
557 |
|
558 if (len == 0) |
|
559 return ComplexColumnVector (0); |
|
560 |
|
561 return ComplexColumnVector (divide (v.data (), a.data (), len), len); |
|
562 } |
|
563 |
1205
|
564 ComplexColumnVector |
|
565 product (const ColumnVector& v, const ComplexColumnVector& a) |
|
566 { |
|
567 int len = v.length (); |
|
568 if (len != a.length ()) |
|
569 { |
|
570 (*current_liboctave_error_handler) |
|
571 ("nonconformant vector product attempted"); |
|
572 return ColumnVector (); |
|
573 } |
|
574 |
|
575 if (len == 0) |
|
576 return ComplexColumnVector (0); |
|
577 |
|
578 return ComplexColumnVector (multiply (v.data (), a.data (), len), len); |
|
579 } |
|
580 |
|
581 ComplexColumnVector |
|
582 quotient (const ColumnVector& v, const ComplexColumnVector& a) |
|
583 { |
|
584 int len = v.length (); |
|
585 if (len != a.length ()) |
|
586 { |
|
587 (*current_liboctave_error_handler) |
|
588 ("nonconformant vector quotient attempted"); |
|
589 return ColumnVector (); |
|
590 } |
|
591 |
|
592 if (len == 0) |
|
593 return ComplexColumnVector (0); |
|
594 |
|
595 return ComplexColumnVector (divide (v.data (), a.data (), len), len); |
|
596 } |
|
597 |
|
598 // matrix by column vector -> column vector operations |
|
599 |
|
600 ComplexColumnVector |
|
601 operator * (const Matrix& m, const ComplexColumnVector& a) |
|
602 { |
|
603 ComplexMatrix tmp (m); |
|
604 return tmp * a; |
|
605 } |
|
606 |
|
607 // diagonal matrix by column vector -> column vector operations |
|
608 |
|
609 ComplexColumnVector |
|
610 operator * (const DiagMatrix& m, const ComplexColumnVector& a) |
|
611 { |
|
612 int nr = m.rows (); |
|
613 int nc = m.cols (); |
|
614 int a_len = a.length (); |
|
615 if (nc != a_len) |
|
616 { |
|
617 (*current_liboctave_error_handler) |
|
618 ("nonconformant matrix multiplication attempted"); |
|
619 return ColumnVector (); |
|
620 } |
|
621 |
|
622 if (nc == 0 || nr == 0) |
|
623 return ComplexColumnVector (0); |
|
624 |
|
625 ComplexColumnVector result (nr); |
|
626 |
|
627 for (int i = 0; i < a_len; i++) |
|
628 result.elem (i) = a.elem (i) * m.elem (i, i); |
|
629 |
1321
|
630 for (int i = a_len; i < nr; i++) |
1205
|
631 result.elem (i) = 0.0; |
|
632 |
|
633 return result; |
|
634 } |
|
635 |
|
636 ComplexColumnVector |
|
637 operator * (const ComplexDiagMatrix& m, const ColumnVector& a) |
|
638 { |
|
639 int nr = m.rows (); |
|
640 int nc = m.cols (); |
|
641 int a_len = a.length (); |
|
642 if (nc != a_len) |
|
643 { |
|
644 (*current_liboctave_error_handler) |
|
645 ("nonconformant matrix muliplication attempted"); |
|
646 return ComplexColumnVector (); |
|
647 } |
|
648 |
|
649 if (nc == 0 || nr == 0) |
|
650 return ComplexColumnVector (0); |
|
651 |
|
652 ComplexColumnVector result (nr); |
|
653 |
|
654 for (int i = 0; i < a_len; i++) |
|
655 result.elem (i) = a.elem (i) * m.elem (i, i); |
|
656 |
1321
|
657 for (int i = a_len; i < nr; i++) |
1205
|
658 result.elem (i) = 0.0; |
|
659 |
|
660 return result; |
|
661 } |
|
662 |
|
663 ComplexColumnVector |
|
664 operator * (const ComplexDiagMatrix& m, const ComplexColumnVector& a) |
|
665 { |
|
666 int nr = m.rows (); |
|
667 int nc = m.cols (); |
|
668 int a_len = a.length (); |
|
669 if (nc != a_len) |
|
670 { |
|
671 (*current_liboctave_error_handler) |
|
672 ("nonconformant matrix muliplication attempted"); |
|
673 return ComplexColumnVector (); |
|
674 } |
|
675 |
|
676 if (nc == 0 || nr == 0) |
|
677 return ComplexColumnVector (0); |
|
678 |
|
679 ComplexColumnVector result (nr); |
|
680 |
|
681 for (int i = 0; i < a_len; i++) |
|
682 result.elem (i) = a.elem (i) * m.elem (i, i); |
|
683 |
1321
|
684 for (int i = a_len; i < nr; i++) |
1205
|
685 result.elem (i) = 0.0; |
|
686 |
|
687 return result; |
|
688 } |
|
689 |
458
|
690 // other operations |
|
691 |
|
692 ComplexColumnVector |
|
693 map (c_c_Mapper f, const ComplexColumnVector& a) |
|
694 { |
|
695 ComplexColumnVector b (a); |
|
696 b.map (f); |
|
697 return b; |
|
698 } |
|
699 |
|
700 void |
|
701 ComplexColumnVector::map (c_c_Mapper f) |
|
702 { |
|
703 for (int i = 0; i < length (); i++) |
|
704 elem (i) = f (elem (i)); |
|
705 } |
|
706 |
|
707 Complex |
|
708 ComplexColumnVector::min (void) const |
|
709 { |
|
710 int len = length (); |
|
711 if (len == 0) |
|
712 return 0.0; |
|
713 |
|
714 Complex res = elem (0); |
|
715 double absres = abs (res); |
|
716 |
|
717 for (int i = 1; i < len; i++) |
|
718 if (abs (elem (i)) < absres) |
|
719 { |
|
720 res = elem (i); |
|
721 absres = abs (res); |
|
722 } |
|
723 |
|
724 return res; |
|
725 } |
|
726 |
|
727 Complex |
|
728 ComplexColumnVector::max (void) const |
|
729 { |
|
730 int len = length (); |
|
731 if (len == 0) |
|
732 return 0.0; |
|
733 |
|
734 Complex res = elem (0); |
|
735 double absres = abs (res); |
|
736 |
|
737 for (int i = 1; i < len; i++) |
|
738 if (abs (elem (i)) > absres) |
|
739 { |
|
740 res = elem (i); |
|
741 absres = abs (res); |
|
742 } |
|
743 |
|
744 return res; |
|
745 } |
|
746 |
|
747 // i/o |
|
748 |
|
749 ostream& |
|
750 operator << (ostream& os, const ComplexColumnVector& a) |
|
751 { |
|
752 // int field_width = os.precision () + 7; |
|
753 for (int i = 0; i < a.length (); i++) |
|
754 os << /* setw (field_width) << */ a.elem (i) << "\n"; |
|
755 return os; |
|
756 } |
|
757 |
|
758 istream& |
|
759 operator >> (istream& is, ComplexColumnVector& a) |
|
760 { |
|
761 int len = a.length(); |
|
762 |
|
763 if (len < 1) |
|
764 is.clear (ios::badbit); |
|
765 else |
|
766 { |
|
767 double tmp; |
|
768 for (int i = 0; i < len; i++) |
|
769 { |
|
770 is >> tmp; |
|
771 if (is) |
|
772 a.elem (i) = tmp; |
|
773 else |
|
774 break; |
|
775 } |
|
776 } |
532
|
777 return is; |
458
|
778 } |
|
779 |
|
780 /* |
|
781 ;;; Local Variables: *** |
|
782 ;;; mode: C++ *** |
|
783 ;;; page-delimiter: "^/\\*" *** |
|
784 ;;; End: *** |
|
785 */ |