Go to the documentation of this file.
28 #include <initializer_list>
31 template<
int N,
int M,
typename T =
float>
39 Matrix(
const std::initializer_list<U>& values) { *
this = values; }
41 Matrix(
const U *values) { *
this = values; }
51 const T *
data()
const {
return m[0]; }
53 T&
operator()(
int row,
int column) {
return m[row-1][column-1]; }
54 T
operator()(
int row,
int column)
const {
return m[row-1][column-1]; }
72 template<
int N,
int M,
typename T>
74 for(
int i=0;i<N;++i) {
75 for(
int j=0;j<M;++j) {
84 template<
int N,
int M,
typename T>
88 if((i==j && m[i][j] != 1.0f) || (i!=j && m[i][j] != 0.0f))
93 template<
int N,
int M,
typename T>
100 template<
int N,
int M,
typename T>
105 result.m[j][i] = m[i][j];
109 template<
int N,
int M,
typename T>
112 auto it = values.begin();
119 template<
int N,
int M,
typename T>
124 m[i][j] = values[i*N + j];
128 template<
int N,
int M,
typename T>
132 m[i][j] += other.m[i][j];
136 template<
int N,
int M,
typename T>
140 m[i][j] -= other.m[i][j];
144 template<
int N,
int M,
typename T>
152 template<
int N,
int M,
typename T>
160 template<
int N,
int M,
typename T>
165 if(m[i][j] != other.m[i][j])
170 template<
int N,
int M,
typename T>
173 return !(*
this == other);
176 template<
int N,
int M,
typename T>
179 for(
int i=1;i<=N;++i) {
180 for(
int j=1;j<=M;++j) {
190 template<
int N,
int M,
typename T>
203 return m[0][0] == other.m[0][0] && m[1][1] == other.m[1][1] &&
204 m[2][1] == other.m[2][1] && m[2][0] == other.m[2][0] &&
205 m[1][2] == other.m[1][2] && m[0][2] == other.m[0][2] &&
206 m[1][0] == other.m[1][0] && m[0][1] == other.m[0][1] &&
207 m[2][2] == other.m[2][2];
210 template<
int M,
int N,
int P,
int Q,
typename T>
213 static_assert(N==P,
"N==P");
215 for(
int i=1;i<=M;++i) {
216 for(
int j=1;j<=Q;++j) {
218 for(
int k=1;k<=N;++k)
219 sum += a(i,k) * b(k,j);
226 template<
int M,
int N,
typename T>
229 template<
int M,
int N,
typename T>
232 template<
int M,
int N,
typename T>
235 template<
int M,
int N,
typename T>
bool operator==(const Matrix< N, M, T > &other) const
Matrix< M, N, T > operator/(const Matrix< M, N, T > &a, float b)
Matrix< M, Q, T > operator*(const Matrix< M, N, T > &a, const Matrix< P, Q, T > &b)
std::enable_if< N==M >::type transpose()
Matrix< N, M, T > & operator+=(const Matrix< N, M, T > &other)
Matrix< M, N, T > operator+(const Matrix< M, N, T > &a, const Matrix< M, N, T > &b)
T & operator()(int row, int column)
Matrix< N, M, T > & operator*=(T factor)
Matrix< M, N, T > transposed() const
Matrix< N, M, T > & operator=(const Matrix< N, M, T > &other)=default
std::istream & operator>>(std::istream &in, Matrix< N, M, T > &mat)
T operator()(int row, int column) const
Matrix< N, M, T > & operator/=(T divisor)
std::ostream & operator<<(std::ostream &out, const Matrix< N, M, T > &mat)
Matrix(const std::initializer_list< U > &values)
Matrix< M, N, T > operator-(const Matrix< M, N, T > &a, const Matrix< M, N, T > &b)
Matrix< N, M, T > & operator-=(const Matrix< N, M, T > &other)
bool operator!=(const Matrix< N, M, T > &other) const