v0.3.0-dev-18 #459
@ -55,7 +55,7 @@ subprojects {
|
|||||||
readme.readmeTemplate = file("docs/templates/README-TEMPLATE.md")
|
readme.readmeTemplate = file("docs/templates/README-TEMPLATE.md")
|
||||||
|
|
||||||
ksciencePublish {
|
ksciencePublish {
|
||||||
github("kmath", publish = false)
|
github("kmath")
|
||||||
space()
|
space()
|
||||||
sonatype()
|
sonatype()
|
||||||
}
|
}
|
||||||
|
@ -1,20 +1,30 @@
|
|||||||
plugins {
|
plugins {
|
||||||
`kotlin-dsl`
|
`kotlin-dsl`
|
||||||
kotlin("plugin.serialization") version "1.5.21"
|
`version-catalog`
|
||||||
|
alias(npmlibs.plugins.kotlin.plugin.serialization)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
java.targetCompatibility = JavaVersion.VERSION_11
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
maven("https://repo.kotlin.link")
|
maven("https://repo.kotlin.link")
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
gradlePluginPortal()
|
gradlePluginPortal()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val toolsVersion: String by extra
|
||||||
|
val kotlinVersion = npmlibs.versions.kotlin.asProvider().get()
|
||||||
|
val benchmarksVersion = npmlibs.versions.kotlinx.benchmark.get()
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
api("org.jetbrains.kotlinx:kotlinx-serialization-json:1.2.2")
|
api("ru.mipt.npm:gradle-tools:$toolsVersion")
|
||||||
api("ru.mipt.npm:gradle-tools:0.10.7")
|
//plugins form benchmarks
|
||||||
api("org.jetbrains.kotlinx:kotlinx-benchmark-plugin:0.3.1")
|
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 {
|
kotlin.sourceSets.all {
|
||||||
languageSettings.useExperimentalAnnotation("kotlin.ExperimentalStdlibApi")
|
languageSettings.optIn("kotlin.OptIn")
|
||||||
}
|
}
|
||||||
|
14
buildSrc/gradle.properties
Normal file
14
buildSrc/gradle.properties
Normal file
@ -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
|
24
buildSrc/settings.gradle.kts
Normal file
24
buildSrc/settings.gradle.kts
Normal file
@ -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")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -6,12 +6,15 @@
|
|||||||
package space.kscience.kmath.benchmarks
|
package space.kscience.kmath.benchmarks
|
||||||
|
|
||||||
import kotlinx.benchmark.gradle.BenchmarksExtension
|
import kotlinx.benchmark.gradle.BenchmarksExtension
|
||||||
import kotlinx.serialization.*
|
import kotlinx.serialization.decodeFromString
|
||||||
import kotlinx.serialization.json.*
|
import kotlinx.serialization.json.Json
|
||||||
import org.gradle.api.Project
|
import org.gradle.api.Project
|
||||||
import ru.mipt.npm.gradle.KScienceReadmeExtension
|
import ru.mipt.npm.gradle.KScienceReadmeExtension
|
||||||
import java.time.*
|
import java.time.LocalDateTime
|
||||||
import java.time.format.*
|
import java.time.ZoneId
|
||||||
|
import java.time.format.DateTimeFormatter
|
||||||
|
import java.time.format.DateTimeFormatterBuilder
|
||||||
|
import java.time.format.SignStyle
|
||||||
import java.time.temporal.ChronoField.*
|
import java.time.temporal.ChronoField.*
|
||||||
|
|
||||||
private val ISO_DATE_TIME: DateTimeFormatter = DateTimeFormatterBuilder().run {
|
private val ISO_DATE_TIME: DateTimeFormatter = DateTimeFormatterBuilder().run {
|
||||||
@ -47,7 +50,7 @@ fun Project.addBenchmarkProperties() {
|
|||||||
rootProject.subprojects.forEach { p ->
|
rootProject.subprojects.forEach { p ->
|
||||||
p.extensions.findByType(KScienceReadmeExtension::class.java)?.run {
|
p.extensions.findByType(KScienceReadmeExtension::class.java)?.run {
|
||||||
benchmarksProject.extensions.findByType(BenchmarksExtension::class.java)?.configurations?.forEach { cfg ->
|
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 launches = benchmarksProject.buildDir.resolve("reports/benchmarks/${cfg.name}")
|
||||||
|
|
||||||
val resDirectory = launches.listFiles()?.maxByOrNull {
|
val resDirectory = launches.listFiles()?.maxByOrNull {
|
||||||
|
@ -7,7 +7,7 @@ package space.kscience.kmath.stat
|
|||||||
|
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
import space.kscience.kmath.chains.Chain
|
import space.kscience.kmath.chains.Chain
|
||||||
import space.kscience.kmath.chains.collectWithState
|
import space.kscience.kmath.chains.combineWithState
|
||||||
import space.kscience.kmath.distributions.NormalDistribution
|
import space.kscience.kmath.distributions.NormalDistribution
|
||||||
|
|
||||||
private data class AveragingChainState(var num: Int = 0, var value: Double = 0.0)
|
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.
|
* Averaging.
|
||||||
*/
|
*/
|
||||||
private fun Chain<Double>.mean(): Chain<Double> = collectWithState(AveragingChainState(), { it.copy() }) { chain ->
|
private fun Chain<Double>.mean(): Chain<Double> = combineWithState(AveragingChainState(), { it.copy() }) { chain ->
|
||||||
val next = chain.next()
|
val next = chain.next()
|
||||||
num++
|
num++
|
||||||
value += next
|
value += next
|
||||||
return@collectWithState value / num
|
return@combineWithState value / num
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,11 +6,9 @@
|
|||||||
kotlin.code.style=official
|
kotlin.code.style=official
|
||||||
kotlin.mpp.stability.nowarn=true
|
kotlin.mpp.stability.nowarn=true
|
||||||
|
|
||||||
#kotlin.mpp.enableGranularSourceSetsMetadata=true
|
|
||||||
#kotlin.native.enableDependencyPropagation=false
|
|
||||||
|
|
||||||
kotlin.jupyter.add.scanner=false
|
kotlin.jupyter.add.scanner=false
|
||||||
|
|
||||||
org.gradle.configureondemand=true
|
org.gradle.configureondemand=true
|
||||||
org.gradle.jvmargs=-XX:MaxMetaspaceSize=2G
|
|
||||||
org.gradle.parallel=true
|
org.gradle.parallel=true
|
||||||
|
|
||||||
|
toolsVersion=0.10.9-kotlin-1.6.10
|
||||||
|
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@ -1,5 +1,5 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
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
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
@ -10,6 +10,7 @@ import kotlinx.coroutines.flow.FlowCollector
|
|||||||
import kotlinx.coroutines.flow.flow
|
import kotlinx.coroutines.flow.flow
|
||||||
import kotlinx.coroutines.sync.Mutex
|
import kotlinx.coroutines.sync.Mutex
|
||||||
import kotlinx.coroutines.sync.withLock
|
import kotlinx.coroutines.sync.withLock
|
||||||
|
import space.kscience.kmath.misc.UnstableKMathAPI
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A not-necessary-Markov chain of some type
|
* A not-necessary-Markov chain of some type
|
||||||
@ -124,20 +125,22 @@ public fun <T> Chain<T>.filter(block: (T) -> Boolean): Chain<T> = object : Chain
|
|||||||
/**
|
/**
|
||||||
* Map the whole chain
|
* Map the whole chain
|
||||||
*/
|
*/
|
||||||
public fun <T, R> Chain<T>.collect(mapper: suspend (Chain<T>) -> R): Chain<R> = object : Chain<R> {
|
@UnstableKMathAPI
|
||||||
override suspend fun next(): R = mapper(this@collect)
|
public fun <T, R> Chain<T>.combine(mapper: suspend (Chain<T>) -> R): Chain<R> = object : Chain<R> {
|
||||||
override suspend fun fork(): Chain<R> = this@collect.fork().collect(mapper)
|
override suspend fun next(): R = mapper(this@combine)
|
||||||
|
override suspend fun fork(): Chain<R> = this@combine.fork().combine(mapper)
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun <T, S, R> Chain<T>.collectWithState(
|
@UnstableKMathAPI
|
||||||
|
public fun <T, S, R> Chain<T>.combineWithState(
|
||||||
state: S,
|
state: S,
|
||||||
stateFork: (S) -> S,
|
stateFork: (S) -> S,
|
||||||
mapper: suspend S.(Chain<T>) -> R,
|
mapper: suspend S.(Chain<T>) -> R,
|
||||||
): Chain<R> = object : Chain<R> {
|
): Chain<R> = object : Chain<R> {
|
||||||
override suspend fun next(): R = state.mapper(this@collectWithState)
|
override suspend fun next(): R = state.mapper(this@combineWithState)
|
||||||
|
|
||||||
override suspend fun fork(): Chain<R> =
|
override suspend fun fork(): Chain<R> =
|
||||||
this@collectWithState.fork().collectWithState(stateFork(state), stateFork, mapper)
|
this@combineWithState.fork().combineWithState(stateFork(state), stateFork, mapper)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -7,8 +7,11 @@ package space.kscience.kmath.stat
|
|||||||
|
|
||||||
import kotlinx.coroutines.flow.first
|
import kotlinx.coroutines.flow.first
|
||||||
import space.kscience.kmath.chains.Chain
|
import space.kscience.kmath.chains.Chain
|
||||||
import space.kscience.kmath.chains.collect
|
import space.kscience.kmath.chains.combine
|
||||||
import space.kscience.kmath.structures.*
|
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
|
import kotlin.jvm.JvmName
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -36,7 +39,7 @@ public fun <T : Any> Sampler<T>.sampleBuffer(
|
|||||||
//creating temporary storage once
|
//creating temporary storage once
|
||||||
val tmp = ArrayList<T>(size)
|
val tmp = ArrayList<T>(size)
|
||||||
|
|
||||||
return sample(generator).collect { chain ->
|
return sample(generator).combine { chain ->
|
||||||
//clear list from previous run
|
//clear list from previous run
|
||||||
tmp.clear()
|
tmp.clear()
|
||||||
//Fill list
|
//Fill list
|
||||||
|
@ -14,7 +14,7 @@ import space.kscience.kmath.operations.ExtendedFieldOps
|
|||||||
import space.kscience.kmath.operations.NumbersAddOps
|
import space.kscience.kmath.operations.NumbersAddOps
|
||||||
import space.kscience.kmath.operations.PowerOperations
|
import space.kscience.kmath.operations.PowerOperations
|
||||||
|
|
||||||
@OptIn(UnstableKMathAPI::class)
|
@OptIn(UnstableKMathAPI::class, PerformancePitfall::class)
|
||||||
@Suppress("OVERRIDE_BY_INLINE", "NOTHING_TO_INLINE")
|
@Suppress("OVERRIDE_BY_INLINE", "NOTHING_TO_INLINE")
|
||||||
public open class ViktorFieldOpsND :
|
public open class ViktorFieldOpsND :
|
||||||
FieldOpsND<Double, DoubleField>,
|
FieldOpsND<Double, DoubleField>,
|
||||||
|
@ -1,20 +1,23 @@
|
|||||||
pluginManagement {
|
rootProject.name = "kmath"
|
||||||
|
|
||||||
|
enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")
|
||||||
|
enableFeaturePreview("VERSION_CATALOGS")
|
||||||
|
|
||||||
|
dependencyResolutionManagement {
|
||||||
|
|
||||||
|
val toolsVersion: String by extra
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
maven("https://repo.kotlin.link")
|
maven("https://repo.kotlin.link")
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
gradlePluginPortal()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val kotlinVersion = "1.6.0"
|
versionCatalogs {
|
||||||
|
create("npmlibs") {
|
||||||
plugins {
|
from("ru.mipt.npm:version-catalog:$toolsVersion")
|
||||||
id("org.jetbrains.kotlinx.benchmark") version "0.3.1"
|
}
|
||||||
kotlin("multiplatform") version kotlinVersion
|
|
||||||
kotlin("plugin.allopen") version kotlinVersion
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rootProject.name = "kmath"
|
|
||||||
|
|
||||||
include(
|
include(
|
||||||
":kmath-memory",
|
":kmath-memory",
|
||||||
|
Loading…
Reference in New Issue
Block a user