diff --git a/kmath-core/src/jvmMain/kotlin/scientifik/kmath/histogram/FastHistogram.kt b/kmath-core/src/commonMain/kotlin/scientifik/kmath/histogram/FastHistogram.kt similarity index 96% rename from kmath-core/src/jvmMain/kotlin/scientifik/kmath/histogram/FastHistogram.kt rename to kmath-core/src/commonMain/kotlin/scientifik/kmath/histogram/FastHistogram.kt index f2f5c04bb..5fd4c7f03 100644 --- a/kmath-core/src/jvmMain/kotlin/scientifik/kmath/histogram/FastHistogram.kt +++ b/kmath-core/src/commonMain/kotlin/scientifik/kmath/histogram/FastHistogram.kt @@ -12,7 +12,7 @@ class MultivariateBin(override val center: RealVector, val sizes: RealVector, va } override fun contains(vector: RealVector): Boolean { - assert(vector.size == center.size) + if(vector.size != center.size) error("Dimension mismatch for input vector. Expected ${center.size}, but found ${vector.size}") return vector.asSequence().mapIndexed { i, value -> value in (center[i] - sizes[i] / 2)..(center[i] + sizes[i] / 2) }.all { it } } diff --git a/kmath-core/src/jvmTest/kotlin/scientifik/kmath/histogram/MultivariateHistogramTest.kt b/kmath-core/src/commonTest/kotlin/scientifik/kmath/histogram/MultivariateHistogramTest.kt similarity index 97% rename from kmath-core/src/jvmTest/kotlin/scientifik/kmath/histogram/MultivariateHistogramTest.kt rename to kmath-core/src/commonTest/kotlin/scientifik/kmath/histogram/MultivariateHistogramTest.kt index e80a7340e..2fbbbc88d 100644 --- a/kmath-core/src/jvmTest/kotlin/scientifik/kmath/histogram/MultivariateHistogramTest.kt +++ b/kmath-core/src/commonTest/kotlin/scientifik/kmath/histogram/MultivariateHistogramTest.kt @@ -1,8 +1,8 @@ package scientifik.kmath.histogram -import org.junit.Test import scientifik.kmath.linear.Vector import kotlin.random.Random +import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertFalse import kotlin.test.assertTrue diff --git a/kmath-core/src/jvmMain/kotlin/scientifik/kmath/histogram/UnivariateHistogram.kt b/kmath-core/src/jvmMain/kotlin/scientifik/kmath/histogram/UnivariateHistogram.kt index 993b1e850..a3b066b02 100644 --- a/kmath-core/src/jvmMain/kotlin/scientifik/kmath/histogram/UnivariateHistogram.kt +++ b/kmath-core/src/jvmMain/kotlin/scientifik/kmath/histogram/UnivariateHistogram.kt @@ -70,15 +70,15 @@ class UnivariateHistogram private constructor(private val factory: (Double) -> U fun custom(borders: DoubleArray): UnivariateHistogram { val sorted = borders.sortedArray() return UnivariateHistogram { value -> - if (value < sorted.first()) { - UnivariateBin(Double.NEGATIVE_INFINITY, Double.MAX_VALUE) - } else if (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] - val right = sorted[index + 1] - UnivariateBin((left + right) / 2, (right - left)) + when { + 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] + val right = sorted[index + 1] + UnivariateBin((left + right) / 2, (right - left)) + } } } }