From ba26c7020e76a5b2384f37d515471f287a37617c Mon Sep 17 00:00:00 2001 From: mrFendel Date: Thu, 6 Apr 2023 17:58:29 +0300 Subject: [PATCH] started TimeSeriesAlgebra --- .../kscience/kmath/series/SeriesAlgebra.kt | 11 ------ .../kmath/series/TimeSeriesAlgebra.kt | 37 +++++++++++++++++++ 2 files changed, 37 insertions(+), 11 deletions(-) create mode 100644 kmath-stat/src/commonMain/kotlin/space/kscience/kmath/series/TimeSeriesAlgebra.kt diff --git a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/series/SeriesAlgebra.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/series/SeriesAlgebra.kt index bdd74c4fe..b6d952955 100644 --- a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/series/SeriesAlgebra.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/series/SeriesAlgebra.kt @@ -155,17 +155,6 @@ public class SeriesAlgebra, out BA : BufferAlgebra, L>( return accumulator } - // TODO: add fold with recorded accumulation -// public inline fun Buffer.traceFold(initial: R, operation: A.(acc: R, T) -> R): Buffer { -// var tempBuffer = elementAlgebra.bufferFactory(this.size) {i -> getAbsolute(i)} -// var accumulator = initial -// for (index in this.indices) { -// accumulator = elementAlgebra.operation(accumulator, getAbsolute(index)) -// tempBuffer.set(index, accumulator) -// } -// return elementAlgebra.bufferFactory(this.size) {i -> tempBuffer.getAbsolute(i)} -// } - public inline fun Buffer.foldWithLabel(initial: R, operation: A.(acc: R, arg: T, label: L) -> R): R { val labels = labels var accumulator = initial diff --git a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/series/TimeSeriesAlgebra.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/series/TimeSeriesAlgebra.kt new file mode 100644 index 000000000..37abe710e --- /dev/null +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/series/TimeSeriesAlgebra.kt @@ -0,0 +1,37 @@ +/* + * Copyright 2018-2023 KMath contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package space.kscience.kmath.series + +import space.kscience.kmath.structures.Buffer + + + +public interface TimeSeries: Series { + public override val origin: Buffer + public override val position: Int + + // TODO: Specify the types of DateTime that can be contained in timeStamp Buffer + public val timeStamp: Buffer // Buffer of some datetime instances like: Instant, LocalDate, LocalTime... +} + +private class TimeSeriesImpl( + override val origin: Buffer, + override val timeStamp: Buffer, + override val position: Int, + override val size: Int = origin.size, +) : TimeSeries by origin { // TODO: manage with delegation + + init { + require(size > 0) { "Size must be positive" } + require(size <= origin.size) { "Slice size is larger than the original buffer" } + require(size <= timeStamp.size) { "Slice size is larger than the timeStamp buffer" } + } + +// override fun toString(): String = "$origin-->${position}" +} + + +// TODO: add conversion to Buffer of Pairs ?