Caffe2 - C++ API
A deep learning, cross platform ML framework
map_ops.cc
1 
17 #include "caffe2/operators/map_ops.h"
18 
19 namespace caffe2 {
20 
21 using MapType64To64 = MapTypeTraits<int64_t, int64_t>::MapType;
22 CAFFE_KNOWN_TYPE(MapType64To64);
23 
24 using MapType64To32 = MapTypeTraits<int64_t, int32_t>::MapType;
25 CAFFE_KNOWN_TYPE(MapType64To32);
26 
27 using MapType32To32 = MapTypeTraits<int32_t, int32_t>::MapType;
28 CAFFE_KNOWN_TYPE(MapType32To32);
29 
30 using MapType32To64 = MapTypeTraits<int32_t, int64_t>::MapType;
31 CAFFE_KNOWN_TYPE(MapType32To64);
32 
33 namespace {
34 
35 REGISTER_BLOB_SERIALIZER(
36  TypeMeta::Id<MapType64To64>(),
37  MapSerializer<int64_t, int64_t>);
38 
39 REGISTER_BLOB_SERIALIZER(
40  TypeMeta::Id<MapType64To32>(),
41  MapSerializer<int64_t, int32_t>);
42 
43 REGISTER_BLOB_SERIALIZER(
44  TypeMeta::Id<MapType32To32>(),
45  MapSerializer<int32_t, int32_t>);
46 
47 REGISTER_BLOB_SERIALIZER(
48  TypeMeta::Id<MapType32To64>(),
49  MapSerializer<int32_t, int64_t>);
50 
51 REGISTER_BLOB_DESERIALIZER(
52  (std::unordered_map<int64_t, int64_t>),
53  MapDeserializer<int64_t, int64_t>);
54 
55 REGISTER_BLOB_DESERIALIZER(
56  (std::unordered_map<int64_t, int32_t>),
57  MapDeserializer<int64_t, int32_t>);
58 
59 REGISTER_BLOB_DESERIALIZER(
60  (std::unordered_map<int32_t, int32_t>),
61  MapDeserializer<int32_t, int32_t>);
62 
63 REGISTER_BLOB_DESERIALIZER(
64  (std::unordered_map<int32_t, int64_t>),
65  MapDeserializer<int32_t, int64_t>);
66 
67 REGISTER_CPU_OPERATOR(CreateMap, CreateMapOp<CPUContext>);
68 REGISTER_CPU_OPERATOR(KeyValueToMap, KeyValueToMapOp<CPUContext>);
69 REGISTER_CPU_OPERATOR(MapToKeyValue, MapToKeyValueOp<CPUContext>);
70 
71 OPERATOR_SCHEMA(CreateMap)
72  .NumInputs(0)
73  .NumOutputs(1)
74  .SetDoc("Create an empty map blob")
75  .Arg("key_dtype", "Key's TensorProto::DataType (default INT32)")
76  .Arg("value_dtype", "Value's TensorProto::DataType (default INT32)")
77  .Output(0, "map blob", "Blob reference to the map");
78 
79 OPERATOR_SCHEMA(KeyValueToMap)
80  .NumInputs(2)
81  .NumOutputs(1)
82  .SetDoc("Convert key and value blob pairs into a map blob")
83  .Input(0, "key blob", "Blob reference to the key")
84  .Input(1, "value blob", "Blob reference to the value")
85  .Output(0, "map blob", "Blob reference to the map");
86 
87 OPERATOR_SCHEMA(MapToKeyValue)
88  .NumInputs(1)
89  .NumOutputs(2)
90  .SetDoc("Convert a map blob into key and value blob pairs")
91  .Input(0, "map blob", "Blob reference to the map")
92  .Output(0, "key blob", "Blob reference to the key")
93  .Output(1, "value blob", "Blob reference to the value");
94 }
95 } // namespace caffe2
Copyright (c) 2016-present, Facebook, Inc.