optional threshold for sparsemat::simplify

This commit is contained in:
Jiri Pittner 2022-08-11 16:02:15 +02:00
parent dc0b823c3a
commit 43e53b0bbc
2 changed files with 4 additions and 4 deletions

View File

@ -315,7 +315,7 @@ return nonzero; //number of (in principle) nonzero elements
template <class T>
void SparseMat<T>::simplify()
void SparseMat<T>::simplify(const double sparseepsilon)
{
unsigned int n;
if(!list) return;
@ -352,7 +352,7 @@ for(i=1; i<n;i++)
//check if summed to zero
for(i=0; i<n;i++) if(rowsorted[i] &&
std::abs(rowsorted[i]->elem)<=SPARSEEPSILON
std::abs(rowsorted[i]->elem)<=sparseepsilon
) {delete rowsorted[i]; rowsorted[i]=NULL;}
//restore connectivity

View File

@ -23,7 +23,7 @@ namespace LA {
//threshold for neglecting elements, if not defined, no tests are done except exact zero test in simplify - might be even faster
//seems to perform better with a threshold, in spite of abs() tests
const double SPARSEEPSILON=1e-35;
const double SPARSEEPSILON=1e-15;
typedef unsigned int SPMatindex;
typedef int SPMatindexdiff; //more clear would be to use traits
@ -140,7 +140,7 @@ public:
unsigned int length() const;
void copyonwrite(bool detachonly=false);
void clear() {copyonwrite(LA_traits<T>::is_plaindata()); if(count) {delete count; count=NULL;}}
void simplify();
void simplify(const double sparseepsilon=SPARSEEPSILON);
const T trace() const;
const typename LA_traits<T>::normtype norm(const T scalar=(T)0) const; //is const only mathematically, not in internal implementation - we have to simplify first
unsigned int sort(int type) const;