Moved sums out of Space
This commit is contained in:
parent
f8f7aa2e44
commit
c0bdacecb3
@ -33,9 +33,6 @@ interface Space<T> {
|
|||||||
operator fun T.times(k: Number) = multiply(this, k.toDouble())
|
operator fun T.times(k: Number) = multiply(this, k.toDouble())
|
||||||
operator fun T.div(k: Number) = multiply(this, 1.0 / k.toDouble())
|
operator fun T.div(k: Number) = multiply(this, 1.0 / k.toDouble())
|
||||||
operator fun Number.times(b: T) = b * this
|
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) }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -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) }
|
Loading…
Reference in New Issue
Block a user