code: def testSafeToCast(
      self, input_dtype, output_dtype, numpy_dtype_promotion
  ):
      with jax.numpy_dtype_promotion(numpy_dtype_promotion):
          # First the special cases which are always safe:
          always_safe = (
              (input_dtype == output_dtype)
              or (
                  dtypes.issubdtype(output_dtype, np.integer)
                  and input_dtype in {int}
              )
              or (
                  dtypes.issubdtype(output_dtype, np.floating)
                  and input_dtype in {int, float}
              )
              or (
                  dtypes.issubdtype(output_dtype, np.complexfloating)
                  and input_dtype in {int, float, complex}
              )
          )
          if always_safe:
              self.assertTrue(
                  dtypes.safe_to_cast(input_dtype, output_dtype)
              )
  
          try:
              result_dtype = dtypes.result_type(
                  input_dtype, dtypes.canonicalize_dtype(output_dtype)
              )
          except dtypes.TypePromotionError:
              result_dtype = None
  
          if result_dtype is None and input_dtype != output_dtype:
              with self.assertRaises(dtypes.TypePromotionError):
                  dtypes.safe_to_cast(input_dtype, output_dtype)
          else:
              self.assertEqual(
                  dtypes.result_type(output_dtype) == result_dtype,
                  dtypes.safe_to_cast(input_dtype, output_dtype),
              )
  
imports: import dataclasses
  import enum
  import functools
  from functools import partial
  import itertools
  import operator
  from absl.testing import absltest
  from absl.testing import parameterized
  import numpy
  import jax
  from jax import numpy
  from jax._src import config
  from jax._src import dtypes
  from jax._src import test_util
  from jax._src.lax import lax
label_desc: Use image node_id 14 for calling the TestPromotionTables obj's underlying member method code with example usage: obj.testSafeToCast(input_dtype, output_dtype, numpy_dtype_promotion) without return types