Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix calling default constructor to use uniform initialization. #334

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions config/ImathConfig.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,15 @@
# define IMATH_HOSTDEVICE
#endif

//
// The namespace of C++ standard library
//
#ifdef __CUDACC__
# define IMATH_STD_NAMESPACE cuda::std
#else
# define IMATH_STD_NAMESPACE std
#endif

//
// Some compilers define a special intrinsic to use in conditionals that can
// speed up extremely performance-critical spots if the conditional is
Expand Down
55 changes: 30 additions & 25 deletions src/Imath/ImathMath.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@

#include "ImathNamespace.h"
#include "ImathPlatform.h"
#include <cmath>
#include <limits>
#ifdef __CUDACC__
# include <cuda/std/cmath>
# include <cuda/std/limits>
#else
# include <cmath>
# include <limits>
#endif

IMATH_INTERNAL_NAMESPACE_HEADER_ENTER

Expand All @@ -38,93 +43,93 @@ template <class T> struct Math
{
IMATH_DEPRECATED ("use std::math functions")
IMATH_HOSTDEVICE
static T acos (T x) { return std::acos (x); }
static T acos (T x) { return IMATH_STD_NAMESPACE::acos (x); }

IMATH_DEPRECATED ("use std::math functions")
IMATH_HOSTDEVICE
static T asin (T x) { return std::asin (x); }
static T asin (T x) { return IMATH_STD_NAMESPACE::asin (x); }

IMATH_DEPRECATED ("use std::math functions")
IMATH_HOSTDEVICE
static T atan (T x) { return std::atan (x); }
static T atan (T x) { return IMATH_STD_NAMESPACE::atan (x); }

IMATH_DEPRECATED ("use std::math functions")
IMATH_HOSTDEVICE
static T atan2 (T x, T y) { return std::atan2 (x, y); }
static T atan2 (T x, T y) { return IMATH_STD_NAMESPACE::atan2 (x, y); }

IMATH_DEPRECATED ("use std::math functions")
IMATH_HOSTDEVICE
static T cos (T x) { return std::cos (x); }
static T cos (T x) { return IMATH_STD_NAMESPACE::cos (x); }

IMATH_DEPRECATED ("use std::math functions")
IMATH_HOSTDEVICE
static T sin (T x) { return std::sin (x); }
static T sin (T x) { return IMATH_STD_NAMESPACE::sin (x); }

IMATH_DEPRECATED ("use std::math functions")
IMATH_HOSTDEVICE
static T tan (T x) { return std::tan (x); }
static T tan (T x) { return IMATH_STD_NAMESPACE::tan (x); }

IMATH_DEPRECATED ("use std::math functions")
IMATH_HOSTDEVICE
static T cosh (T x) { return std::cosh (x); }
static T cosh (T x) { return IMATH_STD_NAMESPACE::cosh (x); }

IMATH_DEPRECATED ("use std::math functions")
IMATH_HOSTDEVICE
static T sinh (T x) { return std::sinh (x); }
static T sinh (T x) { return IMATH_STD_NAMESPACE::sinh (x); }

IMATH_DEPRECATED ("use std::math functions")
IMATH_HOSTDEVICE
static T tanh (T x) { return std::tanh (x); }
static T tanh (T x) { return IMATH_STD_NAMESPACE::tanh (x); }

IMATH_DEPRECATED ("use std::math functions")
IMATH_HOSTDEVICE
static T exp (T x) { return std::exp (x); }
static T exp (T x) { return IMATH_STD_NAMESPACE::exp (x); }

IMATH_DEPRECATED ("use std::math functions")
IMATH_HOSTDEVICE
static T log (T x) { return std::log (x); }
static T log (T x) { return IMATH_STD_NAMESPACE::log (x); }

IMATH_DEPRECATED ("use std::math functions")
IMATH_HOSTDEVICE
static T log10 (T x) { return std::log10 (x); }
static T log10 (T x) { return IMATH_STD_NAMESPACE::log10 (x); }

IMATH_DEPRECATED ("use std::math functions")
IMATH_HOSTDEVICE
static T modf (T x, T* iptr)
{
T ival;
T rval (std::modf (T (x), &ival));
T rval (IMATH_STD_NAMESPACE::modf (T (x), &ival));
*iptr = ival;
return rval;
}

IMATH_DEPRECATED ("use std::math functions")
IMATH_HOSTDEVICE
static T pow (T x, T y) { return std::pow (x, y); }
static T pow (T x, T y) { return IMATH_STD_NAMESPACE::pow (x, y); }

IMATH_DEPRECATED ("use std::math functions")
IMATH_HOSTDEVICE
static T sqrt (T x) { return std::sqrt (x); }
static T sqrt (T x) { return IMATH_STD_NAMESPACE::sqrt (x); }

IMATH_DEPRECATED ("use std::math functions")
IMATH_HOSTDEVICE
static T ceil (T x) { return std::ceil (x); }
static T ceil (T x) { return IMATH_STD_NAMESPACE::ceil (x); }

IMATH_DEPRECATED ("use std::math functions")
IMATH_HOSTDEVICE
static T fabs (T x) { return std::fabs (x); }
static T fabs (T x) { return IMATH_STD_NAMESPACE::fabs (x); }

IMATH_DEPRECATED ("use std::math functions")
IMATH_HOSTDEVICE
static T floor (T x) { return std::floor (x); }
static T floor (T x) { return IMATH_STD_NAMESPACE::floor (x); }

IMATH_DEPRECATED ("use std::math functions")
IMATH_HOSTDEVICE
static T fmod (T x, T y) { return std::fmod (x, y); }
static T fmod (T x, T y) { return IMATH_STD_NAMESPACE::fmod (x, y); }

IMATH_DEPRECATED ("use std::math functions")
IMATH_HOSTDEVICE
static T hypot (T x, T y) { return std::hypot (x, y); }
static T hypot (T x, T y) { return IMATH_STD_NAMESPACE::hypot (x, y); }
};
/// @endcond

Expand All @@ -134,10 +139,10 @@ template <class T>
IMATH_HOSTDEVICE inline T
sinx_over_x (T x)
{
if (x * x < std::numeric_limits<T>::epsilon ())
if (x * x < IMATH_STD_NAMESPACE::numeric_limits<T>::epsilon ())
return T (1);
else
return std::sin (x) / x;
return IMATH_STD_NAMESPACE::sin (x) / x;
}

/// Compare two numbers and test if they are "approximately equal":
Expand Down
46 changes: 25 additions & 21 deletions src/Imath/ImathTypeTraits.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,23 @@
#ifndef INCLUDED_IMATHTYPETRAITS_H
#define INCLUDED_IMATHTYPETRAITS_H

#include <type_traits>
#ifdef __CUDACC__
# include <cuda/std/type_traits>
#else
# include <type_traits>
#endif

#include "ImathPlatform.h"

IMATH_INTERNAL_NAMESPACE_HEADER_ENTER

/// Define Imath::enable_if_t to be std for C++14, equivalent for C++11.
/// Define Imath::enable_if_t to be IMATH_STD_NAMESPACE for C++14, equivalent for C++11.
#if (IMATH_CPLUSPLUS_VERSION >= 14)
using std::enable_if_t; // Use C++14 std::enable_if_t
using IMATH_STD_NAMESPACE::enable_if_t; // Use C++14 IMATH_STD_NAMESPACE::enable_if_t
#else
// Define enable_if_t for C++11
template <bool B, class T = void>
using enable_if_t = typename std::enable_if<B, T>::type;
using enable_if_t = typename IMATH_STD_NAMESPACE::enable_if<B, T>::type;
#endif

/// An enable_if helper to be used in template parameters which results in
Expand Down Expand Up @@ -63,14 +67,14 @@ using enable_if_t = typename std::enable_if<B, T>::type;
/// an Imath::V3f by subscripting:
///
/// template<>
/// struct Imath::has_subscript<mytype, float, 3> : public std::true_type { };
/// struct Imath::has_subscript<mytype, float, 3> : public IMATH_STD_NAMESPACE::true_type { };
///
/// And similarly, user code may correct a potential false positive (that
/// is, a `mytype` looks like it should be convertible to a V3f, but you
/// don't want it to ever happen):
///
/// template<typename B, int N>
/// struct Imath::has_subscript<mytype, B, N> : public std::false_type { };
/// struct Imath::has_subscript<mytype, B, N> : public IMATH_STD_NAMESPACE::false_type { };
///

/// `has_xy<T,Base>::value` will be true if type `T` has member variables
Expand All @@ -85,8 +89,8 @@ template <typename T, typename Base> struct has_xy
// Valid only if .x, .y exist and are the right type: return a Yes.
template <
typename C,
IMATH_ENABLE_IF (std::is_same<decltype (C ().x), Base>::value),
IMATH_ENABLE_IF (std::is_same<decltype (C ().y), Base>::value)>
IMATH_ENABLE_IF (IMATH_STD_NAMESPACE::is_same<decltype (C {}.x), Base>::value),
IMATH_ENABLE_IF (IMATH_STD_NAMESPACE::is_same<decltype (C {}.y), Base>::value)>
static Yes& test (int);

// Fallback, default to returning a No.
Expand All @@ -113,9 +117,9 @@ template <typename T, typename Base> struct has_xyz
// Valid only if .x, .y, .z exist and are the right type: return a Yes.
template <
typename C,
IMATH_ENABLE_IF (std::is_same<decltype (C ().x), Base>::value),
IMATH_ENABLE_IF (std::is_same<decltype (C ().y), Base>::value),
IMATH_ENABLE_IF (std::is_same<decltype (C ().z), Base>::value)>
IMATH_ENABLE_IF (IMATH_STD_NAMESPACE::is_same<decltype (C {}.x), Base>::value),
IMATH_ENABLE_IF (IMATH_STD_NAMESPACE::is_same<decltype (C {}.y), Base>::value),
IMATH_ENABLE_IF (IMATH_STD_NAMESPACE::is_same<decltype (C {}.z), Base>::value)>
static Yes& test (int);

// Fallback, default to returning a No.
Expand All @@ -142,10 +146,10 @@ template <typename T, typename Base> struct has_xyzw
// Valid only if .x, .y, .z, .w exist and are the right type: return a Yes.
template <
typename C,
IMATH_ENABLE_IF (std::is_same<decltype (C ().x), Base>::value),
IMATH_ENABLE_IF (std::is_same<decltype (C ().y), Base>::value),
IMATH_ENABLE_IF (std::is_same<decltype (C ().z), Base>::value),
IMATH_ENABLE_IF (std::is_same<decltype (C ().w), Base>::value)>
IMATH_ENABLE_IF (IMATH_STD_NAMESPACE::is_same<decltype (C {}.x), Base>::value),
IMATH_ENABLE_IF (IMATH_STD_NAMESPACE::is_same<decltype (C {}.y), Base>::value),
IMATH_ENABLE_IF (IMATH_STD_NAMESPACE::is_same<decltype (C {}.z), Base>::value),
IMATH_ENABLE_IF (IMATH_STD_NAMESPACE::is_same<decltype (C {}.w), Base>::value)>
static Yes& test (int);

// Fallback, default to returning a No.
Expand All @@ -172,8 +176,8 @@ template <typename T, typename Base, int Nelem> struct has_subscript
// Valid only if T[] is possible and is the right type: return a Yes.
template <
typename C,
IMATH_ENABLE_IF (std::is_same<
typename std::decay<decltype (C ()[0])>::type,
IMATH_ENABLE_IF (IMATH_STD_NAMESPACE::is_same<
typename IMATH_STD_NAMESPACE::decay<decltype (C {}[0])>::type,
Base>::value)>
static Yes& test (int);

Expand All @@ -191,7 +195,7 @@ template <typename T, typename Base, int Nelem> struct has_subscript

/// C arrays of just the right length also are qualified for has_subscript.
template <typename Base, int Nelem>
struct has_subscript<Base[Nelem], Base, Nelem> : public std::true_type
struct has_subscript<Base[Nelem], Base, Nelem> : public IMATH_STD_NAMESPACE::true_type
{};

/// `has_double_subscript<T,Base,Rows,Cols>::value` will be true if type `T`
Expand All @@ -207,8 +211,8 @@ struct has_double_subscript
// Valid only if T[][] is possible and is the right type: return a Yes.
template <
typename C,
IMATH_ENABLE_IF (std::is_same<
typename std::decay<decltype (C ()[0][0])>::type,
IMATH_ENABLE_IF (IMATH_STD_NAMESPACE::is_same<
typename IMATH_STD_NAMESPACE::decay<decltype (C {}[0][0])>::type,
Base>::value)>
static Yes& test (int);

Expand All @@ -227,7 +231,7 @@ struct has_double_subscript
/// C arrays of just the right length also are qualified for has_double_subscript.
template <typename Base, int Rows, int Cols>
struct has_double_subscript<Base[Rows][Cols], Base, Rows, Cols>
: public std::true_type
: public IMATH_STD_NAMESPACE::true_type
{};

/// @}
Expand Down
Loading