code: def test_handle_numerical_errors(self):
      x = np.zeros(1, dtype=np.float64)
  
      with self.assertRaisesRegex(NotPSDError, "foo"):
          _handle_numerical_errors(NotPSDError("foo"), x=x)
  
      for error in (
          NanError(),
          RuntimeError("singular"),
          RuntimeError("input is not positive-definite"),
      ):
          fake_loss, fake_grad = _handle_numerical_errors(error, x=x)
          self.assertTrue(np.isnan(fake_loss))
          self.assertEqual(fake_grad.shape, x.shape)
          self.assertTrue(np.isnan(fake_grad).all())
  
      fake_loss, fake_grad = _handle_numerical_errors(
          error, x=x, dtype=np.float32
      )
      self.assertEqual(np.float32, fake_loss.dtype)
      self.assertEqual(np.float32, fake_grad.dtype)
  
      with self.assertRaisesRegex(RuntimeError, "foo"):
          _handle_numerical_errors(RuntimeError("foo"), x=x)
  
file_path: botorch/test/optim/utils/test_common.py
imports: from __future__ import annotations
  from functools import partial
  from warnings import catch_warnings, warn
  import numpy
  from botorch.optim.utils import _filter_kwargs, _handle_numerical_errors, _warning_handler_template
  from botorch.utils.testing import BotorchTestCase
  from linear_operator.utils.errors import NanError, NotPSDError
label_desc: Use image node_id 2 for calling the TestUtilsCommon obj's underlying member method code with example usage: obj.test_handle_numerical_errors() without return types