EvolvingObjects
|
00001 #ifndef MATRICES_H 00002 #define MATRICES_H 00003 00004 #include <vector> 00005 00008 class lower_triangular_matrix { 00009 00010 unsigned n; 00011 std::vector<double> data; 00012 00013 public: 00014 00015 lower_triangular_matrix(unsigned n_ = 0) : n(n_), data(n * (n+1) / 2) {}; 00016 00017 void resize(unsigned n_) { 00018 n = n_; 00019 data.resize(n*(n+1)/2); 00020 } 00021 00022 std::vector<double>::iterator operator[](unsigned i) { return data.begin() + i * (i+1) / 2; } 00023 std::vector<double>::const_iterator operator[](unsigned i) const { return data.begin() + i*(i+1)/2; } 00024 }; 00025 00028 class square_matrix { 00029 unsigned n; 00030 std::vector<double> data; 00031 00032 public: 00033 00034 square_matrix(unsigned n_ = 0) : n(n_), data(n * n) {}; 00035 00036 void resize(unsigned n_) { 00037 n = n_; 00038 data.resize(n*n); 00039 } 00040 00041 std::vector<double>::iterator operator[](unsigned i) { return data.begin() + i * n; } 00042 std::vector<double>::const_iterator operator[](unsigned i) const { return data.begin() + i*n; } 00043 }; 00044 00045 #endif