54 #ifndef AMESOS2_SUPERLU_TYPEMAP_HPP
55 #define AMESOS2_SUPERLU_TYPEMAP_HPP
58 #ifdef HAVE_TEUCHOS_COMPLEX
62 #include <Teuchos_as.hpp>
63 #ifdef HAVE_TEUCHOS_COMPLEX
64 #include <Teuchos_SerializationTraits.hpp>
67 #include "Amesos2_TypeMap.hpp"
80 #undef __SUPERLU_SUPERMATRIX
81 #include "supermatrix.h"
83 #ifdef HAVE_TEUCHOS_COMPLEX
85 #undef __SUPERLU_SCOMPLEX
86 #undef SCOMPLEX_INCLUDE
87 #include "slu_scomplex.h"
91 #undef __SUPERLU_DCOMPLEX
92 #undef DCOMPLEX_INCLUDE
93 #include "slu_dcomplex.h"
95 #endif // HAVE_TEUCHOS_COMPLEX
101 template <
typename slu_scalar_t,
typename slu_mag_t>
106 template <
typename T>
107 struct slu_mult<T,T> : std::multiplies<T> {};
109 #ifdef HAVE_TEUCHOS_COMPLEX
113 struct slu_mult<C::complex,float>
114 : std::binary_function<C::complex,float,C::complex> {
115 C::complex operator()(C::complex amesos_c,
float amesos_f) {
116 C::complex amesos_cr;
117 cs_mult(&amesos_cr, &amesos_c, amesos_f);
123 struct slu_mult<C::complex,C::complex>
124 : std::binary_function<C::complex,C::complex,C::complex> {
125 C::complex operator()(C::complex amesos_c1, C::complex amesos_c2) {
126 C::complex amesos_cr;
127 cc_mult(&amesos_cr, &amesos_c1, &amesos_c2);
133 struct slu_mult<Z::doublecomplex,double>
134 : std::binary_function<Z::doublecomplex,double,Z::doublecomplex> {
135 Z::doublecomplex operator()(Z::doublecomplex amesos_z,
double amesos_d) {
136 Z::doublecomplex amesos_zr;
137 zd_mult(&amesos_zr, &amesos_z, amesos_d);
143 struct slu_mult<Z::doublecomplex,Z::doublecomplex>
144 : std::binary_function<Z::doublecomplex,Z::doublecomplex,Z::doublecomplex> {
145 Z::doublecomplex operator()(Z::doublecomplex amesos_z1, Z::doublecomplex amesos_z2) {
146 Z::doublecomplex amesos_zr;
147 zz_mult(&amesos_zr, &amesos_z1, &amesos_z2);
152 #endif // HAVE_TEUCHOS_COMPLEX
154 #ifdef HAVE_TEUCHOS_COMPLEX
169 template <
typename TypeFrom>
170 class ValueTypeConversionTraits<SLU::C::complex, TypeFrom>
173 static SLU::C::complex convert(
const TypeFrom t )
176 ret.r = Teuchos::as<float>(t.real());
177 ret.i = Teuchos::as<float>(t.imag());
181 static SLU::C::complex safeConvert(
const TypeFrom t )
184 ret.r = Teuchos::as<float>(t.real());
185 ret.i = Teuchos::as<float>(t.imag());
191 template <
typename TypeFrom>
192 class ValueTypeConversionTraits<SLU::Z::doublecomplex, TypeFrom>
195 static SLU::Z::doublecomplex convert(
const TypeFrom t )
197 SLU::Z::doublecomplex ret;
198 ret.r = Teuchos::as<double>(t.real());
199 ret.i = Teuchos::as<double>(t.imag());
203 static SLU::Z::doublecomplex safeConvert(
const TypeFrom t )
205 SLU::Z::doublecomplex ret;
206 ret.r = Teuchos::as<double>(t.real());
207 ret.i = Teuchos::as<double>(t.imag());
214 template <
typename TypeTo>
215 class ValueTypeConversionTraits<TypeTo, SLU::C::complex>
218 static TypeTo convert(
const SLU::C::complex t )
220 typedef typename TypeTo::value_type value_type;
221 value_type ret_r = Teuchos::as<value_type>( t.r );
222 value_type ret_i = Teuchos::as<value_type>( t.i );
223 return ( TypeTo( ret_r, ret_i ) );
227 static TypeTo safeConvert(
const SLU::C::complex t )
229 typedef typename TypeTo::value_type value_type;
230 value_type ret_r = Teuchos::as<value_type>( t.r );
231 value_type ret_i = Teuchos::as<value_type>( t.i );
232 return ( TypeTo( ret_r, ret_i ) );
237 template <
typename TypeTo>
238 class ValueTypeConversionTraits<TypeTo, SLU::Z::doublecomplex>
241 static TypeTo convert(
const SLU::Z::doublecomplex t )
243 typedef typename TypeTo::value_type value_type;
244 value_type ret_r = Teuchos::as<value_type>( t.r );
245 value_type ret_i = Teuchos::as<value_type>( t.i );
246 return ( TypeTo( ret_r, ret_i ) );
250 static TypeTo safeConvert(
const SLU::Z::doublecomplex t )
252 typedef typename TypeTo::value_type value_type;
253 value_type ret_r = Teuchos::as<value_type>( t.r );
254 value_type ret_i = Teuchos::as<value_type>( t.i );
255 return ( TypeTo( ret_r, ret_i ) );
259 template <
typename Ordinal>
260 class SerializationTraits<Ordinal,SLU::C::complex>
261 :
public DirectSerializationTraits<Ordinal,SLU::C::complex>
264 template <
typename Ordinal>
265 class SerializationTraits<Ordinal,SLU::Z::doublecomplex>
266 :
public DirectSerializationTraits<Ordinal,SLU::Z::doublecomplex>
275 ostream& operator<<(ostream& out,
const SLU::Z::doublecomplex z);
277 ostream& operator<<(ostream& out,
const SLU::C::complex c);
280 #endif // HAVE_TEUCHOS_COMPLEX
285 template <
class,
class>
class Superlu;
292 struct TypeMap<Superlu,float>
294 static SLU::Dtype_t dtype;
296 typedef float magnitude_type;
301 struct TypeMap<Superlu,double>
303 static SLU::Dtype_t dtype;
305 typedef double magnitude_type;
309 #ifdef HAVE_TEUCHOS_COMPLEX
312 struct TypeMap<Superlu,std::complex<float> >
314 static SLU::Dtype_t dtype;
315 typedef SLU::C::complex type;
316 typedef float magnitude_type;
321 struct TypeMap<Superlu,std::complex<double> >
323 static SLU::Dtype_t dtype;
324 typedef SLU::Z::doublecomplex type;
325 typedef double magnitude_type;
330 struct TypeMap<Superlu,SLU::C::complex>
332 static SLU::Dtype_t dtype;
333 typedef SLU::C::complex type;
334 typedef float magnitude_type;
339 struct TypeMap<Superlu,SLU::Z::doublecomplex>
341 static SLU::Dtype_t dtype;
342 typedef SLU::Z::doublecomplex type;
343 typedef double magnitude_type;
347 #endif // HAVE_TEUCHOS_COMPLEX
354 #endif // AMESOS2_SUPERLU_TYPEMAP_HPP