Package space.kscience.kmath.chains

Types

Link copied to clipboard
interface BlockingBufferChain<out T> : BlockingChain<T> , BufferChain<T>
Link copied to clipboard
interface BlockingChain<out T> : Chain<T>

A chain with blocking generator that could be used without suspension

Link copied to clipboard
interface BlockingDoubleChain : BlockingBufferChain<Double>

Chunked, specialized chain for double values, which supports blocking nextBlocking operation

Link copied to clipboard
interface BlockingIntChain : BlockingBufferChain<Int>

Performance optimized chain for integer values

Link copied to clipboard
interface BufferChain<out T> : Chain<T>
Link copied to clipboard
interface Chain<out T> : Flow<T>

A not-necessary-Markov chain of some type

Link copied to clipboard
class ConstantChain<out T>(value: T) : Chain<T>

A chain that repeats the same value

Link copied to clipboard
class MarkovChain<out R : Any>(seed: suspend () -> R, gen: suspend (R) -> R) : Chain<R>

A stateless Markov chain

Link copied to clipboard
class SimpleChain<out R>(gen: suspend () -> R) : Chain<R>

A simple chain of independent tokens. fork returns the same chain.

Link copied to clipboard
class StatefulChain<S, out R>(state: S, seed: S.() -> R, forkState: (S) -> S, gen: suspend S.(R) -> R) : Chain<R>

A chain with possibly mutable state. The state must not be changed outside the chain. Two chins should never share the state.

Functions

Link copied to clipboard
fun <T> Iterator<T>.asChain(): Chain<T>
fun <T> Sequence<T>.asChain(): Chain<T>
Link copied to clipboard
fun <R> Chain<R>.asSequence(): Sequence<R>

Represent a chain as a sequence

Link copied to clipboard
fun <T, R> Chain<T>.combine(mapper: suspend (Chain<T>) -> R): Chain<R>

Map the whole chain

Link copied to clipboard
fun <T, S, R> Chain<T>.combineWithState(state: S, stateFork: (S) -> S, mapper: suspend S.(Chain<T>) -> R): Chain<R>
Link copied to clipboard
fun <T> Flow<T>.cumulativeSum(group: GroupOps<T>): Flow<T>
Link copied to clipboard
fun <T> Chain<T>.filter(block: (T) -> Boolean): Chain<T>

block must be a pure function or at least not use external random variables, otherwise fork could be broken

Link copied to clipboard
operator fun <R> Chain<R>.iterator(): Iterator<R>

Represent a chain as regular iterator (uses blocking calls)

Link copied to clipboard
fun BlockingDoubleChain.map(transform: (Double) -> Double): BlockingDoubleChain

fun <T, R> Chain<T>.map(func: suspend (T) -> R): Chain<R>

Map the chain result using suspended transformation. Initial chain result can no longer be safely consumed since mapped chain consumes tokens. Accepts regular transformation function.

Link copied to clipboard
fun <T, S : Ring<T>, ScaleOperations<T>> Flow<T>.mean(space: S): Flow<T>
Link copied to clipboard
inline suspend fun <T : Any> Chain<T>.nextBuffer(size: Int): Buffer<T>
Link copied to clipboard
inline fun <T : Any> BlockingChain<T>.nextBufferBlocking(size: Int): Buffer<T>
Link copied to clipboard
fun <T, U, R> Chain<T>.zip(other: Chain<U>, block: suspend (T, U) -> R): Chain<R>

Zip two chains together using given transformation