Skip to content

Commit 2ea394b

Browse files
cyyeverpytorchmergebot
authored andcommitted
Modernize C++ code (pytorch#144603)
Fixes #ISSUE_NUMBER Pull Request resolved: pytorch#144603 Approved by: https://github.com/malfet
1 parent c3fcb36 commit 2ea394b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+142
-149
lines changed

aten/src/ATen/core/boxing/impl/boxing.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ torch::jit::Stack boxArgs(Args... args) {
9191
template <class T>
9292
inline constexpr size_t boxed_size_one() {
9393
static_assert(
94-
!std::is_same<std::decay_t<T>, c10::TensorOptions>::value,
94+
!std::is_same_v<std::decay_t<T>, c10::TensorOptions>,
9595
"need to patch this path to support TensorOptions passed by reference");
9696
return 1;
9797
}

aten/src/ATen/core/boxing/impl/make_boxed_from_unboxed_functor.h

+10-12
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ template <class T, bool AllowDeprecatedTypes>
226226
struct assert_is_valid_input_type<
227227
T,
228228
AllowDeprecatedTypes,
229-
std::enable_if_t<std::is_same<std::vector<bool>, T>::value>> {
229+
std::enable_if_t<std::is_same_v<std::vector<bool>, T>>> {
230230
static_assert(
231231
guts::false_t<T>::value,
232232
"You tried to register a kernel with an unsupported input type: vector<bool>. Please use List<bool> instead.");
@@ -363,7 +363,7 @@ template <class T, bool AllowDeprecatedTypes>
363363
struct assert_is_valid_output_type<
364364
T,
365365
AllowDeprecatedTypes,
366-
std::enable_if_t<std::is_same<std::vector<bool>, T>::value>> {
366+
std::enable_if_t<std::is_same_v<std::vector<bool>, T>>> {
367367
static_assert(
368368
guts::false_t<T>::value,
369369
"You tried to register a kernel with an unsupported output type: vector<bool>. Please use List<bool> instead.");
@@ -546,16 +546,15 @@ struct wrap_kernel_functor_unboxed_<
546546
ReturnType(ParameterTypes...)>
547547
final {
548548
static_assert(
549-
std::is_same<
549+
std::is_same_v<
550550
ReturnType,
551-
typename guts::infer_function_traits_t<KernelFunctor>::return_type>::
552-
value,
551+
typename guts::infer_function_traits_t<KernelFunctor>::return_type>,
553552
"Return type mismatch");
554553
static_assert(
555-
std::is_same<
554+
std::is_same_v<
556555
guts::typelist::typelist<ParameterTypes...>,
557556
typename guts::infer_function_traits_t<
558-
KernelFunctor>::parameter_types>::value,
557+
KernelFunctor>::parameter_types>,
559558
"Parameter types mismatch");
560559

561560
// See [Note: Argument forwarding in the dispatcher] for why ParameterTypes
@@ -588,16 +587,15 @@ struct wrap_kernel_functor_unboxed_<
588587
ReturnType(DispatchKeySet, ParameterTypes...)>
589588
final {
590589
static_assert(
591-
std::is_same<
590+
std::is_same_v<
592591
ReturnType,
593-
typename guts::infer_function_traits_t<KernelFunctor>::return_type>::
594-
value,
592+
typename guts::infer_function_traits_t<KernelFunctor>::return_type>,
595593
"Return type mismatch");
596594
static_assert(
597-
std::is_same<
595+
std::is_same_v<
598596
guts::typelist::typelist<DispatchKeySet, ParameterTypes...>,
599597
typename guts::infer_function_traits_t<
600-
KernelFunctor>::parameter_types>::value,
598+
KernelFunctor>::parameter_types>,
601599
"Parameter types mismatch");
602600

603601
// See [Note: Argument forwarding in the dispatcher] for why ParameterTypes

aten/src/ATen/core/op_registration/infer_schema.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ template <class... Types>
3434
constexpr int checkStaticTypes() {
3535
// Give nice error messages for some of the common error cases.
3636
// Use a LOUD ERROR MESSAGE SO USERS SEE THE STATIC_ASSERT
37-
static_assert(std::conjunction<
37+
static_assert(std::conjunction_v<
3838
bool_t<!std::is_integral_v<Types> || std::is_same_v<Types, int8_t> || std::is_same_v<Types, int64_t> || std::is_same_v<Types, bool>>...
39-
>::value, "INVALID TYPE: Only int8_t, int64_t and bool are supported as an integral argument type");
40-
static_assert(std::conjunction<
39+
>, "INVALID TYPE: Only int8_t, int64_t and bool are supported as an integral argument type");
40+
static_assert(std::conjunction_v<
4141
bool_t<!std::is_same_v<Types, float>>...
42-
>::value, "INVALID TYPE: float is not supported as an argument type, use double instead");
42+
>, "INVALID TYPE: float is not supported as an argument type, use double instead");
4343
return 0;
4444
}
4545

aten/src/ATen/core/op_registration/op_registration.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ void build_feature_required_feature_not_available(const char* feature) {
1616
}
1717
} // namespace impl
1818

19-
static_assert(std::is_nothrow_move_constructible<
20-
std::optional<RegistrationHandleRAII>>::value);
21-
static_assert(std::is_nothrow_move_assignable<
22-
std::optional<RegistrationHandleRAII>>::value);
19+
static_assert(std::is_nothrow_move_constructible_v<
20+
std::optional<RegistrationHandleRAII>>);
21+
static_assert(std::is_nothrow_move_assignable_v<
22+
std::optional<RegistrationHandleRAII>>);
2323

2424
void RegisterOperators::checkSchemaAndRegisterOp_(Options&& options) {
2525
TORCH_CHECK(

aten/src/ATen/core/op_registration/op_registration.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -330,9 +330,9 @@ class TORCH_API RegisterOperators final {
330330
// enable_if: only enable it if Lambda is a functor (note: lambdas are functors)
331331
std::enable_if_t<
332332
guts::is_functor<std::decay_t<Lambda>>::value
333-
&& !std::is_same<typename guts::infer_function_traits_t<std::decay_t<Lambda>>::func_type, KernelFunction::BoxedKernelFunction>::value,
333+
&& !std::is_same_v<typename guts::infer_function_traits_t<std::decay_t<Lambda>>::func_type, KernelFunction::BoxedKernelFunction>,
334334
Options&&> kernel(DispatchKey dispatch_key, Lambda&& functor) && {
335-
static_assert(!std::is_base_of<OperatorKernel, std::decay_t<Lambda>>::value, "The kernel(x) API for registering a kernel is only meant to be used with lambdas. Your kernel is a functor. Please use the kernel<Functor>() API instead.");
335+
static_assert(!std::is_base_of_v<OperatorKernel, std::decay_t<Lambda>>, "The kernel(x) API for registering a kernel is only meant to be used with lambdas. Your kernel is a functor. Please use the kernel<Functor>() API instead.");
336336

337337
// We don't support stateful lambdas (i.e. lambdas with a capture), because their
338338
// behavior would be nonobvious. A functor kernel with cache gets a new instance of
@@ -371,9 +371,9 @@ class TORCH_API RegisterOperators final {
371371
// enable_if: only enable it if Lambda is a functor (note: lambdas are functors)
372372
std::enable_if_t<
373373
guts::is_functor<std::decay_t<Lambda>>::value
374-
&& !std::is_same<typename guts::infer_function_traits_t<std::decay_t<Lambda>>::func_type, KernelFunction::BoxedKernelFunction>::value,
374+
&& !std::is_same_v<typename guts::infer_function_traits_t<std::decay_t<Lambda>>::func_type, KernelFunction::BoxedKernelFunction>,
375375
Options&&> catchAllKernel(Lambda&& lambda) && {
376-
static_assert(!std::is_base_of<OperatorKernel, std::decay_t<Lambda>>::value, "The kernel(x) API for registering a kernel is only meant to be used with lambdas. Your kernel is a functor. Please use the kernel<Functor>() API instead.");
376+
static_assert(!std::is_base_of_v<OperatorKernel, std::decay_t<Lambda>>, "The kernel(x) API for registering a kernel is only meant to be used with lambdas. Your kernel is a functor. Please use the kernel<Functor>() API instead.");
377377

378378
// We don't support stateful lambdas (i.e. lambdas with a capture), because their
379379
// behavior would be nonobvious.

aten/src/ATen/cpu/vec/sve/vec_common_sve.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
#include <ATen/cpu/vec/sve/vec_qint.h>
1616
#endif
1717

18-
namespace at {
19-
namespace vec {
18+
19+
namespace at::vec {
2020
// Note [CPU_CAPABILITY namespace]
2121
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2222
// This header, and all of its subheaders, will be compiled with
@@ -173,4 +173,4 @@ inline deinterleave2<float>(const Vectorized<float>& a, const Vectorized<float>&
173173

174174
#endif // defined(CPU_CAPABILITY_SVE)
175175

176-
}}}
176+
}}

aten/src/ATen/cpu/vec/sve/vec_double.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
#else
1111
#define USE_SLEEF(sleef_code, non_sleef_code) non_sleef_code
1212
#endif
13-
namespace at {
14-
namespace vec {
13+
14+
namespace at::vec {
1515
// Note [CPU_CAPABILITY namespace]
1616
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1717
// This header, and all of its subheaders, will be compiled with
@@ -505,4 +505,4 @@ Vectorized<double> inline fmadd(const Vectorized<double>& a, const Vectorized<do
505505

506506
#endif // defined(CPU_CAPABILITY_SVE)
507507

508-
}}}
508+
}}

aten/src/ATen/cpu/vec/sve/vec_float.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
#else
1111
#define USE_SLEEF(sleef_code, non_sleef_code) non_sleef_code
1212
#endif
13-
namespace at {
14-
namespace vec {
13+
14+
namespace at::vec {
1515
// Note [CPU_CAPABILITY namespace]
1616
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1717
// This header, and all of its subheaders, will be compiled with
@@ -570,4 +570,4 @@ Vectorized<float> inline fmadd(const Vectorized<float>& a, const Vectorized<floa
570570

571571
#endif // defined(CPU_CAPABILITY_SVE)
572572

573-
}}}
573+
}}

aten/src/ATen/cpu/vec/sve/vec_int.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
#include <ATen/cpu/vec/vec_base.h>
55
#include <ATen/cpu/vec/sve/sve_helper.h>
66

7-
namespace at {
8-
namespace vec {
7+
8+
namespace at::vec {
99
// Note [CPU_CAPABILITY namespace]
1010
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1111
// This header, and all of its subheaders, will be compiled with
@@ -407,4 +407,4 @@ Vectorized<int8_t> inline operator>>(const Vectorized<int8_t>& a, const Vectoriz
407407

408408
#endif // defined(CPU_CAPABILITY_SVE)
409409

410-
}}}
410+
}}

aten/src/ATen/cpu/vec/sve/vec_qint.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
// point operations will be carried out in a loop over Vectorized<T>::float_num_vecs
3636
// iterations.
3737

38-
namespace at {
39-
namespace vec {
38+
39+
namespace at::vec {
4040
// Note [CPU_CAPABILITY namespace]
4141
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4242
// This header, and all of its subheaders, will be compiled with
@@ -564,4 +564,4 @@ Vectorized<c10::quint8> inline maximum(const Vectorized<c10::quint8>& a, const V
564564

565565
#endif // defined(CPU_CAPABILITY_SVE)
566566

567-
}}}
567+
}}

aten/src/ATen/cpu/vec/vec512/vec512_bfloat16.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
#include <sleef.h>
1313
#endif
1414

15-
namespace at {
16-
namespace vec {
15+
16+
namespace at::vec {
1717
// See Note [CPU_CAPABILITY namespace]
1818
inline namespace CPU_CAPABILITY {
1919

@@ -1670,4 +1670,4 @@ LOAD_FP32_NON_VECTORIZED_INIT(BFloat16, bf16)
16701670
LOAD_FP32_NON_VECTORIZED_INIT(Half, fp16)
16711671

16721672
#endif
1673-
}}}
1673+
}}

aten/src/ATen/cpu/vec/vec512/vec512_complex_double.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
#include <sleef.h>
1313
#endif
1414

15-
namespace at {
16-
namespace vec {
15+
16+
namespace at::vec {
1717
// See Note [CPU_CAPABILITY namespace]
1818
inline namespace CPU_CAPABILITY {
1919

@@ -512,4 +512,4 @@ inline Vectorized<c10::complex<double>> Vectorized<c10::complex<double>>::ne(con
512512

513513
#endif
514514

515-
}}}
515+
}}

aten/src/ATen/cpu/vec/vec512/vec512_complex_float.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
#include <sleef.h>
1313
#endif
1414

15-
namespace at {
16-
namespace vec {
15+
16+
namespace at::vec {
1717
// See Note [CPU_CAPABILITY namespace]
1818
inline namespace CPU_CAPABILITY {
1919

@@ -1018,4 +1018,4 @@ inline Vectorized<c10::complex<float>> Vectorized<c10::complex<float>>::ne(
10181018

10191019
#endif
10201020

1021-
}}}
1021+
}}

aten/src/ATen/cpu/vec/vec512/vec512_double.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
#include <sleef.h>
1212
#endif
1313

14-
namespace at {
15-
namespace vec {
14+
15+
namespace at::vec {
1616
// See Note [CPU_CAPABILITY namespace]
1717
inline namespace CPU_CAPABILITY {
1818

@@ -472,4 +472,4 @@ Vectorized<double> inline fmsub(const Vectorized<double>& a, const Vectorized<do
472472

473473
#endif
474474

475-
}}}
475+
}}

aten/src/ATen/cpu/vec/vec512/vec512_float.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
#include <sleef.h>
1212
#endif
1313

14-
namespace at {
15-
namespace vec {
14+
15+
namespace at::vec {
1616
// See Note [CPU_CAPABILITY namespace]
1717
inline namespace CPU_CAPABILITY {
1818

@@ -717,4 +717,4 @@ inline void transpose_mxn(const float* src, int64_t ld_src, float* dst, int64_t
717717

718718
#endif
719719

720-
}}}
720+
}}

aten/src/ATen/cpu/vec/vec512/vec512_int.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
#include <c10/macros/Macros.h>
99
#include <c10/util/irange.h>
1010

11-
namespace at {
12-
namespace vec {
11+
12+
namespace at::vec {
1313
inline namespace CPU_CAPABILITY {
1414

1515
#ifdef CPU_CAPABILITY_AVX512
@@ -1462,4 +1462,4 @@ Vectorized<uint8_t> inline operator>>(const Vectorized<uint8_t>& a, const Vector
14621462

14631463
#endif
14641464

1465-
}}}
1465+
}}

aten/src/ATen/cuda/detail/LazyNVRTC.cpp

+4-6
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
#include <ATen/DynamicLibrary.h>
55
#include <stdexcept>
66

7-
namespace at {
8-
namespace cuda {
9-
namespace detail {
7+
8+
9+
namespace at::cuda::detail {
1010
namespace _stubs {
1111

1212
at::DynamicLibrary& getCUDALibrary() {
@@ -293,6 +293,4 @@ NVRTC lazyNVRTC = {
293293
AT_FORALL_NVRTC(_REFERENCE_MEMBER)
294294
#undef _REFERENCE_MEMBER
295295
};
296-
} // namespace detail
297-
} // namespace cuda
298-
} // namespace at
296+
} // namespace at::cuda::detail

aten/src/ATen/native/TensorShape.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -2456,8 +2456,8 @@ Tensor index_select_sparse_cpu(
24562456
// src is a source of indices to binary search in sorted
24572457
Tensor sorted, sorted_idx, src;
24582458
std::tie(sorted, sorted_idx, src) =
2459-
[&dim_indices, &nneg_index, &self, search_in_dim_indices, dim, nnz](
2460-
void) -> std::tuple<Tensor, Tensor, Tensor> {
2459+
[&dim_indices, &nneg_index, &self, search_in_dim_indices, dim, nnz]()
2460+
-> std::tuple<Tensor, Tensor, Tensor> {
24612461
// sort dim_indices to binary search into it
24622462
if (search_in_dim_indices) {
24632463
// dim_indices is already sorted if self is coalesced and dim == 0

aten/src/ATen/native/UpSample.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22

3-
#include <math.h>
3+
#include <cmath>
44

55
#include <ATen/OpMathType.h>
66
#include <ATen/TensorUtils.h>

aten/src/ATen/native/ao_sparse/quantized/cpu/fbgemm_utils.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
#include <fbgemm/FbgemmSparse.h>
99
#include <ATen/native/ao_sparse/quantized/cpu/packed_params.h>
1010

11-
namespace ao {
12-
namespace sparse {
11+
12+
namespace ao::sparse {
1313

1414
struct TORCH_API PackedLinearWeight
1515
: public LinearPackedParamsBase {
@@ -86,7 +86,7 @@ struct TORCH_API PackedLinearWeight
8686
int64_t output_zero_point);
8787
};
8888

89-
}} // namespace ao::sparse
89+
} // namespace ao::sparse
9090

9191
#endif // USE_FBGEMM
9292

aten/src/ATen/native/metal/MetalTensorImplStorage.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class MetalTensorImplStorage final {
88
class Impl;
99

1010
public:
11-
MetalTensorImplStorage(){};
11+
MetalTensorImplStorage() = default;
1212
MetalTensorImplStorage(const std::vector<int64_t>& sizes);
1313
MetalTensorImplStorage(
1414
const std::vector<int64_t>& sizes,

aten/src/ATen/native/mkl/LinearAlgebra.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
C10_DIAGNOSTIC_PUSH_AND_IGNORED_IF_DEFINED("-Wunused-parameter")
66
#if !AT_MKL_ENABLED()
77

8-
namespace at { namespace native {
8+
namespace at::native {
99

1010
void mkl_gemm_batched(
1111
const TransposeType trans_A, const TransposeType trans_B,
@@ -55,7 +55,7 @@ void mkl_gemm_f16f16f32(
5555
TORCH_INTERNAL_ASSERT(false, "mkl_gemm_f16f16f32: ATen not compiled with MKL support");
5656
}
5757

58-
}}
58+
}
5959

6060
#else // AT_MKL_ENABLED
6161

0 commit comments

Comments
 (0)