code: def testCommonStructuredDtype(self):
      structured_dtype_obj = dataclasses.make_dataclass(
          "structured_dtype_obj", ["dtype"]
      )
      x = structured_dtype_obj({"a": tf.float32, "b": (None, None)})
      y = structured_dtype_obj({"a": None, "b": (None, tf.float64)})
      z = structured_dtype_obj({"a": None, "b": (None, None)})
      w = structured_dtype_obj(None)
  
      # Check that structured dtypes unify correctly.
      self.assertAllAssertsNested(
          self.assertEqual,
          dtype_util.common_dtype([w, x, y, z]),
          {"a": tf.float32, "b": (None, tf.float64)},
      )
  
      # Check that dict `args` works and that `dtype_hint` works.
      dtype_hint = {"a": tf.int32, "b": (tf.int32, None)}
      self.assertAllAssertsNested(
          self.assertEqual,
          dtype_util.common_dtype(
              {"x": x, "y": y, "z": z}, dtype_hint=dtype_hint
          ),
          {"a": tf.float32, "b": (tf.int32, tf.float64)},
      )
      self.assertAllAssertsNested(
          self.assertEqual,
          dtype_util.common_dtype([w], dtype_hint=dtype_hint),
          dtype_hint,
      )
  
      # Check that non-nested dtype_hint broadcasts.
      self.assertAllAssertsNested(
          self.assertEqual,
          dtype_util.common_dtype([y, z], dtype_hint=tf.int32),
          {"a": tf.int32, "b": (tf.int32, tf.float64)},
      )
  
      # Check that structured `dtype_hint` behaves as expected.
      s = {
          "a": [tf.ones([3], tf.float32), 4.0],
          "b": (np.float64(2.0), None),
      }
      self.assertAllAssertsNested(
          self.assertEqual,
          dtype_util.common_dtype([x, s], dtype_hint=z.dtype),
          {"a": tf.float32, "b": (tf.float64, None)},
      )
      self.assertAllAssertsNested(
          self.assertEqual,
          dtype_util.common_dtype([y, s], dtype_hint=z.dtype),
          {"a": tf.float32, "b": (tf.float64, tf.float64)},
      )
  
      t = {
          "a": [[1.0, 2.0, 3.0]],
          "b": {"c": np.float64(1.0), "d": np.float64(2.0)},
      }
      self.assertAllAssertsNested(
          self.assertEqual,
          dtype_util.common_dtype(
              [w, t], dtype_hint={"a": tf.float32, "b": tf.float32}
          ),
          {"a": tf.float32, "b": tf.float64},
      )
  
      with self.assertRaisesRegex(
          ValueError, "the same nested structure"
      ):
          dtype_util.common_dtype([x, s])
  
      with self.assertRaisesRegex(
          ValueError, "the same nested structure"
      ):
          dtype_util.common_dtype(
              [x, t], dtype_hint={"a": None, "b": None}
          )
  
      with self.assertRaisesRegex(
          ValueError, "must have a shallow structure that matches"
      ):
          dtype_util.common_dtype(
              [{"a": np.float64(3.0), "b": [3, 2], "c": 3.0}],
              dtype_hint=dtype_hint,
          )
  
      if not dtype_util.SKIP_DTYPE_CHECKS:
          with self.assertRaisesRegex(
              TypeError, "contains elements with incompatible dtypes"
          ):
              dtype_util.common_dtype(
                  [
                      {
                          "a": np.float64(3.0),
                          "b": (
                              tf.ones([3], dtype=tf.float32),
                              tf.ones([2], dtype=tf.float16),
                          ),
                      }
                  ],
                  dtype_hint={"a": None, "b": None},
              )
  
          with self.assertRaisesRegex(
              TypeError, "Found incompatible dtypes"
          ):
              dtype_util.common_dtype(
                  [x, {"a": np.float64(3.0), "b": (3, 2)}],
                  dtype_hint=dtype_hint,
              )
  
          with self.assertRaisesRegex(
              TypeError, "Found incompatible dtypes"
          ):
              dtype_util.common_dtype(
                  [x, structured_dtype_obj(dtype_hint)]
              )
  
imports: import dataclasses
  from absl.testing import parameterized
  import numpy
  import tensorflow.compat.v2
  from tensorflow_probability.python.internal import dtype_util
  from tensorflow_probability.python.internal import test_util
label_desc: Use image node_id 5 for calling the DtypeUtilTest obj's underlying member method code with example usage: obj.testCommonStructuredDtype() without return types