Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,19 @@ void main()
See [the benchmark subpackage](benchmarks/README.md) for selectable statistical
benchmarks and their command-line runner.

#### Distribution tests

Run the ordinary distribution tests and their shared helpers from the
repository root with DMD or LDC.

```sh
dub test mir-stat:distribution-tests
```

Run `dub test` for the full library suite, including callers outside
distributions. For the slower numerical reference sweeps, run
`dub test mir-stat:slow-numerics --build=unittest-optimized`.

#### Extreme numerical tests

Gamma inverse-CDF tests with very large shapes run by default with a DMD
Expand Down
1 change: 1 addition & 0 deletions dub.sdl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ toolchainRequirements frontend=">=2.097"

subPackage "benchmarks"
subPackage "tests/benchmark_helpers"
subPackage "tests/distribution"
subPackage "tests/slow_numerics"

configuration "library" {
Expand Down
29 changes: 15 additions & 14 deletions source/mir/stat/distribution/internal/fp_noncentral_chi2.d
Original file line number Diff line number Diff line change
Expand Up @@ -222,20 +222,6 @@ package(mir.stat.distribution) struct NoncentralChi2(T : Fp!bits, uint bits)
return finish(value);
}

version(mir_stat_test)
static if (bits == 64)
@safe pure nothrow @nogc unittest
{
// Exercise the guarded residual directly on each side of its cutoff.
auto residual = number(1);
residual.exponent = exponentBias - (B.work - bits - 80);
const resolved = positive(residual);
assert(finishFoldedLogDensity(resolved) == finish(resolved));
residual.exponent -= 1;
assert(finishFoldedLogDensity(positive(residual)).isNaN);
assert(finishFoldedLogDensity(Term.init).isNaN);
}

static T density(bool logarithmic)(T x, uint k, T lambda)
{
const infinity = T(false, long.max, UInt!bits(0));
Expand Down Expand Up @@ -468,6 +454,21 @@ package(mir.stat.distribution) struct NoncentralChi2(T : Fp!bits, uint bits)
}
}

version(mir_stat_test)
@safe pure nothrow @nogc unittest
{
enum bits = 64;
alias C = NoncentralChi2!(Fp!bits);
// Exercise the guarded residual directly on each side of its cutoff.
auto residual = C.number(1);
residual.exponent = exponentBias - (C.B.work - bits - 80);
const resolved = C.positive(residual);
assert(C.finishFoldedLogDensity(resolved) == C.finish(resolved));
residual.exponent -= 1;
assert(C.finishFoldedLogDensity(C.positive(residual)).isNaN);
assert(C.finishFoldedLogDensity(C.Term.init).isNaN);
}

version(mir_stat_test)
static if (size_t.sizeof == 4)
@safe pure nothrow @nogc unittest
Expand Down
34 changes: 34 additions & 0 deletions tests/distribution/dub.sdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name "distribution-tests"
description "Ordinary distribution unit tests for mir-stat"
license "Apache-2.0"
targetPath "../../build/distribution-tests"
sourcePaths "../../source/mir/stat/distribution"

// List shared sources once so per-file builds link a single copy of each module.
sourceFiles "../../source/mir/stat/constant.d"
sourceFiles "../../source/mir/stat/covariance_views.d"
sourceFiles "../../source/mir/stat/internal/mahalanobis.d"
sourceFiles "../../source/mir/stat/internal/shape_transform.d"
sourceFiles "../../source/mir/stat/internal/standardize.d"
sourceFiles "../../source/mir/stat/internal/uint_sqrt.d"
sourcePaths "../../source/mir/stat/internal/linearAlgebra"
excludedSourceFiles "../../source/mir/stat/internal/linearAlgebra/package.d"
excludedSourceFiles "../../source/mir/stat/internal/linearAlgebra/crossproducts.d"
excludedSourceFiles "../../source/mir/stat/internal/linearAlgebra/gc.d"
excludedSourceFiles "../../source/mir/stat/internal/linearAlgebra/rc.d"
excludedSourceFiles "../../source/mir/stat/internal/linearAlgebra/custom.d"
sourcePaths "../../source/mir/math/internal"
excludedSourceFiles "../../source/mir/math/internal/benchmark.d"
excludedSourceFiles "../../source/mir/math/internal/powi.d"
importPaths "../../source"
dependency "mir-algorithm" version=">=3.22.5"
versions "mir_stat_test"

dflags "-lowmem" platform="dmd"
dflags "-lowmem" platform="ldc"

configuration "unittest" {
targetType "executable"
// Keep the runner path short in Windows coverage report names.
mainSourceFile "runner.d"
}
8 changes: 8 additions & 0 deletions tests/distribution/runner.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/++
License: $(HTTP www.apache.org/licenses/LICENSE-2.0, Apache-2.0)
Authors: Mir Stat Authors
+/
module mir.stat.tests.distribution_runner;

// D runtime executes the linked modules' unittests before main.
void main() {}
Loading