mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
[5/N] Fixes clang-tidy warnings in c10/{core,util}/*.h (#115354)
This PR continues to fix clang-tidy warnings for headers in c10/core and c10/util. Pull Request resolved: https://github.com/pytorch/pytorch/pull/115354 Approved by: https://github.com/Skylion007
This commit is contained in:
@ -1,9 +1,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
#include <cstdint>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include <c10/core/Device.h>
|
#include <c10/core/Device.h>
|
||||||
|
#include <c10/macros/Macros.h>
|
||||||
#include <c10/util/Exception.h>
|
#include <c10/util/Exception.h>
|
||||||
#include <c10/util/ThreadLocalDebugInfo.h>
|
#include <c10/util/ThreadLocalDebugInfo.h>
|
||||||
#include <c10/util/UniqueVoidPtr.h>
|
#include <c10/util/UniqueVoidPtr.h>
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <c10/core/Device.h>
|
#include <c10/core/Device.h>
|
||||||
|
#include <c10/core/DeviceType.h>
|
||||||
|
#include <c10/macros/Macros.h>
|
||||||
|
#include <cstddef>
|
||||||
|
|
||||||
namespace c10 {
|
namespace c10 {
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <c10/core/Backend.h>
|
|
||||||
#include <c10/core/Device.h>
|
#include <c10/core/Device.h>
|
||||||
|
#include <c10/core/DeviceType.h>
|
||||||
#include <c10/core/Layout.h>
|
#include <c10/core/Layout.h>
|
||||||
#include <c10/core/ScalarType.h>
|
#include <c10/core/ScalarType.h>
|
||||||
#include <c10/util/typeid.h>
|
#include <c10/util/typeid.h>
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#include <c10/util/Exception.h>
|
#include <c10/util/Exception.h>
|
||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
#include <cstdint>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <iosfwd>
|
#include <iosfwd>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#include <c10/core/Allocator.h>
|
#include <c10/core/Allocator.h>
|
||||||
|
#include <cstddef>
|
||||||
|
|
||||||
namespace c10 {
|
namespace c10 {
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ namespace c10 {
|
|||||||
// not be a way to conveniently index based on the object.)
|
// not be a way to conveniently index based on the object.)
|
||||||
class PyHandleCache {
|
class PyHandleCache {
|
||||||
public:
|
public:
|
||||||
PyHandleCache() : pyinterpreter_(nullptr), data_(nullptr) {}
|
PyHandleCache() : pyinterpreter_(nullptr) {}
|
||||||
|
|
||||||
// Attempt to fetch the pointer from the cache, if the PyInterpreter
|
// Attempt to fetch the pointer from the cache, if the PyInterpreter
|
||||||
// matches. If it doesn't exist, or the cache entry is not valid,
|
// matches. If it doesn't exist, or the cache entry is not valid,
|
||||||
@ -69,7 +69,7 @@ class PyHandleCache {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
mutable std::atomic<impl::PyInterpreter*> pyinterpreter_;
|
mutable std::atomic<impl::PyInterpreter*> pyinterpreter_;
|
||||||
mutable PyObject* data_;
|
mutable PyObject* data_{nullptr};
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace c10
|
} // namespace c10
|
||||||
|
@ -149,7 +149,7 @@ struct C10_API TensorOptions {
|
|||||||
/// See NOTE [ TensorOptions Constructors ] on why this is templatized.
|
/// See NOTE [ TensorOptions Constructors ] on why this is templatized.
|
||||||
template <
|
template <
|
||||||
typename T,
|
typename T,
|
||||||
typename = std::enable_if_t<std::is_same<std::decay_t<T>, Device>::value>>
|
typename = std::enable_if_t<std::is_same_v<std::decay_t<T>, Device>>>
|
||||||
/* implicit */ TensorOptions(T&& device) : TensorOptions() {
|
/* implicit */ TensorOptions(T&& device) : TensorOptions() {
|
||||||
this->set_device(std::forward<T>(device));
|
this->set_device(std::forward<T>(device));
|
||||||
}
|
}
|
||||||
@ -164,8 +164,7 @@ struct C10_API TensorOptions {
|
|||||||
/// constructors too.
|
/// constructors too.
|
||||||
template <
|
template <
|
||||||
typename... Args,
|
typename... Args,
|
||||||
typename =
|
typename = std::enable_if_t<std::is_constructible_v<Device, Args&&...>>>
|
||||||
std::enable_if_t<std::is_constructible<Device, Args&&...>::value>>
|
|
||||||
/* implicit */ TensorOptions(Args&&... args)
|
/* implicit */ TensorOptions(Args&&... args)
|
||||||
: TensorOptions(Device(std::forward<Args>(args)...)) {}
|
: TensorOptions(Device(std::forward<Args>(args)...)) {}
|
||||||
|
|
||||||
|
@ -22,15 +22,20 @@ struct InlineEvent final {
|
|||||||
|
|
||||||
// Move constructor and move assignment operator
|
// Move constructor and move assignment operator
|
||||||
InlineEvent(InlineEvent&& other) noexcept
|
InlineEvent(InlineEvent&& other) noexcept
|
||||||
: InlineEvent(other.device_type_, other.flag_) {
|
: event_(other.event_),
|
||||||
swap(std::move(other));
|
backend_(std::move(other.backend_)),
|
||||||
|
device_type_(other.device_type_),
|
||||||
|
device_index_(other.device_index_),
|
||||||
|
flag_(other.flag_),
|
||||||
|
was_marked_for_recording_(other.was_marked_for_recording_) {
|
||||||
|
other.event_ = nullptr;
|
||||||
}
|
}
|
||||||
InlineEvent& operator=(InlineEvent&& other) noexcept {
|
InlineEvent& operator=(InlineEvent&& other) noexcept {
|
||||||
swap(std::move(other));
|
swap(other);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
void swap(InlineEvent&& other) {
|
void swap(InlineEvent& other) noexcept {
|
||||||
std::swap(event_, other.event_);
|
std::swap(event_, other.event_);
|
||||||
std::swap(backend_, other.backend_);
|
std::swap(backend_, other.backend_);
|
||||||
std::swap(device_type_, other.device_type_);
|
std::swap(device_type_, other.device_type_);
|
||||||
|
@ -51,7 +51,7 @@ struct C10_API PODLocalDispatchKeySet {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
static_assert(
|
static_assert(
|
||||||
std::is_trivial<PODLocalDispatchKeySet>::value,
|
std::is_trivial_v<PODLocalDispatchKeySet>,
|
||||||
"PODLocalDispatchKeySet must be a POD type.");
|
"PODLocalDispatchKeySet must be a POD type.");
|
||||||
|
|
||||||
struct C10_API LocalDispatchKeySet {
|
struct C10_API LocalDispatchKeySet {
|
||||||
|
@ -30,7 +30,7 @@ class C10_API SizesAndStrides {
|
|||||||
using strides_iterator = int64_t*;
|
using strides_iterator = int64_t*;
|
||||||
using strides_const_iterator = const int64_t*;
|
using strides_const_iterator = const int64_t*;
|
||||||
|
|
||||||
SizesAndStrides() : size_(1) {
|
SizesAndStrides() {
|
||||||
size_at_unchecked(0) = 0;
|
size_at_unchecked(0) = 0;
|
||||||
stride_at_unchecked(0) = 1;
|
stride_at_unchecked(0) = 1;
|
||||||
}
|
}
|
||||||
@ -297,7 +297,7 @@ class C10_API SizesAndStrides {
|
|||||||
memcpy(outOfLineStorage_, rhs.outOfLineStorage_, storageBytes(rhs.size_));
|
memcpy(outOfLineStorage_, rhs.outOfLineStorage_, storageBytes(rhs.size_));
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t size_;
|
size_t size_{1};
|
||||||
union {
|
union {
|
||||||
int64_t* outOfLineStorage_;
|
int64_t* outOfLineStorage_;
|
||||||
int64_t inlineStorage_[C10_SIZES_AND_STRIDES_MAX_INLINE_SIZE * 2]{};
|
int64_t inlineStorage_[C10_SIZES_AND_STRIDES_MAX_INLINE_SIZE * 2]{};
|
||||||
|
@ -11,11 +11,6 @@
|
|||||||
#include <c10/util/numa.h>
|
#include <c10/util/numa.h>
|
||||||
#include <c10/util/thread_name.h>
|
#include <c10/util/thread_name.h>
|
||||||
|
|
||||||
C10_CLANG_DIAGNOSTIC_PUSH()
|
|
||||||
#if C10_CLANG_HAS_WARNING("-Wshorten-64-to-32")
|
|
||||||
C10_CLANG_DIAGNOSTIC_IGNORE("-Wshorten-64-to-32")
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace c10 {
|
namespace c10 {
|
||||||
|
|
||||||
class C10_API TaskThreadPoolBase {
|
class C10_API TaskThreadPoolBase {
|
||||||
@ -43,7 +38,9 @@ class C10_API ThreadPool : public c10::TaskThreadPoolBase {
|
|||||||
protected:
|
protected:
|
||||||
struct task_element_t {
|
struct task_element_t {
|
||||||
bool run_with_id;
|
bool run_with_id;
|
||||||
|
// NOLINTNEXTLINE(cppcoreguidelines-avoid-const-or-ref-data-members)
|
||||||
const std::function<void()> no_id;
|
const std::function<void()> no_id;
|
||||||
|
// NOLINTNEXTLINE(cppcoreguidelines-avoid-const-or-ref-data-members)
|
||||||
const std::function<void(std::size_t)> with_id;
|
const std::function<void(std::size_t)> with_id;
|
||||||
|
|
||||||
explicit task_element_t(std::function<void()> f)
|
explicit task_element_t(std::function<void()> f)
|
||||||
@ -117,5 +114,3 @@ C10_DECLARE_SHARED_REGISTRY(
|
|||||||
bool);
|
bool);
|
||||||
|
|
||||||
} // namespace c10
|
} // namespace c10
|
||||||
|
|
||||||
C10_CLANG_DIAGNOSTIC_POP()
|
|
||||||
|
@ -65,10 +65,10 @@ constexpr bool is_pod_v = is_pod<T>::value;
|
|||||||
namespace guts {
|
namespace guts {
|
||||||
|
|
||||||
template <typename Base, typename Child, typename... Args>
|
template <typename Base, typename Child, typename... Args>
|
||||||
typename std::enable_if<
|
std::enable_if_t<
|
||||||
!std::is_array<Base>::value && !std::is_array<Child>::value &&
|
!std::is_array_v<Base> && !std::is_array_v<Child> &&
|
||||||
std::is_base_of<Base, Child>::value,
|
std::is_base_of_v<Base, Child>,
|
||||||
std::unique_ptr<Base>>::type
|
std::unique_ptr<Base>>
|
||||||
make_unique_base(Args&&... args) {
|
make_unique_base(Args&&... args) {
|
||||||
return std::unique_ptr<Base>(new Child(std::forward<Args>(args)...));
|
return std::unique_ptr<Base>(new Child(std::forward<Args>(args)...));
|
||||||
}
|
}
|
||||||
@ -188,17 +188,17 @@ CUDA_HOST_DEVICE constexpr decltype(auto) apply(F&& f, Tuple&& t) {
|
|||||||
#undef CUDA_HOST_DEVICE
|
#undef CUDA_HOST_DEVICE
|
||||||
|
|
||||||
template <typename Functor, typename... Args>
|
template <typename Functor, typename... Args>
|
||||||
typename std::enable_if<
|
std::enable_if_t<
|
||||||
std::is_member_pointer<typename std::decay<Functor>::type>::value,
|
std::is_member_pointer_v<std::decay_t<Functor>>,
|
||||||
typename c10::invoke_result_t<Functor, Args...>>::type
|
typename c10::invoke_result_t<Functor, Args...>>
|
||||||
invoke(Functor&& f, Args&&... args) {
|
invoke(Functor&& f, Args&&... args) {
|
||||||
return std::mem_fn(std::forward<Functor>(f))(std::forward<Args>(args)...);
|
return std::mem_fn(std::forward<Functor>(f))(std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Functor, typename... Args>
|
template <typename Functor, typename... Args>
|
||||||
typename std::enable_if<
|
std::enable_if_t<
|
||||||
!std::is_member_pointer<typename std::decay<Functor>::type>::value,
|
!std::is_member_pointer_v<std::decay_t<Functor>>,
|
||||||
typename c10::invoke_result_t<Functor, Args...>>::type
|
typename c10::invoke_result_t<Functor, Args...>>
|
||||||
invoke(Functor&& f, Args&&... args) {
|
invoke(Functor&& f, Args&&... args) {
|
||||||
return std::forward<Functor>(f)(std::forward<Args>(args)...);
|
return std::forward<Functor>(f)(std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
|
@ -438,16 +438,13 @@ C10_CLANG_DIAGNOSTIC_IGNORE("-Wimplicit-float-conversion")
|
|||||||
// `error: comparison of constant '255' with boolean expression is always false`
|
// `error: comparison of constant '255' with boolean expression is always false`
|
||||||
// for `f > limit::max()` below
|
// for `f > limit::max()` below
|
||||||
template <typename To, typename From>
|
template <typename To, typename From>
|
||||||
typename std::enable_if<std::is_same<From, bool>::value, bool>::type overflows(
|
std::enable_if_t<std::is_same_v<From, bool>, bool> overflows(From /*f*/) {
|
||||||
From /*f*/) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// skip isnan and isinf check for integral types
|
// skip isnan and isinf check for integral types
|
||||||
template <typename To, typename From>
|
template <typename To, typename From>
|
||||||
typename std::enable_if<
|
std::enable_if_t<std::is_integral_v<From> && !std::is_same_v<From, bool>, bool>
|
||||||
std::is_integral<From>::value && !std::is_same<From, bool>::value,
|
|
||||||
bool>::type
|
|
||||||
overflows(From f) {
|
overflows(From f) {
|
||||||
using limit = std::numeric_limits<typename scalar_value_type<To>::type>;
|
using limit = std::numeric_limits<typename scalar_value_type<To>::type>;
|
||||||
if (!limit::is_signed && std::numeric_limits<From>::is_signed) {
|
if (!limit::is_signed && std::numeric_limits<From>::is_signed) {
|
||||||
@ -462,8 +459,7 @@ overflows(From f) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename To, typename From>
|
template <typename To, typename From>
|
||||||
typename std::enable_if<std::is_floating_point<From>::value, bool>::type
|
std::enable_if_t<std::is_floating_point_v<From>, bool> overflows(From f) {
|
||||||
overflows(From f) {
|
|
||||||
using limit = std::numeric_limits<typename scalar_value_type<To>::type>;
|
using limit = std::numeric_limits<typename scalar_value_type<To>::type>;
|
||||||
if (limit::has_infinity && std::isinf(static_cast<double>(f))) {
|
if (limit::has_infinity && std::isinf(static_cast<double>(f))) {
|
||||||
return false;
|
return false;
|
||||||
@ -481,7 +477,7 @@ C10_CLANG_DIAGNOSTIC_POP()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
template <typename To, typename From>
|
template <typename To, typename From>
|
||||||
typename std::enable_if<is_complex<From>::value, bool>::type overflows(From f) {
|
std::enable_if_t<is_complex<From>::value, bool> overflows(From f) {
|
||||||
// casts from complex to real are considered to overflow if the
|
// casts from complex to real are considered to overflow if the
|
||||||
// imaginary component is non-zero
|
// imaginary component is non-zero
|
||||||
if (!is_complex<To>::value && f.imag() != 0) {
|
if (!is_complex<To>::value && f.imag() != 0) {
|
||||||
|
@ -101,7 +101,7 @@ namespace detail {
|
|||||||
template <class LambdaType, class FuncType>
|
template <class LambdaType, class FuncType>
|
||||||
struct is_stateless_lambda__ final {
|
struct is_stateless_lambda__ final {
|
||||||
static_assert(
|
static_assert(
|
||||||
!std::is_same<LambdaType, LambdaType>::value,
|
!std::is_same_v<LambdaType, LambdaType>,
|
||||||
"Base case shouldn't be hit");
|
"Base case shouldn't be hit");
|
||||||
};
|
};
|
||||||
// implementation idea: According to the C++ standard, stateless lambdas are
|
// implementation idea: According to the C++ standard, stateless lambdas are
|
||||||
@ -137,7 +137,7 @@ template <template <class> class C>
|
|||||||
struct is_type_condition<
|
struct is_type_condition<
|
||||||
C,
|
C,
|
||||||
std::enable_if_t<
|
std::enable_if_t<
|
||||||
std::is_same<bool, std::remove_cv_t<decltype(C<int>::value)>>::value>>
|
std::is_same_v<bool, std::remove_cv_t<decltype(C<int>::value)>>>>
|
||||||
: std::true_type {};
|
: std::true_type {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -13,13 +13,13 @@ namespace c10 {
|
|||||||
// information as well as the source of our implementations.
|
// information as well as the source of our implementations.
|
||||||
template <class To, class From>
|
template <class To, class From>
|
||||||
std::enable_if_t<
|
std::enable_if_t<
|
||||||
sizeof(To) == sizeof(From) && std::is_trivially_copyable<From>::value &&
|
sizeof(To) == sizeof(From) && std::is_trivially_copyable_v<From> &&
|
||||||
std::is_trivially_copyable<To>::value,
|
std::is_trivially_copyable_v<To>,
|
||||||
To>
|
To>
|
||||||
// constexpr support needs compiler magic
|
// constexpr support needs compiler magic
|
||||||
bit_cast(const From& src) noexcept {
|
bit_cast(const From& src) noexcept {
|
||||||
static_assert(
|
static_assert(
|
||||||
std::is_trivially_constructible<To>::value,
|
std::is_trivially_constructible_v<To>,
|
||||||
"This implementation additionally requires "
|
"This implementation additionally requires "
|
||||||
"destination type to be trivially constructible");
|
"destination type to be trivially constructible");
|
||||||
|
|
||||||
|
@ -168,13 +168,11 @@ struct alignas(sizeof(T) * 2) complex {
|
|||||||
// c10::complex<double>
|
// c10::complex<double>
|
||||||
template <typename U = T>
|
template <typename U = T>
|
||||||
C10_HOST_DEVICE explicit constexpr complex(
|
C10_HOST_DEVICE explicit constexpr complex(
|
||||||
const std::enable_if_t<std::is_same<U, float>::value, complex<double>>&
|
const std::enable_if_t<std::is_same_v<U, float>, complex<double>>& other)
|
||||||
other)
|
|
||||||
: real_(other.real_), imag_(other.imag_) {}
|
: real_(other.real_), imag_(other.imag_) {}
|
||||||
template <typename U = T>
|
template <typename U = T>
|
||||||
C10_HOST_DEVICE constexpr complex(
|
C10_HOST_DEVICE constexpr complex(
|
||||||
const std::enable_if_t<std::is_same<U, double>::value, complex<float>>&
|
const std::enable_if_t<std::is_same_v<U, double>, complex<float>>& other)
|
||||||
other)
|
|
||||||
: real_(other.real_), imag_(other.imag_) {}
|
: real_(other.real_), imag_(other.imag_) {}
|
||||||
|
|
||||||
constexpr complex<T>& operator=(T re) {
|
constexpr complex<T>& operator=(T re) {
|
||||||
@ -332,19 +330,19 @@ struct alignas(sizeof(T) * 2) complex {
|
|||||||
|
|
||||||
namespace complex_literals {
|
namespace complex_literals {
|
||||||
|
|
||||||
constexpr complex<float> operator"" _if(long double imag) {
|
constexpr complex<float> operator""_if(long double imag) {
|
||||||
return complex<float>(0.0f, static_cast<float>(imag));
|
return complex<float>(0.0f, static_cast<float>(imag));
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr complex<double> operator"" _id(long double imag) {
|
constexpr complex<double> operator""_id(long double imag) {
|
||||||
return complex<double>(0.0, static_cast<double>(imag));
|
return complex<double>(0.0, static_cast<double>(imag));
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr complex<float> operator"" _if(unsigned long long imag) {
|
constexpr complex<float> operator""_if(unsigned long long imag) {
|
||||||
return complex<float>(0.0f, static_cast<float>(imag));
|
return complex<float>(0.0f, static_cast<float>(imag));
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr complex<double> operator"" _id(unsigned long long imag) {
|
constexpr complex<double> operator""_id(unsigned long long imag) {
|
||||||
return complex<double>(0.0, static_cast<double>(imag));
|
return complex<double>(0.0, static_cast<double>(imag));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ namespace detail {
|
|||||||
template <
|
template <
|
||||||
typename I,
|
typename I,
|
||||||
bool one_sided = false,
|
bool one_sided = false,
|
||||||
typename std::enable_if<std::is_integral<I>::value, int>::type = 0>
|
std::enable_if_t<std::is_integral_v<I>, int> = 0>
|
||||||
struct integer_iterator {
|
struct integer_iterator {
|
||||||
using iterator_category = std::input_iterator_tag;
|
using iterator_category = std::input_iterator_tag;
|
||||||
using value_type = I;
|
using value_type = I;
|
||||||
@ -78,7 +78,7 @@ struct integer_iterator {
|
|||||||
template <
|
template <
|
||||||
typename I,
|
typename I,
|
||||||
bool one_sided = false,
|
bool one_sided = false,
|
||||||
typename std::enable_if<std::is_integral<I>::value, bool>::type = true>
|
std::enable_if_t<std::is_integral_v<I>, bool> = true>
|
||||||
struct integer_range {
|
struct integer_range {
|
||||||
public:
|
public:
|
||||||
integer_range(I begin, I end) : begin_(begin), end_(end) {}
|
integer_range(I begin, I end) : begin_(begin), end_(end) {}
|
||||||
@ -102,10 +102,8 @@ struct integer_range {
|
|||||||
template <
|
template <
|
||||||
typename Integer1,
|
typename Integer1,
|
||||||
typename Integer2,
|
typename Integer2,
|
||||||
typename std::enable_if<std::is_integral<Integer1>::value, bool>::type =
|
std::enable_if_t<std::is_integral_v<Integer1>, bool> = true,
|
||||||
true,
|
std::enable_if_t<std::is_integral_v<Integer2>, bool> = true>
|
||||||
typename std::enable_if<std::is_integral<Integer2>::value, bool>::type =
|
|
||||||
true>
|
|
||||||
integer_range<Integer2> irange(Integer1 begin, Integer2 end) {
|
integer_range<Integer2> irange(Integer1 begin, Integer2 end) {
|
||||||
// If end<=begin then the range is empty; we can achieve this effect by
|
// If end<=begin then the range is empty; we can achieve this effect by
|
||||||
// choosing the larger of {begin, end} as the loop terminator
|
// choosing the larger of {begin, end} as the loop terminator
|
||||||
@ -118,8 +116,7 @@ integer_range<Integer2> irange(Integer1 begin, Integer2 end) {
|
|||||||
/// If end<=begin, then the range is empty
|
/// If end<=begin, then the range is empty
|
||||||
template <
|
template <
|
||||||
typename Integer,
|
typename Integer,
|
||||||
typename std::enable_if<std::is_integral<Integer>::value, bool>::type =
|
std::enable_if_t<std::is_integral_v<Integer>, bool> = true>
|
||||||
true>
|
|
||||||
integer_range<Integer, true> irange(Integer end) {
|
integer_range<Integer, true> irange(Integer end) {
|
||||||
return {Integer(), end};
|
return {Integer(), end};
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ class basic_string_view final {
|
|||||||
|
|
||||||
static constexpr size_type npos = size_type(-1);
|
static constexpr size_type npos = size_type(-1);
|
||||||
|
|
||||||
constexpr basic_string_view() noexcept : begin_(nullptr), size_(0) {}
|
constexpr basic_string_view() noexcept : begin_(nullptr) {}
|
||||||
|
|
||||||
explicit constexpr basic_string_view(const_pointer str, size_type count)
|
explicit constexpr basic_string_view(const_pointer str, size_type count)
|
||||||
: begin_(str), size_(count) {}
|
: begin_(str), size_(count) {}
|
||||||
@ -580,7 +580,7 @@ inline std::basic_ostream<CharT>& operator<<(
|
|||||||
template <class CharT>
|
template <class CharT>
|
||||||
constexpr inline void swap(
|
constexpr inline void swap(
|
||||||
basic_string_view<CharT>& lhs,
|
basic_string_view<CharT>& lhs,
|
||||||
basic_string_view<CharT>& rhs) {
|
basic_string_view<CharT>& rhs) noexcept {
|
||||||
lhs.swap(rhs);
|
lhs.swap(rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,9 +1,12 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <array>
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <cstdlib>
|
#include <cstdint>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
#include <ostream>
|
||||||
|
#include <string>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@ -12,6 +15,7 @@
|
|||||||
#include <c10/util/IdWrapper.h>
|
#include <c10/util/IdWrapper.h>
|
||||||
#include <c10/util/TypeIndex.h>
|
#include <c10/util/TypeIndex.h>
|
||||||
#include <c10/util/TypeTraits.h>
|
#include <c10/util/TypeTraits.h>
|
||||||
|
#include <c10/util/string_view.h>
|
||||||
|
|
||||||
#include <c10/core/ScalarType.h>
|
#include <c10/core/ScalarType.h>
|
||||||
#include <c10/util/irange.h>
|
#include <c10/util/irange.h>
|
||||||
@ -175,19 +179,19 @@ inline void _PlacementNewNotDefault(void* /*ptr*/, size_t /*n*/) {
|
|||||||
|
|
||||||
template <
|
template <
|
||||||
typename T,
|
typename T,
|
||||||
std::enable_if_t<std::is_default_constructible<T>::value>* = nullptr>
|
std::enable_if_t<std::is_default_constructible_v<T>>* = nullptr>
|
||||||
inline constexpr TypeMetaData::PlacementNew* _PickPlacementNew() {
|
inline constexpr TypeMetaData::PlacementNew* _PickPlacementNew() {
|
||||||
return (c10::guts::is_fundamental<T>::value || std::is_pointer<T>::value)
|
return (c10::guts::is_fundamental<T>::value || std::is_pointer_v<T>)
|
||||||
? nullptr
|
? nullptr
|
||||||
: &_PlacementNew<T>;
|
: &_PlacementNew<T>;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <
|
template <
|
||||||
typename T,
|
typename T,
|
||||||
std::enable_if_t<!std::is_default_constructible<T>::value>* = nullptr>
|
std::enable_if_t<!std::is_default_constructible_v<T>>* = nullptr>
|
||||||
inline constexpr TypeMetaData::PlacementNew* _PickPlacementNew() {
|
inline constexpr TypeMetaData::PlacementNew* _PickPlacementNew() {
|
||||||
static_assert(
|
static_assert(
|
||||||
!c10::guts::is_fundamental<T>::value && !std::is_pointer<T>::value,
|
!c10::guts::is_fundamental<T>::value && !std::is_pointer_v<T>,
|
||||||
"this should have picked the other SFINAE case");
|
"this should have picked the other SFINAE case");
|
||||||
return &_PlacementNewNotDefault<T>;
|
return &_PlacementNewNotDefault<T>;
|
||||||
}
|
}
|
||||||
@ -206,14 +210,14 @@ inline void* _NewNotDefault() {
|
|||||||
|
|
||||||
template <
|
template <
|
||||||
typename T,
|
typename T,
|
||||||
std::enable_if_t<std::is_default_constructible<T>::value>* = nullptr>
|
std::enable_if_t<std::is_default_constructible_v<T>>* = nullptr>
|
||||||
inline constexpr TypeMetaData::New* _PickNew() {
|
inline constexpr TypeMetaData::New* _PickNew() {
|
||||||
return &_New<T>;
|
return &_New<T>;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <
|
template <
|
||||||
typename T,
|
typename T,
|
||||||
std::enable_if_t<!std::is_default_constructible<T>::value>* = nullptr>
|
std::enable_if_t<!std::is_default_constructible_v<T>>* = nullptr>
|
||||||
inline constexpr TypeMetaData::New* _PickNew() {
|
inline constexpr TypeMetaData::New* _PickNew() {
|
||||||
return &_NewNotDefault<T>;
|
return &_NewNotDefault<T>;
|
||||||
}
|
}
|
||||||
@ -240,21 +244,19 @@ inline void _CopyNotAllowed(const void* /*src*/, void* /*dst*/, size_t /*n*/) {
|
|||||||
" does not allow assignment.");
|
" does not allow assignment.");
|
||||||
}
|
}
|
||||||
|
|
||||||
template <
|
template <typename T, std::enable_if_t<std::is_copy_assignable_v<T>>* = nullptr>
|
||||||
typename T,
|
|
||||||
std::enable_if_t<std::is_copy_assignable<T>::value>* = nullptr>
|
|
||||||
inline constexpr TypeMetaData::Copy* _PickCopy() {
|
inline constexpr TypeMetaData::Copy* _PickCopy() {
|
||||||
return (c10::guts::is_fundamental<T>::value || std::is_pointer<T>::value)
|
return (c10::guts::is_fundamental<T>::value || std::is_pointer_v<T>)
|
||||||
? nullptr
|
? nullptr
|
||||||
: &_Copy<T>;
|
: &_Copy<T>;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <
|
template <
|
||||||
typename T,
|
typename T,
|
||||||
std::enable_if_t<!std::is_copy_assignable<T>::value>* = nullptr>
|
std::enable_if_t<!std::is_copy_assignable_v<T>>* = nullptr>
|
||||||
inline constexpr TypeMetaData::Copy* _PickCopy() {
|
inline constexpr TypeMetaData::Copy* _PickCopy() {
|
||||||
static_assert(
|
static_assert(
|
||||||
!c10::guts::is_fundamental<T>::value && !std::is_pointer<T>::value,
|
!c10::guts::is_fundamental<T>::value && !std::is_pointer_v<T>,
|
||||||
"this should have picked the other SFINAE case");
|
"this should have picked the other SFINAE case");
|
||||||
return &_CopyNotAllowed<T>;
|
return &_CopyNotAllowed<T>;
|
||||||
}
|
}
|
||||||
@ -272,7 +274,7 @@ inline void _PlacementDelete(void* ptr, size_t n) {
|
|||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline constexpr TypeMetaData::PlacementDelete* _PickPlacementDelete() {
|
inline constexpr TypeMetaData::PlacementDelete* _PickPlacementDelete() {
|
||||||
return (c10::guts::is_fundamental<T>::value || std::is_pointer<T>::value)
|
return (c10::guts::is_fundamental<T>::value || std::is_pointer_v<T>)
|
||||||
? nullptr
|
? nullptr
|
||||||
: &_PlacementDelete<T>;
|
: &_PlacementDelete<T>;
|
||||||
}
|
}
|
||||||
@ -299,7 +301,7 @@ class _Uninitialized final {};
|
|||||||
//
|
//
|
||||||
|
|
||||||
// item sizes for TypeMeta::itemsize() fast path
|
// item sizes for TypeMeta::itemsize() fast path
|
||||||
static constexpr uint8_t scalarTypeItemSizes[NumScalarTypes] = {
|
static constexpr std::array<uint8_t, NumScalarTypes> scalarTypeItemSizes = {
|
||||||
#define SCALAR_TYPE_SIZE(T, name) sizeof(T),
|
#define SCALAR_TYPE_SIZE(T, name) sizeof(T),
|
||||||
AT_FORALL_SCALAR_TYPES_WITH_COMPLEX_AND_QINTS(SCALAR_TYPE_SIZE)
|
AT_FORALL_SCALAR_TYPES_WITH_COMPLEX_AND_QINTS(SCALAR_TYPE_SIZE)
|
||||||
#undef SCALAR_TYPE_SIZE
|
#undef SCALAR_TYPE_SIZE
|
||||||
@ -693,7 +695,7 @@ template <class T>
|
|||||||
class _guard_long_unique_dummy final {};
|
class _guard_long_unique_dummy final {};
|
||||||
template <class T>
|
template <class T>
|
||||||
using _guard_long_unique = std::conditional_t<
|
using _guard_long_unique = std::conditional_t<
|
||||||
std::is_same<long, int32_t>::value || std::is_same<long, int64_t>::value,
|
std::is_same_v<long, int32_t> || std::is_same_v<long, int64_t>,
|
||||||
_guard_long_unique_dummy<T>,
|
_guard_long_unique_dummy<T>,
|
||||||
T>;
|
T>;
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
Reference in New Issue
Block a user