Main Page   Packages   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Search  

smatrix Class Template Reference

#include <Smatrix.hpp>

Inheritance diagram for smatrix::

smIdentity TLUDecomp List of all members.

Public Types

typedef map< size_t, size_t
>::iterator 
iterator
typedef map< size_t, size_t
>::const_iterator 
const_iterator
typedef pair< size_t, size_t > mapping

Public Methods

virtual ~smatrix ()
 smatrix ()
 smatrix (const smatrix< t > &a)
 smatrix (const t *d, size_t iDim, size_t jDim)
 smatrix (size_t iDim, size_t jDim, size_t MaxNZ)
smatrix< t > & operator= (const smatrix< t > &a)
void initialize (size_t MaxNZ)
void initialize (size_t iDim, size_t jDim, size_t MaxNZ)
void erase (size_t pos)
size_t SlackSpace () const
double Sparsity () const
void reserve (size_t space)
bool insert (size_t i, size_t j, const t &d, iterator &iIter, iterator &jIter, bool bZeroInsert=false)
iterator insert (size_t i, size_t j, const t &d)
iterator ZeroInsert (size_t i, size_t j)
smatrix< t > & Transpose ()
operator() (size_t i, size_t j) const
coefRef operator() (size_t i, size_t j)
void erase (size_t i, size_t j)
Coef (size_t i, size_t j) const
coefRef Coef (size_t i, size_t j)
Coef (const_iterator p) const
t & Coef (const_iterator p)
svector_ref operator() (size_t i, const rng &range)
svector_ref operator() (const rng &range, size_t j)
const_svector_ref operator() (size_t i, const rng &range) const
const_svector_ref operator() (const rng &range, size_t j) const
svector_ref row (size_t i)
svector_ref row (size_t i, const rng &range)
svector_ref col (size_t j)
svector_ref col (const rng &range, size_t j)
const_svector_ref row (size_t i) const
const_svector_ref row (size_t i, const rng &range) const
const_svector_ref col (size_t j) const
const_svector_ref col (const rng &range, size_t j) const
iterator IterFor (size_t n, size_t Start, const vector_map *p)
const_iterator IterFor (size_t n, size_t Start, const vector_map *p) const
iterator EndOf (size_t n, vector_map *p)
const_iterator EndOf (size_t n, const vector_map *p) const
iterator IterForRow (size_t i, size_t jStart=1)
const_iterator IterForRow (size_t i, size_t jStart=1) const
const_iterator EndOfRow (size_t i) const
iterator EndOfRow (size_t i)
iterator IterForCol (size_t j, size_t iStart=1)
const_iterator IterForCol (size_t j, size_t iStart=1) const
const_iterator EndOfCol (size_t j) const
iterator EndOfCol (size_t j)
smatrix< t > operator+ (const smatrix< t > &b) const
smatrix< t > operator- (const smatrix< t > &b) const
smatrix< t > operator * (const smatrix< t > &b) const
bool operator== (const smatrix< t > &b) const
bool operator!= (const const smatrix< t > &b)
bool operator! ()
void PivotMap (size_t a, size_t b, vector_map *Source, vector_map &Dest)
bool Pivot (size_t k, size_t &MaxIdx, t &MaxCoef, vector_map *Source, vector_map &Dest)
void PivotRow (size_t k, size_t MaxIdx, smatrix< t > *pMatix=NULL)
bool PivotRow (size_t k, t &MaxCoef, smatrix< t > *pMatix=NULL)
void PivotCol (size_t k, size_t MaxIdx, smatrix< t > *pMatix=NULL)
bool PivotCol (size_t k, t &MaxCoef, smatrix< t > *pMatix=NULL)
bool GetDiag (size_t k, t &Diag, bool bWithPartialPivot=false, smatrix< t > *pMatix=NULL)
bool FwdElim (bool bWithPartialPivot, bool bErase=true)
bool BackElim (bool bErase=true, bool bScaleDiag=true)
bool SolveWithGaussElim (const smatrix< t > &m, bool bWithPartialPivot=true)
smatrix< t > SolveWithGaussElim (bool bWithPartialPivot=true) const
det (bool bWithPartialPivot)
int lnScaledDet (t &lnScale, bool bWithPartialPivot)
int lnScaledDet (const smatrix< t > &m, t &lnScale, bool bWithPartialPivot)
int lnScaledDet (t &lnScale, bool bWithPartialPivot=true) const
bool FwdElim (smatrix< t > &m, bool bWithPartialPivot)
void RecalcMaxCoef ()
bool BackElim (smatrix< t > &m)
smatrix< t > Solve (const smatrix< t > &L, const smatrix< t > &U) const
smatrix< t > Inverse (bool bWithPartialPivot) const
FrobeniousNormal () const
smatrix< t > & operator *= (const t &d)
smatrix< t > operator * (const t &d) const
void PrintListing (ostream &os) const

Static Public Methods

template<class ta, class tb> t svMultiply (const ta &a, const tb &b)
size_t Index (const_iterator p)
size_t Index (iterator p)
size_t CoefPtr (const_iterator p)
size_t CoefPtr (iterator p)

Public Attributes

vector< t > e
epsilon
maxCoef
vector_mapiMap
vector_mapjMap
size_t iDim
size_t jDim
size_t NZ
size_t FirstBlank
size_t FreeSlots
bool bOddNumPivots

Static Public Attributes

size_t PrintWidth = 8
size_t PrintPrecision = 3

template<class t>
class smatrix< t >


Member Typedef Documentation

template<class t>
typedef map<size_t, size_t>::const_iterator smatrix::const_iterator
 

Definition at line 131 of file Smatrix.hpp.

template<class t>
typedef map<size_t, size_t>::iterator smatrix::iterator
 

Definition at line 130 of file Smatrix.hpp.

template<class t>
typedef pair<size_t, size_t> smatrix::mapping
 

Definition at line 132 of file Smatrix.hpp.

Referenced by PivotMap(), and insert().


Constructor & Destructor Documentation

template<class t>
virtual smatrix< t >::~smatrix   [inline, virtual]
 

Definition at line 134 of file Smatrix.hpp.

00135     {
00136         delete(iMap);
00137         delete(jMap);
00138     }

template<class t>
smatrix< t >::smatrix   [inline]
 

Definition at line 139 of file Smatrix.hpp.

00139               : iMap(NULL), jMap(NULL), maxCoef(0), 
00140         epsilon(0) { initialize(0, 0, 0); }

template<class t>
smatrix< t >::smatrix const smatrix< t > &    a [inline]
 

Definition at line 141 of file Smatrix.hpp.

00141                                  : iMap(NULL), jMap(NULL) 
00142     {
00143         *this = a;
00144     }

template<class t>
smatrix< t >::smatrix const t *    d,
size_t    iDim,
size_t    jDim
[inline]
 

Definition at line 145 of file Smatrix.hpp.

00145                                                   : iMap(NULL), jMap(NULL) 
00146     {
00147         initialize(iDim, jDim, iDim * jDim);
00148         for(size_t r = 1; r <= iDim; r++)
00149         {
00150             for(size_t c = 1; c <= jDim; c++, d++)
00151             {
00152                 if(*d != 0)
00153                     insert(r, c, *d);
00154             }
00155         }
00156     }

template<class t>
smatrix< t >::smatrix size_t    iDim,
size_t    jDim,
size_t    MaxNZ
[inline]
 

Definition at line 157 of file Smatrix.hpp.

00157                                                     : iMap(NULL), jMap(NULL) 
00158     {
00159         initialize(iDim, jDim, MaxNZ);
00160     }


Member Function Documentation

template<class t>
bool smatrix< t >::BackElim smatrix< t > &    m [inline]
 

Definition at line 955 of file Smatrix.hpp.

00956     {
00957         for(size_t k = iDim; k >= 1; k--)
00958         {
00959             t Diag;
00960             if(!GetDiag(k, Diag)) return(false);
00961             Diag = t(-1.0) / Diag;
00962             iterator i = IterForCol(k);
00963             while(Index(i) < k)
00964             {
00965                 t Scaler = Coef(i) * Diag;
00966                 size_t r = Index(i++);
00967                 row(r) += row(k, rng(k, k)) * Scaler;
00968                 m.row(r) += m.row(k) * Scaler;
00969             }
00970             m.row(k) *= -Diag;
00971         }
00972         m.RecalcMaxCoef();
00973         return(true);
00974     }

template<class t>
bool smatrix< t >::BackElim bool    bErase = true,
bool    bScaleDiag = true
[inline]
 

Definition at line 850 of file Smatrix.hpp.

Referenced by Inverse(), TLUDecomp::Inverse(), Solve(), TLUDecomp::Solve(), and SolveWithGaussElim().

00851     {
00852         for(size_t k = iDim; k >= 1; k--)
00853         {
00854             t Diag;
00855             if(!GetDiag(k, Diag)) return(false);
00856             Diag = t(-1.0) / Diag;
00857             iterator i = IterForCol(k);
00858             while(Index(i) < k)
00859             {
00860                 t Scaler = Coef(i) * Diag;
00861                 size_t r = Index(i++);
00862                 row(r) += row(k) * Scaler;
00863                 if(bErase) erase(r, k);
00864             }
00865             if(bScaleDiag) row(k) *= -Diag;
00866         }
00867         return(true);
00868     }

template<class t>
t& smatrix< t >::Coef const_iterator    p [inline]
 

Definition at line 596 of file Smatrix.hpp.

00596 { return(e[p->second]); }

template<class t>
t smatrix< t >::Coef const_iterator    p const [inline]
 

Definition at line 595 of file Smatrix.hpp.

00595 { return(e[p->second]); }

template<class t>
coefRef smatrix< t >::Coef size_t    i,
size_t    j
[inline]
 

Definition at line 594 of file Smatrix.hpp.

00594 { return((*this)(i, j)); }

template<class t>
t smatrix< t >::Coef size_t    i,
size_t    j
const [inline]
 

Definition at line 593 of file Smatrix.hpp.

Referenced by BackElim(), TLUDecomp::BackElim(), TLUDecomp::Decompose(), FwdElim(), TLUDecomp::FwdElim(), GetDiag(), TLUDecomp::L(), Pivot(), det(), and svMultiply().

00593 { return((*this)(i, j)); }

template<class t>
size_t smatrix< t >::CoefPtr iterator    p [inline, static]
 

Definition at line 600 of file Smatrix.hpp.

00600 { return(p->second); }

template<class t>
size_t smatrix< t >::CoefPtr const_iterator    p [inline, static]
 

Definition at line 599 of file Smatrix.hpp.

Referenced by PivotMap().

00599 { return(p->second); }

template<class t>
const_iterator smatrix< t >::EndOf size_t    n,
const vector_map   p
const [inline]
 

Definition at line 643 of file Smatrix.hpp.

00644     {
00645         const map<size_t, size_t> *Map = (n > p->size() ? (*p)[0] : (*p)[n]);
00646         return(Map->end());
00647     }

template<class t>
iterator smatrix< t >::EndOf size_t    n,
vector_map   p
[inline]
 

Definition at line 638 of file Smatrix.hpp.

Referenced by EndOfCol(), EndOfRow(), and PivotMap().

00639     {
00640         map<size_t, size_t> *Map = (n > p->size() ? (*p)[0] : (*p)[n]);
00641         return(Map->end());
00642     }

template<class t>
iterator smatrix< t >::EndOfCol size_t    j [inline]
 

Definition at line 662 of file Smatrix.hpp.

00663         { return(EndOf(j, jMap)); }

template<class t>
const_iterator smatrix< t >::EndOfCol size_t    j const [inline]
 

Definition at line 660 of file Smatrix.hpp.

Referenced by TLUDecomp::Decompose(), FwdElim(), TLUDecomp::FwdElim(), and PrintListing().

00661         { return(EndOf(j, jMap)); }

template<class t>
iterator smatrix< t >::EndOfRow size_t    i [inline]
 

Definition at line 654 of file Smatrix.hpp.

00655         { return(EndOf(i, iMap)); }

template<class t>
const_iterator smatrix< t >::EndOfRow size_t    i const [inline]
 

Definition at line 652 of file Smatrix.hpp.

Referenced by PrintListing(), and RecalcMaxCoef().

00653         { return(EndOf(i, iMap)); }

template<class t>
t smatrix< t >::FrobeniousNormal   const [inline]
 

Definition at line 1000 of file Smatrix.hpp.

01001     {
01002         if(NZ == 0) return(0);
01003         t d(0);
01004         for(vector<t>::const_iterator i = e.begin(); i != e.end(); i++)
01005             d += *i * *i;
01006         return(sqrt(d));
01007     }

template<class t>
bool smatrix< t >::FwdElim smatrix< t > &    m,
bool    bWithPartialPivot
[inline]
 

Definition at line 923 of file Smatrix.hpp.

00924     {
00925         for(size_t k = 1; k < iDim; k++)
00926         {
00927             t Diag;
00928             if(!GetDiag(k, Diag, bWithPartialPivot, &m)) return(false);
00929             Diag = t(-1.0) / Diag;
00930             iterator i = IterForCol(k, k + 1);
00931             while(i != EndOfCol(k))
00932             {
00933                 t Scaler = Coef(i) * Diag;
00934                 size_t r = Index(i++);
00935                 row(r) += row(k, rng(k + 1, jDim)) * Scaler;
00936                 m.row(r) += m.row(k) * Scaler;
00937             }
00938         }
00939         t Diag = Coef(k, k);
00940         if(abs(Diag) < epsilon)
00941             return(false);
00942         return(true);
00943     }

template<class t>
bool smatrix< t >::FwdElim bool    bWithPartialPivot,
bool    bErase = true
[inline]
 

Definition at line 829 of file Smatrix.hpp.

Referenced by Inverse(), TLUDecomp::Inverse(), Solve(), TLUDecomp::Solve(), SolveWithGaussElim(), det(), and lnScaledDet().

00830     {
00831         for(size_t k = 1; k < iDim; k++)
00832         {
00833             t Diag;
00834             if(!GetDiag(k, Diag, bWithPartialPivot)) return(false);
00835             Diag = t(-1.0) / Diag;
00836             iterator i = IterForCol(k, k + 1);
00837             while(i != EndOfCol(k))
00838             {
00839                 t Scaler = Coef(i) * Diag;
00840                 size_t r = Index(i++);
00841                 row(r) += row(k, rng(k + 1, jDim)) * Scaler;
00842                 if(bErase) erase(r, k);
00843             }
00844         }
00845         t Diag = Coef(k, k);
00846         if(abs(Diag) < epsilon)
00847             return(false);
00848         return(true);
00849     }

template<class t>
bool smatrix< t >::GetDiag size_t    k,
t &    Diag,
bool    bWithPartialPivot = false,
smatrix< t > *    pMatix = NULL
[inline]
 

Definition at line 816 of file Smatrix.hpp.

Referenced by BackElim(), TLUDecomp::Decompose(), FwdElim(), and lnScaledDet().

00817     {
00818         if(bWithPartialPivot)
00819         {
00820             if(PivotRow(k, Diag, pMatix) == false)
00821                 return(false);
00822         }
00823         else
00824             Diag = Coef(k, k);
00825         if(abs(Diag) < epsilon)
00826             return(false);
00827         return(true);
00828     }

template<class t>
size_t smatrix< t >::Index iterator    p [inline, static]
 

Definition at line 598 of file Smatrix.hpp.

00598 { return(p->first); }

template<class t>
size_t smatrix< t >::Index const_iterator    p [inline, static]
 

Definition at line 597 of file Smatrix.hpp.

Referenced by BackElim(), TLUDecomp::BackElim(), TLUDecomp::Decompose(), FwdElim(), TLUDecomp::FwdElim(), Pivot(), PivotMap(), TLUDecomp::Solve(), and svMultiply().

00597 { return(p->first); }

template<class t>
smatrix<t> smatrix< t >::Inverse bool    bWithPartialPivot const [inline]
 

Definition at line 987 of file Smatrix.hpp.

00988     {
00989         smIdentity<t> c(iDim);
00990         c.epsilon = epsilon;
00991         smatrix<t> m(*this);
00992 
00993         if(m.FwdElim(c, bWithPartialPivot))
00994         {
00995             if(m.BackElim(c))
00996                 return(c);
00997         }
00998         return(smatrix<t>());
00999     }

template<class t>
const_iterator smatrix< t >::IterFor size_t    n,
size_t    Start,
const vector_map   p
const [inline]
 

Definition at line 633 of file Smatrix.hpp.

00634     {
00635         const map<size_t, size_t> *Map = (n > p->size() ? (*p)[0] : (*p)[n]);
00636         return(Start <= 1 ? Map->begin() : Map->lower_bound(Start));
00637     }

template<class t>
iterator smatrix< t >::IterFor size_t    n,
size_t    Start,
const vector_map   p
[inline]
 

Definition at line 628 of file Smatrix.hpp.

Referenced by IterForCol(), IterForRow(), and PivotMap().

00629     {
00630         map<size_t, size_t> *Map = (n > p->size() ? (*p)[0] : (*p)[n]);
00631         return(Start <= 1 ? Map->begin() : Map->lower_bound(Start));
00632     }

template<class t>
const_iterator smatrix< t >::IterForCol size_t    j,
size_t    iStart = 1
const [inline]
 

Definition at line 658 of file Smatrix.hpp.

00659         { return(IterFor(j, iStart, jMap)); }

template<class t>
iterator smatrix< t >::IterForCol size_t    j,
size_t    iStart = 1
[inline]
 

Definition at line 656 of file Smatrix.hpp.

Referenced by BackElim(), TLUDecomp::BackElim(), TLUDecomp::Decompose(), FwdElim(), TLUDecomp::FwdElim(), PrintListing(), and TLUDecomp::Solve().

00657         { return(IterFor(j, iStart, jMap)); }

template<class t>
const_iterator smatrix< t >::IterForRow size_t    i,
size_t    jStart = 1
const [inline]
 

Definition at line 650 of file Smatrix.hpp.

00651         { return(IterFor(i, jStart, iMap)); }

template<class t>
iterator smatrix< t >::IterForRow size_t    i,
size_t    jStart = 1
[inline]
 

Definition at line 648 of file Smatrix.hpp.

Referenced by PrintListing(), RecalcMaxCoef(), and insert().

00649         { return(IterFor(i, jStart, iMap)); }

template<class t>
bool smatrix< t >::Pivot size_t    k,
size_t &    MaxIdx,
t &    MaxCoef,
vector_map   Source,
vector_map   Dest
[inline]
 

Definition at line 762 of file Smatrix.hpp.

Referenced by PivotCol(), and PivotRow().

00763     {
00764         iterator p = Dest[k]->lower_bound(k);
00765         if(p == Dest[k]->end())
00766             return(false);
00767         MaxIdx = Index(p);
00768         MaxCoef = Coef(p);
00769         for(p++; p != Dest[k]->end(); p++)
00770         {
00771             if(abs(MaxCoef) < abs(Coef(p)))
00772             {
00773                 MaxCoef = Coef(p);
00774                 MaxIdx = Index(p);
00775             }
00776         }
00777         if(k != MaxIdx)
00778             PivotMap(k, MaxIdx, Source, Dest);
00779 
00780         return(true);
00781     }

template<class t>
bool smatrix< t >::PivotCol size_t    k,
t &    MaxCoef,
smatrix< t > *    pMatix = NULL
[inline]
 

Definition at line 805 of file Smatrix.hpp.

00806     {
00807         size_t MaxIdx;
00808         if(Pivot(k, MaxCoef, jMap, *iMap, L))
00809         {
00810             if(pMatix != NULL && k != MaxIdx)
00811                 pMatix->PivotMap(k, MaxIdx, pMatix->jMap, *pMatix->iMap);
00812             return(true);
00813         }
00814         return(false);
00815     }

template<class t>
void smatrix< t >::PivotCol size_t    k,
size_t    MaxIdx,
smatrix< t > *    pMatix = NULL
[inline]
 

Definition at line 799 of file Smatrix.hpp.

00800     {
00801         PivotMap(k, MaxIdx, jMap, *iMap);
00802         if(pMatix != NULL && k != MaxIdx)
00803             pMatix->PivotMap(k, MaxIdx, pMatix->jMap, *pMatix->iMap);
00804     }

template<class t>
void smatrix< t >::PivotMap size_t    a,
size_t    b,
vector_map   Source,
vector_map   Dest
[inline]
 

Definition at line 718 of file Smatrix.hpp.

Referenced by Pivot(), PivotCol(), and PivotRow().

00719     {
00720         bOddNumPivots = (bOddNumPivots == false);
00721         if(a != b)
00722         {
00723             const_iterator ia = IterFor(a, 1, Source);
00724             const_iterator ib = IterFor(b, 1, Source);
00725             while(ia != EndOf(a, Source) || ib != EndOf(b, Source))
00726             {
00727                 if(ia == EndOf(a, Source))
00728                 {
00729                     Dest[Index(ib)]->erase(b);
00730                     Dest[Index(ib)]->insert(mapping(a, CoefPtr(ib)));
00731                     ib++;
00732                 }
00733                 else if(ib == EndOf(b, Source))
00734                 {
00735                     Dest[Index(ia)]->erase(a);
00736                     Dest[Index(ia)]->insert(mapping(b, CoefPtr(ia)));
00737                     ia++;
00738                 }
00739                 else if(Index(ia) > Index(ib))
00740                 {
00741                     Dest[Index(ib)]->erase(b);
00742                     Dest[Index(ib)]->insert(mapping(a, CoefPtr(ib)));
00743                     ib++;
00744                 }
00745                 else if(Index(ia) < Index(ib))
00746                 {
00747                     Dest[Index(ia)]->erase(a);
00748                     Dest[Index(ia)]->insert(mapping(b, CoefPtr(ia)));
00749                     ia++;
00750                 }
00751                 else
00752                 {
00753                     map<size_t, size_t> &p = *Dest[Index(ia)];
00754                     swap(p[a], p[b]);
00755                     ia++;
00756                     ib++;
00757                 }
00758             }
00759         }
00760         swap((*Source)[a], (*Source)[b]);
00761     }

template<class t>
bool smatrix< t >::PivotRow size_t    k,
t &    MaxCoef,
smatrix< t > *    pMatix = NULL
[inline]
 

Definition at line 788 of file Smatrix.hpp.

00789     {
00790         size_t MaxIdx;
00791         if(Pivot(k, MaxIdx, MaxCoef, iMap, *jMap))
00792         {
00793             if(pMatix != NULL && k != MaxIdx)
00794                 pMatix->PivotMap(k, MaxIdx, pMatix->iMap, *pMatix->jMap);
00795             return(true);
00796         }
00797         return(false);
00798     }

template<class t>
void smatrix< t >::PivotRow size_t    k,
size_t    MaxIdx,
smatrix< t > *    pMatix = NULL
[inline]
 

Definition at line 782 of file Smatrix.hpp.

Referenced by GetDiag().

00783     {
00784         PivotMap(k, MaxIdx, iMap, *jMap);
00785         if(pMatix != NULL && k != MaxIdx)
00786             pMatix->PivotMap(k, MaxIdx, pMatix->iMap, *pMatix->jMap);
00787     }

template<class t>
void smatrix< t >::PrintListing ostream &    os const [inline]
 

Definition at line 1019 of file Smatrix.hpp.

01020     {
01021         os << "Matrix" << endl;
01022         os << *this << endl;
01023         os << "vector<t> e" << endl;
01024         for(size_t n = 0; n < e.size(); n++)
01025             os << e[n] << " ";
01026         os << endl << endl;
01027 
01028         for(size_t r = 1; r <= iDim; r++)
01029         {
01030             os << "iMap[" << r << "] ";
01031             for(const_iterator i = IterForRow(r); i != EndOfRow(r); i++)
01032                 os << "(" << i->first << ", " << i->second << ") ";
01033             os << endl;
01034         }
01035         os << endl;
01036         for(size_t c = 1; c <= jDim; c++)
01037         {
01038             os << "jMap[" << c << "] ";
01039             for(const_iterator j = IterForCol(c); j != EndOfCol(c); j++)
01040                 os << "(" << j->first << ", " << j->second << ") ";
01041             os << endl;
01042         }
01043     }

template<class t>
void smatrix< t >::RecalcMaxCoef   [inline]
 

Definition at line 944 of file Smatrix.hpp.

Referenced by BackElim().

00945     {
00946         maxCoef = t(0);
00947         epsilon = 0;
00948         for(size_t i = 1; i < iDim; i++)
00949         {
00950             iterator j = IterForRow(i);            
00951             for(; j != EndOfRow(i); j++)
00952                 CalcEpsilon(maxCoef, epsilon, e[j->second]);
00953         }
00954     }

template<class t>
size_t smatrix< t >::SlackSpace   const [inline]
 

Definition at line 212 of file Smatrix.hpp.

Referenced by reserve().

00213     {
00214         return(FreeSlots + (e.size() - NZ));
00215     }

template<class t>
smatrix<t> smatrix< t >::Solve const smatrix< t > &    L,
const smatrix< t > &    U
const [inline]
 

Definition at line 975 of file Smatrix.hpp.

00976     {
00977         smatrix<t> m, c(*this);
00978         m = L;
00979         if(m.FwdElim(c, false))
00980         {
00981             m = U;
00982             if(m.BackElim(c))
00983                 return(c);
00984         }
00985         return(smatrix<t>());
00986     }

template<class t>
smatrix<t> smatrix< t >::SolveWithGaussElim bool    bWithPartialPivot = true const [inline]
 

Definition at line 875 of file Smatrix.hpp.

00876     {
00877         smatrix<t> m;
00878         if(m.SolveWithGaussElim(*this, bWithPartialPivot) == false)
00879             return(smatrix<t>());
00880         return(m);
00881     }

template<class t>
bool smatrix< t >::SolveWithGaussElim const smatrix< t > &    m,
bool    bWithPartialPivot = true
[inline]
 

Definition at line 869 of file Smatrix.hpp.

Referenced by SolveWithGaussElim().

00870     {
00871         *this = m;
00872         if(FwdElim(bWithPartialPivot) == false) return(false);
00873         return(BackElim());
00874     }

template<class t>
double smatrix< t >::Sparsity   const [inline]
 

Definition at line 216 of file Smatrix.hpp.

00217     {
00218         return((double)NZ / (iDim * jDim));
00219     }

template<class t>
smatrix<t>& smatrix< t >::Transpose   [inline]
 

Definition at line 280 of file Smatrix.hpp.

00281     { 
00282         swap(iMap, jMap); 
00283         swap(iDim, jDim);
00284         return(*this);
00285     }

template<class t>
iterator smatrix< t >::ZeroInsert size_t    i,
size_t    j
[inline]
 

Definition at line 273 of file Smatrix.hpp.

00274     {
00275         iterator iIter, jIter;
00276         t d(0);
00277         insert(i, j, d, iIter, jIter, true);
00278         return(iIter);
00279     }

template<class t>
const_svector_ref smatrix< t >::col const rng   range,
size_t    j
const [inline]
 

Definition at line 625 of file Smatrix.hpp.

00626         { return(const_svector_ref(this, range, j)); }

template<class t>
const_svector_ref smatrix< t >::col size_t    j const [inline]
 

Definition at line 623 of file Smatrix.hpp.

00624         { return(const_svector_ref(this, rng(1, iDim), j)); }

template<class t>
svector_ref smatrix< t >::col const rng   range,
size_t    j
[inline]
 

Definition at line 617 of file Smatrix.hpp.

00618         { return(svector_ref(this, range, j)); }

template<class t>
svector_ref smatrix< t >::col size_t    j [inline]
 

Definition at line 615 of file Smatrix.hpp.

Referenced by operator *().

00616         { return(svector_ref(this, rng(1, iDim), j)); }

template<class t>
t smatrix< t >::det bool    bWithPartialPivot [inline]
 

Definition at line 882 of file Smatrix.hpp.

Referenced by det().

00883     {
00884         if(iDim != jDim) return(t(0));
00885         FwdElim(bWithPartialPivot, true);
00886         t d(bOddNumPivots ? -1.0 : 1.0);
00887         for(size_t k = 1; k <= iDim; k++)
00888             d *= Coef(k, k);
00889         return(d);
00890     }

template<class t>
void smatrix< t >::erase size_t    i,
size_t    j
[inline]
 

Definition at line 582 of file Smatrix.hpp.

00583     {
00584         map<size_t, size_t> *r = (*iMap)[i];
00585         map<size_t, size_t>::iterator p = r->find(j);
00586         if(p != r->end())
00587         {
00588             erase(p->second);
00589             r->erase(p);
00590             (*jMap)[j]->erase(i);
00591         }
00592     }

template<class t>
void smatrix< t >::erase size_t    pos [inline]
 

Definition at line 205 of file Smatrix.hpp.

Referenced by BackElim(), FwdElim(), PivotMap(), erase(), smatrix::svector_ref::erase(), and smatrix::coefRef::operator=().

00206     {
00207         e[pos] = FirstBlank;
00208         FirstBlank = pos;
00209         NZ--;
00210         FreeSlots++;
00211     }

template<class t>
void smatrix< t >::initialize size_t    iDim,
size_t    jDim,
size_t    MaxNZ
[inline]
 

Definition at line 199 of file Smatrix.hpp.

00200     {
00201         this->iDim = iDim;
00202         this->jDim = jDim;
00203         initialize(MaxNZ);
00204     }

template<class t>
void smatrix< t >::initialize size_t    MaxNZ [inline]
 

Definition at line 183 of file Smatrix.hpp.

Referenced by initialize(), operator *(), operator+(), operator-(), and smatrix().

00184     {
00185         delete(iMap);
00186         iMap = new vector_map;
00187         delete(jMap);
00188         jMap = new vector_map;
00189         e.reserve(MaxNZ);
00190         iMap->resize(iDim + 1);
00191         jMap->resize(jDim + 1);
00192         FirstBlank = (size_t)-1;
00193         NZ = 0;
00194         FreeSlots = 0;
00195         bOddNumPivots = false;
00196         epsilon = 0;
00197         maxCoef = 0;
00198     }

template<class t>
iterator smatrix< t >::insert size_t    i,
size_t    j,
const t &    d
[inline]
 

Definition at line 266 of file Smatrix.hpp.

00267     {
00268         iterator iIter, jIter;
00269         if(insert(i, j, d, iIter, jIter))
00270             return(iIter);
00271         return(IterForRow(0, 0));
00272     }

template<class t>
bool smatrix< t >::insert size_t    i,
size_t    j,
const t &    d,
iterator   iIter,
iterator   jIter,
bool    bZeroInsert = false
[inline]
 

Definition at line 226 of file Smatrix.hpp.

Referenced by PivotMap(), ZeroInsert(), smatrix::svector_ref::insert(), insert(), operator *(), smatrix::coefRef::operator=(), smIdentity::smIdentity(), and smatrix().

00227     {
00228         if(bZeroInsert == false && abs(d) <= epsilon)
00229             return(false);
00230 
00231         size_t pos;
00232         if(FirstBlank != (size_t)-1)
00233         {
00234             pos = FirstBlank;
00235             FirstBlank = (size_t)e[pos];
00236             FreeSlots--;
00237         }
00238         else
00239         {
00240             if(e.capacity() == e.size())
00241                 e.reserve(e.size() + (e.size() / 10));
00242             pos = e.size();
00243             e.insert(e.end());
00244         }
00245         NZ++;
00246 
00247         e[pos] = d;
00248         CalcEpsilon(maxCoef, epsilon, d);
00249 
00250         if(i > iDim)
00251         {
00252             iDim = i;
00253             iMap->resize(iDim + 1);
00254         }
00255         jIter = (*iMap)[i]->insert(mapping(j, pos)).first;
00256 
00257         if(j > jDim)
00258         {
00259             jDim = j;
00260             jMap->resize(jDim + 1);
00261         }
00262         iIter = (*jMap)[j]->insert(mapping(i, pos)).first;
00263 
00264         return(true);
00265     }

template<class t>
int smatrix< t >::lnScaledDet t &    lnScale,
bool    bWithPartialPivot = true
const [inline]
 

Definition at line 918 of file Smatrix.hpp.

00919     {
00920         smatrix<t> m;
00921         return(m.lnScaledDet(*this, lnScale, bWithPartialPivot));
00922     }

template<class t>
int smatrix< t >::lnScaledDet const smatrix< t > &    m,
t &    lnScale,
bool    bWithPartialPivot
[inline]
 

Definition at line 913 of file Smatrix.hpp.

00914     {
00915         *this = m;
00916         return(lnScaledDet(lnScale, bWithPartialPivot));
00917     }

template<class t>
int smatrix< t >::lnScaledDet t &    lnScale,
bool    bWithPartialPivot
[inline]
 

Definition at line 891 of file Smatrix.hpp.

Referenced by lnScaledDet().

00892     {
00893         lnScale = t(0);
00894 
00895         if(iDim != jDim) return(t(0));
00896         FwdElim(bWithPartialPivot, true);
00897         int sign = (bOddNumPivots ? -1 : 1);
00898 
00899         for(size_t k = 1; k <= iDim; k++)
00900         {
00901             t d;
00902             if(!GetDiag(k, d, false)) return(false);
00903             if(d > 0) 
00904                 lnScale += log(d);
00905             else
00906             {
00907                 sign *= -1;
00908                 lnScale += log(-d);
00909             }
00910         }
00911         return(sign);
00912     }

template<class t>
smatrix<t> smatrix< t >::operator * const t &    d const [inline]
 

Definition at line 1014 of file Smatrix.hpp.

01015     {
01016         smatrix<t> c(*this);
01017         return(c *= d);
01018     }

template<class t>
smatrix<t> smatrix< t >::operator * const smatrix< t > &    b const [inline]
 

Definition at line 681 of file Smatrix.hpp.

00682     {
00683         smatrix<t> c;
00684 
00685         c.iDim = iDim;
00686         c.jDim = b.jDim;
00687         size_t MaxNZ = max(NZ, b.NZ);
00688         if(c.iDim == 1 && c.jDim == 1) MaxNZ = 1;
00689         else if(c.iDim == 1 || c.jDim == 1) MaxNZ = max(c.iDim, c.jDim);
00690         c.initialize(MaxNZ);
00691 
00692         for(size_t i = 1; i <= iDim; i++)
00693         {
00694             const_svector_ref r = row(i);
00695             for(size_t j = 1; j <= b.jDim; j++)
00696             {
00697                 t d = svMultiply(r, b.col(j));
00698                 c.insert(i, j, d);
00699             }
00700         }
00701         return(c);
00702     }

template<class t>
smatrix<t>& smatrix< t >::operator *= const t &    d [inline]
 

Definition at line 1008 of file Smatrix.hpp.

01009     {
01010         for(vector<t>::iterator i = e.begin(); i != e.end(); i++)
01011             *i *= d;
01012         return(*this);
01013     }

template<class t>
bool smatrix< t >::operator!   [inline]
 

Definition at line 717 of file Smatrix.hpp.

00717 { return(NZ == 0); }

template<class t>
bool smatrix< t >::operator!= const const smatrix< t > &    b [inline]
 

Definition at line 713 of file Smatrix.hpp.

00714     {
00715         return(operator==(b) == false);
00716     }

template<class t>
const_svector_ref smatrix< t >::operator() const rng   range,
size_t    j
const [inline]
 

Definition at line 608 of file Smatrix.hpp.

00609         { return(const_svector_ref(this, range, j)); }

template<class t>
const_svector_ref smatrix< t >::operator() size_t    i,
const rng   range
const [inline]
 

Definition at line 606 of file Smatrix.hpp.

00607         { return(const_svector_ref(this, i, range)); }

template<class t>
svector_ref smatrix< t >::operator() const rng   range,
size_t    j
[inline]
 

Definition at line 604 of file Smatrix.hpp.

00605         { return(svector_ref(this, range, j)); }

template<class t>
svector_ref smatrix< t >::operator() size_t    i,
const rng   range
[inline]
 

Definition at line 602 of file Smatrix.hpp.

00603         { return(svector_ref(this, i, range)); }

template<class t>
coefRef smatrix< t >::operator() size_t    i,
size_t    j
[inline]
 

Definition at line 578 of file Smatrix.hpp.

00579     {
00580         return(coefRef(this, i, j));
00581     }

template<class t>
t smatrix< t >::operator() size_t    i,
size_t    j
const [inline]
 

Definition at line 524 of file Smatrix.hpp.

00525     {
00526         if(i > iDim || j > jDim) return(0);
00527         const map<size_t, size_t> *r = (*iMap)[i];
00528         map<size_t, size_t>::const_iterator p = r->find(j);
00529         if(p == r->end())
00530             return(0);
00531         return(e[p->second]);
00532     }

template<class t>
smatrix<t> smatrix< t >::operator+ const smatrix< t > &    b const [inline]
 

Definition at line 665 of file Smatrix.hpp.

00666     {
00667         smatrix<t> c;
00668         c.initialize(max(iDim, b.iDim), max(jDim, b.jDim), NZ + b.NZ);
00669         for(size_t i = 1; i <= iDim; i++)
00670             c.row(i) = row(i) + b.row(i);
00671         return(c);
00672     }

template<class t>
smatrix<t> smatrix< t >::operator- const smatrix< t > &    b const [inline]
 

Definition at line 673 of file Smatrix.hpp.

00674     {
00675         smatrix<t> c;
00676         c.initialize(max(iDim, b.iDim), max(jDim, b.jDim), NZ + b.NZ);
00677         for(size_t i = 1; i <= iDim; i++)
00678             c.row(i) = row(i) - b.row(i);
00679         return(c);
00680     }

template<class t>
smatrix<t>& smatrix< t >::operator= const smatrix< t > &    a [inline]
 

Definition at line 161 of file Smatrix.hpp.

00162     {
00163         e = a.e;
00164         epsilon = a.epsilon;
00165         maxCoef = a.maxCoef;
00166 
00167         delete(iMap);
00168         iMap = new vector_map;
00169         *iMap = *a.iMap;
00170 
00171         delete(jMap);
00172         jMap = new vector_map;
00173         *jMap = *a.jMap;
00174 
00175         NZ = a.NZ;
00176         iDim = a.iDim;
00177         jDim = a.jDim;
00178         FirstBlank = a.FirstBlank;
00179         bOddNumPivots = a.bOddNumPivots;
00180 
00181         return(*this);
00182     }

template<class t>
bool smatrix< t >::operator== const smatrix< t > &    b const [inline]
 

Definition at line 703 of file Smatrix.hpp.

Referenced by operator!=().

00704     {
00705         if(iDim != b.iDim || jDim != b.jDim || NZ != b.NZ) return(false);
00706         for(size_t i = 1; i <= iDim; i++)
00707         {
00708             if(row(i) != b.row(i))
00709                 return(false);
00710         }
00711         return(true);
00712     }

template<class t>
void smatrix< t >::reserve size_t    space [inline]
 

Definition at line 220 of file Smatrix.hpp.

00221     {
00222         size_t slack = SlackSpace();
00223         if(slack < space)
00224             e.reserve(space - FreeSlots);
00225     }

template<class t>
const_svector_ref smatrix< t >::row size_t    i,
const rng   range
const [inline]
 

Definition at line 621 of file Smatrix.hpp.

00622         { return(const_svector_ref(this, i, range)); }

template<class t>
const_svector_ref smatrix< t >::row size_t    i const [inline]
 

Definition at line 619 of file Smatrix.hpp.

00620         { return(const_svector_ref(this, i, rng(1, jDim))); }

template<class t>
svector_ref smatrix< t >::row size_t    i,
const rng   range
[inline]
 

Definition at line 613 of file Smatrix.hpp.

00614         { return(svector_ref(this, i, range)); }

template<class t>
svector_ref smatrix< t >::row size_t    i [inline]
 

Definition at line 611 of file Smatrix.hpp.

Referenced by BackElim(), TLUDecomp::BackElim(), TLUDecomp::Decompose(), FwdElim(), TLUDecomp::FwdElim(), TLUDecomp::L(), TLUDecomp::Solve(), TLUDecomp::U(), operator *(), operator+(), operator-(), and operator==().

00612         { return(svector_ref(this, i, rng(1, jDim))); }

template<class t>
template<class ta, class tb>
t smatrix< t >::svMultiply const ta &    a,
const tb &    b
[inline, static]
 

Definition at line 286 of file Smatrix.hpp.

Referenced by operator *(), smatrix::const_svector_ref::operator *(), and smatrix::svector::operator *().

00287     {
00288         size_t first = max(a.range.first, b.range.first);
00289         size_t last = min(a.range.second, b.range.second);
00290 
00291         ta::const_iterator ia = a.lower_bound(first);
00292         ta::const_iterator iaEnd = a.lower_bound(last + 1);
00293 
00294         tb::const_iterator ib = b.lower_bound(first);
00295         tb::const_iterator ibEnd = b.lower_bound(last + 1);
00296 
00297         t d(0);
00298         while(ia != iaEnd && ib != ibEnd) 
00299         {
00300             if(a.Index(ia) < b.Index(ib))
00301                 ia++;
00302             else if(a.Index(ia) > b.Index(ib))
00303                 ib++;
00304             else
00305             {
00306                 addEq(d, a.Coef(ia) * b.Coef(ib), false);
00307                 ia++;
00308                 ib++;
00309             }
00310         }
00311         return(d);
00312     }


Member Data Documentation

template<class t>
size_t smatrix::FirstBlank
 

Definition at line 126 of file Smatrix.hpp.

Referenced by operator=().

template<class t>
size_t smatrix::FreeSlots
 

Definition at line 126 of file Smatrix.hpp.

template<class t>
size_t smatrix::NZ
 

Definition at line 126 of file Smatrix.hpp.

Referenced by TLUDecomp::Solve(), operator *(), operator+(), operator-(), operator<<(), operator=(), and operator==().

template<class t>
size_t smatrix< t >::PrintPrecision = 3 [static]
 

Definition at line 6 of file test_sm.cpp.

template<class t>
size_t smatrix< t >::PrintWidth = 8 [static]
 

Definition at line 5 of file test_sm.cpp.

template<class t>
bool smatrix::bOddNumPivots
 

Definition at line 127 of file Smatrix.hpp.

Referenced by operator=().

template<class t>
vector<t> smatrix::e
 

Definition at line 123 of file Smatrix.hpp.

Referenced by smatrix::svector_ref::Coef(), smatrix::const_svector_ref::Coef(), smatrix::coefRef::operator t(), smatrix::svector_ref::operator()(), smatrix::const_svector_ref::operator()(), smatrix::coefRef::operator=(), and operator=().

template<class t>
t smatrix::epsilon
 

Definition at line 124 of file Smatrix.hpp.

Referenced by smatrix::svector_ref::CalcEpsilon(), smatrix::const_svector_ref::GetEpsilon(), Inverse(), operator<<(), smatrix::coefRef::operator=(), and operator=().

template<class t>
size_t smatrix::iDim
 

Definition at line 126 of file Smatrix.hpp.

Referenced by TLUDecomp::Solve(), operator *(), smatrix::coefRef::operator t(), operator+(), operator-(), operator<<(), smatrix::coefRef::operator=(), operator=(), and operator==().

template<class t>
vector_map* smatrix::iMap
 

Definition at line 125 of file Smatrix.hpp.

Referenced by smatrix::svector_ref::GetMap(), smatrix::const_svector_ref::GetMap(), smatrix::svector_ref::erase(), smatrix::coefRef::operator t(), smatrix::coefRef::operator=(), and operator=().

template<class t>
size_t smatrix::jDim
 

Definition at line 126 of file Smatrix.hpp.

Referenced by TLUDecomp::Solve(), operator *(), smatrix::coefRef::operator t(), operator+(), operator-(), operator<<(), smatrix::coefRef::operator=(), operator=(), and operator==().

template<class t>
vector_map * smatrix::jMap
 

Definition at line 125 of file Smatrix.hpp.

Referenced by smatrix::svector_ref::GetMap(), smatrix::const_svector_ref::GetMap(), smatrix::svector_ref::erase(), and operator=().

template<class t>
t smatrix::maxCoef
 

Definition at line 124 of file Smatrix.hpp.

Referenced by smatrix::svector_ref::CalcEpsilon(), operator<<(), smatrix::coefRef::operator=(), and operator=().


The documentation for this class was generated from the following files:
Generated on Sun Oct 14 18:49:44 2001 for Standard J2K Library by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001