forked from kscience/kmath
started TimeSeriesAlgebra
This commit is contained in:
parent
1d7f4ed538
commit
ba26c7020e
@ -155,17 +155,6 @@ public class SeriesAlgebra<T, out A : Ring<T>, out BA : BufferAlgebra<T, A>, L>(
|
||||
return accumulator
|
||||
}
|
||||
|
||||
// TODO: add fold with recorded accumulation
|
||||
// public inline fun <R> Buffer<T>.traceFold(initial: R, operation: A.(acc: R, T) -> R): Buffer<R> {
|
||||
// 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 <R> Buffer<T>.foldWithLabel(initial: R, operation: A.(acc: R, arg: T, label: L) -> R): R {
|
||||
val labels = labels
|
||||
var accumulator = initial
|
||||
|
@ -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<R, T>: Series<R> {
|
||||
public override val origin: Buffer<R>
|
||||
public override val position: Int
|
||||
|
||||
// TODO: Specify the types of DateTime that can be contained in timeStamp Buffer
|
||||
public val timeStamp: Buffer<T> // Buffer of some datetime instances like: Instant, LocalDate, LocalTime...
|
||||
}
|
||||
|
||||
private class TimeSeriesImpl<R, T>(
|
||||
override val origin: Buffer<R>,
|
||||
override val timeStamp: Buffer<T>,
|
||||
override val position: Int,
|
||||
override val size: Int = origin.size,
|
||||
) : TimeSeries<R, T> 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 ?
|
Loading…
Reference in New Issue
Block a user