code: def variance(input, labels=None, index=None):
      """Calculates the variance of the values of an n-D image array, optionally
      at specified sub-regions.
  
      Args:
          input (cupy.ndarray): Nd-image data to process.
          labels (cupy.ndarray or None): Labels defining sub-regions in `input`.
              If not None, must be same shape as `input`.
          index (cupy.ndarray or None): `labels` to include in output. If None
              (default), all values where `labels` is non-zero are used.
  
      Returns:
          cupy.ndarray: Values of variance, for each sub-region if
          `labels` and `index` are specified.
  
      .. seealso:: :func:`scipy.ndimage.variance`
      """
      if not isinstance(input, cupy.ndarray):
          raise TypeError("input must be cupy.ndarray")
  
      if input.dtype in (cupy.complex64, cupy.complex128):
          raise TypeError(
              "cupyx.scipy.ndimage.variance doesn't support %{}"
              "".format(input.dtype.type)
          )
  
      use_kern = False
      # There are constraints on types because of atomicAdd() in CUDA.
      if input.dtype not in [
          cupy.int32,
          cupy.float16,
          cupy.float32,
          cupy.float64,
          cupy.uint32,
          cupy.uint64,
          cupy.ulonglong,
      ]:
          warnings.warn(
              "Using the slower implementation because the provided "
              f"type {input.dtype} is not supported by cupyx.scipy.ndimage.sum. "
              "Consider using an array of type int32, float16, "
              "float32, float64, uint32, uint64 as data types "
              "for the fast implementation",
              _util.PerformanceWarning,
          )
          use_kern = True
  
      def calc_var_with_intermediate_float(input):
          vals_c = input - input.mean()
          count = vals_c.size
          # Does not use `ndarray.mean()` here to return the same results as
          # SciPy does, especially in case `input`'s dtype is float16.
          return cupy.square(vals_c).sum() / cupy.asanyarray(
              count
          ).astype(float)
  
      if labels is None:
          return calc_var_with_intermediate_float(input)
  
      if not isinstance(labels, cupy.ndarray):
          raise TypeError("label must be cupy.ndarray")
  
      input, labels = cupy.broadcast_arrays(input, labels)
  
      if index is None:
          return calc_var_with_intermediate_float(input[labels > 0])
  
      if cupy.isscalar(index):
          return calc_var_with_intermediate_float(
              input[labels == index]
          )
  
      if not isinstance(index, cupy.ndarray):
          if not isinstance(index, int):
              raise TypeError(
                  "index must be cupy.ndarray or a scalar int"
              )
          else:
              return (
                  (input[labels == index])
                  .var()
                  .astype(cupy.float64, copy=False)
              )
  
      mean_val, count = _mean_driver(
          input, labels, index, True, use_kern
      )
      if use_kern:
          new_axis = (..., *(cupy.newaxis for _ in range(input.ndim)))
          return (
              cupy.where(
                  labels[None, ...] == index[new_axis],
                  cupy.square(input - mean_val[new_axis]),
                  0,
              ).sum(tuple(range(1, input.ndim + 1)))
              / count
          )
      out = cupy.zeros_like(index, dtype=cupy.float64)
      return (
          _ndimage_variance_kernel(
              input, labels, index, index.size, mean_val, out
          )
          / count
      )
  
imports: import warnings
  import numpy
  import cupy
  from cupy import _core
  from cupy import _util
label_desc: Use image node_id 12 for calling a global function with example usage: variance(input, labels, index) and returns: unknown, unknown, calc_var_with_intermediate_float, calc_var_with_intermediate_float, calc_var_with_intermediate_float, unknown, input