code: def _generate_broadcasting_indices(out_shape, *shapes):
      """
      Return indices over each shape that broadcast them to match out_shape.
  
      The first returned list is equivalent to numpy.ndindex(out_shape),
      the other returned lists are indices corresponding to the other shapes,
      such that looping over these indices produce tensors of shape out_shape.
      In particular, the indices over broadcasted dimensions should all be 0.
  
      The shapes should have the same length as out_shape. If they are longer,
      the right-most dimensions are ignored.
  
      """
      all_shapes = (out_shape,) + shapes
      # Will contain the return value: a list of indices for each argument
      ret_indices = [[()] for shape in all_shapes]
  
      for dim in xrange(len(out_shape)):
          # Temporary list to generate the indices
          _ret_indices = [[] for shape in all_shapes]
  
          out_range = list(range(out_shape[dim]))
  
          # Verify the shapes are compatible along that dimension
          # and generate the appropriate range: out_range, or [0, ..., 0]
          ranges = [out_range]
          for shape in shapes:
              if shape[dim] == out_shape[dim]:
                  ranges.append(out_range)
              elif shape[dim] == 1:  # broadcast
                  ranges.append([0] * out_shape[dim])
              else:
                  raise ValueError(
                      "shape[%i] (%i) should be equal to out_shape[%i] (%i) or"
                      " to 1" % (dim, shape[dim], dim, out_shape[dim]),
                      shape,
                      out_shape,
                      shapes,
                  )
  
          for prev_index in zip(*ret_indices):
              for dim_index in zip(*ranges):
                  for i in xrange(len(all_shapes)):
                      _ret_indices[i].append(
                          prev_index[i] + (dim_index[i],)
                      )
          ret_indices = _ret_indices
  
      return ret_indices
  
imports: from __future__ import absolute_import, print_function, division
  import sys
  from copy import copy
  import numpy
  from six import string_types
  from six.moves import reduce, xrange
  import theano
  from theano import tensor
  from theano.tensor import opt
  from theano import gof
  from theano.compile import optdb
label_desc: Use image node_id 2 for calling a global function with example usage: _generate_broadcasting_indices(out_shape) and returns: ret_indices