65void demo_shared_buffer()
67 std::cout <<
"[1] .view() aliases the storage's own buffer\n";
74 std::cout <<
"grid.at(1, 1) after v(1,1)=5: " << grid.
at(1, 1) <<
" (expect 5)\n";
77 std::cout <<
"v(0, 0) after grid.set(0,0,9): " << v(0, 0) <<
" (expect 9)\n\n";
84 assert(i > 0
and j > 0);
85 return v(i - 1, j) + v(i + 1, j) + v(i, j - 1) + v(i, j + 1);
88void demo_stencil_kernel()
90 std::cout <<
"[2] A tiny stencil kernel driven directly through the view\n";
96 std::cout <<
"Sum of the 4 orthogonal neighbours of every interior cell\n"
97 "(each has value 1, so every sum should be 4):\n";
98 for (
size_t i = 1; i + 1 < v.extent(0); ++i)
100 for (
size_t j = 1; j + 1 < v.extent(1); ++j)
101 std::cout << neighbour_sum(v, i, j) <<
" ";
109 for (
size_t i = 0; i < v.
extent(0); ++i)
111 for (
size_t j = 0; j < v.
extent(1); ++j)
112 std::cout << v(i, j) <<
" ";
117void demo_read_only_view()
119 std::cout <<
"[3] Read-only view for a function that only reads the lattice\n";
124 for (
size_t i = 0; i < 2; ++i)
125 for (
size_t j = 0; j < 3; ++j)
128 print_view(grid.view());
135 std::cout <<
"\n=== Dense_Cell_Storage::view(): mdspan over a CA lattice ===\n\n";
137 demo_shared_buffer();
138 demo_stencil_kernel();
139 demo_read_only_view();
141 std::cout <<
"Done.\n";
Row-major dense storage for N-dimensional cellular automata.
view_type view() noexcept
Return a mutable Aleph::mdspan view of this storage.
T at(const coord_type &c) const
Read access through a multi-index.
void set(const coord_type &c, const T &v)
Write access through a multi-index.
Non-owning view of a contiguous buffer as a multidimensional grid.
constexpr index_type extent(rank_type r) const noexcept
Run-time size of axis r.
Main namespace for Aleph-w library functions.
and
Check uniqueness with explicit hash + equality functors.
void print_rule()
Prints a horizontal rule for example output separation.
void next()
Advance all underlying iterators (bounds-checked).
Dense, contiguous storage for cellular automata cells (1D/2D/3D).