utils.py
def extract_neighbors(rank: int, stencil: list, dims: list) -> list:
    """
    Given a rank on a grid with dimensions dims, extract all the neighbor ranks
    on the grid, assuming non-periodicity
    :param rank: Rank of interest
    :param stencil: List of tuples of integer describing offset
    :param dims: Integer dimensions of grid
    :return: Array of neighbor ranks
    """
    neighbors = []
    rank_coord = np.unravel_index(rank, dims)
    #logging.info("Calling rank {}, rank coord {}, dims {}, stencil {}".format(rank, rank_coord, dims, stencil))
    d = len(dims)

    #Expect flatted list, i.e., len(stencil)/len(dims is number of neighbors
    for relativ_coord in stencil:
        neighbor_coord = [i for i in rank_coord]
        inside_grid = True

        for idx, offset in enumerate(relativ_coord):
            neighbor_coord[idx] += offset
            #Neighbor not inside of grid. Don't need to bother
            #logging.info("Neighbor coord={}".format(neighbor_coord))
            if neighbor_coord[idx] >= dims[idx] or neighbor_coord[idx] < 0:
                inside_grid = False

        if inside_grid:
            neighbors.append(np.ravel_multi_index(neighbor_coord, dims))

    return neighbors

    Given a rank on a grid with dimensions dims, extract all the neighbor ranks
    on the grid, assuming non-periodicity
    :param rank: Rank of interest
    :param stencil: List of tuples of integer describing offset
    :param dims: Integer dimensions of grid
    :return: Array of neighbor ranks
    
Given a rank on a grid with dimensions dims, extract all the neighbor ranks
on the grid, assuming non-periodicity
Given a rank on a grid with dimensions dims extract all the neighbor ranks on the grid assuming non - periodicity
def extract_neighbors(rank: int, stencil: list, dims: list) -> list:
    neighbors = []
    rank_coord = np.unravel_index(rank, dims)
    d = len(dims)
    for relativ_coord in stencil:
        neighbor_coord = [i for i in rank_coord]
        inside_grid = True
        for idx, offset in enumerate(relativ_coord):
            neighbor_coord[idx] += offset
            if neighbor_coord[idx] >= dims[idx] or neighbor_coord[idx] < 0:
                inside_grid = False
        if inside_grid:
            neighbors.append(np.ravel_multi_index(neighbor_coord, dims))
    return neighbors
def extract_neighbors ( rank : int , stencil : list , dims : list ) -> list : neighbors = [ ] rank_coord = np . unravel_index ( rank , dims ) d = len ( dims ) for relativ_coord in stencil : neighbor_coord = [ i for i in rank_coord ] inside_grid = True for idx , offset in enumerate ( relativ_coord ) : neighbor_coord [ idx ] += offset if neighbor_coord [ idx ] >= dims [ idx ] or neighbor_coord [ idx ] < 0 : inside_grid = False if inside_grid : neighbors . append ( np . ravel_multi_index ( neighbor_coord , dims ) ) return neighbors
Given a rank on a grid with dimensions dims, extract all the neighbor ranks
on the grid, assuming non-periodicity
Given a rank on a grid with dimensions dims extract all the neighbor ranks on the grid assuming non - periodicity
"""
    Given a rank on a grid with dimensions dims, extract all the neighbor ranks
    on the grid, assuming non-periodicity
    :param rank: Rank of interest
    :param stencil: List of tuples of integer describing offset
    :param dims: Integer dimensions of grid
    :return: Array of neighbor ranks
    """ #logging.info("Calling rank {}, rank coord {}, dims {}, stencil {}".format(rank, rank_coord, dims, stencil)) #Expect flatted list, i.e., len(stencil)/len(dims is number of neighbors #Neighbor not inside of grid. Don't need to bother #logging.info("Neighbor coord={}".format(neighbor_coord))
Array of neighbor ranks
Array of neighbor ranks
rank
int
Rank of interest
Rank of interest
stencil
list
List of tuples of integer describing offset
List of tuples of integer describing offset
dims
list
Integer dimensions of grid
Integer dimensions of grid