MOOCHO (Single Doxygen Collection) Version of the Day
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 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 
00038 // 
00039 // ***********************************************************************
00040 // @HEADER
00041 
00042 #include <ostream>
00043 #include <istream>
00044 #include <iomanip>
00045 
00046 #include "DenseLinAlgPack_TestDenseLinAlgPack.hpp"
00047 #include "DenseLinAlgPack_IO.hpp"
00048 #include "DenseLinAlgPack_OutFormat.hpp"
00049 #include "DenseLinAlgPack_DMatrixClass.hpp"
00050 
00051 
00052 // To use this function you must bind _in to the file TestDenseLinAlgPackIO.in
00053 
00054 void DenseLinAlgPack::TestingPack::TestDenseLinAlgPackIO(std::istream& _in, std::ostream& _out) {
00055 
00056   using std::endl;
00057   using std::setw;
00058 
00059   try {
00060 
00061   using InputStreamHelperPack::eat_comment_lines;
00062   using LinAlgPackIO::bind;
00063   using LinAlgPackIO::cbind;
00064   using LinAlgPackIO::format;
00065   
00066   _out
00067     << "\n*****************************************************************"
00068     << "\n*** Testing input/output operators and functions for DVector, ***"
00069     << "\n*** DVectorSlice, DMatrix and DMatrixSlice.                   ***"
00070     << "\n*** Must be run with TestDenseLinAlgPackIO.in as input        ***"
00071     << "\n*****************************************************************\n";
00072   
00073   // Creating a formating object
00074   _out  << "\n  format f(_in);\n"
00075       << "  f.setw(15).showpoint().setprecision(6);\n";
00076   format f(_in);
00077   f.setw(15).showpoint().setprecision(6);
00078 
00079   // Testing The eating of comment lines
00080   _out  << "\nTest Eating comment lines.\n"
00081       << "  eat_comment_lines(_in,'*');\n";
00082   eat_comment_lines(_in,'*');
00083 
00084   // Test inputing and outputing Vectors and VectorSlices
00085 
00086   _out  << "\nTest inputing Vectors and VectorSlices (eat_comment_lines(_in,'*') called inbetween)\n"
00087       << "  DVector v1, v2(4), v3, v4(4);\n"
00088       << "\n  _in >> v1;\n";
00089   DVector v1, v2(4), v3, v4(4);
00090   _in >> v1;              // input (1) : DVector with resizing from 0
00091   _out  << "\n  _out  << cbind(f,v1);\n";
00092   _out  << cbind(f,v1);
00093 
00094   eat_comment_lines(_in,'*');
00095 
00096   _out  << "\n  _in >> v2;\n";
00097   _in >> v2;              // input (2) : DVector with resizing from sized
00098   _out  << "\n  _out  << cbind(f,v2);\n";
00099   _out  << cbind(f,v2);
00100 
00101   eat_comment_lines(_in,'*');
00102 
00103   _out  << "\n  _in >> v3;\n";
00104   _in >> v3;              // input (3) : DVector with resizing from 0
00105   _out  << "\n  _out  << cbind(f,v3());\n";
00106   _out  << cbind(f,v3());
00107 
00108   eat_comment_lines(_in,'*');
00109 
00110   _out  << "\n  _in >> v4();\n";
00111   { DVectorSlice t = v4(); _in >> t; } // input (4) : DVectorSlice with no resizing (must be size 4)
00112   _out  << "\n  _out  << cbind(f,v4());\n";
00113   _out  << cbind(f,v4());
00114 
00115   eat_comment_lines(_in,'*');
00116 
00117   _out  << "  v1.resize(0); v3.resize(0);\n"
00118       << "\n  _in >> bind(f,v1);\n";
00119   v1.resize(0); v3.resize(0);
00120   _in >> bind(f,v1);        // input (5) : DVector with bound format, resize from 0
00121   _out  << "\n  _out  << cbind(f,v1);\n";
00122   _out  << cbind(f,v1);
00123 
00124   eat_comment_lines(_in,'*');
00125 
00126   _out  << "\n  _in >> bind(f,v2);\n";
00127   _in >> bind(f,v2);        // input (6) : DVector with bound format, resize from sized
00128   _out  << "\n  _out  << cbind(f,v2);\n";
00129   _out  << cbind(f,v2);
00130 
00131   eat_comment_lines(_in,'*');
00132 
00133   _out  << "\n  _in >> bind(f,v3);\n";
00134   _in >> bind(f,v3);        // input (7) : DVector with bound format, resize form 0
00135   _out  << "\n  _out  << cbind(f,v3());\n";
00136   _out  << cbind(f,v3());
00137 
00138   eat_comment_lines(_in,'*');
00139 
00140   _out  << "\n  _in >> bind(f,v4());\n";
00141   { DVectorSlice t = v4(); _in >> bind(f,t); }    // input (8) : DVectorSlice with bound format, no resizing (must be size 4)
00142   _out  << "\n  _out  << cbind(f,v4());\n";
00143   _out  << cbind(f,v4());
00144 
00145   eat_comment_lines(_in,'*');
00146 
00147   _out  << "\n  _in >> bind(f.ignore_dim(),v1);\n";
00148   _in >> bind(f.ignore_dim(),v1); // input (9) : DVector with bound format, ignore vector dimension
00149   _out  << "\n  _out  << cbind(f,v1);\n";
00150   _out  << cbind(f,v1);
00151 
00152   eat_comment_lines(_in,'*');
00153 
00154   _out  << "\n  _in >> bind(f,v2);\n";
00155   _in >> bind(f,v2);        // input (10) : DVector with bound format, ignore vector dimension
00156   _out  << "\n  _out  << cbind(f,v2);\n";
00157   _out  << cbind(f,v2);
00158 
00159   eat_comment_lines(_in,'*');
00160 
00161   _out  << "\n  _in >> bind(f,v3());\n";
00162   { DVectorSlice t = v3(); _in >> bind(f,t); }    // input (11) : DVectorSlice with bound format, ignore vector dimension
00163   _out  << "\n  _out  << cbind(f,v3());\n";
00164   _out  << cbind(f,v3());
00165 
00166   eat_comment_lines(_in,'*');
00167 
00168   _out  << "\n  _in >> bind(f,v4());\n";
00169   { DVectorSlice t = v4(); _in >> bind(f,t); }       // input (12) : DVectorSlice with bound format,  ignore vector dimension
00170   _out  << "\n  _out  << cbind(f,v4());\n";
00171   _out  << cbind(f,v4());
00172 
00173   // Test variations of outputing for DVector and DVectorSlice objects
00174 
00175   _out  << "\nTest variations of outputing for Vectors and VectorSlices\n";
00176 
00177   _out  << "\n  _out << cbind(f.ignore_dim(),v1);\n";
00178   _out << cbind(f.ignore_dim(),v1);
00179 
00180   _out  << "\n  _out << cbind(f.no_ignore_dim(), const_cast<const DVectorSlice&>(v1()) );\n";
00181   { const DVectorSlice t = v1(); _out << cbind(f.no_ignore_dim(), t ); }
00182 
00183   _out  << "\n  _out << cbind(f.ignore_dim().no_insert_newlines(),v1) << cbind(f,v1) << endl;\n";
00184   _out << cbind(f.ignore_dim().no_insert_newlines(),v1) << cbind(f,v1) << endl;
00185 
00186   // Test inputing and outputing DMatrix and DMatrixSlice objects
00187 
00188   eat_comment_lines(_in,'*');
00189 
00190   _out  << "\nTest inputing and outputing DMatrix and DMatrixSlice objects (eat_comment_lines(_in,'*') called inbetween)\n"
00191       << "  DMatrix m1, m2(2,2), m3, m4(2,2);\n"
00192       << "\n  _in >> m1;\n";
00193   DMatrix m1, m2(2,2), m3, m4(2,2);
00194   _in >> m1;              // input (13) : DMatrix with resizing from 0
00195   _out  << "\n  _out  << cbind(f.no_ignore_dim().insert_newlines(),m1);\n";
00196   _out  << cbind(f.no_ignore_dim().insert_newlines(),m1);
00197 
00198   eat_comment_lines(_in,'*');
00199 
00200   _out  << "\n  _in >> m2;\n";
00201   _in >> m2;              // input (14) : DMatrix with resizing from sized
00202   _out  << "\n  _out  << cbind(f,m2);\n";
00203   _out  << cbind(f,m2);
00204 
00205   eat_comment_lines(_in,'*');
00206 
00207   _out  << "\n  _in >> m3;\n";
00208   _in >> m3;              // input (15) : DMatrix with resizing from 0
00209   _out  << "\n  _out  << cbind(f,m3());\n";
00210   _out  << cbind(f,m3());
00211 
00212   eat_comment_lines(_in,'*');
00213 
00214   _out  << "\n  _in >> m4();\n";
00215   { DMatrixSlice t = m4(); _in >> t; }        // input (16) : DMatrixSlice with no resizing (must be size 4)
00216   _out  << "\n  _out  << cbind(f,m4());\n";
00217   _out  << cbind(f,m4());
00218 
00219   eat_comment_lines(_in,'*');
00220 
00221   _out  << "  m1.resize(0,0); m3.resize(0,0);\n"
00222       << "\n  _in >> bind(f,m1);\n";
00223   m1.resize(0,0); m3.resize(0,0);
00224   _in >> bind(f,m1);        // input (17) : DMatrix with bound format, resize from 0
00225   _out  << "\n  _out  << cbind(f,m1);\n";
00226   _out  << cbind(f,m1);
00227 
00228   eat_comment_lines(_in,'*');
00229 
00230   _out  << "\n  _in >> bind(f,m2);\n";
00231   _in >> bind(f,m2);        // input (18) : DMatrix with bound format, resize from sized
00232   _out  << "\n  _out  << cbind(f,m2);\n";
00233   _out  << cbind(f,m2);
00234 
00235   eat_comment_lines(_in,'*');
00236 
00237   _out  << "\n  _in >> bind(f,m3);\n";
00238   _in >> bind(f,m3);        // input (19) : DMatrix with bound format, resize form 0
00239   _out  << "\n  _out  << cbind(f,m3());\n";
00240   _out  << cbind(f,m3());
00241 
00242   eat_comment_lines(_in,'*');
00243 
00244   _out  << "\n  _in >> bind(f,m4());\n";
00245   { DMatrixSlice t = m4(); _in >> bind(f,t); }   // input (20) : DMatrixSlice with bound format, no resizing (must be size 4)
00246   _out  << "\n  _out  << cbind(f,m4());\n";
00247   _out  << cbind(f,m4());
00248 
00249   eat_comment_lines(_in,'*');
00250 
00251   _out  << "\n  _in >> bind(f.ignore_dim(),m1);\n";
00252   _in >> bind(f.ignore_dim(),m1); // input (21) : DMatrix with bound format, ignore vector dimension
00253   _out  << "\n  _out  << cbind(f,m1);\n";
00254   _out  << cbind(f,m1);
00255 
00256   eat_comment_lines(_in,'*');
00257 
00258   _out  << "\n  _in >> bind(f,m2);\n";
00259   _in >> bind(f,m2);        // input (22) : DMatrix with bound format, ignore vector dimension
00260   _out  << "\n  _out  << cbind(f,m2);\n";
00261   _out  << cbind(f,m2);
00262 
00263   eat_comment_lines(_in,'*');
00264 
00265   _out  << "\n  _in >> bind(f,m3);\n";
00266   _in >> bind(f,m3);        // input (23) : DMatrixSlice with bound format, ignore vector dimension
00267   _out  << "\n  _out  << cbind(f,m3());\n";
00268   _out  << cbind(f,m3());
00269 
00270   eat_comment_lines(_in,'*');
00271 
00272   _out  << "\n  _in >> bind(f,m4());\n";
00273   { DMatrixSlice t = m4(); _in >> bind(f,t); } // input (24) : DMatrixSlice with bound format,  ignore vector dimension
00274   _out  << "\n  _out  << cbind(f,m4());\n";
00275   _out  << cbind(f,m4());
00276 
00277   // Test variations of outputing for DMatrix and DMatrixSlice objects
00278 
00279   _out  << "\nTest variations of outputing for DMatrix and DMatrixSlice objects\n";
00280 
00281   _out  << "\n  _out << cbind(f.ignore_dim(),m1);\n";
00282   _out << cbind(f.ignore_dim(),m1);
00283 
00284   _out  << "\n  _out << cbind(f.no_ignore_dim(), const_cast<const DMatrixSlice&>(m1()) );\n";
00285   { const DMatrixSlice t = m1(); _out << cbind(f.no_ignore_dim(), t ); }
00286 
00287   _out  << "\n  _out << 2*m1.rows() << ' ' << m1.cols() << endl << cbind(f.ignore_dim(),m1) << cbind(f,m1);\n";
00288   _out << 2*m1.rows() << ' ' << m1.cols() << endl << cbind(f.ignore_dim(),m1) << cbind(f,m1);
00289 
00290   _out  << "\nIf you read this then no unexpected exceptions occured.\n";
00291 
00292   } // end try
00293   catch(const std::exception& excpt) {
00294     _out << "\nCaught a std::exception: " << excpt.what() << endl;
00295   }
00296   catch(...) {
00297     _out << "\nCaught and unknown exception\n";
00298   }
00299 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines