code: def _check_size(size):
      """
      Canonicalise inputs to get valid output sizes for Theano tensors.
  
      Parameters
      ----------
      size : int_vector_like
          Some variable that could serve as the shape for a Theano tensor.
          This can be an int, a tuple of ints, a list of ints
          or a Theano Variable with similar properties.
  
      Returns
      -------
      size_var : int_vector
          A one-dimensional Theano variable encapsulating the given size.
  
      Raises
      ------
      ValueError
          If this method can not build a valid size from the input.
      """
      # non-tuple checks and scalar-to-tuple transform
      if isinstance(size, theano.Variable):
          if size.ndim == 1:
              return size
          elif size.ndim == 0:
              return tensor.stack([size], ndim=1)
          else:
              raise ValueError(
                  "Theano variable must have 1 dimension to be a valid size.",
                  size,
              )
      elif isinstance(size, (np.integer, integer_types)):
          return tensor.constant([size], ndim=1)
      elif not isinstance(size, (tuple, list)):
          raise ValueError(
              "Size must be a int, tuple, list or Theano variable.",
              size,
          )
  
      # check entries of list or tuple
      for i in size:
          if isinstance(i, theano.Variable):
              if i.ndim != 0:
                  raise ValueError(
                      "Non-scalar Theano variable in size", size, i
                  )
          elif isinstance(i, (np.integer, integer_types)):
              if i <= 0:
                  raise ValueError(
                      "Non-positive dimensions not allowed in size.",
                      size,
                      i,
                  )
          else:
              raise ValueError(
                  "Only Theano variables and integers are allowed in a size-tuple.",
                  size,
                  i,
              )
  
      return tensor.as_tensor_variable(size, ndim=1)
  
imports: from __future__ import absolute_import, print_function, division
  import warnings
  import numpy
  from six import integer_types, string_types
  from six.moves import xrange
  import theano
  from theano import Op, Apply, shared, config, Variable
  from theano import gradient, function
  from theano.gradient import undefined_grad
  from theano import tensor
  from theano.tensor import TensorType, as_tensor_variable, get_vector_length, cast, opt, scal
  from theano.compile import optdb
  from theano.gof import local_optimizer, ParamsType
  from theano.scalar import bool, int32
  from .None import multinomial
label_desc: Use image node_id 7 for calling a global function with example usage: _check_size(size) and returns: tensor, size, tensor, tensor