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_LONG_INT_H_
00042 #define _LA_GEN_MAT_LONG_INT_H_
00043
00044 #include "arch.h"
00045 #include "lafnames.h"
00046 #include VECTOR_LONG_INT_H
00047 #include LA_INDEX_H
00048
00049 class LaGenMatComplex;
00050 class LaGenMatDouble;
00051 class LaGenMatFloat;
00052 class LaGenMatInt;
00053 class LaGenMatLongInt;
00054
00055
00071 class DLLIMPORT LaGenMatLongInt
00072 {
00073 public:
00075 typedef long int value_type;
00079 typedef LaGenMatLongInt matrix_type;
00082 typedef VectorLongInt vec_type;
00083 private:
00084 vec_type v;
00085 LaIndex ii[2];
00086 int dim[2];
00087 int sz[2];
00088 void init(int m, int n);
00089 static int debug_;
00090
00091
00092
00093 static int *info_;
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115 int shallow_;
00116
00117
00118
00119
00120
00121
00122
00123
00124 public:
00125
00126
00129
00130
00131
00132
00134 LaGenMatLongInt();
00135
00138 LaGenMatLongInt(int m, int n);
00139
00176 LaGenMatLongInt(long int* v, int m, int n, bool row_ordering=false);
00177
00200 LaGenMatLongInt(const LaGenMatLongInt&);
00201
00205 LaGenMatLongInt& resize(int m, int n);
00206
00210 LaGenMatLongInt& resize(const LaGenMatLongInt& s);
00211
00214 virtual ~LaGenMatLongInt();
00215
00216
00221 bool is_zero() const;
00222
00225 bool is_submatrixview() const
00226 { return size(0) != gdim(0) || size(1) != gdim(1); };
00227
00232 bool has_unitstride() const
00233 { return inc(0) == 1 && inc(1) == 1; };
00234
00237 bool equal_to(const matrix_type& mat) const;
00239
00240
00243
00244
00245
00246
00249 inline int size(int d) const;
00252 inline int cols() const { return size(1); }
00255 inline int rows() const { return size(0); }
00256
00262 inline int inc(int d) const;
00263
00268 inline int gdim(int d) const;
00269
00274 inline int start(int d) const;
00275
00280 inline int end(int d) const;
00281
00286 inline LaIndex index(int d) const;
00287
00291 inline int ref_count() const;
00292
00295 inline long int* addr() const;
00297
00300
00315 inline long int& operator()(int i, int j);
00316
00331 inline long int& operator()(int i, int j) const;
00332
00344 LaGenMatLongInt operator()(const LaIndex& I, const LaIndex& J) ;
00345
00357 LaGenMatLongInt operator()(const LaIndex& I, const LaIndex& J) const;
00358
00365 LaGenMatLongInt row(int k);
00372 LaGenMatLongInt row(int k) const;
00379 LaGenMatLongInt col(int k);
00386 LaGenMatLongInt col(int k) const;
00388
00395 LaGenMatLongInt& operator=(long int s);
00396
00432 LaGenMatLongInt& operator=(const LaGenMatLongInt& s);
00433
00438 LaGenMatLongInt& operator+=(long int s);
00439
00444 LaGenMatLongInt& add(long int s);
00445
00454 LaGenMatLongInt& inject(const LaGenMatLongInt& s);
00455
00460 LaGenMatLongInt& copy(const LaGenMatLongInt& s);
00461
00466 LaGenMatLongInt copy() const;
00467
00472 inline LaGenMatLongInt& shallow_assign();
00473
00481 LaGenMatLongInt& ref(const LaGenMatLongInt& s);
00482
00488 matrix_type repmat (int M, int N) const;
00491 value_type trace () const;
00495 matrix_type diag () const;
00497
00498
00502 inline int shallow() const
00503 { return shallow_;}
00505 inline int debug() const;
00507 inline int debug(int d);
00519 inline const LaGenMatLongInt& info() const {
00520 *(const_cast<LaGenMatLongInt*>(this)->info_) = 1;
00521 return *this;};
00524 inline std::ostream& Info(std::ostream& s) const
00525 {
00526 s << "Size: (" << size(0) << "x" << size(1) << ") " ;
00527 s << "Indeces: " << ii[0] << " " << ii[1];
00528 s << "#ref: " << ref_count() << "addr: " << addr() << std::endl;
00529 return s;
00530 };
00532
00536 friend DLLIMPORT std::ostream& operator<<(std::ostream&, const LaGenMatLongInt&);
00537
00541 LaGenMatComplex to_LaGenMatComplex() const;
00543 LaGenMatDouble to_LaGenMatDouble() const;
00545 LaGenMatFloat to_LaGenMatFloat() const;
00547 LaGenMatInt to_LaGenMatInt() const;
00549
00550
00556 static matrix_type zeros (int N, int M=0);
00560 static matrix_type ones (int N, int M=0);
00564 static matrix_type eye (int N, int M=0);
00573 static matrix_type rand (int N, int M,
00574 value_type low=0, value_type high=1);
00578 static matrix_type from_diag (const matrix_type &vect);
00582 static matrix_type linspace (value_type start, value_type end,
00583 int nr_points);
00585
00586 };
00587
00588
00589 namespace la {
00591 typedef LaGenMatLongInt limat;
00592 }
00593
00601 DLLIMPORT
00602 std::ostream& operator<<(std::ostream&, const LaGenMatLongInt&);
00603
00604
00605
00606
00607
00608
00609
00610 inline int LaGenMatLongInt::size(int d) const
00611 {
00612 return sz[d];
00613 }
00614
00615 inline int LaGenMatLongInt::inc(int d) const
00616 {
00617 return ii[d].inc();
00618 }
00619
00620 inline int LaGenMatLongInt::gdim(int d) const
00621 {
00622 return dim[d];
00623 }
00624
00625 inline int LaGenMatLongInt::start(int d) const
00626 {
00627 return ii[d].start();
00628 }
00629
00630 inline int LaGenMatLongInt::end(int d) const
00631 {
00632 return ii[d].end();
00633 }
00634
00635 inline int LaGenMatLongInt::ref_count() const
00636 {
00637 return v.ref_count();
00638 }
00639
00640
00641 inline LaIndex LaGenMatLongInt::index(int d) const
00642 {
00643 return ii[d];
00644 }
00645
00646 inline long int* LaGenMatLongInt::addr() const
00647 {
00648 return v.addr();
00649 }
00650
00651 inline int LaGenMatLongInt::debug() const
00652 {
00653 return debug_;
00654 }
00655
00656 inline int LaGenMatLongInt::debug(int d)
00657 {
00658 return debug_ = d;
00659 }
00660
00661 inline long int& LaGenMatLongInt::operator()(int i, int j)
00662 {
00663
00664 #ifdef LA_BOUNDS_CHECK
00665 assert(i>=0);
00666 assert(i<size(0));
00667 assert(j>=0);
00668 assert(j<size(1));
00669 #endif
00670 return v( dim[0]*(ii[1].start() + j*ii[1].inc()) +
00671 ii[0].start() + i*ii[0].inc());
00672 }
00673
00674 inline long int& LaGenMatLongInt::operator()(int i, int j) const
00675 {
00676
00677 #ifdef LA_BOUNDS_CHECK
00678 assert(i>=0);
00679 assert(i<size(0));
00680 assert(j>=0);
00681 assert(j<size(1));
00682 #endif
00683
00684 return v( dim[0]*(ii[1].start() + j*ii[1].inc()) +
00685 ii[0].start() + i*ii[0].inc());
00686 }
00687
00688
00689
00690
00691 inline LaGenMatLongInt& LaGenMatLongInt::shallow_assign()
00692 {
00693 shallow_ = 1;
00694 return *this;
00695 }
00696
00697
00698
00699
00700
00701 #endif
00702