1 #ifndef CAFFE2_OPERATORS_FIND_DUPLICATE_ELEMENTS_OP_H 2 #define CAFFE2_OPERATORS_FIND_DUPLICATE_ELEMENTS_OP_H 4 #include <unordered_map> 7 #include "caffe2/core/context.h" 8 #include "caffe2/core/operator.h" 9 #include "caffe2/core/tensor.h" 13 template <
class Context>
16 USE_OPERATOR_CONTEXT_FUNCTIONS;
20 bool RunOnDevice()
override {
26 bool DoRunWithType() {
27 const auto& data =
Input(0);
28 CAFFE_ENFORCE(data.dim() == 1,
"data should be 1-D.");
30 const auto* data_ptr = data.template data<T>();
31 std::unordered_map<T, int64_t> dict;
32 std::vector<int64_t> dupIndices;
34 for (int64_t i = 0, j = 0; j < data.sizes()[0]; ++i, ++j) {
35 bool retVal = dict.insert({data_ptr[j], i}).second;
38 dupIndices.push_back(j);
42 const auto dupSize = dupIndices.size();
44 auto* output = Output(0, {
static_cast<int64_t
>(dupSize)}, at::dtype<int64_t>());
45 auto* out_ptr = output->template mutable_data<int64_t>();
46 for (
size_t i = 0; i < dupSize; ++i) {
47 out_ptr[i] = dupIndices[i];
56 #endif // CAFFE2_OPERATORS_FIND_DUPLICATE_ELEMENTS_OP_H const Tensor & Input(int idx, DeviceType type=Context::GetDeviceType())
Retrieve a non-owning reference to the input at position 'idx' for this operator. ...
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...