A rectangular coordinate grid that provides neighbour lookups.
The grid is the spatial substrate on which processing elements are placed. It knows nothing about PEs or data -- it is pure geometry.
Coordinate system
{row, col}with row increasing southward and col increasing eastward (standard matrix indexing).- Row and column indices start at 0.
Why a separate module?
Separating geometry from computation keeps the Array module focused on
PE orchestration and makes neighbour logic independently testable.
Summary
Functions
Returns all valid coordinates in the grid, row-major order.
Returns the neighbour to the east (same row, col + 1) or :none.
Checks whether a coordinate lies inside the grid.
Returns the neighbour to the north (row - 1, same col) or :none.
Creates a rectangular grid of the given dimensions.
Returns the neighbour to the south (row + 1, same col) or :none.
Returns the neighbour to the west (same row, col - 1) or :none.
Types
@type coord() :: {non_neg_integer(), non_neg_integer()}
@type t() :: %ExSystolic.Grid{cols: pos_integer(), rows: pos_integer()}
Functions
Returns all valid coordinates in the grid, row-major order.
Examples
iex> grid = ExSystolic.Grid.rect(rows: 2, cols: 2)
iex> ExSystolic.Grid.coords(grid)
[{0, 0}, {0, 1}, {1, 0}, {1, 1}]
Returns the neighbour to the east (same row, col + 1) or :none.
Examples
iex> grid = ExSystolic.Grid.rect(rows: 3, cols: 3)
iex> ExSystolic.Grid.east(grid, {1, 1})
{1, 2}
iex> ExSystolic.Grid.east(grid, {1, 2})
:none
Checks whether a coordinate lies inside the grid.
Examples
iex> grid = ExSystolic.Grid.rect(rows: 2, cols: 2)
iex> ExSystolic.Grid.member?(grid, {1, 1})
true
iex> ExSystolic.Grid.member?(grid, {2, 0})
false
iex> ExSystolic.Grid.member?(grid, {-1, 0})
false
Returns the neighbour to the north (row - 1, same col) or :none.
Examples
iex> grid = ExSystolic.Grid.rect(rows: 3, cols: 3)
iex> ExSystolic.Grid.north(grid, {1, 1})
{0, 1}
iex> ExSystolic.Grid.north(grid, {0, 1})
:none
Creates a rectangular grid of the given dimensions.
Examples
iex> grid = ExSystolic.Grid.rect(rows: 3, cols: 4)
iex> grid.rows
3
iex> grid.cols
4
Returns the neighbour to the south (row + 1, same col) or :none.
Examples
iex> grid = ExSystolic.Grid.rect(rows: 3, cols: 3)
iex> ExSystolic.Grid.south(grid, {1, 1})
{2, 1}
iex> ExSystolic.Grid.south(grid, {2, 1})
:none
Returns the neighbour to the west (same row, col - 1) or :none.
Examples
iex> grid = ExSystolic.Grid.rect(rows: 3, cols: 3)
iex> ExSystolic.Grid.west(grid, {1, 1})
{1, 0}
iex> ExSystolic.Grid.west(grid, {1, 0})
:none