From 025ecf4978e37e4b5aa31e4ac3c7953a29a89b07 Mon Sep 17 00:00:00 2001 From: Chris Dyer Date: Thu, 15 May 2014 00:45:56 -0400 Subject: use fma if available --- utils/fast_sparse_vector.h | 8 ++++++++ 1 file changed, 8 insertions(+) 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& v) const { T res = T(); for (const_iterator it = begin(), e = end(); it != e; ++it) +#if FP_FAST_FMA + if (static_cast(it->first) < v.size()) res = std::fma(it->second, v[it->first], res); +#else if (static_cast(it->first) < v.size()) res += it->second * v[it->first]; +#endif return res; } T dot(const FastSparseVector& 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& other) const { -- cgit v1.2.3