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_DOUBLE_H_
00042 #define _LA_GEN_MAT_DOUBLE_H_
00043
00044 #include "arch.h"
00045 #include "lafnames.h"
00046 #include VECTOR_DOUBLE_H
00047 #include LA_INDEX_H
00048 #include LA_GEN_MAT_FLOAT_H
00049
00050 class LaGenMatComplex;
00051 class LaGenMatDouble;
00052 class LaGenMatFloat;
00053 class LaGenMatInt;
00054 class LaGenMatLongInt;
00055
00078 class DLLIMPORT LaGenMatDouble
00079 {
00080 public:
00082 typedef double value_type;
00086 typedef LaGenMatDouble matrix_type;
00089 typedef VectorDouble vec_type;
00090 private:
00091 vec_type v;
00092 LaIndex ii[2];
00093 int dim[2];
00094 int sz[2];
00095 void init(int m, int n);
00096 static int debug_;
00097
00098
00099
00100 static int *info_;
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122 int shallow_;
00123
00124
00125
00126
00127
00128
00129
00130
00131 public:
00132
00135
00136
00137
00138
00140 LaGenMatDouble();
00141
00144 LaGenMatDouble(int m, int n);
00145
00182 LaGenMatDouble(double*v, int m, int n, bool row_ordering=false);
00183
00206 LaGenMatDouble(const LaGenMatDouble&);
00207
00210 explicit LaGenMatDouble(const LaGenMatFloat&);
00211
00215 LaGenMatDouble& resize(int m, int n);
00216
00220 LaGenMatDouble& resize(const LaGenMatDouble& s);
00221
00224 virtual ~LaGenMatDouble();
00226
00227
00232 bool is_zero() const;
00233
00236 bool is_submatrixview() const
00237 { return size(0) != gdim(0) || size(1) != gdim(1); };
00238
00243 bool has_unitstride() const
00244 { return inc(0) == 1 && inc(1) == 1; };
00245
00248 bool equal_to(const LaGenMatDouble& mat) const;
00250
00251
00254
00255
00256
00257
00260 inline int size(int d) const;
00263 inline int cols() const { return size(1); }
00266 inline int rows() const { return size(0); }
00267
00273 inline int inc(int d) const;
00274
00279 inline int gdim(int d) const;
00280
00285 inline int start(int d) const;
00286
00291 inline int end(int d) const;
00292
00297 inline LaIndex index(int d) const;
00298
00302 inline int ref_count() const;
00303
00306 inline double* addr() const;
00308
00325 inline double& operator()(int i, int j);
00326
00340 inline double& operator()(int i, int j) const;
00341
00353 LaGenMatDouble operator()(const LaIndex& I, const LaIndex& J) ;
00354
00366 LaGenMatDouble operator()(const LaIndex& I, const LaIndex& J) const;
00367
00374 LaGenMatDouble row(int k);
00381 LaGenMatDouble row(int k) const;
00388 LaGenMatDouble col(int k);
00395 LaGenMatDouble col(int k) const;
00397
00404 LaGenMatDouble& operator=(double s);
00405
00441 LaGenMatDouble& operator=(const LaGenMatDouble& s);
00442
00451 LaGenMatDouble& operator+=(double s);
00452
00457 LaGenMatDouble& add(double s);
00458
00463 LaGenMatDouble& operator*=(double s);
00464
00469 LaGenMatDouble& scale(double s);
00470
00479 LaGenMatDouble& inject(const LaGenMatDouble& s);
00480
00485 LaGenMatDouble& copy(const LaGenMatDouble& s);
00486
00491 LaGenMatDouble copy() const;
00492
00497 inline LaGenMatDouble& shallow_assign();
00498
00506 LaGenMatDouble& ref(const LaGenMatDouble& s);
00508
00514 LaGenMatDouble repmat (int M, int N) const;
00517 value_type trace () const;
00521 LaGenMatDouble diag () const;
00523
00527 inline int shallow() const
00528 { return shallow_;}
00530 inline int debug() const;
00532 inline int debug(int d);
00544 inline const LaGenMatDouble& info() const {
00545 *(const_cast<LaGenMatDouble*>(this)->info_) = 1;
00546 return *this;
00547 };
00548
00551 inline std::ostream& Info(std::ostream& s) const
00552 {
00553 s << "Size: (" << size(0) << "x" << size(1) << ") " ;
00554 s << "Indeces: " << ii[0] << " " << ii[1];
00555 s << "#ref: " << ref_count()
00556 << "addr: " << addr() << " shallow:" << shallow_ << std::endl;
00557 return s;
00558 };
00560
00567 friend DLLIMPORT std::ostream& operator<<(std::ostream&, const LaGenMatDouble&);
00568
00572 LaGenMatComplex to_LaGenMatComplex() const;
00574 LaGenMatFloat to_LaGenMatFloat() const;
00576 LaGenMatInt to_LaGenMatInt() const;
00578 LaGenMatLongInt to_LaGenMatLongInt() const;
00580
00581
00587 static LaGenMatDouble zeros (int N, int M=0);
00591 static LaGenMatDouble ones (int N, int M=0);
00595 static LaGenMatDouble eye (int N, int M=0);
00604 static LaGenMatDouble rand (int N, int M,
00605 value_type low=0, value_type high=1);
00609 static LaGenMatDouble from_diag (const LaGenMatDouble &vect);
00613 static LaGenMatDouble linspace (value_type start, value_type end,
00614 int nr_points);
00616
00617 };
00618
00619 namespace la {
00621 typedef LaGenMatDouble mat;
00622 }
00623
00631 DLLIMPORT
00632 std::ostream& operator<<(std::ostream&, const LaGenMatDouble&);
00633
00634
00635
00636
00637 inline int LaGenMatDouble::size(int d) const
00638 {
00639 return sz[d];
00640 }
00641
00642 inline int LaGenMatDouble::inc(int d) const
00643 {
00644 return ii[d].inc();
00645 }
00646
00647 inline int LaGenMatDouble::gdim(int d) const
00648 {
00649 return dim[d];
00650 }
00651
00652 inline int LaGenMatDouble::start(int d) const
00653 {
00654 return ii[d].start();
00655 }
00656
00657 inline int LaGenMatDouble::end(int d) const
00658 {
00659 return ii[d].end();
00660 }
00661
00662 inline int LaGenMatDouble::ref_count() const
00663 {
00664 return v.ref_count();
00665 }
00666
00667
00668 inline LaIndex LaGenMatDouble::index(int d) const
00669 {
00670 return ii[d];
00671 }
00672
00673 inline double* LaGenMatDouble::addr() const
00674 {
00675 return v.addr();
00676 }
00677
00678 inline int LaGenMatDouble::debug() const
00679 {
00680 return debug_;
00681 }
00682
00683 inline int LaGenMatDouble::debug(int d)
00684 {
00685 return debug_ = d;
00686 }
00687
00688 inline double& LaGenMatDouble::operator()(int i, int j)
00689 {
00690 #ifdef LA_BOUNDS_CHECK
00691 assert(i>=0);
00692 assert(i<size(0));
00693 assert(j>=0);
00694 assert(j<size(1));
00695 #endif
00696 return v( dim[0]*(ii[1].start() + j*ii[1].inc()) +
00697 ii[0].start() + i*ii[0].inc());
00698 }
00699
00700 inline double& LaGenMatDouble::operator()(int i, int j) const
00701 {
00702
00703 #ifdef LA_BOUNDS_CHECK
00704 assert(i>=0);
00705 assert(i<size(0));
00706 assert(j>=0);
00707 assert(j<size(1));
00708 #endif
00709
00710 return v( dim[0]*(ii[1].start() + j*ii[1].inc()) +
00711 ii[0].start() + i*ii[0].inc());
00712 }
00713
00714 inline LaGenMatDouble& LaGenMatDouble::shallow_assign()
00715 {
00716 shallow_ = 1;
00717 return *this;
00718 }
00719
00720
00721 #endif
00722