2 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "luci/Import/Nodes/CircleOneHot.h"
19 #include <luci/IR/Nodes/CircleOneHot.h>
22 #include <oops/UserExn.h>
27 bool CircleOneHotGraphBuilder::validate(const ValidateArgs &args) const
29 const auto &inputs = args.op.inputs;
30 const auto &outputs = args.op.outputs;
31 const auto *options = args.op.builtin_options.AsOneHotOptions();
33 // Only 4 Input come refered from
34 if (inputs.size() != 4)
37 if (outputs.size() != 1)
40 const auto &tensors = args.reader.tensors();
41 const auto &indices = tensors.at(inputs.at(0));
42 const auto &depth = tensors.at(inputs.at(1));
43 const auto &on_value = tensors.at(inputs.at(2));
44 const auto &off_value = tensors.at(inputs.at(3));
46 if (options->axis < -1 || options->axis > static_cast<int32_t>(indices->shape.size()))
48 if (depth->shape.size() != 0)
50 if (on_value->shape.size() != 0)
52 if (off_value->shape.size() != 0)
54 if (on_value->type != off_value->type)
60 CircleNode *CircleOneHotGraphBuilder::build_node(const circle::OperatorT &op,
61 const std::vector<CircleNode *> &inputs,
62 loco::Graph *graph) const
64 auto *node = graph->nodes()->create<CircleOneHot>();
66 node->indices(inputs.at(0));
67 node->depth(inputs.at(1));
68 node->on_value(inputs.at(2));
69 node->off_value(inputs.at(3));
71 const auto *options = op.builtin_options.AsOneHotOptions();
72 node->axis(options->axis);