Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
Enforce adding documentation for builtin numpy operators (#16575)
Browse files Browse the repository at this point in the history
* Add test

* Delete incomplete code
  • Loading branch information
reminisce authored and haojin2 committed Oct 22, 2019
1 parent 0ba1ce2 commit ca4af0e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
3 changes: 0 additions & 3 deletions src/operator/numpy/np_elemwise_broadcast_op.cu
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,5 @@ NNVM_REGISTER_OP(_backward_npi_ldexp_scalar)
NNVM_REGISTER_OP(_backward_npi_rldexp_scalar)
.set_attr<FCompute>("FCompute<gpu>", BinaryScalarOp::Backward<gpu, mshadow_op::rldexp_grad>);

NNVM_REGISTER_OP(_np_bitwise_xor)
.set_attr<FCompute>("FCompute<gpu>", BinaryBroadcastCompute<gpu, mshadow_op::bitwise_xor>);

} // namespace op
} // namespace mxnet
12 changes: 9 additions & 3 deletions tests/python/unittest/test_numpy_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from mxnet.test_utils import verify_generator, gen_buckets_probs_with_ppf
from mxnet.numpy_op_signature import _get_builtin_op
from mxnet.test_utils import is_op_runnable, has_tvm_ops
from mxnet.operator import get_all_registered_operators


@with_seed()
Expand Down Expand Up @@ -3164,10 +3165,15 @@ def check_output_n_grad(data_shape, idx_shape, axis, mode):
def test_np_builtin_op_signature():
import inspect
from mxnet import _numpy_op_doc
for op_name in dir(_numpy_op_doc):
builtin_np_op_names = [name for name in get_all_registered_operators() if name.startswith('_np_')]
for op_name in builtin_np_op_names:
_op_from_doc = getattr(_numpy_op_doc, op_name, None)
assert _op_from_doc is not None, "Failed to find documentation for operator {}. " \
"Please add the documentation in _numpy_op_doc.py for this operator."\
.format(op_name)
op = _get_builtin_op(op_name)
if op is not None:
assert str(op.__signature__) == str(inspect.signature(getattr(_numpy_op_doc, op_name)))
assert op is not None
assert str(op.__signature__) == str(inspect.signature(_op_from_doc))


@with_seed()
Expand Down

0 comments on commit ca4af0e

Please sign in to comment.