⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 matrix_triangular.cxx

📁 Multivac 的Level set包
💻 CXX
📖 第 1 页 / 共 3 页
字号:
  {    ofstream FileStream;    FileStream.open(FileName.c_str());#ifdef SELDON_CHECK_IO    // Checks if the file was opened.    if (!FileStream.is_open())      throw IOError("Matrix_Triangular::Write(string FileName)",		    string("Unable to open file \"") + FileName + "\".");#endif    this->Write(FileStream);    FileStream.close();  }  //! Writes the matrix to an output stream.  /*!    Writes the matrix to an output stream in binary format.    The number of rows (integer) and the number of columns (integer)    are written, and matrix elements are then written in the same order    as in memory (e.g. row-major storage).    \param FileStream output stream.  */  template <class T, class Prop, class Storage, class Allocator>  void Matrix_Triangular<T, Prop, Storage, Allocator>  ::Write(ofstream& FileStream) const  {#ifdef SELDON_CHECK_IO    // Checks if the stream is ready.    if (!FileStream.good())      throw IOError("Matrix_Triangular::Write(ofstream& FileStream)",		    "Stream is not ready.");#endif    FileStream.write(reinterpret_cast<char*>(const_cast<int*>(&this->m_)),		     sizeof(int));    FileStream.write(reinterpret_cast<char*>(const_cast<int*>(&this->n_)),		     sizeof(int));    FileStream.write(reinterpret_cast<char*>(this->data_),		     this->m_ * this->n_ * sizeof(value_type));#ifdef SELDON_CHECK_IO    // Checks if data was written.    if (!FileStream.good())      throw IOError("Matrix_Triangular::Write(ofstream& FileStream)",                    string("Output operation failed.")		    + string(" The output file may have been removed")		    + " or there is no space left on device.");#endif  }  //! Writes the matrix in a file.  /*!    Stores the matrix in a file in text format.    Only matrix elements are written (not dimensions).    Each row is written on a single line and elements of    a row are delimited by tabulations.    \param FileName output file name.  */  template <class T, class Prop, class Storage, class Allocator>  void Matrix_Triangular<T, Prop, Storage, Allocator>  ::WriteText(string FileName) const  {    ofstream FileStream;    FileStream.open(FileName.c_str());#ifdef SELDON_CHECK_IO    // Checks if the file was opened.    if (!FileStream.is_open())      throw IOError("Matrix_Triangular::WriteText(string FileName)",		    string("Unable to open file \"") + FileName + "\".");#endif    this->WriteText(FileStream);    FileStream.close();  }  //! Writes the matrix to an output stream.  /*!    Writes the matrix to an output stream in text format.    Only matrix elements are written (not dimensions).    Each row is written on a single line and elements of    a row are delimited by tabulations.    \param FileStream output stream.  */  template <class T, class Prop, class Storage, class Allocator>  void Matrix_Triangular<T, Prop, Storage, Allocator>  ::WriteText(ofstream& FileStream) const  {#ifdef SELDON_CHECK_IO    // Checks if the file is ready.    if (!FileStream.good())      throw IOError("Matrix_Triangular::WriteText(ofstream& FileStream)",                    "Stream is not ready.");#endif    int i, j;    for (i = 0; i < this->GetM(); i++)      {	for (j = 0; j < this->GetN(); j++)	  FileStream << (*this)(i, j) << '\t';	FileStream << endl;      }#ifdef SELDON_CHECK_IO    // Checks if data was written.    if (!FileStream.good())      throw IOError("Matrix_Triangular::WriteText(ofstream& FileStream)",                    string("Output operation failed.")		    + string(" The output file may have been removed")		    + " or there is no space left on device.");#endif  }  //! Reads the matrix from a file.  /*!    Reads a matrix stored in binary format in a file.    The number of rows (integer) and the number of columns (integer)    are read, and matrix elements are then read in the same order    as it should be in memory (e.g. row-major storage).    \param FileName input file name.  */  template <class T, class Prop, class Storage, class Allocator>  void Matrix_Triangular<T, Prop, Storage, Allocator>::Read(string FileName)  {    ifstream FileStream;    FileStream.open(FileName.c_str());#ifdef SELDON_CHECK_IO    // Checks if the file was opened.    if (!FileStream.is_open())      throw IOError("Matrix_Triangular::Read(string FileName)",		    string("Unable to open file \"") + FileName + "\".");#endif    this->Read(FileStream);    FileStream.close();  }   //! Reads the matrix from an input stream.  /*!    Reads a matrix in binary format from an input stream.    The number of rows (integer) and the number of columns (integer)    are read, and matrix elements are then read in the same order    as it should be in memory (e.g. row-major storage).    \param FileStream input stream.  */  template <class T, class Prop, class Storage, class Allocator>  void Matrix_Triangular<T, Prop, Storage, Allocator>  ::Read(ifstream& FileStream)  {#ifdef SELDON_CHECK_IO    // Checks if the stream is ready.    if (!FileStream.good())      throw IOError("Matrix_Triangular::Read(ifstream& FileStream)",                    "Stream is not ready.");#endif    int new_m, new_n;    FileStream.read(reinterpret_cast<char*>(&new_m), sizeof(int));    FileStream.read(reinterpret_cast<char*>(&new_n), sizeof(int));    this->Reallocate(new_m, new_n);    FileStream.read(reinterpret_cast<char*>(this->data_),		    new_m * new_n * sizeof(value_type));#ifdef SELDON_CHECK_IO    // Checks if data was read.    if (!FileStream.good())      throw IOError("Matrix_Triangular::Read(ifstream& FileStream)",                    string("Output operation failed.")		    + string(" The intput file may have been removed")		    + " or may not contain enough data.");#endif      }  /////////////////////////  // MATRIX<COLUPTRIANG> //  /////////////////////////  /****************   * CONSTRUCTORS *   ****************/  //! Default constructor.  /*!    Builds an empty 0x0 matrix.  */  template <class T, class Prop, class Allocator>  Matrix<T, Prop, ColUpTriang, Allocator>::Matrix()  throw():    Matrix_Triangular<T, Prop, ColUpTriang, Allocator>()  {  }  //! Main constructor.  /*! Builds a i x j full column-major matrix.    \param i number of rows.    \param j number of columns.  */  template <class T, class Prop, class Allocator>  Matrix<T, Prop, ColUpTriang, Allocator>::Matrix(int i, int j):    Matrix_Triangular<T, Prop, ColUpTriang, Allocator>(i, j)  {  }  /*****************   * OTHER METHODS *   *****************/  //! Fills the matrix with a given value.  /*!    On exit, the matrix is filled with 'x'.    \param x the value to fill the matrix with.  */  template <class T, class Prop, class Allocator>  template <class T0>  Matrix<T, Prop, ColUpTriang, Allocator>&  Matrix<T, Prop, ColUpTriang, Allocator>::operator= (const T0& x)  {    this->Fill(x);    return *this;  }  /////////////////////////  // MATRIX<COLLOTRIANG> //  /////////////////////////  /****************   * CONSTRUCTORS *   ****************/  //! Default constructor.  /*!    Builds an empty 0x0 matrix.  */  template <class T, class Prop, class Allocator>  Matrix<T, Prop, ColLoTriang, Allocator>::Matrix()  throw():    Matrix_Triangular<T, Prop, ColLoTriang, Allocator>()  {  }  //! Main constructor.  /*! Builds a i x j full column-major matrix.    \param i number of rows.    \param j number of columns.  */  template <class T, class Prop, class Allocator>  Matrix<T, Prop, ColLoTriang, Allocator>::Matrix(int i, int j):    Matrix_Triangular<T, Prop, ColLoTriang, Allocator>(i, j)  {  }  /*****************   * OTHER METHODS *   *****************/  //! Fills the matrix with a given value.  /*!    On exit, the matrix is filled with 'x'.    \param x the value to fill the matrix with.  */  template <class T, class Prop, class Allocator>  template <class T0>  Matrix<T, Prop, ColLoTriang, Allocator>&  Matrix<T, Prop, ColLoTriang, Allocator>::operator= (const T0& x)  {    this->Fill(x);    return *this;  }  /////////////////////////  // MATRIX<ROWUPTRIANG> //  /////////////////////////  /****************   * CONSTRUCTORS *   ****************/  //! Default constructor.  /*!    Builds an empty 0x0 matrix.  */  template <class T, class Prop, class Allocator>  Matrix<T, Prop, RowUpTriang, Allocator>::Matrix()  throw():    Matrix_Triangular<T, Prop, RowUpTriang, Allocator>()  {  }  //! Main constructor.  /*! Builds a i x j full row-major matrix.    \param i number of rows.    \param j number of columns.  */  template <class T, class Prop, class Allocator>  Matrix<T, Prop, RowUpTriang, Allocator>::Matrix(int i, int j):    Matrix_Triangular<T, Prop, RowUpTriang, Allocator>(i, j)  {  }  /*****************   * OTHER METHODS *   *****************/  //! Fills the matrix with a given value.  /*!    On exit, the matrix is filled with 'x'.    \param x the value to fill the matrix with.  */  template <class T, class Prop, class Allocator>  template <class T0>  Matrix<T, Prop, RowUpTriang, Allocator>&  Matrix<T, Prop, RowUpTriang, Allocator>::operator= (const T0& x)  {    this->Fill(x);    return *this;  }  /////////////////////////  // MATRIX<ROWLOTRIANG> //  /////////////////////////  /****************   * CONSTRUCTORS *   ****************/  //! Default constructor.  /*!    Builds an empty 0x0 matrix.  */  template <class T, class Prop, class Allocator>  Matrix<T, Prop, RowLoTriang, Allocator>::Matrix()  throw():    Matrix_Triangular<T, Prop, RowLoTriang, Allocator>()  {  }  //! Main constructor.  /*! Builds a i x j full row-major matrix.    \param i number of rows.    \param j number of columns.  */  template <class T, class Prop, class Allocator>  Matrix<T, Prop, RowLoTriang, Allocator>::Matrix(int i, int j):    Matrix_Triangular<T, Prop, RowLoTriang, Allocator>(i, j)  {  }  /*****************   * OTHER METHODS *   *****************/  //! Fills the matrix with a given value.  /*!    On exit, the matrix is filled with 'x'.    \param x the value to fill the matrix with.  */  template <class T, class Prop, class Allocator>  template <class T0>  Matrix<T, Prop, RowLoTriang, Allocator>&  Matrix<T, Prop, RowLoTriang, Allocator>::operator= (const T0& x)  {    this->Fill(x);    return *this;  }} // namespace Seldon.#define SELDON_FILE_MATRIX_TRIANGULAR_CXX#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -