DenseLinAlgPack_TestDenseLinAlgPackIO.cpp

Go to the documentation of this file.
00001 // @HEADER
00002 // ***********************************************************************
00003 // 
00004 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization
00005 //                  Copyright (2003) Sandia Corporation
00006 // 
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 // 
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //  
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //  
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 
00025 // 
00026 // ***********************************************************************
00027 // @HEADER
00028 
00029 #include <ostream>
00030 #include <istream>
00031 #include <iomanip>
00032 
00033 #include "DenseLinAlgPack_TestDenseLinAlgPack.hpp"
00034 #include "DenseLinAlgPack_IO.hpp"
00035 #include "DenseLinAlgPack_OutFormat.hpp"
00036 #include "DenseLinAlgPack_DMatrixClass.hpp"
00037 
00038 
00039 // To use this function you must bind _in to the file TestDenseLinAlgPackIO.in
00040 
00041 void DenseLinAlgPack::TestingPack::TestDenseLinAlgPackIO(std::istream& _in, std::ostream& _out) {
00042 
00043   using std::endl;
00044   using std::setw;
00045 
00046   try {
00047 
00048   using InputStreamHelperPack::eat_comment_lines;
00049   using LinAlgPackIO::bind;
00050   using LinAlgPackIO::cbind;
00051   using LinAlgPackIO::format;
00052   
00053   _out
00054     << "\n*****************************************************************"
00055     << "\n*** Testing input/output operators and functions for DVector, ***"
00056     << "\n*** DVectorSlice, DMatrix and DMatrixSlice.                   ***"
00057     << "\n*** Must be run with TestDenseLinAlgPackIO.in as input        ***"
00058     << "\n*****************************************************************\n";
00059   
00060   // Creating a formating object
00061   _out  << "\n  format f(_in);\n"
00062       << "  f.setw(15).showpoint().setprecision(6);\n";
00063   format f(_in);
00064   f.setw(15).showpoint().setprecision(6);
00065 
00066   // Testing The eating of comment lines
00067   _out  << "\nTest Eating comment lines.\n"
00068       << "  eat_comment_lines(_in,'*');\n";
00069   eat_comment_lines(_in,'*');
00070 
00071   // Test inputing and outputing Vectors and VectorSlices
00072 
00073   _out  << "\nTest inputing Vectors and VectorSlices (eat_comment_lines(_in,'*') called inbetween)\n"
00074       << "  DVector v1, v2(4), v3, v4(4);\n"
00075       << "\n  _in >> v1;\n";
00076   DVector v1, v2(4), v3, v4(4);
00077   _in >> v1;              // input (1) : DVector with resizing from 0
00078   _out  << "\n  _out  << cbind(f,v1);\n";
00079   _out  << cbind(f,v1);
00080 
00081   eat_comment_lines(_in,'*');
00082 
00083   _out  << "\n  _in >> v2;\n";
00084   _in >> v2;              // input (2) : DVector with resizing from sized
00085   _out  << "\n  _out  << cbind(f,v2);\n";
00086   _out  << cbind(f,v2);
00087 
00088   eat_comment_lines(_in,'*');
00089 
00090   _out  << "\n  _in >> v3;\n";
00091   _in >> v3;              // input (3) : DVector with resizing from 0
00092   _out  << "\n  _out  << cbind(f,v3());\n";
00093   _out  << cbind(f,v3());
00094 
00095   eat_comment_lines(_in,'*');
00096 
00097   _out  << "\n  _in >> v4();\n";
00098   { DVectorSlice t = v4(); _in >> t; } // input (4) : DVectorSlice with no resizing (must be size 4)
00099   _out  << "\n  _out  << cbind(f,v4());\n";
00100   _out  << cbind(f,v4());
00101 
00102   eat_comment_lines(_in,'*');
00103 
00104   _out  << "  v1.resize(0); v3.resize(0);\n"
00105       << "\n  _in >> bind(f,v1);\n";
00106   v1.resize(0); v3.resize(0);
00107   _in >> bind(f,v1);        // input (5) : DVector with bound format, resize from 0
00108   _out  << "\n  _out  << cbind(f,v1);\n";
00109   _out  << cbind(f,v1);
00110 
00111   eat_comment_lines(_in,'*');
00112 
00113   _out  << "\n  _in >> bind(f,v2);\n";
00114   _in >> bind(f,v2);        // input (6) : DVector with bound format, resize from sized
00115   _out  << "\n  _out  << cbind(f,v2);\n";
00116   _out  << cbind(f,v2);
00117 
00118   eat_comment_lines(_in,'*');
00119 
00120   _out  << "\n  _in >> bind(f,v3);\n";
00121   _in >> bind(f,v3);        // input (7) : DVector with bound format, resize form 0
00122   _out  << "\n  _out  << cbind(f,v3());\n";
00123   _out  << cbind(f,v3());
00124 
00125   eat_comment_lines(_in,'*');
00126 
00127   _out  << "\n  _in >> bind(f,v4());\n";
00128   { DVectorSlice t = v4(); _in >> bind(f,t); }    // input (8) : DVectorSlice with bound format, no resizing (must be size 4)
00129   _out  << "\n  _out  << cbind(f,v4());\n";
00130   _out  << cbind(f,v4());
00131 
00132   eat_comment_lines(_in,'*');
00133 
00134   _out  << "\n  _in >> bind(f.ignore_dim(),v1);\n";
00135   _in >> bind(f.ignore_dim(),v1); // input (9) : DVector with bound format, ignore vector dimension
00136   _out  << "\n  _out  << cbind(f,v1);\n";
00137   _out  << cbind(f,v1);
00138 
00139   eat_comment_lines(_in,'*');
00140 
00141   _out  << "\n  _in >> bind(f,v2);\n";
00142   _in >> bind(f,v2);        // input (10) : DVector with bound format, ignore vector dimension
00143   _out  << "\n  _out  << cbind(f,v2);\n";
00144   _out  << cbind(f,v2);
00145 
00146   eat_comment_lines(_in,'*');
00147 
00148   _out  << "\n  _in >> bind(f,v3());\n";
00149   { DVectorSlice t = v3(); _in >> bind(f,t); }    // input (11) : DVectorSlice with bound format, ignore vector dimension
00150   _out  << "\n  _out  << cbind(f,v3());\n";
00151   _out  << cbind(f,v3());
00152 
00153   eat_comment_lines(_in,'*');
00154 
00155   _out  << "\n  _in >> bind(f,v4());\n";
00156   { DVectorSlice t = v4(); _in >> bind(f,t); }       // input (12) : DVectorSlice with bound format,  ignore vector dimension
00157   _out  << "\n  _out  << cbind(f,v4());\n";
00158   _out  << cbind(f,v4());
00159 
00160   // Test variations of outputing for DVector and DVectorSlice objects
00161 
00162   _out  << "\nTest variations of outputing for Vectors and VectorSlices\n";
00163 
00164   _out  << "\n  _out << cbind(f.ignore_dim(),v1);\n";
00165   _out << cbind(f.ignore_dim(),v1);
00166 
00167   _out  << "\n  _out << cbind(f.no_ignore_dim(), const_cast<const DVectorSlice&>(v1()) );\n";
00168   { const DVectorSlice t = v1(); _out << cbind(f.no_ignore_dim(), t ); }
00169 
00170   _out  << "\n  _out << cbind(f.ignore_dim().no_insert_newlines(),v1) << cbind(f,v1) << endl;\n";
00171   _out << cbind(f.ignore_dim().no_insert_newlines(),v1) << cbind(f,v1) << endl;
00172 
00173   // Test inputing and outputing DMatrix and DMatrixSlice objects
00174 
00175   eat_comment_lines(_in,'*');
00176 
00177   _out  << "\nTest inputing and outputing DMatrix and DMatrixSlice objects (eat_comment_lines(_in,'*') called inbetween)\n"
00178       << "  DMatrix m1, m2(2,2), m3, m4(2,2);\n"
00179       << "\n  _in >> m1;\n";
00180   DMatrix m1, m2(2,2), m3, m4(2,2);
00181   _in >> m1;              // input (13) : DMatrix with resizing from 0
00182   _out  << "\n  _out  << cbind(f.no_ignore_dim().insert_newlines(),m1);\n";
00183   _out  << cbind(f.no_ignore_dim().insert_newlines(),m1);
00184 
00185   eat_comment_lines(_in,'*');
00186 
00187   _out  << "\n  _in >> m2;\n";
00188   _in >> m2;              // input (14) : DMatrix with resizing from sized
00189   _out  << "\n  _out  << cbind(f,m2);\n";
00190   _out  << cbind(f,m2);
00191 
00192   eat_comment_lines(_in,'*');
00193 
00194   _out  << "\n  _in >> m3;\n";
00195   _in >> m3;              // input (15) : DMatrix with resizing from 0
00196   _out  << "\n  _out  << cbind(f,m3());\n";
00197   _out  << cbind(f,m3());
00198 
00199   eat_comment_lines(_in,'*');
00200 
00201   _out  << "\n  _in >> m4();\n";
00202   { DMatrixSlice t = m4(); _in >> t; }        // input (16) : DMatrixSlice with no resizing (must be size 4)
00203   _out  << "\n  _out  << cbind(f,m4());\n";
00204   _out  << cbind(f,m4());
00205 
00206   eat_comment_lines(_in,'*');
00207 
00208   _out  << "  m1.resize(0,0); m3.resize(0,0);\n"
00209       << "\n  _in >> bind(f,m1);\n";
00210   m1.resize(0,0); m3.resize(0,0);
00211   _in >> bind(f,m1);        // input (17) : DMatrix with bound format, resize from 0
00212   _out  << "\n  _out  << cbind(f,m1);\n";
00213   _out  << cbind(f,m1);
00214 
00215   eat_comment_lines(_in,'*');
00216 
00217   _out  << "\n  _in >> bind(f,m2);\n";
00218   _in >> bind(f,m2);        // input (18) : DMatrix with bound format, resize from sized
00219   _out  << "\n  _out  << cbind(f,m2);\n";
00220   _out  << cbind(f,m2);
00221 
00222   eat_comment_lines(_in,'*');
00223 
00224   _out  << "\n  _in >> bind(f,m3);\n";
00225   _in >> bind(f,m3);        // input (19) : DMatrix with bound format, resize form 0
00226   _out  << "\n  _out  << cbind(f,m3());\n";
00227   _out  << cbind(f,m3());
00228 
00229   eat_comment_lines(_in,'*');
00230 
00231   _out  << "\n  _in >> bind(f,m4());\n";
00232   { DMatrixSlice t = m4(); _in >> bind(f,t); }   // input (20) : DMatrixSlice with bound format, no resizing (must be size 4)
00233   _out  << "\n  _out  << cbind(f,m4());\n";
00234   _out  << cbind(f,m4());
00235 
00236   eat_comment_lines(_in,'*');
00237 
00238   _out  << "\n  _in >> bind(f.ignore_dim(),m1);\n";
00239   _in >> bind(f.ignore_dim(),m1); // input (21) : DMatrix with bound format, ignore vector dimension
00240   _out  << "\n  _out  << cbind(f,m1);\n";
00241   _out  << cbind(f,m1);
00242 
00243   eat_comment_lines(_in,'*');
00244 
00245   _out  << "\n  _in >> bind(f,m2);\n";
00246   _in >> bind(f,m2);        // input (22) : DMatrix with bound format, ignore vector dimension
00247   _out  << "\n  _out  << cbind(f,m2);\n";
00248   _out  << cbind(f,m2);
00249 
00250   eat_comment_lines(_in,'*');
00251 
00252   _out  << "\n  _in >> bind(f,m3);\n";
00253   _in >> bind(f,m3);        // input (23) : DMatrixSlice with bound format, ignore vector dimension
00254   _out  << "\n  _out  << cbind(f,m3());\n";
00255   _out  << cbind(f,m3());
00256 
00257   eat_comment_lines(_in,'*');
00258 
00259   _out  << "\n  _in >> bind(f,m4());\n";
00260   { DMatrixSlice t = m4(); _in >> bind(f,t); } // input (24) : DMatrixSlice with bound format,  ignore vector dimension
00261   _out  << "\n  _out  << cbind(f,m4());\n";
00262   _out  << cbind(f,m4());
00263 
00264   // Test variations of outputing for DMatrix and DMatrixSlice objects
00265 
00266   _out  << "\nTest variations of outputing for DMatrix and DMatrixSlice objects\n";
00267 
00268   _out  << "\n  _out << cbind(f.ignore_dim(),m1);\n";
00269   _out << cbind(f.ignore_dim(),m1);
00270 
00271   _out  << "\n  _out << cbind(f.no_ignore_dim(), const_cast<const DMatrixSlice&>(m1()) );\n";
00272   { const DMatrixSlice t = m1(); _out << cbind(f.no_ignore_dim(), t ); }
00273 
00274   _out  << "\n  _out << 2*m1.rows() << ' ' << m1.cols() << endl << cbind(f.ignore_dim(),m1) << cbind(f,m1);\n";
00275   _out << 2*m1.rows() << ' ' << m1.cols() << endl << cbind(f.ignore_dim(),m1) << cbind(f,m1);
00276 
00277   _out  << "\nIf you read this then no unexpected exceptions occured.\n";
00278 
00279   } // end try
00280   catch(const std::exception& excpt) {
00281     _out << "\nCaught a std::exception: " << excpt.what() << endl;
00282   }
00283   catch(...) {
00284     _out << "\nCaught and unknown exception\n";
00285   }
00286 }

Generated on Tue Oct 20 12:51:46 2009 for MOOCHO (Single Doxygen Collection) by doxygen 1.4.7