00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #ifndef _LA_GEN_MAT_COMPLEX_H_
00042 #define _LA_GEN_MAT_COMPLEX_H_
00043
00044 #ifndef LA_COMPLEX_SUPPORT
00045
00046
00047 # error "The macro LA_COMPLEX_SUPPORT needs to be defined if you want to use complex-valued matrices."
00048 #endif
00049
00050 #include "arch.h"
00051 #include "lafnames.h"
00052 #include VECTOR_COMPLEX_H
00053 #include LA_INDEX_H
00054 #include LA_GEN_MAT_DOUBLE_H
00055
00056 class LaGenMatComplex;
00057 class LaGenMatDouble;
00058 class LaGenMatFloat;
00059 class LaGenMatInt;
00060 class LaGenMatLongInt;
00061
00088 class DLLIMPORT LaGenMatComplex
00089 {
00090 public:
00092 typedef COMPLEX value_type;
00096 typedef LaGenMatComplex matrix_type;
00099 typedef VectorComplex vec_type;
00100 private:
00101 vec_type v;
00102 LaIndex ii[2];
00103 int dim[2];
00104
00105 void init(int m, int n);
00106 int size0;
00107 int size1;
00108 static int debug_;
00109
00110
00111
00112 static int *info_;
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134 int shallow_;
00135
00136
00137
00138
00139
00140
00141
00142
00143 public:
00144
00145
00148
00149
00150
00151
00153 LaGenMatComplex();
00154
00157 LaGenMatComplex(int m, int n);
00158
00195 LaGenMatComplex(COMPLEX*v, int m, int n, bool row_ordering=false);
00196
00219 LaGenMatComplex(const LaGenMatComplex&);
00220
00225 explicit LaGenMatComplex(const LaGenMatDouble& s_real,
00226 const LaGenMatDouble& s_imag = LaGenMatDouble());
00227
00231 LaGenMatComplex& resize(int m, int n);
00232
00236 LaGenMatComplex& resize(const LaGenMatComplex& s);
00237
00240 virtual ~LaGenMatComplex();
00242
00243
00248 bool is_zero() const;
00249
00252 bool is_submatrixview() const
00253 { return size(0) != gdim(0) || size(1) != gdim(1); };
00254
00259 bool has_unitstride() const
00260 { return inc(0) == 1 && inc(1) == 1; };
00261
00264 bool equal_to(const LaGenMatComplex& mat) const;
00266
00267
00270
00271
00272
00273
00276 inline int size(int d) const;
00279 inline int cols() const { return size(1); }
00282 inline int rows() const { return size(0); }
00283
00289 inline int inc(int d) const;
00290
00295 inline int gdim(int d) const;
00296
00301 inline int start(int d) const;
00302
00307 inline int end(int d) const;
00308
00313 inline LaIndex index(int d) const;
00314
00318 inline int ref_count() const;
00319
00322 inline COMPLEX* addr() const;
00324
00341 inline COMPLEX& operator()(int i, int j);
00342
00357 inline COMPLEX& operator()(int i, int j) const;
00358
00370 LaGenMatComplex operator()(const LaIndex& I, const LaIndex& J) ;
00371
00383 LaGenMatComplex operator()(const LaIndex& I, const LaIndex& J) const;
00384
00391 LaGenMatComplex row(int k);
00398 LaGenMatComplex row(int k) const;
00405 LaGenMatComplex col(int k);
00412 LaGenMatComplex col(int k) const;
00414
00421 LaGenMatComplex& operator=(COMPLEX s);
00422
00423
00428 LaGenMatComplex& operator=(const LaComplex& s);
00429
00430
00431
00432
00433
00434
00435
00436
00472 LaGenMatComplex& operator=(const LaGenMatComplex& s);
00473
00482 LaGenMatComplex& operator+=(COMPLEX s);
00483
00488 LaGenMatComplex& add(COMPLEX s);
00489
00494 LaGenMatComplex& scale(const LaComplex& s);
00495
00500 LaGenMatComplex& scale(COMPLEX s);
00501
00506 LaGenMatComplex& operator*=(COMPLEX s);
00507
00516 LaGenMatComplex& inject(const LaGenMatComplex& s);
00517
00522 LaGenMatComplex& copy(const LaGenMatComplex& s);
00523
00528 LaGenMatComplex copy() const;
00529
00537 LaGenMatComplex& copy(const LaGenMatDouble& s_real,
00538 const LaGenMatDouble& s_imag = LaGenMatDouble());
00539
00544 inline LaGenMatComplex& shallow_assign();
00545
00553 LaGenMatComplex& ref(const LaGenMatComplex& s);
00555
00561 LaGenMatComplex repmat (int M, int N) const;
00564 value_type trace () const;
00568 LaGenMatComplex diag () const;
00569
00574 LaGenMatDouble real() const;
00575
00580 LaGenMatDouble imag() const;
00582
00583
00587 inline int shallow() const
00588 { return shallow_;}
00590 inline int debug() const;
00592 inline int debug(int d);
00593
00605 inline const LaGenMatComplex& info() const {
00606 *(const_cast<LaGenMatComplex*>(this)->info_) = 1;
00607 return *this;
00608 };
00609
00612 inline std::ostream& Info(std::ostream& s) const
00613 {
00614 s << "Size: (" << size(0) << "x" << size(1) << ") " ;
00615 s << "Indeces: " << ii[0] << " " << ii[1];
00616 s << "#ref: " << ref_count() << "addr: " << addr() << std::endl;
00617 return s;
00618 };
00620
00627 friend DLLIMPORT std::ostream& operator<<(std::ostream&, const LaGenMatComplex&);
00628
00633 LaGenMatDouble real_to_LaGenMatDouble() const;
00636 LaGenMatFloat real_to_LaGenMatFloat() const;
00638 LaGenMatInt real_to_LaGenMatInt() const;
00641 LaGenMatLongInt real_to_LaGenMatLongInt() const;
00644 LaGenMatDouble imag_to_LaGenMatDouble() const;
00647 LaGenMatFloat imag_to_LaGenMatFloat() const;
00650 LaGenMatInt imag_to_LaGenMatInt() const;
00653 LaGenMatLongInt imag_to_LaGenMatLongInt() const;
00655
00656
00662 static LaGenMatComplex zeros (int N, int M=0);
00666 static LaGenMatComplex ones (int N, int M=0);
00670 static LaGenMatComplex eye (int N, int M=0);
00680 static LaGenMatComplex rand (int N, int M,
00681 double low=0, double high=1);
00685 static LaGenMatComplex from_diag (const LaGenMatComplex &vect);
00689 static LaGenMatComplex linspace (value_type start,
00690 value_type end,
00691 int nr_points);
00693
00694 };
00695
00696
00697
00698 namespace la {
00701 typedef LaGenMatComplex cmat;
00702 }
00703
00711 DLLIMPORT
00712 std::ostream& operator<<(std::ostream&, const LaGenMatComplex&);
00713
00714
00715
00716
00717
00718
00719 inline int LaGenMatComplex::size(int d) const
00720 {
00721 if (d==0)
00722 return size0;
00723 else
00724 return size1;
00725
00726 }
00727
00728 inline int LaGenMatComplex::inc(int d) const
00729 {
00730 return ii[d].inc();
00731 }
00732
00733 inline int LaGenMatComplex::gdim(int d) const
00734 {
00735 return dim[d];
00736 }
00737
00738 inline int LaGenMatComplex::start(int d) const
00739 {
00740 return ii[d].start();
00741 }
00742
00743 inline int LaGenMatComplex::end(int d) const
00744 {
00745 return ii[d].end();
00746 }
00747
00748 inline int LaGenMatComplex::ref_count() const
00749 {
00750 return v.ref_count();
00751 }
00752
00753
00754 inline LaIndex LaGenMatComplex::index(int d) const
00755 {
00756 return ii[d];
00757 }
00758
00759 inline COMPLEX* LaGenMatComplex::addr() const
00760 {
00761 return v.addr();
00762 }
00763
00764 inline int LaGenMatComplex::debug() const
00765 {
00766 return debug_;
00767 }
00768
00769 inline int LaGenMatComplex::debug(int d)
00770 {
00771 return debug_ = d;
00772 }
00773
00774 inline COMPLEX& LaGenMatComplex::operator()(int i, int j)
00775 {
00776
00777 #ifdef LA_BOUNDS_CHECK
00778 assert(i>=0);
00779 assert(i<size(0));
00780 assert(j>=0);
00781 assert(j<size(1));
00782 #endif
00783 return v( dim[0]*(ii[1].start() + j*ii[1].inc()) +
00784 ii[0].start() + i*ii[0].inc());
00785 }
00786
00787 inline COMPLEX& LaGenMatComplex::operator()(int i, int j) const
00788 {
00789
00790 #ifdef LA_BOUNDS_CHECK
00791 assert(i>=0);
00792 assert(i<size(0));
00793 assert(j>=0);
00794 assert(j<size(1));
00795 #endif
00796
00797 return v( dim[0]*(ii[1].start() + j*ii[1].inc()) +
00798 ii[0].start() + i*ii[0].inc());
00799 }
00800
00801
00802
00803
00804 inline LaGenMatComplex& LaGenMatComplex::shallow_assign()
00805 {
00806 shallow_ = 1;
00807 return *this;
00808 }
00809
00810
00811
00812 #ifndef LA_COMPLEX_SUPPORT
00813
00814 # error "The macro LA_COMPLEX_SUPPORT needs to be defined if you want to use complex-valued matrices."
00815 #endif
00816
00817
00818 #endif
00819