Dev #20

Merged
altavir merged 10 commits from dev into master 2018-10-29 19:00:20 +03:00
3 changed files with 11 additions and 11 deletions
Showing only changes of commit 34374e1006 - Show all commits

View File

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

View File

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

View File

@ -70,11 +70,10 @@ 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 {
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]
@ -84,5 +83,6 @@ class UnivariateHistogram private constructor(private val factory: (Double) -> U
}
}
}
}
fun UnivariateHistogram.fill(sequence: Iterable<Double>) = sequence.forEach { put(it) }