code: def _broadcast_arg(U, arg, argtype, name):
      
  
      # if input is not iterable, broadcast it all dimensions of the tensor
      if arg is None or isinstance(arg, argtype):
          return [arg for _ in range(U.ndim)]
  
      # check if iterable input is valid
      elif np.iterable(arg):
          if len(arg) != U.ndim:
              raise ValueError('Parameter {} was specified as a sequence of '
                               'incorrect length. The length must match the '
                               'number of tensor dimensions '
                               '(U.ndim={})'.format(name, U.ndim))
          elif not all([isinstance(a, argtype) for a in arg]):
              raise TypeError('Parameter {} specified as a sequence of '
                              'incorrect type. '
                              'Expected {}.'.format(name, argtype))
          else:
              return arg
  
      # input is not iterable and is not the corrent type.
      else:
          raise TypeError('Parameter {} specified as a {}.'
                          ' Expected {}.'.format(name, type(arg), argtype))
docs: Broadcasts plotting option `arg` to all factors.
  
      Args:
          U : KTensor
          arg : argument provided by the user
          argtype : expected type for arg
          name : name of the variable, used for error handling
  
      Returns:
          iterable version of arg of length U.ndim