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_TCC
34 #define CXXBLAS_DRIVERS_DRIVERS_TCC 1
35
36 #ifndef BLAS_IMPL
37 # define BLAS_IMPL "CXXBLAS (generic)"
38 #endif
39
40 namespace cxxblas {
41
42 template <typename CHAR>
43 const CHAR *
44 blasImpl()
45 {
46 return BLAS_IMPL;
47 }
48
49 //------------------------------------------------------------------------------
50 template <typename ENUM>
51 typename RestrictTo<IsSame<ENUM,Transpose>::value, char>::Type
52 getF77BlasChar(ENUM trans)
53 {
54 if (trans==NoTrans) {
55 return 'N';
56 } else if (trans==Trans) {
57 return 'T';
58 } else if (trans==Conj) {
59 return 'R';
60 } else if (trans==ConjTrans) {
61 return 'C';
62 } else {
63 ASSERT(0);
64 return '?';
65 }
66 }
67
68 template <typename ENUM>
69 typename RestrictTo<IsSame<ENUM,Diag>::value, char>::Type
70 getF77BlasChar(ENUM diag)
71 {
72 if (diag==Unit) {
73 return 'U';
74 }
75 return 'N';
76 }
77
78 template <typename ENUM>
79 typename RestrictTo<IsSame<ENUM,StorageUpLo>::value, char>::Type
80 getF77BlasChar(ENUM upLo)
81 {
82 if (upLo==Upper) {
83 return 'U';
84 }
85 return 'L';
86 }
87
88 //------------------------------------------------------------------------------
89 template <typename ENUM>
90 typename RestrictTo<IsSame<ENUM,Transpose>::value, Transpose>::Type
91 getCxxBlasEnum(char trans)
92 {
93 if ((trans=='N') || (trans=='n')) {
94 return NoTrans;
95 } else if ((trans=='T') || (trans=='t')) {
96 return Trans;
97 } else if ((trans=='C') || (trans=='c')) {
98 return ConjTrans;
99 } else if ((trans=='R') || (trans=='r')) {
100 return Conj;
101 }
102 return NoTrans;
103 }
104
105 template <typename ENUM>
106 typename RestrictTo<IsSame<ENUM,Diag>::value, Diag>::Type
107 getCxxBlasEnum(char diag)
108 {
109 if (diag=='U') {
110 return Unit;
111 }
112 return NonUnit;
113 }
114
115 template <typename ENUM>
116 typename RestrictTo<IsSame<ENUM,StorageUpLo>::value, StorageUpLo>::Type
117 getCxxBlasEnum(char upLo)
118 {
119 if (upLo=='U') {
120 return Upper;
121 }
122 return Lower;
123 }
124
125 //------------------------------------------------------------------------------
126 #ifdef HAVE_CBLAS
127
128 namespace CBLAS {
129
130 template <typename ENUM>
131 typename RestrictTo<IsSame<ENUM,StorageOrder>::value, CBLAS_ORDER>::Type
132 getCblasType(ENUM order)
133 {
134 if (order==RowMajor) {
135 return CblasRowMajor;
136 }
137 return CblasColMajor;
138 }
139
140 template <typename ENUM>
141 typename RestrictTo<IsSame<ENUM,Transpose>::value, CBLAS_TRANSPOSE>::Type
142 getCblasType(ENUM trans)
143 {
144 if (trans==NoTrans) {
145 return CblasNoTrans;
146 }
147 if (trans==Conj) {
148 return CblasConjNoTrans;
149 }
150 if (trans==Trans) {
151 return CblasTrans;
152 }
153 return CblasConjTrans;
154 }
155
156 template <typename ENUM>
157 typename RestrictTo<IsSame<ENUM,StorageUpLo>::value, CBLAS_UPLO>::Type
158 getCblasType(ENUM upLo)
159 {
160 if (upLo==Upper) {
161 return CblasUpper;
162 }
163 return CblasLower;
164 }
165
166 template <typename ENUM>
167 typename RestrictTo<IsSame<ENUM,Side>::value, CBLAS_SIDE>::Type
168 getCblasType(ENUM side)
169 {
170 if (side==Left) {
171 return CblasLeft;
172 }
173 return CblasRight;
174 }
175
176 template <typename ENUM>
177 typename RestrictTo<IsSame<ENUM,Diag>::value, CBLAS_DIAG>::Type
178 getCblasType(ENUM diag)
179 {
180 if (diag==Unit) {
181 return CblasUnit;
182 }
183 return CblasNonUnit;
184 }
185
186 } // namespace CBLAS
187
188 #endif // HAVE_CBLAS
189
190 } // namespace cxxblas
191
192 #endif // CXXBLAS_DRIVERS_DRIVERS_TCC
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_TCC
34 #define CXXBLAS_DRIVERS_DRIVERS_TCC 1
35
36 #ifndef BLAS_IMPL
37 # define BLAS_IMPL "CXXBLAS (generic)"
38 #endif
39
40 namespace cxxblas {
41
42 template <typename CHAR>
43 const CHAR *
44 blasImpl()
45 {
46 return BLAS_IMPL;
47 }
48
49 //------------------------------------------------------------------------------
50 template <typename ENUM>
51 typename RestrictTo<IsSame<ENUM,Transpose>::value, char>::Type
52 getF77BlasChar(ENUM trans)
53 {
54 if (trans==NoTrans) {
55 return 'N';
56 } else if (trans==Trans) {
57 return 'T';
58 } else if (trans==Conj) {
59 return 'R';
60 } else if (trans==ConjTrans) {
61 return 'C';
62 } else {
63 ASSERT(0);
64 return '?';
65 }
66 }
67
68 template <typename ENUM>
69 typename RestrictTo<IsSame<ENUM,Diag>::value, char>::Type
70 getF77BlasChar(ENUM diag)
71 {
72 if (diag==Unit) {
73 return 'U';
74 }
75 return 'N';
76 }
77
78 template <typename ENUM>
79 typename RestrictTo<IsSame<ENUM,StorageUpLo>::value, char>::Type
80 getF77BlasChar(ENUM upLo)
81 {
82 if (upLo==Upper) {
83 return 'U';
84 }
85 return 'L';
86 }
87
88 //------------------------------------------------------------------------------
89 template <typename ENUM>
90 typename RestrictTo<IsSame<ENUM,Transpose>::value, Transpose>::Type
91 getCxxBlasEnum(char trans)
92 {
93 if ((trans=='N') || (trans=='n')) {
94 return NoTrans;
95 } else if ((trans=='T') || (trans=='t')) {
96 return Trans;
97 } else if ((trans=='C') || (trans=='c')) {
98 return ConjTrans;
99 } else if ((trans=='R') || (trans=='r')) {
100 return Conj;
101 }
102 return NoTrans;
103 }
104
105 template <typename ENUM>
106 typename RestrictTo<IsSame<ENUM,Diag>::value, Diag>::Type
107 getCxxBlasEnum(char diag)
108 {
109 if (diag=='U') {
110 return Unit;
111 }
112 return NonUnit;
113 }
114
115 template <typename ENUM>
116 typename RestrictTo<IsSame<ENUM,StorageUpLo>::value, StorageUpLo>::Type
117 getCxxBlasEnum(char upLo)
118 {
119 if (upLo=='U') {
120 return Upper;
121 }
122 return Lower;
123 }
124
125 //------------------------------------------------------------------------------
126 #ifdef HAVE_CBLAS
127
128 namespace CBLAS {
129
130 template <typename ENUM>
131 typename RestrictTo<IsSame<ENUM,StorageOrder>::value, CBLAS_ORDER>::Type
132 getCblasType(ENUM order)
133 {
134 if (order==RowMajor) {
135 return CblasRowMajor;
136 }
137 return CblasColMajor;
138 }
139
140 template <typename ENUM>
141 typename RestrictTo<IsSame<ENUM,Transpose>::value, CBLAS_TRANSPOSE>::Type
142 getCblasType(ENUM trans)
143 {
144 if (trans==NoTrans) {
145 return CblasNoTrans;
146 }
147 if (trans==Conj) {
148 return CblasConjNoTrans;
149 }
150 if (trans==Trans) {
151 return CblasTrans;
152 }
153 return CblasConjTrans;
154 }
155
156 template <typename ENUM>
157 typename RestrictTo<IsSame<ENUM,StorageUpLo>::value, CBLAS_UPLO>::Type
158 getCblasType(ENUM upLo)
159 {
160 if (upLo==Upper) {
161 return CblasUpper;
162 }
163 return CblasLower;
164 }
165
166 template <typename ENUM>
167 typename RestrictTo<IsSame<ENUM,Side>::value, CBLAS_SIDE>::Type
168 getCblasType(ENUM side)
169 {
170 if (side==Left) {
171 return CblasLeft;
172 }
173 return CblasRight;
174 }
175
176 template <typename ENUM>
177 typename RestrictTo<IsSame<ENUM,Diag>::value, CBLAS_DIAG>::Type
178 getCblasType(ENUM diag)
179 {
180 if (diag==Unit) {
181 return CblasUnit;
182 }
183 return CblasNonUnit;
184 }
185
186 } // namespace CBLAS
187
188 #endif // HAVE_CBLAS
189
190 } // namespace cxxblas
191
192 #endif // CXXBLAS_DRIVERS_DRIVERS_TCC