From 9e2d6125f17ac70abddd37170f9e6fe77c201010 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Wed, 13 Feb 2019 18:21:51 +0300 Subject: [PATCH] Histograms evicted from core --- examples/expressions.main.kts | 1 - kmath-histograms/build.gradle.kts | 34 +++++++++++++++++++ .../scientifik/kmath/histogram/Counters.kt | 0 .../kmath/histogram/FastHistogram.kt | 5 ++- .../scientifik/kmath/histogram/Histogram.kt | 3 +- .../kmath/histogram/PhantomHistogram.kt | 3 +- .../histogram/MultivariateHistogramTest.kt | 5 ++- .../scientifik/kmath/histogram/Counters.kt | 0 .../scientifik/kmath/histogram/Counters.kt | 0 .../kmath/histogram/UnivariateHistogram.kt | 10 ++++-- settings.gradle.kts | 1 + 11 files changed, 55 insertions(+), 7 deletions(-) delete mode 100644 examples/expressions.main.kts create mode 100644 kmath-histograms/build.gradle.kts rename {kmath-core => kmath-histograms}/src/commonMain/kotlin/scientifik/kmath/histogram/Counters.kt (100%) rename {kmath-core => kmath-histograms}/src/commonMain/kotlin/scientifik/kmath/histogram/FastHistogram.kt (96%) rename {kmath-core => kmath-histograms}/src/commonMain/kotlin/scientifik/kmath/histogram/Histogram.kt (93%) rename {kmath-core => kmath-histograms}/src/commonMain/kotlin/scientifik/kmath/histogram/PhantomHistogram.kt (97%) rename {kmath-core/src/commonTest/kotlin/scientifik => kmath-histograms/src/commonTest/kotlin/scietifik}/kmath/histogram/MultivariateHistogramTest.kt (87%) rename {kmath-core => kmath-histograms}/src/jsMain/kotlin/scientifik/kmath/histogram/Counters.kt (100%) rename {kmath-core => kmath-histograms}/src/jvmMain/kotlin/scientifik/kmath/histogram/Counters.kt (100%) rename {kmath-core => kmath-histograms}/src/jvmMain/kotlin/scientifik/kmath/histogram/UnivariateHistogram.kt (89%) diff --git a/examples/expressions.main.kts b/examples/expressions.main.kts deleted file mode 100644 index baf6a4ed0..000000000 --- a/examples/expressions.main.kts +++ /dev/null @@ -1 +0,0 @@ -@file:DependsOn("scientifik:kmath-core-jvm:0.0.3-dev") \ No newline at end of file diff --git a/kmath-histograms/build.gradle.kts b/kmath-histograms/build.gradle.kts new file mode 100644 index 000000000..81b3fb83f --- /dev/null +++ b/kmath-histograms/build.gradle.kts @@ -0,0 +1,34 @@ +plugins { + kotlin("multiplatform") +} + +kotlin { + jvm() + js() + + sourceSets { + + val commonMain by getting { + dependencies { + api(project(":kmath-core")) + } + } + val commonTest by getting { + dependencies { + implementation(kotlin("test-common")) + implementation(kotlin("test-annotations-common")) + } + } + val jvmTest by getting { + dependencies { + implementation(kotlin("test")) + implementation(kotlin("test-junit")) + } + } + val jsTest by getting { + dependencies { + implementation(kotlin("test-js")) + } + } + } +} \ No newline at end of file diff --git a/kmath-core/src/commonMain/kotlin/scientifik/kmath/histogram/Counters.kt b/kmath-histograms/src/commonMain/kotlin/scientifik/kmath/histogram/Counters.kt similarity index 100% rename from kmath-core/src/commonMain/kotlin/scientifik/kmath/histogram/Counters.kt rename to kmath-histograms/src/commonMain/kotlin/scientifik/kmath/histogram/Counters.kt diff --git a/kmath-core/src/commonMain/kotlin/scientifik/kmath/histogram/FastHistogram.kt b/kmath-histograms/src/commonMain/kotlin/scientifik/kmath/histogram/FastHistogram.kt similarity index 96% rename from kmath-core/src/commonMain/kotlin/scientifik/kmath/histogram/FastHistogram.kt rename to kmath-histograms/src/commonMain/kotlin/scientifik/kmath/histogram/FastHistogram.kt index d9d4da66a..869f9a02e 100644 --- a/kmath-core/src/commonMain/kotlin/scientifik/kmath/histogram/FastHistogram.kt +++ b/kmath-histograms/src/commonMain/kotlin/scientifik/kmath/histogram/FastHistogram.kt @@ -118,7 +118,10 @@ class FastHistogram( *``` */ fun fromRanges(vararg ranges: ClosedFloatingPointRange): FastHistogram { - return FastHistogram(ranges.map { it.start }.toVector(), ranges.map { it.endInclusive }.toVector()) + return FastHistogram( + ranges.map { it.start }.toVector(), + ranges.map { it.endInclusive }.toVector() + ) } /** diff --git a/kmath-core/src/commonMain/kotlin/scientifik/kmath/histogram/Histogram.kt b/kmath-histograms/src/commonMain/kotlin/scientifik/kmath/histogram/Histogram.kt similarity index 93% rename from kmath-core/src/commonMain/kotlin/scientifik/kmath/histogram/Histogram.kt rename to kmath-histograms/src/commonMain/kotlin/scientifik/kmath/histogram/Histogram.kt index a71ab7207..c5fc67b5c 100644 --- a/kmath-core/src/commonMain/kotlin/scientifik/kmath/histogram/Histogram.kt +++ b/kmath-histograms/src/commonMain/kotlin/scientifik/kmath/histogram/Histogram.kt @@ -42,7 +42,8 @@ interface Histogram> : Iterable { } -interface MutableHistogram> : Histogram { +interface MutableHistogram> : + Histogram { /** * Increment appropriate bin diff --git a/kmath-core/src/commonMain/kotlin/scientifik/kmath/histogram/PhantomHistogram.kt b/kmath-histograms/src/commonMain/kotlin/scientifik/kmath/histogram/PhantomHistogram.kt similarity index 97% rename from kmath-core/src/commonMain/kotlin/scientifik/kmath/histogram/PhantomHistogram.kt rename to kmath-histograms/src/commonMain/kotlin/scientifik/kmath/histogram/PhantomHistogram.kt index 860eb9346..6c6614851 100644 --- a/kmath-core/src/commonMain/kotlin/scientifik/kmath/histogram/PhantomHistogram.kt +++ b/kmath-histograms/src/commonMain/kotlin/scientifik/kmath/histogram/PhantomHistogram.kt @@ -27,7 +27,8 @@ interface HistogramSpace, H : Histogram> : Space { val binSpace: Space> } -class PhantomBin>(val template: BinTemplate, override val value: Number) : Bin { +class PhantomBin>(val template: BinTemplate, override val value: Number) : + Bin { override fun contains(vector: Point): Boolean = template.contains(vector) diff --git a/kmath-core/src/commonTest/kotlin/scientifik/kmath/histogram/MultivariateHistogramTest.kt b/kmath-histograms/src/commonTest/kotlin/scietifik/kmath/histogram/MultivariateHistogramTest.kt similarity index 87% rename from kmath-core/src/commonTest/kotlin/scientifik/kmath/histogram/MultivariateHistogramTest.kt rename to kmath-histograms/src/commonTest/kotlin/scietifik/kmath/histogram/MultivariateHistogramTest.kt index 94ec6666c..d59409e76 100644 --- a/kmath-core/src/commonTest/kotlin/scientifik/kmath/histogram/MultivariateHistogramTest.kt +++ b/kmath-histograms/src/commonTest/kotlin/scietifik/kmath/histogram/MultivariateHistogramTest.kt @@ -1,5 +1,8 @@ -package scientifik.kmath.histogram +package scietifik.kmath.histogram +import scientifik.kmath.histogram.FastHistogram +import scientifik.kmath.histogram.fill +import scientifik.kmath.histogram.put import scientifik.kmath.linear.Vector import kotlin.random.Random import kotlin.test.Test diff --git a/kmath-core/src/jsMain/kotlin/scientifik/kmath/histogram/Counters.kt b/kmath-histograms/src/jsMain/kotlin/scientifik/kmath/histogram/Counters.kt similarity index 100% rename from kmath-core/src/jsMain/kotlin/scientifik/kmath/histogram/Counters.kt rename to kmath-histograms/src/jsMain/kotlin/scientifik/kmath/histogram/Counters.kt diff --git a/kmath-core/src/jvmMain/kotlin/scientifik/kmath/histogram/Counters.kt b/kmath-histograms/src/jvmMain/kotlin/scientifik/kmath/histogram/Counters.kt similarity index 100% rename from kmath-core/src/jvmMain/kotlin/scientifik/kmath/histogram/Counters.kt rename to kmath-histograms/src/jvmMain/kotlin/scientifik/kmath/histogram/Counters.kt diff --git a/kmath-core/src/jvmMain/kotlin/scientifik/kmath/histogram/UnivariateHistogram.kt b/kmath-histograms/src/jvmMain/kotlin/scientifik/kmath/histogram/UnivariateHistogram.kt similarity index 89% rename from kmath-core/src/jvmMain/kotlin/scientifik/kmath/histogram/UnivariateHistogram.kt rename to kmath-histograms/src/jvmMain/kotlin/scientifik/kmath/histogram/UnivariateHistogram.kt index 4d18b714d..f7c4e7fa4 100644 --- a/kmath-core/src/jvmMain/kotlin/scientifik/kmath/histogram/UnivariateHistogram.kt +++ b/kmath-histograms/src/jvmMain/kotlin/scientifik/kmath/histogram/UnivariateHistogram.kt @@ -76,8 +76,14 @@ class UnivariateHistogram private constructor(private val factory: (Double) -> U val sorted = borders.sortedArray() return UnivariateHistogram { value -> when { - value < sorted.first() -> UnivariateBin(Double.NEGATIVE_INFINITY, Double.MAX_VALUE) - value > sorted.last() -> UnivariateBin(Double.POSITIVE_INFINITY, Double.MAX_VALUE) + value < sorted.first() -> UnivariateBin( + Double.NEGATIVE_INFINITY, + Double.MAX_VALUE + ) + value > sorted.last() -> UnivariateBin( + Double.POSITIVE_INFINITY, + Double.MAX_VALUE + ) else -> { val index = (0 until sorted.size).first { value > sorted[it] } val left = sorted[index] diff --git a/settings.gradle.kts b/settings.gradle.kts index b306d1c8d..7d8731532 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -22,6 +22,7 @@ include( ":kmath-core", // ":kmath-io", ":kmath-coroutines", + ":kmath-histograms", ":kmath-commons", ":kmath-koma", ":kmath-sequential",