- Timestamp:
- Dec 2, 2005, 12:52:49 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/better_matrix_class/test/matrix_test.cc
r417 r419 6 6 #include <fstream> 7 7 #include <iostream> 8 9 class matrixwrapper 10 { 11 public: 12 matrixwrapper(size_t i,size_t j,double value=7) 13 : m_(i,j,value) {} 14 15 inline theplu::gslapi::vector 16 row(const size_t& i) { return theplu::gslapi::vector(m_,i); } 17 18 inline const theplu::gslapi::matrix& matrix(void) const { return m_; } 19 20 private: 21 theplu::gslapi::matrix m_; 22 }; 23 8 24 9 25 int main(const int argc,const char* argv[]) … … 18 34 std::cout << "matrix_test -v : for printing extra information\n"; 19 35 } 36 20 37 *error << "Testing matrix class" << std::endl; 21 38 bool ok = true; … … 28 45 29 46 *error << "\toutput operator and istream constructor" << std::endl; 47 // Checking that the matrix output operator writes a file that the 48 // input operator can read. 30 49 std::ofstream my_out("data/tmp_test_matrix.txt"); 31 50 my_out << m2; … … 47 66 48 67 *error << "\tsub-matrix" << std::endl; 68 // Checking that sub-matrices work, i.e. mutation to the view are 69 // reflected in the viewed object. 49 70 is.open("data/knni_matrix.data"); 71 // The stream input is a proper matrix file, with some stray empty 72 // lines and other whitespaces. The file is not expected to break 73 // things. 50 74 gslapi::matrix m5(is); 51 75 is.close(); … … 72 96 73 97 *error << "\tsub-(row)vector" << std::endl; 98 // Checking that the row view works, i.e. mutation to the view are 99 // reflected in the viewed object. 74 100 gslapi::vector v5subrow(m5,3); 75 101 double v5subrow_sum=0; … … 88 114 89 115 *error << "\tsub-(column)vector" << std::endl; 116 // Checking that the column view works, i.e. mutation to the view 117 // are reflected in the viewed object. 90 118 gslapi::vector v5subcolumn(m5,0,false); 91 119 double v5subcolumn_sum=0; … … 102 130 *error << "error sub-vector test 2" << std::endl; 103 131 } 132 // Checking that the column view above mutates the values in the row 133 // view. 104 134 double v5subrow_sum2=0; 105 135 for (size_t i=0; i<v5subrow.size(); ++i) … … 111 141 112 142 *error << "\tsub-vector and vector copying" << std::endl; 143 // Checking that a view is not inherited through the copy 144 // contructor. 113 145 gslapi::vector v6(v5subrow); 114 146 v6.set_all(2); … … 120 152 *error << "error sub-vector test 4" << std::endl; 121 153 } 154 // Checking that values in a vector is copied into a viewed matrix. 122 155 v5subrow.set(v6); 123 156 double m5_sum5=0; … … 129 162 *error << "error sub-vector test 5" << std::endl; 130 163 } 164 // Checking that vector::operator= indeed makes a view to become a 165 // "normal" vector. 131 166 v5subrow=gslapi::vector(23,22); 132 167 double m5_sum6=0; … … 139 174 } 140 175 176 // Checking that the memberfunction matrixwrapper::row() returns a 177 // view 178 *error << "\tthat class member returns a view" << std::endl; 179 matrixwrapper mw(5,2); 180 gslapi::vector mwrow=mw.row(2); 181 if (mwrow.gsl_vector_p()->data != &(mw.matrix()(2,0))) { 182 ok=false; 183 *error << "error sub-vector test 7" << std::endl; 184 } 185 186 *error << "\tsub-matrix of a sub-matrix" << std::endl; 187 // Checking that a sub-matrix of a sub-matrix can be created. 188 gslapi::matrix sub(m5,3,3,3,3); 189 gslapi::matrix subsub(sub,2,1,1,2); 190 subsub(0,0)=23221121; 191 if (&sub(2,1)!=&subsub(0,0) || subsub(0,0)!=m5(5,4) || &subsub(0,0)!=&m5(5,4)){ 192 ok=false; 193 *error << "error sub-matrix test 1" << std::endl; 194 } 195 141 196 if (error!=&std::cerr) 142 197 delete error;
Note: See TracChangeset
for help on using the changeset viewer.