Commit cda85450 authored by Robert Maynard's avatar Robert Maynard Committed by Kitware Robot
Browse files

Merge topic 'better_FloatingPointReturnType'

a9e64c4b

 FloatPointReturnType is float if 'T' is < 32bytes instead of being double.
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Acked-by: Kenneth Moreland's avatarKenneth Moreland <kmorel@sandia.gov>
Acked-by: Thomas Otahal's avatarThomas Otahal <tjotaha@sandia.gov>
Merge-request: !1048
parents 747c5c90 a9e64c4b
This diff is collapsed.
...@@ -108,28 +108,30 @@ static inline VTKM_EXEC_CONT vtkm::Vec<typename detail::FloatingPointReturnType< ...@@ -108,28 +108,30 @@ static inline VTKM_EXEC_CONT vtkm::Vec<typename detail::FloatingPointReturnType<
}} }}
'''.format(vtkmname) '''.format(vtkmname)
def unary_math_function_no_vec(vtkmname, sysname, returntype = None): def unary_math_function_no_vec(vtkmname, sysname):
return unary_function(vtkmname, general_type = '''template <typename T>
'T', static inline VTKM_EXEC_CONT typename detail::FloatingPointReturnType<T>::Type {0}(const T& x)
'typename detail::FloatingPointReturnType<T>::Type' if returntype == None else returntype, {{
'VTKM_CUDA_MATH_FUNCTION_64(' + sysname + ')(static_cast<vtkm::Float64>(x))', using RT = typename detail::FloatingPointReturnType<T>::Type;
'std::' + sysname + '(static_cast<vtkm::Float64>(x))', return vtkm::{0}(static_cast<RT>(x));
'template <typename T>', }}
'static inline') + \ '''.format(vtkmname)
unary_function(vtkmname, specialization_types = unary_function(vtkmname,
'vtkm::Float32',
'vtkm::Float32', 'vtkm::Float32',
'detail::FloatingPointReturnType<vtkm::Float32>::Type' if returntype == None else returntype,
'VTKM_CUDA_MATH_FUNCTION_32(' + sysname + ')(x)', 'VTKM_CUDA_MATH_FUNCTION_32(' + sysname + ')(x)',
'std::' + sysname + '(x)', 'std::' + sysname + '(x)',
'template <>', '',
'inline') + \ 'inline')
unary_function(vtkmname, specialization_types += unary_function(vtkmname,
'vtkm::Float64',
'vtkm::Float64', 'vtkm::Float64',
'detail::FloatingPointReturnType<vtkm::Float64>::Type' if returntype == None else returntype,
'VTKM_CUDA_MATH_FUNCTION_64(' + sysname + ')(x)', 'VTKM_CUDA_MATH_FUNCTION_64(' + sysname + ')(x)',
'std::' + sysname + '(x)', 'std::' + sysname + '(x)',
'template <>', '',
'inline') 'inline')
return specialization_types + general_type
def unary_math_function(vtkmname, sysname): def unary_math_function(vtkmname, sysname):
return unary_math_function_no_vec(vtkmname, sysname) + \ return unary_math_function_no_vec(vtkmname, sysname) + \
...@@ -235,25 +237,15 @@ static inline VTKM_EXEC_CONT vtkm::Float64 Pi_4() ...@@ -235,25 +237,15 @@ static inline VTKM_EXEC_CONT vtkm::Float64 Pi_4()
namespace detail namespace detail
{ {
template <typename T> template <typename T>
struct FloatingPointReturnCondition
: std::enable_if<
std::is_same<typename vtkm::VecTraits<T>::ComponentType, vtkm::Float32>::value ||
std::is_same<typename vtkm::VecTraits<T>::ComponentType, const vtkm::Float32>::value>
{
};
template <typename T, typename = void>
struct FloatingPointReturnType struct FloatingPointReturnType
{ {
using Type = vtkm::Float64; using ctype = typename vtkm::VecTraits<T>::ComponentType;
}; using representable_as_float_type =
std::integral_constant<bool,
template <typename T> ((sizeof(ctype) < sizeof(float)) || std::is_same<ctype, vtkm::Float32>::value)>;
struct FloatingPointReturnType<T, typename FloatingPointReturnCondition<T>::type> using Type =
{ typename std::conditional<representable_as_float_type::value, vtkm::Float32, vtkm::Float64>::type;
using Type = vtkm::Float32;
}; };
} // namespace detail } // namespace detail
......
...@@ -71,9 +71,10 @@ VTKM_EXEC_CONT vtkm::Vec<ValueType, N> Lerp(const vtkm::Vec<ValueType, N>& value ...@@ -71,9 +71,10 @@ VTKM_EXEC_CONT vtkm::Vec<ValueType, N> Lerp(const vtkm::Vec<ValueType, N>& value
/// when possible. /// when possible.
/// ///
template <typename T> template <typename T>
VTKM_EXEC_CONT typename vtkm::VecTraits<T>::ComponentType MagnitudeSquared(const T& x) VTKM_EXEC_CONT typename detail::FloatingPointReturnType<T>::Type MagnitudeSquared(const T& x)
{ {
return vtkm::dot(x, x); using U = typename detail::FloatingPointReturnType<T>::Type;
return static_cast<U>(vtkm::dot(x, x));
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
......
...@@ -38,7 +38,7 @@ public: ...@@ -38,7 +38,7 @@ public:
template <typename T, typename T2> template <typename T, typename T2>
VTKM_EXEC void operator()(const T& inValue, T2& outValue) const VTKM_EXEC void operator()(const T& inValue, T2& outValue) const
{ {
outValue = vtkm::Magnitude(inValue); outValue = static_cast<T2>(vtkm::Magnitude(inValue));
} }
}; };
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment