Skip to content

Commit

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

Reviewed By: ezyang

Differential Revision: D12935827

fbshipit-source-id: 80ecb034c243dbfd267b9f131cee9d7afd5ef063
  • Loading branch information
jerryzh168 authored and facebook-github-bot committed Nov 7, 2018
1 parent e60a7c2 commit 57ec8f1
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 18 deletions.
4 changes: 2 additions & 2 deletions caffe2/sgd/adagrad_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ class SparseAdagradOp final : public Operator<Context> {
CAFFE_ENFORCE_EQ(Input(LR).numel(), 1);
CAFFE_ENFORCE_EQ(
Input(PARAM).size_from_dim(1),
Input(GRAD).size_from_dim(Input(INDICES).ndim()));
Input(GRAD).size_from_dim(Input(INDICES).dim()));

return DispatchHelper<TensorTypes<int32_t, int64_t>>::call(
this, Input(INDICES));
Expand Down Expand Up @@ -254,7 +254,7 @@ class RowWiseSparseAdagradOp final : public Operator<Context> {
CAFFE_ENFORCE_EQ(Input(LR).numel(), 1);
CAFFE_ENFORCE_EQ(
Input(PARAM).size_from_dim(1),
Input(GRAD).size_from_dim(Input(INDICES).ndim()));
Input(GRAD).size_from_dim(Input(INDICES).dim()));

return DispatchHelper<TensorTypes<int32_t, int64_t>>::call(
this, Input(INDICES));
Expand Down
4 changes: 2 additions & 2 deletions caffe2/sgd/adam_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ class SparseAdamOp final : public Operator<Context> {
CAFFE_ENFORCE_EQ(Input(PARAM).numel(), Input(MOMENT_2).numel());
CAFFE_ENFORCE_EQ(
Input(PARAM).size_from_dim(1),
Input(GRAD).size_from_dim(Input(INDICES).ndim()));
Input(GRAD).size_from_dim(Input(INDICES).dim()));
CAFFE_ENFORCE_EQ(Input(LR).numel(), 1);

return DispatchHelper<TensorTypes<int32_t, int64_t>>::call(
Expand Down Expand Up @@ -336,7 +336,7 @@ class RowWiseSparseAdamOp final : public Operator<Context> {
CAFFE_ENFORCE_EQ(Input(PARAM).sizes()[0], Input(MOMENT_2).numel());
CAFFE_ENFORCE_EQ(
Input(PARAM).size_from_dim(1),
Input(GRAD).size_from_dim(Input(INDICES).ndim()));
Input(GRAD).size_from_dim(Input(INDICES).dim()));
CAFFE_ENFORCE_EQ(Input(LR).numel(), 1);

return DispatchHelper<TensorTypes<int32_t, int64_t>>::call(
Expand Down
5 changes: 3 additions & 2 deletions caffe2/sgd/momentum_sgd_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,9 @@ class SparseMomentumSGDUpdateOp final : public Operator<Context> {
// Enforce shapes
CAFFE_ENFORCE_EQ(Input(LR).numel(), 1);
CAFFE_ENFORCE_EQ(Input(PARAM).numel(), Input(MOMENTUM).numel());
CAFFE_ENFORCE_EQ(Input(PARAM).size_from_dim(1),
Input(GRAD).size_from_dim(Input(INDICES).ndim()));
CAFFE_ENFORCE_EQ(
Input(PARAM).size_from_dim(1),
Input(GRAD).size_from_dim(Input(INDICES).dim()));

return DispatchHelper<TensorTypes<int32_t, int64_t>>::call(
this, Input(INDICES));
Expand Down
2 changes: 1 addition & 1 deletion caffe2/sgd/wngrad_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class SparseWngradOp final : public Operator<Context> {
CAFFE_ENFORCE_EQ(Input(LR).numel(), 1);
CAFFE_ENFORCE_EQ(
Input(PARAM).size_from_dim(1),
Input(GRAD).size_from_dim(Input(INDICES).ndim()));
Input(GRAD).size_from_dim(Input(INDICES).dim()));

return DispatchHelper<TensorTypes<int32_t, int64_t>>::call(
this, Input(INDICES));
Expand Down
12 changes: 6 additions & 6 deletions caffe2/sgd/yellowfin_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,16 @@ CAFFE2_YF_READ_INPUT(GRAD, grad)
CAFFE_ENFORCE(OperatorBase::InputIsTensorType(ITER, CPU));
CAFFE_ENFORCE_EQ(lr_avg_tensor.numel(), 1);
CAFFE_ENFORCE_EQ(mu_avg_tensor.numel(), 1);
CAFFE_ENFORCE_EQ(param_tensor.ndim(), moment_tensor.ndim());
CAFFE_ENFORCE_EQ(param_tensor.ndim(), g_avg_tensor.ndim());
CAFFE_ENFORCE_EQ(param_tensor.ndim(), g2_avg_tensor.ndim());
CAFFE_ENFORCE_EQ(param_tensor.ndim(), grad_tensor.ndim());
for (int i = 0; i < param_tensor.ndim(); ++i) {
CAFFE_ENFORCE_EQ(param_tensor.dim(), moment_tensor.dim());
CAFFE_ENFORCE_EQ(param_tensor.dim(), g_avg_tensor.dim());
CAFFE_ENFORCE_EQ(param_tensor.dim(), g2_avg_tensor.dim());
CAFFE_ENFORCE_EQ(param_tensor.dim(), grad_tensor.dim());
for (int i = 0; i < param_tensor.dim(); ++i) {
CAFFE_ENFORCE_EQ(param_tensor.dim32(i), moment_tensor.dim32(i));
CAFFE_ENFORCE_EQ(param_tensor.dim32(i), g_avg_tensor.dim32(i));
CAFFE_ENFORCE_EQ(param_tensor.dim32(i), g2_avg_tensor.dim32(i));
CAFFE_ENFORCE_EQ(param_tensor.dim32(i), grad_tensor.dim32(i));
}
}

iter_ = OperatorBase::Input<Tensor>(ITER, CPU).template data<int64_t>()[0];

Expand Down
2 changes: 1 addition & 1 deletion caffe2/share/contrib/zstd/quant_decomp_zstd_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ bool QuantDecompZstdOp::RunOnDevice() {

// op_compressed: compressed data, 1d
if (op_compressed.template IsType<uint8_t>()) {
CAFFE_ENFORCE_EQ(op_compressed.ndim(), 1, op_compressed.ndim());
CAFFE_ENFORCE_EQ(op_compressed.dim(), 1, op_compressed.dim());
} else {
// string type has 0 dimension
CAFFE_ENFORCE_EQ(op_compressed.numel(), 1, op_compressed.numel());
Expand Down
2 changes: 1 addition & 1 deletion modules/detectron/batch_permutation_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ bool BatchPermutationOp<float, CPUContext>::RunOnDevice() {
const auto& indices = Input(1);
auto* Y = Output(0);

CAFFE_ENFORCE_EQ(indices.ndim(), 1, "indices must be 1-d");
CAFFE_ENFORCE_EQ(indices.dim(), 1, "indices must be 1-d");
CAFFE_ENFORCE_EQ(
X.dim32(0), indices.dim32(0),
"X.dim32(0) must be equal to indices.dim32(0)",
Expand Down
6 changes: 3 additions & 3 deletions modules/detectron/upsample_nearest_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ class UpsampleNearestOp final : public Operator<Context> {
auto& X = Input(0);
auto* Y = Output(0);
auto out_shape = X.sizes().vec();
out_shape[X.ndim() - 1] *= scale_;
out_shape[X.ndim() - 2] *= scale_;
out_shape[X.dim() - 1] *= scale_;
out_shape[X.dim() - 2] *= scale_;
Y->Resize(out_shape);

int d1;
int d2;
int d3;
if (X.ndim() == 3) {
if (X.dim() == 3) {
d1 = Y->dim32(0);
d2 = Y->dim32(1);
d3 = Y->dim32(2);
Expand Down

0 comments on commit 57ec8f1

Please sign in to comment.