From c0bdacecb32a03b1e7e86d48448dfc7f02870e9b Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Wed, 6 Feb 2019 18:18:10 +0300 Subject: [PATCH] Moved sums out of Space --- .../kotlin/scientifik/kmath/operations/Algebra.kt | 3 --- .../scientifik/kmath/operations/AlgebraExtensions.kt | 7 +++++++ 2 files changed, 7 insertions(+), 3 deletions(-) create mode 100644 kmath-core/src/commonMain/kotlin/scientifik/kmath/operations/AlgebraExtensions.kt diff --git a/kmath-core/src/commonMain/kotlin/scientifik/kmath/operations/Algebra.kt b/kmath-core/src/commonMain/kotlin/scientifik/kmath/operations/Algebra.kt index 8aa3a0e05..42c7e9377 100644 --- a/kmath-core/src/commonMain/kotlin/scientifik/kmath/operations/Algebra.kt +++ b/kmath-core/src/commonMain/kotlin/scientifik/kmath/operations/Algebra.kt @@ -33,9 +33,6 @@ interface Space { 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.sum(): T = fold(zero) { left, right -> add(left,right) } - fun Sequence.sum(): T = fold(zero) { left, right -> add(left, right) } } /** diff --git a/kmath-core/src/commonMain/kotlin/scientifik/kmath/operations/AlgebraExtensions.kt b/kmath-core/src/commonMain/kotlin/scientifik/kmath/operations/AlgebraExtensions.kt new file mode 100644 index 000000000..6dec8bd79 --- /dev/null +++ b/kmath-core/src/commonMain/kotlin/scientifik/kmath/operations/AlgebraExtensions.kt @@ -0,0 +1,7 @@ +package scientifik.kmath.operations + +import scientifik.kmath.structures.Buffer +import scientifik.kmath.structures.asSequence + +fun Space.sum(data : Iterable): T = data.fold(zero) { left, right -> add(left,right) } +fun Space.sum(data : Sequence): T = data.fold(zero) { left, right -> add(left, right) } \ No newline at end of file