Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
tic
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wenyuanbo
tic
Commits
d6ff734b
Commit
d6ff734b
authored
Oct 05, 2018
by
Junru Shao
Committed by
Tianqi Chen
Oct 05, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[RELAY][OP] comparison (#1824)
parent
160eaf54
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
158 additions
and
13 deletions
+158
-13
docs/langref/relay_op.rst
+9
-0
python/tvm/relay/op/tensor.py
+105
-0
src/relay/op/tensor/elemwise.cc
+20
-13
tests/python/relay/test_op_level4.py
+24
-0
No files found.
docs/langref/relay_op.rst
View file @
d6ff734b
...
...
@@ -42,6 +42,15 @@ This level enables typical convnet models.
**Level 4: Broadcast and Reductions**
.. autosummary::
:nosignatures:
tvm.relay.equal
tvm.relay.not_equal
tvm.relay.greater
tvm.relay.greater_equal
tvm.relay.less
tvm.relay.less_equal
**Level 5: Vision/Image Operators**
...
...
python/tvm/relay/op/tensor.py
View file @
d6ff734b
...
...
@@ -104,10 +104,115 @@ def subtract(lhs, rhs):
return
_make
.
subtract
(
lhs
,
rhs
)
def
equal
(
lhs
,
rhs
):
"""Broadcasted elementwise test for (lhs == rhs).
Parameters
----------
lhs : relay.Expr
The left hand side input data
rhs : relay.Expr
The right hand side input data
Returns
-------
result : relay.Expr
The computed result.
"""
return
_make
.
equal
(
lhs
,
rhs
)
def
not_equal
(
lhs
,
rhs
):
"""Broadcasted elementwise test for (lhs != rhs).
Parameters
----------
lhs : relay.Expr
The left hand side input data
rhs : relay.Expr
The right hand side input data
Returns
-------
result : relay.Expr
The computed result.
"""
return
_make
.
not_equal
(
lhs
,
rhs
)
def
less
(
lhs
,
rhs
):
"""Broadcasted elementwise test for (lhs < rhs).
Parameters
----------
lhs : relay.Expr
The left hand side input data
rhs : relay.Expr
The right hand side input data
Returns
-------
result : relay.Expr
The computed result.
"""
return
_make
.
less
(
lhs
,
rhs
)
def
less_equal
(
lhs
,
rhs
):
"""Broadcasted elementwise test for (lhs <= rhs).
Parameters
----------
lhs : relay.Expr
The left hand side input data
rhs : relay.Expr
The right hand side input data
Returns
-------
result : relay.Expr
The computed result.
"""
return
_make
.
less_equal
(
lhs
,
rhs
)
def
greater
(
lhs
,
rhs
):
"""Broadcasted elementwise test for (lhs > rhs).
Parameters
----------
lhs : relay.Expr
The left hand side input data
rhs : relay.Expr
The right hand side input data
Returns
-------
result : relay.Expr
The computed result.
"""
return
_make
.
greater
(
lhs
,
rhs
)
def
greater_equal
(
lhs
,
rhs
):
"""Broadcasted elementwise test for (lhs >= rhs).
Parameters
----------
lhs : relay.Expr
The left hand side input data
rhs : relay.Expr
The right hand side input data
Returns
-------
result : relay.Expr
The computed result.
"""
return
_make
.
greater_equal
(
lhs
,
rhs
)
def
concat
(
*
args
):
"""Concatenate the input tensors along the zero axis.
...
...
src/relay/op/tensor/elemwise.cc
View file @
d6ff734b
...
...
@@ -106,19 +106,26 @@ RELAY_REGISTER_OP("subtract")
// input2: Tensor[dtype, s2]
// output: Tensor[dtype, broadcast(s1, s2)]
// Equality Comparison
TVM_REGISTER_API
(
"relay.op._make.equal"
)
.
set_body_typed
<
Expr
(
Expr
,
Expr
)
>
([](
Expr
lhs
,
Expr
rhs
)
{
static
const
Op
&
op
=
Op
::
Get
(
"equal"
);
return
CallNode
::
make
(
op
,
{
lhs
,
rhs
},
Attrs
(),
{});
});
RELAY_REGISTER_OP
(
"equal"
)
.
set_num_inputs
(
2
)
.
add_argument
(
"lhs"
,
"Tensor"
,
"The left hand side tensor."
)
.
add_argument
(
"rhs"
,
"Tensor"
,
"The right hand side tensor."
)
.
set_support_level
(
1
)
.
add_type_rel
(
"BroadcastComp"
,
BroadcastCompRel
);
// Comparisons
#define RELAY_REGISTER_CMP_OP(OpName, SupportLevel) \
TVM_REGISTER_API("relay.op._make." OpName) \
.set_body_typed<Expr(Expr, Expr)>([](Expr lhs, Expr rhs) { \
static const Op& op = Op::Get(OpName); \
return CallNode::make(op, {lhs, rhs}, Attrs(), {}); \
}); \
RELAY_REGISTER_OP(OpName) \
.set_num_inputs(2) \
.add_argument("lhs", "Tensor", "The left hand side tensor.") \
.add_argument("rhs", "Tensor", "The right hand side tensor.") \
.set_support_level(SupportLevel) \
.add_type_rel("BroadcastComp", BroadcastCompRel);
RELAY_REGISTER_CMP_OP
(
"equal"
,
4
);
RELAY_REGISTER_CMP_OP
(
"not_equal"
,
4
);
RELAY_REGISTER_CMP_OP
(
"less"
,
4
);
RELAY_REGISTER_CMP_OP
(
"less_equal"
,
4
);
RELAY_REGISTER_CMP_OP
(
"greater"
,
4
);
RELAY_REGISTER_CMP_OP
(
"greater_equal"
,
4
);
// Concat
TVM_REGISTER_API
(
"relay.op._make.concat"
)
...
...
tests/python/relay/test_op_level4.py
0 → 100644
View file @
d6ff734b
import
tvm
from
tvm
import
relay
def
test_cmp_type
():
for
op
in
(
relay
.
greater
,
relay
.
greater_equal
,
relay
.
less
,
relay
.
less_equal
,
relay
.
equal
,
relay
.
not_equal
):
ib
=
relay
.
ir_builder
.
IRBuilder
()
x
=
ib
.
param
(
"x"
,
relay
.
TensorType
((
10
,
4
),
"float32"
))
y
=
ib
.
param
(
"y"
,
relay
.
TensorType
((
5
,
10
,
1
),
"float32"
))
with
ib
.
function
(
x
,
y
)
as
func
:
ib
.
ret
(
op
(
x
.
var
,
y
.
var
))
ib
.
ret
(
func
)
func
=
relay
.
ir_pass
.
infer_type
(
ib
.
env
,
func
.
to_func
())
ftype
=
func
.
checked_type
()
assert
ftype
.
ret_type
==
relay
.
TensorType
((
5
,
10
,
4
),
"uint1"
)
if
__name__
==
"__main__"
:
test_cmp_type
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment