pytorch/caffe2/operators/index_hash_ops.cc
Nikita Shulga a9b0a921d5 Disable avoid-non-const-global-variables lint check (#62008)
Summary:
As GoogleTest `TEST` macro is non-compliant with it as well as `DEFINE_DISPATCH`

All changes but the ones to `.clang-tidy` are generated using following script:
```
for i in `find . -type f -iname "*.c*" -or -iname "*.h"|xargs grep cppcoreguidelines-avoid-non-const-global-variables|cut -f1 -d:|sort|uniq`;  do sed -i "/\/\/ NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)/d" $i; done
```

Pull Request resolved: https://github.com/pytorch/pytorch/pull/62008

Reviewed By: driazati, r-barnes

Differential Revision: D29838584

Pulled By: malfet

fbshipit-source-id: 1b2f8602c945bd4ce50a9bfdd204755556e31d13
2021-07-22 18:04:40 -07:00

39 lines
1.3 KiB
C++

#include "caffe2/operators/index_hash_ops.h"
namespace caffe2 {
namespace {
REGISTER_CPU_OPERATOR(IndexHash, IndexHashOp<CPUContext>);
OPERATOR_SCHEMA(IndexHash)
.NumInputs(1)
.NumOutputs(1)
.SetDoc(R"DOC(
This operator translates a list of indices into a list of hashed indices.
A seed can be fed as an argument to change the behavior of the hash function.
If a modulo is specified, all the hashed indices will be modulo the
specified number. All input and output indices are enforced to be positive.
)DOC")
.Input(0, "Indices", "Input feature indices.")
.Output(0, "HashedIndices", "Hashed feature indices.")
.AllowOneToOneInplace()
.Arg("seed", "seed for the hash function")
.Arg("modulo", "must be > 0, hashed ids will be modulo this number")
.TensorInferenceFunction([](const OperatorDef& /* unused */,
const vector<TensorShape>& in) {
std::vector<TensorShape> out(1);
std::vector<int64_t> output_dims = GetDimsVector(in[0]);
out[0] = CreateTensorShape(output_dims, in[0].data_type());
return out;
});
SHOULD_NOT_DO_GRADIENT(IndexHash);
} // namespace
} // namespace caffe2
C10_EXPORT_CAFFE2_OP_TO_C10_CPU(
IndexHash,
"_caffe2::IndexHash(Tensor indices, int seed, int modulo) -> Tensor hashed_indices",
caffe2::IndexHashOp<caffe2::CPUContext>);