diff --git a/kmath-core/src/commonMain/kotlin/scientifik/kmath/histogram/FastHistogram.kt b/kmath-core/src/commonMain/kotlin/scientifik/kmath/histogram/FastHistogram.kt index 5f69f9d12..3852de316 100644 --- a/kmath-core/src/commonMain/kotlin/scientifik/kmath/histogram/FastHistogram.kt +++ b/kmath-core/src/commonMain/kotlin/scientifik/kmath/histogram/FastHistogram.kt @@ -17,7 +17,7 @@ class MultivariateBin(override val center: RealVector, val sizes: RealVector, va return vector.asSequence().mapIndexed { i, value -> value in (center[i] - sizes[i] / 2)..(center[i] + sizes[i] / 2) }.all { it } } - override val value: Number get() = counter.sum() + override val value get() = counter.sum() internal operator fun inc() = this.also { counter.increment() } override val dimension: Int get() = center.size @@ -51,8 +51,8 @@ class FastHistogram( val center = indexArray.mapIndexed { axis, index -> when (index) { 0 -> Double.NEGATIVE_INFINITY - actualSizes[axis] -> Double.POSITIVE_INFINITY - else -> lower[axis] + (index - 1) * binSize[axis] + actualSizes[axis] - 1 -> Double.POSITIVE_INFINITY + else -> lower[axis] + (index.toDouble() - 0.5) * binSize[axis] } }.toVector() MultivariateBin(center, binSize) diff --git a/kmath-core/src/commonTest/kotlin/scientifik/kmath/histogram/MultivariateHistogramTest.kt b/kmath-core/src/commonTest/kotlin/scientifik/kmath/histogram/MultivariateHistogramTest.kt index 2fbbbc88d..842a12ae4 100644 --- a/kmath-core/src/commonTest/kotlin/scientifik/kmath/histogram/MultivariateHistogramTest.kt +++ b/kmath-core/src/commonTest/kotlin/scientifik/kmath/histogram/MultivariateHistogramTest.kt @@ -14,10 +14,11 @@ class MultivariateHistogramTest { (-1.0..1.0), (-1.0..1.0) ) - histogram.put(0.6, 0.6) + histogram.put(0.55, 0.55) val bin = histogram.find { it.value.toInt() > 0 }!! - assertTrue { bin.contains(Vector.ofReal(0.6, 0.6)) } - assertFalse { bin.contains(Vector.ofReal(-0.6, 0.6)) } + assertTrue { bin.contains(Vector.ofReal(0.55, 0.55)) } + assertTrue { bin.contains(Vector.ofReal(0.6, 0.5)) } + assertFalse { bin.contains(Vector.ofReal(-0.55, 0.55)) } } @Test