sparse module:

* add row(i), col(i) functions
* add prune() function to remove small coefficients
This commit is contained in:
Gael Guennebaud
2009-01-21 18:46:04 +00:00
parent 25f1658fce
commit 52cf07d266
8 changed files with 138 additions and 17 deletions

View File

@@ -31,6 +31,7 @@
template<typename Scalar>
class CompressedStorage
{
typedef typename NumTraits<Scalar>::Real RealScalar;
public:
CompressedStorage()
: m_values(0), m_indices(0), m_size(0), m_allocatedSize(0)
@@ -183,6 +184,22 @@ class CompressedStorage
}
return m_values[id];
}
void prune(Scalar reference, RealScalar epsilon = precision<RealScalar>())
{
int k = 0;
int n = size();
for (int i=0; i<n; ++i)
{
if (!ei_isMuchSmallerThan(value(i), reference, epsilon))
{
value(k) = value(i);
index(k) = index(i);
++k;
}
}
resize(k,0);
}
protected: