From 31460df721fccef597a62a48d0bbac92e4f1ae05 Mon Sep 17 00:00:00 2001 From: darksnake Date: Wed, 7 Apr 2021 14:14:22 +0300 Subject: [PATCH] GaussianSampler inherits Blocking Sampler --- .../kotlin/space/kscience/kmath/samplers/GaussianSampler.kt | 3 +-- .../space/kscience/kmath/stat/CommonsDistributionsTest.kt | 6 ++++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/GaussianSampler.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/GaussianSampler.kt index 26047830c..237da920c 100644 --- a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/GaussianSampler.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/GaussianSampler.kt @@ -3,7 +3,6 @@ package space.kscience.kmath.samplers import space.kscience.kmath.chains.BlockingDoubleChain import space.kscience.kmath.chains.map import space.kscience.kmath.stat.RandomGenerator -import space.kscience.kmath.stat.Sampler /** * Sampling from a Gaussian distribution with given mean and standard deviation. @@ -18,7 +17,7 @@ public class GaussianSampler( public val mean: Double, public val standardDeviation: Double, private val normalized: NormalizedGaussianSampler = BoxMullerSampler -) : Sampler { +) : BlockingDoubleSampler { init { require(standardDeviation > 0.0) { "standard deviation is not strictly positive: $standardDeviation" } diff --git a/kmath-stat/src/jvmTest/kotlin/space/kscience/kmath/stat/CommonsDistributionsTest.kt b/kmath-stat/src/jvmTest/kotlin/space/kscience/kmath/stat/CommonsDistributionsTest.kt index c6b9cb17a..976020f08 100644 --- a/kmath-stat/src/jvmTest/kotlin/space/kscience/kmath/stat/CommonsDistributionsTest.kt +++ b/kmath-stat/src/jvmTest/kotlin/space/kscience/kmath/stat/CommonsDistributionsTest.kt @@ -18,10 +18,12 @@ internal class CommonsDistributionsTest { } @Test - fun testNormalDistributionBlocking() = runBlocking { + fun testNormalDistributionBlocking() { val distribution = GaussianSampler(7.0, 2.0) val generator = RandomGenerator.default(1) val sample = distribution.sample(generator).nextBufferBlocking(1000) - Assertions.assertEquals(7.0, Mean.double(sample), 0.2) + runBlocking { + Assertions.assertEquals(7.0, Mean.double(sample), 0.2) + } } }