summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Dyer <redpony@gmail.com>2014-05-15 00:45:56 -0400
committerChris Dyer <redpony@gmail.com>2014-05-15 00:45:56 -0400
commit926ed91f7364150eac0867097d80457999a8132f (patch)
tree49f56c4e0e3398d5bf97519edcf514172ef57d6b
parentc11c7af0746edbceec5ad49e2e8efeb34bceaa6b (diff)
use fma if available
-rw-r--r--utils/fast_sparse_vector.h8
1 files changed, 8 insertions, 0 deletions
diff --git a/utils/fast_sparse_vector.h b/utils/fast_sparse_vector.h
index 590a60c4..6e2a77cd 100644
--- a/utils/fast_sparse_vector.h
+++ b/utils/fast_sparse_vector.h
@@ -384,13 +384,21 @@ class FastSparseVector {
T dot(const std::vector<T>& v) const {
T res = T();
for (const_iterator it = begin(), e = end(); it != e; ++it)
+#if FP_FAST_FMA
+ if (static_cast<unsigned>(it->first) < v.size()) res = std::fma(it->second, v[it->first], res);
+#else
if (static_cast<unsigned>(it->first) < v.size()) res += it->second * v[it->first];
+#endif
return res;
}
T dot(const FastSparseVector<T>& other) const {
T res = T();
for (const_iterator it = begin(), e = end(); it != e; ++it)
+#if FP_FAST_FMA
+ res = std::fma(other.value(it->first), it->second, res);
+#else
res += other.value(it->first) * it->second;
+#endif
return res;
}
bool operator==(const FastSparseVector<T>& other) const {