From 6581f3dd8a9579ee6da15533287c8e26add8b42d Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Fri, 19 Feb 2021 13:38:32 +0300 Subject: [PATCH] Cleanup --- build.gradle.kts | 2 +- examples/build.gradle.kts | 8 ++++++++ .../kscience/kmath/structures/StructureReadBenchmark.kt | 1 + .../kscience/kmath/structures/StructureWriteBenchmark.kt | 1 + .../kotlin/space/kscience/kmath/complex/Complex.kt | 3 +++ .../kotlin/space/kscience/kmath/complex/Quaternion.kt | 2 ++ .../kotlin/space/kscience/kmath/linear/BufferMatrix.kt | 2 +- .../kotlin/space/kscience/kmath/structures/RealBuffer.kt | 4 ++-- .../kotlin/space/kscience/kmath/streaming/BufferFlow.kt | 2 +- .../space/kscience/kmath/streaming/RingBufferTest.kt | 2 +- .../commonMain/kotlin/space/kscience/kmath/real/dot.kt | 2 +- .../space/kscience/kmath/histogram/RealHistogramSpace.kt | 2 +- settings.gradle.kts | 5 ++--- 13 files changed, 25 insertions(+), 11 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 783c9ca56..c77ad38b5 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -4,7 +4,7 @@ plugins { id("ru.mipt.npm.project") } -internal val kmathVersion: String by extra("0.2.0-dev-7") +internal val kmathVersion: String by extra("0.2.0") allprojects { repositories { diff --git a/examples/build.gradle.kts b/examples/build.gradle.kts index 5439d46dc..a1ffb32a3 100644 --- a/examples/build.gradle.kts +++ b/examples/build.gradle.kts @@ -69,6 +69,14 @@ benchmark { targets.register("benchmarks") // This one matches sourceSet name above + configurations.register("buffer") { + warmups = 1 // number of warmup iterations + iterations = 3 // number of iterations + iterationTime = 500 // time in seconds per iteration + iterationTimeUnit = "ms" // time unity for iterationTime, default is seconds + include("BufferBenchmark") + } + configurations.register("dot") { warmups = 1 // number of warmup iterations iterations = 3 // number of iterations diff --git a/examples/src/main/kotlin/space/kscience/kmath/structures/StructureReadBenchmark.kt b/examples/src/main/kotlin/space/kscience/kmath/structures/StructureReadBenchmark.kt index cfb3bdf7f..7f6d73394 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/structures/StructureReadBenchmark.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/structures/StructureReadBenchmark.kt @@ -4,6 +4,7 @@ import space.kscience.kmath.nd.DefaultStrides import space.kscience.kmath.nd.NDBuffer import kotlin.system.measureTimeMillis +@Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE") fun main() { val n = 6000 val array = DoubleArray(n * n) { 1.0 } diff --git a/examples/src/main/kotlin/space/kscience/kmath/structures/StructureWriteBenchmark.kt b/examples/src/main/kotlin/space/kscience/kmath/structures/StructureWriteBenchmark.kt index c0d97f9ab..13d6f00e4 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/structures/StructureWriteBenchmark.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/structures/StructureWriteBenchmark.kt @@ -4,6 +4,7 @@ import space.kscience.kmath.nd.NDStructure import space.kscience.kmath.nd.mapToBuffer import kotlin.system.measureTimeMillis +@Suppress("UNUSED_VARIABLE") fun main() { val n = 6000 val structure = NDStructure.build(intArrayOf(n, n), Buffer.Companion::auto) { 1.0 } diff --git a/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/Complex.kt b/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/Complex.kt index 6d2c04c39..deadfda5b 100644 --- a/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/Complex.kt +++ b/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/Complex.kt @@ -3,6 +3,7 @@ package space.kscience.kmath.complex import space.kscience.kmath.memory.MemoryReader import space.kscience.kmath.memory.MemorySpec import space.kscience.kmath.memory.MemoryWriter +import space.kscience.kmath.misc.UnstableKMathAPI import space.kscience.kmath.operations.ExtendedField import space.kscience.kmath.operations.FieldElement import space.kscience.kmath.operations.Norm @@ -45,6 +46,7 @@ private val PI_DIV_2 = Complex(PI / 2, 0) /** * A field of [Complex]. */ +@OptIn(UnstableKMathAPI::class) public object ComplexField : ExtendedField, Norm, RingWithNumbers { public override val zero: Complex = 0.0.toComplex() public override val one: Complex = 1.0.toComplex() @@ -166,6 +168,7 @@ public object ComplexField : ExtendedField, Norm, Rin * @property re The real part. * @property im The imaginary part. */ +@OptIn(UnstableKMathAPI::class) public data class Complex(val re: Double, val im: Double) : FieldElement { public constructor(re: Number, im: Number) : this(re.toDouble(), im.toDouble()) public constructor(re: Number) : this(re.toDouble(), 0.0) diff --git a/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/Quaternion.kt b/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/Quaternion.kt index 848ac728f..d72644abe 100644 --- a/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/Quaternion.kt +++ b/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/Quaternion.kt @@ -3,6 +3,7 @@ package space.kscience.kmath.complex import space.kscience.kmath.memory.MemoryReader import space.kscience.kmath.memory.MemorySpec import space.kscience.kmath.memory.MemoryWriter +import space.kscience.kmath.misc.UnstableKMathAPI import space.kscience.kmath.operations.* import space.kscience.kmath.structures.Buffer import space.kscience.kmath.structures.MemoryBuffer @@ -34,6 +35,7 @@ public val Quaternion.r: Double /** * A field of [Quaternion]. */ +@OptIn(UnstableKMathAPI::class) public object QuaternionField : Field, Norm, PowerOperations, ExponentialOperations, RingWithNumbers { override val zero: Quaternion = 0.toQuaternion() diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/BufferMatrix.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/BufferMatrix.kt index 63f6f77cd..f8f7f5a05 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/BufferMatrix.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/BufferMatrix.kt @@ -91,7 +91,7 @@ public class BufferMatrixContext>( public class BufferMatrix( public override val rowNum: Int, public override val colNum: Int, - public val buffer: Buffer, + public val buffer: Buffer, ) : Matrix { init { diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/RealBuffer.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/RealBuffer.kt index b06efb3fc..e53ed85c7 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/RealBuffer.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/RealBuffer.kt @@ -9,9 +9,9 @@ package space.kscience.kmath.structures public inline class RealBuffer(public val array: DoubleArray) : MutableBuffer { override val size: Int get() = array.size - override inline operator fun get(index: Int): Double = array[index] + override operator fun get(index: Int): Double = array[index] - override inline operator fun set(index: Int, value: Double) { + override operator fun set(index: Int, value: Double) { array[index] = value } diff --git a/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/streaming/BufferFlow.kt b/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/streaming/BufferFlow.kt index 262978306..4df22c2ad 100644 --- a/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/streaming/BufferFlow.kt +++ b/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/streaming/BufferFlow.kt @@ -17,7 +17,7 @@ public fun Buffer.asFlow(): Flow = iterator().asFlow() * Flat map a [Flow] of [Buffer] into continuous [Flow] of elements */ @FlowPreview -public fun Flow>.spread(): Flow = flatMapConcat { it.asFlow() } +public fun Flow>.spread(): Flow = flatMapConcat { it.asFlow() } /** * Collect incoming flow into fixed size chunks diff --git a/kmath-coroutines/src/jvmTest/kotlin/space/kscience/kmath/streaming/RingBufferTest.kt b/kmath-coroutines/src/jvmTest/kotlin/space/kscience/kmath/streaming/RingBufferTest.kt index 3d037cbf9..4a7109310 100644 --- a/kmath-coroutines/src/jvmTest/kotlin/space/kscience/kmath/streaming/RingBufferTest.kt +++ b/kmath-coroutines/src/jvmTest/kotlin/space/kscience/kmath/streaming/RingBufferTest.kt @@ -28,7 +28,7 @@ internal class RingBufferTest { val windowed = flow.windowed(10) runBlocking { - val first = windowed.take(1).single() + @Suppress("UNUSED_VARIABLE") val first = windowed.take(1).single() val res = windowed.take(15).map { it.asSequence().average() }.toList() assertEquals(0.0, res[0]) assertEquals(4.5, res[9]) diff --git a/kmath-for-real/src/commonMain/kotlin/space/kscience/kmath/real/dot.kt b/kmath-for-real/src/commonMain/kotlin/space/kscience/kmath/real/dot.kt index 68ce917fc..cbfb364c1 100644 --- a/kmath-for-real/src/commonMain/kotlin/space/kscience/kmath/real/dot.kt +++ b/kmath-for-real/src/commonMain/kotlin/space/kscience/kmath/real/dot.kt @@ -13,7 +13,7 @@ public infix fun BufferMatrix.dot(other: BufferMatrix): BufferMa val resultArray = DoubleArray(this.rowNum * other.colNum) //convert to array to insure there is no memory indirection - fun Buffer.unsafeArray() = if (this is RealBuffer) + fun Buffer.unsafeArray() = if (this is RealBuffer) this.array else DoubleArray(size) { get(it) } diff --git a/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/RealHistogramSpace.kt b/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/RealHistogramSpace.kt index 89d1a0723..26efdf1fe 100644 --- a/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/RealHistogramSpace.kt +++ b/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/RealHistogramSpace.kt @@ -70,7 +70,7 @@ public class RealHistogramSpace( val ndCounter = NDStructure.auto(strides) { Counter.real() } val hBuilder = HistogramBuilder { point, value -> val index = getIndex(point) - ndCounter[index].add(1.0) + ndCounter[index].add(value.toDouble()) } hBuilder.apply(builder) val values: NDBuffer = ndCounter.mapToBuffer { it.value } diff --git a/settings.gradle.kts b/settings.gradle.kts index 329bce8f9..c040f6e33 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -2,13 +2,12 @@ pluginManagement { repositories { gradlePluginPortal() jcenter() + maven("https://repo.kotlin.link") maven("https://dl.bintray.com/kotlin/kotlin-eap") - maven("https://dl.bintray.com/mipt-npm/kscience") - maven("https://dl.bintray.com/mipt-npm/dev") maven("https://dl.bintray.com/kotlin/kotlinx") } - val toolsVersion = "0.7.6" + val toolsVersion = "0.7.7" val kotlinVersion = "1.4.30" plugins {