#function #testing #approximation #math

nikisas_test

Utilities for testing implementation quality of mathematical functions. Computing errors for inputs randomly sampled from given interval.

1 unstable release

0.1.0 Sep 25, 2020

#36 in #approximation

MIT license

34KB
563 lines

nikisas_test

Utilities for testing implementation quality of mathematical functions. Computing errors for inputs randomly sampled from given interval.

Usage

To determine the errors:

use nikisas_test::prelude::*;

fn exp(x: f32) -> f32 {
    // your implementation
    # 0.0
}

// Uniformly sample 100000 values from -87.3 to 88.7.
UniformSample::with_count(-87.3, 88.7, 100000)
    // Use implementation from the standard library as ground truth.
    .error(|x| (exp(x), x.exp()))
    // Print the errors to standard output.
    .print_plain("exp");

To ensure desired error bounds:

use nikisas_test::prelude::*;

// Uniformly sample 100000 values from -87.3 to 88.7.
UniformSample::with_count(-87.3, 88.7, 100000)
    // Use implementation from the standard library as ground truth.
    // If eny specified error bound is violated, the program panics with a readable message.
    .assert(ErrorBounds::new().rel(0.001).abs(0.0001), |x| (exp(x), x.exp()));

Documentation

See documentation on crates.io.

License

nikisas_test is licensed under MIT. Feel free to use it, contribute or spread the word.

Dependencies

~1.4–2MB
~37K SLoC