1 #pragma once 2 3 namespace torch { 4 namespace jit { 5 namespace tensorexpr { 6 7 constexpr auto cpp_intrinsics_definition = R"( 8 namespace std { 9 10 template <typename T, 11 typename std::enable_if<std::is_floating_point<T>::value, int>::type = 0> 12 T rsqrt(T v) { 13 return 1.0f / std::sqrt(v); 14 } 15 16 template <typename T, 17 typename std::enable_if<std::is_floating_point<T>::value, int>::type = 0> 18 T frac(T v) { 19 T intpart; 20 return std::modf(v, &intpart); 21 } 22 23 template <typename From, typename To> 24 To bitcast(const From& v) { 25 assert(sizeof(To) == sizeof(From)); 26 To res; 27 std::memcpy(&res, &v, sizeof(From)); 28 return res; 29 } 30 31 } // namespace std 32 )"; 33 34 } // namespace tensorexpr 35 } // namespace jit 36 } // namespace torch 37