File indexing completed on 2025-04-03 08:57:54
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010 #include <limits>
0011 #include <memory>
0012
0013 namespace ONNX_NAMESPACE {
0014 namespace version_conversion {
0015
0016 class Clip_10_11 final : public Adapter {
0017 public:
0018 explicit Clip_10_11() : Adapter("Clip", OpSetID(10), OpSetID(11)) {}
0019
0020 void adapt_clip_10_11(std::shared_ptr<Graph> graph, Node* node) const {
0021 bool has_min = node->hasAttribute(kmin);
0022 bool has_max = node->hasAttribute(kmax);
0023
0024
0025 if (has_min) {
0026 attrToInput(graph, node, node->f(kmin));
0027 node->removeAttribute(kmin);
0028 }
0029 if (has_max) {
0030 if (!has_min) {
0031 attrToInput(graph, node, std::numeric_limits<float>::lowest());
0032 }
0033 attrToInput(graph, node, node->f(kmax));
0034 node->removeAttribute(kmax);
0035 }
0036 }
0037
0038 void attrToInput(std::shared_ptr<Graph> graph, Node* node, float val) const {
0039 Tensor t;
0040 t.elem_type() = TensorProto_DataType_FLOAT;
0041 auto& data = t.floats();
0042 data.emplace_back(val);
0043 Node* constant = graph->create(kConstant);
0044 constant->insertBefore(node);
0045 constant->t_(kvalue, t);
0046 node->addInput(constant->output());
0047 }
0048
0049 Node* adapt(std::shared_ptr<Graph> graph, Node* node) const override {
0050 adapt_clip_10_11(graph, node);
0051 return node;
0052 }
0053 };
0054
0055 }
0056 }