ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Operation.cpp
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
3
*
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
7
*
8
* http://www.apache.org/licenses/LICENSE-2.0
9
*
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.
15
*/
16
17
#include "
mir/Operation.h
"
18
#include "
mir/ops/ConcatOp.h
"
19
#include "
mir/ops/InputOp.h
"
20
#include "
mir/ops/ReshapeOp.h
"
21
#include "
mir/ops/SoftmaxOp.h
"
22
23
#include <gtest/gtest.h>
24
25
using namespace
mir
;
26
27
TEST
(
Operation
, ConnectionTest)
28
{
29
30
mir::TensorType
input_type{mir::DataType::FLOAT32,
Shape
{}};
31
auto
op1 =
new
ops::InputOp
(input_type);
32
op1->setId(0);
33
auto
op2 =
new
ops::ReshapeOp
(op1->getOutput(0),
Shape
{});
34
op2->setId(1);
35
36
ASSERT_EQ(op1, op2->getInput(0)->getNode());
37
38
delete
op1;
39
delete
op2;
40
}
41
42
TEST
(
Operation
, InputOutputShapeTest)
43
{
44
Shape
input_shape{1, 2, 3};
45
46
mir::TensorType
input_type{mir::DataType::FLOAT32, input_shape};
47
ops::InputOp
input(input_type);
48
ops::SoftmaxOp
op(input.getOutput(0), 0);
49
50
ASSERT_EQ(input_shape, input.getOutputShape(0));
51
ASSERT_EQ(input_shape, op.
getInputShape
(0));
52
}
53
54
TEST
(
Operation
, SoftmaxAxisTest)
55
{
56
Shape
input_shape{1, 2, 3};
57
58
mir::TensorType
input_type{mir::DataType::FLOAT32, input_shape};
59
ops::InputOp
input(input_type);
60
61
ops::SoftmaxOp
op_1(input.getOutput(0), 1);
62
ASSERT_EQ(op_1.
getAxis
(), 1);
63
64
ops::SoftmaxOp
op_n1(input.getOutput(0), -1);
65
ASSERT_EQ(op_n1.
getAxis
(), 2);
66
67
ops::SoftmaxOp
op_n3(input.getOutput(0), -3);
68
ASSERT_EQ(op_n3.
getAxis
(), 0);
69
}
70
71
TEST
(
Operation
, ConcatAxisTest)
72
{
73
Shape
in_shape{1, 2, 3};
74
75
mir::TensorType
in_type{mir::DataType::FLOAT32, in_shape};
76
ops::InputOp
input1(in_type), input2(in_type);
77
78
ops::ConcatOp
op_1({input1.getOutput(0), input2.
getOutput
(0)}, 1);
79
ASSERT_EQ(op_1.getAxis(), 1);
80
81
ops::ConcatOp
op_n1({input1.getOutput(0), input2.
getOutput
(0)}, -1);
82
ASSERT_EQ(op_n1.getAxis(), 2);
83
84
ops::ConcatOp
op_n3({input1.getOutput(0), input2.
getOutput
(0)}, -3);
85
ASSERT_EQ(op_n3.getAxis(), 0);
86
}
87
88
TEST
(
Operation
, OpNameTest)
89
{
90
#define HANDLE_OP(OpType, OpClass) ASSERT_EQ(getTypeName(Operation::Type::OpType), #OpType);
91
#include "
mir/Operations.inc
"
92
#undef HANDLE_OP
93
}
ConcatOp.h
InputOp.h
Operations.inc
ReshapeOp.h
SoftmaxOp.h
mir::Operation::getOutput
Output * getOutput(std::size_t index)
Definition
Operation.h:149
mir::Operation::getInputShape
const Shape & getInputShape(std::size_t index) const
Definition
Operation.h:161
mir::TensorType
Definition
TensorType.h:28
mir::ops::ConcatOp
Description of tensor concatenation operation.
Definition
ConcatOp.h:31
mir::ops::InputOp
Definition
InputOp.h:28
mir::ops::ReshapeOp
Definition
ReshapeOp.h:28
mir::ops::SoftmaxOp
description of softmax operation.
Definition
SoftmaxOp.h:31
mir::ops::SoftmaxOp::getAxis
int32_t getAxis() const
Definition
SoftmaxOp.h:43
Operation.h
mir
Definition
Attributes.h:25
Operation
Definition
Operation.h:26
Shape
Definition
Shape.h:28
TEST
TEST(Operation, ConnectionTest)
Definition
Operation.cpp:27
compiler
mir
unittests
Operation.cpp
Generated by
1.9.8