Go to the documentation of this file.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 {
00238 return size(0) != gdim(0) || size(1) != gdim(1);
00239 };
00240
00245 bool has_unitstride() const
00246 {
00247 return inc(0) == 1 && inc(1) == 1;
00248 };
00249
00252 bool equal_to(const LaGenMatDouble& mat) const;
00254
00255
00258
00259
00260
00261
00264 inline int size(int d) const;
00267 inline int cols() const
00268 {
00269 return size(1);
00270 }
00273 inline int rows() const
00274 {
00275 return size(0);
00276 }
00277
00283 inline int inc(int d) const;
00284
00289 inline int gdim(int d) const;
00290
00295 inline int start(int d) const;
00296
00301 inline int end(int d) const;
00302
00307 inline LaIndex index(int d) const;
00308
00312 inline int ref_count() const;
00313
00316 inline double* addr() const;
00318
00335 inline double& operator()(int i, int j);
00336
00350 inline const double& operator()(int i, int j) const;
00351
00363 LaGenMatDouble operator()(const LaIndex& I, const LaIndex& J) ;
00364
00376 LaGenMatDouble operator()(const LaIndex& I, const LaIndex& J) const;
00377
00384 LaGenMatDouble row(int k);
00391 LaGenMatDouble row(int k) const;
00398 LaGenMatDouble col(int k);
00405 LaGenMatDouble col(int k) const;
00407
00414 LaGenMatDouble& operator=(double s);
00415
00451 LaGenMatDouble& operator=(const LaGenMatDouble& s);
00452
00461 LaGenMatDouble& operator+=(double s);
00462
00467 LaGenMatDouble& add(double s);
00468
00473 LaGenMatDouble& operator*=(double s);
00474
00479 LaGenMatDouble& scale(double s);
00480
00489 LaGenMatDouble& inject(const LaGenMatDouble& s);
00490
00495 LaGenMatDouble& copy(const LaGenMatDouble& s);
00496
00501 LaGenMatDouble copy() const;
00502
00507 inline LaGenMatDouble& shallow_assign();
00508
00516 LaGenMatDouble& ref(const LaGenMatDouble& s);
00518
00524 LaGenMatDouble repmat (int M, int N) const;
00527 value_type trace () const;
00531 LaGenMatDouble diag () const;
00533
00537 inline int shallow() const
00538 {
00539 return shallow_;
00540 }
00542 inline int debug() const;
00544 inline int debug(int d);
00556 inline const LaGenMatDouble& info() const
00557 {
00558 *(const_cast<LaGenMatDouble*>(this)->info_) = 1;
00559 return *this;
00560 };
00561
00564 inline std::ostream& Info(std::ostream& s) const
00565 {
00566 s << "Size: (" << size(0) << "x" << size(1) << ") " ;
00567 s << "Indeces: " << ii[0] << " " << ii[1];
00568 s << "#ref: " << ref_count()
00569 << "addr: " << addr() << " shallow:" << shallow_ << std::endl;
00570 return s;
00571 };
00573
00580 friend DLLIMPORT std::ostream& operator<<(std::ostream&, const LaGenMatDouble&);
00581
00585 LaGenMatComplex to_LaGenMatComplex() const;
00587 LaGenMatFloat to_LaGenMatFloat() const;
00589 LaGenMatInt to_LaGenMatInt() const;
00591 LaGenMatLongInt to_LaGenMatLongInt() const;
00593
00594
00600 static LaGenMatDouble zeros (int N, int M = 0);
00604 static LaGenMatDouble ones (int N, int M = 0);
00608 static LaGenMatDouble eye (int N, int M = 0);
00617 static LaGenMatDouble rand (int N, int M,
00618 value_type low = 0, value_type high = 1);
00622 static LaGenMatDouble from_diag (const LaGenMatDouble &vect);
00626 static LaGenMatDouble linspace (value_type start, value_type end,
00627 int nr_points);
00629
00630 };
00631
00632 namespace la
00633 {
00635 typedef LaGenMatDouble mat;
00636 }
00637
00645 DLLIMPORT
00646 std::ostream& operator<<(std::ostream&, const LaGenMatDouble&);
00647
00648
00649
00650
00651 inline int LaGenMatDouble::size(int d) const
00652 {
00653 return sz[d];
00654 }
00655
00656 inline int LaGenMatDouble::inc(int d) const
00657 {
00658 return ii[d].inc();
00659 }
00660
00661 inline int LaGenMatDouble::gdim(int d) const
00662 {
00663 return dim[d];
00664 }
00665
00666 inline int LaGenMatDouble::start(int d) const
00667 {
00668 return ii[d].start();
00669 }
00670
00671 inline int LaGenMatDouble::end(int d) const
00672 {
00673 return ii[d].end();
00674 }
00675
00676 inline int LaGenMatDouble::ref_count() const
00677 {
00678 return v.ref_count();
00679 }
00680
00681
00682 inline LaIndex LaGenMatDouble::index(int d) const
00683 {
00684 return ii[d];
00685 }
00686
00687 inline double* LaGenMatDouble::addr() const
00688 {
00689 return v.addr();
00690 }
00691
00692 inline int LaGenMatDouble::debug() const
00693 {
00694 return debug_;
00695 }
00696
00697 inline int LaGenMatDouble::debug(int d)
00698 {
00699 return debug_ = d;
00700 }
00701
00702 inline double& LaGenMatDouble::operator()(int i, int j)
00703 {
00704 #ifdef LA_BOUNDS_CHECK
00705 assert(i >= 0);
00706 assert(i < size(0));
00707 assert(j >= 0);
00708 assert(j < size(1));
00709 #endif
00710 return v( dim[0] * (ii[1].start() + j * ii[1].inc()) +
00711 ii[0].start() + i * ii[0].inc());
00712 }
00713
00714 inline const double& LaGenMatDouble::operator()(int i, int j) const
00715 {
00716
00717 #ifdef LA_BOUNDS_CHECK
00718 assert(i >= 0);
00719 assert(i < size(0));
00720 assert(j >= 0);
00721 assert(j < size(1));
00722 #endif
00723
00724 return v( dim[0] * (ii[1].start() + j * ii[1].inc()) +
00725 ii[0].start() + i * ii[0].inc());
00726 }
00727
00728 inline LaGenMatDouble& LaGenMatDouble::shallow_assign()
00729 {
00730 shallow_ = 1;
00731 return *this;
00732 }
00733
00734
00735 #endif
00736