spherical-volume-rendering / svr-algorithm

A spherical volume rendering algorithm that performs ray casting through a spherical voxel grid.
Other
6 stars 7 forks source link

Performance bottleneck with equality. #123

Closed cgyurgyik closed 4 years ago

cgyurgyik commented 4 years ago
    inline bool isKnEqual(double a, double b) noexcept {
        const double diff = std::abs(a - b);
        if (diff <= ABS_EPSILON) { return true; }
        return diff <= std::max(std::abs(a), std::abs(b)) * REL_EPSILON;
    }

This is currently the performance bottleneck. One consideration would be to only use return std::abs(a - b) <= ABS_EPSILON, with degradation in accuracy. FWIW, all our current tests pass using only ABS_EPSILON

cgyurgyik commented 4 years ago

Thoughts on this @matthewturk ?

cgyurgyik commented 4 years ago

image N = 100

For reference. The current version uses:

 inline bool isKnEqual(double a, double b) noexcept {
        const double diff = std::abs(a - b);
        if (diff <= ABS_EPSILON) { return true; }
        return diff <= std::max(std::abs(a), std::abs(b)) * REL_EPSILON;
    }

The optimized version uses:

 inline bool isKnEqual(double a, double b) noexcept {
        return std::abs(a - b) <= ABS_EPSILON;
    }
matthewturk commented 4 years ago

Genuinely surprised, but in principle I'd say ABS_EPSILON by itself is fine. yt has a unit system that allows us to scale the values going in, so we can always ensure that ABS_EPSILON is roughly within an OOM of REL_EPSILON.