From 8208cb772f51e53c8296406783b678e446202920 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Wed, 24 Apr 2019 09:36:43 +0300 Subject: [PATCH] Chains moved to coroutines. Cumulatives to core --- kmath-commons/build.gradle.kts | 2 +- .../scientifik/kmath/transform/Transformations.kt | 6 +++--- .../kotlin/scientifik/kmath/misc}/Cumulative.kt | 2 +- .../scientifik/kmath/misc}/CumulativeKtTest.kt | 1 - .../kotlin/sicentifik/kmath/chains}/Chain.kt | 15 ++++++--------- .../kotlin/scientifik/kmath/chains}/ChainExt.kt | 3 ++- .../build.gradle.kts | 0 .../kmath/streaming}/BufferStreaming.kt | 2 +- .../scientifik/kmath/streaming}/RingBuffer.kt | 2 +- .../scientifik/kmath/streaming}/Streaming.kt | 2 +- .../jvmTest/kotlin/streaming}/RingBufferTest.kt | 2 +- settings.gradle.kts | 2 +- 12 files changed, 18 insertions(+), 21 deletions(-) rename {kmath-sequential/src/commonMain/kotlin/scientifik/kmath/sequential => kmath-core/src/commonMain/kotlin/scientifik/kmath/misc}/Cumulative.kt (97%) rename {kmath-sequential/src/commonTest/kotlin/scientifik/kmath/sequential => kmath-core/src/commonTest/kotlin/scientifik/kmath/misc}/CumulativeKtTest.kt (86%) rename {kmath-sequential/src/commonMain/kotlin/scientifik/kmath/sequential => kmath-coroutines/src/commonMain/kotlin/sicentifik/kmath/chains}/Chain.kt (89%) rename {kmath-sequential/src/jvmMain/kotlin/scientifik/kmath/sequential => kmath-coroutines/src/jvmMain/kotlin/scientifik/kmath/chains}/ChainExt.kt (93%) rename {kmath-sequential => kmath-streaming}/build.gradle.kts (100%) rename {kmath-sequential/src/commonMain/kotlin/scientifik/kmath/sequential => kmath-streaming/src/commonMain/kotlin/scientifik/kmath/streaming}/BufferStreaming.kt (98%) rename {kmath-sequential/src/commonMain/kotlin/scientifik/kmath/sequential => kmath-streaming/src/commonMain/kotlin/scientifik/kmath/streaming}/RingBuffer.kt (98%) rename {kmath-sequential/src/commonMain/kotlin/scientifik/kmath/sequential => kmath-streaming/src/commonMain/kotlin/scientifik/kmath/streaming}/Streaming.kt (99%) rename {kmath-sequential/src/jvmTest/kotlin/scientifik.kmath.sequential => kmath-streaming/src/jvmTest/kotlin/streaming}/RingBufferTest.kt (92%) diff --git a/kmath-commons/build.gradle.kts b/kmath-commons/build.gradle.kts index 0ea7b7eff..6e3a62ef7 100644 --- a/kmath-commons/build.gradle.kts +++ b/kmath-commons/build.gradle.kts @@ -7,7 +7,7 @@ description = "Commons math binding for kmath" dependencies { api(project(":kmath-core")) - api(project(":kmath-sequential")) + api(project(":kmath-streaming")) api("org.apache.commons:commons-math3:3.6.1") testImplementation("org.jetbrains.kotlin:kotlin-test") testImplementation("org.jetbrains.kotlin:kotlin-test-junit") diff --git a/kmath-commons/src/main/kotlin/scientifik/kmath/transform/Transformations.kt b/kmath-commons/src/main/kotlin/scientifik/kmath/transform/Transformations.kt index 17907adbe..89ecf5f9f 100644 --- a/kmath-commons/src/main/kotlin/scientifik/kmath/transform/Transformations.kt +++ b/kmath-commons/src/main/kotlin/scientifik/kmath/transform/Transformations.kt @@ -2,9 +2,9 @@ package scientifik.kmath.transform import org.apache.commons.math3.transform.* import scientifik.kmath.operations.Complex -import scientifik.kmath.sequential.Processor -import scientifik.kmath.sequential.Producer -import scientifik.kmath.sequential.map +import scientifik.kmath.streaming.Processor +import scientifik.kmath.streaming.Producer +import scientifik.kmath.streaming.map import scientifik.kmath.structures.* diff --git a/kmath-sequential/src/commonMain/kotlin/scientifik/kmath/sequential/Cumulative.kt b/kmath-core/src/commonMain/kotlin/scientifik/kmath/misc/Cumulative.kt similarity index 97% rename from kmath-sequential/src/commonMain/kotlin/scientifik/kmath/sequential/Cumulative.kt rename to kmath-core/src/commonMain/kotlin/scientifik/kmath/misc/Cumulative.kt index b0e1e9ac5..314696262 100644 --- a/kmath-sequential/src/commonMain/kotlin/scientifik/kmath/sequential/Cumulative.kt +++ b/kmath-core/src/commonMain/kotlin/scientifik/kmath/misc/Cumulative.kt @@ -1,4 +1,4 @@ -package scientifik.kmath.sequential +package scientifik.kmath.misc import scientifik.kmath.operations.Space import kotlin.jvm.JvmName diff --git a/kmath-sequential/src/commonTest/kotlin/scientifik/kmath/sequential/CumulativeKtTest.kt b/kmath-core/src/commonTest/kotlin/scientifik/kmath/misc/CumulativeKtTest.kt similarity index 86% rename from kmath-sequential/src/commonTest/kotlin/scientifik/kmath/sequential/CumulativeKtTest.kt rename to kmath-core/src/commonTest/kotlin/scientifik/kmath/misc/CumulativeKtTest.kt index cafa0526f..e7c99e7d0 100644 --- a/kmath-sequential/src/commonTest/kotlin/scientifik/kmath/sequential/CumulativeKtTest.kt +++ b/kmath-core/src/commonTest/kotlin/scientifik/kmath/misc/CumulativeKtTest.kt @@ -1,6 +1,5 @@ package scientifik.kmath.misc -import scientifik.kmath.sequential.cumulativeSum import kotlin.test.Test import kotlin.test.assertEquals diff --git a/kmath-sequential/src/commonMain/kotlin/scientifik/kmath/sequential/Chain.kt b/kmath-coroutines/src/commonMain/kotlin/sicentifik/kmath/chains/Chain.kt similarity index 89% rename from kmath-sequential/src/commonMain/kotlin/scientifik/kmath/sequential/Chain.kt rename to kmath-coroutines/src/commonMain/kotlin/sicentifik/kmath/chains/Chain.kt index 7633b2223..21c2c9eb3 100644 --- a/kmath-sequential/src/commonMain/kotlin/scientifik/kmath/sequential/Chain.kt +++ b/kmath-coroutines/src/commonMain/kotlin/sicentifik/kmath/chains/Chain.kt @@ -14,14 +14,10 @@ * limitations under the License. */ -package scientifik.kmath.sequential +package sicentifik.kmath.chains import kotlinx.atomicfu.atomic -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.ExperimentalCoroutinesApi -import kotlinx.coroutines.channels.ReceiveChannel -import kotlinx.coroutines.channels.produce -import kotlinx.coroutines.isActive +import kotlinx.coroutines.FlowPreview /** @@ -47,10 +43,11 @@ interface Chain { } /** - * Chain as a coroutine receive channel + * Chain as a coroutine flow. The flow emit affects chain state and vice versa */ -@ExperimentalCoroutinesApi -fun Chain.asChannel(scope: CoroutineScope): ReceiveChannel = scope.produce { while (isActive) send(next()) } +@FlowPreview +val Chain.flow + get() = kotlinx.coroutines.flow.flow { while (true) emit(next()) } fun Iterator.asChain(): Chain = SimpleChain { next() } fun Sequence.asChain(): Chain = iterator().asChain() diff --git a/kmath-sequential/src/jvmMain/kotlin/scientifik/kmath/sequential/ChainExt.kt b/kmath-coroutines/src/jvmMain/kotlin/scientifik/kmath/chains/ChainExt.kt similarity index 93% rename from kmath-sequential/src/jvmMain/kotlin/scientifik/kmath/sequential/ChainExt.kt rename to kmath-coroutines/src/jvmMain/kotlin/scientifik/kmath/chains/ChainExt.kt index 74cb6bc6d..e23748bdb 100644 --- a/kmath-sequential/src/jvmMain/kotlin/scientifik/kmath/sequential/ChainExt.kt +++ b/kmath-coroutines/src/jvmMain/kotlin/scientifik/kmath/chains/ChainExt.kt @@ -1,6 +1,7 @@ -package scientifik.kmath.sequential +package scientifik.kmath.chains import kotlinx.coroutines.runBlocking +import sicentifik.kmath.chains.Chain import kotlin.sequences.Sequence /** diff --git a/kmath-sequential/build.gradle.kts b/kmath-streaming/build.gradle.kts similarity index 100% rename from kmath-sequential/build.gradle.kts rename to kmath-streaming/build.gradle.kts diff --git a/kmath-sequential/src/commonMain/kotlin/scientifik/kmath/sequential/BufferStreaming.kt b/kmath-streaming/src/commonMain/kotlin/scientifik/kmath/streaming/BufferStreaming.kt similarity index 98% rename from kmath-sequential/src/commonMain/kotlin/scientifik/kmath/sequential/BufferStreaming.kt rename to kmath-streaming/src/commonMain/kotlin/scientifik/kmath/streaming/BufferStreaming.kt index b98f48186..023199452 100644 --- a/kmath-sequential/src/commonMain/kotlin/scientifik/kmath/sequential/BufferStreaming.kt +++ b/kmath-streaming/src/commonMain/kotlin/scientifik/kmath/streaming/BufferStreaming.kt @@ -1,4 +1,4 @@ -package scientifik.kmath.sequential +package scientifik.kmath.streaming import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.ExperimentalCoroutinesApi diff --git a/kmath-sequential/src/commonMain/kotlin/scientifik/kmath/sequential/RingBuffer.kt b/kmath-streaming/src/commonMain/kotlin/scientifik/kmath/streaming/RingBuffer.kt similarity index 98% rename from kmath-sequential/src/commonMain/kotlin/scientifik/kmath/sequential/RingBuffer.kt rename to kmath-streaming/src/commonMain/kotlin/scientifik/kmath/streaming/RingBuffer.kt index 108b7f828..ac64f921f 100644 --- a/kmath-sequential/src/commonMain/kotlin/scientifik/kmath/sequential/RingBuffer.kt +++ b/kmath-streaming/src/commonMain/kotlin/scientifik/kmath/streaming/RingBuffer.kt @@ -1,4 +1,4 @@ -package scientifik.kmath.sequential +package scientifik.kmath.streaming import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock diff --git a/kmath-sequential/src/commonMain/kotlin/scientifik/kmath/sequential/Streaming.kt b/kmath-streaming/src/commonMain/kotlin/scientifik/kmath/streaming/Streaming.kt similarity index 99% rename from kmath-sequential/src/commonMain/kotlin/scientifik/kmath/sequential/Streaming.kt rename to kmath-streaming/src/commonMain/kotlin/scientifik/kmath/streaming/Streaming.kt index c0332d639..3cb3bcfdd 100644 --- a/kmath-sequential/src/commonMain/kotlin/scientifik/kmath/sequential/Streaming.kt +++ b/kmath-streaming/src/commonMain/kotlin/scientifik/kmath/streaming/Streaming.kt @@ -1,4 +1,4 @@ -package scientifik.kmath.sequential +package scientifik.kmath.streaming import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.GlobalScope diff --git a/kmath-sequential/src/jvmTest/kotlin/scientifik.kmath.sequential/RingBufferTest.kt b/kmath-streaming/src/jvmTest/kotlin/streaming/RingBufferTest.kt similarity index 92% rename from kmath-sequential/src/jvmTest/kotlin/scientifik.kmath.sequential/RingBufferTest.kt rename to kmath-streaming/src/jvmTest/kotlin/streaming/RingBufferTest.kt index c8f84e7d8..a2d798d6b 100644 --- a/kmath-sequential/src/jvmTest/kotlin/scientifik.kmath.sequential/RingBufferTest.kt +++ b/kmath-streaming/src/jvmTest/kotlin/streaming/RingBufferTest.kt @@ -1,4 +1,4 @@ -package scientifik.kmath.sequential +package scientifik.kmath.streaming import kotlinx.coroutines.runBlocking import scientifik.kmath.structures.asSequence diff --git a/settings.gradle.kts b/settings.gradle.kts index 69b1f90fe..b053776f3 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -29,6 +29,6 @@ include( ":kmath-histograms", ":kmath-commons", ":kmath-koma", - ":kmath-sequential", + ":kmath-streaming", ":benchmarks" )