62 inline void alloc(
size_t nl,
size_t nc,
size_t nz);
63 inline void destroy();
71 inline size_t nlin()
const ;
72 inline size_t ncol()
const ;
73 inline void write(std::ostream& f)
const;
74 inline void read(std::istream& f);
76 inline double operator()(
size_t i,
size_t j)
const;
77 inline double& operator()(
size_t i,
size_t j);
83 inline void info()
const;
90 f << M.
nlin() <<
" " << M.
ncol() << std::endl;
92 for(
size_t i=0;i<M.
nlin();i++)
96 f<<(
long unsigned int)i<<
"\t"<<(
long unsigned int)M.
js[j]<<
"\t"<<M.
tank[j]<<std::endl;
103 if ((nlin() == 0) && (ncol() == 0)) {
104 std::cout <<
"Matrix Empty" << std::endl;
108 std::cout <<
"Dimensions : " << nlin() <<
" x " << ncol() << std::endl;
133 tank=
new double[M.
size()];
134 js=
new size_t[M.
size()];
135 rowindex=
new size_t[M.
nlin()+1];
136 m_nlin=(size_t)M.
nlin();
137 m_ncol=(size_t)M.
ncol();
142 size_t current_line = (size_t)-1;
143 for( it = M.
begin(); it != M.
end(); ++it) {
144 size_t i = it->first.first;
145 size_t j = it->first.second;
146 double val = it->second;
149 if(i != current_line) {
150 for(
size_t k = current_line+1; k <= i; ++k) {
158 for(
size_t k = current_line+1; k <= M.
nlin(); ++k) {
159 rowindex[k]=M.
size();
166 size_t nz=rowindex[m_nlin];
167 f.write((
const char*)&m_nlin,(std::streamsize)
sizeof(
size_t));
168 f.write((
const char*)&m_ncol,(std::streamsize)
sizeof(
size_t));
169 f.write((
const char*)&nz,(std::streamsize)
sizeof(
size_t));
170 f.write((
const char*)tank,(std::streamsize)(
sizeof(
double)*nz));
171 f.write((
const char*)js,(std::streamsize)(
sizeof(
size_t)*nz));
172 f.write((
const char*)rowindex,(std::streamsize)(
sizeof(
size_t)*m_nlin));
179 f.read((
char*)&m_nlin,(std::streamsize)
sizeof(
size_t));
180 f.read((
char*)&m_ncol,(std::streamsize)
sizeof(
size_t));
181 f.read((
char*)&nz,(std::streamsize)
sizeof(
size_t));
182 alloc(m_nlin,m_ncol,nz);
183 f.read((
char*)tank,(std::streamsize)(
sizeof(
double)*nz));
184 f.read((
char*)js,(std::streamsize)(
sizeof(
size_t)*nz));
185 f.read((
char*)rowindex,(std::streamsize)(
sizeof(
size_t)*m_nlin));
194 rowindex=
new size_t[nl+1];
219 for(
size_t k=rowindex[i];k<rowindex[i+1];k++)
221 if(js[k]<j)
continue;
222 else if(js[k]==j)
return tank[k];
231 for(
size_t k=rowindex[i];k<rowindex[i+1];k++)
233 if(js[k]<j)
continue;
234 else if(js[k]==j)
return tank[k];
238 std::cerr<<
"FastSparseMatrix : double& operator()(size_t i,size_t j) can't add element"<<std::endl;
245 double *pt_result=&result(0);
247 double *pt_vect=&(*_v)(0);
249 for(
size_t i=0;i<m_nlin;i++)
251 double& total=pt_result[i];
252 for(
size_t j=rowindex[i];j<rowindex[i+1];j++) {
253 total+=tank[j]*pt_vect[js[j]];
void read(std::istream &f)
Vector operator*(const Vector &v) const
void write(std::ostream &f) const
const_iterator end() const
std::ostream & operator<<(std::ostream &os, const Conductivity< REP > &m)
double & operator[](size_t i)
Vect3 operator*(const double &d, const Vect3 &v)
void operator=(const FastSparseMatrix &M)
std::map< std::pair< size_t, size_t >, double >::const_iterator const_iterator
void alloc(size_t nl, size_t nc, size_t nz)
double operator()(size_t i, size_t j) const
const_iterator begin() const
virtual size_t ncol() const