📄 dynmatrix.cpp
字号:
/* Context : Matrix and Vector Operation Author : Frank Hoeppner, see also AUTHORS file Description : implementation of class module DynMatrix History : matvec.nw 980630 fh: first noweb version of generic_matrix 980925 fh: inserted constructors with 1/2/3 field parameters from statmatrix 981007 fh: reorganization of refinements matvec.matrix.nw: 980831 fh: first statmatrix implementation 980925 fh: moved constructors with 1/2/3 field parameters to matrix.nw 990107 fh: refinements reorganization matvec.store-dyn.nw: 980107 fh: first version, offers switching static/dynamic storage strategy matvec.init-diag.nw: 990107 fh: moved constructors from matvec.diagmat.nw Comment : This file was generated automatically. DO NOT EDIT. Copyright : Copyright (C) 1999-2000 Frank Hoeppner This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA*/#ifndef DynMatrix_SOURCE#define DynMatrix_SOURCE/* configuration include */#ifdef HAVE_CONFIG_H/*//FILETREE_IFDEF HAVE_CONFIG_H*/#include "config.h"/*//FILETREE_ENDIF*/#endif// necessary includes#include "DynMatrix.hpp"// data// implementationtemplate <short ROWS, short COLS, class DATA>DynMatrix<ROWS,COLS,DATA>::DynMatrix ( ) : m_array_size(ROWS*COLS) , mp_field( (ROWS*COLS>0) ? new DATA[ROWS*COLS] : NULL ) { if (m_array_size>0) memset(mp_field,0,sizeof(DATA)*ROWS*COLS); m_rows = ROWS; m_cols = COLS; }template <short ROWS, short COLS, class DATA>DynMatrix<ROWS,COLS,DATA>::DynMatrix ( const DynMatrix<ROWS,COLS,DATA>& ar_Copy ) : m_array_size(0) , mp_field(NULL) { adjust(ar_Copy.rows(),ar_Copy.cols()); memcpy(mp_field,ar_Copy.mp_field,sizeof(DATA)*ar_Copy.rows()*ar_Copy.cols()); m_rows = ar_Copy.m_rows; m_cols = ar_Copy.m_cols; }template <short ROWS, short COLS, class DATA>void DynMatrix<ROWS,COLS,DATA>::operator= ( const DynMatrix& ar_Copy ) { adjust(ar_Copy.rows(),ar_Copy.cols()); memcpy(mp_field,ar_Copy.mp_field,sizeof(DATA)*ar_Copy.rows()*ar_Copy.cols()); m_rows = ar_Copy.m_rows; m_cols = ar_Copy.m_cols; }template <short ROWS, short COLS, class DATA>DynMatrix<ROWS,COLS,DATA>::~DynMatrix ( ) { if (m_array_size>0) delete[] mp_field; }template <short ROWS, short COLS, class DATA>DynMatrix<ROWS,COLS,DATA>::DynMatrix ( const value_type value0 ) { matrix_set_vector(*this,value0); }template <short ROWS, short COLS, class DATA>DynMatrix<ROWS,COLS,DATA>::DynMatrix ( const value_type value0, const value_type value1 ) { matrix_set_track(*this,value0,value1); }template <short ROWS, short COLS, class DATA>DynMatrix<ROWS,COLS,DATA>::DynMatrix ( const value_type value0, const value_type value1, const value_type value2 ) { matrix_set_track(*this,value0,value1,value2); }template <short ROWS, short COLS, class DATA>DynMatrix<ROWS,COLS,DATA>::DynMatrix ( const value_type value0, const value_type value1, const value_type value2, const value_type value3 ) { matrix_set_track(*this,value0,value1,value2,value3); }template <short ROWS, short COLS, class DATA>DynMatrix<ROWS,COLS,DATA>::DynMatrix ( const value_type value0, const value_type value1, const value_type value2, const value_type value3, const value_type value4 ) { matrix_set_track(*this,value0,value1,value2,value3,value4); }template <short ROWS, short COLS, class DATA> voidDynMatrix<ROWS,COLS,DATA>::adjust(int rows,int cols) { //#pragma set woff 1209 // SGI remark(1209): controlling expression is constant if (true) { bool allocate(rows*cols > m_array_size); value_type *p_old(mp_field); if (allocate) { m_array_size = rows*cols; mp_field = new DATA[m_array_size]; } value_type *p_new(mp_field); if ((p_old!=NULL) && (p_old!=p_new)) { memcpy(p_new,p_old,sizeof(DATA)*m_rows*m_cols); } if (p_old!=NULL) // anything to reorder? { int cs( min(cols,m_cols) ); int rs( min(rows,m_rows) ); if ( m_cols > cols ) { // reduce no. of columns for (int r=1;r<rs;++r) for (int c=0;c<cs;++c) p_new[ r*cols+c ] = p_old[ r*m_cols+c ]; } else if ( m_cols < cols ) { for (int r=rs-1;r>0;--r) for (int c=cs-1;c>0;--c) p_new[ r*cols+c ] = p_old[ r*m_cols+c ]; } // else same no. of columns, nothing to reorder } if (allocate) { if (p_old!=NULL) delete[] p_old; } m_rows = rows; m_cols = cols; } //#pragma reset woff 1209 // SGI remark(1209): controlling expression is constant }template <short ROWS, short COLS, class DATA>bool DynMatrix<ROWS,COLS,DATA>::operator< ( const DynMatrix& M ) const { return matrix_lexico_less(*this,M); }template <short ROWS, short COLS, class DATA>bool DynMatrix<ROWS,COLS,DATA>::operator== ( const DynMatrix& M ) const { return matrix_numeric_equal(*this,M); }template <short ROWS, short COLS, class DATA>voidDynMatrix<ROWS,COLS,DATA>::write ( ostream& os ) const { write_matrix(os,*this); }template <short ROWS, short COLS, class DATA>voidDynMatrix<ROWS,COLS,DATA>::read ( istream& is ) { read_matrix(is,*this); }// template instantiation#endif // DynMatrix_SOURCE
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -