diff options
author | Chris Dyer <redpony@gmail.com> | 2014-05-15 00:45:56 -0400 |
---|---|---|
committer | Chris Dyer <redpony@gmail.com> | 2014-05-15 00:45:56 -0400 |
commit | 025ecf4978e37e4b5aa31e4ac3c7953a29a89b07 (patch) | |
tree | 8e5f2c8867ecc52ecec2b294e6f4f91b13ad5d26 /utils | |
parent | f5cc1e175e11a59ec1297d4d823f0d59820bf346 (diff) |
use fma if available
Diffstat (limited to 'utils')
-rw-r--r-- | utils/fast_sparse_vector.h | 8 |
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 { |