code: def test_nan_check(self, m, n, o, nans, gc, dc):
      other = np.array([1, 2, 3]).astype(np.float32)
      X = np.random.rand(m, n, o).astype(np.float32)
      if nans:
          x_nan = np.random.randint(0, m)
          y_nan = np.random.randint(0, n)
          z_nan = np.random.randint(0, o)
          X[x_nan, y_nan, z_nan] = float("NaN")
  
      # print('nans: {}'.format(nans))
      # print(X)
  
      def nan_reference(X, Y):
          if not np.isnan(X).any():
              return [X]
          else:
              return [np.array([])]
  
      op = core.CreateOperator("NanCheck", ["X", "other"], ["Y"])
  
      try:
          self.assertReferenceChecks(
              device_option=gc,
              op=op,
              inputs=[X, other],
              reference=nan_reference,
          )
          if nans:
              self.assertTrue(
                  False, "Did not fail when presented with NaN!"
              )
      except RuntimeError:
          self.assertTrue(nans, "No NaNs but failed")
  
      try:
          self.assertGradientChecks(
              device_option=gc,
              op=op,
              inputs=[X],
              outputs_to_check=0,
              outputs_with_grads=[0],
          )
          if nans:
              self.assertTrue(
                  False, "Did not fail when gradient had NaN!"
              )
      except RuntimeError:
          pass
  
imports: from caffe2.python import core, workspace
  from hypothesis import assume, given, settings
  from caffe2.proto import caffe2_pb2
  import caffe2.python.hypothesis_test_util
  import caffe2.python.serialized_test.serialized_test_util
  import hypothesis.strategies
  import numpy
  import random
label_desc: Use image node_id 4 for calling the TestUtilityOps obj's underlying member method code with example usage: obj.test_nan_check(m, n, o, nans, gc, dc) and returns: list, list