URL: https://graphicscomputing.fr/cgp/reference/functions/grids/
Description: Offsets between 2D/3D indices and linear storage, and operations on fixed-size grids.

# Grid helpers

Offsets between 2D/3D indices and linear storage, and operations on fixed-size grids.

- `void check_index_bounds(int index1, int index2, grid_stack_2D<T,N1,N2> const& data)` - Raises an error if (x,y) is outside [0,N1-1]x[0,N2-1]; no-op when CGP_NO_DEBUG is defined.
- `T const& element(grid_stack_2D<T,N1,N2> const& data)` - Element (idx1,idx2) with indices checked at compile time (static_assert).
- `int2 index_grid_from_offset(int offset, int N1)` - Index (k1,k2) of a linear offset in a 2D grid of first dimension N1 (inverse of offset_grid).
- `int3 index_grid_from_offset(int offset, int N1, int N2)` - Index (k1,k2,k3) of a linear offset in a 3D grid of dimensions N1 x N2 (inverse of offset_grid).
- `std::pair<int,int> index_grid_from_offset_stack(int offset)` - Index pair (k1,k2) of a linear offset in a 2D grid whose first dimension N1 is known at compile time.
- `bool is_equal(grid_stack_2D<Ta,Na1,Na2> const& a, grid_stack_2D<Tb,Nb1,Nb2> const& b)` - Equality of two fixed-size grids: same dimensions and element-wise equal values (approximate for floating-point).
- `grid_stack_2D<T,N1,N3> multiply_matrix(grid_stack_2D<T,N1,N2> const& a, grid_stack_2D<T,N2,N3> const& b)` - Matrix product of an N1xN2 grid and an N2xN3 grid, giving an N1xN3 grid.
- `int offset_grid(int k1, int k2, int N1)` - Linear offset k1 + N1*k2 of index (k1,k2) in a 2D grid of first dimension N1.
- `int offset_grid(int k1, int k2, int k3, int N1, int N2)` - Linear offset k1 + N1*(k2 + N2*k3) of index (k1,k2,k3) in a 3D grid of dimensions N1 x N2 x N3.
- `int offset_grid(int2 const& k, int N1)` - Linear offset k.x + N1*k.y of a 2D index in a grid of first dimension N1.
- `int offset_grid(int3 const& k, int N1, int N2)` - Linear offset of a 3D index in a grid of dimensions N1 x N2 x N3.
- `size_t offset_grid_stack(int k1, int k2)` - Linear offset k1 + N1*k2 of index (k1,k2) in a 2D grid whose first dimension N1 is known at compile time.
- `grid_stack_2D<T,N1,N2> operator*(float a, grid_stack_2D<T,N1,N2> const& b)` - Grid with each element multiplied by a scalar.
- `grid_stack_2D<T,N1,N2> operator*(grid_stack_2D<T,N1,N2> const& a, float b)` - Grid with each element multiplied by a scalar.
- `grid_stack_2D<T,N1,N2> operator*(grid_stack_2D<T,N1,N2> const& a, grid_stack_2D<T,N1,N2> const& b)` - Element-wise product of two grids (not a matrix product, see multiply_matrix).
- `grid_stack_2D<T,N1,N2>& operator*=(grid_stack_2D<T,N1,N2>& a, float b)` - Multiplies each element by a scalar in place.
- `grid_stack_2D<T,N1,N2>& operator*=(grid_stack_2D<T,N1,N2>& a, grid_stack_2D<T,N1,N2> const& b)` - Multiplies by a grid element-wise in place.
- `grid_stack_2D<T,N1,N2> operator+(grid_stack_2D<T,N1,N2> const& a, grid_stack_2D<T,N1,N2> const& b)` - Element-wise sum of two grids.
- `grid_stack_2D<T,N1,N2>& operator+=(grid_stack_2D<T,N1,N2>& a, grid_stack_2D<T,N1,N2> const& b)` - Adds a grid element-wise in place.
- `grid_stack_2D<T,N1,N2> operator-(grid_stack_2D<T,N1,N2> const& a, grid_stack_2D<T,N1,N2> const& b)` - Element-wise difference of two grids.
- `grid_stack_2D<T,N1,N2>& operator-=(grid_stack_2D<T,N1,N2>& a, grid_stack_2D<T,N1,N2> const& b)` - Subtracts a grid element-wise in place.
- `grid_stack_2D<T,N1,N2> operator/(grid_stack_2D<T,N1,N2> const& a, float b)` - Grid with each element divided by a scalar.
- `grid_stack_2D<T,N1,N2> operator/(grid_stack_2D<T,N1,N2> const& a, grid_stack_2D<T,N1,N2> const& b)` - Element-wise quotient of two grids.
- `grid_stack_2D<T,N1,N2>& operator/=(grid_stack_2D<T,N1,N2>& a, float b)` - Divides each element by a scalar in place.
- `grid_stack_2D<T,N1,N2>& operator/=(grid_stack_2D<T,N1,N2>& a, grid_stack_2D<T,N1,N2> const& b)` - Divides by a grid element-wise in place.
- `std::ostream& operator<<(std::ostream& s, grid_stack_2D<T,N1,N2> const& v)` - Writes all elements of the grid to the stream, in storage order separated by spaces.
- `std::string str(grid_stack_2D<T,N1,N2> const& v, std::string const& separator = " ", std::string const& begin = "", std::string const& end = "")` - Text representation of all elements in storage order, joined by separator and surrounded by begin and end.
- `std::string type_str(grid_stack_2D<T,N1,N2> const&)` - Type name as a string, e.g. "grid_stack_2D<float,3,3>".
