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

📄 matrix_symcomplexsparse.cxx

📁 Multivac 的Level set包
💻 CXX
📖 第 1 页 / 共 3 页
字号:
// Copyright (C) 2001-2004 Vivien Mallet//// This file is part of Seldon library.// Seldon library provides matrices and vectors structures for// linear algebra.// // Seldon 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.// // Seldon 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 (file "license") for more details.//// For more information, please see the Seldon home page://     http://spacetown.free.fr/lib/seldon/#ifndef SELDON_FILE_MATRIX_SYMCOMPLEXSPARSE_CXX#include "Matrix_SymComplexSparse.hxx"namespace Seldon{  /****************   * CONSTRUCTORS *   ****************/  //! Default constructor.  /*!    Builds an empty 0x0 matrix.  */  template <class T, class Prop, class Storage, class Allocator>  inline Matrix_SymComplexSparse<T, Prop, Storage, Allocator>  ::Matrix_SymComplexSparse(): Matrix_Base<T, Allocator>()  {    real_nz_ = 0;    imag_nz_ = 0;    real_ptr_ = NULL;    imag_ptr_ = NULL;    real_ind_ = NULL;    imag_ind_ = NULL;  }  //! Constructor.  /*!    Builds an empty i by j sparse matrix.    \param i number of rows.    \param j number of columns.    \warning 'j' is assumed to be equal to 'i' so that 'j' is discarded.  */  template <class T, class Prop, class Storage, class Allocator>  inline Matrix_SymComplexSparse<T, Prop, Storage, Allocator>  ::Matrix_SymComplexSparse(int i, int j): Matrix_Base<T, Allocator>(i, i)  {    real_nz_ = 0;    imag_nz_ = 0;    real_ptr_ = NULL;    imag_ptr_ = NULL;    real_ind_ = NULL;    imag_ind_ = NULL;  }  //! Constructor.  /*! Builds a sparse matrix of size i by j , with real_nz    non-zero (stored) elements in the real part of the matrix and imag_nz    non-zero elements in the imaginary part of the matrix.    \param i number of rows.    \param j number of columns.    \param real_nz number of non-zero elements that are stored     for the real part.    \param imag_nz number of non-zero elements that are stored     for the imaginary part.    \note Matrix values are not initialized. Indices of non-zero entries    are not initialized either.  */  template <class T, class Prop, class Storage, class Allocator>  inline Matrix_SymComplexSparse<T, Prop, Storage, Allocator>  ::Matrix_SymComplexSparse(int i, int j, int real_nz, int imag_nz):    Matrix_Base<T, Allocator>(i, i)  {    this->real_nz_ = real_nz;    this->imag_nz_ = imag_nz;#ifdef SELDON_CHECK_DIMENSIONS    if ( (static_cast<long int>(2 * real_nz_ - 2) / static_cast<long int>(i+1)	  >= static_cast<long int>(i)) ||	 (static_cast<long int>(2 * imag_nz_ - 2) / static_cast<long int>(i+1)	  >= static_cast<long int>(i)) )      {	this->m_ = 0;	this->n_ = 0;	real_nz_ = 0;	imag_nz_ = 0;	real_ptr_ = NULL;	imag_ptr_ = NULL;	real_ind_ = NULL;	imag_ind_ = NULL;	this->real_data_ = NULL;	this->imag_data_ = NULL;	throw WrongDim(string("Matrix_SymComplexSparse::")		       + "Matrix_SymComplexSparse(int, int, int, int)",		       string("There are more values to be stored (")		       + to_str(real_nz) + " values for the real part and "		       + to_str(imag_nz) + string(" values for the imaginary")		       + " part) than elements in the matrix ("		       + to_str(i) + " by " + to_str(j) + ").");      }#endif#ifdef SELDON_CHECK_MEMORY    try      {#endif	real_ptr_ = reinterpret_cast<int*>( calloc(i + 1, sizeof(int)) );#ifdef SELDON_CHECK_MEMORY      }    catch (...)      {	this->m_ = 0;	this->n_ = 0;	real_nz_ = 0;	imag_nz_ = 0;	real_ptr_ = NULL;	imag_ptr_ = NULL;	real_ind_ = NULL;	imag_ind_ = NULL;	this->real_data_ = NULL;	this->imag_data_ = NULL;      }    if (real_ptr_ == NULL)      {	this->m_ = 0;	this->n_ = 0;	real_nz_ = 0;	imag_nz_ = 0;	imag_ptr_ = 0;	real_ind_ = NULL;	imag_ind_ = NULL;	this->real_data_ = NULL;	this->imag_data_ = NULL;      }    if (real_ptr_ == NULL && i != 0)      throw NoMemory(string("Matrix_SymComplexSparse::")		     + "Matrix_SymComplexSparse(int, int, int, int)",		     string("Unable to allocate ")		     + to_str(sizeof(int) * (i + 1)) + " bytes to store "		     + to_str(i + 1) + string(" row or column")		     + " start indices (for the real part), for a "		     + to_str(i) + " by " + to_str(i) + " matrix.");#endif#ifdef SELDON_CHECK_MEMORY    try      {#endif	imag_ptr_ = reinterpret_cast<int*>( calloc(i + 1, sizeof(int)) );#ifdef SELDON_CHECK_MEMORY      }    catch (...)      {	this->m_ = 0;	this->n_ = 0;	real_nz_ = 0;	imag_nz_ = 0;	free(real_ptr_);	real_ptr_ = NULL;	imag_ptr_ = NULL;	real_ind_ = NULL;	imag_ind_ = NULL;	this->real_data_ = NULL;	this->imag_data_ = NULL;      }    if (imag_ptr_ == NULL)      {	this->m_ = 0;	this->n_ = 0;	real_nz_ = 0;	imag_nz_ = 0;	free(real_ptr_);	real_ptr_ = 0;	real_ind_ = NULL;	imag_ind_ = NULL;	this->real_data_ = NULL;	this->imag_data_ = NULL;      }    if (imag_ptr_ == NULL && i != 0)      throw NoMemory(string("Matrix_SymComplexSparse::")		     + "Matrix_SymComplexSparse(int, int, int, int)",		     string("Unable to allocate ")		     + to_str(sizeof(int) * (i + 1) ) + " bytes to store "		     + to_str(i + 1) + string(" row or column")		     + " start indices (for the imaginary part), for a "		     + to_str(i) + " by " + to_str(i) + " matrix.");#endif#ifdef SELDON_CHECK_MEMORY    try      {#endif		real_ind_ = reinterpret_cast<int*>( calloc(real_nz_, sizeof(int)) );	#ifdef SELDON_CHECK_MEMORY      }    catch (...)      {	this->m_ = 0;	this->n_ = 0;	real_nz_ = 0;	imag_nz_ = 0;	free(real_ptr_);	free(imag_ptr_);	real_ptr_ = NULL;	imag_ptr_ = NULL;	real_ind_ = NULL;	imag_ind_ = NULL;	this->real_data_ = NULL;	this->imag_data_ = NULL;      }    if (real_ind_ == NULL)      {	this->m_ = 0;	this->n_ = 0;	real_nz_ = 0;	imag_nz_ = 0;	free(real_ptr_);	free(imag_ptr_);	real_ptr_ = NULL;	imag_ptr_ = NULL;	this->real_data_ = NULL;	this->imag_data_ = NULL;      }    if (real_ind_ == NULL && i != 0)      throw NoMemory(string("Matrix_SymComplexSparse::")		     + "Matrix_SymComplexSparse(int, int, int, int)",		     string("Unable to allocate ")		     + to_str(sizeof(int) * real_nz) + " bytes to store "		     + to_str(real_nz)		     + " row or column indices (real part), for a "		     + to_str(i) + " by " + to_str(i) + " matrix.");#endif#ifdef SELDON_CHECK_MEMORY    try      {#endif		imag_ind_ = reinterpret_cast<int*>( calloc(imag_nz_, sizeof(int)) );	#ifdef SELDON_CHECK_MEMORY      }    catch (...)      {	this->m_ = 0;	this->n_ = 0;	real_nz_ = 0;	imag_nz_ = 0;	free(real_ptr_);	free(imag_ptr_);	real_ptr_ = NULL;	imag_ptr_ = NULL;	free(imag_ind_);	real_ind_ = NULL;	imag_ind_ = NULL;	this->real_data_ = NULL;	this->imag_data_ = NULL;      }    if (real_ind_ == NULL)      {	this->m_ = 0;	this->n_ = 0;	real_nz_ = 0;	imag_nz_ = 0;	free(real_ptr_);	free(imag_ptr_);	real_ptr_ = NULL;	imag_ptr_ = NULL;	free(imag_ind_);	imag_ind_ = NULL;	this->real_data_ = NULL;	this->imag_data_ = NULL;      }    if (imag_ind_ == NULL && i != 0)      throw NoMemory(string("Matrix_SymComplexSparse::")		     + "Matrix_SymComplexSparse(int, int, int, int)",		     string("Unable to allocate ")		     + to_str(sizeof(int) * imag_nz) + " bytes to store "		     + to_str(imag_nz)		     + " row or column indices (imaginary part), for a "		     + to_str(i) + " by " + to_str(i) + " matrix.");#endif#ifdef SELDON_CHECK_MEMORY    try      {#endif	this->real_data_ = this->allocator_.allocate(real_nz_, this);#ifdef SELDON_CHECK_MEMORY      }    catch (...)      {	this->m_ = 0;	this->n_ = 0;	free(real_ptr_);	free(imag_ptr_);	real_ptr_ = NULL;	imag_ptr_ = NULL;	free(real_ind_);	free(imag_ind_);	real_ind_ = NULL;	imag_ind_ = NULL;	this->real_data_ = NULL;	this->imag_data_ = NULL;      }    if (real_data_ == NULL)      {	this->m_ = 0;	this->n_ = 0;	free(real_ptr_);	free(imag_ptr_);	real_ptr_ = NULL;	imag_ptr_ = NULL;	free(real_ind_);	free(imag_ind_);	real_ind_ = NULL;	imag_ind_ = NULL;	imag_data_ = NULL;      }    if (real_data_ == NULL && i != 0)      throw NoMemory(string("Matrix_SymComplexSparse::")		     + "Matrix_SymComplexSparse(int, int, int, int)",		     string("Unable to allocate ")		     + to_str(sizeof(int) * real_nz) + " bytes to store "		     + to_str(real_nz) + " values (real part), for a "		     + to_str(i) + " by " + to_str(i) + " matrix.");#endif#ifdef SELDON_CHECK_MEMORY    try      {#endif	this->imag_data_ = this->allocator_.allocate(imag_nz_, this);#ifdef SELDON_CHECK_MEMORY      }    catch (...)      {	this->m_ = 0;	this->n_ = 0;	free(real_ptr_);	free(imag_ptr_);	real_ptr_ = NULL;	imag_ptr_ = NULL;	free(real_ind_);	free(imag_ind_);	real_ind_ = NULL;	imag_ind_ = NULL;	this->allocator_.deallocate(this->real_data_, real_nz_);	this->real_data_ = NULL;	this->imag_data_ = NULL;      }    if (real_data_ == NULL)      {	this->m_ = 0;	this->n_ = 0;	free(real_ptr_);	free(imag_ptr_);	real_ptr_ = NULL;	imag_ptr_ = NULL;	free(real_ind_);	free(imag_ind_);	real_ind_ = NULL;	imag_ind_ = NULL;	this->allocator_.deallocate(this->real_data_, real_nz_);	real_data_ = NULL;      }    if (imag_data_ == NULL && i != 0)      throw NoMemory(string("Matrix_SymComplexSparse::")		     + "Matrix_SymComplexSparse(int, int, int, int)",		     string("Unable to allocate ")		     + to_str(sizeof(int) * imag_nz) + " bytes to store "		     + to_str(imag_nz) + " values (imaginary part), for a "		     + to_str(i) + " by " + to_str(i) + " matrix.");#endif  }  //! Constructor.  /*!    Builds a i by j sparse matrix with non-zero values and indices    provided by 'real_values' (values of the real part), 'real_ptr'    (pointers for the real part), 'real_ind' (indices for the real part),    'imag_values' (values of the imaginary part), 'imag_ptr'    (pointers for the imaginary part) and 'imag_ind' (indices for the    imaginary part). Input vectors are released and are empty on exit.    \param i number of rows.    \param j number of columns.    \param real_values values of non-zero entries for the real part.    \param real_ptr row or column start indices for the real part.    \param real_ind row or column indices for the real part.    \param imag_values values of non-zero entries for the imaginary part.    \param imag_ptr row or column start indices for the imaginary part.    \param imag_ind row or column indices for the imaginary part.    \warning Input vectors 'real_values', 'real_ptr' and 'real_ind',    'imag_values', 'imag_ptr' and 'imag_ind' are empty on exit.    Moreover 'j' is assumed to be equal to 'i' so that 'j' is discarded.  */  template <class T, class Prop, class Storage, class Allocator>  template <class Storage0, class Allocator0,	    class Storage1, class Allocator1,	    class Storage2, class Allocator2>  inline Matrix_SymComplexSparse<T, Prop, Storage, Allocator>::  Matrix_SymComplexSparse(int i, int j,			  Vector<T, Storage0, Allocator0>& real_values,			  Vector<int, Storage1, Allocator1>& real_ptr,			  Vector<int, Storage2, Allocator2>& real_ind,			  Vector<T, Storage0, Allocator0>& imag_values,			  Vector<int, Storage1, Allocator1>& imag_ptr,			  Vector<int, Storage2, Allocator2>& imag_ind):     Matrix_Base<T, Allocator>(i, j)  {    real_nz_ = real_values.GetLength();    imag_nz_ = imag_values.GetLength();    #ifdef SELDON_CHECK_DIMENSIONS    // Checks whether vector sizes are acceptable.        if (real_ind.GetLength() != real_nz_)      {	this->m_ = 0;	this->n_ = 0;	real_nz_ = 0;	imag_nz_ = 0;	real_ptr_ = NULL;	imag_ptr_ = NULL;	real_ind_ = NULL;	imag_ind_ = NULL;	this->real_data_ = NULL;	this->imag_data_ = NULL;	throw WrongDim(string("Matrix_SymComplexSparse::")		       + string("Matrix_SymComplexSparse(int, int, ")		       + string("const Vector&, const Vector&, const Vector&")		       + ", const Vector&, const Vector&, const Vector&)",		       string("There are ") + to_str(real_nz_)		       + " values (real part) but "		       + to_str(real_ind.GetLength())		       + " row or column indices.");      }    if (imag_ind.GetLength() != imag_nz_)      {	this->m_ = 0;	this->n_ = 0;	real_nz_ = 0;	imag_nz_ = 0;	real_ptr_ = NULL;	imag_ptr_ = NULL;	real_ind_ = NULL;

⌨️ 快捷键说明

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