Skip to content

Commit

Permalink
Rename dim(i) -> size(i) - 1/2
Browse files Browse the repository at this point in the history
Summary:
Codemod generated with clangr shard mode, 50 files per diff,
clangr code(dim->size): diffusion/FBS/browse/master/fbcode/caffe2/caffe2/fb/codemods/TensorMethodRename.cpp

Reviewed By: ezyang

Differential Revision: D12896712

fbshipit-source-id: 909731691fab7799efbcfc3b5dcc9e531831c2d4
  • Loading branch information
jerryzh168 authored and facebook-github-bot committed Nov 5, 2018
1 parent 3ea64bd commit e7242cb
Show file tree
Hide file tree
Showing 45 changed files with 195 additions and 193 deletions.
4 changes: 2 additions & 2 deletions caffe2/mpi/mpi_gpu_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ TEST(MPITest, TestMPIAllgather) {
}
auto& X_gathered = ws.GetBlob("X_gathered")->Get<TensorCUDA>();
EXPECT_EQ(X_gathered.numel(), 20 * size);
EXPECT_EQ(X_gathered.dim(0), 2 * size);
EXPECT_EQ(X_gathered.dim(1), 10);
EXPECT_EQ(X_gathered.size(0), 2 * size);
EXPECT_EQ(X_gathered.size(1), 10);
Tensor X_gathered_cpu(X_gathered, CPU);
for (int i = 0; i < X_gathered.numel(); ++i) {
EXPECT_EQ(X_gathered_cpu.data<float>()[i], i / 20);
Expand Down
4 changes: 2 additions & 2 deletions caffe2/mpi/mpi_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ TEST(MPITest, TestMPIAllgather) {
}
auto& X_gathered = ws.GetBlob("X_gathered")->Get<TensorCPU>();
EXPECT_EQ(X_gathered.numel(), 20 * size);
EXPECT_EQ(X_gathered.dim(0), 2 * size);
EXPECT_EQ(X_gathered.dim(1), 10);
EXPECT_EQ(X_gathered.size(0), 2 * size);
EXPECT_EQ(X_gathered.size(1), 10);
for (int i = 0; i < X_gathered.numel(); ++i) {
EXPECT_EQ(X_gathered.data<float>()[i], i / 20);
}
Expand Down
2 changes: 1 addition & 1 deletion caffe2/operators/batch_box_cox_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ bool BatchBoxCoxOp<CPUContext>::DoRunWithType() {
auto& lambda1 = Input(LAMBDA1);
auto& lambda2 = Input(LAMBDA2);
CAFFE_ENFORCE_GE(data.ndim(), 1);
auto N = data.dim(0);
auto N = data.size(0);
auto D = data.size_from_dim(1);

auto* output = Output(0);
Expand Down
4 changes: 2 additions & 2 deletions caffe2/operators/batch_bucketize_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ bool BatchBucketizeOp<CPUContext>::RunOnDevice() {
const auto* indices_data = indices.template data<int32_t>();
const auto* boundaries_data = boundaries.template data<float>();
const auto* feature_data = feature.template data<float>();
auto batch_size = feature.dim(0);
auto feature_dim = feature.dim(1);
auto batch_size = feature.size(0);
auto feature_dim = feature.size(1);
auto output_dim = indices.numel();

int64_t length_sum = 0;
Expand Down
18 changes: 9 additions & 9 deletions caffe2/operators/batch_gather_ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class BatchGatherOp final : public Operator<Context> {
CAFFE_ENFORCE_GE(data.ndim(), 2, "DATA should be at least 2-D");

vector<int64_t> shape;
shape.push_back(data.dim(0));
shape.push_back(data.size(0));
shape.insert(shape.end(), indices.sizes().begin(), indices.sizes().end());
shape.insert(shape.end(), data.sizes().begin() + 2, data.sizes().end());
output->Resize(shape);
Expand All @@ -47,18 +47,18 @@ class BatchGatherOp final : public Operator<Context> {
for (auto i = 0; i < N; ++i) {
auto idx = idxs[i];
CAFFE_ENFORCE(
0 <= idx && idx < data.dim(1),
0 <= idx && idx < data.size(1),
"INDICES element is out of DATA bounds, id=",
idx,
" data_dim=",
data.dim(1));
data.size(1));
}

if (data.template IsType<float>() && block_size == 1) {
auto src = data.template data<float>();
auto dst = output->template mutable_data<float>();

for (auto batch = 0; batch < data.dim(0); ++batch) {
for (auto batch = 0; batch < data.size(0); ++batch) {
auto src_batch_base = src + batch * data_batch_size;
auto out_batch_base = dst + batch * gathered_batch_size;

Expand All @@ -68,7 +68,7 @@ class BatchGatherOp final : public Operator<Context> {
}
}
} else {
for (auto batch = 0; batch < data.dim(0); ++batch) {
for (auto batch = 0; batch < data.size(0); ++batch) {
auto src_batch_base = src_base + batch * data_batch_bytesize;
auto out_batch_base = out + batch * gathered_batch_bytesize;

Expand Down Expand Up @@ -112,7 +112,7 @@ class BatchGatherGradientOp final : public Operator<Context> {

CAFFE_ENFORCE_GE(data.ndim(), 2, "DATA should be at least 2-D");
CAFFE_ENFORCE_EQ(
data.dim(0), grad.dim(0), "batch sizes should be the same");
data.size(0), grad.size(0), "batch sizes should be the same");

output->ResizeLike(data);
TData* out_data = output->template mutable_data<TData>();
Expand All @@ -133,14 +133,14 @@ class BatchGatherGradientOp final : public Operator<Context> {
for (auto i = 0; i < N; ++i) {
auto idx = idxs[i];
CAFFE_ENFORCE(
0 <= idx && idx < data.dim(1),
0 <= idx && idx < data.size(1),
"INDICES element is out of DATA bounds, id=",
idx,
" data_dim=",
data.dim(1));
data.size(1));
}

for (auto batch = 0; batch < grad.dim(0); ++batch) {
for (auto batch = 0; batch < grad.size(0); ++batch) {
auto src_batch_base = grad_data + batch * gathered_batch_size;
auto out_batch_base = out_data + batch * data_batch_size;

Expand Down
14 changes: 7 additions & 7 deletions caffe2/operators/batch_sparse_to_dense_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ bool BatchSparseToDenseOp<T, Context>::RunOnDevice() {
auto& shaper = Input(3);
CAFFE_ENFORCE_EQ(shaper.ndim(), 2);
if (dense_last_dim_ == -1) {
dense_last_dim_ = shaper.dim(1);
dense_last_dim_ = shaper.size(1);
} else {
CAFFE_ENFORCE(
dense_last_dim_ == shaper.dim(1),
dense_last_dim_ == shaper.size(1),
"The last dim argument is not aligned with the shape input last dim");
}
} else {
Expand Down Expand Up @@ -78,8 +78,8 @@ bool BatchDenseToSparseOp<T, Context>::RunOnDevice() {
math::Sum<int64_t, Context>(batch_size, lengths_data, &lengths_sum, &context_);
CAFFE_ENFORCE_EQ(lengths_sum, indices.numel());

CAFFE_ENFORCE_EQ(batch_size, dense.dim(0));
dense_last_dim_ = dense.dim(1);
CAFFE_ENFORCE_EQ(batch_size, dense.size(0));
dense_last_dim_ = dense.size(1);
vector<int64_t> output_shape = indices.sizes().vec();
output->Resize(output_shape);
T* output_data = output->template mutable_data<T>();
Expand All @@ -88,13 +88,13 @@ bool BatchDenseToSparseOp<T, Context>::RunOnDevice() {
for (int64_t i = 0; i < batch_size; ++i) {
for (int64_t j = 0; j < lengths_data[i]; ++j) {
CAFFE_ENFORCE(
indices_data[k] < dense.dim(1),
indices_data[k] < dense.size(1),
"An indice (",
indices_data[k],
") is larger then last dim of dense (",
dense.dim(1),
dense.size(1),
").");
output_data[k] = dense_data[i * dense.dim(1) + indices_data[k]];
output_data[k] = dense_data[i * dense.size(1) + indices_data[k]];
k += 1;
}
}
Expand Down
2 changes: 1 addition & 1 deletion caffe2/operators/bbox_transform_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ bool BBoxTransformOp<float, CPUContext>::RunOnDevice() {

CAFFE_ENFORCE_EQ(iminfo_in.sizes(), (at::IntList{batch_size, 3}));
Eigen::Map<const ERArrXXf> iminfo(
iminfo_in.data<float>(), iminfo_in.dim(0), iminfo_in.dim(1));
iminfo_in.data<float>(), iminfo_in.size(0), iminfo_in.size(1));

box_out->ResizeLike(delta_in);
Eigen::Map<ERArrXXf> new_boxes(
Expand Down
4 changes: 2 additions & 2 deletions caffe2/operators/bisect_percentile_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ class BisectPercentileOp final : public Operator<Context> {
// Input
const auto& raw = Input(RAW);
CAFFE_ENFORCE_EQ(raw.ndim(), 2);
const auto batch_size = raw.dim(0);
const auto num_features = raw.dim(1);
const auto batch_size = raw.size(0);
const auto num_features = raw.size(1);
CAFFE_ENFORCE_EQ(num_features, pct_lens_.size());
const float* raw_data = raw.template data<float>();

Expand Down
2 changes: 1 addition & 1 deletion caffe2/operators/boolean_mask_ops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ bool SequenceMaskOp<CPUContext>::DoRunWithType() {
// product of dims from 1 to batch
const int batch_dim =
(canonical_batch >= 0
? input->size_to_dim(canonical_batch) * input->dim(canonical_batch)
? input->size_to_dim(canonical_batch) * input->size(canonical_batch)
: -1);

T fill_val = convert::To<float, T>(grad_ ? 0.0f : fill_val_);
Expand Down
32 changes: 16 additions & 16 deletions caffe2/operators/box_with_nms_limit_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,36 @@ bool BoxWithNMSLimitOp<CPUContext>::RunOnDevice() {

// tscores: (num_boxes, num_classes), 0 for background
if (tscores.ndim() == 4) {
CAFFE_ENFORCE_EQ(tscores.dim(2), 1, tscores.dim(2));
CAFFE_ENFORCE_EQ(tscores.dim(3), 1, tscores.dim(3));
CAFFE_ENFORCE_EQ(tscores.size(2), 1, tscores.size(2));
CAFFE_ENFORCE_EQ(tscores.size(3), 1, tscores.size(3));
} else {
CAFFE_ENFORCE_EQ(tscores.ndim(), 2, tscores.ndim());
}
CAFFE_ENFORCE(tscores.template IsType<float>(), tscores.dtype().name());
// tboxes: (num_boxes, num_classes * box_dim)
if (tboxes.ndim() == 4) {
CAFFE_ENFORCE_EQ(tboxes.dim(2), 1, tboxes.dim(2));
CAFFE_ENFORCE_EQ(tboxes.dim(3), 1, tboxes.dim(3));
CAFFE_ENFORCE_EQ(tboxes.size(2), 1, tboxes.size(2));
CAFFE_ENFORCE_EQ(tboxes.size(3), 1, tboxes.size(3));
} else {
CAFFE_ENFORCE_EQ(tboxes.ndim(), 2, tboxes.ndim());
}
CAFFE_ENFORCE(tboxes.template IsType<float>(), tboxes.dtype().name());

int N = tscores.dim(0);
int num_classes = tscores.dim(1);
int N = tscores.size(0);
int num_classes = tscores.size(1);

CAFFE_ENFORCE_EQ(N, tboxes.dim(0));
CAFFE_ENFORCE_EQ(num_classes * box_dim, tboxes.dim(1));
CAFFE_ENFORCE_EQ(N, tboxes.size(0));
CAFFE_ENFORCE_EQ(num_classes * box_dim, tboxes.size(1));

int batch_size = 1;
vector<float> batch_splits_default(1, tscores.dim(0));
vector<float> batch_splits_default(1, tscores.size(0));
const float* batch_splits_data = batch_splits_default.data();
if (InputSize() > 2) {
// tscores and tboxes have items from multiple images in a batch. Get the
// corresponding batch splits from input.
const auto& tbatch_splits = Input(2);
CAFFE_ENFORCE_EQ(tbatch_splits.ndim(), 1);
batch_size = tbatch_splits.dim(0);
batch_size = tbatch_splits.size(0);
batch_splits_data = tbatch_splits.data<float>();
}
Eigen::Map<const EArrXf> batch_splits(batch_splits_data, batch_size);
Expand All @@ -69,16 +69,16 @@ bool BoxWithNMSLimitOp<CPUContext>::RunOnDevice() {
for (int b = 0; b < batch_splits.size(); ++b) {
int num_boxes = batch_splits(b);
Eigen::Map<const ERArrXXf> scores(
tscores.data<float>() + offset * tscores.dim(1),
tscores.data<float>() + offset * tscores.size(1),
num_boxes,
tscores.dim(1));
tscores.size(1));
Eigen::Map<const ERArrXXf> boxes(
tboxes.data<float>() + offset * tboxes.dim(1),
tboxes.data<float>() + offset * tboxes.size(1),
num_boxes,
tboxes.dim(1));
tboxes.size(1));

// To store updated scores if SoftNMS is used
ERArrXXf soft_nms_scores(num_boxes, tscores.dim(1));
ERArrXXf soft_nms_scores(num_boxes, tscores.size(1));
vector<vector<int>> keeps(num_classes);

// Perform nms to each class
Expand Down Expand Up @@ -169,7 +169,7 @@ bool BoxWithNMSLimitOp<CPUContext>::RunOnDevice() {
total_keep_per_batch[b] = total_keep_count;

// Write results
int cur_start_idx = out_scores->dim(0);
int cur_start_idx = out_scores->size(0);
out_scores->Extend(total_keep_count, 50, &context_);
out_boxes->Extend(total_keep_count, 50, &context_);
out_classes->Extend(total_keep_count, 50, &context_);
Expand Down
2 changes: 1 addition & 1 deletion caffe2/operators/byte_weight_dequant_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ByteWeightDequantOp : public Operator<Context> {
float bin_interval = (max_ - min_) / 255.0;
int total = 1;
for (int i = 0; i < shape_.size(); i++) {
total *= Y->dim(i);
total *= Y->size(i);
}
const uint8_t* Xdata;
if (WI.template IsType<uint8_t>()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,14 @@ bool CollectAndDistributeFpnRpnProposalsOp<CPUContext>::RunOnDevice() {
int proposal_num = 0;
for (int i = 0; i < num_rpn_lvls; i++) {
const auto& roi_in = Input(i);
proposal_num += roi_in.dim(0);
proposal_num += roi_in.size(0);
}
ERArrXXf rois(proposal_num, 5);
EArrXf scores(proposal_num);
int len = 0;
for (int i = 0; i < num_rpn_lvls; i++) {
const auto& roi_in = Input(i);
const int n = roi_in.dim(0);
const int n = roi_in.size(0);

Eigen::Map<const ERArrXXf> roi(roi_in.data<float>(), n, 5);
rois.block(len, 0, n, 5) = roi;
Expand Down
18 changes: 9 additions & 9 deletions caffe2/operators/crf_viterbi_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class ViterbiPathOp : public Operator<CPUContext> {
int32_t block_bytesize,
TensorCPU* outRow) {
CAFFE_ENFORCE(
0 <= rowIndex && rowIndex < data.dim(0),
0 <= rowIndex && rowIndex < data.size(0),
"rowIndex is out of DATA bounds");
auto out = static_cast<char*>(outRow->raw_mutable_data(data.dtype()));
auto src_base = static_cast<const char*>(data.raw_data());
Expand Down Expand Up @@ -85,13 +85,13 @@ class ViterbiPathOp : public Operator<CPUContext> {
"Predictions and transitions hould 2D matrices");

CAFFE_ENFORCE(
predictions.dim(1) == transitions.dim(0),
predictions.size(1) == transitions.size(0),
"Predictions and transitions dimensions not matching");

auto seqLen = predictions.dim32(0);

viterbiPath->Resize(seqLen);
auto block_size = predictions.numel() / predictions.dim(0);
auto block_size = predictions.numel() / predictions.size(0);
auto block_bytesize =
predictions.size_from_dim(1) * predictions.dtype().itemsize();
Tensor backpointers(CPU);
Expand All @@ -106,8 +106,8 @@ class ViterbiPathOp : public Operator<CPUContext> {
AddColToMat(transitions, trellis, &dpMat);
RowwiseMaxAndArg(
dpMat.template data<float>(),
dpMat.dim(0),
dpMat.dim(1),
dpMat.size(0),
dpMat.size(1),
dpMax.template mutable_data<float>(),
backpointers.template mutable_data<int32_t>() + (i * block_size));

Expand Down Expand Up @@ -159,7 +159,7 @@ class SwapBestPathOp : public Operator<CPUContext> {
"predictions should be a 2D matrix and bestPath should be 1D vector");

CAFFE_ENFORCE(
data.dim(0) == newBestIdicies.dim(0),
data.size(0) == newBestIdicies.size(0),
"predictions and bestPath dimensions not matching");

updatedData->ResizeLike(data);
Expand All @@ -174,12 +174,12 @@ class SwapBestPathOp : public Operator<CPUContext> {

ColwiseMaxAndArg(
data.template data<float>(),
data.dim(0),
data.dim(1),
data.size(0),
data.size(1),
bestScores.template mutable_data<float>(),
oldBestIndices.template mutable_data<int32_t>());

auto block_size = data.numel() / data.dim(0);
auto block_size = data.numel() / data.size(0);

const int32_t* oldBestIdx = oldBestIndices.template data<int32_t>();
const int32_t* newIdx = newBestIdicies.template data<int32_t>();
Expand Down
10 changes: 5 additions & 5 deletions caffe2/operators/dataset_ops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ class UnPackRecordsOp : public Operator<CPUContext> {
CAFFE_ENFORCE_EQ(input.sizes()[k], outputDims[j][k]);
}

outputDims[j][0] += input.dim(0);
outputDims[j][0] += input.size(0);
}
}

Expand Down Expand Up @@ -721,10 +721,10 @@ class ReadRandomBatchOp : public Operator<CPUContext> {
continue;
}
auto dst = static_cast<char*>(out->raw_mutable_data(in.dtype()));
int block_size = in.numel() / in.dim(0);
int block_size = in.numel() / in.size(0);
auto block_bytesize = in.size_from_dim(1) * in.dtype().itemsize();
CAFFE_ENFORCE(
block_bytesize == in.nbytes() / in.dim(0),
block_bytesize == in.nbytes() / in.size(0),
"block_bytesize should be consistent with data dim");
auto src_base = static_cast<const char*>(in.raw_data());
int start = 0;
Expand Down Expand Up @@ -764,7 +764,7 @@ class AppendOp final : public Operator<Context> {
auto& b = Input(1);
auto* c = Output(0);
CAFFE_ENFORCE(b.ndim() >= 1);
if (a.numel() == 0 && a.dim(0) == 0) {
if (a.numel() == 0 && a.size(0) == 0) {
c->CopyFrom(b);
return true;
}
Expand Down Expand Up @@ -821,7 +821,7 @@ class AtomicAppendOp final : public Operator<Context> {
auto& a = Input(1 + i);
auto& b = Input(1 + i + numFields);
auto* c = Output(i);
if (a.numel() == 0 && a.dim(0) == 0) {
if (a.numel() == 0 && a.size(0) == 0) {
c->CopyFrom(b);
continue;
}
Expand Down
Loading

0 comments on commit e7242cb

Please sign in to comment.