1 /*
  2  *   Copyright (c) 2010, Michael Lehn
  3  *
  4  *   All rights reserved.
  5  *
  6  *   Redistribution and use in source and binary forms, with or without
  7  *   modification, are permitted provided that the following conditions
  8  *   are met:
  9  *
 10  *   1) Redistributions of source code must retain the above copyright
 11  *      notice, this list of conditions and the following disclaimer.
 12  *   2) Redistributions in binary form must reproduce the above copyright
 13  *      notice, this list of conditions and the following disclaimer in
 14  *      the documentation and/or other materials provided with the
 15  *      distribution.
 16  *   3) Neither the name of the FLENS development group nor the names of
 17  *      its contributors may be used to endorse or promote products derived
 18  *      from this software without specific prior written permission.
 19  *
 20  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 21  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 22  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 23  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 24  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 25  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 26  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 27  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 28  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 29  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 30  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 31  */
 32 
 33 #ifndef CXXBLAS_DRIVERS_DRIVERS_H
 34 #define CXXBLAS_DRIVERS_DRIVERS_H 1
 35 
 36 // define implementation specific constants, macros, etc.
 37 #if defined (WITH_ATLAS)
 38 #   include <cxxblas/drivers/atlas.h>
 39 #elif defined (WITH_GOTOBLAS)
 40 #   include <cxxblas/drivers/gotoblas.h>
 41 #elif defined (WITH_VECLIB)
 42 #   include <cxxblas/drivers/veclib.h>
 43 #elif defined (WITH_REFBLAS)
 44 #   include <cxxblas/drivers/refblas.h>
 45 #endif
 46 
 47 
 48 #ifdef HAVE_CBLAS
 49 #include <cxxblas/drivers/cblas.h>
 50 #endif
 51 
 52 #include <cxxblas/typedefs.h>
 53 
 54 namespace cxxblas {
 55 
 56 template <typename CHAR>
 57 const CHAR *
 58 blasImpl();
 59 
 60 //------------------------------------------------------------------------------
 61 
 62 template <typename Any>
 63 struct If
 64 {
 65 };
 66 
 67 template <>
 68 struct If<int>
 69 {
 70     typedef void isBlasCompatibleInteger;
 71 };
 72 
 73 template <>
 74 struct If<long>
 75 {
 76     typedef void isBlasCompatibleInteger;
 77 };
 78 
 79 //------------------------------------------------------------------------------
 80 
 81 template <typename A, typename B>
 82 struct IsSame
 83 {
 84     static const bool value = false;
 85 };
 86 
 87 template <typename A>
 88 struct IsSame<A,A>
 89 {
 90     static const bool value = true;
 91 };
 92 
 93 //------------------------------------------------------------------------------
 94 
 95 template <bool b, typename T>
 96 struct RestrictTo
 97 {
 98 };
 99 
100 template <typename T>
101 struct RestrictTo<true, T> 
102 {
103     typedef T Type;
104 };
105 
106 //------------------------------------------------------------------------------
107 template <typename ENUM>
108     typename RestrictTo<IsSame<ENUM,Transpose>::value, char>::Type
109     getF77BlasChar(ENUM trans);
110 
111 template <typename ENUM>
112     typename RestrictTo<IsSame<ENUM,Diag>::value, char>::Type
113     getF77BlasChar(ENUM diag);
114 
115 template <typename ENUM>
116     typename RestrictTo<IsSame<ENUM,StorageUpLo>::value, char>::Type
117     getF77BlasChar(ENUM upLo);
118 
119 //------------------------------------------------------------------------------
120 template <typename ENUM>
121     typename RestrictTo<IsSame<ENUM,Transpose>::value, Transpose>::Type
122     getCxxBlasEnum(char trans);
123 
124 template <typename ENUM>
125     typename RestrictTo<IsSame<ENUM,Diag>::value, Diag>::Type
126     getCxxBlasEnum(char diag);
127 
128 template <typename ENUM>
129     typename RestrictTo<IsSame<ENUM,StorageUpLo>::value, StorageUpLo>::Type
130     getCxxBlasEnum(char upLo);
131 
132 //------------------------------------------------------------------------------
133 #ifdef HAVE_CBLAS
134 
135 namespace CBLAS {
136 
137 //TODO: rename these to getCblasEnum
138 
139 template <typename ENUM>
140     typename RestrictTo<IsSame<ENUM,StorageOrder>::value, CBLAS_ORDER>::Type
141     getCblasType(ENUM order);
142 
143 template <typename ENUM>
144     typename RestrictTo<IsSame<ENUM,Transpose>::value, CBLAS_TRANSPOSE>::Type
145     getCblasType(ENUM trans);
146 
147 template <typename ENUM>
148     typename RestrictTo<IsSame<ENUM,StorageUpLo>::value, CBLAS_UPLO>::Type
149     getCblasType(ENUM upLo);
150 
151 template <typename ENUM>
152     typename RestrictTo<IsSame<ENUM,Side>::value, CBLAS_SIDE>::Type
153     getCblasType(ENUM side);
154 
155 template <typename ENUM>
156     typename RestrictTo<IsSame<ENUM,Diag>::value, CBLAS_DIAG>::Type
157     getCblasType(ENUM diag);
158 
159 // namespace CBLAS
160 
161 #endif // HAVE_CBLAS
162 
163 // namespace cxxblas
164 
165 
166 #endif // CXXBLAS_DRIVERS_DRIVERS_H