matN
Operations shared by all matrices (mat2, mat3, mat4), written once for any size.
Fields and methods
Members of the primary template matrix_stack. Most of what you do with a CGP type goes through the free functions listed below.
Fields
numarray_stack<numarray_stack<T,N2>,N1> data | Coefficients stored row by row as N1 rows of N2 values (a numarray_stack of numarray_stack), contiguous in memory. |
Methods
matrix_stack() | Builds a matrix with all elements set to zero.6 overloads src |
matrix_stack(numarray_stack<numarray_stack<T,N2>,N1> const& elements) | Builds the matrix from an array of N1 rows of N2 elements each. src |
matrix_stack(numarray_stack<T,N1*N2> const& elements) | Builds the matrix from a flat array of N1*N2 elements given in row-major order. src |
matrix_stack(matrix_stack<T,N1_arg,N2_arg> const& M) | Builds the matrix from a matrix of another size (explicit), copying the common top-left block and value-initializing (zero) the other elements. src |
matrix_stack(std::initializer_list<T> const& arg) | Builds the matrix from a brace list of at least N1*N2 values in row-major order (asserted); extra values are ignored. src |
matrix_stack(std::initializer_list<numarray_stack<T,N2>> const& arg) | Builds the matrix from a brace list of at least N1 rows of N2 elements (asserted); extra rows are ignored. src |
| Returns the identity matrix (ones on the main diagonal, zeros elsewhere; for a non-square generic matrix the diagonal has min(N1,N2) ones). src | |
| Returns the matrix with the given values on its main diagonal and zeros elsewhere. src | |
| Returns the total number of elements N1*N2 (4, 9 and 16 for mat2, mat3 and mat4). src | |
| Returns the dimensions {N1, N2} (number of rows, number of columns) as an int2. src | |
| Sets every coefficient of the matrix to the given value and returns a reference to the matrix. src | |
| Returns a const reference to row k (a vec2, vec3 or vec4 for mat2, mat3 or mat4), with bound checking unless CGP_NO_DEBUG is defined. src | |
numarray_stack<T,N2> const& operator()(int k1) constnumarray_stack<T,N2>& operator()(int k1) | Returns a const reference to row k1 (a vector of N2 elements), with bound checking unless CGP_NO_DEBUG is defined.2 overloads src |
T const& operator()(int k1, int k2) constT& operator()(int k1, int k2) | Returns a const reference to the element at row k1 and column k2, with bound checking unless CGP_NO_DEBUG is defined. src |
| Returns a const reference to the element at the row-major offset k1*N2+k2; bound-checked for the generic matrix and mat4 (unless CGP_NO_DEBUG is defined) but not for mat2 and mat3. src | |
| Returns the (N1-1)x(N2-1) matrix obtained by removing row k1 and column k2 (asserts k1<N1 and k2<N2), e.g. a mat2 for a mat3. src | |
| Copies block into the matrix with its top-left coefficient at (offset_1, offset_2). src | |
| Returns a const pointer to the first element (0,0) of the contiguous row-major storage. src | |
| Returns a const pointer one past the last element (N1-1,N2-1) of the contiguous row-major storage. src | |
| Returns a const pointer to the first element (0,0) of the contiguous row-major storage. src | |
| Returns a const pointer one past the last element (N1-1,N2-1) of the contiguous row-major storage. src | |
| Returns a const reference to the element at row k1 and column k2; bound-checked for mat2, mat3 and mat4 (unless CGP_NO_DEBUG is defined) but not for the generic matrix_stack. src | |
T const& coeff(int k1, int k2) constT& coeff(int k1, int k2) | Returns a const reference to the element at row k1 and column k2, without bound checking.2 overloads src |
numarray_stack<T,N2> const& coeff(int k1) constnumarray_stack<T,N2>& coeff(int k1) | Returns a const reference to row k1, without bound checking. src |
| Returns a const reference to the element at the given row-major offset, without bound checking. src |
Functions taking any matN
Transform 1
template <typename T, int N1, int N2>
matrix_stack<T,N1,N2> multiply_componentwise(
matrix_stack<T,N1,N2> const& a,
matrix_stack<T,N1,N2> const& b
)Coefficient-wise (Hadamard) product of two matrices of the same size.
Compute 3
template <typename T, int N1, int N2>
T norm(matrix_stack<T,N1,N2> const& m)Frobenius norm of the matrix.
template <typename T, int N>
T trace(matrix_stack<T,N,N> const& m)Trace (sum of the diagonal entries).
Convert 4
template <typename T, int N1, int N2>
std::string str(
matrix_stack<T,N1,N2> const& v,
std::string const& separator = " ",
std::string const& begin = "",
std::string const& end = "",
std::string const& begin_line = "",
std::string const& end_line = " "
)Text representation of the matrix row by row, each row wrapped by begin_line and end_line with its values joined by separator, the whole surrounded by begin and end.
template <typename T, int N1, int N2>
std::string str_2D(
matrix_stack<T,N1,N2> const& v,
std::string const& separator,
std::string const& begin,
std::string const& end,
std::string const& begin_line,
std::string const& end_line
)Same as str() for a matrix: text of the coefficients row by row with configurable separators.
template <typename T, int N1, int N2>
std::string str_pretty(
matrix_stack<T,N1,N2> const& M,
std::string const& separator = " ",
std::string const& begin = "",
std::string const& end = "",
std::string const& begin_line = "(",
std::string const& end_line = ")\n"
)Multi-line text of the matrix, one parenthesized row per line, values in fixed notation with 2 decimals and width 7.
I/O 1
template <typename T, int N1, int N2>
std::istream& read_from_stream(std::istream& stream, matrix_stack<T,N1,N2>& data)Reads the N1 x N2 coefficients from the stream in row-major order, stopping early if the stream fails.
Access 9
check_index_bounds
2 overloadstemplate <typename T, int N1, int N2>
void check_index_bounds(int index1, int index2, matrix_stack<T,N1,N2> const& data)sourceRaises an error if (row,column) is outside [0,N1-1]x[0,N2-1].
template <typename T, int N1, int N2>
void check_index_bounds(int index1, matrix_stack<T,N1,N2> const& data)sourceRaises an error if the row index is outside [0,N1-1].
No-op when CGP_NO_DEBUG is defined.
template <typename T, int N1, int N2>
void check_offset_bounds(int offset, matrix_stack<T,N1,N2> const& data)Raises an error if the offset is outside [0,N1*N2-1]; no-op when CGP_NO_DEBUG is defined.
get
2 overloadstemplate <int idx1, int idx2, typename T, int N1, int N2>
T const& get(matrix_stack<T,N1,N2> const& data)
T& get(matrix_stack<T,N1,N2>& data)sourceCoefficient (idx1,idx2) with indices checked at compile time (static_assert).
template <int idx1, typename T, int N1, int N2>
numarray_stack<T,N2> const& get(matrix_stack<T,N1,N2> const& data)
numarray_stack<T,N2>& get(matrix_stack<T,N1,N2>& data)sourceRow idx1 as a vector, with the index checked at compile time (static_assert).
template <int offset, typename T, int N1, int N2>
T const& get_offset(matrix_stack<T,N1,N2> const& data)
T& get_offset(matrix_stack<T,N1,N2>& data)Coefficient at a row-major offset, with the offset checked at compile time (static_assert).
template <typename Ta, typename Tb, int Na1, int Na2, int Nb1, int Nb2>
bool is_equal(matrix_stack<Ta,Na1,Na2> const& a, matrix_stack<Tb,Nb1,Nb2> const& b)Equality of two matrices: same dimensions and coefficient-wise equal values (approximate for floating-point).
template <typename T, int N1, int N2>
T const* ptr(matrix_stack<T,N1,N2> const& M)Pointer to the first coefficient; coefficients are stored contiguously in row-major order.
template <typename T, int N1, int N2>
int size_in_memory(matrix_stack<T,N1,N2> const& M)Size in bytes of the N1 x N2 coefficients.
Functions returning any matN
None.
Operators
Show the 14 operators (+, -, *, ==, ...)
operator*
4 overloadstemplate <typename T, int N1, int N2, int N3>
matrix_stack<T,N1,N3> operator*(matrix_stack<T,N1,N2> const& a, matrix_stack<T,N2,N3> const& b)sourceMatrix product of an N1xN2 and an N2xN3 matrix.
template <typename T, int N1, int N2, typename S>
matrix_stack<T,N1,N2> operator*(matrix_stack<T,N1,N2> const& a, S b)sourceMatrix scaled by a scalar.
template <typename T, int N1, int N2, typename S>
matrix_stack<T,N1,N2> operator*(S a, matrix_stack<T,N1,N2> const& b)sourceMatrix scaled by a scalar.
template <typename T, int N1, int N2>
numarray_stack<T,N1> operator*(matrix_stack<T,N1,N2> const& a, numarray_stack<T,N2> const& b)sourceMatrix-vector product, giving a vector of size N1.
operator*=
2 overloadstemplate <typename T, int N>
matrix_stack<T,N,N>& operator*=(matrix_stack<T,N,N>& a, matrix_stack<T,N,N> const& b)sourceReplaces a square matrix a by the matrix product a*b.
template <typename T, int N1, int N2, typename S>
matrix_stack<T,N1,N2>& operator*=(matrix_stack<T,N1,N2>& a, S b)sourceMultiplies each coefficient by a scalar in place.
template <typename T, int N1, int N2>
matrix_stack<T,N1,N2> operator+(matrix_stack<T,N1,N2> const& a, matrix_stack<T,N1,N2> const& b)Sum of two matrices.
template <typename T, int N1, int N2>
matrix_stack<T,N1,N2>& operator+=(matrix_stack<T,N1,N2>& a, matrix_stack<T,N1,N2> const& b)Adds a matrix coefficient-wise in place.
operator-
2 overloadstemplate <typename T, int N1, int N2>
matrix_stack<T,N1,N2> operator-(matrix_stack<T,N1,N2> const& a, matrix_stack<T,N1,N2> const& b)sourceDifference of two matrices.
template <typename T, int N1, int N2>
matrix_stack<T,N1,N2> operator-(matrix_stack<T,N1,N2> const& m)sourceNegated matrix (each coefficient multiplied by -1).
template <typename T, int N1, int N2>
matrix_stack<T,N1,N2>& operator-=(matrix_stack<T,N1,N2>& a, matrix_stack<T,N1,N2> const& b)Subtracts a matrix coefficient-wise in place.
template <typename T, int N1, int N2, typename S>
matrix_stack<T,N1,N2> operator/(matrix_stack<T,N1,N2> const& a, S b)Matrix with each coefficient divided by a scalar.
template <typename T, int N1, int N2, typename S>
matrix_stack<T,N1,N2>& operator/=(matrix_stack<T,N1,N2>& a, S b)Divides each coefficient by a scalar in place.
template <typename T, int N1, int N2>
std::ostream& operator<<(std::ostream& s, matrix_stack<T,N1,N2> const& v)Writes all coefficients of the matrix to the stream, row by row separated by spaces.