From dd8a4796f6494dbe99ec180b722610dd7f309e2a Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Tue, 4 Jan 2022 13:15:50 +0300 Subject: [PATCH] Update gradle plugin and build consistency --- build.gradle.kts | 2 +- buildSrc/build.gradle.kts | 20 ++++++++++++---- buildSrc/gradle.properties | 14 +++++++++++ buildSrc/settings.gradle.kts | 24 +++++++++++++++++++ .../benchmarks/addBenchmarkProperties.kt | 13 ++++++---- .../kscience/kmath/stat/DistributionDemo.kt | 6 ++--- gradle.properties | 6 ++--- gradle/wrapper/gradle-wrapper.properties | 2 +- .../space/kscience/kmath/chains/Chain.kt | 15 +++++++----- .../space/kscience/kmath/stat/Sampler.kt | 9 ++++--- .../kscience/kmath/viktor/ViktorFieldOpsND.kt | 2 +- settings.gradle.kts | 23 ++++++++++-------- 12 files changed, 97 insertions(+), 39 deletions(-) create mode 100644 buildSrc/gradle.properties create mode 100644 buildSrc/settings.gradle.kts diff --git a/build.gradle.kts b/build.gradle.kts index 1da8f5d64..b0797d397 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -55,7 +55,7 @@ subprojects { readme.readmeTemplate = file("docs/templates/README-TEMPLATE.md") ksciencePublish { - github("kmath", publish = false) + github("kmath") space() sonatype() } diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 072309332..a7bf5c326 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -1,20 +1,30 @@ plugins { `kotlin-dsl` - kotlin("plugin.serialization") version "1.5.21" + `version-catalog` + alias(npmlibs.plugins.kotlin.plugin.serialization) } +java.targetCompatibility = JavaVersion.VERSION_11 + repositories { maven("https://repo.kotlin.link") mavenCentral() gradlePluginPortal() } +val toolsVersion: String by extra +val kotlinVersion = npmlibs.versions.kotlin.asProvider().get() +val benchmarksVersion = npmlibs.versions.kotlinx.benchmark.get() + dependencies { - api("org.jetbrains.kotlinx:kotlinx-serialization-json:1.2.2") - api("ru.mipt.npm:gradle-tools:0.10.7") - api("org.jetbrains.kotlinx:kotlinx-benchmark-plugin:0.3.1") + api("ru.mipt.npm:gradle-tools:$toolsVersion") + //plugins form benchmarks + api("org.jetbrains.kotlinx:kotlinx-benchmark-plugin:$benchmarksVersion") + api("org.jetbrains.kotlin:kotlin-allopen:$kotlinVersion") + //to be used inside build-script only + implementation(npmlibs.kotlinx.serialization.json) } kotlin.sourceSets.all { - languageSettings.useExperimentalAnnotation("kotlin.ExperimentalStdlibApi") + languageSettings.optIn("kotlin.OptIn") } diff --git a/buildSrc/gradle.properties b/buildSrc/gradle.properties new file mode 100644 index 000000000..6678f24a8 --- /dev/null +++ b/buildSrc/gradle.properties @@ -0,0 +1,14 @@ +# +# Copyright 2018-2021 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. +# + +kotlin.code.style=official +kotlin.mpp.stability.nowarn=true + +kotlin.jupyter.add.scanner=false + +org.gradle.configureondemand=true +org.gradle.parallel=true + +toolsVersion=0.10.9-kotlin-1.6.10 diff --git a/buildSrc/settings.gradle.kts b/buildSrc/settings.gradle.kts new file mode 100644 index 000000000..87ff205f6 --- /dev/null +++ b/buildSrc/settings.gradle.kts @@ -0,0 +1,24 @@ +/* + * Copyright 2018-2021 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. + */ + + +enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS") +enableFeaturePreview("VERSION_CATALOGS") + +dependencyResolutionManagement { + + val toolsVersion: String by extra + + repositories { + maven("https://repo.kotlin.link") + mavenCentral() + } + + versionCatalogs { + create("npmlibs") { + from("ru.mipt.npm:version-catalog:$toolsVersion") + } + } +} diff --git a/buildSrc/src/main/kotlin/space/kscience/kmath/benchmarks/addBenchmarkProperties.kt b/buildSrc/src/main/kotlin/space/kscience/kmath/benchmarks/addBenchmarkProperties.kt index ca1c330a1..dc9327348 100644 --- a/buildSrc/src/main/kotlin/space/kscience/kmath/benchmarks/addBenchmarkProperties.kt +++ b/buildSrc/src/main/kotlin/space/kscience/kmath/benchmarks/addBenchmarkProperties.kt @@ -6,12 +6,15 @@ package space.kscience.kmath.benchmarks import kotlinx.benchmark.gradle.BenchmarksExtension -import kotlinx.serialization.* -import kotlinx.serialization.json.* +import kotlinx.serialization.decodeFromString +import kotlinx.serialization.json.Json import org.gradle.api.Project import ru.mipt.npm.gradle.KScienceReadmeExtension -import java.time.* -import java.time.format.* +import java.time.LocalDateTime +import java.time.ZoneId +import java.time.format.DateTimeFormatter +import java.time.format.DateTimeFormatterBuilder +import java.time.format.SignStyle import java.time.temporal.ChronoField.* private val ISO_DATE_TIME: DateTimeFormatter = DateTimeFormatterBuilder().run { @@ -47,7 +50,7 @@ fun Project.addBenchmarkProperties() { rootProject.subprojects.forEach { p -> p.extensions.findByType(KScienceReadmeExtension::class.java)?.run { benchmarksProject.extensions.findByType(BenchmarksExtension::class.java)?.configurations?.forEach { cfg -> - property("benchmark${cfg.name.replaceFirstChar(Char::uppercase)}") { + property("benchmark${cfg.name.capitalize()}") { val launches = benchmarksProject.buildDir.resolve("reports/benchmarks/${cfg.name}") val resDirectory = launches.listFiles()?.maxByOrNull { diff --git a/examples/src/main/kotlin/space/kscience/kmath/stat/DistributionDemo.kt b/examples/src/main/kotlin/space/kscience/kmath/stat/DistributionDemo.kt index bde83cea9..15654971f 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/stat/DistributionDemo.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/stat/DistributionDemo.kt @@ -7,7 +7,7 @@ package space.kscience.kmath.stat import kotlinx.coroutines.runBlocking import space.kscience.kmath.chains.Chain -import space.kscience.kmath.chains.collectWithState +import space.kscience.kmath.chains.combineWithState import space.kscience.kmath.distributions.NormalDistribution private data class AveragingChainState(var num: Int = 0, var value: Double = 0.0) @@ -15,11 +15,11 @@ private data class AveragingChainState(var num: Int = 0, var value: Double = 0.0 /** * Averaging. */ -private fun Chain.mean(): Chain = collectWithState(AveragingChainState(), { it.copy() }) { chain -> +private fun Chain.mean(): Chain = combineWithState(AveragingChainState(), { it.copy() }) { chain -> val next = chain.next() num++ value += next - return@collectWithState value / num + return@combineWithState value / num } diff --git a/gradle.properties b/gradle.properties index 959511c68..6678f24a8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,11 +6,9 @@ kotlin.code.style=official kotlin.mpp.stability.nowarn=true -#kotlin.mpp.enableGranularSourceSetsMetadata=true -#kotlin.native.enableDependencyPropagation=false - kotlin.jupyter.add.scanner=false org.gradle.configureondemand=true -org.gradle.jvmargs=-XX:MaxMetaspaceSize=2G org.gradle.parallel=true + +toolsVersion=0.10.9-kotlin-1.6.10 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index ffed3a254..2e6e5897b 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/chains/Chain.kt b/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/chains/Chain.kt index f8d2549e5..994255e38 100644 --- a/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/chains/Chain.kt +++ b/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/chains/Chain.kt @@ -10,6 +10,7 @@ import kotlinx.coroutines.flow.FlowCollector import kotlinx.coroutines.flow.flow import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock +import space.kscience.kmath.misc.UnstableKMathAPI /** * A not-necessary-Markov chain of some type @@ -124,20 +125,22 @@ public fun Chain.filter(block: (T) -> Boolean): Chain = object : Chain /** * Map the whole chain */ -public fun Chain.collect(mapper: suspend (Chain) -> R): Chain = object : Chain { - override suspend fun next(): R = mapper(this@collect) - override suspend fun fork(): Chain = this@collect.fork().collect(mapper) +@UnstableKMathAPI +public fun Chain.combine(mapper: suspend (Chain) -> R): Chain = object : Chain { + override suspend fun next(): R = mapper(this@combine) + override suspend fun fork(): Chain = this@combine.fork().combine(mapper) } -public fun Chain.collectWithState( +@UnstableKMathAPI +public fun Chain.combineWithState( state: S, stateFork: (S) -> S, mapper: suspend S.(Chain) -> R, ): Chain = object : Chain { - override suspend fun next(): R = state.mapper(this@collectWithState) + override suspend fun next(): R = state.mapper(this@combineWithState) override suspend fun fork(): Chain = - this@collectWithState.fork().collectWithState(stateFork(state), stateFork, mapper) + this@combineWithState.fork().combineWithState(stateFork(state), stateFork, mapper) } /** diff --git a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/Sampler.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/Sampler.kt index 4c11fdd65..0dd121f3b 100644 --- a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/Sampler.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/Sampler.kt @@ -7,8 +7,11 @@ package space.kscience.kmath.stat import kotlinx.coroutines.flow.first import space.kscience.kmath.chains.Chain -import space.kscience.kmath.chains.collect -import space.kscience.kmath.structures.* +import space.kscience.kmath.chains.combine +import space.kscience.kmath.structures.Buffer +import space.kscience.kmath.structures.BufferFactory +import space.kscience.kmath.structures.DoubleBuffer +import space.kscience.kmath.structures.IntBuffer import kotlin.jvm.JvmName /** @@ -36,7 +39,7 @@ public fun Sampler.sampleBuffer( //creating temporary storage once val tmp = ArrayList(size) - return sample(generator).collect { chain -> + return sample(generator).combine { chain -> //clear list from previous run tmp.clear() //Fill list diff --git a/kmath-viktor/src/main/kotlin/space/kscience/kmath/viktor/ViktorFieldOpsND.kt b/kmath-viktor/src/main/kotlin/space/kscience/kmath/viktor/ViktorFieldOpsND.kt index ef7702014..dc0f1f97c 100644 --- a/kmath-viktor/src/main/kotlin/space/kscience/kmath/viktor/ViktorFieldOpsND.kt +++ b/kmath-viktor/src/main/kotlin/space/kscience/kmath/viktor/ViktorFieldOpsND.kt @@ -14,7 +14,7 @@ import space.kscience.kmath.operations.ExtendedFieldOps import space.kscience.kmath.operations.NumbersAddOps import space.kscience.kmath.operations.PowerOperations -@OptIn(UnstableKMathAPI::class) +@OptIn(UnstableKMathAPI::class, PerformancePitfall::class) @Suppress("OVERRIDE_BY_INLINE", "NOTHING_TO_INLINE") public open class ViktorFieldOpsND : FieldOpsND, diff --git a/settings.gradle.kts b/settings.gradle.kts index 343e937e1..7108b0cb4 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,21 +1,24 @@ -pluginManagement { +rootProject.name = "kmath" + +enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS") +enableFeaturePreview("VERSION_CATALOGS") + +dependencyResolutionManagement { + + val toolsVersion: String by extra + repositories { maven("https://repo.kotlin.link") mavenCentral() - gradlePluginPortal() } - val kotlinVersion = "1.6.0" - - plugins { - id("org.jetbrains.kotlinx.benchmark") version "0.3.1" - kotlin("multiplatform") version kotlinVersion - kotlin("plugin.allopen") version kotlinVersion + versionCatalogs { + create("npmlibs") { + from("ru.mipt.npm:version-catalog:$toolsVersion") + } } } -rootProject.name = "kmath" - include( ":kmath-memory", ":kmath-complex",