code: def test_np_ndarray_binary_element_wise_ops():
      np_op_map = {
          "+": _np.add,
          "*": _np.multiply,
          "-": _np.subtract,
          "/": _np.divide,
          "mod": _np.mod,
          "pow": _np.power,
      }
  
      if is_op_runnable():
          np_op_map.update(
              {
                  "==": _np.equal,
                  "!=": _np.not_equal,
                  ">": _np.greater,
                  ">=": _np.greater_equal,
                  "<": _np.less,
                  "<=": _np.less_equal,
              }
          )
  
      def _get_grad_func(op, scalar=None, reverse=False):
          if op == "+":
              if scalar is None:
                  return lambda ograd, x1, x2, out: (
                      collapse_sum_like(ograd, x1.shape),
                      collapse_sum_like(ograd, x2.shape),
                  )
              elif not reverse:
                  return lambda ograd, x1, x2, out: ograd
              else:
                  return lambda ograd, x1, x2, out: ograd
          elif op == "-":
              if scalar is None:
                  return lambda ograd, x1, x2, out: (
                      collapse_sum_like(ograd, x1.shape),
                      -collapse_sum_like(ograd, x2.shape),
                  )
              elif not reverse:
                  return lambda ograd, x1, x2, out: ograd
              else:
                  return lambda ograd, x1, x2, out: -ograd
          elif op == "*":
              if scalar is None:
                  return lambda ograd, x1, x2, out: (
                      collapse_sum_like(ograd * x2, x1.shape),
                      collapse_sum_like(ograd * x1, x2.shape),
                  )
              elif not reverse:
                  return lambda ograd, x1, x2, out: ograd * x2
              else:
                  return lambda ograd, x1, x2, out: ograd * x1
          elif op == "/":
              if scalar is None:
                  return lambda ograd, x1, x2, out: (
                      collapse_sum_like(ograd / x2, x1.shape),
                      collapse_sum_like(
                          -x1 * ograd / (x2 * x2), x2.shape
                      ),
                  )
              elif not reverse:
                  return lambda ograd, x1, x2, out: ograd / x2
              else:
                  return (
                      lambda ograd, x1, x2, out: -x1 * ograd / (x2 * x2)
                  )
          elif op == "mod":
              if scalar is None:
                  return lambda ograd, x1, x2, out: (
                      collapse_sum_like(ograd, x1.shape),
                      collapse_sum_like(
                          -ograd * _np.floor(x1 / x2), x2.shape
                      ),
                  )
              elif not reverse:
                  return lambda ograd, x1, x2, out: ograd
              else:
                  return lambda ograd, x1, x2, out: -ograd * _np.floor(
                      x1 / x2
                  )
          elif op == "pow":
              if scalar is None:
                  return lambda ograd, x1, x2, out: (
                      collapse_sum_like(
                          ograd * x2 * _np.power(x1, x2 - 1), x1.shape
                      ),
                      collapse_sum_like(
                          ograd * out * _np.log(x1), x2.shape
                      ),
                  )
              elif not reverse:
                  return (
                      lambda ograd, x1, x2, out: ograd
                      * x2
                      * _np.power(x1, x2 - 1)
                  )
              else:
                  return (
                      lambda ograd, x1, x2, out: ograd
                      * out
                      * _np.log(x1)
                  )
          elif op in ("==", "!=", "<", "<=", ">", ">="):
              if scalar is None:
                  return lambda ograd, x1, x2, out: (
                      _np.zeros_like(x1),
                      _np.zeros_like(x2),
                  )
              else:
                  return lambda ograd, x1, x2, out: _np.zeros_like(
                      ograd
                  )
          return None
  
      def get_np_ret(x1, x2, op):
          return np_op_map[op](x1, x2)
  
      @use_np
      class TestBinaryElementWiseOp(HybridBlock):
          def __init__(self, op, scalar=None, reverse=False):
              super(TestBinaryElementWiseOp, self).__init__()
              self._op = op
              self._scalar = scalar
              self._reverse = (
                  reverse  # if false, scalar is the right operand.
              )
  
          def forward(self, x, *args):
              if self._op == "+":
                  if self._scalar is not None:
                      return (
                          x + self._scalar
                          if not self._reverse
                          else self._scalar + x
                      )
                  else:
                      return (
                          x + args[0]
                          if not self._reverse
                          else args[0] + x
                      )
              elif self._op == "*":
                  if self._scalar is not None:
                      return (
                          x * self._scalar
                          if not self._reverse
                          else self._scalar * x
                      )
                  else:
                      return (
                          x * args[0]
                          if not self._reverse
                          else args[0] * x
                      )
              elif self._op == "-":
                  if self._scalar is not None:
                      return (
                          x - self._scalar
                          if not self._reverse
                          else self._scalar - x
                      )
                  else:
                      return (
                          x - args[0]
                          if not self._reverse
                          else args[0] - x
                      )
              elif self._op == "/":
                  if self._scalar is not None:
                      return (
                          x / self._scalar
                          if not self._reverse
                          else self._scalar / x
                      )
                  else:
                      return (
                          x / args[0]
                          if not self._reverse
                          else args[0] / x
                      )
              elif self._op == "mod":
                  if self._scalar is not None:
                      return (
                          x % self._scalar
                          if not self._reverse
                          else self._scalar % x
                      )
                  else:
                      return (
                          x % args[0]
                          if not self._reverse
                          else args[0] % x
                      )
              elif self._op == "pow":
                  if self._scalar is not None:
                      return (
                          x**self._scalar
                          if not self._reverse
                          else self._scalar**x
                      )
                  else:
                      return (
                          x ** args[0]
                          if not self._reverse
                          else args[0] ** x
                      )
              elif self._op == ">":
                  if self._scalar is not None:
                      return (
                          x > self._scalar
                          if not self._reverse
                          else self._scalar > x
                      )
                  else:
                      return x > args[0]
              elif self._op == ">=":
                  if self._scalar is not None:
                      return (
                          x >= self._scalar
                          if not self._reverse
                          else self._scalar >= x
                      )
                  else:
                      return x >= args[0]
              elif self._op == "<":
                  if self._scalar is not None:
                      return (
                          x < self._scalar
                          if not self._reverse
                          else self._scalar < x
                      )
                  else:
                      return x < args[0]
              elif self._op == "<=":
                  if self._scalar is not None:
                      return (
                          x <= self._scalar
                          if not self._reverse
                          else self._scalar <= x
                      )
                  else:
                      return x <= args[0]
              elif self._op == "==":
                  if self._scalar is not None:
                      return (
                          x == self._scalar
                          if not self._reverse
                          else self._scalar == x
                      )
                  else:
                      return x == args[0]
              elif self._op == "!=":
                  if self._scalar is not None:
                      return (
                          x != self._scalar
                          if not self._reverse
                          else self._scalar != x
                      )
                  else:
                      return x != args[0]
              else:
                  print(self._op)
                  assert False
  
      logic_ops = ["==", "!=", ">", "<", ">=", "<="]
  
      @use_np
      def check_binary_op_result(shape1, shape2, op, dtype=None):
          if shape1 is None:
              mx_input1 = abs(_np.random.uniform()) + 1
              np_input1 = mx_input1
          else:
              mx_input1 = (
                  rand_ndarray(shape1, dtype=dtype).abs() + 1
              ).as_np_ndarray()
              mx_input1.attach_grad()
              np_input1 = mx_input1.asnumpy()
          if shape2 is None:
              mx_input2 = abs(_np.random.uniform()) + 1
              np_input2 = mx_input2
          else:
              mx_input2 = (
                  rand_ndarray(shape2, dtype=dtype).abs() + 1
              ).as_np_ndarray()
              mx_input2.attach_grad()
              np_input2 = mx_input2.asnumpy()
  
          scalar = None
          reverse = False
          if isinstance(mx_input1, mx.nd.NDArray) and not isinstance(
              mx_input2, mx.nd.NDArray
          ):
              scalar = mx_input2
              reverse = False
          elif isinstance(mx_input2, mx.nd.NDArray) and not isinstance(
              mx_input1, mx.nd.NDArray
          ):
              scalar = mx_input1
              reverse = True
  
          grad_func = _get_grad_func(op, scalar, reverse)
          np_out = get_np_ret(np_input1, np_input2, op)
          ograd = _np.ones_like(np_out)
          for hybridize in [True, False]:
              if scalar is None:
                  get_mx_ret_np = TestBinaryElementWiseOp(op)
                  get_mx_ret_classic = TestBinaryElementWiseOp(op)
                  if hybridize:
                      get_mx_ret_np.hybridize()
                      get_mx_ret_classic.hybridize()
                  if grad_func is None:
                      mx_out = get_mx_ret_np(mx_input1, mx_input2)
                  else:
                      with mx.autograd.record():
                          mx_out = get_mx_ret_np(mx_input1, mx_input2)
                      mx_out.backward()
                  assert type(mx_out) == np.ndarray
                  if op in logic_ops:
                      assert np_out.dtype == mx_out.dtype
                  assert_almost_equal(
                      mx_out.asnumpy(),
                      np_out,
                      atol=1e-6,
                      rtol=1e-5,
                      use_broadcast=False,
                  )
  
                  if grad_func is not None:
                      x1_grad_expected, x2_grad_expected = grad_func(
                          ograd, np_input1, np_input2, np_out
                      )
                      assert_almost_equal(
                          mx_input1.grad.asnumpy(),
                          x1_grad_expected,
                          atol=1e-5,
                          rtol=1e-3,
                          use_broadcast=False,
                      )
                      assert_almost_equal(
                          mx_input2.grad.asnumpy(),
                          x2_grad_expected,
                          atol=1e-5,
                          rtol=1e-3,
                          use_broadcast=False,
                      )
              else:
                  get_mx_ret = TestBinaryElementWiseOp(
                      op, scalar=scalar, reverse=reverse
                  )
                  if hybridize:
                      get_mx_ret.hybridize()
                  if reverse:
                      mx_input = mx_input2
                  else:
                      mx_input = mx_input1
  
                  if grad_func is None:
                      mx_out = get_mx_ret(mx_input)
                  else:
                      with mx.autograd.record():
                          mx_out = get_mx_ret(mx_input)
                      mx_out.backward()
                  assert type(mx_out) == np.ndarray
  
                  if op in logic_ops:
                      assert np_out.dtype == mx_out.dtype
                  assert_almost_equal(
                      mx_out.asnumpy(),
                      np_out,
                      atol=1e-6,
                      rtol=1e-5,
                      use_broadcast=False,
                  )
  
                  # check grad
                  if grad_func is not None:
                      x_grad_expected = grad_func(
                          ograd, np_input1, np_input2, np_out
                      )
                      assert_almost_equal(
                          mx_input.grad.asnumpy(),
                          x_grad_expected,
                          atol=1e-5,
                          rtol=1e-3,
                          use_broadcast=False,
                      )
  
      dtypes = [_np.float32, _np.float64, None]
      ops = np_op_map.keys()
      for dtype in dtypes:
          for op in ops:
              check_binary_op_result((3, 4), (3, 4), op, dtype)
              check_binary_op_result(None, (3, 4), op, dtype)
              check_binary_op_result((3, 4), None, op, dtype)
              check_binary_op_result((1, 4), (3, 1), op, dtype)
              check_binary_op_result(None, (3, 1), op, dtype)
              check_binary_op_result((1, 4), None, op, dtype)
              check_binary_op_result((1, 4), (3, 5, 4), op, dtype)
              check_binary_op_result((), (3, 5, 4), op, dtype)
              check_binary_op_result((), None, op, dtype)
              check_binary_op_result(None, (), op, dtype)
              check_binary_op_result((0, 2), (1, 1), op, dtype)
              check_binary_op_result((0, 2), None, op, dtype)
              check_binary_op_result(None, (0, 2), op, dtype)
  
imports: from __future__ import absolute_import
  from __future__ import division
  import itertools
  import os
  import pytest
  import operator
  import numpy
  import mxnet
  from mxnet import np, npx, autograd
  from mxnet.gluon import HybridBlock
  from mxnet.test_utils import same, assert_almost_equal, rand_shape_nd, rand_ndarray, use_np
  from common import retry, TemporaryDirectory, xfail_when_nonstandard_decimal_separator
  from mxnet.test_utils import verify_generator, gen_buckets_probs_with_ppf, assert_exception, is_op_runnable, collapse_sum_like
  from mxnet.ndarray.ndarray import py_slice
  from mxnet.base import integer_types
label_desc: Use image node_id 6 for calling a global function with example usage: test_np_ndarray_binary_element_wise_ops() and returns: None, np_op_map, function, function, function, function, unknown, unknown, function, function, function, unknown, unknown, function, function, function, unknown, unknown, function, function, function, unknown, unknown, function, function, function, unknown, unknown, function, function, function, function, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown