Teuchos - Trilinos Tools Package  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Teuchos_BLAS.hpp
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 // 06.16.03 -- Start over from scratch
44 // 06.16.03 -- Initial templatization (Tpetra_BLAS.cpp is no longer needed)
45 // 06.18.03 -- Changed xxxxx_() function calls to XXXXX_F77()
46 // -- Added warning messages for generic calls
47 // 07.08.03 -- Move into Teuchos package/namespace
48 // 07.24.03 -- The first iteration of BLAS generics is nearing completion. Caveats:
49 // * TRSM isn't finished yet; it works for one case at the moment (left side, upper tri., no transpose, no unit diag.)
50 // * Many of the generic implementations are quite inefficient, ugly, or both. I wrote these to be easy to debug, not for efficiency or legibility. The next iteration will improve both of these aspects as much as possible.
51 // * Very little verification of input parameters is done, save for the character-type arguments (TRANS, etc.) which is quite robust.
52 // * All of the routines that make use of both an incx and incy parameter (which includes much of the L1 BLAS) are set up to work iff incx == incy && incx > 0. Allowing for differing/negative values of incx/incy should be relatively trivial.
53 // * All of the L2/L3 routines assume that the entire matrix is being used (that is, if A is mxn, lda = m); they don't work on submatrices yet. This *should* be a reasonably trivial thing to fix, as well.
54 // -- Removed warning messages for generic calls
55 // 08.08.03 -- TRSM now works for all cases where SIDE == L and DIAG == N. DIAG == U is implemented but does not work correctly; SIDE == R is not yet implemented.
56 // 08.14.03 -- TRSM now works for all cases and accepts (and uses) leading-dimension information.
57 // 09.26.03 -- character input replaced with enumerated input to cause compiling errors and not run-time errors ( suggested by RAB ).
58 
59 #ifndef _TEUCHOS_BLAS_HPP_
60 #define _TEUCHOS_BLAS_HPP_
61 
69 #include "Teuchos_ConfigDefs.hpp"
70 #include "Teuchos_ScalarTraits.hpp"
72 #include "Teuchos_BLAS_types.hpp"
73 #include "Teuchos_Assert.hpp"
74 
107 namespace Teuchos
108 {
109  extern TEUCHOSNUMERICS_LIB_DLL_EXPORT const char ESideChar[];
110  extern TEUCHOSNUMERICS_LIB_DLL_EXPORT const char ETranspChar[];
111  extern TEUCHOSNUMERICS_LIB_DLL_EXPORT const char EUploChar[];
112  extern TEUCHOSNUMERICS_LIB_DLL_EXPORT const char EDiagChar[];
113  extern TEUCHOSNUMERICS_LIB_DLL_EXPORT const char ETypeChar[];
114 
116 
121  template<typename OrdinalType, typename ScalarType>
123  {
124 
125  typedef typename Teuchos::ScalarTraits<ScalarType>::magnitudeType MagnitudeType;
126 
127  public:
129 
130 
132  inline DefaultBLASImpl(void) {}
133 
136 
138  inline virtual ~DefaultBLASImpl(void) {}
140 
142 
143 
145  void ROTG(ScalarType* da, ScalarType* db, MagnitudeType* c, ScalarType* s) const;
146 
148  void ROT(const OrdinalType n, ScalarType* dx, const OrdinalType incx, ScalarType* dy, const OrdinalType incy, MagnitudeType* c, ScalarType* s) const;
149 
151  void SCAL(const OrdinalType n, const ScalarType alpha, ScalarType* x, const OrdinalType incx) const;
152 
154  void COPY(const OrdinalType n, const ScalarType* x, const OrdinalType incx, ScalarType* y, const OrdinalType incy) const;
155 
157  template <typename alpha_type, typename x_type>
158  void AXPY(const OrdinalType n, const alpha_type alpha, const x_type* x, const OrdinalType incx, ScalarType* y, const OrdinalType incy) const;
159 
161  typename ScalarTraits<ScalarType>::magnitudeType ASUM(const OrdinalType n, const ScalarType* x, const OrdinalType incx) const;
162 
164  template <typename x_type, typename y_type>
165  ScalarType DOT(const OrdinalType n, const x_type* x, const OrdinalType incx, const y_type* y, const OrdinalType incy) const;
166 
168  typename ScalarTraits<ScalarType>::magnitudeType NRM2(const OrdinalType n, const ScalarType* x, const OrdinalType incx) const;
169 
171  OrdinalType IAMAX(const OrdinalType n, const ScalarType* x, const OrdinalType incx) const;
173 
175 
176 
178  template <typename alpha_type, typename A_type, typename x_type, typename beta_type>
179  void GEMV(ETransp trans, const OrdinalType m, const OrdinalType n, const alpha_type alpha, const A_type* A,
180  const OrdinalType lda, const x_type* x, const OrdinalType incx, const beta_type beta, ScalarType* y, const OrdinalType incy) const;
181 
183  template <typename A_type>
184  void TRMV(EUplo uplo, ETransp trans, EDiag diag, const OrdinalType n, const A_type* A,
185  const OrdinalType lda, ScalarType* x, const OrdinalType incx) const;
186 
189  template <typename alpha_type, typename x_type, typename y_type>
190  void GER(const OrdinalType m, const OrdinalType n, const alpha_type alpha, const x_type* x, const OrdinalType incx,
191  const y_type* y, const OrdinalType incy, ScalarType* A, const OrdinalType lda) const;
193 
195 
196 
203  template <typename alpha_type, typename A_type, typename B_type, typename beta_type>
204  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;
205 
207  template <typename alpha_type, typename A_type, typename B_type, typename beta_type>
208  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;
209 
211  template <typename alpha_type, typename A_type, typename beta_type>
212  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;
213 
215  template <typename alpha_type, typename A_type>
216  void TRMM(ESide side, EUplo uplo, ETransp transa, EDiag diag, const OrdinalType m, const OrdinalType n,
217  const alpha_type alpha, const A_type* A, const OrdinalType lda, ScalarType* B, const OrdinalType ldb) const;
218 
220  template <typename alpha_type, typename A_type>
221  void TRSM(ESide side, EUplo uplo, ETransp transa, EDiag diag, const OrdinalType m, const OrdinalType n,
222  const alpha_type alpha, const A_type* A, const OrdinalType lda, ScalarType* B, const OrdinalType ldb) const;
224  };
225 
226  template<typename OrdinalType, typename ScalarType>
227  class TEUCHOSNUMERICS_LIB_DLL_EXPORT BLAS : public DefaultBLASImpl<OrdinalType,ScalarType>
228  {
229 
230  typedef typename Teuchos::ScalarTraits<ScalarType>::magnitudeType MagnitudeType;
231 
232  public:
234 
235 
237  inline BLAS(void) {}
238 
240  inline BLAS(const BLAS<OrdinalType, ScalarType>& /*BLAS_source*/) {}
241 
243  inline virtual ~BLAS(void) {}
245  };
246 
247 //------------------------------------------------------------------------------------------
248 // LEVEL 1 BLAS ROUTINES
249 //------------------------------------------------------------------------------------------
250 
258  namespace details {
259 
260  // Compute magnitude.
261  template<typename ScalarType, bool isComplex>
262  class MagValue {
263  public:
264  void
265  blas_dabs1(const ScalarType* a, typename ScalarTraits<ScalarType>::magnitudeType* ret) const;
266  };
267 
268  // Complex-arithmetic specialization.
269  template<typename ScalarType>
270  class MagValue<ScalarType, true> {
271  public:
272  void
273  blas_dabs1(const ScalarType* a, typename ScalarTraits<ScalarType>::magnitudeType* ret) const;
274  };
275 
276  // Real-arithmetic specialization.
277  template<typename ScalarType>
278  class MagValue<ScalarType, false> {
279  public:
280  void
281  blas_dabs1(const ScalarType* a, ScalarType* ret) const;
282  };
283 
284  template<typename ScalarType, bool isComplex>
285  class GivensRotator {
286  public:
287  void
288  ROTG (ScalarType* a,
289  ScalarType* b,
291  ScalarType* s) const;
292  };
293 
294  // Complex-arithmetic specialization.
295  template<typename ScalarType>
296  class GivensRotator<ScalarType, true> {
297  public:
298  void
299  ROTG (ScalarType* ca,
300  ScalarType* cb,
302  ScalarType* s) const;
303  };
304 
305  // Real-arithmetic specialization.
306  template<typename ScalarType>
307  class GivensRotator<ScalarType, false> {
308  public:
309  void
310  ROTG (ScalarType* da,
311  ScalarType* db,
312  ScalarType* c,
313  ScalarType* s) const;
314  private:
327  ScalarType SIGN (ScalarType x, ScalarType y) const {
328  typedef ScalarTraits<ScalarType> STS;
329 
330  if (y > STS::zero()) {
331  return STS::magnitude (x);
332  } else if (y < STS::zero()) {
333  return -STS::magnitude (x);
334  } else { // y == STS::zero()
335  // Suppose that ScalarType implements signed zero, as IEEE
336  // 754 - compliant floating-point numbers should. You can't
337  // use == to test for signed zero, since +0 == -0. However,
338  // 1/0 = Inf > 0 and 1/-0 = -Inf < 0. Let's hope ScalarType
339  // supports Inf... we don't need to test for Inf, just see
340  // if it's greater than or less than zero.
341  //
342  // NOTE: This ONLY works if ScalarType is real. Complex
343  // infinity doesn't have a sign, so we can't compare it with
344  // zero. That's OK, because finite complex numbers don't
345  // have a sign either; they have an angle.
346  ScalarType signedInfinity = STS::one() / y;
347  if (signedInfinity > STS::zero()) {
348  return STS::magnitude (x);
349  } else {
350  // Even if ScalarType doesn't implement signed zero,
351  // Fortran's SIGN intrinsic returns -ABS(X) if the second
352  // argument Y is zero. We imitate this behavior here.
353  return -STS::magnitude (x);
354  }
355  }
356  }
357  };
358 
359  // Implementation of complex-arithmetic specialization.
360  template<typename ScalarType>
361  void
362  GivensRotator<ScalarType, true>::
363  ROTG (ScalarType* ca,
364  ScalarType* cb,
366  ScalarType* s) const
367  {
368  typedef ScalarTraits<ScalarType> STS;
369  typedef typename STS::magnitudeType MagnitudeType;
370  typedef ScalarTraits<MagnitudeType> STM;
371 
372  // This is a straightforward translation into C++ of the
373  // reference BLAS' implementation of ZROTG. You can get
374  // the Fortran 77 source code of ZROTG here:
375  //
376  // http://www.netlib.org/blas/zrotg.f
377  //
378  // I used the following rules to translate Fortran types and
379  // intrinsic functions into C++:
380  //
381  // DOUBLE PRECISION -> MagnitudeType
382  // DOUBLE COMPLEX -> ScalarType
383  // CDABS -> STS::magnitude
384  // DCMPLX -> ScalarType constructor (assuming that ScalarType
385  // is std::complex<MagnitudeType>)
386  // DCONJG -> STS::conjugate
387  // DSQRT -> STM::squareroot
388  ScalarType alpha;
389  MagnitudeType norm, scale;
390 
391  if (STS::magnitude (*ca) == STM::zero()) {
392  *c = STM::zero();
393  *s = STS::one();
394  *ca = *cb;
395  } else {
396  scale = STS::magnitude (*ca) + STS::magnitude (*cb);
397  { // I introduced temporaries into the translated BLAS code in
398  // order to make the expression easier to read and also save a
399  // few floating-point operations.
400  const MagnitudeType ca_scaled =
401  STS::magnitude (*ca / ScalarType(scale, STM::zero()));
402  const MagnitudeType cb_scaled =
403  STS::magnitude (*cb / ScalarType(scale, STM::zero()));
404  norm = scale *
405  STM::squareroot (ca_scaled*ca_scaled + cb_scaled*cb_scaled);
406  }
407  alpha = *ca / STS::magnitude (*ca);
408  *c = STS::magnitude (*ca) / norm;
409  *s = alpha * STS::conjugate (*cb) / norm;
410  *ca = alpha * norm;
411  }
412  }
413 
414  // Implementation of real-arithmetic specialization.
415  template<typename ScalarType>
416  void
417  GivensRotator<ScalarType, false>::
418  ROTG (ScalarType* da,
419  ScalarType* db,
420  ScalarType* c,
421  ScalarType* s) const
422  {
423  typedef ScalarTraits<ScalarType> STS;
424 
425  // This is a straightforward translation into C++ of the
426  // reference BLAS' implementation of DROTG. You can get
427  // the Fortran 77 source code of DROTG here:
428  //
429  // http://www.netlib.org/blas/drotg.f
430  //
431  // I used the following rules to translate Fortran types and
432  // intrinsic functions into C++:
433  //
434  // DOUBLE PRECISION -> ScalarType
435  // DABS -> STS::magnitude
436  // DSQRT -> STM::squareroot
437  // DSIGN -> SIGN (see below)
438  //
439  // DSIGN(x,y) (the old DOUBLE PRECISION type-specific form of
440  // the Fortran type-generic SIGN intrinsic) required special
441  // translation, which we did in a separate utility function in
442  // the specializaton of GivensRotator for real arithmetic.
443  // (ROTG for complex arithmetic doesn't require this function.)
444  // C99 provides a copysign() math library function, but we are
445  // not able to rely on the existence of C99 functions here.
446  ScalarType r, roe, scale, z;
447 
448  roe = *db;
449  if (STS::magnitude (*da) > STS::magnitude (*db)) {
450  roe = *da;
451  }
452  scale = STS::magnitude (*da) + STS::magnitude (*db);
453  if (scale == STS::zero()) {
454  *c = STS::one();
455  *s = STS::zero();
456  r = STS::zero();
457  z = STS::zero();
458  } else {
459  // I introduced temporaries into the translated BLAS code in
460  // order to make the expression easier to read and also save
461  // a few floating-point operations.
462  const ScalarType da_scaled = *da / scale;
463  const ScalarType db_scaled = *db / scale;
464  r = scale * STS::squareroot (da_scaled*da_scaled + db_scaled*db_scaled);
465  r = SIGN (STS::one(), roe) * r;
466  *c = *da / r;
467  *s = *db / r;
468  z = STS::one();
469  if (STS::magnitude (*da) > STS::magnitude (*db)) {
470  z = *s;
471  }
472  if (STS::magnitude (*db) >= STS::magnitude (*da) && *c != STS::zero()) {
473  z = STS::one() / *c;
474  }
475  }
476 
477  *da = r;
478  *db = z;
479  }
480 
481  // Real-valued implementation of MagValue
482  template<typename ScalarType>
483  void
484  MagValue<ScalarType, false>::
485  blas_dabs1(const ScalarType* a, ScalarType* ret) const
486  {
488  }
489 
490  // Complex-valued implementation of MagValue
491  template<typename ScalarType>
492  void
493  MagValue<ScalarType, true>::
494  blas_dabs1(const ScalarType* a, typename ScalarTraits<ScalarType>::magnitudeType* ret) const
495  {
496  *ret = ScalarTraits<typename ScalarTraits<ScalarType>::magnitudeType>::magnitude(a->real());
497  *ret += ScalarTraits<typename ScalarTraits<ScalarType>::magnitudeType>::magnitude(a->imag());
498  }
499 
500  } // namespace details
501 
502  template<typename OrdinalType, typename ScalarType>
503  void
505  ROTG (ScalarType* da,
506  ScalarType* db,
507  MagnitudeType* c,
508  ScalarType* s) const
509  {
510  typedef ScalarTraits<ScalarType> STS;
511  details::GivensRotator<ScalarType, STS::isComplex> rotator;
512  rotator.ROTG (da, db, c, s);
513  }
514 
515  template<typename OrdinalType, typename ScalarType>
516  void DefaultBLASImpl<OrdinalType,ScalarType>::ROT(const OrdinalType n, ScalarType* dx, const OrdinalType incx, ScalarType* dy, const OrdinalType incy, MagnitudeType* c, ScalarType* s) const
517  {
518  OrdinalType izero = OrdinalTraits<OrdinalType>::zero();
519  ScalarType sconj = Teuchos::ScalarTraits<ScalarType>::conjugate(*s);
520  if (n <= 0) return;
521  if (incx==1 && incy==1) {
522  for(OrdinalType i=0; i<n; ++i) {
523  ScalarType temp = *c*dx[i] + sconj*dy[i];
524  dy[i] = *c*dy[i] - sconj*dx[i];
525  dx[i] = temp;
526  }
527  }
528  else {
529  OrdinalType ix = 0, iy = 0;
530  if (incx < izero) ix = (-n+1)*incx;
531  if (incy < izero) iy = (-n+1)*incy;
532  for(OrdinalType i=0; i<n; ++i) {
533  ScalarType temp = *c*dx[ix] + sconj*dy[iy];
534  dy[iy] = *c*dy[iy] - sconj*dx[ix];
535  dx[ix] = temp;
536  ix += incx;
537  iy += incy;
538  }
539  }
540  }
541 
542  template<typename OrdinalType, typename ScalarType>
543  void DefaultBLASImpl<OrdinalType, ScalarType>::SCAL(const OrdinalType n, const ScalarType alpha, ScalarType* x, const OrdinalType incx) const
544  {
545  OrdinalType izero = OrdinalTraits<OrdinalType>::zero();
546  OrdinalType ione = OrdinalTraits<OrdinalType>::one();
547  OrdinalType i, ix = izero;
548 
549  if ( n < ione || incx < ione )
550  return;
551 
552  // Scale the vector.
553  for(i = izero; i < n; i++)
554  {
555  x[ix] *= alpha;
556  ix += incx;
557  }
558  } /* end SCAL */
559 
560  template<typename OrdinalType, typename ScalarType>
561  void DefaultBLASImpl<OrdinalType, ScalarType>::COPY(const OrdinalType n, const ScalarType* x, const OrdinalType incx, ScalarType* y, const OrdinalType incy) const
562  {
563  OrdinalType izero = OrdinalTraits<OrdinalType>::zero();
564  OrdinalType ione = OrdinalTraits<OrdinalType>::one();
565  OrdinalType i, ix = izero, iy = izero;
566  if ( n > izero ) {
567  // Set the initial indices (ix, iy).
568  if (incx < izero) { ix = (-n+ione)*incx; }
569  if (incy < izero) { iy = (-n+ione)*incy; }
570 
571  for(i = izero; i < n; i++)
572  {
573  y[iy] = x[ix];
574  ix += incx;
575  iy += incy;
576  }
577  }
578  } /* end COPY */
579 
580  template<typename OrdinalType, typename ScalarType>
581  template <typename alpha_type, typename x_type>
582  void DefaultBLASImpl<OrdinalType, ScalarType>::AXPY(const OrdinalType n, const alpha_type alpha, const x_type* x, const OrdinalType incx, ScalarType* y, const OrdinalType incy) const
583  {
584  OrdinalType izero = OrdinalTraits<OrdinalType>::zero();
585  OrdinalType ione = OrdinalTraits<OrdinalType>::one();
586  OrdinalType i, ix = izero, iy = izero;
587  if( n > izero && alpha != ScalarTraits<alpha_type>::zero())
588  {
589  // Set the initial indices (ix, iy).
590  if (incx < izero) { ix = (-n+ione)*incx; }
591  if (incy < izero) { iy = (-n+ione)*incy; }
592 
593  for(i = izero; i < n; i++)
594  {
595  y[iy] += alpha * x[ix];
596  ix += incx;
597  iy += incy;
598  }
599  }
600  } /* end AXPY */
601 
602  template<typename OrdinalType, typename ScalarType>
603  typename ScalarTraits<ScalarType>::magnitudeType DefaultBLASImpl<OrdinalType, ScalarType>::ASUM(const OrdinalType n, const ScalarType* x, const OrdinalType incx) const
604  {
605  OrdinalType izero = OrdinalTraits<OrdinalType>::zero();
606  OrdinalType ione = OrdinalTraits<OrdinalType>::one();
607  typename ScalarTraits<ScalarType>::magnitudeType temp, result =
609  OrdinalType i, ix = izero;
610 
611  if ( n < ione || incx < ione )
612  return result;
613 
614  details::MagValue<ScalarType, ScalarTraits<ScalarType>::isComplex> mval;
615  for (i = izero; i < n; i++)
616  {
617  mval.blas_dabs1( &x[ix], &temp );
618  result += temp;
619  ix += incx;
620  }
621 
622  return result;
623  } /* end ASUM */
624 
625  template<typename OrdinalType, typename ScalarType>
626  template <typename x_type, typename y_type>
627  ScalarType DefaultBLASImpl<OrdinalType, ScalarType>::DOT(const OrdinalType n, const x_type* x, const OrdinalType incx, const y_type* y, const OrdinalType incy) const
628  {
629  OrdinalType izero = OrdinalTraits<OrdinalType>::zero();
630  OrdinalType ione = OrdinalTraits<OrdinalType>::one();
631  ScalarType result = ScalarTraits<ScalarType>::zero();
632  OrdinalType i, ix = izero, iy = izero;
633  if( n > izero )
634  {
635  // Set the initial indices (ix,iy).
636  if (incx < izero) { ix = (-n+ione)*incx; }
637  if (incy < izero) { iy = (-n+ione)*incy; }
638 
639  for(i = izero; i < n; i++)
640  {
641  result += ScalarTraits<x_type>::conjugate(x[ix]) * y[iy];
642  ix += incx;
643  iy += incy;
644  }
645  }
646  return result;
647  } /* end DOT */
648 
649  template<typename OrdinalType, typename ScalarType>
650  typename ScalarTraits<ScalarType>::magnitudeType DefaultBLASImpl<OrdinalType, ScalarType>::NRM2(const OrdinalType n, const ScalarType* x, const OrdinalType incx) const
651  {
652  OrdinalType izero = OrdinalTraits<OrdinalType>::zero();
653  OrdinalType ione = OrdinalTraits<OrdinalType>::one();
656  OrdinalType i, ix = izero;
657 
658  if ( n < ione || incx < ione )
659  return result;
660 
661  for(i = izero; i < n; i++)
662  {
664  ix += incx;
665  }
667  return result;
668  } /* end NRM2 */
669 
670  template<typename OrdinalType, typename ScalarType>
671  OrdinalType DefaultBLASImpl<OrdinalType, ScalarType>::IAMAX(const OrdinalType n, const ScalarType* x, const OrdinalType incx) const
672  {
673  OrdinalType izero = OrdinalTraits<OrdinalType>::zero();
674  OrdinalType ione = OrdinalTraits<OrdinalType>::one();
675  OrdinalType result = izero, ix = izero, i;
680 
681  if ( n < ione || incx < ione )
682  return result;
683 
684  details::MagValue<ScalarType, ScalarTraits<ScalarType>::isComplex> mval;
685 
686  mval.blas_dabs1( &x[ix], &maxval );
687  ix += incx;
688  for(i = ione; i < n; i++)
689  {
690  mval.blas_dabs1( &x[ix], &curval );
691  if(curval > maxval)
692  {
693  result = i;
694  maxval = curval;
695  }
696  ix += incx;
697  }
698 
699  return result + 1; // the BLAS I?AMAX functions return 1-indexed (Fortran-style) values
700  } /* end IAMAX */
701 
702 //------------------------------------------------------------------------------------------
703 // LEVEL 2 BLAS ROUTINES
704 //------------------------------------------------------------------------------------------
705  template<typename OrdinalType, typename ScalarType>
706  template <typename alpha_type, typename A_type, typename x_type, typename beta_type>
707  void DefaultBLASImpl<OrdinalType, ScalarType>::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
708  {
709  OrdinalType izero = OrdinalTraits<OrdinalType>::zero();
710  OrdinalType ione = OrdinalTraits<OrdinalType>::one();
711  alpha_type alpha_zero = ScalarTraits<alpha_type>::zero();
712  beta_type beta_zero = ScalarTraits<beta_type>::zero();
713  x_type x_zero = ScalarTraits<x_type>::zero();
714  ScalarType y_zero = ScalarTraits<ScalarType>::zero();
715  beta_type beta_one = ScalarTraits<beta_type>::one();
716  bool noConj = true;
717  bool BadArgument = false;
718 
719  // Quick return if there is nothing to do!
720  if( m == izero || n == izero || ( alpha == alpha_zero && beta == beta_one ) ){ return; }
721 
722  // Otherwise, we need to check the argument list.
723  if( m < izero ) {
724  std::cout << "BLAS::GEMV Error: M == " << m << std::endl;
725  BadArgument = true;
726  }
727  if( n < izero ) {
728  std::cout << "BLAS::GEMV Error: N == " << n << std::endl;
729  BadArgument = true;
730  }
731  if( lda < m ) {
732  std::cout << "BLAS::GEMV Error: LDA < MAX(1,M)"<< std::endl;
733  BadArgument = true;
734  }
735  if( incx == izero ) {
736  std::cout << "BLAS::GEMV Error: INCX == 0"<< std::endl;
737  BadArgument = true;
738  }
739  if( incy == izero ) {
740  std::cout << "BLAS::GEMV Error: INCY == 0"<< std::endl;
741  BadArgument = true;
742  }
743 
744  if(!BadArgument) {
745  OrdinalType i, j, lenx, leny, ix, iy, jx, jy;
746  OrdinalType kx = izero, ky = izero;
747  ScalarType temp;
748 
749  // Determine the lengths of the vectors x and y.
750  if(ETranspChar[trans] == 'N') {
751  lenx = n;
752  leny = m;
753  } else {
754  lenx = m;
755  leny = n;
756  }
757 
758  // Determine if this is a conjugate tranpose
759  noConj = (ETranspChar[trans] == 'T');
760 
761  // Set the starting pointers for the vectors x and y if incx/y < 0.
762  if (incx < izero ) { kx = (ione - lenx)*incx; }
763  if (incy < izero ) { ky = (ione - leny)*incy; }
764 
765  // Form y = beta*y
766  ix = kx; iy = ky;
767  if(beta != beta_one) {
768  if (incy == ione) {
769  if (beta == beta_zero) {
770  for(i = izero; i < leny; i++) { y[i] = y_zero; }
771  } else {
772  for(i = izero; i < leny; i++) { y[i] *= beta; }
773  }
774  } else {
775  if (beta == beta_zero) {
776  for(i = izero; i < leny; i++) {
777  y[iy] = y_zero;
778  iy += incy;
779  }
780  } else {
781  for(i = izero; i < leny; i++) {
782  y[iy] *= beta;
783  iy += incy;
784  }
785  }
786  }
787  }
788 
789  // Return if we don't have to do anything more.
790  if(alpha == alpha_zero) { return; }
791 
792  if( ETranspChar[trans] == 'N' ) {
793  // Form y = alpha*A*y
794  jx = kx;
795  if (incy == ione) {
796  for(j = izero; j < n; j++) {
797  if (x[jx] != x_zero) {
798  temp = alpha*x[jx];
799  for(i = izero; i < m; i++) {
800  y[i] += temp*A[j*lda + i];
801  }
802  }
803  jx += incx;
804  }
805  } else {
806  for(j = izero; j < n; j++) {
807  if (x[jx] != x_zero) {
808  temp = alpha*x[jx];
809  iy = ky;
810  for(i = izero; i < m; i++) {
811  y[iy] += temp*A[j*lda + i];
812  iy += incy;
813  }
814  }
815  jx += incx;
816  }
817  }
818  } else {
819  jy = ky;
820  if (incx == ione) {
821  for(j = izero; j < n; j++) {
822  temp = y_zero;
823  if ( noConj ) {
824  for(i = izero; i < m; i++) {
825  temp += A[j*lda + i]*x[i];
826  }
827  } else {
828  for(i = izero; i < m; i++) {
829  temp += ScalarTraits<A_type>::conjugate(A[j*lda + i])*x[i];
830  }
831  }
832  y[jy] += alpha*temp;
833  jy += incy;
834  }
835  } else {
836  for(j = izero; j < n; j++) {
837  temp = y_zero;
838  ix = kx;
839  if ( noConj ) {
840  for (i = izero; i < m; i++) {
841  temp += A[j*lda + i]*x[ix];
842  ix += incx;
843  }
844  } else {
845  for (i = izero; i < m; i++) {
846  temp += ScalarTraits<A_type>::conjugate(A[j*lda + i])*x[ix];
847  ix += incx;
848  }
849  }
850  y[jy] += alpha*temp;
851  jy += incy;
852  }
853  }
854  }
855  } /* if (!BadArgument) */
856  } /* end GEMV */
857 
858  template<typename OrdinalType, typename ScalarType>
859  template <typename A_type>
860  void DefaultBLASImpl<OrdinalType, ScalarType>::TRMV(EUplo uplo, ETransp trans, EDiag diag, const OrdinalType n, const A_type* A, const OrdinalType lda, ScalarType* x, const OrdinalType incx) const
861  {
862  OrdinalType izero = OrdinalTraits<OrdinalType>::zero();
863  OrdinalType ione = OrdinalTraits<OrdinalType>::one();
864  ScalarType zero = ScalarTraits<ScalarType>::zero();
865  bool BadArgument = false;
866  bool noConj = true;
867 
868  // Quick return if there is nothing to do!
869  if( n == izero ){ return; }
870 
871  // Otherwise, we need to check the argument list.
872  if( n < izero ) {
873  std::cout << "BLAS::TRMV Error: N == " << n << std::endl;
874  BadArgument = true;
875  }
876  if( lda < n ) {
877  std::cout << "BLAS::TRMV Error: LDA < MAX(1,N)"<< std::endl;
878  BadArgument = true;
879  }
880  if( incx == izero ) {
881  std::cout << "BLAS::TRMV Error: INCX == 0"<< std::endl;
882  BadArgument = true;
883  }
884 
885  if(!BadArgument) {
886  OrdinalType i, j, ix, jx, kx = izero;
887  ScalarType temp;
888  bool noUnit = (EDiagChar[diag] == 'N');
889 
890  // Determine if this is a conjugate tranpose
891  noConj = (ETranspChar[trans] == 'T');
892 
893  // Set the starting pointer for the vector x if incx < 0.
894  if (incx < izero) { kx = (-n+ione)*incx; }
895 
896  // Start the operations for a nontransposed triangular matrix
897  if (ETranspChar[trans] == 'N') {
898  /* Compute x = A*x */
899  if (EUploChar[uplo] == 'U') {
900  /* A is an upper triangular matrix */
901  if (incx == ione) {
902  for (j=izero; j<n; j++) {
903  if (x[j] != zero) {
904  temp = x[j];
905  for (i=izero; i<j; i++) {
906  x[i] += temp*A[j*lda + i];
907  }
908  if ( noUnit )
909  x[j] *= A[j*lda + j];
910  }
911  }
912  } else {
913  jx = kx;
914  for (j=izero; j<n; j++) {
915  if (x[jx] != zero) {
916  temp = x[jx];
917  ix = kx;
918  for (i=izero; i<j; i++) {
919  x[ix] += temp*A[j*lda + i];
920  ix += incx;
921  }
922  if ( noUnit )
923  x[jx] *= A[j*lda + j];
924  }
925  jx += incx;
926  }
927  } /* if (incx == ione) */
928  } else { /* A is a lower triangular matrix */
929  if (incx == ione) {
930  for (j=n-ione; j>-ione; j--) {
931  if (x[j] != zero) {
932  temp = x[j];
933  for (i=n-ione; i>j; i--) {
934  x[i] += temp*A[j*lda + i];
935  }
936  if ( noUnit )
937  x[j] *= A[j*lda + j];
938  }
939  }
940  } else {
941  kx += (n-ione)*incx;
942  jx = kx;
943  for (j=n-ione; j>-ione; j--) {
944  if (x[jx] != zero) {
945  temp = x[jx];
946  ix = kx;
947  for (i=n-ione; i>j; i--) {
948  x[ix] += temp*A[j*lda + i];
949  ix -= incx;
950  }
951  if ( noUnit )
952  x[jx] *= A[j*lda + j];
953  }
954  jx -= incx;
955  }
956  }
957  } /* if (EUploChar[uplo]=='U') */
958  } else { /* A is transposed/conjugated */
959  /* Compute x = A'*x */
960  if (EUploChar[uplo]=='U') {
961  /* A is an upper triangular matrix */
962  if (incx == ione) {
963  for (j=n-ione; j>-ione; j--) {
964  temp = x[j];
965  if ( noConj ) {
966  if ( noUnit )
967  temp *= A[j*lda + j];
968  for (i=j-ione; i>-ione; i--) {
969  temp += A[j*lda + i]*x[i];
970  }
971  } else {
972  if ( noUnit )
973  temp *= ScalarTraits<A_type>::conjugate(A[j*lda + j]);
974  for (i=j-ione; i>-ione; i--) {
975  temp += ScalarTraits<A_type>::conjugate(A[j*lda + i])*x[i];
976  }
977  }
978  x[j] = temp;
979  }
980  } else {
981  jx = kx + (n-ione)*incx;
982  for (j=n-ione; j>-ione; j--) {
983  temp = x[jx];
984  ix = jx;
985  if ( noConj ) {
986  if ( noUnit )
987  temp *= A[j*lda + j];
988  for (i=j-ione; i>-ione; i--) {
989  ix -= incx;
990  temp += A[j*lda + i]*x[ix];
991  }
992  } else {
993  if ( noUnit )
994  temp *= ScalarTraits<A_type>::conjugate(A[j*lda + j]);
995  for (i=j-ione; i>-ione; i--) {
996  ix -= incx;
997  temp += ScalarTraits<A_type>::conjugate(A[j*lda + i])*x[ix];
998  }
999  }
1000  x[jx] = temp;
1001  jx -= incx;
1002  }
1003  }
1004  } else {
1005  /* A is a lower triangular matrix */
1006  if (incx == ione) {
1007  for (j=izero; j<n; j++) {
1008  temp = x[j];
1009  if ( noConj ) {
1010  if ( noUnit )
1011  temp *= A[j*lda + j];
1012  for (i=j+ione; i<n; i++) {
1013  temp += A[j*lda + i]*x[i];
1014  }
1015  } else {
1016  if ( noUnit )
1017  temp *= ScalarTraits<A_type>::conjugate(A[j*lda + j]);
1018  for (i=j+ione; i<n; i++) {
1019  temp += ScalarTraits<A_type>::conjugate(A[j*lda + i])*x[i];
1020  }
1021  }
1022  x[j] = temp;
1023  }
1024  } else {
1025  jx = kx;
1026  for (j=izero; j<n; j++) {
1027  temp = x[jx];
1028  ix = jx;
1029  if ( noConj ) {
1030  if ( noUnit )
1031  temp *= A[j*lda + j];
1032  for (i=j+ione; i<n; i++) {
1033  ix += incx;
1034  temp += A[j*lda + i]*x[ix];
1035  }
1036  } else {
1037  if ( noUnit )
1038  temp *= ScalarTraits<A_type>::conjugate(A[j*lda + j]);
1039  for (i=j+ione; i<n; i++) {
1040  ix += incx;
1041  temp += ScalarTraits<A_type>::conjugate(A[j*lda + i])*x[ix];
1042  }
1043  }
1044  x[jx] = temp;
1045  jx += incx;
1046  }
1047  }
1048  } /* if (EUploChar[uplo]=='U') */
1049  } /* if (ETranspChar[trans]=='N') */
1050  } /* if (!BadArgument) */
1051  } /* end TRMV */
1052 
1053  template<typename OrdinalType, typename ScalarType>
1054  template <typename alpha_type, typename x_type, typename y_type>
1055  void DefaultBLASImpl<OrdinalType, ScalarType>::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
1056  {
1057  OrdinalType izero = OrdinalTraits<OrdinalType>::zero();
1058  OrdinalType ione = OrdinalTraits<OrdinalType>::one();
1059  alpha_type alpha_zero = ScalarTraits<alpha_type>::zero();
1060  y_type y_zero = ScalarTraits<y_type>::zero();
1061  bool BadArgument = false;
1062 
1063  // Quick return if there is nothing to do!
1064  if( m == izero || n == izero || alpha == alpha_zero ){ return; }
1065 
1066  // Otherwise, we need to check the argument list.
1067  if( m < izero ) {
1068  std::cout << "BLAS::GER Error: M == " << m << std::endl;
1069  BadArgument = true;
1070  }
1071  if( n < izero ) {
1072  std::cout << "BLAS::GER Error: N == " << n << std::endl;
1073  BadArgument = true;
1074  }
1075  if( lda < m ) {
1076  std::cout << "BLAS::GER Error: LDA < MAX(1,M)"<< std::endl;
1077  BadArgument = true;
1078  }
1079  if( incx == 0 ) {
1080  std::cout << "BLAS::GER Error: INCX == 0"<< std::endl;
1081  BadArgument = true;
1082  }
1083  if( incy == 0 ) {
1084  std::cout << "BLAS::GER Error: INCY == 0"<< std::endl;
1085  BadArgument = true;
1086  }
1087 
1088  if(!BadArgument) {
1089  OrdinalType i, j, ix, jy = izero, kx = izero;
1090  ScalarType temp;
1091 
1092  // Set the starting pointers for the vectors x and y if incx/y < 0.
1093  if (incx < izero) { kx = (-m+ione)*incx; }
1094  if (incy < izero) { jy = (-n+ione)*incy; }
1095 
1096  // Start the operations for incx == 1
1097  if( incx == ione ) {
1098  for( j=izero; j<n; j++ ) {
1099  if ( y[jy] != y_zero ) {
1100  temp = alpha*y[jy];
1101  for ( i=izero; i<m; i++ ) {
1102  A[j*lda + i] += x[i]*temp;
1103  }
1104  }
1105  jy += incy;
1106  }
1107  }
1108  else { // Start the operations for incx != 1
1109  for( j=izero; j<n; j++ ) {
1110  if ( y[jy] != y_zero ) {
1111  temp = alpha*y[jy];
1112  ix = kx;
1113  for( i=izero; i<m; i++ ) {
1114  A[j*lda + i] += x[ix]*temp;
1115  ix += incx;
1116  }
1117  }
1118  jy += incy;
1119  }
1120  }
1121  } /* if(!BadArgument) */
1122  } /* end GER */
1123 
1124 //------------------------------------------------------------------------------------------
1125 // LEVEL 3 BLAS ROUTINES
1126 //------------------------------------------------------------------------------------------
1127 
1128  template<typename OrdinalType, typename ScalarType>
1129  template <typename alpha_type, typename A_type, typename B_type, typename beta_type>
1130  void DefaultBLASImpl<OrdinalType, ScalarType>::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
1131  {
1132 
1133  OrdinalType izero = OrdinalTraits<OrdinalType>::zero();
1134  alpha_type alpha_zero = ScalarTraits<alpha_type>::zero();
1135  beta_type beta_zero = ScalarTraits<beta_type>::zero();
1136  B_type B_zero = ScalarTraits<B_type>::zero();
1137  ScalarType C_zero = ScalarTraits<ScalarType>::zero();
1138  beta_type beta_one = ScalarTraits<beta_type>::one();
1139  OrdinalType i, j, p;
1140  OrdinalType NRowA = m, NRowB = k;
1141  ScalarType temp;
1142  bool BadArgument = false;
1143  bool conjA = false, conjB = false;
1144 
1145  // Change dimensions of matrix if either matrix is transposed
1146  if( !(ETranspChar[transa]=='N') ) {
1147  NRowA = k;
1148  }
1149  if( !(ETranspChar[transb]=='N') ) {
1150  NRowB = n;
1151  }
1152 
1153  // Quick return if there is nothing to do!
1154  if( (m==izero) || (n==izero) || (((alpha==alpha_zero)||(k==izero)) && (beta==beta_one)) ){ return; }
1155  if( m < izero ) {
1156  std::cout << "BLAS::GEMM Error: M == " << m << std::endl;
1157  BadArgument = true;
1158  }
1159  if( n < izero ) {
1160  std::cout << "BLAS::GEMM Error: N == " << n << std::endl;
1161  BadArgument = true;
1162  }
1163  if( k < izero ) {
1164  std::cout << "BLAS::GEMM Error: K == " << k << std::endl;
1165  BadArgument = true;
1166  }
1167  if( lda < NRowA ) {
1168  std::cout << "BLAS::GEMM Error: LDA < "<<NRowA<<std::endl;
1169  BadArgument = true;
1170  }
1171  if( ldb < NRowB ) {
1172  std::cout << "BLAS::GEMM Error: LDB < "<<NRowB<<std::endl;
1173  BadArgument = true;
1174  }
1175  if( ldc < m ) {
1176  std::cout << "BLAS::GEMM Error: LDC < MAX(1,M)"<< std::endl;
1177  BadArgument = true;
1178  }
1179 
1180  if(!BadArgument) {
1181 
1182  // Determine if this is a conjugate tranpose
1183  conjA = (ETranspChar[transa] == 'C');
1184  conjB = (ETranspChar[transb] == 'C');
1185 
1186  // Only need to scale the resulting matrix C.
1187  if( alpha == alpha_zero ) {
1188  if( beta == beta_zero ) {
1189  for (j=izero; j<n; j++) {
1190  for (i=izero; i<m; i++) {
1191  C[j*ldc + i] = C_zero;
1192  }
1193  }
1194  } else {
1195  for (j=izero; j<n; j++) {
1196  for (i=izero; i<m; i++) {
1197  C[j*ldc + i] *= beta;
1198  }
1199  }
1200  }
1201  return;
1202  }
1203  //
1204  // Now start the operations.
1205  //
1206  if ( ETranspChar[transb]=='N' ) {
1207  if ( ETranspChar[transa]=='N' ) {
1208  // Compute C = alpha*A*B + beta*C
1209  for (j=izero; j<n; j++) {
1210  if( beta == beta_zero ) {
1211  for (i=izero; i<m; i++){
1212  C[j*ldc + i] = C_zero;
1213  }
1214  } else if( beta != beta_one ) {
1215  for (i=izero; i<m; i++){
1216  C[j*ldc + i] *= beta;
1217  }
1218  }
1219  for (p=izero; p<k; p++){
1220  if (B[j*ldb + p] != B_zero ){
1221  temp = alpha*B[j*ldb + p];
1222  for (i=izero; i<m; i++) {
1223  C[j*ldc + i] += temp*A[p*lda + i];
1224  }
1225  }
1226  }
1227  }
1228  } else if ( conjA ) {
1229  // Compute C = alpha*conj(A')*B + beta*C
1230  for (j=izero; j<n; j++) {
1231  for (i=izero; i<m; i++) {
1232  temp = C_zero;
1233  for (p=izero; p<k; p++) {
1234  temp += ScalarTraits<A_type>::conjugate(A[i*lda + p])*B[j*ldb + p];
1235  }
1236  if (beta == beta_zero) {
1237  C[j*ldc + i] = alpha*temp;
1238  } else {
1239  C[j*ldc + i] = alpha*temp + beta*C[j*ldc + i];
1240  }
1241  }
1242  }
1243  } else {
1244  // Compute C = alpha*A'*B + beta*C
1245  for (j=izero; j<n; j++) {
1246  for (i=izero; i<m; i++) {
1247  temp = C_zero;
1248  for (p=izero; p<k; p++) {
1249  temp += A[i*lda + p]*B[j*ldb + p];
1250  }
1251  if (beta == beta_zero) {
1252  C[j*ldc + i] = alpha*temp;
1253  } else {
1254  C[j*ldc + i] = alpha*temp + beta*C[j*ldc + i];
1255  }
1256  }
1257  }
1258  }
1259  } else if ( ETranspChar[transa]=='N' ) {
1260  if ( conjB ) {
1261  // Compute C = alpha*A*conj(B') + beta*C
1262  for (j=izero; j<n; j++) {
1263  if (beta == beta_zero) {
1264  for (i=izero; i<m; i++) {
1265  C[j*ldc + i] = C_zero;
1266  }
1267  } else if ( beta != beta_one ) {
1268  for (i=izero; i<m; i++) {
1269  C[j*ldc + i] *= beta;
1270  }
1271  }
1272  for (p=izero; p<k; p++) {
1273  if (B[p*ldb + j] != B_zero) {
1274  temp = alpha*ScalarTraits<B_type>::conjugate(B[p*ldb + j]);
1275  for (i=izero; i<m; i++) {
1276  C[j*ldc + i] += temp*A[p*lda + i];
1277  }
1278  }
1279  }
1280  }
1281  } else {
1282  // Compute C = alpha*A*B' + beta*C
1283  for (j=izero; j<n; j++) {
1284  if (beta == beta_zero) {
1285  for (i=izero; i<m; i++) {
1286  C[j*ldc + i] = C_zero;
1287  }
1288  } else if ( beta != beta_one ) {
1289  for (i=izero; i<m; i++) {
1290  C[j*ldc + i] *= beta;
1291  }
1292  }
1293  for (p=izero; p<k; p++) {
1294  if (B[p*ldb + j] != B_zero) {
1295  temp = alpha*B[p*ldb + j];
1296  for (i=izero; i<m; i++) {
1297  C[j*ldc + i] += temp*A[p*lda + i];
1298  }
1299  }
1300  }
1301  }
1302  }
1303  } else if ( conjA ) {
1304  if ( conjB ) {
1305  // Compute C = alpha*conj(A')*conj(B') + beta*C
1306  for (j=izero; j<n; j++) {
1307  for (i=izero; i<m; i++) {
1308  temp = C_zero;
1309  for (p=izero; p<k; p++) {
1310  temp += ScalarTraits<A_type>::conjugate(A[i*lda + p])
1311  * ScalarTraits<B_type>::conjugate(B[p*ldb + j]);
1312  }
1313  if (beta == beta_zero) {
1314  C[j*ldc + i] = alpha*temp;
1315  } else {
1316  C[j*ldc + i] = alpha*temp + beta*C[j*ldc + i];
1317  }
1318  }
1319  }
1320  } else {
1321  // Compute C = alpha*conj(A')*B' + beta*C
1322  for (j=izero; j<n; j++) {
1323  for (i=izero; i<m; i++) {
1324  temp = C_zero;
1325  for (p=izero; p<k; p++) {
1326  temp += ScalarTraits<A_type>::conjugate(A[i*lda + p])
1327  * B[p*ldb + j];
1328  }
1329  if (beta == beta_zero) {
1330  C[j*ldc + i] = alpha*temp;
1331  } else {
1332  C[j*ldc + i] = alpha*temp + beta*C[j*ldc + i];
1333  }
1334  }
1335  }
1336  }
1337  } else {
1338  if ( conjB ) {
1339  // Compute C = alpha*A'*conj(B') + beta*C
1340  for (j=izero; j<n; j++) {
1341  for (i=izero; i<m; i++) {
1342  temp = C_zero;
1343  for (p=izero; p<k; p++) {
1344  temp += A[i*lda + p]
1345  * ScalarTraits<B_type>::conjugate(B[p*ldb + j]);
1346  }
1347  if (beta == beta_zero) {
1348  C[j*ldc + i] = alpha*temp;
1349  } else {
1350  C[j*ldc + i] = alpha*temp + beta*C[j*ldc + i];
1351  }
1352  }
1353  }
1354  } else {
1355  // Compute C = alpha*A'*B' + beta*C
1356  for (j=izero; j<n; j++) {
1357  for (i=izero; i<m; i++) {
1358  temp = C_zero;
1359  for (p=izero; p<k; p++) {
1360  temp += A[i*lda + p]*B[p*ldb + j];
1361  }
1362  if (beta == beta_zero) {
1363  C[j*ldc + i] = alpha*temp;
1364  } else {
1365  C[j*ldc + i] = alpha*temp + beta*C[j*ldc + i];
1366  }
1367  }
1368  }
1369  } // end if (ETranspChar[transa]=='N') ...
1370  } // end if (ETranspChar[transb]=='N') ...
1371  } // end if (!BadArgument) ...
1372  } // end of GEMM
1373 
1374 
1375  template<typename OrdinalType, typename ScalarType>
1376  template <typename alpha_type, typename A_type, typename B_type, typename beta_type>
1377  void DefaultBLASImpl<OrdinalType, ScalarType>::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
1378  {
1379  OrdinalType izero = OrdinalTraits<OrdinalType>::zero();
1380  OrdinalType ione = OrdinalTraits<OrdinalType>::one();
1381  alpha_type alpha_zero = ScalarTraits<alpha_type>::zero();
1382  beta_type beta_zero = ScalarTraits<beta_type>::zero();
1383  ScalarType C_zero = ScalarTraits<ScalarType>::zero();
1384  beta_type beta_one = ScalarTraits<beta_type>::one();
1385  OrdinalType i, j, k, NRowA = m;
1386  ScalarType temp1, temp2;
1387  bool BadArgument = false;
1388  bool Upper = (EUploChar[uplo] == 'U');
1389  if (ESideChar[side] == 'R') { NRowA = n; }
1390 
1391  // Quick return.
1392  if ( (m==izero) || (n==izero) || ( (alpha==alpha_zero)&&(beta==beta_one) ) ) { return; }
1393  if( m < izero ) {
1394  std::cout << "BLAS::SYMM Error: M == "<< m << std::endl;
1395  BadArgument = true; }
1396  if( n < izero ) {
1397  std::cout << "BLAS::SYMM Error: N == "<< n << std::endl;
1398  BadArgument = true; }
1399  if( lda < NRowA ) {
1400  std::cout << "BLAS::SYMM Error: LDA < "<<NRowA<<std::endl;
1401  BadArgument = true; }
1402  if( ldb < m ) {
1403  std::cout << "BLAS::SYMM Error: LDB < MAX(1,M)"<<std::endl;
1404  BadArgument = true; }
1405  if( ldc < m ) {
1406  std::cout << "BLAS::SYMM Error: LDC < MAX(1,M)"<<std::endl;
1407  BadArgument = true; }
1408 
1409  if(!BadArgument) {
1410 
1411  // Only need to scale C and return.
1412  if (alpha == alpha_zero) {
1413  if (beta == beta_zero ) {
1414  for (j=izero; j<n; j++) {
1415  for (i=izero; i<m; i++) {
1416  C[j*ldc + i] = C_zero;
1417  }
1418  }
1419  } else {
1420  for (j=izero; j<n; j++) {
1421  for (i=izero; i<m; i++) {
1422  C[j*ldc + i] *= beta;
1423  }
1424  }
1425  }
1426  return;
1427  }
1428 
1429  if ( ESideChar[side] == 'L') {
1430  // Compute C = alpha*A*B + beta*C
1431 
1432  if (Upper) {
1433  // The symmetric part of A is stored in the upper triangular part of the matrix.
1434  for (j=izero; j<n; j++) {
1435  for (i=izero; i<m; i++) {
1436  temp1 = alpha*B[j*ldb + i];
1437  temp2 = C_zero;
1438  for (k=izero; k<i; k++) {
1439  C[j*ldc + k] += temp1*A[i*lda + k];
1440  temp2 += B[j*ldb + k]*A[i*lda + k];
1441  }
1442  if (beta == beta_zero) {
1443  C[j*ldc + i] = temp1*A[i*lda + i] + alpha*temp2;
1444  } else {
1445  C[j*ldc + i] = beta*C[j*ldc + i] + temp1*A[i*lda + i] + alpha*temp2;
1446  }
1447  }
1448  }
1449  } else {
1450  // The symmetric part of A is stored in the lower triangular part of the matrix.
1451  for (j=izero; j<n; j++) {
1452  for (i=m-ione; i>-ione; i--) {
1453  temp1 = alpha*B[j*ldb + i];
1454  temp2 = C_zero;
1455  for (k=i+ione; k<m; k++) {
1456  C[j*ldc + k] += temp1*A[i*lda + k];
1457  temp2 += B[j*ldb + k]*A[i*lda + k];
1458  }
1459  if (beta == beta_zero) {
1460  C[j*ldc + i] = temp1*A[i*lda + i] + alpha*temp2;
1461  } else {
1462  C[j*ldc + i] = beta*C[j*ldc + i] + temp1*A[i*lda + i] + alpha*temp2;
1463  }
1464  }
1465  }
1466  }
1467  } else {
1468  // Compute C = alpha*B*A + beta*C.
1469  for (j=izero; j<n; j++) {
1470  temp1 = alpha*A[j*lda + j];
1471  if (beta == beta_zero) {
1472  for (i=izero; i<m; i++) {
1473  C[j*ldc + i] = temp1*B[j*ldb + i];
1474  }
1475  } else {
1476  for (i=izero; i<m; i++) {
1477  C[j*ldc + i] = beta*C[j*ldc + i] + temp1*B[j*ldb + i];
1478  }
1479  }
1480  for (k=izero; k<j; k++) {
1481  if (Upper) {
1482  temp1 = alpha*A[j*lda + k];
1483  } else {
1484  temp1 = alpha*A[k*lda + j];
1485  }
1486  for (i=izero; i<m; i++) {
1487  C[j*ldc + i] += temp1*B[k*ldb + i];
1488  }
1489  }
1490  for (k=j+ione; k<n; k++) {
1491  if (Upper) {
1492  temp1 = alpha*A[k*lda + j];
1493  } else {
1494  temp1 = alpha*A[j*lda + k];
1495  }
1496  for (i=izero; i<m; i++) {
1497  C[j*ldc + i] += temp1*B[k*ldb + i];
1498  }
1499  }
1500  }
1501  } // end if (ESideChar[side]=='L') ...
1502  } // end if(!BadArgument) ...
1503 } // end SYMM
1504 
1505  template<typename OrdinalType, typename ScalarType>
1506  template <typename alpha_type, typename A_type, typename beta_type>
1507  void DefaultBLASImpl<OrdinalType, ScalarType>::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
1508  {
1509  typedef TypeNameTraits<OrdinalType> OTNT;
1510  typedef TypeNameTraits<ScalarType> STNT;
1511 
1512  OrdinalType izero = OrdinalTraits<OrdinalType>::zero();
1513  alpha_type alpha_zero = ScalarTraits<alpha_type>::zero();
1514  beta_type beta_zero = ScalarTraits<beta_type>::zero();
1515  beta_type beta_one = ScalarTraits<beta_type>::one();
1516  A_type temp, A_zero = ScalarTraits<A_type>::zero();
1517  ScalarType C_zero = ScalarTraits<ScalarType>::zero();
1518  OrdinalType i, j, l, NRowA = n;
1519  bool BadArgument = false;
1520  bool Upper = (EUploChar[uplo] == 'U');
1521 
1524  && (trans == CONJ_TRANS),
1525  std::logic_error,
1526  "Teuchos::BLAS<"<<OTNT::name()<<","<<STNT::name()<<">::SYRK()"
1527  " does not support CONJ_TRANS for complex data types."
1528  );
1529 
1530  // Change dimensions of A matrix is transposed
1531  if( !(ETranspChar[trans]=='N') ) {
1532  NRowA = k;
1533  }
1534 
1535  // Quick return.
1536  if ( n==izero ) { return; }
1537  if ( ( (alpha==alpha_zero) || (k==izero) ) && (beta==beta_one) ) { return; }
1538  if( n < izero ) {
1539  std::cout << "BLAS::SYRK Error: N == "<< n <<std::endl;
1540  BadArgument = true; }
1541  if( k < izero ) {
1542  std::cout << "BLAS::SYRK Error: K == "<< k <<std::endl;
1543  BadArgument = true; }
1544  if( lda < NRowA ) {
1545  std::cout << "BLAS::SYRK Error: LDA < "<<NRowA<<std::endl;
1546  BadArgument = true; }
1547  if( ldc < n ) {
1548  std::cout << "BLAS::SYRK Error: LDC < MAX(1,N)"<<std::endl;
1549  BadArgument = true; }
1550 
1551  if(!BadArgument) {
1552 
1553  // Scale C when alpha is zero
1554  if (alpha == alpha_zero) {
1555  if (Upper) {
1556  if (beta==beta_zero) {
1557  for (j=izero; j<n; j++) {
1558  for (i=izero; i<=j; i++) {
1559  C[j*ldc + i] = C_zero;
1560  }
1561  }
1562  }
1563  else {
1564  for (j=izero; j<n; j++) {
1565  for (i=izero; i<=j; i++) {
1566  C[j*ldc + i] *= beta;
1567  }
1568  }
1569  }
1570  }
1571  else {
1572  if (beta==beta_zero) {
1573  for (j=izero; j<n; j++) {
1574  for (i=j; i<n; i++) {
1575  C[j*ldc + i] = C_zero;
1576  }
1577  }
1578  }
1579  else {
1580  for (j=izero; j<n; j++) {
1581  for (i=j; i<n; i++) {
1582  C[j*ldc + i] *= beta;
1583  }
1584  }
1585  }
1586  }
1587  return;
1588  }
1589 
1590  // Now we can start the computation
1591 
1592  if ( ETranspChar[trans]=='N' ) {
1593 
1594  // Form C <- alpha*A*A' + beta*C
1595  if (Upper) {
1596  for (j=izero; j<n; j++) {
1597  if (beta==beta_zero) {
1598  for (i=izero; i<=j; i++) {
1599  C[j*ldc + i] = C_zero;
1600  }
1601  }
1602  else if (beta!=beta_one) {
1603  for (i=izero; i<=j; i++) {
1604  C[j*ldc + i] *= beta;
1605  }
1606  }
1607  for (l=izero; l<k; l++) {
1608  if (A[l*lda + j] != A_zero) {
1609  temp = alpha*A[l*lda + j];
1610  for (i = izero; i <=j; i++) {
1611  C[j*ldc + i] += temp*A[l*lda + i];
1612  }
1613  }
1614  }
1615  }
1616  }
1617  else {
1618  for (j=izero; j<n; j++) {
1619  if (beta==beta_zero) {
1620  for (i=j; i<n; i++) {
1621  C[j*ldc + i] = C_zero;
1622  }
1623  }
1624  else if (beta!=beta_one) {
1625  for (i=j; i<n; i++) {
1626  C[j*ldc + i] *= beta;
1627  }
1628  }
1629  for (l=izero; l<k; l++) {
1630  if (A[l*lda + j] != A_zero) {
1631  temp = alpha*A[l*lda + j];
1632  for (i=j; i<n; i++) {
1633  C[j*ldc + i] += temp*A[l*lda + i];
1634  }
1635  }
1636  }
1637  }
1638  }
1639  }
1640  else {
1641 
1642  // Form C <- alpha*A'*A + beta*C
1643  if (Upper) {
1644  for (j=izero; j<n; j++) {
1645  for (i=izero; i<=j; i++) {
1646  temp = A_zero;
1647  for (l=izero; l<k; l++) {
1648  temp += A[i*lda + l]*A[j*lda + l];
1649  }
1650  if (beta==beta_zero) {
1651  C[j*ldc + i] = alpha*temp;
1652  }
1653  else {
1654  C[j*ldc + i] = alpha*temp + beta*C[j*ldc + i];
1655  }
1656  }
1657  }
1658  }
1659  else {
1660  for (j=izero; j<n; j++) {
1661  for (i=j; i<n; i++) {
1662  temp = A_zero;
1663  for (l=izero; l<k; ++l) {
1664  temp += A[i*lda + l]*A[j*lda + l];
1665  }
1666  if (beta==beta_zero) {
1667  C[j*ldc + i] = alpha*temp;
1668  }
1669  else {
1670  C[j*ldc + i] = alpha*temp + beta*C[j*ldc + i];
1671  }
1672  }
1673  }
1674  }
1675  }
1676  } /* if (!BadArgument) */
1677  } /* END SYRK */
1678 
1679  template<typename OrdinalType, typename ScalarType>
1680  template <typename alpha_type, typename A_type>
1681  void DefaultBLASImpl<OrdinalType, ScalarType>::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
1682  {
1683  OrdinalType izero = OrdinalTraits<OrdinalType>::zero();
1684  OrdinalType ione = OrdinalTraits<OrdinalType>::one();
1685  alpha_type alpha_zero = ScalarTraits<alpha_type>::zero();
1686  A_type A_zero = ScalarTraits<A_type>::zero();
1687  ScalarType B_zero = ScalarTraits<ScalarType>::zero();
1688  ScalarType one = ScalarTraits<ScalarType>::one();
1689  OrdinalType i, j, k, NRowA = m;
1690  ScalarType temp;
1691  bool BadArgument = false;
1692  bool LSide = (ESideChar[side] == 'L');
1693  bool noUnit = (EDiagChar[diag] == 'N');
1694  bool Upper = (EUploChar[uplo] == 'U');
1695  bool noConj = (ETranspChar[transa] == 'T');
1696 
1697  if(!LSide) { NRowA = n; }
1698 
1699  // Quick return.
1700  if (n==izero || m==izero) { return; }
1701  if( m < izero ) {
1702  std::cout << "BLAS::TRMM Error: M == "<< m <<std::endl;
1703  BadArgument = true; }
1704  if( n < izero ) {
1705  std::cout << "BLAS::TRMM Error: N == "<< n <<std::endl;
1706  BadArgument = true; }
1707  if( lda < NRowA ) {
1708  std::cout << "BLAS::TRMM Error: LDA < "<<NRowA<<std::endl;
1709  BadArgument = true; }
1710  if( ldb < m ) {
1711  std::cout << "BLAS::TRMM Error: LDB < MAX(1,M)"<<std::endl;
1712  BadArgument = true; }
1713 
1714  if(!BadArgument) {
1715 
1716  // B only needs to be zeroed out.
1717  if( alpha == alpha_zero ) {
1718  for( j=izero; j<n; j++ ) {
1719  for( i=izero; i<m; i++ ) {
1720  B[j*ldb + i] = B_zero;
1721  }
1722  }
1723  return;
1724  }
1725 
1726  // Start the computations.
1727  if ( LSide ) {
1728  // A is on the left side of B.
1729 
1730  if ( ETranspChar[transa]=='N' ) {
1731  // Compute B = alpha*A*B
1732 
1733  if ( Upper ) {
1734  // A is upper triangular
1735  for( j=izero; j<n; j++ ) {
1736  for( k=izero; k<m; k++) {
1737  if ( B[j*ldb + k] != B_zero ) {
1738  temp = alpha*B[j*ldb + k];
1739  for( i=izero; i<k; i++ ) {
1740  B[j*ldb + i] += temp*A[k*lda + i];
1741  }
1742  if ( noUnit )
1743  temp *=A[k*lda + k];
1744  B[j*ldb + k] = temp;
1745  }
1746  }
1747  }
1748  } else {
1749  // A is lower triangular
1750  for( j=izero; j<n; j++ ) {
1751  for( k=m-ione; k>-ione; k-- ) {
1752  if( B[j*ldb + k] != B_zero ) {
1753  temp = alpha*B[j*ldb + k];
1754  B[j*ldb + k] = temp;
1755  if ( noUnit )
1756  B[j*ldb + k] *= A[k*lda + k];
1757  for( i=k+ione; i<m; i++ ) {
1758  B[j*ldb + i] += temp*A[k*lda + i];
1759  }
1760  }
1761  }
1762  }
1763  }
1764  } else {
1765  // Compute B = alpha*A'*B or B = alpha*conj(A')*B
1766  if( Upper ) {
1767  for( j=izero; j<n; j++ ) {
1768  for( i=m-ione; i>-ione; i-- ) {
1769  temp = B[j*ldb + i];
1770  if ( noConj ) {
1771  if( noUnit )
1772  temp *= A[i*lda + i];
1773  for( k=izero; k<i; k++ ) {
1774  temp += A[i*lda + k]*B[j*ldb + k];
1775  }
1776  } else {
1777  if( noUnit )
1778  temp *= ScalarTraits<A_type>::conjugate(A[i*lda + i]);
1779  for( k=izero; k<i; k++ ) {
1780  temp += ScalarTraits<A_type>::conjugate(A[i*lda + k])*B[j*ldb + k];
1781  }
1782  }
1783  B[j*ldb + i] = alpha*temp;
1784  }
1785  }
1786  } else {
1787  for( j=izero; j<n; j++ ) {
1788  for( i=izero; i<m; i++ ) {
1789  temp = B[j*ldb + i];
1790  if ( noConj ) {
1791  if( noUnit )
1792  temp *= A[i*lda + i];
1793  for( k=i+ione; k<m; k++ ) {
1794  temp += A[i*lda + k]*B[j*ldb + k];
1795  }
1796  } else {
1797  if( noUnit )
1798  temp *= ScalarTraits<A_type>::conjugate(A[i*lda + i]);
1799  for( k=i+ione; k<m; k++ ) {
1800  temp += ScalarTraits<A_type>::conjugate(A[i*lda + k])*B[j*ldb + k];
1801  }
1802  }
1803  B[j*ldb + i] = alpha*temp;
1804  }
1805  }
1806  }
1807  }
1808  } else {
1809  // A is on the right hand side of B.
1810 
1811  if( ETranspChar[transa] == 'N' ) {
1812  // Compute B = alpha*B*A
1813 
1814  if( Upper ) {
1815  // A is upper triangular.
1816  for( j=n-ione; j>-ione; j-- ) {
1817  temp = alpha;
1818  if( noUnit )
1819  temp *= A[j*lda + j];
1820  for( i=izero; i<m; i++ ) {
1821  B[j*ldb + i] *= temp;
1822  }
1823  for( k=izero; k<j; k++ ) {
1824  if( A[j*lda + k] != A_zero ) {
1825  temp = alpha*A[j*lda + k];
1826  for( i=izero; i<m; i++ ) {
1827  B[j*ldb + i] += temp*B[k*ldb + i];
1828  }
1829  }
1830  }
1831  }
1832  } else {
1833  // A is lower triangular.
1834  for( j=izero; j<n; j++ ) {
1835  temp = alpha;
1836  if( noUnit )
1837  temp *= A[j*lda + j];
1838  for( i=izero; i<m; i++ ) {
1839  B[j*ldb + i] *= temp;
1840  }
1841  for( k=j+ione; k<n; k++ ) {
1842  if( A[j*lda + k] != A_zero ) {
1843  temp = alpha*A[j*lda + k];
1844  for( i=izero; i<m; i++ ) {
1845  B[j*ldb + i] += temp*B[k*ldb + i];
1846  }
1847  }
1848  }
1849  }
1850  }
1851  } else {
1852  // Compute B = alpha*B*A' or B = alpha*B*conj(A')
1853 
1854  if( Upper ) {
1855  for( k=izero; k<n; k++ ) {
1856  for( j=izero; j<k; j++ ) {
1857  if( A[k*lda + j] != A_zero ) {
1858  if ( noConj )
1859  temp = alpha*A[k*lda + j];
1860  else
1861  temp = alpha*ScalarTraits<A_type>::conjugate(A[k*lda + j]);
1862  for( i=izero; i<m; i++ ) {
1863  B[j*ldb + i] += temp*B[k*ldb + i];
1864  }
1865  }
1866  }
1867  temp = alpha;
1868  if( noUnit ) {
1869  if ( noConj )
1870  temp *= A[k*lda + k];
1871  else
1872  temp *= ScalarTraits<A_type>::conjugate(A[k*lda + k]);
1873  }
1874  if( temp != one ) {
1875  for( i=izero; i<m; i++ ) {
1876  B[k*ldb + i] *= temp;
1877  }
1878  }
1879  }
1880  } else {
1881  for( k=n-ione; k>-ione; k-- ) {
1882  for( j=k+ione; j<n; j++ ) {
1883  if( A[k*lda + j] != A_zero ) {
1884  if ( noConj )
1885  temp = alpha*A[k*lda + j];
1886  else
1887  temp = alpha*ScalarTraits<A_type>::conjugate(A[k*lda + j]);
1888  for( i=izero; i<m; i++ ) {
1889  B[j*ldb + i] += temp*B[k*ldb + i];
1890  }
1891  }
1892  }
1893  temp = alpha;
1894  if( noUnit ) {
1895  if ( noConj )
1896  temp *= A[k*lda + k];
1897  else
1898  temp *= ScalarTraits<A_type>::conjugate(A[k*lda + k]);
1899  }
1900  if( temp != one ) {
1901  for( i=izero; i<m; i++ ) {
1902  B[k*ldb + i] *= temp;
1903  }
1904  }
1905  }
1906  }
1907  } // end if( ETranspChar[transa] == 'N' ) ...
1908  } // end if ( LSide ) ...
1909  } // end if (!BadArgument)
1910  } // end TRMM
1911 
1912  template<typename OrdinalType, typename ScalarType>
1913  template <typename alpha_type, typename A_type>
1914  void DefaultBLASImpl<OrdinalType, ScalarType>::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
1915  {
1916  OrdinalType izero = OrdinalTraits<OrdinalType>::zero();
1917  OrdinalType ione = OrdinalTraits<OrdinalType>::one();
1918  alpha_type alpha_zero = ScalarTraits<alpha_type>::zero();
1919  A_type A_zero = ScalarTraits<A_type>::zero();
1920  ScalarType B_zero = ScalarTraits<ScalarType>::zero();
1921  alpha_type alpha_one = ScalarTraits<alpha_type>::one();
1922  ScalarType B_one = ScalarTraits<ScalarType>::one();
1923  ScalarType temp;
1924  OrdinalType NRowA = m;
1925  bool BadArgument = false;
1926  bool noUnit = (EDiagChar[diag]=='N');
1927  bool noConj = (ETranspChar[transa] == 'T');
1928 
1929  if (!(ESideChar[side] == 'L')) { NRowA = n; }
1930 
1931  // Quick return.
1932  if (n == izero || m == izero) { return; }
1933  if( m < izero ) {
1934  std::cout << "BLAS::TRSM Error: M == "<<m<<std::endl;
1935  BadArgument = true; }
1936  if( n < izero ) {
1937  std::cout << "BLAS::TRSM Error: N == "<<n<<std::endl;
1938  BadArgument = true; }
1939  if( lda < NRowA ) {
1940  std::cout << "BLAS::TRSM Error: LDA < "<<NRowA<<std::endl;
1941  BadArgument = true; }
1942  if( ldb < m ) {
1943  std::cout << "BLAS::TRSM Error: LDB < MAX(1,M)"<<std::endl;
1944  BadArgument = true; }
1945 
1946  if(!BadArgument)
1947  {
1948  int i, j, k;
1949  // Set the solution to the zero vector.
1950  if(alpha == alpha_zero) {
1951  for(j = izero; j < n; j++) {
1952  for( i = izero; i < m; i++) {
1953  B[j*ldb+i] = B_zero;
1954  }
1955  }
1956  }
1957  else
1958  { // Start the operations.
1959  if(ESideChar[side] == 'L') {
1960  //
1961  // Perform computations for OP(A)*X = alpha*B
1962  //
1963  if(ETranspChar[transa] == 'N') {
1964  //
1965  // Compute B = alpha*inv( A )*B
1966  //
1967  if(EUploChar[uplo] == 'U') {
1968  // A is upper triangular.
1969  for(j = izero; j < n; j++) {
1970  // Perform alpha*B if alpha is not 1.
1971  if(alpha != alpha_one) {
1972  for( i = izero; i < m; i++) {
1973  B[j*ldb+i] *= alpha;
1974  }
1975  }
1976  // Perform a backsolve for column j of B.
1977  for(k = (m - ione); k > -ione; k--) {
1978  // If this entry is zero, we don't have to do anything.
1979  if (B[j*ldb + k] != B_zero) {
1980  if ( noUnit ) {
1981  B[j*ldb + k] /= A[k*lda + k];
1982  }
1983  for(i = izero; i < k; i++) {
1984  B[j*ldb + i] -= B[j*ldb + k] * A[k*lda + i];
1985  }
1986  }
1987  }
1988  }
1989  }
1990  else
1991  { // A is lower triangular.
1992  for(j = izero; j < n; j++) {
1993  // Perform alpha*B if alpha is not 1.
1994  if(alpha != alpha_one) {
1995  for( i = izero; i < m; i++) {
1996  B[j*ldb+i] *= alpha;
1997  }
1998  }
1999  // Perform a forward solve for column j of B.
2000  for(k = izero; k < m; k++) {
2001  // If this entry is zero, we don't have to do anything.
2002  if (B[j*ldb + k] != B_zero) {
2003  if ( noUnit ) {
2004  B[j*ldb + k] /= A[k*lda + k];
2005  }
2006  for(i = k+ione; i < m; i++) {
2007  B[j*ldb + i] -= B[j*ldb + k] * A[k*lda + i];
2008  }
2009  }
2010  }
2011  }
2012  } // end if (uplo == 'U')
2013  } // if (transa =='N')
2014  else {
2015  //
2016  // Compute B = alpha*inv( A' )*B
2017  // or B = alpha*inv( conj(A') )*B
2018  //
2019  if(EUploChar[uplo] == 'U') {
2020  // A is upper triangular.
2021  for(j = izero; j < n; j++) {
2022  for( i = izero; i < m; i++) {
2023  temp = alpha*B[j*ldb+i];
2024  if ( noConj ) {
2025  for(k = izero; k < i; k++) {
2026  temp -= A[i*lda + k] * B[j*ldb + k];
2027  }
2028  if ( noUnit ) {
2029  temp /= A[i*lda + i];
2030  }
2031  } else {
2032  for(k = izero; k < i; k++) {
2033  temp -= ScalarTraits<A_type>::conjugate(A[i*lda + k])
2034  * B[j*ldb + k];
2035  }
2036  if ( noUnit ) {
2037  temp /= ScalarTraits<A_type>::conjugate(A[i*lda + i]);
2038  }
2039  }
2040  B[j*ldb + i] = temp;
2041  }
2042  }
2043  }
2044  else
2045  { // A is lower triangular.
2046  for(j = izero; j < n; j++) {
2047  for(i = (m - ione) ; i > -ione; i--) {
2048  temp = alpha*B[j*ldb+i];
2049  if ( noConj ) {
2050  for(k = i+ione; k < m; k++) {
2051  temp -= A[i*lda + k] * B[j*ldb + k];
2052  }
2053  if ( noUnit ) {
2054  temp /= A[i*lda + i];
2055  }
2056  } else {
2057  for(k = i+ione; k < m; k++) {
2058  temp -= ScalarTraits<A_type>::conjugate(A[i*lda + k])
2059  * B[j*ldb + k];
2060  }
2061  if ( noUnit ) {
2062  temp /= ScalarTraits<A_type>::conjugate(A[i*lda + i]);
2063  }
2064  }
2065  B[j*ldb + i] = temp;
2066  }
2067  }
2068  }
2069  }
2070  } // if (side == 'L')
2071  else {
2072  // side == 'R'
2073  //
2074  // Perform computations for X*OP(A) = alpha*B
2075  //
2076  if (ETranspChar[transa] == 'N') {
2077  //
2078  // Compute B = alpha*B*inv( A )
2079  //
2080  if(EUploChar[uplo] == 'U') {
2081  // A is upper triangular.
2082  // Perform a backsolve for column j of B.
2083  for(j = izero; j < n; j++) {
2084  // Perform alpha*B if alpha is not 1.
2085  if(alpha != alpha_one) {
2086  for( i = izero; i < m; i++) {
2087  B[j*ldb+i] *= alpha;
2088  }
2089  }
2090  for(k = izero; k < j; k++) {
2091  // If this entry is zero, we don't have to do anything.
2092  if (A[j*lda + k] != A_zero) {
2093  for(i = izero; i < m; i++) {
2094  B[j*ldb + i] -= A[j*lda + k] * B[k*ldb + i];
2095  }
2096  }
2097  }
2098  if ( noUnit ) {
2099  temp = B_one/A[j*lda + j];
2100  for(i = izero; i < m; i++) {
2101  B[j*ldb + i] *= temp;
2102  }
2103  }
2104  }
2105  }
2106  else
2107  { // A is lower triangular.
2108  for(j = (n - ione); j > -ione; j--) {
2109  // Perform alpha*B if alpha is not 1.
2110  if(alpha != alpha_one) {
2111  for( i = izero; i < m; i++) {
2112  B[j*ldb+i] *= alpha;
2113  }
2114  }
2115  // Perform a forward solve for column j of B.
2116  for(k = j+ione; k < n; k++) {
2117  // If this entry is zero, we don't have to do anything.
2118  if (A[j*lda + k] != A_zero) {
2119  for(i = izero; i < m; i++) {
2120  B[j*ldb + i] -= A[j*lda + k] * B[k*ldb + i];
2121  }
2122  }
2123  }
2124  if ( noUnit ) {
2125  temp = B_one/A[j*lda + j];
2126  for(i = izero; i < m; i++) {
2127  B[j*ldb + i] *= temp;
2128  }
2129  }
2130  }
2131  } // end if (uplo == 'U')
2132  } // if (transa =='N')
2133  else {
2134  //
2135  // Compute B = alpha*B*inv( A' )
2136  // or B = alpha*B*inv( conj(A') )
2137  //
2138  if(EUploChar[uplo] == 'U') {
2139  // A is upper triangular.
2140  for(k = (n - ione); k > -ione; k--) {
2141  if ( noUnit ) {
2142  if ( noConj )
2143  temp = B_one/A[k*lda + k];
2144  else
2145  temp = B_one/ScalarTraits<A_type>::conjugate(A[k*lda + k]);
2146  for(i = izero; i < m; i++) {
2147  B[k*ldb + i] *= temp;
2148  }
2149  }
2150  for(j = izero; j < k; j++) {
2151  if (A[k*lda + j] != A_zero) {
2152  if ( noConj )
2153  temp = A[k*lda + j];
2154  else
2155  temp = ScalarTraits<A_type>::conjugate(A[k*lda + j]);
2156  for(i = izero; i < m; i++) {
2157  B[j*ldb + i] -= temp*B[k*ldb + i];
2158  }
2159  }
2160  }
2161  if (alpha != alpha_one) {
2162  for (i = izero; i < m; i++) {
2163  B[k*ldb + i] *= alpha;
2164  }
2165  }
2166  }
2167  }
2168  else
2169  { // A is lower triangular.
2170  for(k = izero; k < n; k++) {
2171  if ( noUnit ) {
2172  if ( noConj )
2173  temp = B_one/A[k*lda + k];
2174  else
2175  temp = B_one/ScalarTraits<A_type>::conjugate(A[k*lda + k]);
2176  for (i = izero; i < m; i++) {
2177  B[k*ldb + i] *= temp;
2178  }
2179  }
2180  for(j = k+ione; j < n; j++) {
2181  if(A[k*lda + j] != A_zero) {
2182  if ( noConj )
2183  temp = A[k*lda + j];
2184  else
2185  temp = ScalarTraits<A_type>::conjugate(A[k*lda + j]);
2186  for(i = izero; i < m; i++) {
2187  B[j*ldb + i] -= temp*B[k*ldb + i];
2188  }
2189  }
2190  }
2191  if (alpha != alpha_one) {
2192  for (i = izero; i < m; i++) {
2193  B[k*ldb + i] *= alpha;
2194  }
2195  }
2196  }
2197  }
2198  }
2199  }
2200  }
2201  }
2202  }
2203 
2204  // Explicit instantiation for template<int,float>
2205 
2206  template <>
2207  class TEUCHOSNUMERICS_LIB_DLL_EXPORT BLAS<int, float>
2208  {
2209  public:
2210  inline BLAS(void) {}
2211  inline BLAS(const BLAS<int, float>& /*BLAS_source*/) {}
2212  inline virtual ~BLAS(void) {}
2213  void ROTG(float* da, float* db, float* c, float* s) const;
2214  void ROT(const int n, float* dx, const int incx, float* dy, const int incy, float* c, float* s) const;
2215  float ASUM(const int n, const float* x, const int incx) const;
2216  void AXPY(const int n, const float alpha, const float* x, const int incx, float* y, const int incy) const;
2217  void COPY(const int n, const float* x, const int incx, float* y, const int incy) const;
2218  float DOT(const int n, const float* x, const int incx, const float* y, const int incy) const;
2219  float NRM2(const int n, const float* x, const int incx) const;
2220  void SCAL(const int n, const float alpha, float* x, const int incx) const;
2221  int IAMAX(const int n, const float* x, const int incx) const;
2222  void GEMV(ETransp trans, const int m, const int n, const float alpha, const float* A, const int lda, const float* x, const int incx, const float beta, float* y, const int incy) const;
2223  void TRMV(EUplo uplo, ETransp trans, EDiag diag, const int n, const float* A, const int lda, float* x, const int incx) const;
2224  void GER(const int m, const int n, const float alpha, const float* x, const int incx, const float* y, const int incy, float* A, const int lda) const;
2225  void GEMM(ETransp transa, ETransp transb, const int m, const int n, const int k, const float alpha, const float* A, const int lda, const float* B, const int ldb, const float beta, float* C, const int ldc) const;
2226  void SYMM(ESide side, EUplo uplo, const int m, const int n, const float alpha, const float* A, const int lda, const float *B, const int ldb, const float beta, float *C, const int ldc) const;
2227  void SYRK(EUplo uplo, ETransp trans, const int n, const int k, const float alpha, const float* A, const int lda, const float beta, float* C, const int ldc) const;
2228  void TRMM(ESide side, EUplo uplo, ETransp transa, EDiag diag, const int m, const int n, const float alpha, const float* A, const int lda, float* B, const int ldb) const;
2229  void TRSM(ESide side, EUplo uplo, ETransp transa, EDiag diag, const int m, const int n, const float alpha, const float* A, const int lda, float* B, const int ldb) const;
2230  };
2231 
2232  // Explicit instantiation for template<int,double>
2233 
2234  template<>
2235  class TEUCHOSNUMERICS_LIB_DLL_EXPORT BLAS<int, double>
2236  {
2237  public:
2238  inline BLAS(void) {}
2239  inline BLAS(const BLAS<int, double>& /*BLAS_source*/) {}
2240  inline virtual ~BLAS(void) {}
2241  void ROTG(double* da, double* db, double* c, double* s) const;
2242  void ROT(const int n, double* dx, const int incx, double* dy, const int incy, double* c, double* s) const;
2243  double ASUM(const int n, const double* x, const int incx) const;
2244  void AXPY(const int n, const double alpha, const double* x, const int incx, double* y, const int incy) const;
2245  void COPY(const int n, const double* x, const int incx, double* y, const int incy) const;
2246  double DOT(const int n, const double* x, const int incx, const double* y, const int incy) const;
2247  double NRM2(const int n, const double* x, const int incx) const;
2248  void SCAL(const int n, const double alpha, double* x, const int incx) const;
2249  int IAMAX(const int n, const double* x, const int incx) const;
2250  void GEMV(ETransp trans, const int m, const int n, const double alpha, const double* A, const int lda, const double* x, const int incx, const double beta, double* y, const int incy) const;
2251  void TRMV(EUplo uplo, ETransp trans, EDiag diag, const int n, const double* A, const int lda, double* x, const int incx) const;
2252  void GER(const int m, const int n, const double alpha, const double* x, const int incx, const double* y, const int incy, double* A, const int lda) const;
2253  void GEMM(ETransp transa, ETransp transb, const int m, const int n, const int k, const double alpha, const double* A, const int lda, const double* B, const int ldb, const double beta, double* C, const int ldc) const;
2254  void SYMM(ESide side, EUplo uplo, const int m, const int n, const double alpha, const double* A, const int lda, const double *B, const int ldb, const double beta, double *C, const int ldc) const;
2255  void SYRK(EUplo uplo, ETransp trans, const int n, const int k, const double alpha, const double* A, const int lda, const double beta, double* C, const int ldc) const;
2256  void TRMM(ESide side, EUplo uplo, ETransp transa, EDiag diag, const int m, const int n, const double alpha, const double* A, const int lda, double* B, const int ldb) const;
2257  void TRSM(ESide side, EUplo uplo, ETransp transa, EDiag diag, const int m, const int n, const double alpha, const double* A, const int lda, double* B, const int ldb) const;
2258  };
2259 
2260  // Explicit instantiation for template<int,complex<float> >
2261 
2262  template<>
2263  class TEUCHOSNUMERICS_LIB_DLL_EXPORT BLAS<int, std::complex<float> >
2264  {
2265  public:
2266  inline BLAS(void) {}
2267  inline BLAS(const BLAS<int, std::complex<float> >& /*BLAS_source*/) {}
2268  inline virtual ~BLAS(void) {}
2269  void ROTG(std::complex<float>* da, std::complex<float>* db, float* c, std::complex<float>* s) const;
2270  void ROT(const int n, std::complex<float>* dx, const int incx, std::complex<float>* dy, const int incy, float* c, std::complex<float>* s) const;
2271  float ASUM(const int n, const std::complex<float>* x, const int incx) const;
2272  void AXPY(const int n, const std::complex<float> alpha, const std::complex<float>* x, const int incx, std::complex<float>* y, const int incy) const;
2273  void COPY(const int n, const std::complex<float>* x, const int incx, std::complex<float>* y, const int incy) const;
2274  std::complex<float> DOT(const int n, const std::complex<float>* x, const int incx, const std::complex<float>* y, const int incy) const;
2275  float NRM2(const int n, const std::complex<float>* x, const int incx) const;
2276  void SCAL(const int n, const std::complex<float> alpha, std::complex<float>* x, const int incx) const;
2277  int IAMAX(const int n, const std::complex<float>* x, const int incx) const;
2278  void GEMV(ETransp trans, const int m, const int n, const std::complex<float> alpha, const std::complex<float>* A, const int lda, const std::complex<float>* x, const int incx, const std::complex<float> beta, std::complex<float>* y, const int incy) const;
2279  void TRMV(EUplo uplo, ETransp trans, EDiag diag, const int n, const std::complex<float>* A, const int lda, std::complex<float>* x, const int incx) const;
2280  void GER(const int m, const int n, const std::complex<float> alpha, const std::complex<float>* x, const int incx, const std::complex<float>* y, const int incy, std::complex<float>* A, const int lda) const;
2281  void GEMM(ETransp transa, ETransp transb, const int m, const int n, const int k, const std::complex<float> alpha, const std::complex<float>* A, const int lda, const std::complex<float>* B, const int ldb, const std::complex<float> beta, std::complex<float>* C, const int ldc) const;
2282  void SYMM(ESide side, EUplo uplo, const int m, const int n, const std::complex<float> alpha, const std::complex<float>* A, const int lda, const std::complex<float> *B, const int ldb, const std::complex<float> beta, std::complex<float> *C, const int ldc) const;
2283  void SYRK(EUplo uplo, ETransp trans, const int n, const int k, const std::complex<float> alpha, const std::complex<float>* A, const int lda, const std::complex<float> beta, std::complex<float>* C, const int ldc) const;
2284  void TRMM(ESide side, EUplo uplo, ETransp transa, EDiag diag, const int m, const int n, const std::complex<float> alpha, const std::complex<float>* A, const int lda, std::complex<float>* B, const int ldb) const;
2285  void TRSM(ESide side, EUplo uplo, ETransp transa, EDiag diag, const int m, const int n, const std::complex<float> alpha, const std::complex<float>* A, const int lda, std::complex<float>* B, const int ldb) const;
2286  };
2287 
2288  // Explicit instantiation for template<int,complex<double> >
2289 
2290  template<>
2291  class TEUCHOSNUMERICS_LIB_DLL_EXPORT BLAS<int, std::complex<double> >
2292  {
2293  public:
2294  inline BLAS(void) {}
2295  inline BLAS(const BLAS<int, std::complex<double> >& /*BLAS_source*/) {}
2296  inline virtual ~BLAS(void) {}
2297  void ROTG(std::complex<double>* da, std::complex<double>* db, double* c, std::complex<double>* s) const;
2298  void ROT(const int n, std::complex<double>* dx, const int incx, std::complex<double>* dy, const int incy, double* c, std::complex<double>* s) const;
2299  double ASUM(const int n, const std::complex<double>* x, const int incx) const;
2300  void AXPY(const int n, const std::complex<double> alpha, const std::complex<double>* x, const int incx, std::complex<double>* y, const int incy) const;
2301  void COPY(const int n, const std::complex<double>* x, const int incx, std::complex<double>* y, const int incy) const;
2302  std::complex<double> DOT(const int n, const std::complex<double>* x, const int incx, const std::complex<double>* y, const int incy) const;
2303  double NRM2(const int n, const std::complex<double>* x, const int incx) const;
2304  void SCAL(const int n, const std::complex<double> alpha, std::complex<double>* x, const int incx) const;
2305  int IAMAX(const int n, const std::complex<double>* x, const int incx) const;
2306  void GEMV(ETransp trans, const int m, const int n, const std::complex<double> alpha, const std::complex<double>* A, const int lda, const std::complex<double>* x, const int incx, const std::complex<double> beta, std::complex<double>* y, const int incy) const;
2307  void TRMV(EUplo uplo, ETransp trans, EDiag diag, const int n, const std::complex<double>* A, const int lda, std::complex<double>* x, const int incx) const;
2308  void GER(const int m, const int n, const std::complex<double> alpha, const std::complex<double>* x, const int incx, const std::complex<double>* y, const int incy, std::complex<double>* A, const int lda) const;
2309  void GEMM(ETransp transa, ETransp transb, const int m, const int n, const int k, const std::complex<double> alpha, const std::complex<double>* A, const int lda, const std::complex<double>* B, const int ldb, const std::complex<double> beta, std::complex<double>* C, const int ldc) const;
2310  void SYMM(ESide side, EUplo uplo, const int m, const int n, const std::complex<double> alpha, const std::complex<double>* A, const int lda, const std::complex<double> *B, const int ldb, const std::complex<double> beta, std::complex<double> *C, const int ldc) const;
2311  void SYRK(EUplo uplo, ETransp trans, const int n, const int k, const std::complex<double> alpha, const std::complex<double>* A, const int lda, const std::complex<double> beta, std::complex<double>* C, const int ldc) const;
2312  void TRMM(ESide side, EUplo uplo, ETransp transa, EDiag diag, const int m, const int n, const std::complex<double> alpha, const std::complex<double>* A, const int lda, std::complex<double>* B, const int ldb) const;
2313  void TRSM(ESide side, EUplo uplo, ETransp transa, EDiag diag, const int m, const int n, const std::complex<double> alpha, const std::complex<double>* A, const int lda, std::complex<double>* B, const int ldb) const;
2314  };
2315 
2316 } // namespace Teuchos
2317 
2318 #endif // _TEUCHOS_BLAS_HPP_
OrdinalType IAMAX(const OrdinalType n, const ScalarType *x, const OrdinalType incx) const
Return the index of the element of x with the maximum magnitude.
static T one()
Returns representation of one for this ordinal type.
BLAS(const BLAS< OrdinalType, ScalarType > &)
Copy constructor.
Enumerated types for BLAS input characters.
virtual ~DefaultBLASImpl(void)
Destructor.
T magnitudeType
Mandatory typedef for result of magnitude.
virtual ~BLAS(void)
Destructor.
static T zero()
Returns representation of zero for this ordinal type.
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 TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
BLAS(void)
Default constructor.
DefaultBLASImpl(void)
Default constructor.
Teuchos header file which uses auto-configuration information to include necessary C++ headers...
Templated BLAS wrapper.
This structure defines some basic traits for a scalar field type.
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.
DefaultBLASImpl(const DefaultBLASImpl< OrdinalType, ScalarType > &)
Copy constructor.
static T conjugate(T a)
Returns the conjugate of the scalar type a.
void ROTG(ScalarType *da, ScalarType *db, MagnitudeType *c, ScalarType *s) const
Computes a Givens plane rotation.
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...
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.
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.
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...
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.
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.
static magnitudeType magnitude(T a)
Returns the magnitudeType of the scalar type a.
Defines basic traits for the ordinal field type.
Default traits class that just returns typeid(T).name().
Default implementation for BLAS routines.
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.
Defines basic traits for the scalar field type.
ScalarTraits< ScalarType >::magnitudeType ASUM(const OrdinalType n, const ScalarType *x, const OrdinalType incx) const
Sum the absolute values of the entries of x.
static T zero()
Returns representation of zero for this scalar type.
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...
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.
static T one()
Returns representation of one for this scalar type.
ScalarTraits< ScalarType >::magnitudeType NRM2(const OrdinalType n, const ScalarType *x, const OrdinalType incx) const
Compute the 2-norm of the vector x.