forked from kscience/kmath
Replace opt-in annotations with useExperimentalAnnotation for modules
This commit is contained in:
parent
1b8ddedfe3
commit
40888f66d6
@ -56,6 +56,12 @@ benchmark {
|
||||
}
|
||||
}
|
||||
|
||||
kotlin.sourceSets.all {
|
||||
with(languageSettings) {
|
||||
useExperimentalAnnotation("kotlin.contracts.ExperimentalContracts")
|
||||
useExperimentalAnnotation("kotlin.ExperimentalUnsignedTypes")
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType<KotlinCompile> {
|
||||
kotlinOptions {
|
||||
|
@ -1,11 +1,9 @@
|
||||
package scientifik.kmath.utils
|
||||
|
||||
import kotlin.contracts.ExperimentalContracts
|
||||
import kotlin.contracts.InvocationKind
|
||||
import kotlin.contracts.contract
|
||||
import kotlin.system.measureTimeMillis
|
||||
|
||||
@OptIn(ExperimentalContracts::class)
|
||||
internal inline fun measureAndPrint(title: String, block: () -> Unit) {
|
||||
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
|
||||
val time = measureTimeMillis(block)
|
||||
|
@ -8,7 +8,6 @@ import kotlin.contracts.InvocationKind
|
||||
import kotlin.contracts.contract
|
||||
import kotlin.system.measureTimeMillis
|
||||
|
||||
@OptIn(ExperimentalContracts::class)
|
||||
internal inline fun measureAndPrint(title: String, block: () -> Unit) {
|
||||
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
|
||||
val time = measureTimeMillis(block)
|
||||
|
@ -16,7 +16,6 @@ fun DMatrixContext<Double, RealField>.simple() {
|
||||
|
||||
|
||||
object D5 : Dimension {
|
||||
@OptIn(ExperimentalUnsignedTypes::class)
|
||||
override val dim: UInt = 5u
|
||||
}
|
||||
|
||||
|
@ -1,11 +1,8 @@
|
||||
plugins { id("scientifik.mpp") }
|
||||
|
||||
kotlin.sourceSets {
|
||||
// all {
|
||||
// languageSettings.apply{
|
||||
// enableLanguageFeature("NewInference")
|
||||
// }
|
||||
// }
|
||||
all { languageSettings.useExperimentalAnnotation("kotlin.contracts.ExperimentalContracts") }
|
||||
|
||||
commonMain {
|
||||
dependencies {
|
||||
api(project(":kmath-core"))
|
||||
|
@ -41,7 +41,6 @@ inline fun <reified T : Any, A : Algebra<T>, E : Algebra<MST>> A.mst(
|
||||
/**
|
||||
* Builds [MstExpression] over [Space].
|
||||
*/
|
||||
@OptIn(ExperimentalContracts::class)
|
||||
inline fun <reified T : Any> Space<T>.mstInSpace(block: MstSpace.() -> MST): MstExpression<T> {
|
||||
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
|
||||
return MstExpression(this, MstSpace.block())
|
||||
@ -50,7 +49,6 @@ inline fun <reified T : Any> Space<T>.mstInSpace(block: MstSpace.() -> MST): Mst
|
||||
/**
|
||||
* Builds [MstExpression] over [Ring].
|
||||
*/
|
||||
@OptIn(ExperimentalContracts::class)
|
||||
inline fun <reified T : Any> Ring<T>.mstInRing(block: MstRing.() -> MST): MstExpression<T> {
|
||||
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
|
||||
return MstExpression(this, MstRing.block())
|
||||
@ -59,7 +57,6 @@ inline fun <reified T : Any> Ring<T>.mstInRing(block: MstRing.() -> MST): MstExp
|
||||
/**
|
||||
* Builds [MstExpression] over [Field].
|
||||
*/
|
||||
@OptIn(ExperimentalContracts::class)
|
||||
inline fun <reified T : Any> Field<T>.mstInField(block: MstField.() -> MST): MstExpression<T> {
|
||||
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
|
||||
return MstExpression(this, MstField.block())
|
||||
@ -68,7 +65,6 @@ inline fun <reified T : Any> Field<T>.mstInField(block: MstField.() -> MST): Mst
|
||||
/**
|
||||
* Builds [MstExpression] over [ExtendedField].
|
||||
*/
|
||||
@OptIn(ExperimentalContracts::class)
|
||||
inline fun <reified T : Any> Field<T>.mstInExtendedField(block: MstExtendedField.() -> MST): MstExpression<T> {
|
||||
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
|
||||
return MstExpression(this, MstExtendedField.block())
|
||||
@ -77,7 +73,6 @@ inline fun <reified T : Any> Field<T>.mstInExtendedField(block: MstExtendedField
|
||||
/**
|
||||
* Builds [MstExpression] over [FunctionalExpressionSpace].
|
||||
*/
|
||||
@OptIn(ExperimentalContracts::class)
|
||||
inline fun <reified T : Any, A : Space<T>> FunctionalExpressionSpace<T, A>.mstInSpace(block: MstSpace.() -> MST): MstExpression<T> {
|
||||
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
|
||||
return algebra.mstInSpace(block)
|
||||
@ -86,8 +81,6 @@ inline fun <reified T : Any, A : Space<T>> FunctionalExpressionSpace<T, A>.mstIn
|
||||
/**
|
||||
* Builds [MstExpression] over [FunctionalExpressionRing].
|
||||
*/
|
||||
|
||||
@OptIn(ExperimentalContracts::class)
|
||||
inline fun <reified T : Any, A : Ring<T>> FunctionalExpressionRing<T, A>.mstInRing(block: MstRing.() -> MST): MstExpression<T> {
|
||||
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
|
||||
return algebra.mstInRing(block)
|
||||
@ -96,7 +89,6 @@ inline fun <reified T : Any, A : Ring<T>> FunctionalExpressionRing<T, A>.mstInRi
|
||||
/**
|
||||
* Builds [MstExpression] over [FunctionalExpressionField].
|
||||
*/
|
||||
@OptIn(ExperimentalContracts::class)
|
||||
inline fun <reified T : Any, A : Field<T>> FunctionalExpressionField<T, A>.mstInField(block: MstField.() -> MST): MstExpression<T> {
|
||||
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
|
||||
return algebra.mstInField(block)
|
||||
@ -105,7 +97,6 @@ inline fun <reified T : Any, A : Field<T>> FunctionalExpressionField<T, A>.mstIn
|
||||
/**
|
||||
* Builds [MstExpression] over [FunctionalExpressionExtendedField].
|
||||
*/
|
||||
@OptIn(ExperimentalContracts::class)
|
||||
inline fun <reified T : Any, A : ExtendedField<T>> FunctionalExpressionExtendedField<T, A>.mstInExtendedField(block: MstExtendedField.() -> MST): MstExpression<T> {
|
||||
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
|
||||
return algebra.mstInExtendedField(block)
|
||||
|
@ -29,7 +29,6 @@ internal val KClass<*>.asm: Type
|
||||
/**
|
||||
* Returns singleton array with this value if the [predicate] is true, returns empty array otherwise.
|
||||
*/
|
||||
@OptIn(ExperimentalContracts::class)
|
||||
internal inline fun <reified T> T.wrapToArrayIf(predicate: (T) -> Boolean): Array<T> {
|
||||
contract { callsInPlace(predicate, InvocationKind.EXACTLY_ONCE) }
|
||||
return if (predicate(this)) arrayOf(this) else emptyArray()
|
||||
@ -43,7 +42,6 @@ private fun MethodVisitor.instructionAdapter(): InstructionAdapter = Instruction
|
||||
/**
|
||||
* Creates an [InstructionAdapter] from this [MethodVisitor] and applies [block] to it.
|
||||
*/
|
||||
@OptIn(ExperimentalContracts::class)
|
||||
internal inline fun MethodVisitor.instructionAdapter(block: InstructionAdapter.() -> Unit): InstructionAdapter {
|
||||
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
|
||||
return instructionAdapter().apply(block)
|
||||
@ -72,14 +70,12 @@ internal tailrec fun buildName(mst: MST, collision: Int = 0): String {
|
||||
return buildName(mst, collision + 1)
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalContracts::class)
|
||||
@Suppress("FunctionName")
|
||||
internal inline fun ClassWriter(flags: Int, block: ClassWriter.() -> Unit): ClassWriter {
|
||||
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
|
||||
return ClassWriter(flags).apply(block)
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalContracts::class)
|
||||
internal inline fun ClassWriter.visitField(
|
||||
access: Int,
|
||||
name: String,
|
||||
@ -167,7 +163,6 @@ private fun <T> AsmBuilder<T>.tryInvokeSpecific(
|
||||
/**
|
||||
* Builds specialized algebra call with option to fallback to generic algebra operation accepting String.
|
||||
*/
|
||||
@OptIn(ExperimentalContracts::class)
|
||||
internal inline fun <T> AsmBuilder<T>.buildAlgebraOperationCall(
|
||||
context: Algebra<T>,
|
||||
name: String,
|
||||
|
@ -1,7 +1,4 @@
|
||||
plugins {
|
||||
id("scientifik.jvm")
|
||||
}
|
||||
|
||||
plugins { id("scientifik.jvm") }
|
||||
description = "Commons math binding for kmath"
|
||||
|
||||
dependencies {
|
||||
@ -10,4 +7,6 @@ dependencies {
|
||||
api(project(":kmath-prob"))
|
||||
api(project(":kmath-functions"))
|
||||
api("org.apache.commons:commons-math3:3.6.1")
|
||||
}
|
||||
}
|
||||
|
||||
kotlin.sourceSets.all { languageSettings.useExperimentalAnnotation("kotlin.contracts.ExperimentalContracts") }
|
||||
|
@ -1,13 +1,11 @@
|
||||
package scientifik.kmath.commons.expressions
|
||||
|
||||
import scientifik.kmath.expressions.invoke
|
||||
import kotlin.contracts.ExperimentalContracts
|
||||
import kotlin.contracts.InvocationKind
|
||||
import kotlin.contracts.contract
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
@OptIn(ExperimentalContracts::class)
|
||||
inline fun <R> diff(order: Int, vararg parameters: Pair<String, Double>, block: DerivativeStructureField.() -> R): R {
|
||||
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
|
||||
return DerivativeStructureField(order, mapOf(*parameters)).run(block)
|
||||
|
@ -1,7 +1,6 @@
|
||||
plugins { id("scientifik.mpp") }
|
||||
|
||||
kotlin.sourceSets {
|
||||
commonMain {
|
||||
dependencies { api(project(":kmath-memory")) }
|
||||
}
|
||||
all { languageSettings.useExperimentalAnnotation("kotlin.contracts.ExperimentalContracts") }
|
||||
commonMain { dependencies { api(project(":kmath-memory")) } }
|
||||
}
|
||||
|
@ -11,7 +11,6 @@ import kotlin.contracts.contract
|
||||
/**
|
||||
* Creates a functional expression with this [Space].
|
||||
*/
|
||||
@OptIn(ExperimentalContracts::class)
|
||||
inline fun <T> Space<T>.spaceExpression(block: FunctionalExpressionSpace<T, Space<T>>.() -> Expression<T>): Expression<T> {
|
||||
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
|
||||
return FunctionalExpressionSpace(this).block()
|
||||
@ -20,7 +19,6 @@ inline fun <T> Space<T>.spaceExpression(block: FunctionalExpressionSpace<T, Spac
|
||||
/**
|
||||
* Creates a functional expression with this [Ring].
|
||||
*/
|
||||
@OptIn(ExperimentalContracts::class)
|
||||
inline fun <T> Ring<T>.ringExpression(block: FunctionalExpressionRing<T, Ring<T>>.() -> Expression<T>): Expression<T> {
|
||||
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
|
||||
return FunctionalExpressionRing(this).block()
|
||||
@ -29,7 +27,6 @@ inline fun <T> Ring<T>.ringExpression(block: FunctionalExpressionRing<T, Ring<T>
|
||||
/**
|
||||
* Creates a functional expression with this [Field].
|
||||
*/
|
||||
@OptIn(ExperimentalContracts::class)
|
||||
inline fun <T> Field<T>.fieldExpression(block: FunctionalExpressionField<T, Field<T>>.() -> Expression<T>): Expression<T> {
|
||||
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
|
||||
return FunctionalExpressionField(this).block()
|
||||
@ -38,7 +35,6 @@ inline fun <T> Field<T>.fieldExpression(block: FunctionalExpressionField<T, Fiel
|
||||
/**
|
||||
* Creates a functional expression with this [ExtendedField].
|
||||
*/
|
||||
@OptIn(ExperimentalContracts::class)
|
||||
inline fun <T> ExtendedField<T>.extendedFieldExpression(block: FunctionalExpressionExtendedField<T, ExtendedField<T>>.() -> Expression<T>): Expression<T> {
|
||||
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
|
||||
return FunctionalExpressionExtendedField(this).block()
|
||||
|
@ -28,7 +28,6 @@ interface FeaturedMatrix<T : Any> : Matrix<T> {
|
||||
companion object
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalContracts::class)
|
||||
inline fun Structure2D.Companion.real(rows: Int, columns: Int, initializer: (Int, Int) -> Double): Matrix<Double> {
|
||||
contract { callsInPlace(initializer) }
|
||||
return MatrixContext.real.produce(rows, columns, initializer)
|
||||
|
@ -55,7 +55,6 @@ class DerivationResult<T : Any>(
|
||||
* assertEquals(9.0, x.d) // dy/dx
|
||||
* ```
|
||||
*/
|
||||
@OptIn(ExperimentalContracts::class)
|
||||
inline fun <T : Any, F : Field<T>> F.deriv(body: AutoDiffField<T, F>.() -> Variable<T>): DerivationResult<T> {
|
||||
contract { callsInPlace(body, InvocationKind.EXACTLY_ONCE) }
|
||||
|
||||
|
@ -13,7 +13,6 @@ import kotlin.jvm.JvmName
|
||||
* @param R the type of resulting iterable.
|
||||
* @param initial lazy evaluated.
|
||||
*/
|
||||
@OptIn(ExperimentalContracts::class)
|
||||
inline fun <T, R> Iterator<T>.cumulative(initial: R, crossinline operation: (R, T) -> R): Iterator<R> {
|
||||
contract { callsInPlace(operation) }
|
||||
|
||||
|
@ -10,7 +10,6 @@ import kotlin.math.max
|
||||
import kotlin.math.min
|
||||
import kotlin.math.sign
|
||||
|
||||
|
||||
typealias Magnitude = UIntArray
|
||||
typealias TBase = ULong
|
||||
|
||||
@ -487,13 +486,11 @@ fun String.parseBigInteger(): BigInt? {
|
||||
return res * sign
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalContracts::class)
|
||||
inline fun Buffer.Companion.bigInt(size: Int, initializer: (Int) -> BigInt): Buffer<BigInt> {
|
||||
contract { callsInPlace(initializer) }
|
||||
return boxing(size, initializer)
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalContracts::class)
|
||||
inline fun MutableBuffer.Companion.bigInt(size: Int, initializer: (Int) -> BigInt): MutableBuffer<BigInt> {
|
||||
contract { callsInPlace(initializer) }
|
||||
return boxing(size, initializer)
|
||||
|
@ -198,13 +198,11 @@ data class Complex(val re: Double, val im: Double) : FieldElement<Complex, Compl
|
||||
*/
|
||||
fun Number.toComplex(): Complex = Complex(this, 0.0)
|
||||
|
||||
@OptIn(ExperimentalContracts::class)
|
||||
inline fun Buffer.Companion.complex(size: Int, crossinline init: (Int) -> Complex): Buffer<Complex> {
|
||||
contract { callsInPlace(init) }
|
||||
return MemoryBuffer.create(Complex, size, init)
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalContracts::class)
|
||||
inline fun MutableBuffer.Companion.complex(size: Int, crossinline init: (Int) -> Complex): Buffer<Complex> {
|
||||
contract { callsInPlace(init) }
|
||||
return MemoryBuffer.create(Complex, size, init)
|
||||
|
@ -167,7 +167,6 @@ fun <T> List<T>.asBuffer(): ListBuffer<T> = ListBuffer(this)
|
||||
* The function [init] is called for each array element sequentially starting from the first one.
|
||||
* It should return the value for an array element given its index.
|
||||
*/
|
||||
@OptIn(ExperimentalContracts::class)
|
||||
inline fun <T> ListBuffer(size: Int, init: (Int) -> T): ListBuffer<T> {
|
||||
contract { callsInPlace(init) }
|
||||
return List(size, init).asBuffer()
|
||||
|
@ -112,7 +112,6 @@ inline fun ComplexNDElement.mapIndexed(crossinline transform: ComplexField.(inde
|
||||
/**
|
||||
* Map one [ComplexNDElement] using function without indices.
|
||||
*/
|
||||
@OptIn(ExperimentalContracts::class)
|
||||
inline fun ComplexNDElement.map(crossinline transform: ComplexField.(Complex) -> Complex): ComplexNDElement {
|
||||
contract { callsInPlace(transform) }
|
||||
val buffer = Buffer.complex(strides.linearSize) { offset -> ComplexField.transform(buffer[offset]) }
|
||||
@ -153,7 +152,6 @@ fun NDElement.Companion.complex(vararg shape: Int, initializer: ComplexField.(In
|
||||
/**
|
||||
* Produce a context for n-dimensional operations inside this real field
|
||||
*/
|
||||
@OptIn(ExperimentalContracts::class)
|
||||
inline fun <R> ComplexField.nd(vararg shape: Int, action: ComplexNDField.() -> R): R {
|
||||
contract { callsInPlace(action, InvocationKind.EXACTLY_ONCE) }
|
||||
return NDField.complex(*shape).action()
|
||||
|
@ -66,7 +66,6 @@ class FlaggedRealBuffer(val values: DoubleArray, val flags: ByteArray) : Flagged
|
||||
}.iterator()
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalContracts::class)
|
||||
inline fun FlaggedRealBuffer.forEachValid(block: (Double) -> Unit) {
|
||||
contract { callsInPlace(block) }
|
||||
|
||||
|
@ -30,7 +30,6 @@ inline class FloatBuffer(val array: FloatArray) : MutableBuffer<Float> {
|
||||
* The function [init] is called for each array element sequentially starting from the first one.
|
||||
* It should return the value for an buffer element given its index.
|
||||
*/
|
||||
@OptIn(ExperimentalContracts::class)
|
||||
inline fun FloatBuffer(size: Int, init: (Int) -> Float): FloatBuffer {
|
||||
contract { callsInPlace(init) }
|
||||
return FloatBuffer(FloatArray(size) { init(it) })
|
||||
|
@ -31,7 +31,6 @@ inline class IntBuffer(val array: IntArray) : MutableBuffer<Int> {
|
||||
* The function [init] is called for each array element sequentially starting from the first one.
|
||||
* It should return the value for an buffer element given its index.
|
||||
*/
|
||||
@OptIn(ExperimentalContracts::class)
|
||||
inline fun IntBuffer(size: Int, init: (Int) -> Int): IntBuffer {
|
||||
contract { callsInPlace(init) }
|
||||
return IntBuffer(IntArray(size) { init(it) })
|
||||
|
@ -31,7 +31,6 @@ inline class LongBuffer(val array: LongArray) : MutableBuffer<Long> {
|
||||
* The function [init] is called for each array element sequentially starting from the first one.
|
||||
* It should return the value for an buffer element given its index.
|
||||
*/
|
||||
@OptIn(ExperimentalContracts::class)
|
||||
inline fun LongBuffer(size: Int, init: (Int) -> Long): LongBuffer {
|
||||
contract { callsInPlace(init) }
|
||||
return LongBuffer(LongArray(size) { init(it) })
|
||||
|
@ -140,7 +140,6 @@ interface MutableNDStructure<T> : NDStructure<T> {
|
||||
operator fun set(index: IntArray, value: T)
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalContracts::class)
|
||||
inline fun <T> MutableNDStructure<T>.mapInPlace(action: (IntArray, T) -> T) {
|
||||
contract { callsInPlace(action) }
|
||||
elements().forEach { (index, oldValue) -> this[index] = action(index, oldValue) }
|
||||
|
@ -30,7 +30,6 @@ inline class RealBuffer(val array: DoubleArray) : MutableBuffer<Double> {
|
||||
* The function [init] is called for each array element sequentially starting from the first one.
|
||||
* It should return the value for an buffer element given its index.
|
||||
*/
|
||||
@OptIn(ExperimentalContracts::class)
|
||||
inline fun RealBuffer(size: Int, init: (Int) -> Double): RealBuffer {
|
||||
contract { callsInPlace(init) }
|
||||
return RealBuffer(DoubleArray(size) { init(it) })
|
||||
|
@ -30,7 +30,6 @@ inline class ShortBuffer(val array: ShortArray) : MutableBuffer<Short> {
|
||||
* The function [init] is called for each array element sequentially starting from the first one.
|
||||
* It should return the value for an buffer element given its index.
|
||||
*/
|
||||
@OptIn(ExperimentalContracts::class)
|
||||
inline fun ShortBuffer(size: Int, init: (Int) -> Short): ShortBuffer {
|
||||
contract { callsInPlace(init) }
|
||||
return ShortBuffer(ShortArray(size) { init(it) })
|
||||
|
@ -4,20 +4,27 @@ plugins {
|
||||
}
|
||||
|
||||
kotlin.sourceSets {
|
||||
all {
|
||||
with(languageSettings) {
|
||||
useExperimentalAnnotation("kotlin.contracts.ExperimentalContracts")
|
||||
useExperimentalAnnotation("kotlinx.coroutines.InternalCoroutinesApi")
|
||||
useExperimentalAnnotation("kotlinx.coroutines.ExperimentalCoroutinesApi")
|
||||
useExperimentalAnnotation("kotlinx.coroutines.FlowPreview")
|
||||
}
|
||||
}
|
||||
|
||||
commonMain {
|
||||
dependencies {
|
||||
api(project(":kmath-core"))
|
||||
api("org.jetbrains.kotlinx:kotlinx-coroutines-core-common:${Scientifik.coroutinesVersion}")
|
||||
}
|
||||
}
|
||||
|
||||
jvmMain {
|
||||
dependencies {
|
||||
api("org.jetbrains.kotlinx:kotlinx-coroutines-core:${Scientifik.coroutinesVersion}")
|
||||
}
|
||||
dependencies { api("org.jetbrains.kotlinx:kotlinx-coroutines-core:${Scientifik.coroutinesVersion}") }
|
||||
}
|
||||
|
||||
jsMain {
|
||||
dependencies {
|
||||
api("org.jetbrains.kotlinx:kotlinx-coroutines-core-js:${Scientifik.coroutinesVersion}")
|
||||
}
|
||||
dependencies { api("org.jetbrains.kotlinx:kotlinx-coroutines-core-js:${Scientifik.coroutinesVersion}") }
|
||||
}
|
||||
}
|
||||
|
@ -16,9 +16,9 @@
|
||||
|
||||
package scientifik.kmath.chains
|
||||
|
||||
import kotlinx.coroutines.InternalCoroutinesApi
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.FlowCollector
|
||||
import kotlinx.coroutines.flow.flow
|
||||
import kotlinx.coroutines.sync.Mutex
|
||||
import kotlinx.coroutines.sync.withLock
|
||||
|
||||
@ -37,14 +37,8 @@ interface Chain<out R> : Flow<R> {
|
||||
*/
|
||||
fun fork(): Chain<R>
|
||||
|
||||
@OptIn(InternalCoroutinesApi::class)
|
||||
override suspend fun collect(collector: FlowCollector<R>) {
|
||||
kotlinx.coroutines.flow.flow {
|
||||
while (true) {
|
||||
emit(next())
|
||||
}
|
||||
}.collect(collector)
|
||||
}
|
||||
override suspend fun collect(collector: FlowCollector<R>): Unit =
|
||||
flow { while (true) emit(next()) }.collect(collector)
|
||||
|
||||
companion object
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ import scientifik.kmath.operations.Space
|
||||
import scientifik.kmath.operations.SpaceOperations
|
||||
import scientifik.kmath.operations.invoke
|
||||
|
||||
|
||||
@ExperimentalCoroutinesApi
|
||||
fun <T> Flow<T>.cumulativeSum(space: SpaceOperations<T>): Flow<T> = space {
|
||||
scanReduce { sum: T, element: T -> sum + element }
|
||||
|
@ -3,7 +3,6 @@ package scientifik.kmath.coroutines
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.channels.produce
|
||||
import kotlinx.coroutines.flow.*
|
||||
import kotlin.contracts.ExperimentalContracts
|
||||
import kotlin.contracts.contract
|
||||
|
||||
val Dispatchers.Math: CoroutineDispatcher
|
||||
@ -25,15 +24,11 @@ internal class LazyDeferred<T>(val dispatcher: CoroutineDispatcher, val block: s
|
||||
}
|
||||
|
||||
class AsyncFlow<T> internal constructor(internal val deferredFlow: Flow<LazyDeferred<T>>) : Flow<T> {
|
||||
@InternalCoroutinesApi
|
||||
override suspend fun collect(collector: FlowCollector<T>) {
|
||||
deferredFlow.collect {
|
||||
collector.emit((it.await()))
|
||||
}
|
||||
deferredFlow.collect { collector.emit((it.await())) }
|
||||
}
|
||||
}
|
||||
|
||||
@FlowPreview
|
||||
fun <T, R> Flow<T>.async(
|
||||
dispatcher: CoroutineDispatcher = Dispatchers.Default,
|
||||
block: suspend CoroutineScope.(T) -> R
|
||||
@ -44,7 +39,6 @@ fun <T, R> Flow<T>.async(
|
||||
return AsyncFlow(flow)
|
||||
}
|
||||
|
||||
@FlowPreview
|
||||
fun <T, R> AsyncFlow<T>.map(action: (T) -> R): AsyncFlow<R> =
|
||||
AsyncFlow(deferredFlow.map { input ->
|
||||
//TODO add function composition
|
||||
@ -54,10 +48,9 @@ fun <T, R> AsyncFlow<T>.map(action: (T) -> R): AsyncFlow<R> =
|
||||
}
|
||||
})
|
||||
|
||||
@ExperimentalCoroutinesApi
|
||||
@FlowPreview
|
||||
suspend fun <T> AsyncFlow<T>.collect(concurrency: Int, collector: FlowCollector<T>) {
|
||||
require(concurrency >= 1) { "Buffer size should be more than 1, but was $concurrency" }
|
||||
|
||||
coroutineScope {
|
||||
//Starting up to N deferred coroutines ahead of time
|
||||
val channel = produce(capacity = concurrency - 1) {
|
||||
@ -83,9 +76,6 @@ suspend fun <T> AsyncFlow<T>.collect(concurrency: Int, collector: FlowCollector<
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalContracts::class)
|
||||
@ExperimentalCoroutinesApi
|
||||
@FlowPreview
|
||||
suspend inline fun <T> AsyncFlow<T>.collect(concurrency: Int, crossinline action: suspend (value: T) -> Unit) {
|
||||
contract { callsInPlace(action) }
|
||||
|
||||
@ -94,9 +84,6 @@ suspend inline fun <T> AsyncFlow<T>.collect(concurrency: Int, crossinline action
|
||||
})
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalContracts::class)
|
||||
@ExperimentalCoroutinesApi
|
||||
@FlowPreview
|
||||
inline fun <T, R> Flow<T>.mapParallel(
|
||||
dispatcher: CoroutineDispatcher = Dispatchers.Default,
|
||||
crossinline transform: suspend (T) -> R
|
||||
|
@ -1,11 +1,6 @@
|
||||
plugins {
|
||||
id("scientifik.mpp")
|
||||
}
|
||||
plugins { id("scientifik.mpp") }
|
||||
|
||||
kotlin.sourceSets {
|
||||
commonMain {
|
||||
dependencies {
|
||||
api(project(":kmath-core"))
|
||||
}
|
||||
}
|
||||
}
|
||||
all { languageSettings.useExperimentalAnnotation("kotlin.contracts.ExperimentalContracts") }
|
||||
commonMain { dependencies { api(project(":kmath-core")) } }
|
||||
}
|
||||
|
@ -120,7 +120,6 @@ operator fun Matrix<Double>.minus(other: Matrix<Double>): RealMatrix =
|
||||
* Operations on columns
|
||||
*/
|
||||
|
||||
@OptIn(ExperimentalContracts::class)
|
||||
inline fun Matrix<Double>.appendColumn(crossinline mapper: (Buffer<Double>) -> Double): Matrix<Double> {
|
||||
contract { callsInPlace(mapper) }
|
||||
|
||||
|
@ -1,11 +1,6 @@
|
||||
plugins {
|
||||
id("scientifik.mpp")
|
||||
}
|
||||
plugins { id("scientifik.mpp") }
|
||||
|
||||
kotlin.sourceSets {
|
||||
commonMain {
|
||||
dependencies {
|
||||
api(project(":kmath-core"))
|
||||
}
|
||||
}
|
||||
all { languageSettings.useExperimentalAnnotation("kotlin.contracts.ExperimentalContracts") }
|
||||
commonMain { dependencies { api(project(":kmath-core")) } }
|
||||
}
|
||||
|
@ -71,7 +71,6 @@ class PolynomialSpace<T : Any, C : Ring<T>>(val ring: C) : Space<Polynomial<T>>
|
||||
operator fun Polynomial<T>.invoke(arg: T): T = value(ring, arg)
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalContracts::class)
|
||||
inline fun <T : Any, C : Ring<T>, R> C.polynomial(block: PolynomialSpace<T, C>.() -> R): R {
|
||||
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
|
||||
return PolynomialSpace(this).block()
|
||||
|
@ -1,3 +1,2 @@
|
||||
plugins {
|
||||
id("scientifik.mpp")
|
||||
}
|
||||
plugins { id("scientifik.mpp") }
|
||||
kotlin.sourceSets.all { languageSettings.useExperimentalAnnotation("kotlin.contracts.ExperimentalContracts") }
|
||||
|
@ -1,6 +1,5 @@
|
||||
package scientifik.memory
|
||||
|
||||
import kotlin.contracts.ExperimentalContracts
|
||||
import kotlin.contracts.InvocationKind
|
||||
import kotlin.contracts.contract
|
||||
|
||||
@ -84,7 +83,6 @@ interface MemoryReader {
|
||||
/**
|
||||
* Uses the memory for read then releases the reader.
|
||||
*/
|
||||
@OptIn(ExperimentalContracts::class)
|
||||
inline fun Memory.read(block: MemoryReader.() -> Unit) {
|
||||
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
|
||||
reader().apply(block).release()
|
||||
@ -138,7 +136,6 @@ interface MemoryWriter {
|
||||
/**
|
||||
* Uses the memory for write then releases the writer.
|
||||
*/
|
||||
@OptIn(ExperimentalContracts::class)
|
||||
inline fun Memory.write(block: MemoryWriter.() -> Unit) {
|
||||
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
|
||||
writer().apply(block).release()
|
||||
|
@ -117,7 +117,6 @@ fun ByteBuffer.asMemory(startOffset: Int = 0, size: Int = limit()): Memory =
|
||||
/**
|
||||
* Uses direct memory-mapped buffer from file to read something and close it afterwards.
|
||||
*/
|
||||
@OptIn(ExperimentalContracts::class)
|
||||
@Throws(IOException::class)
|
||||
inline fun <R> Path.readAsMemory(position: Long = 0, size: Long = Files.size(this), block: Memory.() -> R): R {
|
||||
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
|
||||
|
Loading…
Reference in New Issue
Block a user