| 296 | } |
| 297 | |
| 298 | Status AddConsumer(NodeId consumer, ValueId value) final { |
| 299 | ValueDef* v; |
| 300 | RETURN_IF_ERROR(LookupValue(value, &v)); |
| 301 | Value<TensorT>* value_ptr = v->value.get(); |
| 302 | NodeDef* n; |
| 303 | RETURN_IF_ERROR(LookupNode(consumer, &n)); |
| 304 | Node* node_ptr = n->node.get(); |
| 305 | |
| 306 | // check if this value has the same producer already |
| 307 | if (node_ptr == v->producer) { |
| 308 | return InvalidArgumentError("Node is a producer of the value"); |
| 309 | } |
| 310 | |
| 311 | // check if this value has the same consumer already |
| 312 | if (std::find(n->inputs.begin(), n->inputs.end(), value_ptr) != |
| 313 | n->inputs.end()) { |
| 314 | return InvalidArgumentError("Node is already a consumer of the value"); |
| 315 | } |
| 316 | |
| 317 | n->inputs.push_back(value_ptr); |
| 318 | v->consumers.push_back(node_ptr); |
| 319 | return OkStatus(); |
| 320 | } |
| 321 | |
| 322 | Status RemoveConsumer(NodeId consumer, ValueId value) final { |
| 323 | ValueDef* v; |