Skip to content

Commit 830021b

Browse files
committed
use auto in intermediate expr
1 parent 87e1fad commit 830021b

File tree

180 files changed

+1217
-1024
lines changed

Some content is hidden

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

180 files changed

+1217
-1024
lines changed

paddle/phi/kernels/cpu/add_position_encoding_kernel.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,9 @@ void AddPositionEncodingKernel(const Context& dev_ctx,
7676

7777
const int half_size = enc_size / 2;
7878
for (int i = 0; i < batch_size; ++i) {
79-
const int max_length =
80-
x_lod.empty() ? max_seq_len : x_lod[0][i + 1] - x_lod[0][i];
79+
const auto max_length(x_lod.empty() ? max_seq_len
80+
: x_lod[0][i + 1] - x_lod[0][i]);
81+
8182
for (int j = 0; j < max_length; ++j) {
8283
for (int k = 0; k < half_size; ++k) {
8384
const double val =

paddle/phi/kernels/cpu/batch_norm_grad_kernel.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ void BatchNormGradFunctor(const Context& dev_ctx,
181181
bias_arr.setZero();
182182
}
183183

184-
int scale_coeff = use_global_stats ? 1 : N * sample_size;
184+
auto scale_coeff = use_global_stats ? 1 : N * sample_size;
185185
const auto scale_inv_var_nhw = scale_arr * inv_var_arr / scale_coeff;
186186

187187
DenseTensor dy_sum;

paddle/phi/kernels/cpu/box_coder_kernel.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ void DecodeCenterSize(const DenseTensor *target_box,
120120
std::array<T, 4> var_data{1., 1., 1., 1.};
121121
T *var_ptr = var_data.data();
122122
size_t offset = i * col * len + j * len;
123-
int prior_box_offset = axis == 0 ? j * len : i * len;
123+
auto prior_box_offset = axis == 0 ? j * len : i * len;
124124

125125
T prior_box_width = prior_box_data[prior_box_offset + 2] -
126126
prior_box_data[prior_box_offset] +
@@ -135,7 +135,7 @@ void DecodeCenterSize(const DenseTensor *target_box,
135135

136136
T target_box_center_x = 0, target_box_center_y = 0;
137137
T target_box_width = 0, target_box_height = 0;
138-
int prior_var_offset = axis == 0 ? j * len : i * len;
138+
auto prior_var_offset = axis == 0 ? j * len : i * len;
139139
if (var_size == 2) {
140140
std::memcpy(var_ptr,
141141
prior_box_var->data<T>() + prior_var_offset,

paddle/phi/kernels/cpu/broadcast_tensors_grad_kernel.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ void BroadcastTensorsGradKernel(const Context& dev_ctx,
112112
std::vector<int> reduce_dims_vec;
113113
std::vector<int> reshape_dims_vec;
114114
for (int j = 0; j < in_rank; j++) {
115-
int out_axis = out_rank - j - 1;
116-
int in_axis = in_rank - j - 1;
115+
auto out_axis = out_rank - j - 1;
116+
auto in_axis = in_rank - j - 1;
117117

118118
reshape_dims_vec.push_back(static_cast<int>(input_dims[j]));
119119
if (out_axis < 0 || output_dims[out_axis] != input_dims[in_axis]) {

paddle/phi/kernels/cpu/conv_util.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,9 @@ inline int ConvOutSize(int input_size,
7777
int pad_left,
7878
int pad_right,
7979
int stride) {
80-
const int dkernel = dilation * (filter_size - 1) + 1;
81-
int output_size =
80+
const auto dkernel(dilation * (filter_size - 1) + 1);
81+
82+
auto output_size =
8283
(input_size + (pad_left + pad_right) - dkernel) / stride + 1;
8384

8485
PADDLE_ENFORCE_GT(

paddle/phi/kernels/cpu/cross_entropy_grad_kernel.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ void CrossEntropyWithSoftmaxGradCPUKernel(const CPUContext& dev_ctx,
9595
const int remain = d / axis_dim;
9696
for (int i = 0; i < n; ++i) { // for each sample_1_dim
9797
for (int j = 0; j < remain; j++) { // for each sample_other_dims
98-
int idx = i * remain + j; // this sample's label_idx. for 1d case,
99-
// remain=1 and j=0, so, idx = i
98+
auto idx = i * remain + j; // this sample's label_idx. for 1d case,
99+
// remain=1 and j=0, so, idx = i
100100
auto lbl = static_cast<int64_t>(label_data[idx]); // NOLINT
101101
if (lbl == ignore_index) {
102102
for (int k = 0; k < axis_dim; ++k) { // for each class id's label
@@ -147,8 +147,8 @@ void CrossEntropyWithSoftmaxGradCPUKernel(const CPUContext& dev_ctx,
147147
const int remain = d / axis_dim;
148148
for (int i = 0; i < n; ++i) { // for each sample_1_dim
149149
for (int j = 0; j < remain; j++) { // for each sample_other_dims
150-
int idx = i * remain + j; // this sample's label_idx. for 1d case,
151-
// remain=1 and j=0, so, idx = i
150+
auto idx = i * remain + j; // this sample's label_idx. for 1d case,
151+
// remain=1 and j=0, so, idx = i
152152
auto lbl = static_cast<int64_t>(label_data[idx]); // NOLINT
153153
if (lbl == ignore_index) {
154154
for (int k = 0; k < axis_dim; ++k) { // for each class id's label

paddle/phi/kernels/cpu/distribute_fpn_proposals_kernel.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ void DistributeFpnProposalsKernel(
3333
std::vector<DenseTensor*> multi_fpn_rois,
3434
std::vector<DenseTensor*> multi_level_rois_num,
3535
DenseTensor* restore_index) {
36-
const int num_level = max_level - min_level + 1;
36+
const auto num_level(max_level - min_level + 1);
3737

3838
// check that the fpn_rois is not empty
3939
if (!rois_num.get_ptr()) {

paddle/phi/kernels/cpu/lookup_table_dequant_kernel.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ void LookupTableDequantKernel(const Context &dev_ctx,
8282
ids[i]));
8383
float min = *(table + ids[i] * quant_number);
8484
float max = *(table + ids[i] * quant_number + 1);
85-
int offset = ids[i] * quant_number + 2;
85+
auto offset = ids[i] * quant_number + 2;
8686
const unsigned char *tensor_buf =
8787
reinterpret_cast<const unsigned char *>(table + offset);
8888
dequant(

paddle/phi/kernels/cpu/lrn_kernel.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ struct LRNFunctor<phi::CPUContext, T> {
9191
}
9292
for (int c = 1; c < C; ++c) {
9393
// copy previous scale
94-
int mid_offset = i * fea_size + c * img_size;
94+
auto mid_offset = i * fea_size + c * img_size;
9595
std::memcpy(mdata + mid_offset,
9696
mdata + mid_offset - img_size,
9797
img_size * sizeof(T));

paddle/phi/kernels/cpu/matrix_rank_tol_kernel.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void LapackSVD(const T* x_data,
4242
int mn = std::min(rows, cols);
4343
T* a = const_cast<T*>(x_data); // NOLINT
4444
int lda = rows;
45-
int lwork = 3 * mn + std::max(mx, 7 * mn);
45+
auto lwork = 3 * mn + std::max(mx, 7 * mn);
4646
std::vector<phi::dtype::Real<T>> rwork(
4747
std::max(5 * mn * mn + 5 * mn, 2 * mx * mn + 2 * mn * mn + mn));
4848
std::vector<T> work(lwork);

0 commit comments

Comments
 (0)