From 0f634688cc4ed5cba39596a4c72b58e30fec4d2f Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sat, 2 Oct 2021 15:56:57 +0300 Subject: [PATCH] API cleanup --- gradle.properties | 6 ++- .../DoubleBufferOperations.kt} | 48 +++++++++---------- .../kmath/operations/OptionalOperations.kt | 4 +- .../kscience/kmath/ejml/EjmlLinearSpace.kt | 4 +- .../space/kscience/kmath/real/RealVector.kt | 7 +-- 5 files changed, 37 insertions(+), 32 deletions(-) rename kmath-core/src/commonMain/kotlin/space/kscience/kmath/{structures/DoubleBufferField.kt => operations/DoubleBufferOperations.kt} (89%) diff --git a/gradle.properties b/gradle.properties index 49bbf36dd..959511c68 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,9 +4,11 @@ # kotlin.code.style=official -kotlin.mpp.enableGranularSourceSetsMetadata=true kotlin.mpp.stability.nowarn=true -kotlin.native.enableDependencyPropagation=false + +#kotlin.mpp.enableGranularSourceSetsMetadata=true +#kotlin.native.enableDependencyPropagation=false + kotlin.jupyter.add.scanner=false org.gradle.configureondemand=true diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/DoubleBufferField.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/DoubleBufferOperations.kt similarity index 89% rename from kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/DoubleBufferField.kt rename to kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/DoubleBufferOperations.kt index 2bf6de3cb..a95bd2541 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/DoubleBufferField.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/DoubleBufferOperations.kt @@ -3,18 +3,18 @@ * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ -package space.kscience.kmath.structures +package space.kscience.kmath.operations import space.kscience.kmath.linear.Point -import space.kscience.kmath.misc.UnstableKMathAPI -import space.kscience.kmath.operations.* +import space.kscience.kmath.structures.Buffer +import space.kscience.kmath.structures.DoubleBuffer +import space.kscience.kmath.structures.fold import kotlin.math.* /** * [ExtendedFieldOperations] over [DoubleBuffer]. */ -@Deprecated("To be replaced by generic BufferAlgebra") -public object DoubleBufferFieldOperations : ExtendedFieldOperations> { +public object DoubleBufferOperations : ExtendedFieldOperations> { override fun Buffer.unaryMinus(): DoubleBuffer = if (this is DoubleBuffer) { DoubleBuffer(size) { -array[it] } } else { @@ -179,13 +179,13 @@ public class DoubleBufferField(public val size: Int) : ExtendedField = DoubleBuffer(size) { value.toDouble() } - override fun Buffer.unaryMinus(): Buffer = DoubleBufferFieldOperations.run { + override fun Buffer.unaryMinus(): Buffer = DoubleBufferOperations.run { -this@unaryMinus } override fun add(a: Buffer, b: Buffer): DoubleBuffer { require(a.size == size) { "The buffer size ${a.size} does not match context size $size" } - return DoubleBufferFieldOperations.add(a, b) + return DoubleBufferOperations.add(a, b) } override fun scale(a: Buffer, value: Double): DoubleBuffer { @@ -199,87 +199,87 @@ public class DoubleBufferField(public val size: Int) : ExtendedField, b: Buffer): DoubleBuffer { require(a.size == size) { "The buffer size ${a.size} does not match context size $size" } - return DoubleBufferFieldOperations.multiply(a, b) + return DoubleBufferOperations.multiply(a, b) } override fun divide(a: Buffer, b: Buffer): DoubleBuffer { require(a.size == size) { "The buffer size ${a.size} does not match context size $size" } - return DoubleBufferFieldOperations.divide(a, b) + return DoubleBufferOperations.divide(a, b) } override fun sin(arg: Buffer): DoubleBuffer { require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } - return DoubleBufferFieldOperations.sin(arg) + return DoubleBufferOperations.sin(arg) } override fun cos(arg: Buffer): DoubleBuffer { require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } - return DoubleBufferFieldOperations.cos(arg) + return DoubleBufferOperations.cos(arg) } override fun tan(arg: Buffer): DoubleBuffer { require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } - return DoubleBufferFieldOperations.tan(arg) + return DoubleBufferOperations.tan(arg) } override fun asin(arg: Buffer): DoubleBuffer { require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } - return DoubleBufferFieldOperations.asin(arg) + return DoubleBufferOperations.asin(arg) } override fun acos(arg: Buffer): DoubleBuffer { require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } - return DoubleBufferFieldOperations.acos(arg) + return DoubleBufferOperations.acos(arg) } override fun atan(arg: Buffer): DoubleBuffer { require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } - return DoubleBufferFieldOperations.atan(arg) + return DoubleBufferOperations.atan(arg) } override fun sinh(arg: Buffer): DoubleBuffer { require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } - return DoubleBufferFieldOperations.sinh(arg) + return DoubleBufferOperations.sinh(arg) } override fun cosh(arg: Buffer): DoubleBuffer { require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } - return DoubleBufferFieldOperations.cosh(arg) + return DoubleBufferOperations.cosh(arg) } override fun tanh(arg: Buffer): DoubleBuffer { require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } - return DoubleBufferFieldOperations.tanh(arg) + return DoubleBufferOperations.tanh(arg) } override fun asinh(arg: Buffer): DoubleBuffer { require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } - return DoubleBufferFieldOperations.asinh(arg) + return DoubleBufferOperations.asinh(arg) } override fun acosh(arg: Buffer): DoubleBuffer { require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } - return DoubleBufferFieldOperations.acosh(arg) + return DoubleBufferOperations.acosh(arg) } override fun atanh(arg: Buffer): DoubleBuffer { require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } - return DoubleBufferFieldOperations.atanh(arg) + return DoubleBufferOperations.atanh(arg) } override fun power(arg: Buffer, pow: Number): DoubleBuffer { require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } - return DoubleBufferFieldOperations.power(arg, pow) + return DoubleBufferOperations.power(arg, pow) } override fun exp(arg: Buffer): DoubleBuffer { require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } - return DoubleBufferFieldOperations.exp(arg) + return DoubleBufferOperations.exp(arg) } override fun ln(arg: Buffer): DoubleBuffer { require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } - return DoubleBufferFieldOperations.ln(arg) + return DoubleBufferOperations.ln(arg) } override fun norm(arg: Buffer): Double = DoubleL2Norm.norm(arg) diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/OptionalOperations.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/OptionalOperations.kt index 7f44eda49..3a2703c54 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/OptionalOperations.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/OptionalOperations.kt @@ -306,14 +306,14 @@ public fun >> tanh(arg: T): T */ @UnstableKMathAPI @Deprecated("AlgebraElements are considered odd and will be removed in future releases.") -public fun >> asinh(arg: T): T = arg.context.asinh(arg) +public fun >> asinh(arg: T): T = arg.context.asinh(arg) /** * Computes the inverse hyperbolic cosine of [arg]. */ @UnstableKMathAPI @Deprecated("AlgebraElements are considered odd and will be removed in future releases.") -public fun >> acosh(arg: T): T = arg.context.acosh(arg) +public fun >> acosh(arg: T): T = arg.context.acosh(arg) /** * Computes the inverse hyperbolic tangent of [arg]. diff --git a/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/EjmlLinearSpace.kt b/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/EjmlLinearSpace.kt index 4a53af60d..25333157a 100644 --- a/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/EjmlLinearSpace.kt +++ b/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/EjmlLinearSpace.kt @@ -40,6 +40,8 @@ public abstract class EjmlLinearSpace, out M : org.ejml public abstract override fun buildVector(size: Int, initializer: A.(Int) -> T): EjmlVector + @Suppress("UNCHECKED_CAST") @UnstableKMathAPI - public fun EjmlMatrix.inverse(): Structure2D = computeFeature(this, InverseMatrixFeature::class)?.inverse as Structure2D + public fun EjmlMatrix.inverse(): Structure2D = + computeFeature(this, InverseMatrixFeature::class)?.inverse as Structure2D } diff --git a/kmath-for-real/src/commonMain/kotlin/space/kscience/kmath/real/RealVector.kt b/kmath-for-real/src/commonMain/kotlin/space/kscience/kmath/real/RealVector.kt index b707ebfc5..cca1c3551 100644 --- a/kmath-for-real/src/commonMain/kotlin/space/kscience/kmath/real/RealVector.kt +++ b/kmath-for-real/src/commonMain/kotlin/space/kscience/kmath/real/RealVector.kt @@ -7,11 +7,12 @@ package space.kscience.kmath.real import space.kscience.kmath.linear.Point import space.kscience.kmath.misc.UnstableKMathAPI -import space.kscience.kmath.operations.Norm -import space.kscience.kmath.structures.* +import space.kscience.kmath.operations.DoubleL2Norm +import space.kscience.kmath.structures.Buffer import space.kscience.kmath.structures.MutableBuffer.Companion.double +import space.kscience.kmath.structures.asBuffer +import space.kscience.kmath.structures.indices import kotlin.math.pow -import kotlin.math.sqrt public typealias DoubleVector = Point