code: def test_while_loop_simple_forward():
      class _TestBlock(gluon.HybridBlock):
          def __init__(self, cond, func, max_iterations):
              super(_TestBlock, self).__init__()
              self.cond = cond
              self.func = func
              self.max_iterations = max_iterations
  
          def forward(self, *loop_vars):
              return mx.npx.while_loop(
                  cond=self.cond,
                  func=self.func,
                  loop_vars=loop_vars,
                  max_iterations=self.max_iterations,
              )
  
      for hybridize in [False, True]:
          # Case 1.1: result should be sum([1, 2, 3 ... 100])
          model = _TestBlock(
              cond=lambda i, s: i <= 5,
              func=lambda i, s: (None, (i + 1, s + i)),
              max_iterations=10,
          )
          if hybridize:
              model.hybridize()
          _, result = model(
              mx.np.array([1], dtype="int64"),  # i
              mx.np.array([0], dtype="int64"),  # s
          )
          assert result[0].item() == 6
          assert result[1].item() == 15
          # Case 1.2: result should be sum([1, 2, 3 ... 1000])
          model = _TestBlock(
              cond=lambda i, s, true: true,
              func=lambda i, s, true: (None, (i + 1, s + i, true)),
              max_iterations=1000,
          )
          if hybridize:
              model.hybridize()
          _, result = model(
              mx.np.array([1], dtype="int64"),  # i
              mx.np.array([0], dtype="int64"),  # s
              mx.np.array([1], dtype="int64"),  # true
          )
          assert result[0].item() == 1001
          assert result[1].item() == 500500
          assert result[2].item() == 1
          # Case 1.3: result should be sum([])
          model = _TestBlock(
              cond=lambda i, s, false: false,
              func=lambda i, s, false: (None, (i + 1, s + i, false)),
              max_iterations=1000,
          )
          if hybridize:
              model.hybridize()
          _, result = model(
              mx.np.array([1], dtype="int64"),  # i
              mx.np.array([0], dtype="int64"),  # s
              mx.np.array([0], dtype="int64"),  # false
          )
          assert result[0].item() == 1
          assert result[1].item() == 0
          assert result[2].item() == 0
          # Case 2.1: result should be sum([1, 2, 3 ... 100])
          model = _TestBlock(
              cond=lambda i, s: i <= 100,
              func=lambda i, s: (i, (i + 1, s + i)),
              max_iterations=1000,
          )
          if hybridize:
              model.hybridize()
          outputs, (result_i, result_s) = model(
              mx.np.array([1], dtype="int64"),  # i
              mx.np.array([0], dtype="int64"),  # s
          )
          assert all(
              outputs.asnumpy()[:100]
              == np.arange(1, 101).reshape(100, 1)
          )
          assert result_i.item() == 101
          assert result_s.item() == 5050
          # Case 2.2: result should be sum([1, 2, 3 ... 1000])
          model = _TestBlock(
              cond=lambda i, s, true: true,
              func=lambda i, s, true: (i, (i + 1, s + i, true)),
              max_iterations=1000,
          )
          if hybridize:
              model.hybridize()
          outputs, (result_i, result_s, _) = model(
              mx.np.array([1], dtype="int64"),  # i
              mx.np.array([0], dtype="int64"),  # s
              mx.np.array([1], dtype="int64"),  # true
          )
          assert all(
              outputs.asnumpy() == np.arange(1, 1001).reshape(1000, 1)
          )
          assert result_i.item() == 1001
          assert result_s.item() == 500500
          # Case 2.3: a corner case, in which loop body is never executed
          model = _TestBlock(
              cond=lambda i, s, false: false,
              func=lambda i, s, false: (i, (i + 1, s + i, false)),
              max_iterations=1000,
          )
          if hybridize:
              model.hybridize()
          _, (result_i, result_s, _) = model(
              mx.np.array([1], dtype="int64"),  # i
              mx.np.array([0], dtype="int64"),  # s
              mx.np.array([0], dtype="int64"),  # false
          )
          assert result_i.item() == 1
          assert result_s.item() == 0
  
imports: import copy
  import numpy
  import mxnet
  from mxnet import gluon
  from mxnet.test_utils import *
  from mxnet.base import _as_list
  from collections import defaultdict
  from mxnet.attribute import AttrScope
label_desc: Use image node_id 1 for calling a global function with example usage: test_while_loop_simple_forward() and returns: mx