def prefer_static_broadcast_shape(shape1,<EOL>shape2,<EOL>name="<STR_LIT>"):
with tf.name_scope(name):<EOL><INDENT>def make_shape_tensor(x):<EOL><INDENT>return tf.convert_to_tensor(value=x, name="<STR_LIT>", dtype=tf.int32)<EOL><DEDENT>def get_tensor_shape(s):<EOL><INDENT>if isinstance(s, tf.TensorShape):<EOL><INDENT>return s<EOL><DEDENT>s_ = tf.get_static_value(make_shape_tensor(s))<EOL>if s_ is not None:<EOL><INDENT>return tf.TensorShape(s_)<EOL><DEDENT>return None<EOL><DEDENT>def get_shape_tensor(s):<EOL><INDENT>if not isinstance(s, tf.TensorShape):<EOL><INDENT>return make_shape_tensor(s)<EOL><DEDENT>if tensorshape_util.is_fully_defined(s):<EOL><INDENT>return make_shape_tensor(tensorshape_util.as_list(s))<EOL><DEDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>shape1_ = get_tensor_shape(shape1)<EOL>shape2_ = get_tensor_shape(shape2)<EOL>if shape1_ is not None and shape2_ is not None:<EOL><INDENT>return tf.broadcast_static_shape(shape1_, shape2_)<EOL><DEDENT>shape1_ = get_shape_tensor(shape1)<EOL>shape2_ = get_shape_tensor(shape2)<EOL>return tf.broadcast_dynamic_shape(shape1_, shape2_)<EOL><DEDENT>
Convenience function which statically broadcasts shape when possible.

    Args:
      shape1:  `1-D` integer `Tensor`.  Already converted to tensor!
      shape2:  `1-D` integer `Tensor`.  Already converted to tensor!
      name:  A string name to prepend to created ops.

    Returns:
      The broadcast shape, either as `TensorShape` (if broadcast can be done
        statically), or as a `Tensor`.