namespace LinAl {
/**
-A general mathematical matrix.
+A general mathematical matrix with M rows and N columns.
*/
template<typename T, unsigned M, unsigned N>
class Matrix
T &operator()(unsigned i, unsigned j) { return element(i, j); }
const T &operator()(unsigned i, unsigned j) const { return element(i, j); }
+ template<unsigned P, unsigned Q>
+ Matrix<T, P, Q> block(unsigned, unsigned) const;
+
Matrix &operator*=(T);
Matrix &operator/=(T);
Matrix &operator+=(const Matrix &);
for(unsigned i=0; i<M; ++i)
for(unsigned j=0; j<N; ++j)
m(i, j) = v[j][i];
+ return m;
}
template<typename T, unsigned M, unsigned N>
for(unsigned i=0; i<M; ++i)
for(unsigned j=0; j<N; ++j)
m(i, j) = v[i][j];
+ return m;
+}
+
+template<typename T, unsigned M, unsigned N>
+template<unsigned P, unsigned Q>
+inline Matrix<T, P, Q> Matrix<T, M, N>::block(unsigned y, unsigned x) const
+{
+ Matrix<T, P, Q> r;
+ for(unsigned j=0; j<P; ++j)
+ for(unsigned i=0; i<Q; ++i)
+ r(j, i) = element(y+j, x+i);
+ return r;
}
template<typename T, unsigned M, unsigned N>
template<typename T, unsigned M, unsigned N>
inline Matrix<T, M, N> &Matrix<T, M, N>::exchange_rows(unsigned i, unsigned j)
{
+ using std::swap;
for(unsigned k=0; k<N; ++k)
- std::swap(element(i, k), element(j, k));
+ swap(element(i, k), element(j, k));
return *this;
}