comparison liboctave/CRowVector.cc @ 1205:8302fab9fe24

[project @ 1995-04-04 02:05:01 by jwe]
author jwe
date Tue, 04 Apr 1995 02:05:01 +0000
parents b6360f2d4fa6
children 0bf4d2b7def4
comparison
equal deleted inserted replaced
1204:68d147abe7ca 1205:8302fab9fe24
61 { 61 {
62 for (int i = 0; i < length (); i++) 62 for (int i = 0; i < length (); i++)
63 elem (i) = a.elem (i); 63 elem (i) = a.elem (i);
64 } 64 }
65 65
66 #if 0
67 ComplexRowVector&
68 ComplexRowVector::resize (int n)
69 {
70 if (n < 0)
71 {
72 (*current_liboctave_error_handler)
73 ("can't resize to negative dimension");
74 return *this;
75 }
76
77 Complex *new_data = 0;
78 if (n > 0)
79 {
80 new_data = new Complex [n];
81 int min_len = len < n ? len : n;
82
83 for (int i = 0; i < min_len; i++)
84 new_data[i] = data[i];
85 }
86
87 delete [] data;
88 len = n;
89 data = new_data;
90
91 return *this;
92 }
93
94 ComplexRowVector&
95 ComplexRowVector::resize (int n, double val)
96 {
97 int old_len = len;
98 resize (n);
99 for (int i = old_len; i < len; i++)
100 data[i] = val;
101
102 return *this;
103 }
104
105 ComplexRowVector&
106 ComplexRowVector::resize (int n, const Complex& val)
107 {
108 int old_len = len;
109 resize (n);
110 for (int i = old_len; i < len; i++)
111 data[i] = val;
112
113 return *this;
114 }
115 #endif
116
117 int 66 int
118 ComplexRowVector::operator == (const ComplexRowVector& a) const 67 ComplexRowVector::operator == (const ComplexRowVector& a) const
119 { 68 {
120 int len = length (); 69 int len = length ();
121 if (len != a.length ()) 70 if (len != a.length ())
253 { 202 {
254 int len = length (); 203 int len = length ();
255 return ComplexColumnVector (dup (data (), len), len); 204 return ComplexColumnVector (dup (data (), len), len);
256 } 205 }
257 206
258 RowVector
259 real (const ComplexRowVector& a)
260 {
261 int a_len = a.length ();
262 RowVector retval;
263 if (a_len > 0)
264 retval = RowVector (real_dup (a.data (), a_len), a_len);
265 return retval;
266 }
267
268 RowVector
269 imag (const ComplexRowVector& a)
270 {
271 int a_len = a.length ();
272 RowVector retval;
273 if (a_len > 0)
274 retval = RowVector (imag_dup (a.data (), a_len), a_len);
275 return retval;
276 }
277
278 ComplexRowVector 207 ComplexRowVector
279 conj (const ComplexRowVector& a) 208 conj (const ComplexRowVector& a)
280 { 209 {
281 int a_len = a.length (); 210 int a_len = a.length ();
282 ComplexRowVector retval; 211 ComplexRowVector retval;
412 { 341 {
413 int len = v.length (); 342 int len = v.length ();
414 return ComplexRowVector (divide (v.data (), len, s), len); 343 return ComplexRowVector (divide (v.data (), len, s), len);
415 } 344 }
416 345
346 ComplexRowVector
347 operator + (const RowVector& v, const Complex& s)
348 {
349 int len = v.length ();
350 return ComplexRowVector (add (v.data (), len, s), len);
351 }
352
353 ComplexRowVector
354 operator - (const RowVector& v, const Complex& s)
355 {
356 int len = v.length ();
357 return ComplexRowVector (subtract (v.data (), len, s), len);
358 }
359
360 ComplexRowVector
361 operator * (const RowVector& v, const Complex& s)
362 {
363 int len = v.length ();
364 return ComplexRowVector (multiply (v.data (), len, s), len);
365 }
366
367 ComplexRowVector
368 operator / (const RowVector& v, const Complex& s)
369 {
370 int len = v.length ();
371 return ComplexRowVector (divide (v.data (), len, s), len);
372 }
373
417 // scalar by row vector -> row vector operations 374 // scalar by row vector -> row vector operations
418 375
419 ComplexRowVector 376 ComplexRowVector
420 operator + (double s, const ComplexRowVector& a) 377 operator + (double s, const ComplexRowVector& a)
421 { 378 {
442 { 399 {
443 int a_len = a.length (); 400 int a_len = a.length ();
444 return ComplexRowVector (divide (s, a.data (), a_len), a_len); 401 return ComplexRowVector (divide (s, a.data (), a_len), a_len);
445 } 402 }
446 403
447 // row vector by column vector -> scalar 404 ComplexRowVector
448 405 operator + (const Complex& s, const RowVector& a)
449 Complex 406 {
450 operator * (const ComplexRowVector& v, const ColumnVector& a) 407 return ComplexRowVector ();
451 { 408 }
452 ComplexColumnVector tmp (a); 409
453 return v * tmp; 410 ComplexRowVector
454 } 411 operator - (const Complex& s, const RowVector& a)
455 412 {
456 Complex 413 return ComplexRowVector ();
457 operator * (const ComplexRowVector& v, const ComplexColumnVector& a) 414 }
458 { 415
459 int len = v.length (); 416 ComplexRowVector
460 if (len != a.length ()) 417 operator * (const Complex& s, const RowVector& a)
461 { 418 {
462 (*current_liboctave_error_handler) 419 return ComplexRowVector ();
463 ("nonconformant vector multiplication attempted"); 420 }
464 return 0.0; 421
465 } 422 ComplexRowVector
466 423 operator / (const Complex& s, const RowVector& a)
467 Complex retval (0.0, 0.0); 424 {
468 425 return ComplexRowVector ();
469 for (int i = 0; i < len; i++)
470 retval += v.elem (i) * a.elem (i);
471
472 return retval;
473 } 426 }
474 427
475 // row vector by matrix -> row vector 428 // row vector by matrix -> row vector
476 429
477 ComplexRowVector 430 ComplexRowVector
505 v.data (), &i_one, &beta, y, &i_one, 1L); 458 v.data (), &i_one, &beta, y, &i_one, 1L);
506 459
507 return ComplexRowVector (y, len); 460 return ComplexRowVector (y, len);
508 } 461 }
509 462
463 ComplexRowVector
464 operator * (const RowVector& v, const ComplexMatrix& a)
465 {
466 ComplexRowVector tmp (v);
467 return tmp * a;
468 }
469
510 // row vector by row vector -> row vector operations 470 // row vector by row vector -> row vector operations
511 471
512 ComplexRowVector 472 ComplexRowVector
513 operator + (const ComplexRowVector& v, const RowVector& a) 473 operator + (const ComplexRowVector& v, const RowVector& a)
514 { 474 {
542 502
543 return ComplexRowVector (subtract (v.data (), a.data (), len), len); 503 return ComplexRowVector (subtract (v.data (), a.data (), len), len);
544 } 504 }
545 505
546 ComplexRowVector 506 ComplexRowVector
507 operator + (const RowVector& v, const ComplexRowVector& a)
508 {
509 int len = v.length ();
510 if (len != a.length ())
511 {
512 (*current_liboctave_error_handler)
513 ("nonconformant vector addition attempted");
514 return ComplexRowVector ();
515 }
516
517 if (len == 0)
518 return ComplexRowVector (0);
519
520 return ComplexRowVector (add (v.data (), a.data (), len), len);
521 }
522
523 ComplexRowVector
524 operator - (const RowVector& v, const ComplexRowVector& a)
525 {
526 int len = v.length ();
527 if (len != a.length ())
528 {
529 (*current_liboctave_error_handler)
530 ("nonconformant vector subtraction attempted");
531 return ComplexRowVector ();
532 }
533
534 if (len == 0)
535 return ComplexRowVector (0);
536
537 return ComplexRowVector (subtract (v.data (), a.data (), len), len);
538 }
539
540 ComplexRowVector
547 product (const ComplexRowVector& v, const RowVector& a) 541 product (const ComplexRowVector& v, const RowVector& a)
548 { 542 {
549 int len = v.length (); 543 int len = v.length ();
550 if (len != a.length ()) 544 if (len != a.length ())
551 { 545 {
560 return ComplexRowVector (multiply (v.data (), a.data (), len), len); 554 return ComplexRowVector (multiply (v.data (), a.data (), len), len);
561 } 555 }
562 556
563 ComplexRowVector 557 ComplexRowVector
564 quotient (const ComplexRowVector& v, const RowVector& a) 558 quotient (const ComplexRowVector& v, const RowVector& a)
559 {
560 int len = v.length ();
561 if (len != a.length ())
562 {
563 (*current_liboctave_error_handler)
564 ("nonconformant vector quotient attempted");
565 return ComplexRowVector ();
566 }
567
568 if (len == 0)
569 return ComplexRowVector (0);
570
571 return ComplexRowVector (divide (v.data (), a.data (), len), len);
572 }
573
574 ComplexRowVector
575 product (const RowVector& v, const ComplexRowVector& a)
576 {
577 int len = v.length ();
578 if (len != a.length ())
579 {
580 (*current_liboctave_error_handler)
581 ("nonconformant vector product attempted");
582 return ComplexRowVector ();
583 }
584
585 if (len == 0)
586 return ComplexRowVector (0);
587
588 return ComplexRowVector (multiply (v.data (), a.data (), len), len);
589 }
590
591 ComplexRowVector
592 quotient (const RowVector& v, const ComplexRowVector& a)
565 { 593 {
566 int len = v.length (); 594 int len = v.length ();
567 if (len != a.length ()) 595 if (len != a.length ())
568 { 596 {
569 (*current_liboctave_error_handler) 597 (*current_liboctave_error_handler)
585 ComplexRowVector b (a); 613 ComplexRowVector b (a);
586 b.map (f); 614 b.map (f);
587 return b; 615 return b;
588 } 616 }
589 617
590 RowVector
591 map (d_c_Mapper f, const ComplexRowVector& a)
592 {
593 int a_len = a.length ();
594 RowVector b (a_len);
595 for (int i = 0; i < a_len; i++)
596 b.elem (i) = f (a.elem (i));
597 return b;
598 }
599
600 void 618 void
601 ComplexRowVector::map (c_c_Mapper f) 619 ComplexRowVector::map (c_c_Mapper f)
602 { 620 {
603 for (int i = 0; i < length (); i++) 621 for (int i = 0; i < length (); i++)
604 elem (i) = f (elem (i)); 622 elem (i) = f (elem (i));
605 }
606
607 ComplexRowVector
608 linspace (const Complex& x1, const Complex& x2, int n)
609 {
610 ComplexRowVector retval;
611
612 if (n > 0)
613 {
614 retval.resize (n);
615 Complex delta = (x2 - x1) / (n - 1);
616 retval.elem (0) = x1;
617 for (int i = 1; i < n-1; i++)
618 retval.elem (i) = x1 + i * delta;
619 retval.elem (n-1) = x2;
620 }
621
622 return retval;
623 } 623 }
624 624
625 Complex 625 Complex
626 ComplexRowVector::min (void) const 626 ComplexRowVector::min (void) const
627 { 627 {
693 } 693 }
694 } 694 }
695 return is; 695 return is;
696 } 696 }
697 697
698 // row vector by column vector -> scalar
699
700 // row vector by column vector -> scalar
701
702 Complex
703 operator * (const ComplexRowVector& v, const ColumnVector& a)
704 {
705 ComplexColumnVector tmp (a);
706 return v * tmp;
707 }
708
709 Complex
710 operator * (const ComplexRowVector& v, const ComplexColumnVector& a)
711 {
712 int len = v.length ();
713 if (len != a.length ())
714 {
715 (*current_liboctave_error_handler)
716 ("nonconformant vector multiplication attempted");
717 return 0.0;
718 }
719
720 Complex retval (0.0, 0.0);
721
722 for (int i = 0; i < len; i++)
723 retval += v.elem (i) * a.elem (i);
724
725 return retval;
726 }
727
728 // other operations
729
730 ComplexRowVector
731 linspace (const Complex& x1, const Complex& x2, int n)
732 {
733 ComplexRowVector retval;
734
735 if (n > 0)
736 {
737 retval.resize (n);
738 Complex delta = (x2 - x1) / (n - 1);
739 retval.elem (0) = x1;
740 for (int i = 1; i < n-1; i++)
741 retval.elem (i) = x1 + i * delta;
742 retval.elem (n-1) = x2;
743 }
744
745 return retval;
746 }
747
698 /* 748 /*
699 ;;; Local Variables: *** 749 ;;; Local Variables: ***
700 ;;; mode: C++ *** 750 ;;; mode: C++ ***
701 ;;; page-delimiter: "^/\\*" *** 751 ;;; page-delimiter: "^/\\*" ***
702 ;;; End: *** 752 ;;; End: ***