 Timestamp:
 Dec 1, 2005, 11:20:31 PM (18 years ago)
 Location:
 branches/better_matrix_class
 Files:

 2 edited
Legend:
 Unmodified
 Added
 Removed

branches/better_matrix_class/lib/gslapi/matrix.cc
r415 r417 75 75 if (view_) 76 76 delete view_; 77 if (m_) {77 else if (m_) 78 78 gsl_matrix_free(m_); 79 m_=NULL; 80 } 79 m_=NULL; 81 80 } 82 81 
branches/better_matrix_class/test/matrix_test.cc
r399 r417 3 3 #include <c++_tools/gslapi/matrix.h> 4 4 5 #include <unistd.h> 5 6 #include <fstream> 6 7 #include <iostream> 7 8 8 9 int main(const int argc,const char* argv[]) 9 { 10 { 10 11 using namespace theplu; 11 12 std::ostream* error; … … 17 18 std::cout << "matrix_test v : for printing extra information\n"; 18 19 } 19 *error << " testing matrix" << std::endl;20 *error << "Testing matrix class" << std::endl; 20 21 bool ok = true; 21 22 23 *error << "\tcopy constructor and operator!=" << std::endl; 22 24 gslapi::matrix m(3,3,9); 23 25 gslapi::matrix m2(m); 24 26 if (m2!=m) 25 27 ok=false; 28 29 *error << "\toutput operator and istream constructor" << std::endl; 26 30 std::ofstream my_out("data/tmp_test_matrix.txt"); 27 31 my_out << m2; 28 32 my_out.close(); 29 30 33 std::ifstream is("data/tmp_test_matrix.txt"); 31 34 gslapi::matrix m3(is); … … 33 36 if (m3!=m2) 34 37 ok=false; 38 unlink("data/tmp_test_matrix.txt"); 35 39 40 *error << "\toperator*(double)" << std::endl; 36 41 gslapi::matrix m4(3,3,1); 37 42 m4 *= 9; 38 39 if (m4!=m){ 43 if (m4!=m) { 40 44 ok=false; 41 45 *error << "error operator*=(double)" << std::endl; 42 46 } 43 47 48 *error << "\tsubmatrix" << std::endl; 49 is.open("data/knni_matrix.data"); 50 gslapi::matrix m5(is); 51 is.close(); 52 double m5_sum=0; 53 for (size_t i=0; i<m5.rows(); ++i) 54 for (size_t j=0; j<m5.columns(); ++j) 55 m5_sum+=m5(i,j); 56 gslapi::matrix* m5sub=new gslapi::matrix(m5,3,3,3,3); 57 double m5sub_sum=0; 58 for (size_t i=0; i<m5sub>rows(); ++i) 59 for (size_t j=0; j<m5sub>columns(); ++j) { 60 m5sub_sum+=(*m5sub)(i,j); 61 (*m5sub)(i,j)=1; 62 } 63 delete m5sub; 64 double m5_sum2=0; 65 for (size_t i=0; i<m5.rows(); ++i) 66 for (size_t j=0; j<m5.columns(); ++j) 67 m5_sum2+=m5(i,j); 68 if (m5_sum2m5_sum9+m5sub_sum>1e13) { 69 ok=false; 70 *error << "error submatrix test" << std::endl; 71 } 72 73 *error << "\tsub(row)vector" << std::endl; 74 gslapi::vector v5subrow(m5,3); 75 double v5subrow_sum=0; 76 for (size_t i=0; i<v5subrow.size(); ++i) { 77 v5subrow_sum+=v5subrow(i); 78 v5subrow[i]=0; 79 } 80 double m5_sum3=0; 81 for (size_t i=0; i<m5.rows(); ++i) 82 for (size_t j=0; j<m5.columns(); ++j) 83 m5_sum3+=m5(i,j); 84 if (m5_sum3m5_sum2+v5subrow_sum>1e13) { 85 ok=false; 86 *error << "error subvector test 1" << std::endl; 87 } 88 89 *error << "\tsub(column)vector" << std::endl; 90 gslapi::vector v5subcolumn(m5,0,false); 91 double v5subcolumn_sum=0; 92 for (size_t i=0; i<v5subcolumn.size(); ++i) { 93 v5subcolumn_sum+=v5subcolumn(i); 94 v5subcolumn(i)=1; 95 } 96 double m5_sum4=0; 97 for (size_t i=0; i<m5.rows(); ++i) 98 for (size_t j=0; j<m5.columns(); ++j) 99 m5_sum4+=m5(i,j); 100 if (m5_sum4m5_sum3v5subcolumn.size()+v5subcolumn_sum>1e13) { 101 ok=false; 102 *error << "error subvector test 2" << std::endl; 103 } 104 double v5subrow_sum2=0; 105 for (size_t i=0; i<v5subrow.size(); ++i) 106 v5subrow_sum2+=v5subrow(i); 107 if (v5subrow_sum2v5subcolumn(3)>1e13) { 108 ok=false; 109 *error << "error subvector test 3" << std::endl; 110 } 111 112 *error << "\tsubvector and vector copying" << std::endl; 113 gslapi::vector v6(v5subrow); 114 v6.set_all(2); 115 double v5subrow_sum3=0; 116 for (size_t i=0; i<v5subrow.size(); ++i) 117 v5subrow_sum3+=v5subrow(i); 118 if (v5subrow_sum3v5subrow_sum2>1e13) { 119 ok=false; 120 *error << "error subvector test 4" << std::endl; 121 } 122 v5subrow.set(v6); 123 double m5_sum5=0; 124 for (size_t i=0; i<m5.rows(); ++i) 125 for (size_t j=0; j<m5.columns(); ++j) 126 m5_sum5+=m5(i,j); 127 if (m5_sum5m5_sum4v5subrow.size()*2+v5subrow_sum3>1e13) { 128 ok=false; 129 *error << "error subvector test 5" << std::endl; 130 } 131 v5subrow=gslapi::vector(23,22); 132 double m5_sum6=0; 133 for (size_t i=0; i<m5.rows(); ++i) 134 for (size_t j=0; j<m5.columns(); ++j) 135 m5_sum6+=m5(i,j); 136 if (m5_sum6m5_sum5>1e13) { 137 ok=false; 138 *error << "error subvector test 6" << std::endl; 139 } 44 140 45 141 if (error!=&std::cerr) … … 47 143 48 144 return (ok ? 0 : 1); 49 50 145 }
Note: See TracChangeset
for help on using the changeset viewer.