summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstruss <rrstrous@nate.com>2020-06-25 15:46:21 +0900
committerGitHub <noreply@github.com>2020-06-25 15:46:21 +0900
commitd590b746d3072b86ef322c3cca1601f10096d342 (patch)
tree7028eec73f3dd69191624fd7ab266c726cd24154
parent5c86e8b69e95be1bd6c985b2738be26d52dcade6 (diff)
downloadnnfw-d590b746d3072b86ef322c3cca1601f10096d342.tar.gz
nnfw-d590b746d3072b86ef322c3cca1601f10096d342.tar.bz2
nnfw-d590b746d3072b86ef322c3cca1601f10096d342.zip
[luci/lang]Add SparseToDense Operation on luci/lang (#2605)
* [luci/lang]Add SparseToDense Operation on luci/lang This commit add `SparseToDense` operation on luci/lang. ONE-DCO-1.0-Signed-off-by: KiDeuk Bang <rrstrous@nate.com> * Update Test name and add negative case on it.
-rw-r--r--compiler/luci/lang/include/luci/IR/CircleNodes.h1
-rw-r--r--compiler/luci/lang/include/luci/IR/CircleNodes.lst1
-rw-r--r--compiler/luci/lang/include/luci/IR/Nodes/CircleSparseToDense.h57
-rw-r--r--compiler/luci/lang/src/Nodes/CircleSparseToDense.test.cpp93
4 files changed, 152 insertions, 0 deletions
diff --git a/compiler/luci/lang/include/luci/IR/CircleNodes.h b/compiler/luci/lang/include/luci/IR/CircleNodes.h
index e17b469de..e4ea6ea67 100644
--- a/compiler/luci/lang/include/luci/IR/CircleNodes.h
+++ b/compiler/luci/lang/include/luci/IR/CircleNodes.h
@@ -97,6 +97,7 @@
#include "Nodes/CircleSoftmax.h"
#include "Nodes/CircleSpaceToBatchND.h"
#include "Nodes/CircleSpaceToDepth.h"
+#include "Nodes/CircleSparseToDense.h"
#include "Nodes/CircleSplit.h"
#include "Nodes/CircleSplitV.h"
#include "Nodes/CircleSqrt.h"
diff --git a/compiler/luci/lang/include/luci/IR/CircleNodes.lst b/compiler/luci/lang/include/luci/IR/CircleNodes.lst
index 6d0ccaf05..6b24a86f8 100644
--- a/compiler/luci/lang/include/luci/IR/CircleNodes.lst
+++ b/compiler/luci/lang/include/luci/IR/CircleNodes.lst
@@ -91,6 +91,7 @@ CIRCLE_NODE(SLICE, luci::CircleSlice)
CIRCLE_NODE(SOFTMAX, luci::CircleSoftmax)
CIRCLE_NODE(SPACE_TO_BATCH_ND, luci::CircleSpaceToBatchND)
CIRCLE_NODE(SPACE_TO_DEPTH, luci::CircleSpaceToDepth)
+CIRCLE_NODE(SPARSE_TO_DENSE, luci::CircleSparseToDense)
CIRCLE_NODE(SPLIT, luci::CircleSplit)
CIRCLE_NODE(SPLIT_V, luci::CircleSplitV)
CIRCLE_NODE(SQRT, luci::CircleSqrt)
diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleSparseToDense.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleSparseToDense.h
new file mode 100644
index 000000000..9f5051317
--- /dev/null
+++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleSparseToDense.h
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __LUCI_IR_CIRCELSPARSETODENSE_H__
+#define __LUCI_IR_CIRCELSPARSETODENSE_H__
+
+#include "luci/IR/CircleNodeDecl.h"
+#include "luci/IR/CircleOpcode.h"
+
+#include "luci/IR/LuciNodeMixins.h"
+
+namespace luci
+{
+
+/**
+ * @brief SPARSE_TO_DENSE in Circle
+ */
+class CircleSparseToDense final
+ : public FixedArityNode<4, CircleNodeImpl<CircleOpcode::SPARSE_TO_DENSE>>
+{
+public:
+ loco::Node *indices(void) const { return at(0)->node(); }
+ void indices(loco::Node *node) { at(0)->node(node); }
+
+ loco::Node *output_shape(void) const { return at(1)->node(); }
+ void output_shape(loco::Node *node) { at(1)->node(node); }
+
+ loco::Node *values(void) const { return at(2)->node(); }
+ void values(loco::Node *node) { at(2)->node(node); }
+
+ loco::Node *default_value(void) const { return at(3)->node(); }
+ void default_value(loco::Node *node) { at(3)->node(node); }
+
+public:
+ bool validate_indices(void) const { return _validate_indices; }
+ void validate_indices(bool validate_indices) { _validate_indices = validate_indices; }
+
+private:
+ bool _validate_indices{true};
+};
+
+} // namespace luci
+
+#endif // __LUCI_IR_CIRCELSPARSETODENSE_H__
diff --git a/compiler/luci/lang/src/Nodes/CircleSparseToDense.test.cpp b/compiler/luci/lang/src/Nodes/CircleSparseToDense.test.cpp
new file mode 100644
index 000000000..de3cf6e9a
--- /dev/null
+++ b/compiler/luci/lang/src/Nodes/CircleSparseToDense.test.cpp
@@ -0,0 +1,93 @@
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "luci/IR/Nodes/CircleSparseToDense.h"
+
+#include "luci/IR/CircleDialect.h"
+#include "luci/IR/CircleNodeVisitor.h"
+
+#include <gtest/gtest.h>
+
+TEST(CircleSparseToDenseTest, constructor)
+{
+ luci::CircleSparseToDense stb_node;
+
+ ASSERT_EQ(luci::CircleDialect::get(), stb_node.dialect());
+ ASSERT_EQ(luci::CircleOpcode::SPARSE_TO_DENSE, stb_node.opcode());
+
+ ASSERT_EQ(nullptr, stb_node.indices());
+ ASSERT_EQ(nullptr, stb_node.output_shape());
+ ASSERT_EQ(nullptr, stb_node.values());
+ ASSERT_EQ(nullptr, stb_node.default_value());
+
+ ASSERT_EQ(true, stb_node.validate_indices());
+}
+
+TEST(CircleSparseToDenseTest, input_NEG)
+{
+ luci::CircleSparseToDense stb_node;
+ luci::CircleSparseToDense node;
+
+ stb_node.indices(&node);
+ stb_node.output_shape(&node);
+ stb_node.values(&node);
+ stb_node.default_value(&node);
+ ASSERT_NE(nullptr, stb_node.indices());
+ ASSERT_NE(nullptr, stb_node.output_shape());
+ ASSERT_NE(nullptr, stb_node.values());
+ ASSERT_NE(nullptr, stb_node.default_value());
+
+ stb_node.indices(nullptr);
+ stb_node.output_shape(nullptr);
+ stb_node.values(nullptr);
+ stb_node.default_value(nullptr);
+ ASSERT_EQ(nullptr, stb_node.indices());
+ ASSERT_EQ(nullptr, stb_node.output_shape());
+ ASSERT_EQ(nullptr, stb_node.values());
+ ASSERT_EQ(nullptr, stb_node.default_value());
+}
+
+TEST(CircleSparseToDenseTest, arity_NEG)
+{
+ luci::CircleSparseToDense stb_node;
+
+ ASSERT_NO_THROW(stb_node.arg(3));
+ ASSERT_THROW(stb_node.arg(4), std::out_of_range);
+}
+
+TEST(CircleSparseToDenseTest, visit_mutable_NEG)
+{
+ struct TestVisitor final : public luci::CircleNodeMutableVisitor<void>
+ {
+ };
+
+ luci::CircleSparseToDense stb_node;
+
+ TestVisitor tv;
+ ASSERT_THROW(stb_node.accept(&tv), std::exception);
+}
+
+TEST(CircleSparseToDenseTest, visit_NEG)
+{
+ struct TestVisitor final : public luci::CircleNodeVisitor<void>
+ {
+ };
+
+ luci::CircleSparseToDense stb_node;
+
+ TestVisitor tv;
+ ASSERT_THROW(stb_node.accept(&tv), std::exception);
+}