MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / BuildConstNode

Function BuildConstNode

tensorflow/lite/toco/import_tensorflow_test.cc:100–160  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

98
99namespace {
100void BuildConstNode(std::initializer_list<int64_t> shape,
101 tensorflow::DataType dtype, int64_t num_elements,
102 NodeDef* node) {
103 node->set_op("Const");
104 node->set_name("Node1");
105
106 // An attribute describing the type of this const node.
107 AttrValue dtype_attr;
108 SetAttrValue(dtype, &dtype_attr);
109 (*node->mutable_attr())["dtype"] = dtype_attr;
110
111 // An attribute describing the content of this const node.
112 tensorflow::TensorProto t;
113 t.set_dtype(dtype);
114 auto* s = t.mutable_tensor_shape();
115 for (auto d : shape) {
116 s->add_dim()->set_size(d);
117 }
118
119 switch (dtype) {
120 case DT_FLOAT:
121 for (int64_t i = 0; i < num_elements; ++i) {
122 t.add_float_val(i / 10000.0 + 1);
123 }
124 break;
125 case DT_INT32:
126 for (int64_t i = 0; i < num_elements; ++i) {
127 t.add_int_val(i % std::numeric_limits<int>::max() + 1);
128 }
129 break;
130 case DT_QUINT8:
131 for (int64_t i = 0; i < num_elements; ++i) {
132 t.add_int_val(i % std::numeric_limits<uint8_t>::max() + 1);
133 }
134 break;
135 case DT_INT64:
136 for (int64_t i = 0; i < num_elements; ++i) {
137 t.add_int64_val(i + 1);
138 }
139 break;
140 case DT_STRING:
141 break;
142 case DT_BOOL:
143 for (int64_t i = 0; i < num_elements; ++i) {
144 t.add_bool_val((i % 2) == 0);
145 }
146 break;
147 case DT_COMPLEX64:
148 for (int64_t i = 0; i < num_elements; ++i) {
149 t.add_scomplex_val(i / 10000.0 + 1);
150 t.add_scomplex_val(-i / 10000.0 - 1);
151 }
152 break;
153 default:
154 break;
155 }
156
157 AttrValue value_attr;

Callers 3

TESTFunction · 0.85
TEST_PFunction · 0.85
TEST_FFunction · 0.85

Calls 6

set_opMethod · 0.80
SetAttrValueFunction · 0.50
maxFunction · 0.50
set_nameMethod · 0.45
set_dtypeMethod · 0.45
set_sizeMethod · 0.45

Tested by

no test coverage detected