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
1bfda4d3
Commit
1bfda4d3
authored
Oct 05, 2018
by
雾雨魔理沙
Committed by
Tianqi Chen
Oct 05, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Relay] [Op] zeros_like and ones_like (#1835)
parent
3aaafc38
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
61 additions
and
4 deletions
+61
-4
docs/langref/relay_op.rst
+6
-0
python/tvm/relay/op/tensor.py
+32
-0
src/relay/op/tensor/unary.cc
+10
-4
tests/python/relay/test_op_level3.py
+13
-0
No files found.
docs/langref/relay_op.rst
View file @
1bfda4d3
...
@@ -41,6 +41,12 @@ This level enables typical convnet models.
...
@@ -41,6 +41,12 @@ This level enables typical convnet models.
**Level 3: Additional Math And Transform Operators**
**Level 3: Additional Math And Transform Operators**
.. autosummary::
:nosignatures:
tvm.relay.zeros_like
tvm.relay.ones_like
**Level 4: Broadcast and Reductions**
**Level 4: Broadcast and Reductions**
.. autosummary::
.. autosummary::
...
...
python/tvm/relay/op/tensor.py
View file @
1bfda4d3
...
@@ -295,3 +295,35 @@ def concat(*args):
...
@@ -295,3 +295,35 @@ def concat(*args):
"""
"""
tup
=
Tuple
(
list
(
args
))
tup
=
Tuple
(
list
(
args
))
return
_make
.
concat
(
tup
)
return
_make
.
concat
(
tup
)
def
zeros_like
(
data
):
"""Returns an array of zeros, with same type and shape as the input.
Parameters
----------
data : relay.Expr
The input data
Returns
-------
result : relay.Expr
The computed result.
"""
return
_make
.
zeros_like
(
data
)
def
ones_like
(
data
):
"""Returns an array of ones, with same type and shape as the input.
Parameters
----------
data : relay.Expr
The input data
Returns
-------
result : relay.Expr
The computed result.
"""
return
_make
.
ones_like
(
data
)
src/relay/op/tensor/unary.cc
View file @
1bfda4d3
...
@@ -56,14 +56,21 @@ RELAY_REGISTER_UNARY_OP("exp")
...
@@ -56,14 +56,21 @@ RELAY_REGISTER_UNARY_OP("exp")
RELAY_REGISTER_UNARY_OP
(
"sqrt"
)
RELAY_REGISTER_UNARY_OP
(
"sqrt"
)
.
describe
(
R"code(Returns the sqrt input array, computed element-wise.
.
describe
(
R"code(Returns the sqrt input array, computed element-wise.
)code"
TVM_ADD_FILELINE
)
.
set_support_level
(
1
)
.
add_type_rel
(
"Identity"
,
IdentityRel
);
.. math::
RELAY_REGISTER_UNARY_OP
(
"zeros_like"
)
sqrt(x)
.
describe
(
R"code(Returns an array of zeros, with same type and shape as the input.
)code"
TVM_ADD_FILELINE
)
)code"
TVM_ADD_FILELINE
)
.
set_support_level
(
1
)
.
set_support_level
(
1
)
.
add_type_rel
(
"Identity"
,
IdentityRel
);
.
add_type_rel
(
"Identity"
,
IdentityRel
);
RELAY_REGISTER_UNARY_OP
(
"ones_like"
)
.
describe
(
R"code(Returns an array of ones, with same type and shape as the input.
)code"
TVM_ADD_FILELINE
)
.
set_support_level
(
1
)
.
add_type_rel
(
"Identity"
,
IdentityRel
);
RELAY_REGISTER_UNARY_OP
(
"sigmoid"
)
RELAY_REGISTER_UNARY_OP
(
"sigmoid"
)
.
describe
(
R"code(Returns the sigmoid input array, computed element-wise.
.
describe
(
R"code(Returns the sigmoid input array, computed element-wise.
...
@@ -75,7 +82,6 @@ RELAY_REGISTER_UNARY_OP("sigmoid")
...
@@ -75,7 +82,6 @@ RELAY_REGISTER_UNARY_OP("sigmoid")
.
set_support_level
(
1
)
.
set_support_level
(
1
)
.
add_type_rel
(
"Identity"
,
IdentityRel
);
.
add_type_rel
(
"Identity"
,
IdentityRel
);
// Concat
// Concat
TVM_REGISTER_API
(
"relay.op._make.concat"
)
TVM_REGISTER_API
(
"relay.op._make.concat"
)
.
set_body_typed
<
Expr
(
Expr
)
>
([](
Expr
tuple
)
{
.
set_body_typed
<
Expr
(
Expr
)
>
([](
Expr
tuple
)
{
...
...
tests/python/relay/test_op_level3.py
0 → 100644
View file @
1bfda4d3
import
tvm
from
tvm
import
relay
def
test_unary_identity
():
for
op
in
[
relay
.
zeros_like
,
relay
.
ones_like
]:
ib
=
relay
.
ir_builder
.
IRBuilder
()
x
=
ib
.
param
(
"x"
,
relay
.
TensorType
((
8
,
9
,
4
),
"int32"
))
with
ib
.
function
(
x
)
as
func
:
ib
.
ret
(
op
(
x
.
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
((
8
,
9
,
4
),
"int32"
)
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