Skip to content

Commit

Permalink
Add abstract methods to Neighborhood base class (#23, #27)
Browse files Browse the repository at this point in the history
  • Loading branch information
a5kin committed Jan 2, 2018
1 parent b020824 commit e6074f1
Showing 1 changed file with 49 additions and 1 deletion.
50 changes: 49 additions & 1 deletion xentica/core/topology/neighborhood.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Topology:
"""
import itertools
import abc

from xentica.core.topology.mixins import DimensionsMixin

Expand Down Expand Up @@ -47,6 +48,53 @@ def __len__(self):
"""Return number of neighbors for a single cell."""
return self.num_neighbors

@abc.abstractmethod
def neighbor_coords(self, index, coord_prefix, neighbor_prefix):
"""
Generate C code to obtain neighbor coordinates by its index.
This is an abstract method, you must implement it in
:class:`Neighborhood` subclasses.
:param index:
Neighbor index, a non-negative integer less than number of
neighbors.
:param coord_prefix:
The prefix for variables containing main cell's coordinates.
:param neighbor_prefix:
The prefix for resulting variables containing neighbor coordinates.
:returns:
A string with C code doing all necessary to get neighbor
state from RAM. No assignment, only a valid expression
needed.
"""

@abc.abstractmethod
def neighbor_state(self, neighbor_index, state_index, coord_prefix):
"""
Generate C code to obtain neighbor state by its index.
This is an abstract method, you must implement it in
:class:`Neighborhood` subclasses.
:param neighbor_index:
Neighbor index, a non-negative integer less than number of
neighbors.
:param state_index:
State index, a non-negative integer less than number of
neighbors for buffered states or -1 for main state.
:param coord_prefix:
The prefix for variables containing neighbor coordinates.
:returns:
A string with C code doing all necessary to process
neighbors's coordinates and store them to neighbor
coordinates variables.
"""


class OrthogonalNeighborhood(Neighborhood):
"""
Expand Down Expand Up @@ -97,7 +145,7 @@ class MooreNeighborhood(OrthogonalNeighborhood):
"""
N-dimensional Moore neighborhood implementation.
The neighbors is all cells, sharing at least one vertex.
The neighbors are all cells, sharing at least one vertex.
"""

Expand Down

0 comments on commit e6074f1

Please sign in to comment.