1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
Matrix(Index n1) : Matrix_base<T>(n1), d1(n1) { }
Matrix(Row<T,1>& a) : Matrix_base<T>(a.dim1(),a.p), d1(a.dim1())
{
// std::cerr << "construct 1D Matrix from Row\n";
}
// copy constructor: let the base do the copy:
Matrix(const Matrix& a) : Matrix_base<T>(a.size(),0), d1(a.d1)
{
// std::cerr << "copy ctor\n";
this->base_copy(a);
}
template<int n>
Matrix(const T (&a)[n]) : Matrix_base<T>(n), d1(n)
// deduce "n" (and "T"), Matrix_base allocates T[n]
{
// std::cerr << "matrix ctor\n";
for (Index i = 0; i<n; ++i) this->elem[i]=a[i];
}
Matrix(const T* p, Index n) : Matrix_base<T>(n), d1(n)
// Matrix_base allocates T[n]
{
// std::cerr << "matrix ctor\n";
for (Index i = 0; i<n; ++i) this->elem[i]=p[i];
}
template<class F> Matrix(const Matrix& a, F f) : Matrix_base<T>(a.size()), d1(a.d1)
// construct a new Matrix with element's that are functions of a's elements:
// does not modify a unless f has been specifically programmed to modify its argument
// T f(const T&) would be a typical type for f
{
for (Index i = 0; i<this->sz; ++i) this->elem[i] = f(a.elem[i]);
}
template<class F, class Arg> Matrix(const Matrix& a, F f, const Arg& t1) : Matrix_base<T>(a.size()), d1(a.d1)
// construct a new Matrix with element's that are functions of a's elements:
// does not modify a unless f has been specifically programmed to modify its argument
// T f(const T&, const Arg&) would be a typical type for f
{
for (Index i = 0; i<this->sz; ++i) this->elem[i] = f(a.elem[i],t1);
}
|