/*
$Id: Matrices.h 15565 2013-01-07 14:27:05Z sloot $
$URL: https://ilk.uvt.nl/svn/trunk/sources/Timbl6/include/timbl/Matrices.h $
Copyright (c) 1998 - 2013
ILK - Tilburg University
CLiPS - University of Antwerp
This file is part of timbl
timbl 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 3 of the License, or
(at your option) any later version.
timbl 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, see .
For questions and suggestions, see:
http://ilk.uvt.nl/software.html
or send mail to:
timbl@uvt.nl
*/
#ifndef TIMBL_MATRICES_H
#define TIMBL_MATRICES_H
template class SparseSymetricMatrix;
template std::ostream& operator << (std::ostream&,
const SparseSymetricMatrix& );
template
class SparseSymetricMatrix {
typedef std::map< Class, double > CDmap;
typedef std::map< Class, CDmap > CCDmap;
friend std::ostream& operator << <> ( std::ostream&,
const SparseSymetricMatrix& );
public:
void Clear() { my_mat.clear(); };
void Assign( Class i, Class j, double d ){
if ( i == j )
return;
if ( i second.find(i);
if ( it2 != it1->second.end() ){
return it2->second;
}
}
}
else {
typename CCDmap::const_iterator it1 = my_mat.find(i);
if ( it1 != my_mat.end() ){
typename CDmap::const_iterator it2 = it1->second.find(j);
if ( it2 != it1->second.end() ){
return it2->second;
}
}
}
return 0.0;
};
unsigned int NumBytes(void) const{
unsigned int tot = sizeof(std::map);
typename CCDmap::const_iterator it1 = my_mat.begin();
while ( it1 != my_mat.end() ){
tot += sizeof(CDmap);
typename CDmap::const_iterator it2 = it1->second.begin();
while ( it2 != it1->second.end() ){
tot += sizeof(double);
++it2;
}
++it1;
}
return tot;
};
SparseSymetricMatrix *copy(void) const{
SparseSymetricMatrix *res = new SparseSymetricMatrix();
typename CCDmap::const_iterator it1 = my_mat.begin();
while ( it1 != my_mat.end() ){
typename CDmap::const_iterator it2 = it1->second.begin();
while ( it2 != it1->second.end() ){
res->my_mat[it1->first][it2->first] = it2->second;
++it2;
}
++it1;
}
return res;
}
private:
CCDmap my_mat;
};
template
inline std::ostream& operator << (std::ostream& os,
const SparseSymetricMatrix& m ){
typename SparseSymetricMatrix::CCDmap::const_iterator it1 = m.my_mat.begin();
while ( it1 != m.my_mat.end() ){
typename SparseSymetricMatrix::CDmap::const_iterator it2 = it1->second.begin();
while ( it2 != it1->second.end() ){
os << "[" << it1->first << ",\t" << it2->first << "] "
<< it2->second << std::endl;
++it2;
}
++it1;
}
return os;
}
#endif // TIMBL_MATRICES_H