Skip to content

Instantly share code, notes, and snippets.

@yt-siden
Created July 22, 2015 12:22
Show Gist options
  • Save yt-siden/81943eda303f309ea467 to your computer and use it in GitHub Desktop.
Save yt-siden/81943eda303f309ea467 to your computer and use it in GitHub Desktop.
MAGMA type wrapper for converting complex type (std::complex -> magmaComplex)
#ifndef UUID_6DBD3348_8ECE_4541_A1E1_3D5EBF9C3BD8
#define UUID_6DBD3348_8ECE_4541_A1E1_3D5EBF9C3BD8
#include <complex>
#include <magma.h>
// MAGMA type wrapper for using std::complex
/*
* T -> magma_type_wrapper<T>::type
* ---------------------------------------------------
* std::complex<float> -> magmaFloatComplex
* std::complex<double> -> magmaDoubleComplex
* T (not listed above) -> T
*/
template <typename T>
struct magma_type_wrapper
{
typedef T type;
};
template<>
struct magma_type_wrapper<std::complex<float>>
{
typedef magmaFloatComplex type;
};
template<>
struct magma_type_wrapper<std::complex<double>>
{
typedef magmaDoubleComplex type;
};
// example use -- magma_setvector
template <typename T>
void setvector(int const n, T const * const hx_src, int const incx, T * const dy_dst, int const incy)
{
return magma_setvector(const_cast<int&>(n), sizeof(T),
reinterpret_cast<magma_type_wrapper<T>::type *>(const_cast<T const *>(hx_src)),
const_cast<int&>(incx),
reinterpret_cast<magma_type_wrapper<T>::type *>(const_cast<T *>(dy_dst)),
const_cast<int&>(incy));
}
#endif //UUID_6DBD3348_8ECE_4541_A1E1_3D5EBF9C3BD8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment