Teuchos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxx_tmpl_main_comp.cpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Teuchos: Common Tools Package
5 // Copyright (2004) 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 Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 // Kris
43 // 07.24.03 -- Initial checkin
44 // 08.08.03 -- All test suites except for TRSM are finished.
45 // 08.14.03 -- The test suite for TRSM is finished (Heidi).
46 /*
47 
48 This test program is intended to check an experimental default type (e.g. mp_real) against an "officialy supported" control type (e.g. double). For each test, the program will generate the appropriate scalars and randomly-sized vectors and matrices of random numbers for the routine being tested. All of the input data for the experimental type is casted into the control type, so in theory both BLAS routines should get the same input data. Upon return, the experimental output data is casted back into the control type, and the results are compared; if they are equal (within a user-definable tolerance) the test is considered successful.
49 
50 The test routine for TRSM is still being developed; all of the others are more or less finalized.
51 
52 */
53 
54 #include "Teuchos_BLAS.hpp"
55 #include "Teuchos_Time.hpp"
56 #include "Teuchos_Version.hpp"
58 
59 using Teuchos::BLAS;
61 
62 // OType1 and OType2 define the ordinal datatypes for which BLAS output will be compared.
63 // The difference in OType should enable the comparison of the templated routines with the "officially" supported BLAS.
64 
65 // Define the scalar type
66 #ifdef HAVE_TEUCHOS_COMPLEX
67 #define SType std::complex<double>
68 #else
69 #define SType double
70 #endif
71 
72 // Define the ordinal type
73 #define OType1 long int
74 #define OType2 int
75 
76 // MVMIN/MAX define the minimum and maximum dimensions of generated matrices and vectors, respectively.
77 // These are well within the range of OType1 and OType2
78 #define MVMIN 2
79 #define MVMAX 20
80 // SCALARMAX defines the maximum positive value (with a little leeway) generated for matrix and std::vector elements and scalars:
81 // random numbers in [-SCALARMAX, SCALARMAX] will be generated.
82 // Set SCALARMAX to a floating-point value (e.g. 10.0) to enable floating-point random number generation, such that
83 // random numbers in (-SCALARMAX - 1, SCALARMAX + 1) will be generated.
84 #ifdef HAVE_TEUCHOS_COMPLEX
85 #define SCALARMAX SType(10,0)
86 #else
87 #define SCALARMAX SType(10)
88 #endif
89 // These define the number of tests to be run for each individual BLAS routine.
90 #define ROTGTESTS 5
91 #define ROTTESTS 5
92 #define ASUMTESTS 5
93 #define AXPYTESTS 5
94 #define COPYTESTS 5
95 #define DOTTESTS 5
96 #define IAMAXTESTS 5
97 #define NRM2TESTS 5
98 #define SCALTESTS 5
99 #define GEMVTESTS 5
100 #define GERTESTS 5
101 #define TRMVTESTS 5
102 #define GEMMTESTS 5
103 #define SYMMTESTS 5
104 #define SYRKTESTS 5
105 #define TRMMTESTS 5
106 #define TRSMTESTS 5
107 
108 // Returns ScalarTraits<TYPE>::random() (the input parameters are ignored)
109 template<typename TYPE>
110 TYPE GetRandom(TYPE, TYPE);
111 
112 // Returns a random integer between the two input parameters, inclusive
113 template<>
114 int GetRandom(int, int);
115 
116 // Returns a random double between the two input parameters, plus or minus a random number between 0 and 1
117 template<>
118 double GetRandom(double, double);
119 
120 template<typename T>
121 std::complex<T> GetRandom( std::complex<T>, std::complex<T> );
122 
123 template<typename TYPE, typename OTYPE>
124 void PrintVector(TYPE* Vector, OTYPE Size, std::string Name, bool Matlab = 0);
125 
126 template<typename TYPE, typename OTYPE>
127 void PrintMatrix(TYPE* Matrix, OTYPE Rows, OTYPE Columns, OTYPE LDM, std::string Name, bool Matlab = 0);
128 
129 template<typename TYPE>
130 bool CompareScalars(TYPE Scalar1, TYPE Scalar2, typename ScalarTraits<TYPE>::magnitudeType Tolerance );
131 
132 template<typename TYPE, typename OTYPE1, typename OTYPE2>
133 bool CompareVectors(TYPE* Vector1, OTYPE1 Size1, TYPE* Vector2, OTYPE2 Size2, typename ScalarTraits<TYPE>::magnitudeType Tolerance );
134 
135 template<typename TYPE, typename OTYPE1, typename OTYPE2>
136 bool CompareMatrices(TYPE* Matrix1, OTYPE1 Rows1, OTYPE1 Columns1, OTYPE1 LDM1,
137  TYPE* Matrix2, OTYPE2 Rows2, OTYPE2 Columns2, OTYPE2 LDM2,
138  typename ScalarTraits<TYPE>::magnitudeType Tolerance );
139 
140 // Use this to convert the larger ordinal type to the smaller one (nothing inherently makes sure of this).
141 template<typename OTYPE1, typename OTYPE2>
142 OTYPE2 ConvertType(OTYPE1 T1, OTYPE2 T2)
143 {
144  return static_cast<OTYPE2>(T1);
145 }
146 
147 // These functions return a random character appropriate for the BLAS arguments that share their names (uses GetRandom())
152 
153 int main(int argc, char *argv[])
154 {
155  Teuchos::GlobalMPISession mpiSession(&argc, &argv);
156  bool verbose = 0;
157  bool debug = 0;
158  bool matlab = 0;
159  bool InvalidCmdLineArgs = 0;
160  int i;
161  OType1 j1, k1;
162  OType2 j2, k2;
163  for(i = 1; i < argc; i++)
164  {
165  if(argv[i][0] == '-')
166  {
167  switch(argv[i][1])
168  {
169  case 'v':
170  if(!verbose)
171  {
172  verbose = 1;
173  }
174  else
175  {
176  InvalidCmdLineArgs = 1;
177  }
178  break;
179  case 'd':
180  if(!debug)
181  {
182  debug = 1;
183  }
184  else
185  {
186  InvalidCmdLineArgs = 1;
187  }
188  break;
189  case 'm':
190  if(!matlab)
191  {
192  matlab = 1;
193  }
194  else
195  {
196  InvalidCmdLineArgs = 1;
197  }
198  break;
199  default:
200  InvalidCmdLineArgs = 1;
201  break;
202  }
203  }
204  }
205 
206  if (verbose)
207  std::cout << Teuchos::Teuchos_Version() << std::endl << std::endl;
208 
209  if(InvalidCmdLineArgs || (argc > 4))
210  {
211  std::cout << "Invalid command line arguments detected. Use the following flags:" << std::endl
212  << "\t -v enables verbose mode (reports number of failed/successful tests)" << std::endl
213  << "\t -d enables debug mode (same as verbose with output of each test, not recommended for large numbers of tests)" << std::endl
214  << "\t -m enables matlab-style output; only has an effect if debug mode is enabled" << std::endl;
215  return 1;
216  }
218  BLAS<OType1, SType> OType1BLAS;
219  BLAS<OType2, SType> OType2BLAS;
220  SType STypezero = ScalarTraits<SType>::zero();
221  SType STypeone = ScalarTraits<SType>::one();
222  SType OType1alpha, OType1beta;
223  SType OType2alpha, OType2beta;
224  SType *OType1A, *OType1B, *OType1C, *OType1x, *OType1y;
225  SType *OType2A, *OType2B, *OType2C, *OType2x, *OType2y;
226  SType OType1ASUMresult, OType1DOTresult, OType1NRM2result, OType1SINresult;
227  SType OType2ASUMresult, OType2DOTresult, OType2NRM2result, OType2SINresult;
228  MType OType1COSresult, OType2COSresult;
229  OType1 incx1, incy1;
230  OType2 incx2, incy2;
231  OType1 OType1IAMAXresult;
232  OType2 OType2IAMAXresult;
233  OType1 TotalTestCount = 1, GoodTestSubcount, GoodTestCount = 0, M1, N1, P1, K1, LDA1, LDB1, LDC1, Mx1, My1;
234  OType2 M2, N2, P2, K2, LDA2, LDB2, LDC2, Mx2, My2;
235  Teuchos::EUplo UPLO;
236  Teuchos::ESide SIDE;
237  Teuchos::ETransp TRANS, TRANSA, TRANSB;
238  Teuchos::EDiag DIAG;
239  MType TOL = 1e-8*ScalarTraits<MType>::one();
240 
241  std::srand(time(NULL));
242 
243  //--------------------------------------------------------------------------------
244  // BEGIN LEVEL 1 BLAS TESTS
245  //--------------------------------------------------------------------------------
246  // Begin ROTG Tests
247  //--------------------------------------------------------------------------------
248  GoodTestSubcount = 0;
249  for(i = 0; i < ROTGTESTS; i++)
250  {
251  OType1alpha = GetRandom(-SCALARMAX, SCALARMAX);
252  OType2alpha = OType1alpha;
253  OType1beta = GetRandom(-SCALARMAX, SCALARMAX);
254  OType2beta = OType1beta;
255  OType1COSresult = ScalarTraits<MType>::zero();
256  OType2COSresult = OType1COSresult;
257  OType1SINresult = ScalarTraits<SType>::zero();
258  OType2SINresult = OType1SINresult;
259 
260  if(debug)
261  {
262  std::cout << "Test #" << TotalTestCount << " -- ROTG -- " << std::endl;
263  std::cout << "OType1alpha = " << OType1alpha << std::endl;
264  std::cout << "OType2alpha = " << OType2alpha << std::endl;
265  std::cout << "OType1beta = " << OType1beta << std::endl;
266  std::cout << "OType2beta = " << OType2beta << std::endl;
267  }
268  TotalTestCount++;
269  OType1BLAS.ROTG(&OType1alpha, &OType1beta, &OType1COSresult, &OType1SINresult);
270  OType2BLAS.ROTG(&OType2alpha, &OType2beta, &OType2COSresult, &OType2SINresult);
271  if(debug)
272  {
273  std::cout << "OType1 ROTG COS result: " << OType1COSresult << std::endl;
274  std::cout << "OType2 ROTG COS result: " << OType2COSresult << std::endl;
275  std::cout << "OType1 ROTG SIN result: " << OType1SINresult << std::endl;
276  std::cout << "OType2 ROTG SIN result: " << OType2SINresult << std::endl;
277  }
278  if ( !CompareScalars(OType1COSresult, OType2COSresult, TOL) || !CompareScalars(OType1SINresult, OType2SINresult, TOL) )
279  std::cout << "FAILED TEST!!!!!!" << std::endl;
280  GoodTestSubcount += ( CompareScalars(OType1COSresult, OType2COSresult, TOL) &&
281  CompareScalars(OType1SINresult, OType2SINresult, TOL) );
282  }
283  GoodTestCount += GoodTestSubcount;
284  if(verbose || debug) std::cout << "ROTG: " << GoodTestSubcount << " of " << ROTGTESTS << " tests were successful." << std::endl;
285  if(debug) std::cout << std::endl;
286  //--------------------------------------------------------------------------------
287  // End ROTG Tests
288  //--------------------------------------------------------------------------------
289 
290  //--------------------------------------------------------------------------------
291  // Begin ROT Tests
292  //--------------------------------------------------------------------------------
293  GoodTestSubcount = 0;
294  for(i = 0; i < ROTTESTS; i++)
295  {
296  incx1 = GetRandom(-5,5);
297  incy1 = GetRandom(-5,5);
298  if (incx1 == 0) incx1 = 1;
299  if (incy1 == 0) incy1 = 1;
300  incx2 = ConvertType( incx1, incx2 );
301  incy2 = ConvertType( incy1, incy2 );
302  M1 = GetRandom(MVMIN, MVMIN+8);
303  M2 = ConvertType( M1, M2 );
304  Mx1 = M1*std::abs(incx1);
305  My1 = M1*std::abs(incy1);
306  if (Mx1 == 0) { Mx1 = 1; }
307  if (My1 == 0) { My1 = 1; }
308  Mx2 = ConvertType( Mx1, Mx2 );
309  My2 = ConvertType( My1, My2 );
310  OType1x = new SType[Mx1];
311  OType1y = new SType[My1];
312  OType2x = new SType[Mx2];
313  OType2y = new SType[My2];
314  for(j1 = 0, j2 = 0; j1 < Mx1; j1++, j2++)
315  {
316  OType1x[j1] = GetRandom(-SCALARMAX, SCALARMAX);
317  OType2x[j2] = OType1x[j1];
318  }
319  for(j1 = 0, j2 = 0; j1 < My1; j1++, j2++)
320  {
321  OType1y[j1] = GetRandom(-SCALARMAX, SCALARMAX);
322  OType2y[j2] = OType1y[j1];
323  }
325  MType c2 = c1;
327  SType s2 = s1;
328  if(debug)
329  {
330  std::cout << "Test #" << TotalTestCount << " -- ROT -- " << std::endl;
331  std::cout << "c1 = " << c1 << ", s1 = " << s1 << std::endl;
332  std::cout << "c2 = " << c2 << ", s2 = " << s2 << std::endl;
333  std::cout << "incx1 = " << incx1 << ", incy1 = " << incy1 << std::endl;
334  std::cout << "incx2 = " << incx2 << ", incy2 = " << incy2 << std::endl;
335  PrintVector(OType1x, Mx1, "OType1x", matlab);
336  PrintVector(OType1y, My1, "OType1y_before_operation", matlab);
337  PrintVector(OType2x, Mx2, "OType2x", matlab);
338  PrintVector(OType2y, My2, "OType2y_before_operation", matlab);
339  }
340  TotalTestCount++;
341  OType1BLAS.ROT(M1, OType1x, incx1, OType1y, incy1, &c1, &s1);
342  OType2BLAS.ROT(M2, OType2x, incx2, OType2y, incy2, &c2, &s2);
343  if(debug)
344  {
345  PrintVector(OType1y, My1, "OType1y_after_operation", matlab);
346  PrintVector(OType2y, My2, "OType2y_after_operation", matlab);
347  }
348  if ( !CompareVectors(OType1x, Mx1, OType2x, Mx2, TOL) || !CompareVectors(OType1y, My1, OType2y, My2, TOL) )
349  std::cout << "FAILED TEST!!!!!!" << std::endl;
350  GoodTestSubcount += ( CompareVectors(OType1x, Mx1, OType2x, Mx2, TOL) &&
351  CompareVectors(OType1y, My1, OType2y, My2, TOL) );
352  delete [] OType1x;
353  delete [] OType1y;
354  delete [] OType2x;
355  delete [] OType2y;
356  }
357  GoodTestCount += GoodTestSubcount;
358  if(verbose || debug) std::cout << "ROT: " << GoodTestSubcount << " of " << ROTTESTS << " tests were successful." << std::endl;
359  if(debug) std::cout << std::endl;
360  //--------------------------------------------------------------------------------
361  // End ROT Tests
362  //--------------------------------------------------------------------------------
363 
364  //--------------------------------------------------------------------------------
365  // Begin ASUM Tests
366  //--------------------------------------------------------------------------------
367  GoodTestSubcount = 0;
369  for(i = 0; i < ASUMTESTS; i++)
370  {
371  incx1 = GetRandom(1, MVMAX);
372  incx2 = ConvertType( incx1, incx2 );
373  M1 = GetRandom(MVMIN, MVMAX);
374  M2 = ConvertType( M1, M2 );
375  OType1x = new SType[M1*incx1];
376  OType2x = new SType[M2*incx2];
377  for(j1 = 0, j2 = 0; j2 < M2*incx2; j1++, j2++)
378  {
379  OType1x[j1] = GetRandom(-SCALARMAX, SCALARMAX);
380  OType2x[j2] = OType1x[j1];
381  }
382  if(debug)
383  {
384  std::cout << "Test #" << TotalTestCount << " -- ASUM -- " << std::endl;
385  std::cout << "incx1 = " << incx1 << "\t" << "incx2 = " << incx2
386  << "\t" << "M1 = " << M1 << "\t" << "M2 = " << M2 << std::endl;
387  PrintVector(OType1x, M1*incx1, "OType1x", matlab);
388  PrintVector(OType2x, M2*incx2, "OType2x", matlab);
389  }
390  TotalTestCount++;
391  OType1ASUMresult = OType1BLAS.ASUM(M1, OType1x, incx1);
392  OType2ASUMresult = OType2BLAS.ASUM(M2, OType2x, incx2);
393  if(debug)
394  {
395  std::cout << "OType1 ASUM result: " << OType1ASUMresult << std::endl;
396  std::cout << "OType2 ASUM result: " << OType2ASUMresult << std::endl;
397  }
398  if (CompareScalars(OType1ASUMresult, OType2ASUMresult, TOL)==0)
399  std::cout << "FAILED TEST!!!!!!" << std::endl;
400  GoodTestSubcount += CompareScalars(OType1ASUMresult, OType2ASUMresult, TOL);
401 
402  delete [] OType1x;
403  delete [] OType2x;
404  }
405  GoodTestCount += GoodTestSubcount;
406  if(verbose || debug) std::cout << "ASUM: " << GoodTestSubcount << " of " << ASUMTESTS << " tests were successful." << std::endl;
407  if(debug) std::cout << std::endl;
408 
409  //--------------------------------------------------------------------------------
410  // End ASUM Tests
411  //--------------------------------------------------------------------------------
412 
413  //--------------------------------------------------------------------------------
414  // Begin AXPY Tests
415  //--------------------------------------------------------------------------------
416  GoodTestSubcount = 0;
417  for(i = 0; i < AXPYTESTS; i++)
418  {
419  incx1 = GetRandom(1, MVMAX);
420  incy1 = GetRandom(1, MVMAX);
421  incx2 = ConvertType( incx1, incx2 );
422  incy2 = ConvertType( incy1, incy2 );
423  M1 = GetRandom(MVMIN, MVMAX);
424  M2 = ConvertType( M1, M2 );
425  Mx1 = M1*std::abs(incx1);
426  My1 = M1*std::abs(incy1);
427  if (Mx1 == 0) { Mx1 = 1; }
428  if (My1 == 0) { My1 = 1; }
429  Mx2 = ConvertType( Mx1, Mx2 );
430  My2 = ConvertType( My1, My2 );
431  OType1x = new SType[Mx1];
432  OType1y = new SType[My1];
433  OType2x = new SType[Mx2];
434  OType2y = new SType[My2];
435  for(j1 = 0, j2 = 0; j1 < Mx1; j1++, j2++)
436  {
437  OType1x[j1] = GetRandom(-SCALARMAX, SCALARMAX);
438  OType2x[j2] = OType1x[j1];
439  }
440  for(j1 = 0, j2 = 0; j1 < My1; j1++, j2++)
441  {
442  OType1y[j1] = GetRandom(-SCALARMAX, SCALARMAX);
443  OType2y[j2] = OType1y[j1];
444  }
445  OType1alpha = GetRandom(-SCALARMAX, SCALARMAX);
446  OType2alpha = OType1alpha;
447  if(debug)
448  {
449  std::cout << "Test #" << TotalTestCount << " -- AXPY -- " << std::endl;
450  std::cout << "OType1alpha = " << OType1alpha << std::endl;
451  std::cout << "OType2alpha = " << OType2alpha << std::endl;
452  PrintVector(OType1x, Mx1, "OType1x", matlab);
453  PrintVector(OType1y, My1, "OType1y_before_operation", matlab);
454  PrintVector(OType2x, Mx2, "OType2x", matlab);
455  PrintVector(OType2y, My2, "OType2y_before_operation", matlab);
456  }
457  TotalTestCount++;
458  OType1BLAS.AXPY(M1, OType1alpha, OType1x, incx1, OType1y, incy1);
459  OType2BLAS.AXPY(M2, OType2alpha, OType2x, incx2, OType2y, incy2);
460  if(debug)
461  {
462  PrintVector(OType1y, My1, "OType1y_after_operation", matlab);
463  PrintVector(OType2y, My2, "OType2y_after_operation", matlab);
464  }
465  if (CompareVectors(OType1y, My1, OType2y, My2, TOL)==0)
466  std::cout << "FAILED TEST!!!!!!" << std::endl;
467  GoodTestSubcount += CompareVectors(OType1y, My1, OType2y, My2, TOL);
468 
469  delete [] OType1x;
470  delete [] OType1y;
471  delete [] OType2x;
472  delete [] OType2y;
473  }
474  GoodTestCount += GoodTestSubcount;
475  if(verbose || debug) std::cout << "AXPY: " << GoodTestSubcount << " of " << AXPYTESTS << " tests were successful." << std::endl;
476  if(debug) std::cout << std::endl;
477  //--------------------------------------------------------------------------------
478  // End AXPY Tests
479  //--------------------------------------------------------------------------------
480 
481  //--------------------------------------------------------------------------------
482  // Begin COPY Tests
483  //--------------------------------------------------------------------------------
484  GoodTestSubcount = 0;
485  for(i = 0; i < COPYTESTS; i++)
486  {
487  incx1 = GetRandom(1, MVMAX);
488  incy1 = GetRandom(1, MVMAX);
489  incx2 = ConvertType( incx1, incx2 );
490  incy2 = ConvertType( incy1, incy2 );
491  M1 = GetRandom(MVMIN, MVMAX);
492  M2 = ConvertType( M1, M2 );
493  Mx1 = M1*std::abs(incx1);
494  My1 = M1*std::abs(incy1);
495  if (Mx1 == 0) { Mx1 = 1; }
496  if (My1 == 0) { My1 = 1; }
497  Mx2 = ConvertType( Mx1, Mx2 );
498  My2 = ConvertType( My1, My2 );
499  OType1x = new SType[Mx1];
500  OType1y = new SType[My1];
501  OType2x = new SType[Mx2];
502  OType2y = new SType[My2];
503  for(j1 = 0, j2 = 0; j1 < Mx1; j1++, j2++)
504  {
505  OType1x[j1] = GetRandom(-SCALARMAX, SCALARMAX);
506  OType2x[j2] = OType1x[j1];
507  }
508  for(j1 = 0, j2 = 0; j1 < My1; j1++, j2++)
509  {
510  OType1y[j1] = GetRandom(-SCALARMAX, SCALARMAX);
511  OType2y[j2] = OType1y[j1];
512  }
513  if(debug)
514  {
515  std::cout << "Test #" << TotalTestCount << " -- COPY -- " << std::endl;
516  PrintVector(OType1x, Mx1, "OType1x", matlab);
517  PrintVector(OType1y, My1, "OType1y_before_operation", matlab);
518  PrintVector(OType2x, Mx2, "OType2x", matlab);
519  PrintVector(OType2y, My2, "OType2y_before_operation", matlab);
520  }
521  TotalTestCount++;
522  OType1BLAS.COPY(M1, OType1x, incx1, OType1y, incy1);
523  OType2BLAS.COPY(M2, OType2x, incx2, OType2y, incy2);
524  if(debug)
525  {
526  PrintVector(OType1y, My1, "OType1y_after_operation", matlab);
527  PrintVector(OType2y, My2, "OType2y_after_operation", matlab);
528  }
529  if (CompareVectors(OType1y, My1, OType2y, My2, TOL) == 0 )
530  std::cout << "FAILED TEST!!!!!!" << std::endl;
531  GoodTestSubcount += CompareVectors(OType1y, My1, OType2y, My2, TOL);
532 
533  delete [] OType1x;
534  delete [] OType1y;
535  delete [] OType2x;
536  delete [] OType2y;
537  }
538  GoodTestCount += GoodTestSubcount; if(verbose || debug) std::cout << "COPY: " << GoodTestSubcount << " of " << COPYTESTS << " tests were successful." << std::endl;
539  if(debug) std::cout << std::endl;
540  //--------------------------------------------------------------------------------
541  // End COPY Tests
542  //--------------------------------------------------------------------------------
543 
544  //--------------------------------------------------------------------------------
545  // Begin DOT Tests
546  //--------------------------------------------------------------------------------
547  GoodTestSubcount = 0;
548  for(i = 0; i < DOTTESTS; i++)
549  {
550  incx1 = GetRandom(1, MVMAX);
551  incy1 = GetRandom(1, MVMAX);
552  incx2 = ConvertType( incx1, incx2 );
553  incy2 = ConvertType( incy1, incy2 );
554  M1 = GetRandom(MVMIN, MVMAX);
555  M2 = ConvertType( M1, M2 );
556  Mx1 = M1*std::abs(incx1);
557  My1 = M1*std::abs(incy1);
558  if (Mx1 == 0) { Mx1 = 1; }
559  if (My1 == 0) { My1 = 1; }
560  Mx2 = ConvertType( Mx1, Mx2 );
561  My2 = ConvertType( My1, My2 );
562  OType1x = new SType[Mx1];
563  OType1y = new SType[My1];
564  OType2x = new SType[Mx2];
565  OType2y = new SType[My2];
566  for(j1 = 0, j2 = 0; j1 < Mx1; j1++, j2++)
567  {
568  OType1x[j1] = GetRandom(-SCALARMAX, SCALARMAX);
569  OType2x[j2] = OType1x[j1];
570  }
571  for(j1 = 0, j2 = 0; j1 < My1; j1++, j2++)
572  {
573  OType1y[j1] = GetRandom(-SCALARMAX, SCALARMAX);
574  OType2y[j2] = OType1y[j1];
575  }
576  if(debug)
577  {
578  std::cout << "Test #" << TotalTestCount << " -- DOT -- " << std::endl;
579  PrintVector(OType1x, Mx1, "OType1x", matlab);
580  PrintVector(OType1y, My1, "OType1y", matlab);
581  PrintVector(OType2x, Mx2, "OType2x", matlab);
582  PrintVector(OType2y, My2, "OType2y", matlab);
583  }
584  TotalTestCount++;
585  OType1DOTresult = OType1BLAS.DOT(M1, OType1x, incx1, OType1y, incy1);
586  OType2DOTresult = OType2BLAS.DOT(M2, OType2x, incx2, OType2y, incy2);
587  if(debug)
588  {
589  std::cout << "OType1 DOT result: " << OType1DOTresult << std::endl;
590  std::cout << "OType2 DOT result: " << OType2DOTresult << std::endl;
591  }
592  if (CompareScalars(OType1DOTresult, OType2DOTresult, TOL) == 0) {
593  std::cout << "DOT test " << i+1 << " of " << DOTTESTS << " FAILED! "
594  << "SType = " << Teuchos::TypeNameTraits<SType>::name () << ". "
595  << "The two results are " << OType1DOTresult << " and "
596  << OType2DOTresult << ". incx1 = " << incx1 << ", incy1 = "
597  << incy1 << ", incx2 = " << incx2 << ", and incy2 = "
598  << incy2 << std::endl;
599  }
600 
601  GoodTestSubcount += CompareScalars(OType1DOTresult, OType2DOTresult, TOL);
602 
603  delete [] OType1x;
604  delete [] OType1y;
605  delete [] OType2x;
606  delete [] OType2y;
607  }
608  GoodTestCount += GoodTestSubcount;
609  if(verbose || debug) std::cout << "DOT: " << GoodTestSubcount << " of " << DOTTESTS << " tests were successful." << std::endl;
610  if(debug) std::cout << std::endl;
611  //--------------------------------------------------------------------------------
612  // End DOT Tests
613  //--------------------------------------------------------------------------------
614 
615  //--------------------------------------------------------------------------------
616  // Begin NRM2 Tests
617  //--------------------------------------------------------------------------------
618  GoodTestSubcount = 0;
619  for(i = 0; i < NRM2TESTS; i++)
620  {
621  incx1 = GetRandom(1, MVMAX);
622  incx2 = ConvertType( incx1, incx2 );
623  M1 = GetRandom(MVMIN, MVMAX);
624  M2 = ConvertType( M1, M2 );
625  OType1x = new SType[M1*incx1];
626  OType2x = new SType[M2*incx2];
627  for(j1 = 0, j2 = 0; j1 < M1*incx1; j1++, j2++)
628  {
629  OType1x[j1] = GetRandom(-SCALARMAX, SCALARMAX);
630  OType2x[j2] = OType1x[j1];
631  }
632  if(debug)
633  {
634  std::cout << "Test #" << TotalTestCount << " -- NRM2 -- " << std::endl;
635  PrintVector(OType1x, M1*incx1, "OType1x", matlab);
636  PrintVector(OType2x, M2*incx2, "OType2x", matlab);
637  }
638  TotalTestCount++;
639  OType1NRM2result = OType1BLAS.NRM2(M1, OType1x, incx1);
640  OType2NRM2result = OType2BLAS.NRM2(M2, OType2x, incx2);
641  if(debug)
642  {
643  std::cout << "OType1 NRM2 result: " << OType1NRM2result << std::endl;
644  std::cout << "OType2 NRM2 result: " << OType2NRM2result << std::endl;
645  }
646  if (CompareScalars(OType1NRM2result, OType2NRM2result, TOL)==0)
647  std::cout << "FAILED TEST!!!!!!" << std::endl;
648  GoodTestSubcount += CompareScalars(OType1NRM2result, OType2NRM2result, TOL);
649 
650  delete [] OType1x;
651  delete [] OType2x;
652  }
653  GoodTestCount += GoodTestSubcount; if(verbose || debug) std::cout << "NRM2: " << GoodTestSubcount << " of " << NRM2TESTS << " tests were successful." << std::endl;
654  if(debug) std::cout << std::endl;
655  //--------------------------------------------------------------------------------
656  // End NRM2 Tests
657  //--------------------------------------------------------------------------------
658 
659  //--------------------------------------------------------------------------------
660  // Begin SCAL Tests
661  //--------------------------------------------------------------------------------
662  GoodTestSubcount = 0;
663  for(i = 0; i < SCALTESTS; i++)
664  {
665  // These will only test for the case that the increment is > 0, the
666  // templated case can handle when incx < 0, but the blas library doesn't
667  // seem to be able to on some machines.
668  incx1 = GetRandom(1, MVMAX);
669  incx2 = ConvertType( incx1, incx2 );
670  M1 = GetRandom(MVMIN, MVMAX);
671  M2 = ConvertType( M1, M2 );
672  OType1x = new SType[M1*incx1];
673  OType2x = new SType[M2*incx2];
674  for(j1 = 0, j2 = 0; j1 < M1*incx1; j1++, j2++)
675  {
676  OType1x[j1] = GetRandom(-SCALARMAX, SCALARMAX);
677  OType2x[j2] = OType1x[j1];
678  }
679  OType1alpha = GetRandom(-SCALARMAX, SCALARMAX);
680  OType2alpha = OType1alpha;
681  if(debug)
682  {
683  std::cout << "Test #" << TotalTestCount << " -- SCAL -- " << std::endl;
684  std::cout << "OType1alpha = " << OType1alpha << std::endl;
685  std::cout << "OType2alpha = " << OType2alpha << std::endl;
686  PrintVector(OType1x, M1*incx1, "OType1x_before_operation", matlab);
687  PrintVector(OType2x, M2*incx2, "OType2x_before_operation", matlab);
688  }
689  TotalTestCount++;
690  OType1BLAS.SCAL(M1, OType1alpha, OType1x, incx1);
691  OType2BLAS.SCAL(M2, OType2alpha, OType2x, incx2);
692  if(debug)
693  {
694  PrintVector(OType1x, M1*incx1, "OType1x_after_operation", matlab);
695  PrintVector(OType2x, M2*incx2, "OType2x_after_operation", matlab);
696  }
697  if (CompareVectors(OType1x, M1*incx1, OType2x, M2*incx2, TOL)==0)
698  std::cout << "FAILED TEST!!!!!!" << std::endl;
699  GoodTestSubcount += CompareVectors(OType1x, M1*incx1, OType2x, M2*incx2, TOL);
700 
701  delete [] OType1x;
702  delete [] OType2x;
703  }
704  GoodTestCount += GoodTestSubcount;
705  if(verbose || debug) std::cout << "SCAL: " << GoodTestSubcount << " of " << SCALTESTS << " tests were successful." << std::endl;
706  if(debug) std::cout << std::endl;
707  //--------------------------------------------------------------------------------
708  // End SCAL Tests
709  //--------------------------------------------------------------------------------
710 
711  //--------------------------------------------------------------------------------
712  // Begin IAMAX Tests
713  //--------------------------------------------------------------------------------
714  GoodTestSubcount = 0;
715  for(i = 0; i < IAMAXTESTS; i++)
716  {
717  incx1 = GetRandom(1, MVMAX);
718  incx2 = ConvertType( incx1, incx2 );
719  M1 = GetRandom(MVMIN, MVMAX);
720  M2 = ConvertType( M1, M2 );
721  OType1x = new SType[M1*incx1];
722  OType2x = new SType[M2*incx2];
723  for(j1 = 0, j2 = 0; j1 < M1*incx1; j1++, j2++)
724  {
725  OType1x[j1] = GetRandom(-SCALARMAX, SCALARMAX);
726  OType2x[j2] = OType1x[j1];
727  }
728  if(debug)
729  {
730  std::cout << "Test #" << TotalTestCount << " -- IAMAX -- " << std::endl;
731  PrintVector(OType1x, M1*incx1, "OType1x", matlab);
732  PrintVector(OType2x, M2*incx2, "OType2x", matlab);
733  }
734  TotalTestCount++;
735  OType1IAMAXresult = OType1BLAS.IAMAX(M1, OType1x, incx1);
736  OType2IAMAXresult = OType2BLAS.IAMAX(M2, OType2x, incx2);
737  if(debug)
738  {
739  std::cout << "OType1 IAMAX result: " << OType1IAMAXresult << std::endl;
740  std::cout << "OType2 IAMAX result: " << OType2IAMAXresult << std::endl;
741  }
742  if (OType1IAMAXresult != OType2IAMAXresult)
743  std::cout << "FAILED TEST!!!!!!" << std::endl;
744  GoodTestSubcount += (OType1IAMAXresult == OType2IAMAXresult);
745 
746  delete [] OType1x;
747  delete [] OType2x;
748  }
749  GoodTestCount += GoodTestSubcount;
750  if(verbose || debug) std::cout << "IAMAX: " << GoodTestSubcount << " of " << IAMAXTESTS << " tests were successful." << std::endl;
751  if(debug) std::cout << std::endl;
752  //--------------------------------------------------------------------------------
753  // End IAMAX Tests
754  //--------------------------------------------------------------------------------
755 
756  //--------------------------------------------------------------------------------
757  // BEGIN LEVEL 2 BLAS TESTS
758  //--------------------------------------------------------------------------------
759  // Begin GEMV Tests
760  //--------------------------------------------------------------------------------
761  GoodTestSubcount = 0;
762  for(i = 0; i < GEMVTESTS; i++)
763  {
764  // The parameters used to construct the test problem are chosen to be
765  // valid parameters, so the GEMV routine won't bomb out.
766  incx1 = GetRandom(1, MVMAX);
767  while (incx1 == 0) {
768  incx1 = GetRandom(1, MVMAX);
769  }
770  incy1 = GetRandom(1, MVMAX);
771  while (incy1 == 0) {
772  incy1 = GetRandom(1, MVMAX);
773  }
774  incx2 = ConvertType( incx1, incx2 );
775  incy2 = ConvertType( incy1, incy2 );
776  M1 = GetRandom(MVMIN, MVMAX);
777  N1 = GetRandom(MVMIN, MVMAX);
778  M2 = ConvertType( M1, M2 );
779  N2 = ConvertType( N1, N2 );
780 
781  TRANS = RandomTRANS();
782  OType1 M2_1 = 0, N2_1 = 0;
783  if (Teuchos::ETranspChar[TRANS] == 'N') {
784  M2_1 = M1*std::abs(incy1);
785  N2_1 = N1*std::abs(incx1);
786  } else {
787  M2_1 = N1*std::abs(incy1);
788  N2_1 = M1*std::abs(incx1);
789  }
790  OType2 M2_2 = ConvertType( M2_1, M2_2 );
791  OType2 N2_2 = ConvertType( N2_1, N2_2 );
792 
793  LDA1 = GetRandom(MVMIN, MVMAX);
794  while (LDA1 < M1) {
795  LDA1 = GetRandom(MVMIN, MVMAX);
796  }
797  LDA2 = ConvertType( LDA1, LDA2 );
798 
799  OType1alpha = GetRandom(-SCALARMAX, SCALARMAX);
800  OType1beta = GetRandom(-SCALARMAX, SCALARMAX);
801  OType2alpha = OType1alpha;
802  OType2beta = OType1beta;
803 
804  OType1A = new SType[LDA1 * N1];
805  OType1x = new SType[N2_1];
806  OType1y = new SType[M2_1];
807  OType2A = new SType[LDA2 * N2];
808  OType2x = new SType[N2_2];
809  OType2y = new SType[M2_2];
810 
811  for(j1 = 0, j2 = 0; j1 < LDA1 * N1; j1++, j2++)
812  {
813  OType1A[j1] = GetRandom(-SCALARMAX, SCALARMAX);
814  OType2A[j2] = OType1A[j1];
815  }
816  for(j1 = 0, j2 = 0; j1 < N2_1; j1++, j2++)
817  {
818  OType1x[j1] = GetRandom(-SCALARMAX, SCALARMAX);
819  OType2x[j2] = OType1x[j1];
820  }
821  for(j1 = 0, j2 = 0; j1 < M2_1; j1++, j2++)
822  {
823  OType1y[j1] = GetRandom(-SCALARMAX, SCALARMAX);
824  OType2y[j2] = OType1y[j1];
825  }
826  if(debug)
827  {
828  std::cout << "Test #" << TotalTestCount << " -- GEMV -- " << std::endl;
829  std::cout << "TRANS = " << Teuchos::ETranspChar[TRANS] << std::endl;
830  std::cout << "OType1alpha = " << OType1alpha << std::endl;
831  std::cout << "OType2alpha = " << OType2alpha << std::endl;
832  std::cout << "OType1beta = " << OType1beta << std::endl;
833  std::cout << "OType2beta = " << OType2beta << std::endl;
834  PrintMatrix(OType1A, M1, N1, LDA1, "OType1A", matlab);
835  PrintVector(OType1x, N2_1, "OType1x", matlab);
836  PrintVector(OType1y, M2_1, "OType1y_before_operation", matlab);
837  PrintMatrix(OType2A, M2, N2, LDA2, "OType2A", matlab);
838  PrintVector(OType2x, N2_2, "OType2x", matlab);
839  PrintVector(OType2y, M2_2, "OType2y_before_operation", matlab);
840  }
841  TotalTestCount++;
842  OType1BLAS.GEMV(TRANS, M1, N1, OType1alpha, OType1A, LDA1, OType1x, incx1, OType1beta, OType1y, incy1);
843  OType2BLAS.GEMV(TRANS, M2, N2, OType2alpha, OType2A, LDA2, OType2x, incx2, OType2beta, OType2y, incy2);
844  if(debug)
845  {
846  PrintVector(OType1y, M2_1, "OType1y_after_operation", matlab);
847  PrintVector(OType2y, M2_2, "OType2y_after_operation", matlab);
848  }
849  if (CompareVectors(OType1y, M2_1, OType2y, M2_2, TOL)==0)
850  std::cout << "FAILED TEST!!!!!!" << std::endl;
851  GoodTestSubcount += CompareVectors(OType1y, M2_1, OType2y, M2_2, TOL);
852 
853  delete [] OType1A;
854  delete [] OType1x;
855  delete [] OType1y;
856  delete [] OType2A;
857  delete [] OType2x;
858  delete [] OType2y;
859  }
860  GoodTestCount += GoodTestSubcount;
861  if(verbose || debug) std::cout << "GEMV: " << GoodTestSubcount << " of " << GEMVTESTS << " tests were successful." << std::endl;
862  if(debug) std::cout << std::endl;
863  //--------------------------------------------------------------------------------
864  // End GEMV Tests
865  //--------------------------------------------------------------------------------
866 
867  //--------------------------------------------------------------------------------
868  // Begin TRMV Tests
869  //--------------------------------------------------------------------------------
870  GoodTestSubcount = 0;
871  for(i = 0; i < TRMVTESTS; i++)
872  {
873  UPLO = RandomUPLO();
874  TRANSA = RandomTRANS();
875 
876  // Since the entries are integers, we don't want to use the unit diagonal feature,
877  // this creates ill-conditioned, nearly-singular matrices.
878  //DIAG = RandomDIAG();
879  DIAG = Teuchos::NON_UNIT_DIAG;
880 
881  N1 = GetRandom(MVMIN, MVMAX);
882  N2 = ConvertType( N1, N2 );
883  incx1 = GetRandom(1, MVMAX);
884  while (incx1 == 0) {
885  incx1 = GetRandom(1, MVMAX);
886  }
887  incx2 = ConvertType( incx1, incx2 );
888  OType1x = new SType[N1*std::abs(incx1)];
889  OType2x = new SType[N2*std::abs(incx2)];
890 
891  for(j1 = 0, j2 = 0; j1 < N1*std::abs(incx1); j1++, j2++)
892  {
893  OType1x[j1] = GetRandom(-SCALARMAX, SCALARMAX);
894  OType2x[j2] = OType1x[j1];
895  }
896 
897  LDA1 = GetRandom(MVMIN, MVMAX);
898  while (LDA1 < N1) {
899  LDA1 = GetRandom(MVMIN, MVMAX);
900  }
901  LDA2 = ConvertType( LDA1, LDA2 );
902  OType1A = new SType[LDA1 * N1];
903  OType2A = new SType[LDA2 * N2];
904 
905  for(j1 = 0, j2 = 0; j1 < N1; j1++, j2++)
906  {
907  if(Teuchos::EUploChar[UPLO] == 'U') {
908  // The operator is upper triangular, make sure that the entries are
909  // only in the upper triangular part of A and the diagonal is non-zero.
910  for(k1 = 0, k2 = 0; k1 < N1; k1++, k2++)
911  {
912  if(k1 < j1) {
913  OType1A[j1*LDA1+k1] = GetRandom(-SCALARMAX, SCALARMAX);
914  } else {
915  OType1A[j1*LDA1+k1] = STypezero;
916  }
917  OType2A[j2*LDA2+k2] = OType1A[j1*LDA1+k1];
918  if(k1 == j1) {
919  if (Teuchos::EDiagChar[DIAG] == 'N') {
920  OType1A[j1*LDA1+k1] = GetRandom(-SCALARMAX, SCALARMAX);
921  while (OType1A[j1*LDA1+k1] == STypezero) {
922  OType1A[j1*LDA1+k1] = GetRandom(-SCALARMAX, SCALARMAX);
923  }
924  OType2A[j2*LDA2+k2] = OType1A[j1*LDA1+k1];
925  } else {
926  OType1A[j1*LDA1+k1] = STypeone;
927  OType2A[j2*LDA2+k2] = STypeone;
928  }
929  }
930  }
931  } else {
932  // The operator is lower triangular, make sure that the entries are
933  // only in the lower triangular part of A and the diagonal is non-zero.
934  for(k1 = 0, k2 = 0; k1 < N1; k1++, k2++)
935  {
936  if(k1 > j1) {
937  OType1A[j1*LDA1+k1] = GetRandom(-SCALARMAX, SCALARMAX);
938  } else {
939  OType1A[j1*LDA1+k1] = STypezero;
940  }
941  OType2A[j2*LDA2+k2] = OType1A[j1*LDA1+k1];
942  if(k1 == j1) {
943  if (Teuchos::EDiagChar[DIAG] == 'N') {
944  OType1A[j1*LDA1+k1] = GetRandom(-SCALARMAX, SCALARMAX);
945  while (OType1A[j1*LDA1+k1] == STypezero) {
946  OType1A[j1*LDA1+k1] = GetRandom(-SCALARMAX, SCALARMAX);
947  }
948  OType2A[j2*LDA2+k2] = OType1A[j1*LDA1+k1];
949  } else {
950  OType1A[j1*LDA1+k1] = STypeone;
951  OType2A[j2*LDA2+k2] = STypeone;
952  }
953  }
954  } // end for(k=0 ...
955  } // end if(UPLO == 'U') ...
956  } // end for(j=0 ... for(j = 0; j < N*N; j++)
957 
958  if(debug)
959  {
960  std::cout << "Test #" << TotalTestCount << " -- TRMV -- " << std::endl;
961  std::cout << "UPLO = " << Teuchos::EUploChar[UPLO] << "\t"
962  << "TRANSA = " << Teuchos::ETranspChar[TRANSA] << "\t"
963  << "DIAG = " << Teuchos::EDiagChar[DIAG] << std::endl;
964  PrintMatrix(OType1A, N1, N1, LDA1,"OType1A", matlab);
965  PrintVector(OType1x, N1*incx1, "OType1x_before_operation", matlab);
966  PrintMatrix(OType2A, N2, N2, LDA2, "OType2A", matlab);
967  PrintVector(OType2x, N2*incx2, "OType2x_before_operation", matlab);
968  }
969  TotalTestCount++;
970  OType1BLAS.TRMV(UPLO, TRANSA, DIAG, N1, OType1A, LDA1, OType1x, incx1);
971  OType2BLAS.TRMV(UPLO, TRANSA, DIAG, N2, OType2A, LDA2, OType2x, incx2);
972  if(debug)
973  {
974  PrintVector(OType1x, N1*incx1, "OType1x_after_operation", matlab);
975  PrintVector(OType2x, N2*incx2, "OType2x_after_operation", matlab);
976  }
977  if (CompareVectors(OType1x, std::abs(N1*incx1), OType2x, std::abs(N2*incx2), TOL)==0)
978  std::cout << "FAILED TEST!!!!!!" << std::endl;
979  GoodTestSubcount += CompareVectors(OType1x, std::abs(N1*incx1), OType2x, std::abs(N2*incx2), TOL);
980 
981  delete [] OType1A;
982  delete [] OType1x;
983  delete [] OType2A;
984  delete [] OType2x;
985  }
986  GoodTestCount += GoodTestSubcount;
987  if(verbose || debug) std::cout << "TRMV: " << GoodTestSubcount << " of " << TRMVTESTS << " tests were successful." << std::endl;
988  if(debug) std::cout << std::endl;
989  //--------------------------------------------------------------------------------
990  // End TRMV Tests
991  //--------------------------------------------------------------------------------
992 
993  //--------------------------------------------------------------------------------
994  // Begin GER Tests
995  //--------------------------------------------------------------------------------
996  GoodTestSubcount = 0;
997  for(i = 0; i < GERTESTS; i++)
998  {
999  incx1 = GetRandom(1, MVMAX);
1000  while (incx1 == 0) {
1001  incx1 = GetRandom(1, MVMAX);
1002  }
1003  incy1 = GetRandom(1, MVMAX);
1004  while (incy1 == 0) {
1005  incy1 = GetRandom(1, MVMAX);
1006  }
1007  incx2 = ConvertType( incx1, incx2 );
1008  incy2 = ConvertType( incy1, incy2 );
1009  M1 = GetRandom(MVMIN, MVMAX);
1010  N1 = GetRandom(MVMIN, MVMAX);
1011  M2 = ConvertType( M1, M2 );
1012  N2 = ConvertType( N1, N2 );
1013 
1014  LDA1 = GetRandom(MVMIN, MVMAX);
1015  while (LDA1 < M1) {
1016  LDA1 = GetRandom(MVMIN, MVMAX);
1017  }
1018  LDA2 = ConvertType( LDA1, LDA2 );
1019 
1020  OType1A = new SType[LDA1 * N1];
1021  OType1x = new SType[M1*std::abs(incx1)];
1022  OType1y = new SType[N1*std::abs(incy1)];
1023  OType2A = new SType[LDA2 * N2];
1024  OType2x = new SType[M2*std::abs(incx2)];
1025  OType2y = new SType[N2*std::abs(incy2)];
1026  OType1alpha = GetRandom(-SCALARMAX, SCALARMAX);
1027  OType2alpha = OType1alpha;
1028  for(j1 = 0, j2 = 0; j1 < LDA1 * N1; j1++, j2++)
1029  {
1030  OType1A[j1] = GetRandom(-SCALARMAX, SCALARMAX);
1031  OType2A[j2] = OType1A[j1];
1032  }
1033  for(j1 = 0, j2 = 0; j1 < std::abs(M1*incx1); j1++, j2++)
1034  {
1035  OType1x[j1] = GetRandom(-SCALARMAX, SCALARMAX);
1036  OType2x[j2] = OType1x[j1];
1037  }
1038  for(j1 = 0, j2 = 0; j1 < std::abs(N1*incy1); j1++, j2++)
1039  {
1040  OType1y[j1] = GetRandom(-SCALARMAX, SCALARMAX);
1041  OType2y[j2] = OType1y[j1];
1042  }
1043  if(debug)
1044  {
1045  std::cout << "Test #" << TotalTestCount << " -- GER -- " << std::endl;
1046  std::cout << "OType1alpha = " << OType1alpha << std::endl;
1047  std::cout << "OType2alpha = " << OType2alpha << std::endl;
1048  PrintMatrix(OType1A, M1, N1, LDA1,"OType1A_before_operation", matlab);
1049  PrintVector(OType1x, std::abs(M1*incx1), "OType1x", matlab);
1050  PrintVector(OType1y, std::abs(N1*incy1), "OType1y", matlab);
1051  PrintMatrix(OType2A, M2, N2, LDA2,"OType2A_before_operation", matlab);
1052  PrintVector(OType2x, std::abs(M2*incx2), "OType2x", matlab);
1053  PrintVector(OType2y, std::abs(N2*incy2), "OType2y", matlab);
1054  }
1055  TotalTestCount++;
1056  OType1BLAS.GER(M1, N1, OType1alpha, OType1x, incx1, OType1y, incy1, OType1A, LDA1);
1057  OType2BLAS.GER(M2, N2, OType2alpha, OType2x, incx2, OType2y, incy2, OType2A, LDA2);
1058  if(debug)
1059  {
1060  PrintMatrix(OType1A, M1, N1, LDA1, "OType1A_after_operation", matlab);
1061  PrintMatrix(OType2A, M2, N2, LDA2, "OType2A_after_operation", matlab);
1062  }
1063  if (CompareMatrices(OType1A, M1, N1, LDA1, OType2A, M2, N2, LDA2, TOL)==0)
1064  std::cout << "FAILED TEST!!!!!!" << std::endl;
1065  GoodTestSubcount += CompareMatrices(OType1A, M1, N1, LDA1, OType2A, M2, N2, LDA2, TOL);
1066 
1067  delete [] OType1A;
1068  delete [] OType1x;
1069  delete [] OType1y;
1070  delete [] OType2A;
1071  delete [] OType2x;
1072  delete [] OType2y;
1073  }
1074  GoodTestCount += GoodTestSubcount;
1075  if(verbose || debug) std::cout << "GER: " << GoodTestSubcount << " of " << GERTESTS << " tests were successful." << std::endl;
1076  if(debug) std::cout << std::endl;
1077  //--------------------------------------------------------------------------------
1078  // End GER Tests
1079  //--------------------------------------------------------------------------------
1080 
1081  //--------------------------------------------------------------------------------
1082  // BEGIN LEVEL 3 BLAS TESTS
1083  //--------------------------------------------------------------------------------
1084  // Begin GEMM Tests
1085  //--------------------------------------------------------------------------------
1086  GoodTestSubcount = 0;
1087  for(i = 0; i < GEMMTESTS; i++)
1088  {
1089  TRANSA = RandomTRANS();
1090  TRANSB = RandomTRANS();
1091  M1 = GetRandom(MVMIN, MVMAX);
1092  N1 = GetRandom(MVMIN, MVMAX);
1093  P1 = GetRandom(MVMIN, MVMAX);
1094  M2 = ConvertType( M1, M2 );
1095  N2 = ConvertType( N1, N2 );
1096  P2 = ConvertType( P1, P2 );
1097 
1098  if(debug) {
1099  std::cout << "Test #" << TotalTestCount << " -- GEMM -- " << std::endl;
1100  std::cout << "TRANSA = " << Teuchos::ETranspChar[TRANSA] << "\t"
1101  << "TRANSB = " << Teuchos::ETranspChar[TRANSB] << std::endl;
1102  }
1103  LDA1 = GetRandom(MVMIN, MVMAX);
1104  if (Teuchos::ETranspChar[TRANSA] == 'N') {
1105  while (LDA1 < M1) { LDA1 = GetRandom(MVMIN, MVMAX); }
1106  LDA2 = ConvertType( LDA1, LDA2 );
1107  OType1A = new SType[LDA1 * P1];
1108  OType2A = new SType[LDA2 * P2];
1109  for(j1 = 0, j2 = 0; j1 < LDA1 * P1; j1++, j2++)
1110  {
1111  OType1A[j1] = GetRandom(-SCALARMAX, SCALARMAX);
1112  OType2A[j2] = OType1A[j1];
1113  }
1114  if (debug) {
1115  PrintMatrix(OType1A, M1, P1, LDA1, "OType1A", matlab);
1116  PrintMatrix(OType2A, M2, P2, LDA2, "OType2A", matlab);
1117  }
1118  } else {
1119  while (LDA1 < P1) { LDA1 = GetRandom(MVMIN, MVMAX); }
1120  LDA2 = ConvertType( LDA1, LDA2 );
1121  OType1A = new SType[LDA1 * M1];
1122  OType2A = new SType[LDA1 * M1];
1123  for(j1 = 0, j2 = 0; j1 < LDA1 * M1; j1++, j2++)
1124  {
1125  OType1A[j1] = GetRandom(-SCALARMAX, SCALARMAX);
1126  OType2A[j2] = OType1A[j1];
1127  }
1128  if (debug) {
1129  PrintMatrix(OType1A, P1, M1, LDA1, "OType1A", matlab);
1130  PrintMatrix(OType2A, P2, M2, LDA2, "OType2A", matlab);
1131  }
1132  }
1133 
1134  LDB1 = GetRandom(MVMIN, MVMAX);
1135  if (Teuchos::ETranspChar[TRANSB] == 'N') {
1136  while (LDB1 < P1) { LDB1 = GetRandom(MVMIN, MVMAX); }
1137  LDB2 = ConvertType( LDB1, LDB2 );
1138  OType1B = new SType[LDB1 * N1];
1139  OType2B = new SType[LDB2 * N2];
1140  for(j1 = 0, j2 = 0; j1 < LDB1 * N1; j1++, j2++)
1141  {
1142  OType1B[j1] = GetRandom(-SCALARMAX, SCALARMAX);
1143  OType2B[j2] = OType1B[j1];
1144  }
1145  if (debug) {
1146  PrintMatrix(OType1B, P1, N1, LDB1,"OType1B", matlab);
1147  PrintMatrix(OType2B, P2, N2, LDB2,"OType2B", matlab);
1148  }
1149  } else {
1150  while (LDB1 < N1) { LDB1 = GetRandom(MVMIN, MVMAX); }
1151  LDB2 = ConvertType( LDB1, LDB2 );
1152  OType1B = new SType[LDB1 * P1];
1153  OType2B = new SType[LDB2 * P2];
1154  for(j1 = 0, j2 = 0; j1 < LDB1 * P1; j1++, j2++)
1155  {
1156  OType1B[j1] = GetRandom(-SCALARMAX, SCALARMAX);
1157  OType2B[j2] = OType1B[j1];
1158  }
1159  if (debug) {
1160  PrintMatrix(OType1B, N1, P1, LDB1,"OType1B", matlab);
1161  PrintMatrix(OType2B, N2, P2, LDB2,"OType2B", matlab);
1162  }
1163  }
1164 
1165  LDC1 = GetRandom(MVMIN, MVMAX);
1166  while (LDC1 < M1) { LDC1 = GetRandom(MVMIN, MVMAX); }
1167  LDC2 = ConvertType( LDC1, LDC2 );
1168  OType1C = new SType[LDC1 * N1];
1169  OType2C = new SType[LDC2 * N2];
1170  for(j1 = 0, j2 = 0; j1 < LDC1 * N1; j1++, j2++) {
1171  OType1C[j1] = GetRandom(-SCALARMAX, SCALARMAX);
1172  OType2C[j2] = OType1C[j1];
1173  }
1174  if(debug)
1175  {
1176  PrintMatrix(OType1C, M1, N1, LDC1, "OType1C_before_operation", matlab);
1177  PrintMatrix(OType2C, M2, N2, LDC2, "OType2C_before_operation", matlab);
1178  }
1179 
1180  OType1alpha = GetRandom(-SCALARMAX, SCALARMAX);
1181  OType1beta = GetRandom(-SCALARMAX, SCALARMAX);
1182  OType2alpha = OType1alpha;
1183  OType2beta = OType1beta;
1184 
1185  TotalTestCount++;
1186  OType1BLAS.GEMM(TRANSA, TRANSB, M1, N1, P1, OType1alpha, OType1A, LDA1, OType1B, LDB1, OType1beta, OType1C, LDC1);
1187  OType2BLAS.GEMM(TRANSA, TRANSB, M2, N2, P2, OType2alpha, OType2A, LDA2, OType2B, LDB2, OType2beta, OType2C, LDC2);
1188  if(debug)
1189  {
1190  std::cout << "M1="<<M1 << "\t" << "N1="<<N1 << "\t" << "P1 = " << P1
1191  << "\t" << "LDA1="<<LDA1 << "\t" << "LDB1="<<LDB1 << "\t" << "LDC1=" << LDC1 << std::endl;
1192  std::cout << "M2="<<M2 << "\t" << "N2="<<N2 << "\t" << "P2 = " << P2
1193  << "\t" << "LDA2="<<LDA2 << "\t" << "LDB2="<<LDB2 << "\t" << "LDC2=" << LDC2 << std::endl;
1194  std::cout << "OType1alpha = " << OType1alpha << std::endl;
1195  std::cout << "OType2alpha = " << OType2alpha << std::endl;
1196  std::cout << "OType1beta = " << OType1beta << std::endl;
1197  std::cout << "OType2beta = " << OType2beta << std::endl;
1198  PrintMatrix(OType1C, M1, N1, LDC1, "OType1C_after_operation", matlab);
1199  PrintMatrix(OType2C, M2, N2, LDC2, "OType2C_after_operation", matlab);
1200  }
1201  if (CompareMatrices(OType1C, M1, N1, LDC1, OType2C, M2, N2, LDC2, TOL)==0)
1202  std::cout << "FAILED TEST!!!!!!" << std::endl;
1203  GoodTestSubcount += CompareMatrices(OType1C, M1, N1, LDC1, OType2C, M2, N2, LDC2, TOL);
1204 
1205  delete [] OType1A;
1206  delete [] OType1B;
1207  delete [] OType1C;
1208  delete [] OType2A;
1209  delete [] OType2B;
1210  delete [] OType2C;
1211  }
1212  GoodTestCount += GoodTestSubcount;
1213  if(verbose || debug) std::cout << "GEMM: " << GoodTestSubcount << " of " << GEMMTESTS << " tests were successful." << std::endl;
1214  if(debug) std::cout << std::endl;
1215  //--------------------------------------------------------------------------------
1216  // End GEMM Tests
1217  //--------------------------------------------------------------------------------
1218 
1219  //--------------------------------------------------------------------------------
1220  // Begin SYMM Tests
1221  //--------------------------------------------------------------------------------
1222  GoodTestSubcount = 0;
1223  for(i = 0; i < SYMMTESTS; i++)
1224  {
1225  M1 = GetRandom(MVMIN, MVMAX);
1226  N1 = GetRandom(MVMIN, MVMAX);
1227  M2 = ConvertType( M1, M2 );
1228  N2 = ConvertType( N1, N2 );
1229  SIDE = RandomSIDE();
1230  UPLO = RandomUPLO();
1231 
1232  LDA1 = GetRandom(MVMIN, MVMAX);
1233  if(Teuchos::ESideChar[SIDE] == 'L') {
1234  while (LDA1 < M1) { LDA1 = GetRandom(MVMIN, MVMAX); }
1235  LDA2 = ConvertType( LDA1, LDA2 );
1236  OType1A = new SType[LDA1 * M1];
1237  OType2A = new SType[LDA2 * M2];
1238  for(j1 = 0, j2 = 0; j1 < LDA1 * M1; j1++, j2++) {
1239  OType1A[j1] = GetRandom(-SCALARMAX, SCALARMAX);
1240  OType2A[j2] = OType1A[j1];
1241  }
1242  } else {
1243  while (LDA1 < N1) { LDA1 = GetRandom(MVMIN, MVMAX); }
1244  LDA2 = ConvertType( LDA1, LDA2 );
1245  OType1A = new SType[LDA1 * N1];
1246  OType2A = new SType[LDA2 * N2];
1247  for(j1 = 0, j2 = 0; j1 < LDA1 * N1; j1++, j2++) {
1248  OType1A[j1] = GetRandom(-SCALARMAX, SCALARMAX);
1249  OType2A[j2] = OType1A[j1];
1250  }
1251  }
1252 
1253  LDB1 = GetRandom(MVMIN, MVMAX);
1254  while (LDB1 < M1) { LDB1 = GetRandom(MVMIN, MVMAX); }
1255  LDB2 = ConvertType( LDB1, LDB2 );
1256  OType1B = new SType[LDB1 * N1];
1257  OType2B = new SType[LDB2 * N2];
1258  for(j1 = 0, j2 = 0; j1 < LDB1 * N1; j1++, j2++) {
1259  OType1B[j1] = GetRandom(-SCALARMAX, SCALARMAX);
1260  OType2B[j2] = OType1B[j1];
1261  }
1262 
1263  LDC1 = GetRandom(MVMIN, MVMAX);
1264  while (LDC1 < M1) { LDC1 = GetRandom(MVMIN, MVMAX); }
1265  LDC2 = ConvertType( LDC1, LDC2 );
1266  OType1C = new SType[LDC1 * N1];
1267  OType2C = new SType[LDC2 * N2];
1268  for(j1 = 0, j2 = 0; j1 < LDC1 * N1; j1++, j2++) {
1269  OType1C[j1] = GetRandom(-SCALARMAX, SCALARMAX);
1270  OType2C[j2] = OType1C[j1];
1271  }
1272 
1273  OType1alpha = GetRandom(-SCALARMAX, SCALARMAX);
1274  OType1beta = GetRandom(-SCALARMAX, SCALARMAX);
1275  OType2alpha = OType1alpha;
1276  OType2beta = OType1beta;
1277  if(debug)
1278  {
1279  std::cout << "Test #" << TotalTestCount << " -- SYMM -- " << std::endl;
1280  std::cout << "SIDE = " << Teuchos::ESideChar[SIDE] << "\t"
1281  << "UPLO = " << Teuchos::EUploChar[UPLO] << std::endl;
1282  std::cout << "OType1alpha = " << OType1alpha << std::endl;
1283  std::cout << "OType2alpha = " << OType2alpha << std::endl;
1284  std::cout << "OType1beta = " << OType1beta << std::endl;
1285  std::cout << "OType2beta = " << OType2beta << std::endl;
1286  if (Teuchos::ESideChar[SIDE] == 'L') {
1287  PrintMatrix(OType1A, M1, M1, LDA1,"OType1A", matlab);
1288  PrintMatrix(OType2A, M2, M2, LDA2,"OType2A", matlab);
1289  } else {
1290  PrintMatrix(OType1A, N1, N1, LDA1, "OType1A", matlab);
1291  PrintMatrix(OType2A, N2, N2, LDA2, "OType2A", matlab);
1292  }
1293  PrintMatrix(OType1B, M1, N1, LDB1,"OType1B", matlab);
1294  PrintMatrix(OType1C, M1, N1, LDC1,"OType1C_before_operation", matlab);
1295  PrintMatrix(OType2B, M2, N2, LDB2,"OType2B", matlab);
1296  PrintMatrix(OType2C, M2, N2, LDC2,"OType2C_before_operation", matlab);
1297  }
1298  TotalTestCount++;
1299 
1300  OType1BLAS.SYMM(SIDE, UPLO, M1, N1, OType1alpha, OType1A, LDA1, OType1B, LDB1, OType1beta, OType1C, LDC1);
1301  OType2BLAS.SYMM(SIDE, UPLO, M2, N2, OType2alpha, OType2A, LDA2, OType2B, LDB2, OType2beta, OType2C, LDC2);
1302  if(debug)
1303  {
1304  PrintMatrix(OType1C, M1, N1, LDC1,"OType1C_after_operation", matlab);
1305  PrintMatrix(OType2C, M2, N2, LDC2,"OType2C_after_operation", matlab);
1306  }
1307  if (CompareMatrices(OType1C, M1, N1, LDC1, OType2C, M2, N2, LDC2, TOL)==0)
1308  std::cout << "FAILED TEST!!!!!!" << std::endl;
1309  GoodTestSubcount += CompareMatrices(OType1C, M1, N1, LDC1, OType2C, M2, N2, LDC2, TOL);
1310 
1311  delete [] OType1A;
1312  delete [] OType1B;
1313  delete [] OType1C;
1314  delete [] OType2A;
1315  delete [] OType2B;
1316  delete [] OType2C;
1317  }
1318  GoodTestCount += GoodTestSubcount;
1319  if(verbose || debug) std::cout << "SYMM: " << GoodTestSubcount << " of " << SYMMTESTS << " tests were successful." << std::endl;
1320  if(debug) std::cout << std::endl;
1321  //--------------------------------------------------------------------------------
1322  // End SYMM Tests
1323  //--------------------------------------------------------------------------------
1324 
1325  //--------------------------------------------------------------------------------
1326  // Begin SYRK Tests
1327  //--------------------------------------------------------------------------------
1328  GoodTestSubcount = 0;
1329  for(i = 0; i < SYRKTESTS; i++)
1330  {
1331  N1 = GetRandom(MVMIN, MVMAX);
1332  K1 = GetRandom(MVMIN, MVMAX);
1333  while (K1 > N1) { K1 = GetRandom(MVMIN, MVMAX); }
1334  N2 = ConvertType( N1, N2 );
1335  K2 = ConvertType( K1, K2 );
1336 
1337  UPLO = RandomUPLO();
1338  TRANS = RandomTRANS();
1339 #ifdef HAVE_TEUCHOS_COMPLEX
1340  while (TRANS == Teuchos::CONJ_TRANS) { TRANS = RandomTRANS(); }
1341 #endif
1342 
1343  LDA1 = GetRandom(MVMIN, MVMAX);
1344  if(Teuchos::ETranspChar[TRANS] == 'N') {
1345  while (LDA1 < N1) { LDA1 = GetRandom(MVMIN, MVMAX); }
1346  LDA2 = ConvertType( LDA1, LDA2 );
1347  OType1A = new SType[LDA1 * K1];
1348  OType2A = new SType[LDA2 * K2];
1349  for(j1 = 0, j2 = 0; j1 < LDA1 * K1; j1++, j2++) {
1350  OType1A[j1] = GetRandom(-SCALARMAX, SCALARMAX);
1351  OType2A[j2] = OType1A[j1];
1352  }
1353  } else {
1354  while (LDA1 < K1) { LDA1 = GetRandom(MVMIN, MVMAX); }
1355  LDA2 = ConvertType( LDA1, LDA2 );
1356  OType1A = new SType[LDA1 * N1];
1357  OType2A = new SType[LDA2 * N2];
1358  for(j1 = 0, j2 = 0; j1 < LDA1 * N1; j1++, j2++) {
1359  OType1A[j1] = GetRandom(-SCALARMAX, SCALARMAX);
1360  OType2A[j2] = OType1A[j1];
1361  }
1362  }
1363 
1364  LDC1 = GetRandom(MVMIN, MVMAX);
1365  while (LDC1 < N1) { LDC1 = GetRandom(MVMIN, MVMAX); }
1366  LDC2 = ConvertType( LDC1, LDC2 );
1367  OType1C = new SType[LDC1 * N1];
1368  OType2C = new SType[LDC2 * N2];
1369  for(j1 = 0, j2 = 0; j1 < N1; j1++, j2++) {
1370 
1371  if(Teuchos::EUploChar[UPLO] == 'U') {
1372  // The operator is upper triangular, make sure that the entries are
1373  // only in the upper triangular part of C.
1374  for(k1 = 0, k2 = 0; k1 < N1; k1++, k2++)
1375  {
1376  if(k1 <= j1) {
1377  OType1C[j1*LDC1+k1] = GetRandom(-SCALARMAX, SCALARMAX);
1378  } else {
1379  OType1C[j1*LDC1+k1] = STypezero;
1380  }
1381  OType2C[j2*LDC2+k2] = OType1C[j1*LDC1+k1];
1382  }
1383  }
1384  else {
1385  for(k1 = 0, k2 = 0; k1 < N1; k1++, k2++)
1386  {
1387  if(k1 >= j1) {
1388  OType1C[j1*LDC1+k1] = GetRandom(-SCALARMAX, SCALARMAX);
1389  } else {
1390  OType1C[j1*LDC1+k1] = STypezero;
1391  }
1392  OType2C[j2*LDC2+k2] = OType1C[j1*LDC1+k1];
1393  }
1394  }
1395  }
1396 
1397  OType1alpha = GetRandom(-SCALARMAX, SCALARMAX);
1398  OType1beta = GetRandom(-SCALARMAX, SCALARMAX);
1399  OType2alpha = OType1alpha;
1400  OType2beta = OType1beta;
1401  if(debug)
1402  {
1403  std::cout << "Test #" << TotalTestCount << " -- SYRK -- " << std::endl;
1404  std::cout << "UPLO = " << Teuchos::EUploChar[UPLO] << "\t"
1405  << "TRANS = " << Teuchos::ETranspChar[TRANS] << std::endl;
1406  std::cout << "N1="<<N1 << "\t" << "K1 = " << K1
1407  << "\t" << "LDA1="<<LDA1 << "\t" << "LDC1=" << LDC1 << std::endl;
1408  std::cout << "N2="<<N2 << "\t" << "K2 = " << K2
1409  << "\t" << "LDA2="<<LDA2 << "\t" << "LDC2=" << LDC2 << std::endl;
1410  std::cout << "OType1alpha = " << OType1alpha << std::endl;
1411  std::cout << "OType2alpha = " << OType2alpha << std::endl;
1412  std::cout << "OType1beta = " << OType1beta << std::endl;
1413  std::cout << "OType2beta = " << OType2beta << std::endl;
1414  if (Teuchos::ETranspChar[TRANS] == 'N') {
1415  PrintMatrix(OType1A, N1, K1, LDA1,"OType1A", matlab);
1416  PrintMatrix(OType2A, N2, K2, LDA2,"OType2A", matlab);
1417  } else {
1418  PrintMatrix(OType1A, K1, N1, LDA1, "OType1A", matlab);
1419  PrintMatrix(OType2A, K2, N2, LDA2, "OType2A", matlab);
1420  }
1421  PrintMatrix(OType1C, N1, N1, LDC1,"OType1C_before_operation", matlab);
1422  PrintMatrix(OType2C, N2, N2, LDC2,"OType2C_before_operation", matlab);
1423  }
1424  TotalTestCount++;
1425 
1426  OType1BLAS.SYRK(UPLO, TRANS, N1, K1, OType1alpha, OType1A, LDA1, OType1beta, OType1C, LDC1);
1427  OType2BLAS.SYRK(UPLO, TRANS, N2, K2, OType2alpha, OType2A, LDA2, OType2beta, OType2C, LDC2);
1428  if(debug)
1429  {
1430  PrintMatrix(OType1C, N1, N1, LDC1,"OType1C_after_operation", matlab);
1431  PrintMatrix(OType2C, N2, N2, LDC2,"OType2C_after_operation", matlab);
1432  }
1433  if (CompareMatrices(OType1C, N1, N1, LDC1, OType2C, N2, N2, LDC2, TOL)==0)
1434  std::cout << "FAILED TEST!!!!!!" << std::endl;
1435  GoodTestSubcount += CompareMatrices(OType1C, N1, N1, LDC1, OType2C, N2, N2, LDC2, TOL);
1436 
1437  delete [] OType1A;
1438  delete [] OType1C;
1439  delete [] OType2A;
1440  delete [] OType2C;
1441  }
1442  GoodTestCount += GoodTestSubcount;
1443  if(verbose || debug) std::cout << "SYRK: " << GoodTestSubcount << " of " << SYRKTESTS << " tests were successful." << std::endl;
1444  if(debug) std::cout << std::endl;
1445  //--------------------------------------------------------------------------------
1446  // End SYRK Tests
1447  //--------------------------------------------------------------------------------
1448 
1449  //--------------------------------------------------------------------------------
1450  // Begin TRMM Tests
1451  //--------------------------------------------------------------------------------
1452  GoodTestSubcount = 0;
1453  for(i = 0; i < TRMMTESTS; i++)
1454  {
1455  M1 = GetRandom(MVMIN, MVMAX);
1456  N1 = GetRandom(MVMIN, MVMAX);
1457  M2 = ConvertType( M1, M2 );
1458  N2 = ConvertType( N1, N2 );
1459 
1460  LDB1 = GetRandom(MVMIN, MVMAX);
1461  while (LDB1 < M1) {
1462  LDB1 = GetRandom(MVMIN, MVMAX);
1463  }
1464  LDB2 = ConvertType( LDB1, LDB2 );
1465 
1466  OType1B = new SType[LDB1 * N1];
1467  OType2B = new SType[LDB2 * N2];
1468 
1469  SIDE = RandomSIDE();
1470  UPLO = RandomUPLO();
1471  TRANSA = RandomTRANS();
1472  DIAG = RandomDIAG();
1473 
1474  if(Teuchos::ESideChar[SIDE] == 'L') // The operator is on the left side
1475  {
1476  LDA1 = GetRandom(MVMIN, MVMAX);
1477  while (LDA1 < M1) {
1478  LDA1 = GetRandom(MVMIN, MVMAX);
1479  }
1480  LDA2 = ConvertType( LDA1, LDA2 );
1481 
1482  OType1A = new SType[LDA1 * M1];
1483  OType2A = new SType[LDA2 * M2];
1484 
1485  for(j1 = 0, j2 = 0; j1 < M1; j1++, j2++)
1486  {
1487  if(Teuchos::EUploChar[UPLO] == 'U') {
1488  // The operator is upper triangular, make sure that the entries are
1489  // only in the upper triangular part of A and the diagonal is non-zero.
1490  for(k1 = 0, k2 = 0; k1 < M1; k1++, k2++)
1491  {
1492  if(k1 < j1) {
1493  OType1A[j1*LDA1+k1] = GetRandom(-SCALARMAX, SCALARMAX);
1494  } else {
1495  OType1A[j1*LDA1+k1] = STypezero;
1496  }
1497  OType2A[j2*LDA2+k2] = OType1A[j1*LDA1+k1];
1498  if(k1 == j1) {
1499  if (Teuchos::EDiagChar[DIAG] == 'N') {
1500  OType1A[j1*LDA1+k1] = GetRandom(-SCALARMAX, SCALARMAX);
1501  while (OType1A[j1*LDA1+k1] == STypezero) {
1502  OType1A[j1*LDA1+k1] = GetRandom(-SCALARMAX, SCALARMAX);
1503  }
1504  OType2A[j2*LDA2+k2] = OType1A[j1*LDA1+k1];
1505  } else {
1506  OType1A[j1*LDA1+k1] = STypeone;
1507  OType2A[j2*LDA2+k2] = STypeone;
1508  }
1509  }
1510  }
1511  } else {
1512  // The operator is lower triangular, make sure that the entries are
1513  // only in the lower triangular part of A and the diagonal is non-zero.
1514  for(k1 = 0, k2 = 0; k1 < M1; k1++, k2++)
1515  {
1516  if(k1 > j1) {
1517  OType1A[j1*LDA1+k1] = GetRandom(-SCALARMAX, SCALARMAX);
1518  } else {
1519  OType1A[j1*LDA1+k1] = STypezero;
1520  }
1521  OType2A[j2*LDA2+k2] = OType1A[j1*LDA1+k1];
1522  if(k1 == j1) {
1523  if (Teuchos::EDiagChar[DIAG] == 'N') {
1524  OType1A[j1*LDA1+k1] = GetRandom(-SCALARMAX, SCALARMAX);
1525  while (OType1A[j1*LDA1+k1] == STypezero) {
1526  OType1A[j1*LDA1+k1] = GetRandom(-SCALARMAX, SCALARMAX);
1527  }
1528  OType2A[j2*LDA2+k2] = OType1A[j1*LDA1+k1];
1529  } else {
1530  OType1A[j1*LDA1+k1] = STypeone;
1531  OType2A[j2*LDA2+k2] = STypeone;
1532  }
1533  }
1534  } // end for(k=0 ...
1535  } // end if(UPLO == 'U') ...
1536  } // end for(j=0 ...
1537  } // if(SIDE == 'L') ...
1538  else // The operator is on the right side
1539  {
1540  LDA1 = GetRandom(MVMIN, MVMAX);
1541  while (LDA1 < N1) {
1542  LDA1 = GetRandom(MVMIN, MVMAX);
1543  }
1544  LDA2 = ConvertType( LDA1, LDA2 );
1545 
1546  OType1A = new SType[LDA1 * N1];
1547  OType2A = new SType[LDA2 * N2];
1548 
1549  for(j1 = 0, j2 = 0; j1 < N1; j1++, j2++)
1550  {
1551  if(Teuchos::EUploChar[UPLO] == 'U') {
1552  // The operator is upper triangular, make sure that the entries are
1553  // only in the upper triangular part of A and the diagonal is non-zero.
1554  for(k1 = 0, k2 = 0; k1 < N1; k1++, k2++)
1555  {
1556  if(k1 < j1) {
1557  OType1A[j1*LDA1+k1] = GetRandom(-SCALARMAX, SCALARMAX);
1558  } else {
1559  OType1A[j1*LDA1+k1] = STypezero;
1560  }
1561  OType2A[j1*LDA1+k1] = OType1A[j1*LDA1+k1];
1562  if(k1 == j1) {
1563  if (Teuchos::EDiagChar[DIAG] == 'N') {
1564  OType1A[j1*LDA1+k1] = GetRandom(-SCALARMAX, SCALARMAX);
1565  while (OType1A[j1*LDA1+k1] == STypezero) {
1566  OType1A[j1*LDA1+k1] = GetRandom(-SCALARMAX, SCALARMAX);
1567  }
1568  OType2A[j2*LDA2+k2] = OType1A[j1*LDA1+k1];
1569  } else {
1570  OType1A[j1*LDA1+k1] = STypeone;
1571  OType2A[j2*LDA2+k2] = STypeone;
1572  }
1573  }
1574  }
1575  } else {
1576  // The operator is lower triangular, make sure that the entries are
1577  // only in the lower triangular part of A and the diagonal is non-zero.
1578  for(k1 = 0, k2 = 0; k1 < N1; k1++, k2++)
1579  {
1580  if(k1 > j1) {
1581  OType1A[j1*LDA1+k1] = GetRandom(-SCALARMAX, SCALARMAX);
1582  } else {
1583  OType1A[j1*LDA1+k1] = STypezero;
1584  }
1585  OType2A[j2*LDA2+k2] = OType1A[j1*LDA1+k1];
1586  if(k1 == j1) {
1587  if (Teuchos::EDiagChar[DIAG] == 'N') {
1588  OType1A[j1*LDA1+k1] = GetRandom(-SCALARMAX, SCALARMAX);
1589  while (OType1A[j1*LDA1+k1] == STypezero) {
1590  OType1A[j1*LDA1+k1] = GetRandom(-SCALARMAX, SCALARMAX);
1591  }
1592  OType2A[j2*LDA2+k2] = OType1A[j1*LDA1+k1];
1593  } else {
1594  OType1A[j1*LDA1+k1] = STypeone;
1595  OType2A[j2*LDA2+k2] = STypeone;
1596  }
1597  }
1598  } // end for(k=0 ...
1599  } // end if(UPLO == 'U') ...
1600  } // end for(j=0 ...
1601  } // end if(SIDE == 'L') ...
1602 
1603  // Fill in the right hand side block B.
1604  for(j1 = 0, j2 = 0; j1 < N1; j1++, j2++) {
1605  for(k1 = 0, k2 = 0; k1 < M1; k1++, k2++) {
1606  OType1B[j1*LDB1+k1] = GetRandom(-SCALARMAX, SCALARMAX);
1607  OType2B[j2*LDB2+k2] = OType1B[j1*LDB1+k1];
1608  }
1609  }
1610  OType1alpha = GetRandom(-SCALARMAX, SCALARMAX);
1611  OType2alpha = OType1alpha;
1612  if(debug)
1613  {
1614  std::cout << "Test #" << TotalTestCount << " -- TRMM -- " << std::endl;
1615  std::cout << "SIDE = " << Teuchos::ESideChar[SIDE] << "\t"
1616  << "UPLO = " << Teuchos::EUploChar[UPLO] << "\t"
1617  << "TRANSA = " << Teuchos::ETranspChar[TRANSA] << "\t"
1618  << "DIAG = " << Teuchos::EDiagChar[DIAG] << std::endl;
1619  std::cout << "OType1alpha = " << OType1alpha << std::endl;
1620  std::cout << "OType2alpha = " << OType2alpha << std::endl;
1621  if(Teuchos::ESideChar[SIDE] == 'L') {
1622  PrintMatrix(OType1A, M1, M1, LDA1, "OType1A", matlab);
1623  PrintMatrix(OType2A, M2, M2, LDA2, "OType2A", matlab);
1624  } else {
1625  PrintMatrix(OType1A, N1, N1, LDA1, "OType1A", matlab);
1626  PrintMatrix(OType2A, N2, N2, LDA2, "OType2A", matlab);
1627  }
1628  PrintMatrix(OType1B, M1, N1, LDB1,"OType1B_before_operation", matlab);
1629  PrintMatrix(OType2B, M2, N2, LDB2,"OType2B_before_operation", matlab);
1630  }
1631  TotalTestCount++;
1632  OType1BLAS.TRMM(SIDE, UPLO, TRANSA, DIAG, M1, N1, OType1alpha, OType1A, LDA1, OType1B, LDB1);
1633  OType2BLAS.TRMM(SIDE, UPLO, TRANSA, DIAG, M2, N2, OType2alpha, OType2A, LDA2, OType2B, LDB2);
1634  if(debug)
1635  {
1636  PrintMatrix(OType1B, M1, N1, LDB1, "OType1B_after_operation", matlab);
1637  PrintMatrix(OType2B, M2, N2, LDB2, "OType2B_after_operation", matlab);
1638  }
1639  if (CompareMatrices(OType1B, M1, N1, LDB1, OType2B, M2, N2, LDB2, TOL)==0)
1640  std::cout << "FAILED TEST!!!!!!" << std::endl;
1641  GoodTestSubcount += CompareMatrices(OType1B, M1, N1, LDB1, OType2B, M2, N2, LDB2, TOL);
1642  delete [] OType1A;
1643  delete [] OType1B;
1644  delete [] OType2A;
1645  delete [] OType2B;
1646  }
1647  GoodTestCount += GoodTestSubcount;
1648  if(verbose || debug) std::cout << "TRMM: " << GoodTestSubcount << " of " << TRMMTESTS << " tests were successful." << std::endl;
1649  if(debug) std::cout << std::endl;
1650  //--------------------------------------------------------------------------------
1651  // End TRMM Tests
1652  //--------------------------------------------------------------------------------
1653 
1654  //--------------------------------------------------------------------------------
1655  // Begin TRSM Tests
1656  //--------------------------------------------------------------------------------
1657  GoodTestSubcount = 0;
1658  for(i = 0; i < TRSMTESTS; i++)
1659  {
1660  M1 = GetRandom(MVMIN, MVMAX);
1661  N1 = GetRandom(MVMIN, MVMAX);
1662  M2 = ConvertType( M1, M2 );
1663  N2 = ConvertType( N1, N2 );
1664 
1665  LDB1 = GetRandom(MVMIN, MVMAX);
1666  while (LDB1 < M1) {
1667  LDB1 = GetRandom(MVMIN, MVMAX);
1668  }
1669  LDB2 = ConvertType( LDB1, LDB2 );
1670 
1671  OType1B = new SType[LDB1 * N1];
1672  OType2B = new SType[LDB2 * N2];
1673 
1674  SIDE = RandomSIDE();
1675  UPLO = RandomUPLO();
1676  TRANSA = RandomTRANS();
1677  // Since the entries are integers, we don't want to use the unit diagonal feature,
1678  // this creates ill-conditioned, nearly-singular matrices.
1679  //DIAG = RandomDIAG();
1680  DIAG = Teuchos::NON_UNIT_DIAG;
1681 
1682  if(Teuchos::ESideChar[SIDE] == 'L') // The operator is on the left side
1683  {
1684  LDA1 = GetRandom(MVMIN, MVMAX);
1685  while (LDA1 < M1) {
1686  LDA1 = GetRandom(MVMIN, MVMAX);
1687  }
1688  LDA2 = ConvertType( LDA1, LDA2 );
1689 
1690  OType1A = new SType[LDA1 * M1];
1691  OType2A = new SType[LDA2 * M2];
1692 
1693  for(j1 = 0, j2 = 0; j1 < M1; j1++, j2++)
1694  {
1695  if(Teuchos::EUploChar[UPLO] == 'U') {
1696  // The operator is upper triangular, make sure that the entries are
1697  // only in the upper triangular part of A and the diagonal is non-zero.
1698  for(k1 = 0, k2 = 0; k1 < M1; k1++, k2++)
1699  {
1700  if(k1 < j1) {
1701  OType1A[j1*LDA1+k1] = GetRandom(-SCALARMAX, SCALARMAX);
1702  } else {
1703  OType1A[j1*LDA1+k1] = STypezero;
1704  }
1705  OType2A[j2*LDA2+k2] = OType1A[j1*LDA1+k1];
1706  if(k1 == j1) {
1707  if (Teuchos::EDiagChar[DIAG] == 'N') {
1708  OType1A[j1*LDA1+k1] = GetRandom(-SCALARMAX, SCALARMAX);
1709  while (OType1A[j1*LDA1+k1] == STypezero) {
1710  OType1A[j1*LDA1+k1] = GetRandom(-SCALARMAX, SCALARMAX);
1711  }
1712  OType2A[j2*LDA2+k2] = OType1A[j1*LDA1+k1];
1713  } else {
1714  OType1A[j1*LDA1+k1] = STypeone;
1715  OType2A[j2*LDA2+k2] = STypeone;
1716  }
1717  }
1718  }
1719  } else {
1720  // The operator is lower triangular, make sure that the entries are
1721  // only in the lower triangular part of A and the diagonal is non-zero.
1722  for(k1 = 0, k2 = 0; k1 < M1; k1++, k2++)
1723  {
1724  if(k1 > j1) {
1725  OType1A[j1*LDA1+k1] = GetRandom(-SCALARMAX, SCALARMAX);
1726  } else {
1727  OType1A[j1*LDA1+k1] = STypezero;
1728  }
1729  OType2A[j2*LDA2+k2] = OType1A[j1*LDA1+k1];
1730  if(k1 == j1) {
1731  if (Teuchos::EDiagChar[DIAG] == 'N') {
1732  OType1A[j1*LDA1+k1] = GetRandom(-SCALARMAX, SCALARMAX);
1733  while (OType1A[j1*LDA1+k1] == STypezero) {
1734  OType1A[j1*LDA1+k1] = GetRandom(-SCALARMAX, SCALARMAX);
1735  }
1736  OType2A[j2*LDA2+k2] = OType1A[j1*LDA1+k1];
1737  } else {
1738  OType1A[j1*LDA1+k1] = STypeone;
1739  OType2A[j2*LDA2+k2] = STypeone;
1740  }
1741  }
1742  } // end for(k=0 ...
1743  } // end if(UPLO == 'U') ...
1744  } // end for(j=0 ...
1745  } // if(SIDE == 'L') ...
1746  else // The operator is on the right side
1747  {
1748  LDA1 = GetRandom(MVMIN, MVMAX);
1749  while (LDA1 < N1) {
1750  LDA1 = GetRandom(MVMIN, MVMAX);
1751  }
1752  LDA2 = ConvertType( LDA1, LDA2 );
1753 
1754  OType1A = new SType[LDA1 * N1];
1755  OType2A = new SType[LDA2 * N2];
1756 
1757  for(j1 = 0, j2 = 0; j1 < N1; j1++, j2++)
1758  {
1759  if(Teuchos::EUploChar[UPLO] == 'U') {
1760  // The operator is upper triangular, make sure that the entries are
1761  // only in the upper triangular part of A and the diagonal is non-zero.
1762  for(k1 = 0, k2 = 0; k1 < N1; k1++, k2++)
1763  {
1764  if(k1 < j1) {
1765  OType1A[j1*LDA1+k1] = GetRandom(-SCALARMAX, SCALARMAX);
1766  } else {
1767  OType1A[j1*LDA1+k1] = STypezero;
1768  }
1769  OType2A[j2*LDA2+k2] = OType1A[j1*LDA1+k1];
1770  if(k1 == j1) {
1771  if (Teuchos::EDiagChar[DIAG] == 'N') {
1772  OType1A[j1*LDA1+k1] = GetRandom(-SCALARMAX, SCALARMAX);
1773  while (OType1A[j1*LDA1+k1] == STypezero) {
1774  OType1A[j1*LDA1+k1] = GetRandom(-SCALARMAX, SCALARMAX);
1775  }
1776  OType2A[j2*LDA2+k2] = OType1A[j1*LDA1+k1];
1777  } else {
1778  OType1A[j1*LDA1+k1] = STypeone;
1779  OType2A[j2*LDA2+k2] = STypeone;
1780  }
1781  }
1782  }
1783  } else {
1784  // The operator is lower triangular, make sure that the entries are
1785  // only in the lower triangular part of A and the diagonal is non-zero.
1786  for(k1 = 0, k2 = 0; k1 < N1; k1++, k2++)
1787  {
1788  if(k1 > j1) {
1789  OType1A[j1*LDA1+k1] = GetRandom(-SCALARMAX, SCALARMAX);
1790  } else {
1791  OType1A[j1*LDA1+k1] = STypezero;
1792  }
1793  OType2A[j2*LDA2+k2] = OType1A[j1*LDA1+k1];
1794  if(k1 == j1) {
1795  if (Teuchos::EDiagChar[DIAG] == 'N') {
1796  OType1A[j1*LDA1+k1] = GetRandom(-SCALARMAX, SCALARMAX);
1797  while (OType1A[j1*LDA1+k1] == STypezero) {
1798  OType1A[j1*LDA1+k1] = GetRandom(-SCALARMAX, SCALARMAX);
1799  }
1800  OType2A[j2*LDA2+k2] = OType1A[j1*LDA1+k1];
1801  } else {
1802  OType1A[j1*LDA1+k1] = STypeone;
1803  OType2A[j2*LDA2+k2] = STypeone;
1804  }
1805  }
1806  } // end for(k=0 ...
1807  } // end if(UPLO == 'U') ...
1808  } // end for(j=0 ...
1809  } // end if(SIDE == 'L') ...
1810 
1811  // Fill in the right hand side block B.
1812  for(j1 = 0, j2 = 0; j1 < N1; j1++, j2++)
1813  {
1814  for(k1 = 0, k2 = 0; k1 < M1; k1++, k2++)
1815  {
1816  OType1B[j1*LDB1+k1] = GetRandom(-SCALARMAX, SCALARMAX);
1817  OType2B[j2*LDB2+k2] = OType1B[j1*LDB1+k1];
1818  }
1819  }
1820 
1821  OType1alpha = GetRandom(-SCALARMAX, SCALARMAX);
1822  OType2alpha = OType1alpha;
1823 
1824  if(debug)
1825  {
1826  std::cout << "Test #" << TotalTestCount << " -- TRSM -- " << std::endl;
1827  std::cout << "SIDE = " << Teuchos::ESideChar[SIDE] << "\t"
1828  << "UPLO = " << Teuchos::EUploChar[UPLO] << "\t"
1829  << "TRANSA = " << Teuchos::ETranspChar[TRANSA] << "\t"
1830  << "DIAG = " << Teuchos::EDiagChar[DIAG] << std::endl;
1831  std::cout << "M1="<<M1 << "\t" << "N1="<<N1 << "\t" << "LDA1="<<LDA1 << "\t" << "LDB1="<<LDB1 << std::endl;
1832  std::cout << "M2="<<M2 << "\t" << "N2="<<N2 << "\t" << "LDA2="<<LDA2 << "\t" << "LDB2="<<LDB2 << std::endl;
1833  std::cout << "OType1alpha = " << OType1alpha << std::endl;
1834  std::cout << "OType2alpha = " << OType2alpha << std::endl;
1835  if (Teuchos::ESideChar[SIDE] == 'L') {
1836  PrintMatrix(OType1A, M1, M1, LDA1, "OType1A", matlab);
1837  PrintMatrix(OType2A, M2, M2, LDA2, "OType2A", matlab);
1838  } else {
1839  PrintMatrix(OType1A, N1, N1, LDA1, "OType1A", matlab);
1840  PrintMatrix(OType2A, N2, N2, LDA2, "OType2A", matlab);
1841  }
1842  PrintMatrix(OType1B, M1, N1, LDB1, "OType1B_before_operation", matlab);
1843  PrintMatrix(OType2B, M2, N2, LDB2, "OType2B_before_operation", matlab);
1844  }
1845  TotalTestCount++;
1846 
1847  OType1BLAS.TRSM(SIDE, UPLO, TRANSA, DIAG, M1, N1, OType1alpha, OType1A, LDA1, OType1B, LDB1);
1848  OType2BLAS.TRSM(SIDE, UPLO, TRANSA, DIAG, M2, N2, OType2alpha, OType2A, LDA2, OType2B, LDB2);
1849 
1850  if(debug)
1851  {
1852  PrintMatrix(OType1B, M1, N1, LDB1, "OType1B_after_operation", matlab);
1853  PrintMatrix(OType2B, M2, N2, LDB2, "OType2B_after_operation", matlab);
1854  }
1855 
1856  if (CompareMatrices(OType1B, M1, N1, LDB1, OType2B, M2, N2, LDB2, TOL)==0)
1857  std::cout << "FAILED TEST!!!!!!" << std::endl;
1858  GoodTestSubcount += CompareMatrices(OType1B, M1, N1, LDB1, OType2B, M2, N2, LDB2, TOL);
1859 
1860  delete [] OType1A;
1861  delete [] OType1B;
1862  delete [] OType2A;
1863  delete [] OType2B;
1864  }
1865  GoodTestCount += GoodTestSubcount;
1866  if(verbose || debug) std::cout << "TRSM: " << GoodTestSubcount << " of " << TRSMTESTS << " tests were successful." << std::endl;
1867  if(debug) std::cout << std::endl;
1868  //--------------------------------------------------------------------------------
1869  // End TRSM Tests
1870  //--------------------------------------------------------------------------------
1871 
1872  if((((TotalTestCount - 1) - GoodTestCount) != 0) || (verbose) || (debug))
1873  {
1874  std::cout << GoodTestCount << " of " << (TotalTestCount - 1) << " total tests were successful." << std::endl;
1875  }
1876 
1877  if ((TotalTestCount-1) == GoodTestCount) {
1878  std::cout << "End Result: TEST PASSED" << std::endl;
1879  return 0;
1880  }
1881 
1882  std::cout << "End Result: TEST FAILED" << std::endl;
1883  return (TotalTestCount-GoodTestCount-1);
1884 }
1885 
1886 template<typename TYPE>
1887 TYPE GetRandom(TYPE Low, TYPE High)
1888 {
1889  return ((TYPE)((double)((1.0 * ScalarTraits<int>::random()) / RAND_MAX) * (High - Low + 1)) + Low);
1890 }
1891 
1892 template<typename T>
1893 std::complex<T> GetRandom( std::complex<T> Low, std::complex<T> High)
1894 {
1895  T lowMag = Low.real();
1896  T highMag = High.real();
1897  T real = (T)(((1.0 * ScalarTraits<int>::random()) / RAND_MAX) * (highMag - lowMag + ScalarTraits<T>::one())) + lowMag;
1898  T imag = (T)(((1.0 * ScalarTraits<int>::random()) / RAND_MAX) * (highMag - lowMag + ScalarTraits<T>::one())) + lowMag;
1899  return std::complex<T>( real, imag );
1900 }
1901 
1902 template<>
1903 int GetRandom(int Low, int High)
1904 {
1905  return ((int)((double)((1.0 * ScalarTraits<int>::random()) / RAND_MAX) * (High - Low + 1)) + Low);
1906 }
1907 
1908 template<>
1909 double GetRandom(double Low, double High)
1910 {
1911  return (((double)((1.0 * ScalarTraits<int>::random()) / RAND_MAX) * (High - Low + 1)) + Low + ScalarTraits<double>::random());
1912 }
1913 
1914 template<typename TYPE, typename OTYPE>
1915 void PrintVector(TYPE* Vector, OTYPE Size, std::string Name, bool Matlab)
1916 {
1917  std::cout << Name << " =" << std::endl;
1918  OTYPE i;
1919  if(Matlab) std::cout << "[";
1920  for(i = 0; i < Size; i++)
1921  {
1922  std::cout << Vector[i] << " ";
1923  }
1924  if(Matlab) std::cout << "]";
1925  if(!Matlab)
1926  {
1927  std::cout << std::endl << std::endl;
1928  }
1929  else
1930  {
1931  std::cout << ";" << std::endl;
1932  }
1933 }
1934 
1935 template<typename TYPE, typename OTYPE>
1936 void PrintMatrix(TYPE* Matrix, OTYPE Rows, OTYPE Columns, OTYPE LDM, std::string Name, bool Matlab)
1937 {
1938  if(!Matlab)
1939  {
1940  std::cout << Name << " =" << std::endl;
1941  OTYPE i, j;
1942  for(i = 0; i < Rows; i++)
1943  {
1944  for(j = 0; j < Columns; j++)
1945  {
1946  std::cout << Matrix[i + (j * LDM)] << " ";
1947  }
1948  std::cout << std::endl;
1949  }
1950  std::cout << std::endl;
1951  }
1952  else
1953  {
1954  std::cout << Name << " = ";
1955  OTYPE i, j;
1956  std::cout << "[";
1957  for(i = 0; i < Rows; i++)
1958  {
1959  std::cout << "[";
1960  for(j = 0; j < Columns; j++)
1961  {
1962  std::cout << Matrix[i + (j * LDM)] << " ";
1963  }
1964  std::cout << "];";
1965  }
1966  std::cout << "];" << std::endl;
1967  }
1968 }
1969 
1970 template<typename TYPE>
1971 bool CompareScalars(TYPE Scalar1, TYPE Scalar2, typename ScalarTraits<TYPE>::magnitudeType Tolerance)
1972 {
1974  typename ScalarTraits<TYPE>::magnitudeType temp2 = ScalarTraits<TYPE>::magnitude(Scalar1 - Scalar2);
1975  if (temp != ScalarTraits<typename ScalarTraits<TYPE>::magnitudeType>::zero()) {
1976  temp2 /= temp;
1977  }
1978  return( temp2 < Tolerance );
1979 }
1980 
1981 
1982 /* Function: CompareVectors
1983  Purpose: Compares the difference between two vectors using relative euclidean-norms, i.e. ||v_1-v_2||_2/||v_2||_2
1984 */
1985 template<typename TYPE, typename OTYPE1, typename OTYPE2>
1986 bool CompareVectors(TYPE* Vector1, OTYPE1 Size1, TYPE* Vector2, OTYPE2 Size2, typename ScalarTraits<TYPE>::magnitudeType Tolerance)
1987 {
1988  TYPE temp = ScalarTraits<TYPE>::zero();
1993  OTYPE1 i1;
1994  OTYPE2 i2;
1995  for(i1 = 0, i2 = 0; i1 < Size1; i1++, i2++)
1996  {
1997  sum2 += ScalarTraits<TYPE>::magnitude(ScalarTraits<TYPE>::conjugate(Vector2[i2])*Vector2[i2]);
1998  temp = Vector1[i1] - Vector2[i2];
2000  }
2002  if (temp2 != ScalarTraits<typename ScalarTraits<TYPE>::magnitudeType>::zero())
2003  temp3 = ScalarTraits<typename ScalarTraits<TYPE>::magnitudeType>::squareroot(sum)/temp2;
2004  else
2006  if (temp3 > Tolerance )
2007  return false;
2008  else
2009  return true;
2010 }
2011 
2012 /* Function: CompareMatrices
2013  Purpose: Compares the difference between two matrices using relative frobenius-norms, i.e. ||M_1-M_2||_F/||M_2||_F
2014 */
2015 template<typename TYPE, typename OTYPE1, typename OTYPE2>
2016 bool CompareMatrices(TYPE* Matrix1, OTYPE1 Rows1, OTYPE1 Columns1, OTYPE1 LDM1,
2017  TYPE* Matrix2, OTYPE2 Rows2, OTYPE2 Columns2, OTYPE2 LDM2,
2018  typename ScalarTraits<TYPE>::magnitudeType Tolerance)
2019 {
2020  TYPE temp = ScalarTraits<TYPE>::zero();
2025  OTYPE1 i1, j1;
2026  OTYPE2 i2, j2;
2027  for(j1 = 0, j2 = 0; j1 < Columns1; j1++, j2++)
2028  {
2029  for(i1 = 0, i2 = 0; i1 < Rows1; i1++, i2++)
2030  {
2031  sum2 = ScalarTraits<TYPE>::magnitude(ScalarTraits<TYPE>::conjugate(Matrix2[j2*LDM2 + i2])*Matrix2[j2*LDM2 + i2]);
2032  temp = Matrix1[j1*LDM1 + i1] - Matrix2[j2*LDM2 + i2];
2034  }
2035  }
2037  if (temp2 != ScalarTraits<typename ScalarTraits<TYPE>::magnitudeType>::zero())
2038  temp3 = ScalarTraits<typename ScalarTraits<TYPE>::magnitudeType>::squareroot(sum)/temp2;
2039  else
2041  if (temp3 > Tolerance)
2042  return false;
2043  else
2044  return true;
2045 }
2046 
2047 
2049 {
2050  Teuchos::ESide result;
2051  int r = GetRandom(1, 2);
2052  if(r == 1)
2053  {
2054  result = Teuchos::LEFT_SIDE;
2055  }
2056  else
2057  {
2058  result = Teuchos::RIGHT_SIDE;
2059  }
2060  return result;
2061 }
2062 
2064 {
2065  Teuchos::EUplo result;
2066  int r = GetRandom(1, 2);
2067  if(r == 1)
2068  {
2069  result = Teuchos::UPPER_TRI;
2070  }
2071  else
2072  {
2073  result = Teuchos::LOWER_TRI;
2074  }
2075  return result;
2076 }
2077 
2079 {
2080  Teuchos::ETransp result;
2081  int r = GetRandom(1, 4);
2082  if(r == 1 || r == 2)
2083  {
2084  result = Teuchos::NO_TRANS;
2085  }
2086  else if(r == 3)
2087  {
2088  result = Teuchos::TRANS;
2089  }
2090  else
2091  {
2092  result = Teuchos::CONJ_TRANS;
2093  }
2094  return result;
2095 }
2096 
2098 {
2099  Teuchos::EDiag result;
2100  int r = GetRandom(1, 2);
2101  if(r == 1)
2102  {
2103  result = Teuchos::NON_UNIT_DIAG;
2104  }
2105  else
2106  {
2107  result = Teuchos::UNIT_DIAG;
2108  }
2109  return result;
2110 }
2111 
#define SYMMTESTS
#define ROTGTESTS
OrdinalType IAMAX(const OrdinalType n, const ScalarType *x, const OrdinalType incx) const
Return the index of the element of x with the maximum magnitude.
#define MVMAX
#define MVMIN
Templated interface class to BLAS routines.
#define TRMMTESTS
#define SType
#define GERTESTS
Basic wall-clock timer class.
void COPY(const OrdinalType n, const ScalarType *x, const OrdinalType incx, ScalarType *y, const OrdinalType incy) const
Copy the vector x to the vector y.
#define IAMAXTESTS
Templated BLAS wrapper.
#define GEMMTESTS
#define TRMVTESTS
void PrintMatrix(TYPE *Matrix, OType Rows, OType Columns, OType LDM, std::string Name, bool Matlab=0)
Initialize, finalize, and query the global MPI session.
TEUCHOSNUMERICS_LIB_DLL_EXPORT const char EDiagChar[]
This structure defines some basic traits for a scalar field type.
#define OType2
Teuchos::EUplo RandomUPLO()
#define DOTTESTS
void SYMM(ESide side, EUplo uplo, const OrdinalType m, const OrdinalType n, const alpha_type alpha, const A_type *A, const OrdinalType lda, const B_type *B, const OrdinalType ldb, const beta_type beta, ScalarType *C, const OrdinalType ldc) const
Performs the matrix-matrix operation: C &lt;- alpha*A*B+beta*C or C &lt;- alpha*B*A+beta*C where A is an m ...
void SCAL(const OrdinalType n, const ScalarType alpha, ScalarType *x, const OrdinalType incx) const
Scale the vector x by the constant alpha.
void ROTG(ScalarType *da, ScalarType *db, MagnitudeType *c, ScalarType *s) const
Computes a Givens plane rotation.
#define GEMVTESTS
void GEMV(ETransp trans, const OrdinalType m, const OrdinalType n, const alpha_type alpha, const A_type *A, const OrdinalType lda, const x_type *x, const OrdinalType incx, const beta_type beta, ScalarType *y, const OrdinalType incy) const
Performs the matrix-vector operation: y &lt;- alpha*A*x+beta*y or y &lt;- alpha*A&#39;*x+beta*y where A is a gene...
TYPE GetRandom(TYPE, TYPE)
#define ASUMTESTS
Teuchos::ESide RandomSIDE()
void SYRK(EUplo uplo, ETransp trans, const OrdinalType n, const OrdinalType k, const alpha_type alpha, const A_type *A, const OrdinalType lda, const beta_type beta, ScalarType *C, const OrdinalType ldc) const
Performs the symmetric rank k operation: C &lt;- alpha*A*A&#39;+beta*C or C &lt;- alpha*A&#39;*A+beta*C, where alpha and beta are scalars, C is an n by n symmetric matrix and A is an n by k matrix in the first case or k by n matrix in the second case.
TEUCHOSNUMERICS_LIB_DLL_EXPORT const char EUploChar[]
Teuchos::EDiag RandomDIAG()
void GEMM(ETransp transa, ETransp transb, const OrdinalType m, const OrdinalType n, const OrdinalType k, const alpha_type alpha, const A_type *A, const OrdinalType lda, const B_type *B, const OrdinalType ldb, const beta_type beta, ScalarType *C, const OrdinalType ldc) const
General matrix-matrix multiply.
#define SCALARMAX
bool CompareVectors(TYPE1 *Vector1, TYPE2 *Vector2, OType Size, TYPE2 Tolerance)
bool CompareScalars(TYPE1 Scalar1, TYPE2 Scalar2, TYPE2 Tolerance)
void TRMM(ESide side, EUplo uplo, ETransp transa, EDiag diag, const OrdinalType m, const OrdinalType n, const alpha_type alpha, const A_type *A, const OrdinalType lda, ScalarType *B, const OrdinalType ldb) const
Performs the matrix-matrix operation: B &lt;- alpha*op(A)*B or B &lt;- alpha*B*op(A) where op(A) is an unit...
TEUCHOSNUMERICS_LIB_DLL_EXPORT const char ESideChar[]
#define ROTTESTS
void AXPY(const OrdinalType n, const alpha_type alpha, const x_type *x, const OrdinalType incx, ScalarType *y, const OrdinalType incy) const
Perform the operation: y &lt;- y+alpha*x.
std::string Teuchos_Version()
void ROT(const OrdinalType n, ScalarType *dx, const OrdinalType incx, ScalarType *dy, const OrdinalType incy, MagnitudeType *c, ScalarType *s) const
Applies a Givens plane rotation.
void PrintVector(TYPE *Vector, OType Size, std::string Name, bool Matlab=0)
int main(int argc, char *argv[])
bool CompareMatrices(TYPE1 *Matrix1, TYPE2 *Matrix2, OType Rows, OType Columns, OType LDM, TYPE2 Tolerance)
TYPE2 ConvertType(TYPE1, TYPE2)
A MPI utilities class, providing methods for initializing, finalizing, and querying the global MPI se...
void TRMV(EUplo uplo, ETransp trans, EDiag diag, const OrdinalType n, const A_type *A, const OrdinalType lda, ScalarType *x, const OrdinalType incx) const
Performs the matrix-vector operation: x &lt;- A*x or x &lt;- A&#39;*x where A is a unit/non-unit n by n upper/low...
void GER(const OrdinalType m, const OrdinalType n, const alpha_type alpha, const x_type *x, const OrdinalType incx, const y_type *y, const OrdinalType incy, ScalarType *A, const OrdinalType lda) const
Performs the rank 1 operation: A &lt;- alpha*x*y&#39;+A.
ScalarTraits< ScalarType >::magnitudeType ASUM(const OrdinalType n, const ScalarType *x, const OrdinalType incx) const
Sum the absolute values of the entries of x.
#define COPYTESTS
#define TRSMTESTS
TEUCHOSNUMERICS_LIB_DLL_EXPORT const char ETranspChar[]
void TRSM(ESide side, EUplo uplo, ETransp transa, EDiag diag, const OrdinalType m, const OrdinalType n, const alpha_type alpha, const A_type *A, const OrdinalType lda, ScalarType *B, const OrdinalType ldb) const
Solves the matrix equations: op(A)*X=alpha*B or X*op(A)=alpha*B where X and B are m by n matrices...
Teuchos::ETransp RandomTRANS()
#define NRM2TESTS
#define AXPYTESTS
#define OType1
ScalarType DOT(const OrdinalType n, const x_type *x, const OrdinalType incx, const y_type *y, const OrdinalType incy) const
Form the dot product of the vectors x and y.
#define SCALTESTS
#define SYRKTESTS
ScalarTraits< ScalarType >::magnitudeType NRM2(const OrdinalType n, const ScalarType *x, const OrdinalType incx) const
Compute the 2-norm of the vector x.