code: def size0(x, name=None):
      """Returns the size of the first dimension (0 if scalar)."""
      with tf.name_scope(name or "size0"):
          # First, ensure hasattr(x, 'shape').
          x_ = tf.get_static_value(x)
          if x_ is not None:
              x = np.array(x_)
          if not hasattr(x, "shape"):
              x = tf.convert_to_tensor(x)
          # Next, try to read shape[0].
          ndims = tensorshape_util.rank(x.shape)
          if ndims is None or ndims == 0:
              n = ndims
          else:
              n = tf.compat.dimension_value(x.shape[0])
          if n is not None:
              return np.int32(n)
          return pad(
              shape(x)[:1], paddings=[[0, 1]], constant_values=0
          )[0]
  
imports: import decorator
  import numpy
  import tensorflow.compat.v1
  import tensorflow.compat.v2
  from tensorflow_probability.python.internal import dtype_util
  from tensorflow_probability.python.internal import tensorshape_util
  from tensorflow_probability.python.internal.backend import numpy
  from tensorflow.python.framework import tensor_util
  from tensorflow.python.ops import control_flow_case
  from tensorflow.python.util import tf_inspect
label_desc: Use image node_id 13 for calling a global function with example usage: size0(x, name) and returns: pad, np