You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hypot (https://en.wikipedia.org/wiki/Hypot) computes the hypotenuse of a right-angle triangle. The motivation essentially boils down to underflow/overflow problems with the naive implementation r = T.sqrt (x*x + y*y). It seems natural to add it since we already have atan2, and they are frequently used together for the purpose of transforming Cartesian coordinates to polar coordinates.
Implementation example:
let hypot x y =
if x == 0 && y == 0
then 0
else
let switch = f32.abs x < f32.abs y
let (x, y) = if switch then (y, x) else (x, y)
let square a = a * a
in f32.abs x * f32.sqrt (1 + square (y/x))
There are implementations with more cases to reduce the number of math operations, but I'm not sure they make sense in the context of execution masks.
The text was updated successfully, but these errors were encountered:
The policy for including mathematical primitive functions is that we try to include everything that is available in the C math library. This is because I don't want the Futhark compiler itself to become distracted by the yak-shaving of implementing numerically high-quality primitives (although libraries can shave whichever yaks they want).
But hypot is actually part of the C11 math library, so we should definitely include it. It is also part of both OpenCL and CUDA, as far as I can see.
Hypot (https://en.wikipedia.org/wiki/Hypot) computes the hypotenuse of a right-angle triangle. The motivation essentially boils down to underflow/overflow problems with the naive implementation
r = T.sqrt (x*x + y*y)
. It seems natural to add it since we already haveatan2
, and they are frequently used together for the purpose of transforming Cartesian coordinates to polar coordinates.Implementation example:
There are implementations with more cases to reduce the number of math operations, but I'm not sure they make sense in the context of execution masks.
The text was updated successfully, but these errors were encountered: