Skip to content

Commit dcbca53

Browse files
jerryzh168facebook-github-bot
authored andcommitted
Renaming size() to numel() - 1/6
Summary: Codemod generated with clangr shard mode, 50 files per diff Reviewed By: li-roy Differential Revision: D10866373 fbshipit-source-id: 589194164d4fea93b74d83fa7fc4c59558c41f4a
1 parent b1cf3ad commit dcbca53

Some content is hidden

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

41 files changed

+188
-188
lines changed

caffe2/ideep/operators/concat_split_op.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class IDEEPSplitOp final : public IDEEPOperator {
9898
"If you set split with an input blob, do not pass in "
9999
"split in the argument.");
100100
auto& axis_info = OperatorBase::Input<Tensor>(AXIS_INFO, CPU);
101-
CAFFE_ENFORCE_EQ(axis_info.size(), OutputSize());
101+
CAFFE_ENFORCE_EQ(axis_info.numel(), OutputSize());
102102
auto* axis_data = axis_info.template data<int>();
103103
axis_vdata.assign(axis_data, axis_data + OutputSize());
104104
} else if (axis_offset_.size() == 0) {

caffe2/ideep/operators/momentum_sgd_op.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class IDEEPMomentumSGDOp final : public IDEEPOperator {
5555

5656
// TODO: Use itensor after 0-dim is supported. Now use CPU tensor.
5757
const auto& lr = OperatorBase::Input<TensorCPU>(LR, CPU);
58-
CAFFE_ENFORCE(lr.size() == 1);
58+
CAFFE_ENFORCE(lr.numel() == 1);
5959

6060
momentum_sgd_update(
6161
Input(GRAD).get_nelems(),
@@ -97,7 +97,7 @@ class IDEEPMomentumSGDUpdateOp final : public IDEEPOperator {
9797

9898
// TODO: Use itensor after 0-dim is supported. Now use CPU tensor.
9999
const auto& lr = OperatorBase::Input<TensorCPU>(LR, CPU);
100-
CAFFE_ENFORCE(lr.size() == 1);
100+
CAFFE_ENFORCE(lr.numel() == 1);
101101

102102
momentum_sgd_update(
103103
Input(GRAD).get_nelems(),

caffe2/mpi/mpi_gpu_test.cc

+14-14
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ TEST(MPITest, TestMPIBroadcast) {
6666
// Let's test the value.
6767
auto& X = ws.GetBlob("X")->Get<Tensor>();
6868
Tensor X_cpu(X, CPU);
69-
EXPECT_EQ(X.size(), 10);
70-
for (int i = 0; i < X.size(); ++i) {
69+
EXPECT_EQ(X.numel(), 10);
70+
for (int i = 0; i < X.numel(); ++i) {
7171
EXPECT_EQ(X_cpu.data<float>()[i], root);
7272
}
7373
}
@@ -132,10 +132,10 @@ TEST(MPITest, TestMPIReduce) {
132132
if (rank == root) {
133133
// Let's test the value.
134134
auto& X = ws.GetBlob("X_reduced")->Get<TensorCUDA>();
135-
EXPECT_EQ(X.size(), 10);
135+
EXPECT_EQ(X.numel(), 10);
136136
int expected_result = size * (size - 1) / 2;
137137
Tensor X_cpu(X, CPU);
138-
for (int i = 0; i < X.size(); ++i) {
138+
for (int i = 0; i < X.numel(); ++i) {
139139
EXPECT_EQ(X_cpu.data<float>()[i], expected_result);
140140
}
141141
}
@@ -192,16 +192,16 @@ TEST(MPITest, TestMPIAllgather) {
192192
// Let's test the value.
193193
auto& X = ws.GetBlob("X")->Get<TensorCUDA>();
194194
Tensor X_cpu(X, CPU);
195-
EXPECT_EQ(X.size(), 20);
196-
for (int i = 0; i < X.size(); ++i) {
195+
EXPECT_EQ(X.numel(), 20);
196+
for (int i = 0; i < X.numel(); ++i) {
197197
EXPECT_EQ(X_cpu.data<float>()[i], rank);
198198
}
199199
auto& X_gathered = ws.GetBlob("X_gathered")->Get<TensorCUDA>();
200-
EXPECT_EQ(X_gathered.size(), 20 * size);
200+
EXPECT_EQ(X_gathered.numel(), 20 * size);
201201
EXPECT_EQ(X_gathered.dim(0), 2 * size);
202202
EXPECT_EQ(X_gathered.dim(1), 10);
203203
Tensor X_gathered_cpu(X_gathered, CPU);
204-
for (int i = 0; i < X_gathered.size(); ++i) {
204+
for (int i = 0; i < X_gathered.numel(); ++i) {
205205
EXPECT_EQ(X_gathered_cpu.data<float>()[i], i / 20);
206206
}
207207
}
@@ -254,16 +254,16 @@ TEST(MPITest, TestMPIAllreduce) {
254254
EXPECT_TRUE(net->Run());
255255
// Let's test the value.
256256
auto& X = ws.GetBlob("X")->Get<TensorCUDA>();
257-
EXPECT_EQ(X.size(), 10);
257+
EXPECT_EQ(X.numel(), 10);
258258
Tensor X_cpu(X, CPU);
259-
for (int i = 0; i < X.size(); ++i) {
259+
for (int i = 0; i < X.numel(); ++i) {
260260
EXPECT_EQ(X_cpu.data<float>()[i], rank);
261261
}
262262
auto& X_reduced = ws.GetBlob("X_reduced")->Get<TensorCUDA>();
263-
EXPECT_EQ(X_reduced.size(), 10);
263+
EXPECT_EQ(X_reduced.numel(), 10);
264264
int expected_result = size * (size - 1) / 2;
265265
Tensor X_reduced_cpu(X_reduced, CPU);
266-
for (int i = 0; i < X_reduced.size(); ++i) {
266+
for (int i = 0; i < X_reduced.numel(); ++i) {
267267
EXPECT_EQ(X_reduced_cpu.data<float>()[i], expected_result);
268268
}
269269
}
@@ -315,10 +315,10 @@ TEST(MPITest, TestInPlaceMPIAllreduce) {
315315
EXPECT_NE(nullptr, net.get());
316316
EXPECT_TRUE(net->Run());
317317
auto& X_reduced = ws.GetBlob("X")->Get<TensorCUDA>();
318-
EXPECT_EQ(X_reduced.size(), 10);
318+
EXPECT_EQ(X_reduced.numel(), 10);
319319
int expected_result = size * (size - 1) / 2;
320320
Tensor X_reduced_cpu(X_reduced, CPU);
321-
for (int i = 0; i < X_reduced.size(); ++i) {
321+
for (int i = 0; i < X_reduced.numel(); ++i) {
322322
EXPECT_EQ(X_reduced_cpu.data<float>()[i], expected_result);
323323
}
324324
}

caffe2/mpi/mpi_ops.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class MPIBroadcastOp final : public Operator<Context> {
4141
auto* output = Output(0);
4242
// Make sure that output is already allocated.
4343
CAFFE_ENFORCE(
44-
output->size() > 0,
44+
output->numel() > 0,
4545
"Broadcast op uses in-place operation so the output "
4646
"should be already allocated.");
4747
MPI_CHECK(MPI_Bcast(
@@ -75,7 +75,7 @@ class MPIReduceOp final : public Operator<Context> {
7575
MPI_CHECK(MPI_Reduce(
7676
const_cast<T*>(input.template data<T>()),
7777
output->template mutable_data<T>(),
78-
input.size(),
78+
input.numel(),
7979
MPIDataTypeWrapper<T>::type(),
8080
MPI_SUM,
8181
root_,
@@ -103,10 +103,10 @@ class MPIAllgatherOp final : public Operator<Context> {
103103
output->Resize(output_dims);
104104
MPI_CHECK(MPI_Allgather(
105105
const_cast<T*>(input.template data<T>()),
106-
input.size(),
106+
input.numel(),
107107
MPIDataTypeWrapper<T>::type(),
108108
output->template mutable_data<T>(),
109-
input.size(),
109+
input.numel(),
110110
MPIDataTypeWrapper<T>::type(),
111111
comm));
112112
return true;
@@ -136,7 +136,7 @@ class MPIAllreduceOp final : public Operator<Context> {
136136
MPI_CHECK(MPI_Allreduce(
137137
source,
138138
output->template mutable_data<T>(),
139-
input.size(),
139+
input.numel(),
140140
MPIDataTypeWrapper<T>::type(),
141141
MPI_SUM,
142142
comm));

caffe2/mpi/mpi_test.cc

+14-14
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ TEST(MPITest, TestMPIBroadcast) {
6262
EXPECT_TRUE(net->Run());
6363
// Let's test the value.
6464
auto& X = ws.GetBlob("X")->Get<TensorCPU>();
65-
EXPECT_EQ(X.size(), 10);
66-
for (int i = 0; i < X.size(); ++i) {
65+
EXPECT_EQ(X.numel(), 10);
66+
for (int i = 0; i < X.numel(); ++i) {
6767
EXPECT_EQ(X.data<float>()[i], root);
6868
}
6969
}
@@ -125,9 +125,9 @@ TEST(MPITest, TestMPIReduce) {
125125
if (rank == root) {
126126
// Let's test the value.
127127
auto& X = ws.GetBlob("X_reduced")->Get<TensorCPU>();
128-
EXPECT_EQ(X.size(), 10);
128+
EXPECT_EQ(X.numel(), 10);
129129
int expected_result = size * (size - 1) / 2;
130-
for (int i = 0; i < X.size(); ++i) {
130+
for (int i = 0; i < X.numel(); ++i) {
131131
EXPECT_EQ(X.data<float>()[i], expected_result);
132132
}
133133
}
@@ -180,15 +180,15 @@ TEST(MPITest, TestMPIAllgather) {
180180
EXPECT_TRUE(net->Run());
181181
// Let's test the value.
182182
auto& X = ws.GetBlob("X")->Get<TensorCPU>();
183-
EXPECT_EQ(X.size(), 20);
184-
for (int i = 0; i < X.size(); ++i) {
183+
EXPECT_EQ(X.numel(), 20);
184+
for (int i = 0; i < X.numel(); ++i) {
185185
EXPECT_EQ(X.data<float>()[i], rank);
186186
}
187187
auto& X_gathered = ws.GetBlob("X_gathered")->Get<TensorCPU>();
188-
EXPECT_EQ(X_gathered.size(), 20 * size);
188+
EXPECT_EQ(X_gathered.numel(), 20 * size);
189189
EXPECT_EQ(X_gathered.dim(0), 2 * size);
190190
EXPECT_EQ(X_gathered.dim(1), 10);
191-
for (int i = 0; i < X_gathered.size(); ++i) {
191+
for (int i = 0; i < X_gathered.numel(); ++i) {
192192
EXPECT_EQ(X_gathered.data<float>()[i], i / 20);
193193
}
194194
}
@@ -238,14 +238,14 @@ TEST(MPITest, TestMPIAllreduce) {
238238
EXPECT_TRUE(net->Run());
239239
// Let's test the value.
240240
auto& X = ws.GetBlob("X")->Get<TensorCPU>();
241-
EXPECT_EQ(X.size(), 10);
242-
for (int i = 0; i < X.size(); ++i) {
241+
EXPECT_EQ(X.numel(), 10);
242+
for (int i = 0; i < X.numel(); ++i) {
243243
EXPECT_EQ(X.data<float>()[i], rank);
244244
}
245245
auto& X_reduced = ws.GetBlob("X_reduced")->Get<TensorCPU>();
246-
EXPECT_EQ(X_reduced.size(), 10);
246+
EXPECT_EQ(X_reduced.numel(), 10);
247247
int expected_result = size * (size - 1) / 2;
248-
for (int i = 0; i < X_reduced.size(); ++i) {
248+
for (int i = 0; i < X_reduced.numel(); ++i) {
249249
EXPECT_EQ(X_reduced.data<float>()[i], expected_result);
250250
}
251251
}
@@ -294,9 +294,9 @@ TEST(MPITest, TestInPlaceMPIAllreduce) {
294294
EXPECT_NE(nullptr, net.get());
295295
EXPECT_TRUE(net->Run());
296296
auto& X_reduced = ws.GetBlob("X")->Get<TensorCPU>();
297-
EXPECT_EQ(X_reduced.size(), 10);
297+
EXPECT_EQ(X_reduced.numel(), 10);
298298
int expected_result = size * (size - 1) / 2;
299-
for (int i = 0; i < X_reduced.size(); ++i) {
299+
for (int i = 0; i < X_reduced.numel(); ++i) {
300300
EXPECT_EQ(X_reduced.data<float>()[i], expected_result);
301301
}
302302
}

caffe2/operators/accumulate_op.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ class AccumulateOp final : public Operator<Context> {
2323
LOG(INFO) << "Reshaping and initializing output.";
2424
output->ResizeLike(input);
2525
math::Set<T, Context>(
26-
output->size(), 0, output->template mutable_data<T>(), &context_);
26+
output->numel(), 0, output->template mutable_data<T>(), &context_);
2727
}
2828
math::Axpby<T, T, Context>(
29-
input.size(),
29+
input.numel(),
3030
static_cast<T>(1),
3131
input.template data<T>(),
3232
gamma_,

caffe2/operators/activation_ops_cudnn.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ class CuDNNActivationOp final : public CuDNNActivationOpBase {
7070
const auto& X = Input(0);
7171
auto* Y = Output(0);
7272
Y->ResizeLike(X);
73-
if (X.size() == 0) {
73+
if (X.numel() == 0) {
7474
Y->template mutable_data<T>();
7575
return true;
7676
}
77-
this->SetTensorDescriptor(cudnnTypeWrapper<T>::type, X.size());
77+
this->SetTensorDescriptor(cudnnTypeWrapper<T>::type, X.numel());
7878
CUDNN_ENFORCE(cudnnActivationForward(
7979
this->cudnn_wrapper_.inline_cudnn_handle(),
8080
this->act_desc_,
@@ -109,11 +109,11 @@ class CuDNNActivationGradientOp final : public CuDNNActivationOpBase {
109109
const auto& dY = Input(1);
110110
auto* dX = Output(0);
111111
dX->ResizeLike(Y);
112-
if (Y.size() == 0) {
112+
if (Y.numel() == 0) {
113113
dX->template mutable_data<T>();
114114
return true;
115115
}
116-
this->SetTensorDescriptor(cudnnTypeWrapper<T>::type, Y.size());
116+
this->SetTensorDescriptor(cudnnTypeWrapper<T>::type, Y.numel());
117117
CUDNN_ENFORCE(cudnnActivationBackward(
118118
this->cudnn_wrapper_.inline_cudnn_handle(),
119119
this->act_desc_,

caffe2/operators/affine_channel_op.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ bool AffineChannelGradientOp<float, CPUContext>::RunOnDeviceWithOrderNCHW() {
5858
dX->ResizeLike(dY);
5959
const int N = dY.dim32(0);
6060
const int C = dY.dim32(1);
61-
const int HxW = dY.size() / (N * C);
61+
const int HxW = dY.numel() / (N * C);
6262
const float* dY_data = dY.data<float>();
6363
const float* scale_data = scale.data<float>();
6464
const std::array<int, 3> X_dims = {N, C, HxW};
@@ -99,7 +99,7 @@ bool AffineChannelGradientOp<float, CPUContext>::RunOnDeviceWithOrderNHWC() {
9999
dX->ResizeLike(dY);
100100
const int ndim = dY.ndim();
101101
const int C = dY.dim32(ndim - 1);
102-
const int rows = dY.size() / C;
102+
const int rows = dY.numel() / C;
103103
const int cols = C;
104104
const float* dY_data = dY.data<float>();
105105
const float* scale_data = scale.data<float>();

caffe2/operators/affine_channel_op.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class AffineChannelOp final : public Operator<Context> {
4242
}
4343
const int N = X.dim32(0);
4444
const int C = X.dim32(1);
45-
const int HxW = X.size() / (N * C);
45+
const int HxW = X.numel() / (N * C);
4646
Y->ResizeLike(X);
4747
math::AffineChannel<T, Context, StorageOrder::NCHW>(
4848
N,
@@ -71,7 +71,7 @@ class AffineChannelOp final : public Operator<Context> {
7171
const int ndim = X.ndim();
7272
const int N = X.dim32(0);
7373
const int C = X.dim32(ndim - 1);
74-
const int HxW = X.size() / (N * C);
74+
const int HxW = X.numel() / (N * C);
7575
Y->ResizeLike(X);
7676
math::AffineChannel<T, Context, StorageOrder::NHWC>(
7777
N,

caffe2/operators/assert_op.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class AssertOp final : public Operator<Context> {
2222
cmp_tensor_.CopyFrom(Input(0));
2323
auto* cmp_data = cmp_tensor_.template data<T>();
2424

25-
for (int64_t i = 0; i < cmp_tensor_.size(); ++i) {
25+
for (int64_t i = 0; i < cmp_tensor_.numel(); ++i) {
2626
CAFFE_ENFORCE((bool)cmp_data[i], [&]() {
2727
std::stringstream ss;
2828
ss << "Assert failed for element " << i

caffe2/operators/batch_box_cox_op.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,12 @@ bool BatchBoxCoxOp<CPUContext>::DoRunWithType() {
8383
output->ResizeLike(Input(DATA));
8484
auto* output_ptr = output->template mutable_data<T>();
8585

86-
if (data.size() <= 0) {
86+
if (data.numel() <= 0) {
8787
return true;
8888
}
8989

90-
CAFFE_ENFORCE_EQ(lambda1.size(), D);
91-
CAFFE_ENFORCE_EQ(lambda2.size(), D);
90+
CAFFE_ENFORCE_EQ(lambda1.numel(), D);
91+
CAFFE_ENFORCE_EQ(lambda2.numel(), D);
9292

9393
const auto* data_ptr = data.template data<T>();
9494
const auto* lambda1_ptr = lambda1.template data<T>();

caffe2/operators/batch_bucketize_op.cc

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,22 @@ bool BatchBucketizeOp<CPUContext>::RunOnDevice() {
1616
CAFFE_ENFORCE_EQ(indices.ndim(), 1);
1717
CAFFE_ENFORCE_EQ(boundaries.ndim(), 1);
1818
CAFFE_ENFORCE_EQ(feature.ndim(), 2);
19-
CAFFE_ENFORCE_EQ(lengths.size(), indices.size());
19+
CAFFE_ENFORCE_EQ(lengths.numel(), indices.numel());
2020

2121
const auto* lengths_data = lengths.template data<int32_t>();
2222
const auto* indices_data = indices.template data<int32_t>();
2323
const auto* boundaries_data = boundaries.template data<float>();
2424
const auto* feature_data = feature.template data<float>();
2525
auto batch_size = feature.dim(0);
2626
auto feature_dim = feature.dim(1);
27-
auto output_dim = indices.size();
27+
auto output_dim = indices.numel();
2828

2929
int64_t length_sum = 0;
30-
for (int64_t i = 0; i < lengths.size(); i++) {
30+
for (int64_t i = 0; i < lengths.numel(); i++) {
3131
CAFFE_ENFORCE_GE(feature_dim, indices_data[i]);
3232
length_sum += lengths_data[i];
3333
}
34-
CAFFE_ENFORCE_EQ(length_sum, boundaries.size());
34+
CAFFE_ENFORCE_EQ(length_sum, boundaries.numel());
3535

3636
int64_t lower_bound = 0;
3737
output->Resize(batch_size, output_dim);

caffe2/operators/batch_gather_ops.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class BatchGatherOp final : public Operator<Context> {
3434

3535
auto block_size = data.size_from_dim(2);
3636
auto block_bytesize = block_size * data.meta().itemsize();
37-
auto N = indices.size();
37+
auto N = indices.numel();
3838
auto data_batch_size = data.size_from_dim(1);
3939
auto gathered_batch_size = N * data.size_from_dim(2);
4040
auto data_batch_bytesize = data_batch_size * data.meta().itemsize();
@@ -115,7 +115,7 @@ class BatchGatherGradientOp final : public Operator<Context> {
115115

116116
output->ResizeLike(data);
117117
TData* out_data = output->template mutable_data<TData>();
118-
if (data.size() <= 0) {
118+
if (data.numel() <= 0) {
119119
return true;
120120
}
121121

@@ -124,7 +124,7 @@ class BatchGatherGradientOp final : public Operator<Context> {
124124
const TData* grad_data = grad.template data<TData>();
125125

126126
auto block_size = data.size_from_dim(2);
127-
auto N = indices.size();
127+
auto N = indices.numel();
128128
auto data_batch_size = data.size_from_dim(1);
129129
auto gathered_batch_size = N * data.size_from_dim(2);
130130
const TInd* idxs = indices.template data<TInd>();

caffe2/operators/batch_matmul_op_gpu_test.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class BatchMatMulOpGPUTest : public testing::Test {
3333
auto* tensor = BlobGetMutableTensor(blob, CUDA);
3434
tensor->Resize(dims);
3535
math::Set<float, CUDAContext>(
36-
tensor->size(),
36+
tensor->numel(),
3737
value,
3838
tensor->template mutable_data<float>(),
3939
cuda_context_.get());
@@ -49,7 +49,7 @@ class BatchMatMulOpGPUTest : public testing::Test {
4949
for (std::size_t i = 0; i < dims.size(); ++i) {
5050
ASSERT_EQ(dims[i], Y_dims[i]);
5151
}
52-
for (int i = 0; i < Y_cpu.size(); ++i) {
52+
for (int i = 0; i < Y_cpu.numel(); ++i) {
5353
EXPECT_FLOAT_EQ(value, Y_cpu.data<float>()[i]);
5454
}
5555
}

0 commit comments

Comments
 (0)