MOOCHO (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DenseLinAlgPack_TestDenseLinAlgPackIO.cpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization
5 // Copyright (2003) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 #include <ostream>
43 #include <istream>
44 #include <iomanip>
45 
47 #include "DenseLinAlgPack_IO.hpp"
50 
51 
52 // To use this function you must bind _in to the file TestDenseLinAlgPackIO.in
53 
54 void DenseLinAlgPack::TestingPack::TestDenseLinAlgPackIO(std::istream& _in, std::ostream& _out) {
55 
56  using std::endl;
57  using std::setw;
58 
59  try {
60 
62  using LinAlgPackIO::bind;
63  using LinAlgPackIO::cbind;
65 
66  _out
67  << "\n*****************************************************************"
68  << "\n*** Testing input/output operators and functions for DVector, ***"
69  << "\n*** DVectorSlice, DMatrix and DMatrixSlice. ***"
70  << "\n*** Must be run with TestDenseLinAlgPackIO.in as input ***"
71  << "\n*****************************************************************\n";
72 
73  // Creating a formating object
74  _out << "\n format f(_in);\n"
75  << " f.setw(15).showpoint().setprecision(6);\n";
76  format f(_in);
77  f.setw(15).showpoint().setprecision(6);
78 
79  // Testing The eating of comment lines
80  _out << "\nTest Eating comment lines.\n"
81  << " eat_comment_lines(_in,'*');\n";
82  eat_comment_lines(_in,'*');
83 
84  // Test inputing and outputing Vectors and VectorSlices
85 
86  _out << "\nTest inputing Vectors and VectorSlices (eat_comment_lines(_in,'*') called inbetween)\n"
87  << " DVector v1, v2(4), v3, v4(4);\n"
88  << "\n _in >> v1;\n";
89  DVector v1, v2(4), v3, v4(4);
90  _in >> v1; // input (1) : DVector with resizing from 0
91  _out << "\n _out << cbind(f,v1);\n";
92  _out << cbind(f,v1);
93 
94  eat_comment_lines(_in,'*');
95 
96  _out << "\n _in >> v2;\n";
97  _in >> v2; // input (2) : DVector with resizing from sized
98  _out << "\n _out << cbind(f,v2);\n";
99  _out << cbind(f,v2);
100 
101  eat_comment_lines(_in,'*');
102 
103  _out << "\n _in >> v3;\n";
104  _in >> v3; // input (3) : DVector with resizing from 0
105  _out << "\n _out << cbind(f,v3());\n";
106  _out << cbind(f,v3());
107 
108  eat_comment_lines(_in,'*');
109 
110  _out << "\n _in >> v4();\n";
111  { DVectorSlice t = v4(); _in >> t; } // input (4) : DVectorSlice with no resizing (must be size 4)
112  _out << "\n _out << cbind(f,v4());\n";
113  _out << cbind(f,v4());
114 
115  eat_comment_lines(_in,'*');
116 
117  _out << " v1.resize(0); v3.resize(0);\n"
118  << "\n _in >> bind(f,v1);\n";
119  v1.resize(0); v3.resize(0);
120  _in >> bind(f,v1); // input (5) : DVector with bound format, resize from 0
121  _out << "\n _out << cbind(f,v1);\n";
122  _out << cbind(f,v1);
123 
124  eat_comment_lines(_in,'*');
125 
126  _out << "\n _in >> bind(f,v2);\n";
127  _in >> bind(f,v2); // input (6) : DVector with bound format, resize from sized
128  _out << "\n _out << cbind(f,v2);\n";
129  _out << cbind(f,v2);
130 
131  eat_comment_lines(_in,'*');
132 
133  _out << "\n _in >> bind(f,v3);\n";
134  _in >> bind(f,v3); // input (7) : DVector with bound format, resize form 0
135  _out << "\n _out << cbind(f,v3());\n";
136  _out << cbind(f,v3());
137 
138  eat_comment_lines(_in,'*');
139 
140  _out << "\n _in >> bind(f,v4());\n";
141  { DVectorSlice t = v4(); _in >> bind(f,t); } // input (8) : DVectorSlice with bound format, no resizing (must be size 4)
142  _out << "\n _out << cbind(f,v4());\n";
143  _out << cbind(f,v4());
144 
145  eat_comment_lines(_in,'*');
146 
147  _out << "\n _in >> bind(f.ignore_dim(),v1);\n";
148  _in >> bind(f.ignore_dim(),v1); // input (9) : DVector with bound format, ignore vector dimension
149  _out << "\n _out << cbind(f,v1);\n";
150  _out << cbind(f,v1);
151 
152  eat_comment_lines(_in,'*');
153 
154  _out << "\n _in >> bind(f,v2);\n";
155  _in >> bind(f,v2); // input (10) : DVector with bound format, ignore vector dimension
156  _out << "\n _out << cbind(f,v2);\n";
157  _out << cbind(f,v2);
158 
159  eat_comment_lines(_in,'*');
160 
161  _out << "\n _in >> bind(f,v3());\n";
162  { DVectorSlice t = v3(); _in >> bind(f,t); } // input (11) : DVectorSlice with bound format, ignore vector dimension
163  _out << "\n _out << cbind(f,v3());\n";
164  _out << cbind(f,v3());
165 
166  eat_comment_lines(_in,'*');
167 
168  _out << "\n _in >> bind(f,v4());\n";
169  { DVectorSlice t = v4(); _in >> bind(f,t); } // input (12) : DVectorSlice with bound format, ignore vector dimension
170  _out << "\n _out << cbind(f,v4());\n";
171  _out << cbind(f,v4());
172 
173  // Test variations of outputing for DVector and DVectorSlice objects
174 
175  _out << "\nTest variations of outputing for Vectors and VectorSlices\n";
176 
177  _out << "\n _out << cbind(f.ignore_dim(),v1);\n";
178  _out << cbind(f.ignore_dim(),v1);
179 
180  _out << "\n _out << cbind(f.no_ignore_dim(), const_cast<const DVectorSlice&>(v1()) );\n";
181  { const DVectorSlice t = v1(); _out << cbind(f.no_ignore_dim(), t ); }
182 
183  _out << "\n _out << cbind(f.ignore_dim().no_insert_newlines(),v1) << cbind(f,v1) << endl;\n";
184  _out << cbind(f.ignore_dim().no_insert_newlines(),v1) << cbind(f,v1) << endl;
185 
186  // Test inputing and outputing DMatrix and DMatrixSlice objects
187 
188  eat_comment_lines(_in,'*');
189 
190  _out << "\nTest inputing and outputing DMatrix and DMatrixSlice objects (eat_comment_lines(_in,'*') called inbetween)\n"
191  << " DMatrix m1, m2(2,2), m3, m4(2,2);\n"
192  << "\n _in >> m1;\n";
193  DMatrix m1, m2(2,2), m3, m4(2,2);
194  _in >> m1; // input (13) : DMatrix with resizing from 0
195  _out << "\n _out << cbind(f.no_ignore_dim().insert_newlines(),m1);\n";
196  _out << cbind(f.no_ignore_dim().insert_newlines(),m1);
197 
198  eat_comment_lines(_in,'*');
199 
200  _out << "\n _in >> m2;\n";
201  _in >> m2; // input (14) : DMatrix with resizing from sized
202  _out << "\n _out << cbind(f,m2);\n";
203  _out << cbind(f,m2);
204 
205  eat_comment_lines(_in,'*');
206 
207  _out << "\n _in >> m3;\n";
208  _in >> m3; // input (15) : DMatrix with resizing from 0
209  _out << "\n _out << cbind(f,m3());\n";
210  _out << cbind(f,m3());
211 
212  eat_comment_lines(_in,'*');
213 
214  _out << "\n _in >> m4();\n";
215  { DMatrixSlice t = m4(); _in >> t; } // input (16) : DMatrixSlice with no resizing (must be size 4)
216  _out << "\n _out << cbind(f,m4());\n";
217  _out << cbind(f,m4());
218 
219  eat_comment_lines(_in,'*');
220 
221  _out << " m1.resize(0,0); m3.resize(0,0);\n"
222  << "\n _in >> bind(f,m1);\n";
223  m1.resize(0,0); m3.resize(0,0);
224  _in >> bind(f,m1); // input (17) : DMatrix with bound format, resize from 0
225  _out << "\n _out << cbind(f,m1);\n";
226  _out << cbind(f,m1);
227 
228  eat_comment_lines(_in,'*');
229 
230  _out << "\n _in >> bind(f,m2);\n";
231  _in >> bind(f,m2); // input (18) : DMatrix with bound format, resize from sized
232  _out << "\n _out << cbind(f,m2);\n";
233  _out << cbind(f,m2);
234 
235  eat_comment_lines(_in,'*');
236 
237  _out << "\n _in >> bind(f,m3);\n";
238  _in >> bind(f,m3); // input (19) : DMatrix with bound format, resize form 0
239  _out << "\n _out << cbind(f,m3());\n";
240  _out << cbind(f,m3());
241 
242  eat_comment_lines(_in,'*');
243 
244  _out << "\n _in >> bind(f,m4());\n";
245  { DMatrixSlice t = m4(); _in >> bind(f,t); } // input (20) : DMatrixSlice with bound format, no resizing (must be size 4)
246  _out << "\n _out << cbind(f,m4());\n";
247  _out << cbind(f,m4());
248 
249  eat_comment_lines(_in,'*');
250 
251  _out << "\n _in >> bind(f.ignore_dim(),m1);\n";
252  _in >> bind(f.ignore_dim(),m1); // input (21) : DMatrix with bound format, ignore vector dimension
253  _out << "\n _out << cbind(f,m1);\n";
254  _out << cbind(f,m1);
255 
256  eat_comment_lines(_in,'*');
257 
258  _out << "\n _in >> bind(f,m2);\n";
259  _in >> bind(f,m2); // input (22) : DMatrix with bound format, ignore vector dimension
260  _out << "\n _out << cbind(f,m2);\n";
261  _out << cbind(f,m2);
262 
263  eat_comment_lines(_in,'*');
264 
265  _out << "\n _in >> bind(f,m3);\n";
266  _in >> bind(f,m3); // input (23) : DMatrixSlice with bound format, ignore vector dimension
267  _out << "\n _out << cbind(f,m3());\n";
268  _out << cbind(f,m3());
269 
270  eat_comment_lines(_in,'*');
271 
272  _out << "\n _in >> bind(f,m4());\n";
273  { DMatrixSlice t = m4(); _in >> bind(f,t); } // input (24) : DMatrixSlice with bound format, ignore vector dimension
274  _out << "\n _out << cbind(f,m4());\n";
275  _out << cbind(f,m4());
276 
277  // Test variations of outputing for DMatrix and DMatrixSlice objects
278 
279  _out << "\nTest variations of outputing for DMatrix and DMatrixSlice objects\n";
280 
281  _out << "\n _out << cbind(f.ignore_dim(),m1);\n";
282  _out << cbind(f.ignore_dim(),m1);
283 
284  _out << "\n _out << cbind(f.no_ignore_dim(), const_cast<const DMatrixSlice&>(m1()) );\n";
285  { const DMatrixSlice t = m1(); _out << cbind(f.no_ignore_dim(), t ); }
286 
287  _out << "\n _out << 2*m1.rows() << ' ' << m1.cols() << endl << cbind(f.ignore_dim(),m1) << cbind(f,m1);\n";
288  _out << 2*m1.rows() << ' ' << m1.cols() << endl << cbind(f.ignore_dim(),m1) << cbind(f,m1);
289 
290  _out << "\nIf you read this then no unexpected exceptions occured.\n";
291 
292  } // end try
293  catch(const std::exception& excpt) {
294  _out << "\nCaught a std::exception: " << excpt.what() << endl;
295  }
296  catch(...) {
297  _out << "\nCaught and unknown exception\n";
298  }
299 }
bound_format< T > bind(const format &f, T &obj)
void f()
std::istream & eat_comment_lines(std::istream &is, char comment_identifier)
Discards comment lines from an input stream.
const_bound_format< T > cbind(const format &f, const T &obj)
void TestDenseLinAlgPackIO(std::istream &in, std::ostream &out)