dlinear  0.0.1
Delta-complete SMT solver for linear programming
Loading...
Searching...
No Matches
libonnx.cpp
1
6#include "libonnx.h"
7
8namespace dlinear {
9
10std::ostream &operator<<(std::ostream &os, const onnx::GraphProto &graph) {
11 return os << "GraphProto(" << graph.name() << ")";
12}
13
14std::ostream &operator<<(std::ostream &os, const onnx::TensorProto &tensor) {
15 os << "TensorProto(";
16 if (tensor.has_data_type()) os << "data_type: " << tensor.data_type() << ", ";
17 if (tensor.has_doc_string()) os << "doc_string: " << tensor.doc_string() << ", ";
18 if (tensor.has_name()) os << "name: " << tensor.name() << ", ";
19 if (tensor.has_segment()) os << "segment: " << tensor.segment() << ", ";
20 return os << "dims: " << tensor.dims() << ")";
21}
22
23std::ostream &operator<<(std::ostream &os, const google::protobuf::RepeatedField<int64_t> &int64s) {
24 os << "[";
25 std::copy(int64s.begin(), std::prev(int64s.end()), std::ostream_iterator<int64_t>(os, ", "));
26 return os << *(int64s.rbegin()) << "]";
27}
28
29std::ostream &operator<<(std::ostream &os, const onnx::TensorProto_Segment &tensor_segment) {
30 os << "TensorProto_Segment(";
31 if (tensor_segment.has_begin()) os << "begin: " << tensor_segment.begin() << ", ";
32 if (tensor_segment.has_end()) os << "end: " << tensor_segment.end() << ", ";
33 return os << ")";
34}
35
36std::ostream &operator<<(std::ostream &os, const onnx::SparseTensorProto &tensor) {
37 os << "SparseTensorProto(";
38 if (tensor.has_indices()) os << "indices: " << tensor.indices() << ", ";
39 if (tensor.has_values()) os << "values: " << tensor.values() << ", ";
40 std::cout << "dims: " << tensor.dims();
41 return os << ")";
42}
43
44std::ostream &operator<<(std::ostream &os, const onnx::AttributeProto &attribute) {
45 os << "AttributeProto(";
46 if (attribute.has_name()) os << "name: " << attribute.name() << ", ";
47 if (attribute.has_type()) os << "type: " << attribute.type() << ", ";
48 if (attribute.has_doc_string()) os << "doc_string: " << attribute.doc_string() << ", ";
49 if (attribute.has_f()) os << "f: " << attribute.f() << ", ";
50 if (attribute.has_i()) os << "i: " << attribute.i() << ", ";
51 if (attribute.has_s()) os << "s: " << attribute.s() << ", ";
52 if (attribute.has_t()) os << "t: " << attribute.t() << ", ";
53 if (attribute.has_g()) os << "g: " << attribute.g() << ", ";
54 if (attribute.has_sparse_tensor()) os << "sparse_tensor: " << attribute.sparse_tensor() << ", ";
55 if (attribute.floats_size() > 0) {
56 os << "floats: [";
57 std::copy(attribute.floats().begin(), std::prev(attribute.floats().end()), std::ostream_iterator<float>(os, ", "));
58 os << attribute.floats().rbegin()[0] << "], ";
59 }
60 if (attribute.ints_size() > 0) {
61 os << "ints: [";
62 std::copy(attribute.ints().begin(), std::prev(attribute.ints().end()), std::ostream_iterator<int64_t>(os, ", "));
63 os << attribute.ints().rbegin()[0] << "], ";
64 }
65 if (attribute.strings_size() > 0) {
66 os << "strings: [";
67 std::copy(attribute.strings().begin(), std::prev(attribute.strings().end()),
68 std::ostream_iterator<std::string>(os, ", "));
69 os << attribute.strings().rbegin()[0] << "], ";
70 }
71 if (attribute.tensors_size() > 0) {
72 os << "tensors: [";
73 for (const auto &tensor : attribute.tensors()) os << tensor << ", ";
74 os << "], ";
75 }
76 // if (attribute.graphs_size() > 0) {
77 // os << "graphs: [";
78 // std::copy(attribute.graphs().begin(), std::prev(attribute.graphs().end()),
79 // std::ostream_iterator<onnx::GraphProto>(os, ", "));
80 // os << *attribute.graphs().rbegin() << "], ";
81 // }
82 return os << ")";
83}
84
85std::ostream &operator<<(std::ostream &os, const onnx::NodeProto &node) {
86 os << "NodeProto(";
87 if (node.has_name()) os << "name: " << node.name() << ", ";
88 if (node.has_op_type()) os << "op_type: " << node.op_type() << ", ";
89 if (node.has_domain()) os << "domain: " << node.domain() << ", ";
90 if (node.has_doc_string()) os << "doc_string: " << node.doc_string() << ", ";
91 if (node.input_size() > 0) {
92 os << "inputs: [";
93 std::copy(node.input().begin(), std::prev(node.input().end()), std::ostream_iterator<std::string>(os, ", "));
94 os << node.input().rbegin()[0] << "], ";
95 }
96 if (node.output_size() > 0) {
97 os << "outputs: [";
98 std::copy(node.output().begin(), std::prev(node.output().end()), std::ostream_iterator<std::string>(os, ", "));
99 os << node.output().rbegin()[0] << "], ";
100 }
101 if (node.attribute_size() > 0) {
102 os << "attributes: [";
103 for (const auto &attr : node.attribute()) os << attr << ", ";
104 os << "], ";
105 }
106 return os << ")";
107}
108
109std::ostream &operator<<(std::ostream &os, const onnx::ValueInfoProto &value_info) {
110 os << "ValueInfoProto(";
111 if (value_info.has_name()) os << "name: " << value_info.name() << ", ";
112 if (value_info.has_type()) os << "type: " << value_info.type() << ", ";
113 if (value_info.has_doc_string()) os << "doc_string: " << value_info.doc_string() << ", ";
114 return os << ")";
115}
116
117std::ostream &operator<<(std::ostream &os, const onnx::TypeProto &type) {
118 os << "TypeProto(";
119 if (type.has_tensor_type()) os << "tensor_type: " << type.tensor_type() << ", ";
120 if (type.has_sequence_type()) os << "sequence_type: " << type.sequence_type() << ", ";
121 if (type.has_map_type()) os << "map_type: " << type.map_type() << ", ";
122 if (type.has_opaque_type()) os << "opaque_type: " << type.opaque_type() << ", ";
123 return os << ")";
124}
125
126std::ostream &operator<<(std::ostream &os, const onnx::TypeProto_Sequence &type_sequence) {
127 os << "TypeProto_Sequence(";
128 if (type_sequence.has_elem_type()) os << "elem_type: " << type_sequence.elem_type() << ", ";
129 return os << ")";
130}
131
132std::ostream &operator<<(std::ostream &os, const onnx::TypeProto_Map &type_map) {
133 os << "TypeProto_Map(";
134 if (type_map.has_key_type()) os << "key_type: " << type_map.key_type() << ", ";
135 if (type_map.has_value_type()) os << "value_type: " << type_map.value_type() << ", ";
136 return os << ")";
137}
138
139std::ostream &operator<<(std::ostream &os, const onnx::TypeProto_Tensor &type_tensor) {
140 os << "TypeProto_Tensor(";
141 if (type_tensor.has_elem_type()) os << "elem_type: " << type_tensor.elem_type() << ", ";
142 if (type_tensor.has_shape()) os << "shape: " << type_tensor.shape() << ", ";
143 return os << ")";
144}
145
146std::ostream &operator<<(std::ostream &os, const onnx::TypeProto_Opaque &type_opaque) {
147 os << "TypeProto_Opaque(";
148 if (type_opaque.has_domain()) os << "domain: " << type_opaque.domain() << ", ";
149 if (type_opaque.has_name()) os << "name: " << type_opaque.name() << ", ";
150 return os << ")";
151}
152
153std::ostream &operator<<(std::ostream &os, const onnx::TensorShapeProto &tensor_shape) {
154 os << "TensorShapeProto(";
155 for (const auto &dim : tensor_shape.dim()) os << "dim: " << dim << ", ";
156 return os << ")";
157}
158
159std::ostream &operator<<(std::ostream &os, const onnx::TensorShapeProto_Dimension &tensor_shape_dim) {
160 os << "TensorShapeProto_Dimension(";
161 if (tensor_shape_dim.has_denotation()) os << "denotation: " << tensor_shape_dim.denotation() << ", ";
162 if (tensor_shape_dim.has_dim_value()) os << "dim_value: " << tensor_shape_dim.dim_value() << ", ";
163 if (tensor_shape_dim.has_dim_param()) os << "dim_param: " << tensor_shape_dim.dim_param() << ", ";
164 return os << ")";
165}
166
167std::ostream &operator<<(std::ostream &os,
168 const google::protobuf::RepeatedPtrField<onnx::ValueInfoProto> &value_infos) {
169 os << "ValueInfoProto[";
170 for (const auto &value_info : value_infos) os << value_info << ", ";
171 return os << "]";
172}
173std::ostream &operator<<(std::ostream &os, const google::protobuf::RepeatedPtrField<onnx::TensorProto> &tensors) {
174 os << "TensorProto[";
175 for (const auto &tensor : tensors) os << tensor << ", ";
176 return os << "]";
177}
178
179} // namespace dlinear
Global namespace for the dlinear library.