diff --git a/build.gradle.kts b/build.gradle.kts index 2fe3900ed..f3ea58b8e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -5,7 +5,7 @@ allprojects { jcenter() maven("https://kotlin.bintray.com/kotlinx") } - + group = "scientifik" version = kmathVersion } diff --git a/examples/build.gradle b/examples/build.gradle deleted file mode 100644 index 7c948e219..000000000 --- a/examples/build.gradle +++ /dev/null @@ -1,39 +0,0 @@ -plugins { - id "java" - id "me.champeau.gradle.jmh" version "0.4.8" - id 'org.jetbrains.kotlin.jvm' -} - -repositories { - maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' } - maven{ url "http://dl.bintray.com/kyonifer/maven"} - mavenCentral() -} - -dependencies { - implementation project(":kmath-core") - implementation project(":kmath-coroutines") - implementation project(":kmath-commons") - implementation project(":kmath-koma") - implementation group: "com.kyonifer", name:"koma-core-ejml", version: "0.12" - implementation "org.jetbrains.kotlinx:kotlinx-io-jvm:0.1.5" - //compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8" - //jmh project(':kmath-core') -} - -jmh { - warmupIterations = 1 -} - -jmhClasses.dependsOn(compileKotlin) - -compileKotlin { - kotlinOptions { - jvmTarget = "1.8" - } -} -compileTestKotlin { - kotlinOptions { - jvmTarget = "1.8" - } -} \ No newline at end of file diff --git a/examples/build.gradle.kts b/examples/build.gradle.kts new file mode 100644 index 000000000..7f6bec31f --- /dev/null +++ b/examples/build.gradle.kts @@ -0,0 +1,67 @@ +import org.jetbrains.gradle.benchmarks.JvmBenchmarkTarget +import org.jetbrains.kotlin.allopen.gradle.AllOpenExtension +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +plugins { + java + kotlin("jvm") + kotlin("plugin.allopen") version "1.3.31" + id("org.jetbrains.gradle.benchmarks.plugin") version "0.1.7-dev-24" +} + +configure { + annotation("org.openjdk.jmh.annotations.State") +} + +repositories { + maven("https://dl.bintray.com/kotlin/kotlin-eap") + maven("http://dl.bintray.com/kyonifer/maven") + maven("https://dl.bintray.com/orangy/maven") + mavenCentral() +} + +sourceSets { + register("benchmarks") +} + +dependencies { + implementation(project(":kmath-core")) + implementation(project(":kmath-coroutines")) + implementation(project(":kmath-commons")) + implementation(project(":kmath-koma")) + implementation("com.kyonifer:koma-core-ejml:0.12") + implementation("org.jetbrains.kotlinx:kotlinx-io-jvm:0.1.5") + + implementation("org.jetbrains.gradle.benchmarks:runtime:0.1.7-dev-24") + + + "benchmarksCompile"(sourceSets.main.get().compileClasspath) +} + +// Configure benchmark +benchmark { + // Setup configurations + targets { + // This one matches sourceSet name above + register("benchmarks") { + this as JvmBenchmarkTarget + jmhVersion = "1.21" + } + } + + configurations { + register("fast") { + warmups = 5 // number of warmup iterations + iterations = 3 // number of iterations + iterationTime = 500 // time in seconds per iteration + iterationTimeUnit = "ms" // time unity for iterationTime, default is seconds + } + } +} + + +tasks.withType { + kotlinOptions { + jvmTarget = "1.8" + } +} \ No newline at end of file diff --git a/examples/src/jmh/kotlin/scientifik/kmath/structures/ArrayBenchmark.kt b/examples/src/benchmarks/kotlin/scientifik/kmath/structures/ArrayBenchmark.kt similarity index 95% rename from examples/src/jmh/kotlin/scientifik/kmath/structures/ArrayBenchmark.kt rename to examples/src/benchmarks/kotlin/scientifik/kmath/structures/ArrayBenchmark.kt index 393d7b06a..d605e1b9c 100644 --- a/examples/src/jmh/kotlin/scientifik/kmath/structures/ArrayBenchmark.kt +++ b/examples/src/benchmarks/kotlin/scientifik/kmath/structures/ArrayBenchmark.kt @@ -7,7 +7,7 @@ import java.nio.IntBuffer @State(Scope.Benchmark) -open class ArrayBenchmark { +class ArrayBenchmark { @Benchmark fun benchmarkArrayRead() { @@ -32,10 +32,10 @@ open class ArrayBenchmark { res += nativeBuffer.get(size - i) } } - + companion object { val size = 1000 - + val array = IntArray(size) { it } val arrayBuffer = IntBuffer.wrap(array) val nativeBuffer = IntBuffer.allocate(size).also { diff --git a/examples/src/jmh/kotlin/scientifik/kmath/structures/BufferBenchmark.kt b/examples/src/benchmarks/kotlin/scientifik/kmath/structures/BufferBenchmark.kt similarity index 96% rename from examples/src/jmh/kotlin/scientifik/kmath/structures/BufferBenchmark.kt rename to examples/src/benchmarks/kotlin/scientifik/kmath/structures/BufferBenchmark.kt index a41ca83d3..9676b5e4a 100644 --- a/examples/src/jmh/kotlin/scientifik/kmath/structures/BufferBenchmark.kt +++ b/examples/src/benchmarks/kotlin/scientifik/kmath/structures/BufferBenchmark.kt @@ -7,7 +7,7 @@ import scientifik.kmath.operations.Complex import scientifik.kmath.operations.complex @State(Scope.Benchmark) -open class BufferBenchmark { +class BufferBenchmark { @Benchmark fun genericDoubleBufferReadWrite() { diff --git a/examples/src/jmh/kotlin/scientifik/kmath/structures/NDFieldBenchmark.kt b/examples/src/benchmarks/kotlin/scientifik/kmath/structures/NDFieldBenchmark.kt similarity index 89% rename from examples/src/jmh/kotlin/scientifik/kmath/structures/NDFieldBenchmark.kt rename to examples/src/benchmarks/kotlin/scientifik/kmath/structures/NDFieldBenchmark.kt index 3e41323f1..9c2434bda 100644 --- a/examples/src/jmh/kotlin/scientifik/kmath/structures/NDFieldBenchmark.kt +++ b/examples/src/benchmarks/kotlin/scientifik/kmath/structures/NDFieldBenchmark.kt @@ -1,9 +1,12 @@ package scientifik.kmath.structures import org.openjdk.jmh.annotations.Benchmark +import org.openjdk.jmh.annotations.Scope +import org.openjdk.jmh.annotations.State import scientifik.kmath.operations.RealField -open class NDFieldBenchmark { +@State(Scope.Benchmark) +class NDFieldBenchmark { @Benchmark fun autoFieldAdd() { diff --git a/examples/src/main/kotlin/scientifik/kmath/commons/prob/DistributionDemo.kt b/examples/src/main/kotlin/scientifik/kmath/commons/prob/DistributionDemo.kt new file mode 100644 index 000000000..1db7643a0 --- /dev/null +++ b/examples/src/main/kotlin/scientifik/kmath/commons/prob/DistributionDemo.kt @@ -0,0 +1,11 @@ +package scientifik.kmath.commons.prob + +import kotlinx.coroutines.flow.take +import scientifik.kmath.chains.flow +import scientifik.kmath.prob.Distribution +import scientifik.kmath.prob.RandomGenerator + +fun main() { + val normal = Distribution.normal() + normal.sample(RandomGenerator.default) +} \ No newline at end of file diff --git a/examples/src/main/kotlin/scientifik/kmath/operations/ComplexDemo.kt b/examples/src/main/kotlin/scientifik/kmath/operations/ComplexDemo.kt new file mode 100644 index 000000000..86b28303d --- /dev/null +++ b/examples/src/main/kotlin/scientifik/kmath/operations/ComplexDemo.kt @@ -0,0 +1,10 @@ +package scientifik.kmath.operations + +import scientifik.kmath.structures.NDElement +import scientifik.kmath.structures.complex + +fun main() { + val element = NDElement.complex(2, 2) { index: IntArray -> + Complex(index[0].toDouble() - index[1].toDouble(), index[0].toDouble() + index[1].toDouble()) + } +} \ No newline at end of file diff --git a/examples/src/main/kotlin/scientifik/kmath/structures/ComplexNDBenchmark.kt b/examples/src/main/kotlin/scientifik/kmath/structures/ComplexND.kt similarity index 100% rename from examples/src/main/kotlin/scientifik/kmath/structures/ComplexNDBenchmark.kt rename to examples/src/main/kotlin/scientifik/kmath/structures/ComplexND.kt diff --git a/kmath-core/src/commonMain/kotlin/scientifik/kmath/structures/ComplexNDField.kt b/kmath-core/src/commonMain/kotlin/scientifik/kmath/structures/ComplexNDField.kt index 6444f667d..e9d518bd5 100644 --- a/kmath-core/src/commonMain/kotlin/scientifik/kmath/structures/ComplexNDField.kt +++ b/kmath-core/src/commonMain/kotlin/scientifik/kmath/structures/ComplexNDField.kt @@ -131,4 +131,7 @@ operator fun ComplexNDElement.plus(arg: Double) = operator fun ComplexNDElement.minus(arg: Double) = map { it - arg } -fun NDField.Companion.complex(vararg shape: Int) = ComplexNDField(shape) \ No newline at end of file +fun NDField.Companion.complex(vararg shape: Int): ComplexNDField = ComplexNDField(shape) + +fun NDElement.Companion.complex(vararg shape: Int, initializer: ComplexField.(IntArray) -> Complex): ComplexNDElement = + NDField.complex(*shape).produce(initializer) \ No newline at end of file diff --git a/kmath-core/src/commonMain/kotlin/scientifik/kmath/structures/NDAlgebra.kt b/kmath-core/src/commonMain/kotlin/scientifik/kmath/structures/NDAlgebra.kt index c6f0f7a48..9857e4150 100644 --- a/kmath-core/src/commonMain/kotlin/scientifik/kmath/structures/NDAlgebra.kt +++ b/kmath-core/src/commonMain/kotlin/scientifik/kmath/structures/NDAlgebra.kt @@ -57,6 +57,8 @@ interface NDAlgebra> { * element-by-element invoke a function working on [T] on a [NDStructure] */ operator fun Function1.invoke(structure: N) = map(structure) { value -> this@invoke(value) } + + companion object } /** diff --git a/settings.gradle.kts b/settings.gradle.kts index efb1bf0d7..004b432fd 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -3,6 +3,7 @@ pluginManagement { jcenter() gradlePluginPortal() maven("https://dl.bintray.com/kotlin/kotlin-eap") + maven("https://dl.bintray.com/orangy/maven") } resolutionStrategy { eachPlugin {