Skip to main content

Crate reproducible

Crate reproducible 

Source
Expand description

reproducible helps Rust projects generate reproducible accuracy and benchmark reports.

§Quick Start

use reproducible::prelude::*;
use reproducible::metrics;

// 1. Define the functions we want to evaluate

let fn_add = |inputs: &[f64]| vec![inputs[0] + inputs[1] + 5.0 * f64::EPSILON];
let fn_sub = |inputs: &[f64]| vec![inputs[0] - inputs[1] - 10.0 * f64::EPSILON];

// 2. Compose the report

let report = Report::new()

    // Add columns for metrics and statistics
    .with_column(
        Column::<f64>::accuracy("Mean Relative Error (eps)")
            .with_metric(metrics::rel_err_eps)
    )
    .with_column(
        Column::<f64>::accuracy("Max Absolute Error")
            .with_metric(metrics::abs_err)
            .with_stat(ColumnStat::Max)
    )
    .with_column(Column::<f64>::perf("Latency"))

    // Add rows corresponding to each function you want to evaluate
    .with_row(Row::new("math/add", fn_add).with_test_cases(vec![
        TestCase { inputs: vec![1.0, 2.0], expected: vec![3.0] },
    ]))
    .with_row(Row::new("math/sub", fn_sub).with_test_cases(vec![
        TestCase { inputs: vec![1.0, 2.0], expected: vec![-1.0] },
    ]));

// 3. Render to Markdown

println!("{}", report.render_markdown());

Output:

| Function | Mean Relative Error (eps) | Max Absolute Error | Latency |
|----------|---------------------------|--------------------|---------|
| math/add | 1.33                      | 8.88e-16           | 9.3 ns  |
| math/sub | 10.00                     | 2.22e-15           | 9.7 ns  |

Modules§

benchmark
Benchmark ingestion helpers.
columns
metrics
parser
CSV parsing utilities for accuracy test datasets.
prelude
render
Markdown table rendering for reports.
report
Fluent report composition API.
rows
stats
Statistical utilities for report aggregation.

Macros§

as_array
Wrap a function that takes a fixed array into one that takes a slice.
row
Shorthand for creating a Row from a function, using its name as the row label.
wrap_args
Wrap a function that takes positional arguments into one that takes a slice.

Functions§

to_pretty_json
Serialize report rows to pretty JSON for machine-friendly artifacts.