code: def test_broadcast_forward_backward(
      align, ndim, broadcast_dim, seed, fname, ctx, func_name
  ):
      func = getattr(F, fname)
      ref_func = eval("ref_" + fname)
      rng = np.random.RandomState(seed)
      shape = rng.randint(2, 5, size=(ndim,))
      inshape = shape.copy()
      inshape[broadcast_dim] = 1
  
      if ndim == 0:
          # Performing 0-dim array test too.
          inputs = [np.array(rng.randn()).astype("float32")]
          function_tester(
              rng,
              func,
              ref_func,
              inputs,
              [shape],
              ctx=ctx,
              backward=[True],
              func_name=func_name,
              atol_b=4e-3,
          )
          return
  
      if not align:
          # Trailing pattern, e.g., inshape = (3, 4), shape = (2, 3, 4)
          if np.all(broadcast_dim) or not np.all(broadcast_dim):
              pytest.skip(
                  "All true or all false of broadcast_dim is not needed to test."
              )
  
          inshape = inshape[np.logical_not(broadcast_dim)]
          shape1 = shape[broadcast_dim]
          shape0 = shape[np.logical_not(broadcast_dim)]
          shape = shape1 + shape0
  
      inputs = [np.array(rng.randn(*inshape)).astype("float32")]
      function_tester(
          rng,
          func,
          ref_func,
          inputs,
          [shape],
          ctx=ctx,
          backward=[True],
          func_name=func_name,
          atol_b=6e-3,
      )
  
file_path: nnabla/python/test/function/test_broadcast.py
imports: import pytest
  import numpy
  import nnabla.functions
  from nbla_test_utils import function_tester, list_ctx_and_func_name
label_desc: Use image node_id 4 for calling a global function with example usage: test_broadcast_forward_backward(align, ndim, broadcast_dim, seed, fname, ctx, func_name) without return types