Example fix

This commit is contained in:
Alexander Nozik 2019-06-08 16:25:51 +03:00
parent 9c2164cd64
commit f480aa1c5c
12 changed files with 104 additions and 46 deletions

View File

@ -5,7 +5,7 @@ allprojects {
jcenter()
maven("https://kotlin.bintray.com/kotlinx")
}
group = "scientifik"
version = kmathVersion
}

View File

@ -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"
}
}

67
examples/build.gradle.kts Normal file
View File

@ -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<AllOpenExtension> {
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<KotlinCompile> {
kotlinOptions {
jvmTarget = "1.8"
}
}

View File

@ -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 {

View File

@ -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() {

View File

@ -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() {

View File

@ -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)
}

View File

@ -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())
}
}

View File

@ -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)
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)

View File

@ -57,6 +57,8 @@ interface NDAlgebra<T, C, N : NDStructure<T>> {
* element-by-element invoke a function working on [T] on a [NDStructure]
*/
operator fun Function1<T, T>.invoke(structure: N) = map(structure) { value -> this@invoke(value) }
companion object
}
/**

View File

@ -3,6 +3,7 @@ pluginManagement {
jcenter()
gradlePluginPortal()
maven("https://dl.bintray.com/kotlin/kotlin-eap")
maven("https://dl.bintray.com/orangy/maven")
}
resolutionStrategy {
eachPlugin {