mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Apply clang-format
This commit is contained in:
@@ -31,7 +31,7 @@
|
||||
// to the first inclusion of <complex>.
|
||||
|
||||
#if defined(EIGEN_GPUCC) && defined(EIGEN_GPU_COMPILE_PHASE)
|
||||
|
||||
|
||||
// ICC already specializes std::complex<float> and std::complex<double>
|
||||
// operators, preventing us from making them device functions here.
|
||||
// This will lead to silent runtime errors if the operators are used on device.
|
||||
@@ -62,33 +62,30 @@ namespace Eigen {
|
||||
// Specialized std::complex overloads.
|
||||
namespace complex_operator_detail {
|
||||
|
||||
template<typename T>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
||||
std::complex<T> complex_multiply(const std::complex<T>& a, const std::complex<T>& b) {
|
||||
template <typename T>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::complex<T> complex_multiply(const std::complex<T>& a,
|
||||
const std::complex<T>& b) {
|
||||
const T a_real = numext::real(a);
|
||||
const T a_imag = numext::imag(a);
|
||||
const T b_real = numext::real(b);
|
||||
const T b_imag = numext::imag(b);
|
||||
return std::complex<T>(
|
||||
a_real * b_real - a_imag * b_imag,
|
||||
a_imag * b_real + a_real * b_imag);
|
||||
return std::complex<T>(a_real * b_real - a_imag * b_imag, a_imag * b_real + a_real * b_imag);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
||||
std::complex<T> complex_divide_fast(const std::complex<T>& a, const std::complex<T>& b) {
|
||||
template <typename T>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::complex<T> complex_divide_fast(const std::complex<T>& a,
|
||||
const std::complex<T>& b) {
|
||||
const T a_real = numext::real(a);
|
||||
const T a_imag = numext::imag(a);
|
||||
const T b_real = numext::real(b);
|
||||
const T b_imag = numext::imag(b);
|
||||
const T norm = (b_real * b_real + b_imag * b_imag);
|
||||
return std::complex<T>((a_real * b_real + a_imag * b_imag) / norm,
|
||||
(a_imag * b_real - a_real * b_imag) / norm);
|
||||
return std::complex<T>((a_real * b_real + a_imag * b_imag) / norm, (a_imag * b_real - a_real * b_imag) / norm);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
||||
std::complex<T> complex_divide_stable(const std::complex<T>& a, const std::complex<T>& b) {
|
||||
template <typename T>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::complex<T> complex_divide_stable(const std::complex<T>& a,
|
||||
const std::complex<T>& b) {
|
||||
const T a_real = numext::real(a);
|
||||
const T a_imag = numext::imag(a);
|
||||
const T b_real = numext::real(b);
|
||||
@@ -99,13 +96,13 @@ std::complex<T> complex_divide_stable(const std::complex<T>& a, const std::compl
|
||||
const T rscale = scale_imag ? T(1) : b_real / b_imag;
|
||||
const T iscale = scale_imag ? b_imag / b_real : T(1);
|
||||
const T denominator = b_real * rscale + b_imag * iscale;
|
||||
return std::complex<T>((a_real * rscale + a_imag * iscale) / denominator,
|
||||
return std::complex<T>((a_real * rscale + a_imag * iscale) / denominator,
|
||||
(a_imag * rscale - a_real * iscale) / denominator);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
||||
std::complex<T> complex_divide(const std::complex<T>& a, const std::complex<T>& b) {
|
||||
template <typename T>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::complex<T> complex_divide(const std::complex<T>& a,
|
||||
const std::complex<T>& b) {
|
||||
#if EIGEN_FAST_MATH
|
||||
return complex_divide_fast(a, b);
|
||||
#else
|
||||
@@ -118,131 +115,107 @@ std::complex<T> complex_divide(const std::complex<T>& a, const std::complex<T>&
|
||||
// since they are already specialized for float/double/long double within
|
||||
// the standard <complex> header. We also do not specialize the stream
|
||||
// operators.
|
||||
#define EIGEN_CREATE_STD_COMPLEX_OPERATOR_SPECIALIZATIONS(T) \
|
||||
\
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
|
||||
std::complex<T> operator+(const std::complex<T>& a) { return a; } \
|
||||
\
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
|
||||
std::complex<T> operator-(const std::complex<T>& a) { \
|
||||
return std::complex<T>(-numext::real(a), -numext::imag(a)); \
|
||||
} \
|
||||
\
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
|
||||
std::complex<T> operator+(const std::complex<T>& a, const std::complex<T>& b) { \
|
||||
return std::complex<T>(numext::real(a) + numext::real(b), numext::imag(a) + numext::imag(b)); \
|
||||
} \
|
||||
\
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
|
||||
std::complex<T> operator+(const std::complex<T>& a, const T& b) { \
|
||||
return std::complex<T>(numext::real(a) + b, numext::imag(a)); \
|
||||
} \
|
||||
\
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
|
||||
std::complex<T> operator+(const T& a, const std::complex<T>& b) { \
|
||||
return std::complex<T>(a + numext::real(b), numext::imag(b)); \
|
||||
} \
|
||||
\
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
|
||||
std::complex<T> operator-(const std::complex<T>& a, const std::complex<T>& b) { \
|
||||
return std::complex<T>(numext::real(a) - numext::real(b), numext::imag(a) - numext::imag(b)); \
|
||||
} \
|
||||
\
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
|
||||
std::complex<T> operator-(const std::complex<T>& a, const T& b) { \
|
||||
return std::complex<T>(numext::real(a) - b, numext::imag(a)); \
|
||||
} \
|
||||
\
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
|
||||
std::complex<T> operator-(const T& a, const std::complex<T>& b) { \
|
||||
return std::complex<T>(a - numext::real(b), -numext::imag(b)); \
|
||||
} \
|
||||
\
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
|
||||
std::complex<T> operator*(const std::complex<T>& a, const std::complex<T>& b) { \
|
||||
return complex_multiply(a, b); \
|
||||
} \
|
||||
\
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
|
||||
std::complex<T> operator*(const std::complex<T>& a, const T& b) { \
|
||||
return std::complex<T>(numext::real(a) * b, numext::imag(a) * b); \
|
||||
} \
|
||||
\
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
|
||||
std::complex<T> operator*(const T& a, const std::complex<T>& b) { \
|
||||
return std::complex<T>(a * numext::real(b), a * numext::imag(b)); \
|
||||
} \
|
||||
\
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
|
||||
std::complex<T> operator/(const std::complex<T>& a, const std::complex<T>& b) { \
|
||||
return complex_divide(a, b); \
|
||||
} \
|
||||
\
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
|
||||
std::complex<T> operator/(const std::complex<T>& a, const T& b) { \
|
||||
return std::complex<T>(numext::real(a) / b, numext::imag(a) / b); \
|
||||
} \
|
||||
\
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
|
||||
std::complex<T> operator/(const T& a, const std::complex<T>& b) { \
|
||||
return complex_divide(std::complex<T>(a, 0), b); \
|
||||
} \
|
||||
\
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
|
||||
std::complex<T>& operator+=(std::complex<T>& a, const std::complex<T>& b) { \
|
||||
numext::real_ref(a) += numext::real(b); \
|
||||
numext::imag_ref(a) += numext::imag(b); \
|
||||
return a; \
|
||||
} \
|
||||
\
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
|
||||
std::complex<T>& operator-=(std::complex<T>& a, const std::complex<T>& b) { \
|
||||
numext::real_ref(a) -= numext::real(b); \
|
||||
numext::imag_ref(a) -= numext::imag(b); \
|
||||
return a; \
|
||||
} \
|
||||
\
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
|
||||
std::complex<T>& operator*=(std::complex<T>& a, const std::complex<T>& b) { \
|
||||
a = complex_multiply(a, b); \
|
||||
return a; \
|
||||
} \
|
||||
\
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
|
||||
std::complex<T>& operator/=(std::complex<T>& a, const std::complex<T>& b) { \
|
||||
a = complex_divide(a, b); \
|
||||
return a; \
|
||||
} \
|
||||
\
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
|
||||
bool operator==(const std::complex<T>& a, const std::complex<T>& b) { \
|
||||
return numext::real(a) == numext::real(b) && numext::imag(a) == numext::imag(b); \
|
||||
} \
|
||||
\
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
|
||||
bool operator==(const std::complex<T>& a, const T& b) { \
|
||||
return numext::real(a) == b && numext::imag(a) == 0; \
|
||||
} \
|
||||
\
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
|
||||
bool operator==(const T& a, const std::complex<T>& b) { \
|
||||
return a == numext::real(b) && 0 == numext::imag(b); \
|
||||
} \
|
||||
\
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
|
||||
bool operator!=(const std::complex<T>& a, const std::complex<T>& b) { \
|
||||
return !(a == b); \
|
||||
} \
|
||||
\
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
|
||||
bool operator!=(const std::complex<T>& a, const T& b) { \
|
||||
return !(a == b); \
|
||||
} \
|
||||
\
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
|
||||
bool operator!=(const T& a, const std::complex<T>& b) { \
|
||||
return !(a == b); \
|
||||
}
|
||||
#define EIGEN_CREATE_STD_COMPLEX_OPERATOR_SPECIALIZATIONS(T) \
|
||||
\
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::complex<T> operator+(const std::complex<T>& a) { return a; } \
|
||||
\
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::complex<T> operator-(const std::complex<T>& a) { \
|
||||
return std::complex<T>(-numext::real(a), -numext::imag(a)); \
|
||||
} \
|
||||
\
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::complex<T> operator+(const std::complex<T>& a, \
|
||||
const std::complex<T>& b) { \
|
||||
return std::complex<T>(numext::real(a) + numext::real(b), numext::imag(a) + numext::imag(b)); \
|
||||
} \
|
||||
\
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::complex<T> operator+(const std::complex<T>& a, const T& b) { \
|
||||
return std::complex<T>(numext::real(a) + b, numext::imag(a)); \
|
||||
} \
|
||||
\
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::complex<T> operator+(const T& a, const std::complex<T>& b) { \
|
||||
return std::complex<T>(a + numext::real(b), numext::imag(b)); \
|
||||
} \
|
||||
\
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::complex<T> operator-(const std::complex<T>& a, \
|
||||
const std::complex<T>& b) { \
|
||||
return std::complex<T>(numext::real(a) - numext::real(b), numext::imag(a) - numext::imag(b)); \
|
||||
} \
|
||||
\
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::complex<T> operator-(const std::complex<T>& a, const T& b) { \
|
||||
return std::complex<T>(numext::real(a) - b, numext::imag(a)); \
|
||||
} \
|
||||
\
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::complex<T> operator-(const T& a, const std::complex<T>& b) { \
|
||||
return std::complex<T>(a - numext::real(b), -numext::imag(b)); \
|
||||
} \
|
||||
\
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::complex<T> operator*(const std::complex<T>& a, \
|
||||
const std::complex<T>& b) { \
|
||||
return complex_multiply(a, b); \
|
||||
} \
|
||||
\
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::complex<T> operator*(const std::complex<T>& a, const T& b) { \
|
||||
return std::complex<T>(numext::real(a) * b, numext::imag(a) * b); \
|
||||
} \
|
||||
\
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::complex<T> operator*(const T& a, const std::complex<T>& b) { \
|
||||
return std::complex<T>(a * numext::real(b), a * numext::imag(b)); \
|
||||
} \
|
||||
\
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::complex<T> operator/(const std::complex<T>& a, \
|
||||
const std::complex<T>& b) { \
|
||||
return complex_divide(a, b); \
|
||||
} \
|
||||
\
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::complex<T> operator/(const std::complex<T>& a, const T& b) { \
|
||||
return std::complex<T>(numext::real(a) / b, numext::imag(a) / b); \
|
||||
} \
|
||||
\
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::complex<T> operator/(const T& a, const std::complex<T>& b) { \
|
||||
return complex_divide(std::complex<T>(a, 0), b); \
|
||||
} \
|
||||
\
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::complex<T>& operator+=(std::complex<T>& a, const std::complex<T>& b) { \
|
||||
numext::real_ref(a) += numext::real(b); \
|
||||
numext::imag_ref(a) += numext::imag(b); \
|
||||
return a; \
|
||||
} \
|
||||
\
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::complex<T>& operator-=(std::complex<T>& a, const std::complex<T>& b) { \
|
||||
numext::real_ref(a) -= numext::real(b); \
|
||||
numext::imag_ref(a) -= numext::imag(b); \
|
||||
return a; \
|
||||
} \
|
||||
\
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::complex<T>& operator*=(std::complex<T>& a, const std::complex<T>& b) { \
|
||||
a = complex_multiply(a, b); \
|
||||
return a; \
|
||||
} \
|
||||
\
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::complex<T>& operator/=(std::complex<T>& a, const std::complex<T>& b) { \
|
||||
a = complex_divide(a, b); \
|
||||
return a; \
|
||||
} \
|
||||
\
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool operator==(const std::complex<T>& a, const std::complex<T>& b) { \
|
||||
return numext::real(a) == numext::real(b) && numext::imag(a) == numext::imag(b); \
|
||||
} \
|
||||
\
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool operator==(const std::complex<T>& a, const T& b) { \
|
||||
return numext::real(a) == b && numext::imag(a) == 0; \
|
||||
} \
|
||||
\
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool operator==(const T& a, const std::complex<T>& b) { \
|
||||
return a == numext::real(b) && 0 == numext::imag(b); \
|
||||
} \
|
||||
\
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool operator!=(const std::complex<T>& a, const std::complex<T>& b) { \
|
||||
return !(a == b); \
|
||||
} \
|
||||
\
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool operator!=(const std::complex<T>& a, const T& b) { return !(a == b); } \
|
||||
\
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool operator!=(const T& a, const std::complex<T>& b) { return !(a == b); }
|
||||
|
||||
// Do not specialize for long double, since that reduces to double on device.
|
||||
EIGEN_CREATE_STD_COMPLEX_OPERATOR_SPECIALIZATIONS(float)
|
||||
@@ -250,7 +223,6 @@ EIGEN_CREATE_STD_COMPLEX_OPERATOR_SPECIALIZATIONS(double)
|
||||
|
||||
#undef EIGEN_CREATE_STD_COMPLEX_OPERATOR_SPECIALIZATIONS
|
||||
|
||||
|
||||
} // namespace complex_operator_detail
|
||||
|
||||
EIGEN_USING_STD_COMPLEX_OPERATORS
|
||||
|
||||
@@ -21,86 +21,73 @@ namespace internal {
|
||||
// introduce conflicts between these packet_traits definitions and the ones
|
||||
// we'll use on the host side (SSE, AVX, ...)
|
||||
#if defined(EIGEN_GPUCC) && defined(EIGEN_USE_GPU)
|
||||
template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
||||
float4 plog<float4>(const float4& a)
|
||||
{
|
||||
template <>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 plog<float4>(const float4& a) {
|
||||
return make_float4(logf(a.x), logf(a.y), logf(a.z), logf(a.w));
|
||||
}
|
||||
|
||||
template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
||||
double2 plog<double2>(const double2& a)
|
||||
{
|
||||
template <>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 plog<double2>(const double2& a) {
|
||||
using ::log;
|
||||
return make_double2(log(a.x), log(a.y));
|
||||
}
|
||||
|
||||
template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
||||
float4 plog1p<float4>(const float4& a)
|
||||
{
|
||||
template <>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 plog1p<float4>(const float4& a) {
|
||||
return make_float4(log1pf(a.x), log1pf(a.y), log1pf(a.z), log1pf(a.w));
|
||||
}
|
||||
|
||||
template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
||||
double2 plog1p<double2>(const double2& a)
|
||||
{
|
||||
template <>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 plog1p<double2>(const double2& a) {
|
||||
return make_double2(log1p(a.x), log1p(a.y));
|
||||
}
|
||||
|
||||
template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
||||
float4 pexp<float4>(const float4& a)
|
||||
{
|
||||
template <>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pexp<float4>(const float4& a) {
|
||||
return make_float4(expf(a.x), expf(a.y), expf(a.z), expf(a.w));
|
||||
}
|
||||
|
||||
template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
||||
double2 pexp<double2>(const double2& a)
|
||||
{
|
||||
template <>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 pexp<double2>(const double2& a) {
|
||||
using ::exp;
|
||||
return make_double2(exp(a.x), exp(a.y));
|
||||
}
|
||||
|
||||
template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
||||
float4 pexpm1<float4>(const float4& a)
|
||||
{
|
||||
template <>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pexpm1<float4>(const float4& a) {
|
||||
return make_float4(expm1f(a.x), expm1f(a.y), expm1f(a.z), expm1f(a.w));
|
||||
}
|
||||
|
||||
template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
||||
double2 pexpm1<double2>(const double2& a)
|
||||
{
|
||||
template <>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 pexpm1<double2>(const double2& a) {
|
||||
return make_double2(expm1(a.x), expm1(a.y));
|
||||
}
|
||||
|
||||
template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
||||
float4 psqrt<float4>(const float4& a)
|
||||
{
|
||||
template <>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 psqrt<float4>(const float4& a) {
|
||||
return make_float4(sqrtf(a.x), sqrtf(a.y), sqrtf(a.z), sqrtf(a.w));
|
||||
}
|
||||
|
||||
template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
||||
double2 psqrt<double2>(const double2& a)
|
||||
{
|
||||
template <>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 psqrt<double2>(const double2& a) {
|
||||
using ::sqrt;
|
||||
return make_double2(sqrt(a.x), sqrt(a.y));
|
||||
}
|
||||
|
||||
template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
||||
float4 prsqrt<float4>(const float4& a)
|
||||
{
|
||||
template <>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 prsqrt<float4>(const float4& a) {
|
||||
return make_float4(rsqrtf(a.x), rsqrtf(a.y), rsqrtf(a.z), rsqrtf(a.w));
|
||||
}
|
||||
|
||||
template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
||||
double2 prsqrt<double2>(const double2& a)
|
||||
{
|
||||
template <>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 prsqrt<double2>(const double2& a) {
|
||||
return make_double2(rsqrt(a.x), rsqrt(a.y));
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
} // end namespace internal
|
||||
} // end namespace internal
|
||||
|
||||
} // end namespace Eigen
|
||||
} // end namespace Eigen
|
||||
|
||||
#endif // EIGEN_MATH_FUNCTIONS_GPU_H
|
||||
#endif // EIGEN_MATH_FUNCTIONS_GPU_H
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -20,196 +20,173 @@ namespace internal {
|
||||
namespace tuple_impl {
|
||||
|
||||
// Internal tuple implementation.
|
||||
template<size_t N, typename... Types>
|
||||
template <size_t N, typename... Types>
|
||||
class TupleImpl;
|
||||
|
||||
// Generic recursive tuple.
|
||||
template<size_t N, typename T1, typename... Ts>
|
||||
template <size_t N, typename T1, typename... Ts>
|
||||
class TupleImpl<N, T1, Ts...> {
|
||||
public:
|
||||
// Tuple may contain Eigen types.
|
||||
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
|
||||
|
||||
|
||||
// Default constructor, enable if all types are default-constructible.
|
||||
template<typename U1 = T1, typename EnableIf = std::enable_if_t<
|
||||
std::is_default_constructible<U1>::value
|
||||
&& reduce_all<std::is_default_constructible<Ts>::value...>::value
|
||||
>>
|
||||
EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC
|
||||
TupleImpl() : head_{}, tail_{} {}
|
||||
|
||||
template <typename U1 = T1,
|
||||
typename EnableIf = std::enable_if_t<std::is_default_constructible<U1>::value &&
|
||||
reduce_all<std::is_default_constructible<Ts>::value...>::value>>
|
||||
EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC TupleImpl() : head_{}, tail_{} {}
|
||||
|
||||
// Element constructor.
|
||||
template<typename U1, typename... Us,
|
||||
// Only enable if...
|
||||
typename EnableIf = std::enable_if_t<
|
||||
// the number of input arguments match, and ...
|
||||
sizeof...(Us) == sizeof...(Ts) && (
|
||||
// this does not look like a copy/move constructor.
|
||||
N > 1 || std::is_convertible<U1, T1>::value)
|
||||
>>
|
||||
EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC
|
||||
TupleImpl(U1&& arg1, Us&&... args)
|
||||
: head_(std::forward<U1>(arg1)), tail_(std::forward<Us>(args)...) {}
|
||||
|
||||
// The first stored value.
|
||||
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
|
||||
T1& head() {
|
||||
return head_;
|
||||
}
|
||||
|
||||
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
|
||||
const T1& head() const {
|
||||
return head_;
|
||||
}
|
||||
|
||||
template <typename U1, typename... Us,
|
||||
// Only enable if...
|
||||
typename EnableIf = std::enable_if_t<
|
||||
// the number of input arguments match, and ...
|
||||
sizeof...(Us) == sizeof...(Ts) && (
|
||||
// this does not look like a copy/move constructor.
|
||||
N > 1 || std::is_convertible<U1, T1>::value)>>
|
||||
EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC TupleImpl(U1&& arg1, Us&&... args)
|
||||
: head_(std::forward<U1>(arg1)), tail_(std::forward<Us>(args)...) {}
|
||||
|
||||
// The first stored value.
|
||||
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T1& head() { return head_; }
|
||||
|
||||
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE const T1& head() const { return head_; }
|
||||
|
||||
// The tail values.
|
||||
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
|
||||
TupleImpl<N-1, Ts...>& tail() {
|
||||
return tail_;
|
||||
}
|
||||
|
||||
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
|
||||
const TupleImpl<N-1, Ts...>& tail() const {
|
||||
return tail_;
|
||||
}
|
||||
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
||||
void swap(TupleImpl& other) {
|
||||
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE TupleImpl<N - 1, Ts...>& tail() { return tail_; }
|
||||
|
||||
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE const TupleImpl<N - 1, Ts...>& tail() const { return tail_; }
|
||||
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void swap(TupleImpl& other) {
|
||||
using numext::swap;
|
||||
swap(head_, other.head_);
|
||||
swap(tail_, other.tail_);
|
||||
}
|
||||
|
||||
template<typename... UTypes>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
||||
TupleImpl& operator=(const TupleImpl<N, UTypes...>& other) {
|
||||
|
||||
template <typename... UTypes>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TupleImpl& operator=(const TupleImpl<N, UTypes...>& other) {
|
||||
head_ = other.head_;
|
||||
tail_ = other.tail_;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename... UTypes>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
||||
TupleImpl& operator=(TupleImpl<N, UTypes...>&& other) {
|
||||
|
||||
template <typename... UTypes>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TupleImpl& operator=(TupleImpl<N, UTypes...>&& other) {
|
||||
head_ = std::move(other.head_);
|
||||
tail_ = std::move(other.tail_);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
// Allow related tuples to reference head_/tail_.
|
||||
template<size_t M, typename... UTypes>
|
||||
template <size_t M, typename... UTypes>
|
||||
friend class TupleImpl;
|
||||
|
||||
|
||||
T1 head_;
|
||||
TupleImpl<N-1, Ts...> tail_;
|
||||
TupleImpl<N - 1, Ts...> tail_;
|
||||
};
|
||||
|
||||
// Empty tuple specialization.
|
||||
template<>
|
||||
template <>
|
||||
class TupleImpl<size_t(0)> {};
|
||||
|
||||
template<typename TupleType>
|
||||
template <typename TupleType>
|
||||
struct is_tuple : std::false_type {};
|
||||
|
||||
template<typename... Types>
|
||||
struct is_tuple< TupleImpl<sizeof...(Types), Types...> > : std::true_type {};
|
||||
template <typename... Types>
|
||||
struct is_tuple<TupleImpl<sizeof...(Types), Types...>> : std::true_type {};
|
||||
|
||||
// Gets an element from a tuple.
|
||||
template<size_t Idx, typename T1, typename... Ts>
|
||||
template <size_t Idx, typename T1, typename... Ts>
|
||||
struct tuple_get_impl {
|
||||
using TupleType = TupleImpl<sizeof...(Ts) + 1, T1, Ts...>;
|
||||
using ReturnType = typename tuple_get_impl<Idx - 1, Ts...>::ReturnType;
|
||||
|
||||
static EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
|
||||
ReturnType& run(TupleType& tuple) {
|
||||
return tuple_get_impl<Idx-1, Ts...>::run(tuple.tail());
|
||||
|
||||
static EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE ReturnType& run(TupleType& tuple) {
|
||||
return tuple_get_impl<Idx - 1, Ts...>::run(tuple.tail());
|
||||
}
|
||||
|
||||
static EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
|
||||
const ReturnType& run(const TupleType& tuple) {
|
||||
return tuple_get_impl<Idx-1, Ts...>::run(tuple.tail());
|
||||
static EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE const ReturnType& run(const TupleType& tuple) {
|
||||
return tuple_get_impl<Idx - 1, Ts...>::run(tuple.tail());
|
||||
}
|
||||
};
|
||||
|
||||
// Base case, getting the head element.
|
||||
template<typename T1, typename... Ts>
|
||||
template <typename T1, typename... Ts>
|
||||
struct tuple_get_impl<0, T1, Ts...> {
|
||||
using TupleType = TupleImpl<sizeof...(Ts) + 1, T1, Ts...>;
|
||||
using ReturnType = T1;
|
||||
|
||||
static EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
|
||||
T1& run(TupleType& tuple) {
|
||||
return tuple.head();
|
||||
}
|
||||
static EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T1& run(TupleType& tuple) { return tuple.head(); }
|
||||
|
||||
static EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
|
||||
const T1& run(const TupleType& tuple) {
|
||||
static EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE const T1& run(const TupleType& tuple) {
|
||||
return tuple.head();
|
||||
}
|
||||
};
|
||||
|
||||
// Concatenates N Tuples.
|
||||
template<size_t NTuples, typename... Tuples>
|
||||
template <size_t NTuples, typename... Tuples>
|
||||
struct tuple_cat_impl;
|
||||
|
||||
template<size_t NTuples, size_t N1, typename... Args1, size_t N2, typename... Args2, typename... Tuples>
|
||||
template <size_t NTuples, size_t N1, typename... Args1, size_t N2, typename... Args2, typename... Tuples>
|
||||
struct tuple_cat_impl<NTuples, TupleImpl<N1, Args1...>, TupleImpl<N2, Args2...>, Tuples...> {
|
||||
using TupleType1 = TupleImpl<N1, Args1...>;
|
||||
using TupleType2 = TupleImpl<N2, Args2...>;
|
||||
using MergedTupleType = TupleImpl<N1 + N2, Args1..., Args2...>;
|
||||
|
||||
using ReturnType = typename tuple_cat_impl<NTuples-1, MergedTupleType, Tuples...>::ReturnType;
|
||||
|
||||
|
||||
using ReturnType = typename tuple_cat_impl<NTuples - 1, MergedTupleType, Tuples...>::ReturnType;
|
||||
|
||||
// Uses the index sequences to extract and merge elements from tuple1 and tuple2,
|
||||
// then recursively calls again.
|
||||
template<typename Tuple1, size_t... I1s, typename Tuple2, size_t... I2s, typename... MoreTuples>
|
||||
static EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
||||
ReturnType run(Tuple1&& tuple1, std::index_sequence<I1s...>,
|
||||
Tuple2&& tuple2, std::index_sequence<I2s...>,
|
||||
MoreTuples&&... tuples) {
|
||||
return tuple_cat_impl<NTuples-1, MergedTupleType, Tuples...>::run(
|
||||
template <typename Tuple1, size_t... I1s, typename Tuple2, size_t... I2s, typename... MoreTuples>
|
||||
static EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ReturnType run(Tuple1&& tuple1,
|
||||
std::index_sequence<I1s...>,
|
||||
Tuple2&& tuple2,
|
||||
std::index_sequence<I2s...>,
|
||||
MoreTuples&&... tuples) {
|
||||
return tuple_cat_impl<NTuples - 1, MergedTupleType, Tuples...>::run(
|
||||
MergedTupleType(tuple_get_impl<I1s, Args1...>::run(std::forward<Tuple1>(tuple1))...,
|
||||
tuple_get_impl<I2s, Args2...>::run(std::forward<Tuple2>(tuple2))...),
|
||||
std::forward<MoreTuples>(tuples)...);
|
||||
}
|
||||
|
||||
|
||||
// Concatenates the first two tuples.
|
||||
template<typename Tuple1, typename Tuple2, typename... MoreTuples>
|
||||
static EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
||||
ReturnType run(Tuple1&& tuple1, Tuple2&& tuple2, MoreTuples&&... tuples) {
|
||||
return run(std::forward<Tuple1>(tuple1), std::make_index_sequence<N1>{},
|
||||
std::forward<Tuple2>(tuple2), std::make_index_sequence<N2>{},
|
||||
std::forward<MoreTuples>(tuples)...);
|
||||
template <typename Tuple1, typename Tuple2, typename... MoreTuples>
|
||||
static EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ReturnType run(Tuple1&& tuple1, Tuple2&& tuple2,
|
||||
MoreTuples&&... tuples) {
|
||||
return run(std::forward<Tuple1>(tuple1), std::make_index_sequence<N1>{}, std::forward<Tuple2>(tuple2),
|
||||
std::make_index_sequence<N2>{}, std::forward<MoreTuples>(tuples)...);
|
||||
}
|
||||
};
|
||||
|
||||
// Base case with a single tuple.
|
||||
template<size_t N, typename... Args>
|
||||
struct tuple_cat_impl<1, TupleImpl<N, Args...> > {
|
||||
template <size_t N, typename... Args>
|
||||
struct tuple_cat_impl<1, TupleImpl<N, Args...>> {
|
||||
using ReturnType = TupleImpl<N, Args...>;
|
||||
|
||||
template<typename Tuple1>
|
||||
static EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
||||
ReturnType run(Tuple1&& tuple1) {
|
||||
|
||||
template <typename Tuple1>
|
||||
static EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ReturnType run(Tuple1&& tuple1) {
|
||||
return tuple1;
|
||||
}
|
||||
};
|
||||
|
||||
// Special case of no tuples.
|
||||
template<>
|
||||
struct tuple_cat_impl<0> {
|
||||
template <>
|
||||
struct tuple_cat_impl<0> {
|
||||
using ReturnType = TupleImpl<0>;
|
||||
static EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
||||
ReturnType run() {return ReturnType{}; }
|
||||
static EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ReturnType run() { return ReturnType{}; }
|
||||
};
|
||||
|
||||
// For use in make_tuple, unwraps a reference_wrapper.
|
||||
template <typename T>
|
||||
struct unwrap_reference_wrapper { using type = T; };
|
||||
|
||||
struct unwrap_reference_wrapper {
|
||||
using type = T;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct unwrap_reference_wrapper<std::reference_wrapper<T> > { using type = T&; };
|
||||
struct unwrap_reference_wrapper<std::reference_wrapper<T>> {
|
||||
using type = T&;
|
||||
};
|
||||
|
||||
// For use in make_tuple, decays a type and unwraps a reference_wrapper.
|
||||
template <typename T>
|
||||
@@ -220,11 +197,11 @@ struct unwrap_decay {
|
||||
/**
|
||||
* Utility for determining a tuple's size.
|
||||
*/
|
||||
template<typename Tuple>
|
||||
template <typename Tuple>
|
||||
struct tuple_size;
|
||||
|
||||
template<typename... Types >
|
||||
struct tuple_size< TupleImpl<sizeof...(Types), Types...> > : std::integral_constant<size_t, sizeof...(Types)> {};
|
||||
template <typename... Types>
|
||||
struct tuple_size<TupleImpl<sizeof...(Types), Types...>> : std::integral_constant<size_t, sizeof...(Types)> {};
|
||||
|
||||
/**
|
||||
* Gets an element of a tuple.
|
||||
@@ -233,17 +210,15 @@ struct tuple_size< TupleImpl<sizeof...(Types), Types...> > : std::integral_const
|
||||
* \param tuple the tuple.
|
||||
* \return a reference to the desired element.
|
||||
*/
|
||||
template<size_t Idx, typename... Types>
|
||||
EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
||||
const typename tuple_get_impl<Idx, Types...>::ReturnType&
|
||||
get(const TupleImpl<sizeof...(Types), Types...>& tuple) {
|
||||
template <size_t Idx, typename... Types>
|
||||
EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename tuple_get_impl<Idx, Types...>::ReturnType& get(
|
||||
const TupleImpl<sizeof...(Types), Types...>& tuple) {
|
||||
return tuple_get_impl<Idx, Types...>::run(tuple);
|
||||
}
|
||||
|
||||
template<size_t Idx, typename... Types>
|
||||
EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
||||
typename tuple_get_impl<Idx, Types...>::ReturnType&
|
||||
get(TupleImpl<sizeof...(Types), Types...>& tuple) {
|
||||
template <size_t Idx, typename... Types>
|
||||
EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename tuple_get_impl<Idx, Types...>::ReturnType& get(
|
||||
TupleImpl<sizeof...(Types), Types...>& tuple) {
|
||||
return tuple_get_impl<Idx, Types...>::run(tuple);
|
||||
}
|
||||
|
||||
@@ -252,31 +227,27 @@ get(TupleImpl<sizeof...(Types), Types...>& tuple) {
|
||||
* \param tuples ... list of tuples.
|
||||
* \return concatenated tuple.
|
||||
*/
|
||||
template<typename... Tuples,
|
||||
typename EnableIf = std::enable_if_t<
|
||||
internal::reduce_all<
|
||||
is_tuple<typename std::decay<Tuples>::type>::value...>::value>>
|
||||
template <typename... Tuples, typename EnableIf = std::enable_if_t<
|
||||
internal::reduce_all<is_tuple<typename std::decay<Tuples>::type>::value...>::value>>
|
||||
EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
||||
typename tuple_cat_impl<sizeof...(Tuples), typename std::decay<Tuples>::type...>::ReturnType
|
||||
tuple_cat(Tuples&&... tuples) {
|
||||
typename tuple_cat_impl<sizeof...(Tuples), typename std::decay<Tuples>::type...>::ReturnType
|
||||
tuple_cat(Tuples&&... tuples) {
|
||||
return tuple_cat_impl<sizeof...(Tuples), typename std::decay<Tuples>::type...>::run(std::forward<Tuples>(tuples)...);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tie arguments together into a tuple.
|
||||
*/
|
||||
template <typename... Args, typename ReturnType = TupleImpl<sizeof...(Args), Args&...> >
|
||||
EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
||||
ReturnType tie(Args&... args) EIGEN_NOEXCEPT {
|
||||
return ReturnType{args...};
|
||||
template <typename... Args, typename ReturnType = TupleImpl<sizeof...(Args), Args&...>>
|
||||
EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ReturnType tie(Args&... args) EIGEN_NOEXCEPT {
|
||||
return ReturnType{args...};
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a tuple of l-values with the supplied arguments.
|
||||
*/
|
||||
template <typename... Args, typename ReturnType = TupleImpl<sizeof...(Args), typename unwrap_decay<Args>::type...> >
|
||||
EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
||||
ReturnType make_tuple(Args&&... args) {
|
||||
template <typename... Args, typename ReturnType = TupleImpl<sizeof...(Args), typename unwrap_decay<Args>::type...>>
|
||||
EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ReturnType make_tuple(Args&&... args) {
|
||||
return ReturnType{std::forward<Args>(args)...};
|
||||
}
|
||||
|
||||
@@ -284,15 +255,15 @@ ReturnType make_tuple(Args&&... args) {
|
||||
* Forward a set of arguments as a tuple.
|
||||
*/
|
||||
template <typename... Args>
|
||||
EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
||||
TupleImpl<sizeof...(Args), Args...> forward_as_tuple(Args&&... args) {
|
||||
EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TupleImpl<sizeof...(Args), Args...> forward_as_tuple(
|
||||
Args&&... args) {
|
||||
return TupleImpl<sizeof...(Args), Args...>(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
/**
|
||||
* Alternative to std::tuple that can be used on device.
|
||||
*/
|
||||
template<typename... Types>
|
||||
template <typename... Types>
|
||||
using tuple = TupleImpl<sizeof...(Types), Types...>;
|
||||
|
||||
} // namespace tuple_impl
|
||||
|
||||
@@ -22,61 +22,56 @@ namespace internal {
|
||||
|
||||
template <>
|
||||
struct type_casting_traits<Eigen::half, float> {
|
||||
enum {
|
||||
VectorizedCast = 1,
|
||||
SrcCoeffRatio = 1,
|
||||
TgtCoeffRatio = 2
|
||||
};
|
||||
enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 2 };
|
||||
};
|
||||
|
||||
template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pcast<half2, float4>(const half2& a, const half2& b) {
|
||||
template <>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pcast<half2, float4>(const half2& a, const half2& b) {
|
||||
float2 r1 = __half22float2(a);
|
||||
float2 r2 = __half22float2(b);
|
||||
return make_float4(r1.x, r1.y, r2.x, r2.y);
|
||||
}
|
||||
|
||||
|
||||
template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4h2 pcast<float4, Packet4h2>(const float4& a, const float4& b) {
|
||||
template <>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4h2 pcast<float4, Packet4h2>(const float4& a, const float4& b) {
|
||||
Packet4h2 r;
|
||||
half2* r_alias=reinterpret_cast<half2*>(&r);
|
||||
r_alias[0]=__floats2half2_rn(a.x,a.y);
|
||||
r_alias[1]=__floats2half2_rn(a.z,a.w);
|
||||
r_alias[2]=__floats2half2_rn(b.x,b.y);
|
||||
r_alias[3]=__floats2half2_rn(b.z,b.w);
|
||||
half2* r_alias = reinterpret_cast<half2*>(&r);
|
||||
r_alias[0] = __floats2half2_rn(a.x, a.y);
|
||||
r_alias[1] = __floats2half2_rn(a.z, a.w);
|
||||
r_alias[2] = __floats2half2_rn(b.x, b.y);
|
||||
r_alias[3] = __floats2half2_rn(b.z, b.w);
|
||||
return r;
|
||||
}
|
||||
|
||||
template <>
|
||||
struct type_casting_traits<float, Eigen::half> {
|
||||
enum {
|
||||
VectorizedCast = 1,
|
||||
SrcCoeffRatio = 2,
|
||||
TgtCoeffRatio = 1
|
||||
};
|
||||
enum { VectorizedCast = 1, SrcCoeffRatio = 2, TgtCoeffRatio = 1 };
|
||||
};
|
||||
|
||||
template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pcast<Packet4h2, float4>(const Packet4h2& a) {
|
||||
template <>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pcast<Packet4h2, float4>(const Packet4h2& a) {
|
||||
// Simply discard the second half of the input
|
||||
float4 r;
|
||||
const half2* a_alias=reinterpret_cast<const half2*>(&a);
|
||||
const half2* a_alias = reinterpret_cast<const half2*>(&a);
|
||||
float2 r1 = __half22float2(a_alias[0]);
|
||||
float2 r2 = __half22float2(a_alias[1]);
|
||||
r.x=static_cast<float>(r1.x);
|
||||
r.y=static_cast<float>(r1.y);
|
||||
r.z=static_cast<float>(r2.x);
|
||||
r.w=static_cast<float>(r2.y);
|
||||
r.x = static_cast<float>(r1.x);
|
||||
r.y = static_cast<float>(r1.y);
|
||||
r.z = static_cast<float>(r2.x);
|
||||
r.w = static_cast<float>(r2.y);
|
||||
return r;
|
||||
}
|
||||
|
||||
template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pcast<float4, half2>(const float4& a) {
|
||||
template <>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pcast<float4, half2>(const float4& a) {
|
||||
// Simply discard the second half of the input
|
||||
return __floats2half2_rn(a.x, a.y);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
} // end namespace internal
|
||||
} // end namespace internal
|
||||
|
||||
} // end namespace Eigen
|
||||
} // end namespace Eigen
|
||||
|
||||
#endif // EIGEN_TYPE_CASTING_GPU_H
|
||||
#endif // EIGEN_TYPE_CASTING_GPU_H
|
||||
|
||||
Reference in New Issue
Block a user