optional threshold for sparsemat::simplify
This commit is contained in:
		
							parent
							
								
									dc0b823c3a
								
							
						
					
					
						commit
						43e53b0bbc
					
				@ -315,7 +315,7 @@ return nonzero; //number of (in principle) nonzero elements
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
template <class T>
 | 
					template <class T>
 | 
				
			||||||
void SparseMat<T>::simplify()
 | 
					void SparseMat<T>::simplify(const double sparseepsilon)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
unsigned int n;
 | 
					unsigned int n;
 | 
				
			||||||
if(!list) return;
 | 
					if(!list) return;
 | 
				
			||||||
@ -352,7 +352,7 @@ for(i=1; i<n;i++)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
//check if  summed to zero
 | 
					//check if  summed to zero
 | 
				
			||||||
for(i=0; i<n;i++) if(rowsorted[i] &&
 | 
					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;}
 | 
						)	 {delete rowsorted[i]; rowsorted[i]=NULL;}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//restore connectivity
 | 
					//restore connectivity
 | 
				
			||||||
 | 
				
			|||||||
@ -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
 | 
					//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
 | 
					//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 unsigned int SPMatindex;
 | 
				
			||||||
typedef int SPMatindexdiff; //more clear would be to use traits
 | 
					typedef int SPMatindexdiff; //more clear would be to use traits
 | 
				
			||||||
@ -140,7 +140,7 @@ public:
 | 
				
			|||||||
	unsigned int length() const;
 | 
						unsigned int length() const;
 | 
				
			||||||
	void copyonwrite(bool detachonly=false);
 | 
						void copyonwrite(bool detachonly=false);
 | 
				
			||||||
	void clear() {copyonwrite(LA_traits<T>::is_plaindata()); if(count) {delete count; count=NULL;}}
 | 
						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 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
 | 
						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;
 | 
						unsigned int sort(int type) const;
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user