def common_dtype(args_list, preferred_dtype=None):
dtype = None<EOL>preferred_dtype = (None if preferred_dtype is None<EOL>else tf.as_dtype(preferred_dtype))<EOL>for a in tf.nest.flatten(args_list):<EOL><INDENT>if hasattr(a, '<STR_LIT>'):<EOL><INDENT>dt = tf.as_dtype(a.dtype)<EOL><DEDENT>else:<EOL><INDENT>continue<EOL><DEDENT>if dtype is None:<EOL><INDENT>dtype = dt<EOL><DEDENT>elif dtype != dt:<EOL><INDENT>raise TypeError('<STR_LIT>'.format(dtype, dt))<EOL><DEDENT><DEDENT>if dtype is None and preferred_dtype is None:<EOL><INDENT>return None<EOL><DEDENT>return (preferred_dtype if dtype is None else dtype).as_numpy_dtype<EOL>
Returns explict dtype from `args_list` if exists, else preferred_dtype.