pytorch/caffe2/operators/map_ops.cc
Nikita Shulga 4cb534f92e Make PyTorch code-base clang-tidy compliant (#56892)
Summary:
This is an automatic change generated by the following script:
```
#!/usr/bin/env python3
from subprocess import check_output, check_call
import os

def get_compiled_files_list():
    import json
    with open("build/compile_commands.json") as f:
        data = json.load(f)
    files = [os.path.relpath(node['file']) for node in data]
    for idx, fname in enumerate(files):
        if fname.startswith('build/') and fname.endswith('.DEFAULT.cpp'):
            files[idx] = fname[len('build/'):-len('.DEFAULT.cpp')]
    return files

def run_clang_tidy(fname):
    check_call(["python3", "tools/clang_tidy.py", "-c", "build", "-x", fname,"-s"])
    changes = check_output(["git", "ls-files", "-m"])
    if len(changes) == 0:
        return
    check_call(["git", "commit","--all", "-m", f"NOLINT stubs for {fname}"])

def main():
    git_files = check_output(["git", "ls-files"]).decode("ascii").split("\n")
    compiled_files = get_compiled_files_list()
    for idx, fname in enumerate(git_files):
        if fname not in compiled_files:
            continue
        if fname.startswith("caffe2/contrib/aten/"):
            continue
        print(f"[{idx}/{len(git_files)}] Processing {fname}")
        run_clang_tidy(fname)

if __name__ == "__main__":
    main()
```

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

Reviewed By: H-Huang

Differential Revision: D27991944

Pulled By: malfet

fbshipit-source-id: 5415e1eb2c1b34319a4f03024bfaa087007d7179
2021-04-28 14:10:25 -07:00

95 lines
3.4 KiB
C++

#include "caffe2/operators/map_ops.h"
namespace caffe2 {
using MapType64To64 = MapTypeTraits<int64_t, int64_t>::MapType;
CAFFE_KNOWN_TYPE(MapType64To64);
using MapType64To32 = MapTypeTraits<int64_t, int32_t>::MapType;
CAFFE_KNOWN_TYPE(MapType64To32);
using MapType32To32 = MapTypeTraits<int32_t, int32_t>::MapType;
CAFFE_KNOWN_TYPE(MapType32To32);
using MapType32To64 = MapTypeTraits<int32_t, int64_t>::MapType;
CAFFE_KNOWN_TYPE(MapType32To64);
namespace {
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
REGISTER_BLOB_SERIALIZER(
TypeMeta::Id<MapType64To64>(),
MapSerializer<int64_t, int64_t>);
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
REGISTER_BLOB_SERIALIZER(
TypeMeta::Id<MapType64To32>(),
MapSerializer<int64_t, int32_t>);
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
REGISTER_BLOB_SERIALIZER(
TypeMeta::Id<MapType32To32>(),
MapSerializer<int32_t, int32_t>);
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
REGISTER_BLOB_SERIALIZER(
TypeMeta::Id<MapType32To64>(),
MapSerializer<int32_t, int64_t>);
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
REGISTER_BLOB_DESERIALIZER(
(std::unordered_map<int64_t, int64_t>),
MapDeserializer<int64_t, int64_t>);
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
REGISTER_BLOB_DESERIALIZER(
(std::unordered_map<int64_t, int32_t>),
MapDeserializer<int64_t, int32_t>);
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
REGISTER_BLOB_DESERIALIZER(
(std::unordered_map<int32_t, int32_t>),
MapDeserializer<int32_t, int32_t>);
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
REGISTER_BLOB_DESERIALIZER(
(std::unordered_map<int32_t, int64_t>),
MapDeserializer<int32_t, int64_t>);
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
REGISTER_CPU_OPERATOR(CreateMap, CreateMapOp<CPUContext>);
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
REGISTER_CPU_OPERATOR(KeyValueToMap, KeyValueToMapOp<CPUContext>);
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
REGISTER_CPU_OPERATOR(MapToKeyValue, MapToKeyValueOp<CPUContext>);
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
OPERATOR_SCHEMA(CreateMap)
.NumInputs(0)
.NumOutputs(1)
.SetDoc("Create an empty map blob")
.Arg("key_dtype", "Key's TensorProto::DataType (default INT32)")
.Arg("value_dtype", "Value's TensorProto::DataType (default INT32)")
.Output(0, "map blob", "Blob reference to the map")
.ScalarType(TensorProto_DataType_UNDEFINED);
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
OPERATOR_SCHEMA(KeyValueToMap)
.NumInputs(2)
.NumOutputs(1)
.SetDoc("Convert key and value blob pairs into a map blob")
.Input(0, "key blob", "Blob reference to the key")
.Input(1, "value blob", "Blob reference to the value")
.Output(0, "map blob", "Blob reference to the map");
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
OPERATOR_SCHEMA(MapToKeyValue)
.NumInputs(1)
.NumOutputs(2)
.SetDoc("Convert a map blob into key and value blob pairs")
.Input(0, "map blob", "Blob reference to the map")
.Output(0, "key blob", "Blob reference to the key")
.Output(1, "value blob", "Blob reference to the value");
}
} // namespace caffe2