From ae3434643786e062b87ee6b6869dcc3619ccd193 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Fri, 26 Oct 2018 20:14:07 +0300 Subject: [PATCH] Quick AIDA port --- .gitignore | 2 +- build.gradle | 28 ++-------- kmath-aida/build.gradle.kts | 15 ++++++ .../main/kotlin/scientifik/kmath/aida/AIDA.kt | 9 ++++ .../scientifik/kmath/aida/Histograms.kt | 23 ++++++++ .../kmath/structures/ArrayBenchmark.kt | 52 ------------------- settings.gradle | 3 +- 7 files changed, 53 insertions(+), 79 deletions(-) create mode 100644 kmath-aida/build.gradle.kts create mode 100644 kmath-aida/src/main/kotlin/scientifik/kmath/aida/AIDA.kt create mode 100644 kmath-aida/src/main/kotlin/scientifik/kmath/aida/Histograms.kt delete mode 100644 kmath-core/src/jmh/kotlin/scietifik/kmath/structures/ArrayBenchmark.kt diff --git a/.gitignore b/.gitignore index d07c3c850..e91684008 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,4 @@ # Cache of project .gradletasknamecache -gradle.properties \ No newline at end of file +artifactory.gradle \ No newline at end of file diff --git a/build.gradle b/build.gradle index 14ecae465..e802034f0 100644 --- a/build.gradle +++ b/build.gradle @@ -13,6 +13,7 @@ buildscript { classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4+" } } + allprojects { apply plugin: 'maven-publish' apply plugin: "com.jfrog.artifactory" @@ -21,29 +22,6 @@ allprojects { version = '0.0.1-SNAPSHOT' } - -artifactory { - contextUrl = "${artifactory_contextUrl}" //The base Artifactory URL if not overridden by the publisher/resolver - publish { - repository { - repoKey = 'gradle-dev-local' - username = "${artifactory_user}" - password = "${artifactory_password}" - } - - defaults { - publications('jvm', 'js', 'kotlinMultiplatform', 'metadata') - publishBuildInfo = false - publishArtifacts = true - publishPom = true - publishIvy = false - } - } - resolve { - repository { - repoKey = 'gradle-dev' - username = "${artifactory_user}" - password = "${artifactory_password}" - } - } +if(file('artifactory.gradle').exists()){ + apply from: 'artifactory.gradle' } \ No newline at end of file diff --git a/kmath-aida/build.gradle.kts b/kmath-aida/build.gradle.kts new file mode 100644 index 000000000..2e7deb8b0 --- /dev/null +++ b/kmath-aida/build.gradle.kts @@ -0,0 +1,15 @@ +plugins { + kotlin("jvm") +} + +repositories { + mavenCentral() + maven ("http://dl.bintray.com/kotlin/kotlin-eap") + maven("http://java.freehep.org/maven2/") +} + +dependencies { + implementation(kotlin("stdlib")) + api(project(":kmath-core")) + api(group = "org.freehep", name = "freehep-jaida", version = "3.4.13") +} \ No newline at end of file diff --git a/kmath-aida/src/main/kotlin/scientifik/kmath/aida/AIDA.kt b/kmath-aida/src/main/kotlin/scientifik/kmath/aida/AIDA.kt new file mode 100644 index 000000000..fc7a044d3 --- /dev/null +++ b/kmath-aida/src/main/kotlin/scientifik/kmath/aida/AIDA.kt @@ -0,0 +1,9 @@ +package scientifik.kmath.aida + +import hep.aida.IAnalysisFactory +import hep.aida.IHistogramFactory +import hep.aida.ITreeFactory + +val analysisFactory: IAnalysisFactory by lazy { IAnalysisFactory.create() } +val treeFactory: ITreeFactory by lazy { analysisFactory.createTreeFactory() } +val histogramFactory: IHistogramFactory by lazy { analysisFactory.createHistogramFactory(treeFactory.create()) } \ No newline at end of file diff --git a/kmath-aida/src/main/kotlin/scientifik/kmath/aida/Histograms.kt b/kmath-aida/src/main/kotlin/scientifik/kmath/aida/Histograms.kt new file mode 100644 index 000000000..974fa64a5 --- /dev/null +++ b/kmath-aida/src/main/kotlin/scientifik/kmath/aida/Histograms.kt @@ -0,0 +1,23 @@ +package scientifik.kmath.aida + +import hep.aida.IHistogram1D +import hep.aida.IHistogram2D + +fun Iterable.histogram(range: ClosedFloatingPointRange, bins: Int = 100, path: String = ""): IHistogram1D{ + val h1d = Histograms.create1D(range,bins,path) + forEach{ + h1d.fill(it) + } + return h1d +} + + +object Histograms { + fun create1D(range: ClosedFloatingPointRange, bins: Int = 100, path: String = ""): IHistogram1D { + return histogramFactory.createHistogram1D(path, bins, range.start, range.endInclusive) + } + + fun create2D(xRange: ClosedFloatingPointRange, yRange: ClosedFloatingPointRange, xBins: Int = 100, yBins: Int = 100, path: String = ""): IHistogram2D { + return histogramFactory.createHistogram2D(path, xBins, xRange.start, xRange.endInclusive, yBins, yRange.start, yRange.endInclusive) + } +} \ No newline at end of file diff --git a/kmath-core/src/jmh/kotlin/scietifik/kmath/structures/ArrayBenchmark.kt b/kmath-core/src/jmh/kotlin/scietifik/kmath/structures/ArrayBenchmark.kt deleted file mode 100644 index 9658e8e75..000000000 --- a/kmath-core/src/jmh/kotlin/scietifik/kmath/structures/ArrayBenchmark.kt +++ /dev/null @@ -1,52 +0,0 @@ -package scietifik.kmath.structures - -import java.nio.IntBuffer - - -@Fork(1) -@Warmup(iterations = 2) -@Measurement(iterations = 5) -@State(Scope.Benchmark) -open class ArrayBenchmark { - - lateinit var array: IntArray - lateinit var arrayBuffer: IntBuffer - lateinit var nativeBuffer: IntBuffer - - @Setup - fun setup() { - array = IntArray(10000) { it } - arrayBuffer = IntBuffer.wrap(array) - nativeBuffer = IntBuffer.allocate(10000) - for (i in 0 until 10000) { - nativeBuffer.put(i,i) - } - } - - @Benchmark - fun benchmarkArrayRead() { - var res = 0 - for (i in 1..10000) { - res += array[10000 - i] - } - print(res) - } - - @Benchmark - fun benchmarkBufferRead() { - var res = 0 - for (i in 1..10000) { - res += arrayBuffer.get(10000 - i) - } - print(res) - } - - @Benchmark - fun nativeBufferRead() { - var res = 0 - for (i in 1..10000) { - res += nativeBuffer.get(10000 - i) - } - print(res) - } -} \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 0e4b6fea7..90567bfb2 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,7 +1,7 @@ pluginManagement { repositories { - maven { url = 'http://dl.bintray.com/kotlin/kotlin-eap' } mavenCentral() + maven { url = 'http://dl.bintray.com/kotlin/kotlin-eap' } maven { url = 'https://plugins.gradle.org/m2/' } } } @@ -10,5 +10,6 @@ enableFeaturePreview('GRADLE_METADATA') rootProject.name = 'kmath' include ':kmath-core' +include ':kmath-aida' include ':kmath-jmh'