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