From d303c912d6713c9b150aaaea012e61dff2bfc673 Mon Sep 17 00:00:00 2001 From: Roland Grinis Date: Tue, 13 Jul 2021 12:45:07 +0100 Subject: [PATCH] testing seed setting --- kmath-noa/build.gradle.kts | 2 -- .../space/kscience/kmath/noa/TestUtils.kt | 34 +++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/kmath-noa/build.gradle.kts b/kmath-noa/build.gradle.kts index 7fd8b95c8..383bd6140 100644 --- a/kmath-noa/build.gradle.kts +++ b/kmath-noa/build.gradle.kts @@ -35,8 +35,6 @@ val cmakeCmd = "$thirdPartyDir/cmake/$cmakeArchive/bin/cmake" val ninjaCmd = "$thirdPartyDir/ninja/ninja" val generateJNIHeader by tasks.registering { - println("Path:") - println(System.getProperty("java.library.path")) doLast { exec { workingDir(projectDir.resolve("src/main/java/space/kscience/kmath/noa")) diff --git a/kmath-noa/src/test/kotlin/space/kscience/kmath/noa/TestUtils.kt b/kmath-noa/src/test/kotlin/space/kscience/kmath/noa/TestUtils.kt index 5987282d4..21fe71f9c 100644 --- a/kmath-noa/src/test/kotlin/space/kscience/kmath/noa/TestUtils.kt +++ b/kmath-noa/src/test/kotlin/space/kscience/kmath/noa/TestUtils.kt @@ -8,6 +8,31 @@ package space.kscience.kmath.noa import kotlin.test.Test import kotlin.test.assertEquals + +internal val SEED = 987654 +internal val TOLERANCE = 1e-6 + +internal fun , AlgebraT : NoaAlgebra> + AlgebraT.withCuda(block: AlgebraT.(Device) -> Unit): Unit { + this.block(Device.CPU) + if (cudaAvailable()) this.block(Device.CUDA(0)) +} + +internal fun NoaFloat.testingSetSeed(device: Device = Device.CPU): Unit { + setSeed(SEED) + val integral = randDiscrete(0, 100, IntArray(0), device = device).value() + val normal = randNormal(IntArray(0), device = device).value() + val uniform = randUniform(IntArray(0), device = device).value() + setSeed(SEED) + val nextIntegral = randDiscrete(0, 100, IntArray(0), device = device).value() + val nextNormal = randNormal(IntArray(0), device = device).value() + val nextUniform = randUniform(IntArray(0), device = device).value() + assertEquals(normal, nextNormal) + assertEquals(uniform, nextUniform) + assertEquals(integral, nextIntegral) +} + + class TestUtils { @Test @@ -26,5 +51,14 @@ class TestUtils { setNumThreads(numThreads) assertEquals(numThreads, getNumThreads()) } + + @Test + fun testSetSeed(): Unit = NoaFloat { + withCuda { device -> + testingSetSeed(device) + } + }!! + + }