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 &);
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>
inline Matrix<T, M, N> &Matrix<T, M, N>::operator*=(T s)
{
Vector(T, T, T, T);
template<typename U>
Vector(const Vector<U, N> &);
- template<typename U>
- Vector(const Vector<U, N-1> &, U);
- template<typename U>
- explicit Vector(const Vector<U, N+1> &);
+
+ template<unsigned M>
+ Vector<T, M> slice(unsigned) const;
Vector &operator*=(T);
Vector &operator/=(T);
}
template<typename T, unsigned N>
-template<typename U>
-inline Vector<T, N>::Vector(const Vector<U, N-1> &v, U s)
+inline Vector<T, N+1> compose(const Vector<T, N> &v, T s)
{
- for(unsigned i=0; i<N-1; ++i)
- (*this)[i] = v[i];
- (*this)[N-1] = s;
+ Vector<T, N+1> r;
+ for(unsigned i=0; i<N; ++i)
+ r[i] = v[i];
+ r[N] = s;
+ return r;
}
template<typename T, unsigned N>
-template<typename U>
-inline Vector<T, N>::Vector(const Vector<U, N+1> &v)
+inline Vector<T, N+1> compose(T s, const Vector<T, N> &v)
{
+ Vector<T, N+1> r;
for(unsigned i=0; i<N; ++i)
- (*this)[i] = v[i];
+ r[i] = v[i];
+ r[N] = s;
+ return r;
+}
+
+template<typename T, unsigned N, unsigned M>
+inline Vector<T, N+M> compose(const Vector<T, N> &v1, const Vector<T, M> &v2)
+{
+ Vector<T, N+M> r;
+ for(unsigned i=0; i<N; ++i)
+ r[i] = v1[i];
+ for(unsigned i=0; i<M; ++i)
+ r[N+i] = v2[i];
+ return r;
+}
+
+template<typename T, unsigned N>
+template<unsigned M>
+inline Vector<T, M> Vector<T, N>::slice(unsigned j) const
+{
+ Vector<T, M> r;
+ for(unsigned i=0; i<M; ++i)
+ r[i] = (*this)[j+i];
+ return r;
}
template<typename T, unsigned N>