Matrix<T> Matrix<T>::get(int rw, int cl, int nr, int nc) const { Matrix<T> getmat(nr,nc) ; if ( (rw+nr) > this->rows() || (cl+nc) > this->cols()) { #ifdef USE_EXCEPTION throw MatrixErr(); #else Error error("Matrix<T>::get") ; error << "Matrix of size "<< nr << ", " << nc << " not available at " << rw << ", " << cl << endl ; error.fatal() ; #endif } int i, j; #ifdef COLUMN_ORDER for(i=0;i<nr;++i) for(j=0;j<nc;++j) getmat(i,j) = this->elem(i+rw,j+cl) ; #else T *pptr,*aptr ; aptr = getmat.m-1; for (i = 0; i < nr; ++i) { pptr = &m[(i+rw)*cols()+cl]-1 ; for ( j = 0; j < nc; ++j) *(++aptr) = *(++pptr) ; } #endif return getmat ; }
void Matrix<T>::as(int rw, int cl, Matrix<T>& a) { // Assign matrix a to this matrix at (i,j) int i, j; if ( (rw + a.rows()) > this->rows() || ( cl + a.cols()) > this->cols()) { #ifdef USE_EXCEPTION throw MatrixErr(); #else Error error("Matrix<T>::as") ; error << "Matrix A will not fit in this Matrix at " << rw << ", " << cl << endl ; error.fatal() ; #endif } #ifdef COLUMN_ORDER for(i=0;i<a.rows();++i) for(j=0;j<a.cols();++j) this->elem(i+rw,j+cl) = a(i,j) ; #else T *pptr,*aptr ; aptr = a.m-1 ; for ( i = 0; i<a.rows(); ++i) { pptr = &m[(i+rw)*cols()+cl]-1 ; for ( j = 0; j < a.cols(); ++j) *(++pptr) = *(++aptr); } #endif }
void Matrix<T>::qSort(){ #ifdef USE_EXCEPTION throw MatrixErr(); #else Error error("Matrix<T>::qSort()"); error << "qSort is not defined for that type.\nPlease defined it in your .cpp file!"; error.fatal() ; #endif }
void IM_ImageT<T>::setImage() { #ifdef USE_EXCEPTION throw MatrixErr() ; #else Error error("IM_ImageT<T>::setImage") ; error << "An image of this type is NOT supported!\n" ; error.fatal() ; #endif }
template<> int Vector<Color>::minIndex() const { #ifdef USE_EXCEPTION throw MatrixErr() ; #else Error error("Vector<color>::minIndex") ; error << "ERROR: you can't get the minIndex of a vector of Colors!\n" ; error.fatal() ; #endif return 0 ; }
int IM_ImageT<T>::write(const char* filename) { #ifdef USE_EXCEPTION throw MatrixErr() ; #else Error error("IM_ImageT<T>::write") ; error << "An image of this type is NOT supported!\n" ; error.fatal() ; #endif return 0 ; }
template<> double Matrix<Color>::norm(void) { #ifdef USE_EXCEPTION throw MatrixErr(); #else Error error("Matrix<Color>::norm()") ; error << "ERROR: you can't get the norm of a Color matrix\n" ; error.fatal() ; #endif return 0 ; }
void Vector<T>::as(int i, const Vector<T> &b) { if ( (i + b.rows()) > rows() ) { #ifdef USE_EXCEPTION throw MatrixErr() ; #else Error error("Vector<T>::as(int,Vector<T>)"); error << "Vector is too long to fit at i= " << i << endl ; error.fatal() ; #endif } T *aptr,*bptr ; aptr = &this->x[i]-1 ; bptr = b.x-1 ; for ( int j = b.rows(); j > 0; --j) *(++aptr) = *(++bptr) ; }
Vector<T> Vector<T>::get(int i, int l) { if ( (i + l) > rows() ) { #ifdef USE_EXCEPTION throw MatrixErr() ; #else Error error("Vector<T>::get(int,Vector<T>)"); error << "Vector is too long to extract from i= " << i << "from l=" << l << endl ; error.fatal() ; #endif } Vector<T> subvec(l) ; T *aptr, *bptr ; aptr = &this->x[i] - 1 ; bptr = subvec.x -1 ; for ( int j = l; j > 0; --j) *(++bptr) = *(++aptr) ; return subvec ; }