# Optimizing sums of products (dot products)

**URL:** <https://discourse.julialang.org/t/optimizing-sums-of-products-dot-products/119515>\
**Category:** Performance\
**Tags:** simd, linearalgebra, sum\
**Created:** [September 17, 2024, 4:40pm UTC](https://discourse.julialang.org/t/optimizing-sums-of-products-dot-products/119515 "2024-09-17T16:40:15Z")\
**Posts on this page:** 1\
**Showing post:** 12

<div class="post-metadata">

**Author:** ![danielwe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danielwe/32/35657_2.png) [@danielwe](https://discourse.julialang.org/u/danielwe)\
**Post date:** [September 23, 2024, 6:43pm UTC](https://discourse.julialang.org/t/optimizing-sums-of-products-dot-products/119515/12 "2024-09-23T18:43:59Z")

</div>

> [@mikmoore](#):
>
> `afn` “allow approximate functions” - This allows some LLVM functions like `sin`, `cos`, `log`, `exp`, to be replaced with less accurate versions that are faster. However, Julia does not use these LLVM versions so I don’t believe this has any effect in Julia (as of v1.10, at least, and probably for a while yet).

`@fastmath` doesn’t just set compiler flags; the `ninf`, `nnan`, and `afn` flags are (mostly?) implemented in Julia, replacing Julia-native functions like `sin` and `exp` with Julia-native equivalents like `sin_fast` and `exp_fast`. See the full list at [julia/base/fastmath.jl at 0fade450a183470b01c656a9001512ef2f1aae47 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/blob/0fade450a183470b01c656a9001512ef2f1aae47/base/fastmath.jl#L35-L93).

For the most part, the implementations only differ for complex numbers, but you also have things like `hypot_fast(x, y) = sqrt(x * x + y * y)`, i.e., throwing caution about over/underflow to the wind, which I guess makes sense next to `isinf_fast(x) = false` and `issubnormal_fast(x) = false`.

---

_[View the full topic](https://discourse.julialang.org/t/optimizing-sums-of-products-dot-products/119515)._
