summaryrefslogtreecommitdiff
path: root/utils/fast_sparse_vector.h
diff options
context:
space:
mode:
Diffstat (limited to 'utils/fast_sparse_vector.h')
-rw-r--r--utils/fast_sparse_vector.h19
1 files changed, 10 insertions, 9 deletions
diff --git a/utils/fast_sparse_vector.h b/utils/fast_sparse_vector.h
index 4aae2039..9d72cb87 100644
--- a/utils/fast_sparse_vector.h
+++ b/utils/fast_sparse_vector.h
@@ -235,6 +235,13 @@ class FastSparseVector {
}
return *this;
}
+ FastSparseVector<T> erase_zeros(const T& EPSILON = 1e-4) const {
+ FastSparseVector<T> o;
+ for (const_iterator it = begin(); it != end(); ++it) {
+ if (fabs(it->second) > EPSILON) o.set_value(it->first, it->second);
+ }
+ return o;
+ }
const_iterator begin() const {
return const_iterator(*this, false);
}
@@ -344,15 +351,9 @@ const FastSparseVector<T> operator+(const FastSparseVector<T>& x, const FastSpar
template <typename T>
const FastSparseVector<T> operator-(const FastSparseVector<T>& x, const FastSparseVector<T>& y) {
- if (x.size() > y.size()) {
- FastSparseVector<T> res(x);
- res -= y;
- return res;
- } else {
- FastSparseVector<T> res(y);
- res -= x;
- return res;
- }
+ FastSparseVector<T> res(x);
+ res -= y;
+ return res;
}
template <class T>