code: def linear(
      x: Union[tf.Tensor, tf.Variable],
      weight: Union[tf.Tensor, tf.Variable],
      /,
      *,
      bias: Optional[Union[tf.Tensor, tf.Variable]] = None,
      out: Optional[Union[tf.Tensor, tf.Variable]] = None,
  ) -> Union[tf.Tensor, tf.Variable]:
      # TODO: try to generalize this for >=2 dimensions
      result = (
          tf.matmul(x, weight, transpose_b=True)
          if len(x.shape) == len(weight.shape) == 2
          and x.shape[-1] == weight.shape[-1]
          else tf.einsum("...i,...ji->...j", x, weight)
      )
  
      if bias is not None:
          return tf.add(result, bias)
      return result
  
imports: from typing import Optional, Tuple, Union, Sequence
  import tensorflow
  from tensorflow.python.types.core import Tensor
  import ivy
  from ivy.func_wrapper import with_supported_dtypes, with_unsupported_dtypes
  from .None import backend_version
  from ivy.functional.ivy.layers import _deconv_length, _get_x_data_format
label_desc: Use image node_id 1 for calling a global function with example usage: linear() and returns: result, tf