def neighbours_findFast(a_dimension, a_depth, *args, **kwargs):
if (a_depth < <NUM_LIT:1>):<EOL><INDENT>A = None<EOL>return A;<EOL><DEDENT>b_includeOrigin = False <EOL>b_wrapGridEdges = False <EOL>b_gridSize = False <EOL>for key, value in kwargs.items():<EOL><INDENT>if key == '<STR_LIT>':      b_includeOrigin = value<EOL>if key == '<STR_LIT>':      b_wrapGridEdges = value<EOL>if key == '<STR_LIT>':<EOL><INDENT>a_gridSize = value<EOL>b_gridSize = True<EOL>if type(a_gridSize).__name__ != "<STR_LIT>":<EOL><INDENT>error_exit("<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>", <NUM_LIT:2>)<EOL><DEDENT><DEDENT><DEDENT>if b_wrapGridEdges and not b_gridSize:<EOL><INDENT>error_exit("<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL><NUM_LIT:1>)<EOL><DEDENT>v_origin = zeros((a_dimension));<EOL>b_origin = <NUM_LIT:0>;<EOL>if len(args):<EOL><INDENT>av_origin = args[<NUM_LIT:0>];<EOL>if av_origin.size == a_dimension:<EOL><INDENT>v_origin = av_origin;<EOL>b_origin = <NUM_LIT:1>;<EOL><DEDENT><DEDENT>A = array(list(itertools.product(arange(-a_depth, a_depth + <NUM_LIT:1>),<EOL>repeat=a_dimension)))<EOL>if not b_includeOrigin:<EOL><INDENT>Wbool = A == <NUM_LIT:0><EOL>W = Wbool.prod(axis=<NUM_LIT:1>)<EOL>A = A[where(W == <NUM_LIT:0>)]<EOL><DEDENT>if b_origin: A += v_origin<EOL>if b_gridSize: A = pointInGrid(A, a_gridSize, b_wrapGridEdges)<EOL>return A<EOL>
SYNOPSIS

    [A] = neighbours_findFast(a_dimension, a_depth, *args, **kwargs)

ARGS

   INPUT
   a_dimension         int32           number of dimensions
   a_depth             int32           depth of neighbours to find

   OPTIONAL
   av_origin           array          row vector that defines the
                                      + origin in the <a_dimension>
                                      + space. Neighbours' locations
                                      + are returned relative to this
                                      + origin. Default is the zero
                                      + origin.

                                      If specified, this *must* be
                                      a 1xa_dimension nparray, i.e.
                                      np.array( [(x,y)] ) in the
                                      2D case.

   OUTPUT
   A                   array           a single array containing
                                           all the neighbours. This
                                           does not include the origin.

Named keyword args
  "includeOrigin"    If True, return the origin in the set.
  "wrapGridEdges"    If True, wrap around the edges of grid.
                     If False, do not wrap around grid edges.
  "gridSize"         Specifies the gridSize for 'wrapEdges'.

  If "gridSize" is set, and "wrapEdges" is not, then the neighbors will
  not include coordinates "outside" of the grid.

DESC
       This method determines the neighbours of a point in an
       n - dimensional discrete space. The "depth" (or ply) to
       calculate is `a_depth'.

NOTE
       o Uses the 'itertools' module product() method for
         MUCH faster results than the explicit neighbours_find()
         method.

 PRECONDITIONS
       o The underlying problem is discrete.

 POSTCONDITIONS
       o Returns all neighbours

 HISTORY
 23 December 2011
 o Rewrote earlier method using python idioms and resulting
   in multiple order speed improvement.