Commit eec3648a by Meghan Cowan Committed by Tianqi Chen

[RELAY] Add sigmoid relay operator (#1836)

parent b90620ea
......@@ -25,6 +25,7 @@ This level enables fully connected multi-layer perceptron.
tvm.relay.log
tvm.relay.sqrt
tvm.relay.exp
tvm.relay.sigmoid
tvm.relay.add
tvm.relay.expand_dims
......@@ -61,6 +62,7 @@ Level 1 Definitions
.. autofunction:: tvm.relay.log
.. autofunction:: tvm.relay.sqrt
.. autofunction:: tvm.relay.exp
.. autofunction:: tvm.relay.sigmoid
.. autofunction:: tvm.relay.add
......
......@@ -60,6 +60,22 @@ def sqrt(data):
return _make.sqrt(data)
def sigmoid(data):
"""Compute elementwise sigmoid of data.
Parameters
----------
data : relay.Expr
The input data
Returns
-------
result : relay.Expr
The computed result.
"""
return _make.sigmoid(data)
def add(lhs, rhs):
"""Addition with numpy-style broadcasting.
......
......@@ -65,6 +65,17 @@ RELAY_REGISTER_UNARY_OP("sqrt")
.add_type_rel("Identity", IdentityRel);
RELAY_REGISTER_UNARY_OP("sigmoid")
.describe(R"code(Returns the sigmoid input array, computed element-wise.
.. math::
sigmoid(x)
)code" TVM_ADD_FILELINE)
.set_support_level(1)
.add_type_rel("Identity", IdentityRel);
// Concat
TVM_REGISTER_API("relay.op._make.concat")
.set_body_typed<Expr(Expr)>([](Expr tuple) {
......
......@@ -16,5 +16,21 @@ def test_expand_dims_infer_type():
(n, t, 1, 100), "float32")
def test_unary_op():
for op in [relay.exp,
relay.log,
relay.sqrt,
relay.sigmoid]:
ib = relay.ir_builder.IRBuilder()
x = ib.param("x", relay.TensorType((10, 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((10, 4), "int32")
if __name__ == "__main__":
test_expand_dims_infer_type()
test_unary_op()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment