6 if( i<0 || j<0 ||
m<=i ||
n<=j ){
8 std::cerr <<
"The required component is out of the matrix size." << std::endl
9 <<
"Your input is (" << i <<
"," << j <<
"), whereas the matrix size is " <<
m <<
"x" <<
n <<
"." << std::endl;
15 const std::vector<CPPL_INT>::const_iterator rows_i_end =
rows[
i].end();
16 for(std::vector<CPPL_INT>::const_iterator p=
rows[i].begin(); p!=rows_i_end; p++){
17 if(
data[*p].j==j){
return data[*p].v; }
29 if( i<0 || j<0 ||
m<=i ||
n<=j ){
31 std::cerr <<
"The required component is out of the matrix size." << std::endl
32 <<
"Your input is (" << i <<
"," << j <<
"), whereas the matrix size is " <<
m <<
"x" <<
n <<
"." << std::endl;
38 const std::vector<CPPL_INT>::iterator rows_i_end =
rows[
i].end();
39 for(std::vector<CPPL_INT>::iterator p=
rows[i].begin(); p!=rows_i_end; p++){
40 if(
data[*p].j==j){
return data[*p].v; }
45 cols[j].push_back(CPPL_INT(
data.size()));
59 if( i<0 || j<0 ||
m<=i ||
n<=j ){
61 std::cerr <<
"The required component is out of the matrix size." << std::endl
62 <<
"Your input is (" << i <<
"," << j <<
"), whereas the matrix size is " <<
m <<
"x" <<
n <<
"." << std::endl;
65 const std::vector<dcomponent>::const_iterator data_end =
data.end();
66 for(std::vector<dcomponent>::const_iterator it=
data.begin(); it!=data_end; it++){
67 if( it->i==i && it->j==j ){
69 std::cerr <<
"The required component is already listed." << std::endl
70 <<
"Your input was (" << i <<
"," << j <<
"," << v <<
")." << std::endl;
78 cols[j].push_back(CPPL_INT(
data.size()));
93 if( i<0 || j<0 ||
m<=i ||
n<=j ){
95 std::cerr <<
"The required component is out of the matrix size." << std::endl
96 <<
"Your input is (" << i <<
"," << j <<
"), whereas the matrix size is " <<
m <<
"x" <<
n <<
"." << std::endl;
102 const std::vector<CPPL_INT>::iterator rows_i_end =
rows[
i].end();
103 for(std::vector<CPPL_INT>::iterator p=
rows[i].begin(); p!=rows_i_end; p++){
107 CPPL_INT C =CPPL_INT(
data.size()-1);
115 const std::vector<CPPL_INT>::iterator cols_j_end =
cols[j].end();
116 for(std::vector<CPPL_INT>::iterator q=
cols[j].begin(); q!=cols_j_end; q++){
117 if(*q==c){
cols[j].erase(q);
break; }
121 CPPL_INT I(data[c].i), J(data[c].j);
122 const std::vector<CPPL_INT>::iterator rows_I_end =
rows[I].end();
123 for(std::vector<CPPL_INT>::iterator q=
rows[I].begin(); q!=rows_I_end; q++){
124 if(*q==C){ *q=c;
break; }
126 const std::vector<CPPL_INT>::iterator cols_J_end =
cols[J].end();
127 for(std::vector<CPPL_INT>::iterator q=
cols[J].begin(); q!=cols_J_end; q++){
128 if(*q==C){ *q=c;
break; }
135 std::cerr <<
"# [NOTE]@dgsmatrix::del(CPPL_INT&, CPPL_INT&): The required component was not listed. Your input was (" << i <<
"," << j <<
")." << std::endl;
144 {CPPL_VERBOSE_REPORT;
145 if( c==CPPL_INT(
data.size()-1) ){
147 const std::vector<CPPL_INT>::iterator rows_i_end =
rows[
i].end();
148 for(std::vector<CPPL_INT>::iterator q=
rows[i].begin(); q!=rows_i_end; q++){
149 if(*q==c){
rows[
i].erase(q);
break; }
151 const std::vector<CPPL_INT>::iterator cols_j_end =
cols[j].end();
152 for(std::vector<CPPL_INT>::iterator q=
cols[j].begin(); q!=cols_j_end; q++){
153 if(*q==c){
cols[j].erase(q);
break; }
160 CPPL_INT C =CPPL_INT(
data.size()-1);
164 const std::vector<CPPL_INT>::iterator rows_i_end =
rows[
i].end();
165 for(std::vector<CPPL_INT>::iterator q=
rows[i].begin(); q!=rows_i_end; q++){
166 if(*q==c){
rows[
i].erase(q);
break; }
168 const std::vector<CPPL_INT>::iterator cols_j_end =
cols[j].end();
169 for(std::vector<CPPL_INT>::iterator q=
cols[j].begin(); q!=cols_j_end; q++){
170 if(*q==c){
cols[j].erase(q);
break; }
173 const std::vector<CPPL_INT>::iterator rows_I_end =
rows[I].end();
174 for(std::vector<CPPL_INT>::iterator q=
rows[I].begin(); q!=rows_I_end; q++){
175 if(*q==C){ *q=c;
break; }
177 const std::vector<CPPL_INT>::iterator cols_J_end =
cols[J].end();
178 for(std::vector<CPPL_INT>::iterator q=
cols[J].begin(); q!=cols_J_end; q++){
179 if(*q==C){ *q=c;
break; }
194 {CPPL_VERBOSE_REPORT;
195 for(CPPL_INT
i=0;
i<mat.
m;
i++){
196 const std::vector<CPPL_INT>::const_iterator mat_rows_i_end =mat.
rows[
i].end();
197 for(CPPL_INT j=0; j<mat.
n; j++){
198 std::vector<CPPL_INT>::const_iterator q;
199 for(q=mat.
rows[
i].begin(); q!=mat_rows_i_end; q++){
200 if(mat.
data[*q].j==j){
break; }
202 if(q!=mat_rows_i_end){ s <<
" " << mat.
data[*q].v; }
217 {CPPL_VERBOSE_REPORT;
218 std::ofstream ofs(filename, std::ios::trunc);
219 ofs.setf(std::cout.flags());
220 ofs.precision(std::cout.precision());
221 ofs.width(std::cout.width());
222 ofs.fill(std::cout.fill());
224 ofs <<
"#dgsmatrix " <<
m <<
" " <<
n <<
" " <<
data.size() << std::endl;
226 const std::vector<dcomponent>::const_iterator data_end =
data.end();
227 for(std::vector<dcomponent>::const_iterator it=
data.begin(); it!=data_end; it++){
228 ofs << it->i <<
" " << it->j <<
" " << it->v << std::endl;
236 {CPPL_VERBOSE_REPORT;
237 std::ifstream s( filename );
240 std::cerr <<
"The file \"" << filename <<
"\" can not be opened." << std::endl;
247 if(
id !=
"dgsmatrix" &&
id !=
"#dgsmatrix" ){
249 std::cerr <<
"The type name of the file \"" << filename <<
"\" is not dgsmatrix." << std::endl
250 <<
"Its type name was " <<
id <<
" ." << std::endl;
263 for(
size_t k=0; k<size; k++){
272 std::cerr <<
"There is something is wrong with the file \"" << filename <<
" ." << std::endl
273 <<
"Most likely, there are too many data components over the context." << std::endl;
Real Double-precision General Sparse Matrix Class.
std::vector< dcomponent > data
matrix data
double operator()(const CPPL_INT &, const CPPL_INT &) const
Component Class for Real Double-precision Sparse Matrix Classes.
CPPL_INT n
matrix column size
std::vector< std::vector< CPPL_INT > > cols
array of vector to store the entry information of component for each column
_dgematrix i(const _dgbmatrix &mat)
dgsmatrix & del(const CPPL_INT, const CPPL_INT)
void write(const char *) const
dgsmatrix & put(const CPPL_INT &, const CPPL_INT &, const double &)
std::ostream & operator<<(std::ostream &s, const dgsmatrix &mat)
dgsmatrix & resize(const CPPL_INT &, const CPPL_INT &, const CPPL_INT=0, const CPPL_INT=0)
std::vector< std::vector< CPPL_INT > > rows
array of vector to store the entry information of component for each row
CPPL_INT m
matrix row size