News for hackers. Stuff that matters.
Re:A not so fast implementation of cosine similarity in C++ ... by mshockwave on Tuesday October 15, 2024 @06:39PM (#41853866)
which flags did you use and which compiler version?
Re:A not so fast implementation of cosine similarity in C++ ... by QuadmasterXLII on Tuesday October 15, 2024 @06:42PM (#41853882)
clang 19, -O3 -ffast-math -march=native
Re:A not so fast implementation of cosine similarity in C++ ... by mshockwave on Tuesday October 15, 2024 @06:56PM (#41853962)
can confirm fast math makes the biggest difference
Re:A not so fast implementation of cosine similarity in C++ ... by QuadmasterXLII on Tuesday October 15, 2024 @08:14PM (#41854399)
I feel like I’m kinda being the bad aunt by encouraging -ffast-math. It can definitely break some things (i.e. https://pspdfkit.com/blog/2021/understanding-fast-math/ ) but I use it habitually and I’m fine so clearly it’s safe.
Re:A not so fast implementation of cosine similarity in C++ ... by magicalhippo on Tuesday October 15, 2024 @09:11PM (#41854704)
> It can definitely break some things

I recall it totally fudged up the ray-axis aligned bounding box intersection routine in the raytracer I worked on. The routine relied on infinities being handled correctly, and -ffast-math broke that.

I see the linked article goes into that aspect in detail, wish I had it back then.

IIRC we ended up disabling it for just that file, as it did speed up the rest my a fair bit.

Re:A not so fast implementation of cosine similarity in C++ ... by hansvm on Wednesday October 16, 2024 @10:05AM (#41859169)
I would love a fast-math implementation which handled inf correctly, but no language/compiler seems to care.
Re:A not so fast implementation of cosine similarity in C++ ... by mkristiansen on Tuesday October 15, 2024 @07:19PM (#41854114)
Fast Math basically means "who cares about standards just add in whatever order you want" :)