diff --git a/benchmarks/build.gradle b/examples/build.gradle similarity index 100% rename from benchmarks/build.gradle rename to examples/build.gradle diff --git a/benchmarks/src/jmh/kotlin/scientifik/kmath/structures/ArrayBenchmark.kt b/examples/src/jmh/kotlin/scientifik/kmath/structures/ArrayBenchmark.kt similarity index 100% rename from benchmarks/src/jmh/kotlin/scientifik/kmath/structures/ArrayBenchmark.kt rename to examples/src/jmh/kotlin/scientifik/kmath/structures/ArrayBenchmark.kt diff --git a/benchmarks/src/jmh/kotlin/scientifik/kmath/structures/BufferBenchmark.kt b/examples/src/jmh/kotlin/scientifik/kmath/structures/BufferBenchmark.kt similarity index 100% rename from benchmarks/src/jmh/kotlin/scientifik/kmath/structures/BufferBenchmark.kt rename to examples/src/jmh/kotlin/scientifik/kmath/structures/BufferBenchmark.kt diff --git a/benchmarks/src/jmh/kotlin/scientifik/kmath/structures/NDFieldBenchmark.kt b/examples/src/jmh/kotlin/scientifik/kmath/structures/NDFieldBenchmark.kt similarity index 100% rename from benchmarks/src/jmh/kotlin/scientifik/kmath/structures/NDFieldBenchmark.kt rename to examples/src/jmh/kotlin/scientifik/kmath/structures/NDFieldBenchmark.kt diff --git a/benchmarks/src/main/kotlin/scientifik/kmath/linear/LinearAlgebraBenchmark.kt b/examples/src/main/kotlin/scientifik/kmath/linear/LinearAlgebraBenchmark.kt similarity index 92% rename from benchmarks/src/main/kotlin/scientifik/kmath/linear/LinearAlgebraBenchmark.kt rename to examples/src/main/kotlin/scientifik/kmath/linear/LinearAlgebraBenchmark.kt index c397e9bd0..960f03de3 100644 --- a/benchmarks/src/main/kotlin/scientifik/kmath/linear/LinearAlgebraBenchmark.kt +++ b/examples/src/main/kotlin/scientifik/kmath/linear/LinearAlgebraBenchmark.kt @@ -1,6 +1,9 @@ package scientifik.kmath.linear import koma.matrix.ejml.EJMLMatrixFactory +import scientifik.kmath.commons.linear.CMMatrixContext +import scientifik.kmath.commons.linear.inverse +import scientifik.kmath.commons.linear.toCM import scientifik.kmath.operations.RealField import scientifik.kmath.structures.Matrix import kotlin.contracts.ExperimentalContracts diff --git a/benchmarks/src/main/kotlin/scientifik/kmath/linear/MultiplicationBenchmark.kt b/examples/src/main/kotlin/scientifik/kmath/linear/MultiplicationBenchmark.kt similarity index 92% rename from benchmarks/src/main/kotlin/scientifik/kmath/linear/MultiplicationBenchmark.kt rename to examples/src/main/kotlin/scientifik/kmath/linear/MultiplicationBenchmark.kt index 31a890867..03bd0001c 100644 --- a/benchmarks/src/main/kotlin/scientifik/kmath/linear/MultiplicationBenchmark.kt +++ b/examples/src/main/kotlin/scientifik/kmath/linear/MultiplicationBenchmark.kt @@ -1,6 +1,8 @@ package scientifik.kmath.linear import koma.matrix.ejml.EJMLMatrixFactory +import scientifik.kmath.commons.linear.CMMatrixContext +import scientifik.kmath.commons.linear.toCM import scientifik.kmath.operations.RealField import scientifik.kmath.structures.Matrix import kotlin.random.Random diff --git a/benchmarks/src/main/kotlin/scientifik/kmath/structures/ComplexNDBenchmark.kt b/examples/src/main/kotlin/scientifik/kmath/structures/ComplexNDBenchmark.kt similarity index 100% rename from benchmarks/src/main/kotlin/scientifik/kmath/structures/ComplexNDBenchmark.kt rename to examples/src/main/kotlin/scientifik/kmath/structures/ComplexNDBenchmark.kt diff --git a/benchmarks/src/main/kotlin/scientifik/kmath/structures/NDFieldBenchmark.kt b/examples/src/main/kotlin/scientifik/kmath/structures/NDFieldBenchmark.kt similarity index 100% rename from benchmarks/src/main/kotlin/scientifik/kmath/structures/NDFieldBenchmark.kt rename to examples/src/main/kotlin/scientifik/kmath/structures/NDFieldBenchmark.kt diff --git a/benchmarks/src/main/kotlin/scientifik/kmath/structures/StructureReadBenchmark.kt b/examples/src/main/kotlin/scientifik/kmath/structures/StructureReadBenchmark.kt similarity index 100% rename from benchmarks/src/main/kotlin/scientifik/kmath/structures/StructureReadBenchmark.kt rename to examples/src/main/kotlin/scientifik/kmath/structures/StructureReadBenchmark.kt diff --git a/benchmarks/src/main/kotlin/scientifik/kmath/structures/StructureWriteBenchmark.kt b/examples/src/main/kotlin/scientifik/kmath/structures/StructureWriteBenchmark.kt similarity index 100% rename from benchmarks/src/main/kotlin/scientifik/kmath/structures/StructureWriteBenchmark.kt rename to examples/src/main/kotlin/scientifik/kmath/structures/StructureWriteBenchmark.kt diff --git a/kmath-commons/build.gradle.kts b/kmath-commons/build.gradle.kts index c610749be..ffdc27d43 100644 --- a/kmath-commons/build.gradle.kts +++ b/kmath-commons/build.gradle.kts @@ -8,6 +8,7 @@ description = "Commons math binding for kmath" dependencies { api(project(":kmath-core")) api(project(":kmath-coroutines")) + api(project(":kmath-prob")) api("org.apache.commons:commons-math3:3.6.1") testImplementation("org.jetbrains.kotlin:kotlin-test") testImplementation("org.jetbrains.kotlin:kotlin-test-junit") diff --git a/kmath-commons/src/main/kotlin/scientifik/kmath/expressions/DiffExpression.kt b/kmath-commons/src/main/kotlin/scientifik/kmath/commons/expressions/DiffExpression.kt similarity index 83% rename from kmath-commons/src/main/kotlin/scientifik/kmath/expressions/DiffExpression.kt rename to kmath-commons/src/main/kotlin/scientifik/kmath/commons/expressions/DiffExpression.kt index 5f6d0d8fe..e687cb2af 100644 --- a/kmath-commons/src/main/kotlin/scientifik/kmath/expressions/DiffExpression.kt +++ b/kmath-commons/src/main/kotlin/scientifik/kmath/commons/expressions/DiffExpression.kt @@ -1,6 +1,8 @@ -package scientifik.kmath.expressions +package scientifik.kmath.commons.expressions import org.apache.commons.math3.analysis.differentiation.DerivativeStructure +import scientifik.kmath.expressions.Expression +import scientifik.kmath.expressions.ExpressionContext import scientifik.kmath.operations.ExtendedField import scientifik.kmath.operations.Field import kotlin.properties.ReadOnlyProperty @@ -81,8 +83,12 @@ class DerivativeStructureField( /** * A constructs that creates a derivative structure with required order on-demand */ -class DiffExpression(val function: DerivativeStructureField.() -> DerivativeStructure) : Expression { - override fun invoke(arguments: Map): Double = DerivativeStructureField(0, arguments) +class DiffExpression(val function: DerivativeStructureField.() -> DerivativeStructure) : + Expression { + override fun invoke(arguments: Map): Double = DerivativeStructureField( + 0, + arguments + ) .run(function).value /** @@ -109,21 +115,27 @@ fun DiffExpression.derivative(name: String) = derivative(name to 1) * A context for [DiffExpression] (not to be confused with [DerivativeStructure]) */ object DiffExpressionContext : ExpressionContext, Field { - override fun variable(name: String, default: Double?) = DiffExpression { variable(name, default?.const()) } + override fun variable(name: String, default: Double?) = + DiffExpression { variable(name, default?.const()) } - override fun const(value: Double): DiffExpression = DiffExpression { value.const() } + override fun const(value: Double): DiffExpression = + DiffExpression { value.const() } - override fun add(a: DiffExpression, b: DiffExpression) = DiffExpression { a.function(this) + b.function(this) } + override fun add(a: DiffExpression, b: DiffExpression) = + DiffExpression { a.function(this) + b.function(this) } override val zero = DiffExpression { 0.0.const() } - override fun multiply(a: DiffExpression, k: Number) = DiffExpression { a.function(this) * k } + override fun multiply(a: DiffExpression, k: Number) = + DiffExpression { a.function(this) * k } override val one = DiffExpression { 1.0.const() } - override fun multiply(a: DiffExpression, b: DiffExpression) = DiffExpression { a.function(this) * b.function(this) } + override fun multiply(a: DiffExpression, b: DiffExpression) = + DiffExpression { a.function(this) * b.function(this) } - override fun divide(a: DiffExpression, b: DiffExpression) = DiffExpression { a.function(this) / b.function(this) } + override fun divide(a: DiffExpression, b: DiffExpression) = + DiffExpression { a.function(this) / b.function(this) } } diff --git a/kmath-commons/src/main/kotlin/scientifik/kmath/linear/CMMatrix.kt b/kmath-commons/src/main/kotlin/scientifik/kmath/commons/linear/CMMatrix.kt similarity index 83% rename from kmath-commons/src/main/kotlin/scientifik/kmath/linear/CMMatrix.kt rename to kmath-commons/src/main/kotlin/scientifik/kmath/commons/linear/CMMatrix.kt index 9103f0fb2..72e5fb95a 100644 --- a/kmath-commons/src/main/kotlin/scientifik/kmath/linear/CMMatrix.kt +++ b/kmath-commons/src/main/kotlin/scientifik/kmath/commons/linear/CMMatrix.kt @@ -1,11 +1,13 @@ -package scientifik.kmath.linear +package scientifik.kmath.commons.linear import org.apache.commons.math3.linear.* import org.apache.commons.math3.linear.RealMatrix import org.apache.commons.math3.linear.RealVector +import scientifik.kmath.linear.* import scientifik.kmath.structures.Matrix -class CMMatrix(val origin: RealMatrix, features: Set? = null) : FeaturedMatrix { +class CMMatrix(val origin: RealMatrix, features: Set? = null) : + FeaturedMatrix { override val rowNum: Int get() = origin.rowDimension override val colNum: Int get() = origin.columnDimension @@ -70,10 +72,14 @@ object CMMatrixContext : MatrixContext { override fun multiply(a: Matrix, k: Number) = CMMatrix(a.toCM().origin.scalarMultiply(k.toDouble())) - override fun Matrix.times(value: Double): Matrix = produce(rowNum,colNum){i,j-> get(i,j)*value} + override fun Matrix.times(value: Double): Matrix = + produce(rowNum, colNum) { i, j -> get(i, j) * value } } -operator fun CMMatrix.plus(other: CMMatrix): CMMatrix = CMMatrix(this.origin.add(other.origin)) -operator fun CMMatrix.minus(other: CMMatrix): CMMatrix = CMMatrix(this.origin.subtract(other.origin)) +operator fun CMMatrix.plus(other: CMMatrix): CMMatrix = + CMMatrix(this.origin.add(other.origin)) +operator fun CMMatrix.minus(other: CMMatrix): CMMatrix = + CMMatrix(this.origin.subtract(other.origin)) -infix fun CMMatrix.dot(other: CMMatrix): CMMatrix = CMMatrix(this.origin.multiply(other.origin)) \ No newline at end of file +infix fun CMMatrix.dot(other: CMMatrix): CMMatrix = + CMMatrix(this.origin.multiply(other.origin)) \ No newline at end of file diff --git a/kmath-commons/src/main/kotlin/scientifik/kmath/linear/CMSolver.kt b/kmath-commons/src/main/kotlin/scientifik/kmath/commons/linear/CMSolver.kt similarity index 94% rename from kmath-commons/src/main/kotlin/scientifik/kmath/linear/CMSolver.kt rename to kmath-commons/src/main/kotlin/scientifik/kmath/commons/linear/CMSolver.kt index a56e8c93e..77b688e31 100644 --- a/kmath-commons/src/main/kotlin/scientifik/kmath/linear/CMSolver.kt +++ b/kmath-commons/src/main/kotlin/scientifik/kmath/commons/linear/CMSolver.kt @@ -1,6 +1,7 @@ -package scientifik.kmath.linear +package scientifik.kmath.commons.linear import org.apache.commons.math3.linear.* +import scientifik.kmath.linear.Point import scientifik.kmath.structures.Matrix enum class CMDecomposition { diff --git a/kmath-commons/src/main/kotlin/scientifik/kmath/commons/prob/CMRandomGeneratorWrapper.kt b/kmath-commons/src/main/kotlin/scientifik/kmath/commons/prob/CMRandomGeneratorWrapper.kt new file mode 100644 index 000000000..8267f8c73 --- /dev/null +++ b/kmath-commons/src/main/kotlin/scientifik/kmath/commons/prob/CMRandomGeneratorWrapper.kt @@ -0,0 +1,18 @@ +package scientifik.kmath.commons.prob + +import org.apache.commons.math3.random.RandomGenerator + +inline class CMRandomGeneratorWrapper(val generator: RandomGenerator) : scientifik.kmath.prob.RandomGenerator { + override fun nextDouble(): Double = generator.nextDouble() + + override fun nextInt(): Int = generator.nextInt() + + override fun nextLong(): Long = generator.nextLong() + + override fun nextBlock(size: Int): ByteArray = ByteArray(size).apply { generator.nextBytes(this) } +} + +fun RandomGenerator.asKmathGenerator() = CMRandomGeneratorWrapper(this) + +fun scientifik.kmath.prob.RandomGenerator.asCMGenerator() = + (this as? CMRandomGeneratorWrapper)?.generator ?: TODO("Implement reverse CM wrapper") \ No newline at end of file diff --git a/kmath-commons/src/main/kotlin/scientifik/kmath/commons/prob/CommonsDistribution.kt b/kmath-commons/src/main/kotlin/scientifik/kmath/commons/prob/CommonsDistribution.kt new file mode 100644 index 000000000..51de07975 --- /dev/null +++ b/kmath-commons/src/main/kotlin/scientifik/kmath/commons/prob/CommonsDistribution.kt @@ -0,0 +1,84 @@ +package scientifik.kmath.commons.prob + +import org.apache.commons.math3.distribution.* +import scientifik.kmath.chains.Chain +import scientifik.kmath.chains.SimpleChain +import scientifik.kmath.prob.Distribution +import scientifik.kmath.prob.RandomChain +import scientifik.kmath.prob.RandomGenerator +import scientifik.kmath.prob.UnivariateDistribution +import org.apache.commons.math3.random.RandomGenerator as CMRandom + +class CMRealDistributionWrapper(val builder: (CMRandom?) -> RealDistribution) : UnivariateDistribution { + + private val defaultDistribution by lazy { builder(null) } + + override fun probability(arg: Double): Double = defaultDistribution.probability(arg) + + override fun cumulative(arg: Double): Double = defaultDistribution.cumulativeProbability(arg) + + override fun sample(generator: RandomGenerator): RandomChain { + val distribution = builder(generator.asCMGenerator()) + return RandomChain(generator) { distribution.sample() } + } +} + +class CMIntDistributionWrapper(val builder: (CMRandom?) -> IntegerDistribution) : UnivariateDistribution { + + private val defaultDistribution by lazy { builder(null) } + + override fun probability(arg: Int): Double = defaultDistribution.probability(arg) + + override fun cumulative(arg: Int): Double = defaultDistribution.cumulativeProbability(arg) + + override fun sample(generator: RandomGenerator): RandomChain { + val distribution = builder(generator.asCMGenerator()) + return RandomChain(generator) { distribution.sample() } + } +} + + +fun Distribution.Companion.normal(mean: Double, sigma: Double): UnivariateDistribution = + CMRealDistributionWrapper { generator -> NormalDistribution(generator, mean, sigma) } + +fun Distribution.Companion.poisson(mean: Double): UnivariateDistribution = CMIntDistributionWrapper { generator -> + PoissonDistribution( + generator, + mean, + PoissonDistribution.DEFAULT_EPSILON, + PoissonDistribution.DEFAULT_MAX_ITERATIONS + ) +} + +fun Distribution.Companion.binomial(trials: Int, p: Double): UnivariateDistribution = + CMIntDistributionWrapper { generator -> + BinomialDistribution(generator, trials, p) + } + +fun Distribution.Companion.student(degreesOfFreedom: Double): UnivariateDistribution = + CMRealDistributionWrapper { generator -> + TDistribution(generator, degreesOfFreedom, TDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY) + } + +fun Distribution.Companion.chi2(degreesOfFreedom: Double): UnivariateDistribution = + CMRealDistributionWrapper { generator -> + ChiSquaredDistribution(generator, degreesOfFreedom) + } + +fun Distribution.Companion.fisher( + numeratorDegreesOfFreedom: Double, + denominatorDegreesOfFreedom: Double +): UnivariateDistribution = + CMRealDistributionWrapper { generator -> + FDistribution(generator, numeratorDegreesOfFreedom, denominatorDegreesOfFreedom) + } + +fun Distribution.Companion.exponential(mean: Double): UnivariateDistribution = + CMRealDistributionWrapper { generator -> + ExponentialDistribution(generator, mean) + } + +fun Distribution.Companion.uniform(a: Double, b: Double): UnivariateDistribution = + CMRealDistributionWrapper { generator -> + UniformRealDistribution(generator, a, b) + } \ No newline at end of file diff --git a/kmath-commons/src/main/kotlin/scientifik/kmath/transform/Transformations.kt b/kmath-commons/src/main/kotlin/scientifik/kmath/commons/transform/Transformations.kt similarity index 97% rename from kmath-commons/src/main/kotlin/scientifik/kmath/transform/Transformations.kt rename to kmath-commons/src/main/kotlin/scientifik/kmath/commons/transform/Transformations.kt index ac6922262..ce51735fe 100644 --- a/kmath-commons/src/main/kotlin/scientifik/kmath/transform/Transformations.kt +++ b/kmath-commons/src/main/kotlin/scientifik/kmath/commons/transform/Transformations.kt @@ -1,4 +1,4 @@ -package scientifik.kmath.transform +package scientifik.kmath.commons.transform import kotlinx.coroutines.FlowPreview import kotlinx.coroutines.flow.Flow diff --git a/kmath-commons/src/test/kotlin/scientifik/kmath/expressions/AutoDiffTest.kt b/kmath-commons/src/test/kotlin/scientifik/kmath/commons/expressions/AutoDiffTest.kt similarity index 78% rename from kmath-commons/src/test/kotlin/scientifik/kmath/expressions/AutoDiffTest.kt rename to kmath-commons/src/test/kotlin/scientifik/kmath/commons/expressions/AutoDiffTest.kt index 2695bb918..37e4e9ff9 100644 --- a/kmath-commons/src/test/kotlin/scientifik/kmath/expressions/AutoDiffTest.kt +++ b/kmath-commons/src/test/kotlin/scientifik/kmath/commons/expressions/AutoDiffTest.kt @@ -1,6 +1,9 @@ -package scientifik.kmath.expressions +package scientifik.kmath.commons.expressions import org.junit.Test +import scientifik.kmath.commons.expressions.DerivativeStructureField +import scientifik.kmath.commons.expressions.DiffExpression +import scientifik.kmath.commons.expressions.derivative import kotlin.test.assertEquals inline fun diff(order: Int, vararg parameters: Pair, block: DerivativeStructureField.() -> R) = diff --git a/kmath-prob/build.gradle.kts b/kmath-prob/build.gradle.kts index 77a4aefc8..972b9bba0 100644 --- a/kmath-prob/build.gradle.kts +++ b/kmath-prob/build.gradle.kts @@ -13,7 +13,7 @@ kotlin.sourceSets { jvmMain { dependencies { // https://mvnrepository.com/artifact/org.apache.commons/commons-rng-simple - api("org.apache.commons:commons-rng-sampling:1.2") + //api("org.apache.commons:commons-rng-sampling:1.2") compileOnly("org.jetbrains.kotlinx:atomicfu:${Versions.atomicfuVersion}") } } diff --git a/kmath-prob/src/commonMain/kotlin/scientifik/kmath/prob/Distribution.kt b/kmath-prob/src/commonMain/kotlin/scientifik/kmath/prob/Distribution.kt index 946b173ff..a8614963b 100644 --- a/kmath-prob/src/commonMain/kotlin/scientifik/kmath/prob/Distribution.kt +++ b/kmath-prob/src/commonMain/kotlin/scientifik/kmath/prob/Distribution.kt @@ -16,8 +16,13 @@ interface Distribution { * Create a chain of samples from this distribution. * The chain is not guaranteed to be stateless. */ - fun sample(generator: RandomGenerator): Chain + fun sample(generator: RandomGenerator): RandomChain //TODO add sample bunch generator + + /** + * An empty companion. Distribution factories should be written as its extensions + */ + companion object } interface UnivariateDistribution> : Distribution { @@ -25,4 +30,4 @@ interface UnivariateDistribution> : Distribution { * Cumulative distribution for ordered parameter */ fun cumulative(arg: T): Double -} \ No newline at end of file +} diff --git a/kmath-prob/src/commonMain/kotlin/scientifik/kmath/prob/RandomChain.kt b/kmath-prob/src/commonMain/kotlin/scientifik/kmath/prob/RandomChain.kt new file mode 100644 index 000000000..792b60603 --- /dev/null +++ b/kmath-prob/src/commonMain/kotlin/scientifik/kmath/prob/RandomChain.kt @@ -0,0 +1,17 @@ +package scientifik.kmath.prob + +import kotlinx.atomicfu.atomic +import scientifik.kmath.chains.Chain + +/** + * A possibly stateful chain producing random values. + * TODO make random chain properly fork generator + */ +class RandomChain(val generator: RandomGenerator, private val gen: suspend RandomGenerator.() -> R) : Chain { + private val atomicValue = atomic(null) + override fun peek(): R? = atomicValue.value + + override suspend fun next(): R = generator.gen().also { atomicValue.lazySet(it) } + + override fun fork(): Chain = RandomChain(generator, gen) +} \ No newline at end of file diff --git a/kmath-prob/src/jvmMain/kotlin/scientifik/kmath/prob/CommonDistributions.kt b/kmath-prob/src/jvmMain/kotlin/scientifik/kmath/prob/CommonDistributions.kt deleted file mode 100644 index c08008c28..000000000 --- a/kmath-prob/src/jvmMain/kotlin/scientifik/kmath/prob/CommonDistributions.kt +++ /dev/null @@ -1,53 +0,0 @@ -package scientifik.kmath.prob - -import org.apache.commons.rng.sampling.distribution.* -import scientifik.kmath.chains.Chain -import scientifik.kmath.chains.SimpleChain -import kotlin.math.PI -import kotlin.math.exp -import kotlin.math.sqrt - -class NormalDistribution(val mean: Double, val sigma: Double) : UnivariateDistribution { - enum class Sampler { - BoxMuller, - Marsaglia, - Ziggurat - } - - override fun probability(arg: Double): Double { - val d = (arg - mean) / sigma - return 1.0 / sqrt(2.0 * PI * sigma) * exp(-d * d / 2) - } - - override fun cumulative(arg: Double): Double { - TODO("not implemented") //To change body of created functions use File | Settings | File Templates. - } - - fun sample(generator: RandomGenerator, sampler: Sampler): Chain { - val normalized = when (sampler) { - Sampler.BoxMuller -> BoxMullerNormalizedGaussianSampler(generator.asProvider()) - Sampler.Marsaglia -> MarsagliaNormalizedGaussianSampler(generator.asProvider()) - Sampler.Ziggurat -> ZigguratNormalizedGaussianSampler(generator.asProvider()) - } - val gauss = GaussianSampler(normalized, mean, sigma) - //TODO add generator to chain state to allow stateful forks - return SimpleChain { gauss.sample() } - } - - override fun sample(generator: RandomGenerator): Chain = sample(generator, Sampler.BoxMuller) -} - -class PoissonDistribution(val mean: Double): UnivariateDistribution{ - override fun probability(arg: Int): Double { - TODO("not implemented") //To change body of created functions use File | Settings | File Templates. - } - - override fun cumulative(arg: Int): Double { - TODO("not implemented") //To change body of created functions use File | Settings | File Templates. - } - - override fun sample(generator: RandomGenerator): Chain { - val sampler = PoissonSampler(generator.asProvider(), mean) - return SimpleChain{sampler.sample()} - } -} \ No newline at end of file diff --git a/kmath-prob/src/jvmMain/kotlin/scientifik/kmath/prob/CommonsRandomProviderWrapper.kt b/kmath-prob/src/jvmMain/kotlin/scientifik/kmath/prob/CommonsRandomProviderWrapper.kt deleted file mode 100644 index ad408460d..000000000 --- a/kmath-prob/src/jvmMain/kotlin/scientifik/kmath/prob/CommonsRandomProviderWrapper.kt +++ /dev/null @@ -1,18 +0,0 @@ -package scientifik.kmath.prob - -import org.apache.commons.rng.UniformRandomProvider - -inline class CommonsRandomProviderWrapper(val provider: UniformRandomProvider) : RandomGenerator { - override fun nextDouble(): Double = provider.nextDouble() - - override fun nextInt(): Int = provider.nextInt() - - override fun nextLong(): Long = provider.nextLong() - - override fun nextBlock(size: Int): ByteArray = ByteArray(size).also { provider.nextBytes(it) } -} - -fun UniformRandomProvider.asGenerator(): RandomGenerator = CommonsRandomProviderWrapper(this) - -fun RandomGenerator.asProvider(): UniformRandomProvider = - (this as? CommonsRandomProviderWrapper)?.provider ?: TODO("implement reverse wrapper") \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index 5adf75fa5..efb1bf0d7 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -28,5 +28,5 @@ include( ":kmath-commons", ":kmath-koma", ":kmath-prob", - ":benchmarks" + ":examples" )