Implement Commons RNG-like samplers in kmath-prob module for Multiplatform #164

Merged
CommanderTvis merged 44 commits from feature/mp-samplers into dev 2021-03-31 09:25:44 +03:00
Showing only changes of commit 59b120e086 - Show all commits

View File

@ -6,6 +6,7 @@ import kscience.kmath.chains.collect
import kscience.kmath.structures.Buffer import kscience.kmath.structures.Buffer
import kscience.kmath.structures.BufferFactory import kscience.kmath.structures.BufferFactory
import kscience.kmath.structures.IntBuffer import kscience.kmath.structures.IntBuffer
import kotlin.jvm.JvmName
/** /**
* Sampler that generates chains of values of type [T]. * Sampler that generates chains of values of type [T].
@ -83,11 +84,13 @@ public suspend fun <T : Any> Sampler<T>.next(generator: RandomGenerator): T = sa
/** /**
* Generates [size] real samples and chunks them into some buffers. * Generates [size] real samples and chunks them into some buffers.
*/ */
@JvmName("sampleRealBuffer")
public fun Sampler<Double>.sampleBuffer(generator: RandomGenerator, size: Int): Chain<Buffer<Double>> = public fun Sampler<Double>.sampleBuffer(generator: RandomGenerator, size: Int): Chain<Buffer<Double>> =
sampleBuffer(generator, size, Buffer.Companion::real) sampleBuffer(generator, size, Buffer.Companion::real)
/** /**
* Generates [size] integer samples and chunks them into some buffers. * Generates [size] integer samples and chunks them into some buffers.
*/ */
@JvmName("sampleIntBuffer")
public fun Sampler<Int>.sampleBuffer(generator: RandomGenerator, size: Int): Chain<Buffer<Int>> = public fun Sampler<Int>.sampleBuffer(generator: RandomGenerator, size: Int): Chain<Buffer<Int>> =
sampleBuffer(generator, size, ::IntBuffer) sampleBuffer(generator, size, ::IntBuffer)