π Geometric Computer Vision Library for Spatial AI
cart2pol now computes float16 and bfloat16 radii in float32 and rounds them once. It used to form x ** 2 + y ** 2 in the input dtype, so a float16 radius of about 256 or more gave rho = nan ((300, 150)) and small float16 radii were inexact ((2e-4, 0) gave 2.44e-4). Inside the eps neighbourhood rho is now the exact radius: it used to be computed as (rho + 1) - 1, which in float32 turned (1e-5, 0) into 1.0014e-5 and every radius below about 6e-8 into 0, and in bfloat16 every radius up to 1e-4 into 0. A float32 or float64 square sum that overflows now gives rho = inf instead of nan. Elsewhere float32 and float64 values and gradients are unchanged; float16 and bfloat16 radii and gradients can move by about one unit in the last place, to the correctly rounded value. The gradient inside eps is still zero, and for float16 input eps is compared with the float32 square sum, so radii between 1e-4 and about 2e-4 now get the gradient x / rho instead of 0 or a wrong value.