code: def _check_parameter(
      parameter,
      name,
      min_value=None,
      max_value=None,
      value_sum=None,
      value_sum_dim=None,
      value_set=None,
      dtypes=None,
      ndim=None,
      shape=None,
      check_parameter=True,
      epsilon=1e-6,
  ):
      """Ensures that the parameter falls within a valid range.
  
      This check accepts several optional conditions that can be used to ensure
      that the value has the desired properties. If these conditions are set to
      `None`, they are not checked.
  
      Note: `parameter` can be a single value or it can be a whole tensor/array
      of values. These checks are run either against the entire tensor, e.g.
      ndims, or against each of the values in the parameter.
  
  
      Parameters
      ----------
      parameter: anything
              The parameter meant to be checked
  
      name: str
              The name of the parameter for error logging purposes.
  
      min_value: float or None, optional
              The minimum numeric value that any values in the parameter can take.
              Default is None.
  
      max_value: float or None, optional
              The maximum numeric value that any values in the parameter can take.
              Default is None.
  
      value_sum: float or None, optional
              The approximate sum, within eps, of the parameter. Default is None.
  
      value_sum_dim: int or float, optional
              What dimension to sum over. If None, sum over entire tensor. Default
              is None.
  
      value_set: tuple or list or set or None, optional
              The set of values that each element in the parameter can take. Default
              is None.
  
      dtypes: tuple or list or set or None, optional
              The set of dtypes that the parameter can take. Default is None.
  
      ndim: int or list or tuple or None, optional
              The number of dimensions of the tensor. Should not be used when the
              parameter is a single value. Default is None.
  
      shape: tuple or None, optional
              The shape of the parameter. -1 can be used to accept any value for that
              dimension.
  
      epsilon: float, optional
              When using `value_sum`, this is the maximum difference acceptable.
              Default is 1e-6.
      """
  
      vector = (numpy.ndarray, torch.Tensor, torch.nn.Parameter)
  
      if parameter is None:
          return None
  
      if check_parameter == False:
          return parameter
  
      if dtypes is not None:
          if isinstance(parameter, vector):
              if parameter.dtype not in dtypes:
                  raise ValueError(
                      "Parameter {} dtype must be one of {}".format(
                          name, dtypes
                      )
                  )
          else:
              if type(parameter) not in dtypes:
                  raise ValueError(
                      "Parameter {} dtype must be one of {}".format(
                          name, dtypes
                      )
                  )
  
      if min_value is not None:
          if isinstance(parameter, vector):
              if (parameter < min_value).sum() > 0:
                  raise ValueError(
                      "Parameter {} must have a minimum value above"
                      " {}".format(name, min_value)
                  )
          else:
              if parameter < min_value:
                  raise ValueError(
                      "Parameter {} must have a minimum value above"
                      " {}".format(name, min_value)
                  )
  
      if max_value is not None:
          if isinstance(parameter, vector):
              if (parameter > max_value).sum() > 0:
                  raise ValueError(
                      "Parameter {} must have a maximum value below"
                      " {}".format(name, max_value)
                  )
          else:
              if parameter > max_value:
                  raise ValueError(
                      "Parameter {} must have a maximum value below"
                      " {}".format(name, max_value)
                  )
  
      if value_sum is not None:
          if isinstance(parameter, vector):
              if value_sum_dim is None:
                  delta = torch.sum(parameter) - value_sum
              else:
                  delta = (
                      torch.sum(parameter, dim=value_sum_dim)
                      - value_sum
                  )
  
              if torch.any(torch.abs(delta) > epsilon):
                  raise ValueError(
                      "Parameter {} must sum to {}".format(
                          name, value_sum
                      )
                  )
          else:
              if abs(parameter - value_sum) > epsilon:
                  raise ValueError(
                      "Parameter {} must sum to {}".format(
                          name, value_sum
                      )
                  )
  
      if value_set is not None:
          if isinstance(parameter, vector):
              if (~numpy.isin(parameter, value_set)).sum() > 0:
                  raise ValueError(
                      "Parameter {} must contain values in set"
                      " {}".format(name, value_set)
                  )
          else:
              if parameter not in value_set:
                  raise ValueError(
                      "Parameter {} must contain values in set"
                      " {}".format(name, value_set)
                  )
  
      if ndim is not None:
          if isinstance(parameter, vector):
              if isinstance(ndim, int):
                  if len(parameter.shape) != ndim:
                      raise ValueError(
                          "Parameter {} must have {} dims".format(
                              name, ndim
                          )
                      )
              else:
                  if len(parameter.shape) not in ndim:
                      raise ValueError(
                          "Parameter {} must have {} dims".format(
                              name, ndim
                          )
                      )
          else:
              if ndim != 0:
                  raise ValueError(
                      "Parameter {} must have {} dims".format(
                          name, ndim
                      )
                  )
  
      if shape is not None:
          if isinstance(parameter, vector):
              if len(parameter.shape) != len(shape):
                  raise ValueError(
                      "Parameter {} must have shape {}".format(
                          name, shape
                      )
                  )
  
              for i in range(len(shape)):
                  if shape[i] != -1 and shape[i] != parameter.shape[i]:
                      raise ValueError(
                          "Parameter {} must have shape {}".format(
                              name, shape
                          )
                      )
  
      return parameter
  
file_path: pomegranate/pomegranate/_utils.py
imports: import numpy
  import torch
  import collections
  from apricot import FacilityLocationSelection
  from apricot import FeatureBasedSelection
label_desc: Use image node_id 5 for calling a global function with example usage: _check_parameter(parameter, name, min_value, max_value, value_sum, value_sum_dim, value_set, dtypes, ndim, shape, check_parameter, epsilon) and returns: parameter, None, parameter