0.3.1 #514
@ -199,12 +199,25 @@ public open class SeriesAlgebra<T, out A : Ring<T>, out BA : BufferAlgebra<T, A>
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Zip buffer with itself, but shifted
|
||||
* */
|
||||
public inline fun Buffer<T>.shiftOp(
|
||||
shift: Int = 1,
|
||||
crossinline operation: A.(left: T, right: T) -> T
|
||||
): Buffer<T> {
|
||||
val shifted = this.moveTo(this.startOffset+shift)
|
||||
return zip(shifted, operation)
|
||||
}
|
||||
|
||||
override fun Buffer<T>.unaryMinus(): Buffer<T> = map { -it }
|
||||
|
||||
override fun add(left: Buffer<T>, right: Buffer<T>): Series<T> = left.zip(right) { l, r -> l + r }
|
||||
|
||||
override fun multiply(left: Buffer<T>, right: Buffer<T>): Buffer<T> = left.zip(right) { l, r -> l * r }
|
||||
|
||||
public inline fun Buffer<T>.diff(): Buffer<T> = this.shiftOp {l, r -> r - l}
|
||||
|
||||
public companion object
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user