Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RELAY][OP] Add relay minimum op #1840

Merged
merged 3 commits into from
Oct 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/langref/relay_op.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ This level enables typical convnet models.
tvm.relay.less
tvm.relay.less_equal
tvm.relay.maximum
tvm.relay.minimum

**Level 5: Vision/Image Operators**

Expand Down Expand Up @@ -89,4 +90,5 @@ Level 4 Definitions
.. autofunction:: tvm.relay.greater_equal
.. autofunction:: tvm.relay.less
.. autofunction:: tvm.relay.less_equal
.. autofunction:: tvm.relay.maximum
.. autofunction:: tvm.relay.maximum
.. autofunction:: tvm.relay.minimum
Mutinifni marked this conversation as resolved.
Show resolved Hide resolved
18 changes: 18 additions & 0 deletions python/tvm/relay/op/tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,24 @@ def maximum(lhs, rhs):
return _make.maximum(lhs, rhs)


def minimum(lhs, rhs):
"""Minimum with numpy-style broadcasting.

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.minimum(lhs, rhs)


def right_shift(lhs, rhs):
"""Right shift with numpy-style broadcasting.

Expand Down
4 changes: 4 additions & 0 deletions src/relay/op/tensor/binary.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ RELAY_REGISTER_BINARY_OP("maximum")
.describe("Elementwise maximum of two tensors with broadcasting")
.set_support_level(4);

RELAY_REGISTER_BINARY_OP("minimum")
.describe("Elementwise minimum of two tensors with broadcasting")
.set_support_level(4);

// Comparisons
#define RELAY_REGISTER_CMP_OP(OpName) \
TVM_REGISTER_API("relay.op._make." OpName) \
Expand Down
3 changes: 2 additions & 1 deletion tests/python/relay/test_op_level4.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ def test_cmp_type():
def test_binary_broadcast():
for op in [relay.right_shift,
relay.left_shift,
relay.maximum]:
relay.maximum,
relay.minimum]:
ib = relay.ir_builder.IRBuilder()
x = ib.param("x", relay.TensorType((10, 4), "int32"))
y = ib.param("y", relay.TensorType((5, 10, 1), "int32"))
Expand Down