Moved sums out of Space

This commit is contained in:
Alexander Nozik 2019-02-06 18:18:10 +03:00
parent f8f7aa2e44
commit c0bdacecb3
2 changed files with 7 additions and 3 deletions

View File

@ -33,9 +33,6 @@ interface Space<T> {
operator fun T.times(k: Number) = multiply(this, k.toDouble())
operator fun T.div(k: Number) = multiply(this, 1.0 / k.toDouble())
operator fun Number.times(b: T) = b * this
fun Iterable<T>.sum(): T = fold(zero) { left, right -> add(left,right) }
fun Sequence<T>.sum(): T = fold(zero) { left, right -> add(left, right) }
}
/**

View File

@ -0,0 +1,7 @@
package scientifik.kmath.operations
import scientifik.kmath.structures.Buffer
import scientifik.kmath.structures.asSequence
fun <T> Space<T>.sum(data : Iterable<T>): T = data.fold(zero) { left, right -> add(left,right) }
fun <T> Space<T>.sum(data : Sequence<T>): T = data.fold(zero) { left, right -> add(left, right) }