Grid helpers
Offsets between 2D/3D indices and linear storage, and operations on fixed-size grids.
Construct 2
index_grid_from_offset
2 overloadsint2 index_grid_from_offset(int offset, int N1)sourceIndex (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)sourceIndex (k1,k2,k3) of a linear offset in a 3D grid of dimensions N1 x N2 (inverse of offset_grid).
Compute 7
template <int N1>
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.
template <typename T, int N1, int N2, int N3>
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.
offset_grid
4 overloadsint offset_grid(int k1, int k2, int N1)sourceLinear offset k1 + N1*k2 of index (k1,k2) in a 2D grid of first dimension N1.
int offset_grid(int2 const& k, int N1)sourceLinear offset k.x + N1*k.y of a 2D index in a grid of first dimension N1.
int offset_grid(int k1, int k2, int k3, int N1, int N2)sourceLinear 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(int3 const& k, int N1, int N2)sourceLinear offset of a 3D index in a grid of dimensions N1 x N2 x N3.
template <int N1>
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.
Convert 2
template <typename T, int N1, int N2>
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.
Access 3
template <typename T, int N1, int N2>
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.
template <int idx1, int idx2, typename T, int N1, int N2>
T const& element(grid_stack_2D<T,N1,N2> const& data)
T& element(grid_stack_2D<T,N1,N2>& data)Element (idx1,idx2) with indices checked at compile time (static_assert).
Other 14
operator*
3 overloadstemplate <typename T, int N1, int N2>
grid_stack_2D<T,N1,N2> operator*(grid_stack_2D<T,N1,N2> const& a, grid_stack_2D<T,N1,N2> const& b)sourceElement-wise product of two grids (not a matrix product, see multiply_matrix).
template <typename T, int N1, int N2>
grid_stack_2D<T,N1,N2> operator*(grid_stack_2D<T,N1,N2> const& a, float b)sourceGrid with each element multiplied by a scalar.
template <typename T, int N1, int N2>
grid_stack_2D<T,N1,N2> operator*(float a, grid_stack_2D<T,N1,N2> const& b)sourceGrid with each element multiplied by a scalar.
operator*=
2 overloadstemplate <typename T, int N1, int N2>
grid_stack_2D<T,N1,N2>& operator*=(grid_stack_2D<T,N1,N2>& a, grid_stack_2D<T,N1,N2> const& b)sourceMultiplies by a grid element-wise in place.
template <typename T, int N1, int N2>
grid_stack_2D<T,N1,N2>& operator*=(grid_stack_2D<T,N1,N2>& a, float b)sourceMultiplies each element by a scalar in place.
template <typename T, int N1, int N2>
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.
template <typename T, int N1, int N2>
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.
template <typename T, int N1, int N2>
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.
template <typename T, int N1, int N2>
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.
operator/
2 overloadstemplate <typename T, int N1, int N2>
grid_stack_2D<T,N1,N2> operator/(grid_stack_2D<T,N1,N2> const& a, grid_stack_2D<T,N1,N2> const& b)sourceElement-wise quotient of two grids.
template <typename T, int N1, int N2>
grid_stack_2D<T,N1,N2> operator/(grid_stack_2D<T,N1,N2> const& a, float b)sourceGrid with each element divided by a scalar.
operator/=
2 overloadstemplate <typename T, int N1, int N2>
grid_stack_2D<T,N1,N2>& operator/=(grid_stack_2D<T,N1,N2>& a, grid_stack_2D<T,N1,N2> const& b)sourceDivides by a grid element-wise in place.
template <typename T, int N1, int N2>
grid_stack_2D<T,N1,N2>& operator/=(grid_stack_2D<T,N1,N2>& a, float b)sourceDivides each element by a scalar in place.
template <typename T, int N1, int N2>
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.