Caffe2 - C++ API
A deep learning, cross platform ML framework
map_ops.cc
1 #include "caffe2/operators/map_ops.h"
2 
3 namespace caffe2 {
4 
5 using MapType64To64 = MapTypeTraits<int64_t, int64_t>::MapType;
6 CAFFE_KNOWN_TYPE(MapType64To64);
7 
8 using MapType64To32 = MapTypeTraits<int64_t, int32_t>::MapType;
9 CAFFE_KNOWN_TYPE(MapType64To32);
10 
11 using MapType32To32 = MapTypeTraits<int32_t, int32_t>::MapType;
12 CAFFE_KNOWN_TYPE(MapType32To32);
13 
14 using MapType32To64 = MapTypeTraits<int32_t, int64_t>::MapType;
15 CAFFE_KNOWN_TYPE(MapType32To64);
16 
17 namespace {
18 
19 REGISTER_BLOB_SERIALIZER(
20  TypeMeta::Id<MapType64To64>(),
21  MapSerializer<int64_t, int64_t>);
22 
23 REGISTER_BLOB_SERIALIZER(
24  TypeMeta::Id<MapType64To32>(),
25  MapSerializer<int64_t, int32_t>);
26 
27 REGISTER_BLOB_SERIALIZER(
28  TypeMeta::Id<MapType32To32>(),
29  MapSerializer<int32_t, int32_t>);
30 
31 REGISTER_BLOB_SERIALIZER(
32  TypeMeta::Id<MapType32To64>(),
33  MapSerializer<int32_t, int64_t>);
34 
35 REGISTER_BLOB_DESERIALIZER(
36  (std::unordered_map<int64_t, int64_t>),
37  MapDeserializer<int64_t, int64_t>);
38 
39 REGISTER_BLOB_DESERIALIZER(
40  (std::unordered_map<int64_t, int32_t>),
41  MapDeserializer<int64_t, int32_t>);
42 
43 REGISTER_BLOB_DESERIALIZER(
44  (std::unordered_map<int32_t, int32_t>),
45  MapDeserializer<int32_t, int32_t>);
46 
47 REGISTER_BLOB_DESERIALIZER(
48  (std::unordered_map<int32_t, int64_t>),
49  MapDeserializer<int32_t, int64_t>);
50 
51 REGISTER_CPU_OPERATOR(CreateMap, CreateMapOp<CPUContext>);
52 REGISTER_CPU_OPERATOR(KeyValueToMap, KeyValueToMapOp<CPUContext>);
53 REGISTER_CPU_OPERATOR(MapToKeyValue, MapToKeyValueOp<CPUContext>);
54 
55 OPERATOR_SCHEMA(CreateMap)
56  .NumInputs(0)
57  .NumOutputs(1)
58  .SetDoc("Create an empty map blob")
59  .Arg("key_dtype", "Key's TensorProto::DataType (default INT32)")
60  .Arg("value_dtype", "Value's TensorProto::DataType (default INT32)")
61  .Output(0, "map blob", "Blob reference to the map")
62  .ScalarType(TensorProto_DataType_UNDEFINED);
63 
64 OPERATOR_SCHEMA(KeyValueToMap)
65  .NumInputs(2)
66  .NumOutputs(1)
67  .SetDoc("Convert key and value blob pairs into a map blob")
68  .Input(0, "key blob", "Blob reference to the key")
69  .Input(1, "value blob", "Blob reference to the value")
70  .Output(0, "map blob", "Blob reference to the map");
71 
72 OPERATOR_SCHEMA(MapToKeyValue)
73  .NumInputs(1)
74  .NumOutputs(2)
75  .SetDoc("Convert a map blob into key and value blob pairs")
76  .Input(0, "map blob", "Blob reference to the map")
77  .Output(0, "key blob", "Blob reference to the key")
78  .Output(1, "value blob", "Blob reference to the value");
79 }
80 } // namespace caffe2
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...
Definition: blob.h:13