forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathivalue.cpp
83 lines (68 loc) · 2.03 KB
/
ivalue.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <ATen/core/ivalue.h>
#include <ATen/core/Formatting.h>
#define TORCH_FORALL_TAGS(_) \
_(None) \
_(Tensor) \
_(Double) \
_(Int) \
_(Bool) \
_(Tuple) \
_(IntList) \
_(DoubleList) \
_(BoolList) \
_(String) \
_(TensorList) \
_(Blob) \
_(GenericList) \
_(World) \
_(Future) \
namespace c10 {
namespace ivalue {
CAFFE2_API c10::intrusive_ptr<ConstantString> ConstantString::create(
std::string str_) {
return c10::make_intrusive<ConstantString>(std::move(str_));
}
namespace {
template<typename Elem>
std::ostream& printList(std::ostream & out, const List<Elem> &v,
const std::string start, const std::string delim, const std::string finish) {
out << start;
for(size_t i = 0; i < v.elements().size(); ++i) {
if(i > 0)
out << delim;
out << v.elements()[i];
}
out << finish;
return out;
}
} // anonymous namespace
template<typename PointerType>
std::ostream& operator<<(std::ostream & out, const Shared<PointerType> & v) {
return out << *v;
}
std::ostream& operator<<(std::ostream & out, const ConstantString & v) {
return out << v.string();
}
std::ostream& operator<<(std::ostream & out, const Future & v) {
return out << "Future";
}
template<typename Elem>
std::ostream& operator<<(std::ostream & out, const List<Elem> & v) {
return printList<Elem>(out, v, "[", ", ", "]");
}
// tuple case
template<>
std::ostream& operator<<(std::ostream & out, const List<IValue> & v) {
return printList<IValue>(out, v, "(", ", ", ")");
}
} // namespace ivalue
std::ostream& operator<<(std::ostream & out, const IValue & v) {
switch(v.tag) {
#define DEFINE_CASE(x) case IValue::Tag::x: return out << v.to ## x();
TORCH_FORALL_TAGS(DEFINE_CASE)
#undef DEFINE_CASE
}
AT_ERROR("Tag not found\n");
}
#undef TORCH_FORALL_TAGS
} // namespace c10