Bug report mtl library, sparse matrices
Alexander Dreyer <[email protected]>
| Newsgroups | gmane.comp.lib.mtl.devel |
|---|---|
| Organization | Fraunhofer ITWM |
| Message-ID | <[email protected]> |
Dear Sirs,
Experimenting with sparse matrices on mtl I recently found the following
strange behavior, which seems to be a bug.
The c++ program code:
-------------------------------------------------------------------------------------
#include <iostream.h>
#include <mtl/matrix.h>
#include <mtl/mtl.h>
#include <mtl/utils.h>
#include <mtl/sparse1D.h>
using namespace mtl;
typedef matrix<double, rectangle<>, array< linked_list > ,
row_major>::type
theMatrix;
main(){
theMatrix whatIsTheMatrix(2, 2);
whatIsTheMatrix(0,1)=1;
print_all_matrix(whatIsTheMatrix);
for(theMatrix::iterator theRow = whatIsTheMatrix.begin();
theRow != whatIsTheMatrix.end();
++theRow)
for(theMatrix::OneD::iterator theElt =(*theRow).begin();
theElt != (*theRow).end();
++theElt)
cout << *theElt<<endl;cout.flush();
}
-------------------------------------------------------------------------------------
The output of the complied program was the following:
BASH sparseTest
2x2
[
[0,0],
[0,0]
]
BASH
-------------------------------------------------------------------------------------
My quick fix for this problem is to change
static inline bool notequal(const self& x, const self& y)
of
template <class Cat> struct choose
at line 67 of sparse_iterator.h as follows:
-------------------------------------------------------------------------------------
template <class self>
static inline bool self& x, const self& y) {
//AD changed from
// return x.pos != y.pos;
return x.iter != y.iter;
}
-------------------------------------------------------------------------------------
As far as I understand the code of mtl, x.pos and y.pos are always zero
in this case.
Hence for loops (as above or used in operator[](int) const of sparse1D)
terminate too early (i.e. immediately).
After fixing notequal, the expected result is obtained:
-------------------------------------------------------------------------------------
BASH sparseTest
2x2
[
[0,1],
[0,0]
]
1
BASH
-------------------------------------------------------------------------------------
Is the bug already knows to you? Is this the best way to fix the
problem? (My changes may also interfere other mtl matrix types.)
I'm using mtl-2.1.2-21 on linux with gcc version 2.95.2 19991024.
Sincerely yours
Alexander Dreyer
PS: Since my PhD-Thesis will also be about solving sparse systems, I
would be interested to know if there are any sparse solvers implemented
yet.
--
/ Alexander Dreyer, Dipl.-Math. - Abteilung Adaptive Systeme \
/ Fraunhofer Institut fuer Techno- und Wirtschaftsmathematik (ITWM) \
\ Gottlieb-Daimler-Strasse, Geb. 7^2=49/313 D-67663 Kaiserslautern /
\ http://www.itwm.fhg.de Tel.:(0631)205-2851 Fax:(0631)205-4139 /
_______________________________________________
This list is archived at http://www.osl.iu.edu/MailArchives/mtl-devel/