From da9608128b2ef17b2014e54fa5ff2667ad36d66a Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sun, 12 Jan 2025 11:40:07 +0300 Subject: [PATCH] Move attributes to separate project --- attributes-kt/README.md | 21 --- .../attributes/PolymorphicAttribute.kt | 34 ----- .../space/kscience/attributes/SafeType.kt | 35 ----- kmath-jafama/README.md | 45 ------ kmath-jafama/api/kmath-jafama.api | 128 ------------------ kmath-jafama/docs/README-TEMPLATE.md | 30 ---- .../kscience/kmath/jafama/KMathJafama.kt | 120 ---------------- 7 files changed, 413 deletions(-) delete mode 100644 attributes-kt/README.md delete mode 100644 attributes-kt/src/commonMain/kotlin/space/kscience/attributes/PolymorphicAttribute.kt delete mode 100644 attributes-kt/src/commonMain/kotlin/space/kscience/attributes/SafeType.kt delete mode 100644 kmath-jafama/README.md delete mode 100644 kmath-jafama/api/kmath-jafama.api delete mode 100644 kmath-jafama/docs/README-TEMPLATE.md delete mode 100644 kmath-jafama/src/main/kotlin/space/kscience/kmath/jafama/KMathJafama.kt diff --git a/attributes-kt/README.md b/attributes-kt/README.md deleted file mode 100644 index 96d273d5b..000000000 --- a/attributes-kt/README.md +++ /dev/null @@ -1,21 +0,0 @@ -# Module attributes-kt - - - -## Usage - -## Artifact: - -The Maven coordinates of this project are `space.kscience:attributes-kt:0.1.0`. - -**Gradle Kotlin DSL:** -```kotlin -repositories { - maven("https://repo.kotlin.link") - mavenCentral() -} - -dependencies { - implementation("space.kscience:attributes-kt:0.1.0") -} -``` diff --git a/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/PolymorphicAttribute.kt b/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/PolymorphicAttribute.kt deleted file mode 100644 index e81d88e46..000000000 --- a/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/PolymorphicAttribute.kt +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2018-2023 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. - */ - -package space.kscience.attributes - -/** - * An attribute that has a type parameter for value - * @param type parameter-type - */ -public abstract class PolymorphicAttribute(public val type: SafeType) : Attribute { - override fun equals(other: Any?): Boolean = other != null && - (this::class == other::class) && - (other as? PolymorphicAttribute<*>)?.type == this.type - - override fun hashCode(): Int = this::class.hashCode() + type.hashCode() -} - - -/** - * Get a polymorphic attribute using attribute factory - */ -@UnstableAttributesAPI -public operator fun Attributes.get(attributeKeyBuilder: () -> PolymorphicAttribute): T? = - get(attributeKeyBuilder()) - -/** - * Set a polymorphic attribute using its factory - */ -@UnstableAttributesAPI -public operator fun AttributesBuilder.set(attributeKeyBuilder: () -> PolymorphicAttribute, value: T) { - set(attributeKeyBuilder(), value) -} diff --git a/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/SafeType.kt b/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/SafeType.kt deleted file mode 100644 index b76589164..000000000 --- a/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/SafeType.kt +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2018-2023 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. - */ - -package space.kscience.attributes - -import kotlin.jvm.JvmInline -import kotlin.reflect.KClass -import kotlin.reflect.KType -import kotlin.reflect.typeOf - -/** - * Safe variant ok Kotlin [KType] that ensures that the type parameter is of the same type as [kType] - * - * @param kType raw [KType] - */ -@JvmInline -public value class SafeType @PublishedApi internal constructor(public val kType: KType) - -public inline fun safeTypeOf(): SafeType = SafeType(typeOf()) - -/** - * Derive Kotlin [KClass] from this type and fail if the type is not a class (should not happen) - */ -@Suppress("UNCHECKED_CAST") -@UnstableAttributesAPI -public val SafeType.kClass: KClass get() = kType.classifier as KClass - -/** - * An interface containing [type] for dynamic type checking. - */ -public interface WithType { - public val type: SafeType -} \ No newline at end of file diff --git a/kmath-jafama/README.md b/kmath-jafama/README.md deleted file mode 100644 index 2f8f365c1..000000000 --- a/kmath-jafama/README.md +++ /dev/null @@ -1,45 +0,0 @@ -# Module kmath-jafama - -Integration with [Jafama](https://github.com/jeffhain/jafama). - - - [jafama-double](src/main/kotlin/space/kscience/kmath/jafama/) : Double ExtendedField implementations based on Jafama - - -## Artifact: - -The Maven coordinates of this project are `space.kscience:kmath-jafama:0.4.0`. - -**Gradle Kotlin DSL:** -```kotlin -repositories { - maven("https://repo.kotlin.link") - mavenCentral() -} - -dependencies { - implementation("space.kscience:kmath-jafama:0.4.0") -} -``` - -## Example usage - -All the `DoubleField` uses can be replaced with `JafamaDoubleField` or `StrictJafamaDoubleField`. - -```kotlin -import space.kscience.kmath.jafama.* -import space.kscience.kmath.operations.* - -fun main() { - val a = 2.0 - val b = StrictJafamaDoubleField { exp(a) } - println(JafamaDoubleField { b + a }) - println(StrictJafamaDoubleField { ln(b) }) -} -``` - -## Performance - -According to KMath benchmarks on GraalVM, Jafama functions are slower than JDK math; however, there are indications that -on Hotspot Jafama is a bit faster. - -> **Can't find appropriate benchmark data. Try generating readme files after running benchmarks**. diff --git a/kmath-jafama/api/kmath-jafama.api b/kmath-jafama/api/kmath-jafama.api deleted file mode 100644 index 989634e9b..000000000 --- a/kmath-jafama/api/kmath-jafama.api +++ /dev/null @@ -1,128 +0,0 @@ -public final class space/kscience/kmath/jafama/JafamaDoubleField : space/kscience/kmath/operations/ExtendedField, space/kscience/kmath/operations/Norm, space/kscience/kmath/operations/ScaleOperations { - public static final field INSTANCE Lspace/kscience/kmath/jafama/JafamaDoubleField; - public fun acos (D)Ljava/lang/Double; - public synthetic fun acos (Ljava/lang/Object;)Ljava/lang/Object; - public fun acosh (D)Ljava/lang/Double; - public synthetic fun acosh (Ljava/lang/Object;)Ljava/lang/Object; - public fun add (DD)Ljava/lang/Double; - public synthetic fun add (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun asin (D)Ljava/lang/Double; - public synthetic fun asin (Ljava/lang/Object;)Ljava/lang/Object; - public fun asinh (D)Ljava/lang/Double; - public synthetic fun asinh (Ljava/lang/Object;)Ljava/lang/Object; - public fun atan (D)Ljava/lang/Double; - public synthetic fun atan (Ljava/lang/Object;)Ljava/lang/Object; - public fun atanh (D)Ljava/lang/Double; - public synthetic fun atanh (Ljava/lang/Object;)Ljava/lang/Object; - public fun binaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; - public fun cos (D)Ljava/lang/Double; - public synthetic fun cos (Ljava/lang/Object;)Ljava/lang/Object; - public fun cosh (D)Ljava/lang/Double; - public synthetic fun cosh (Ljava/lang/Object;)Ljava/lang/Object; - public fun div (DD)Ljava/lang/Double; - public synthetic fun div (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun divide (DD)Ljava/lang/Double; - public synthetic fun divide (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun exp (D)Ljava/lang/Double; - public synthetic fun exp (Ljava/lang/Object;)Ljava/lang/Object; - public fun getBufferFactory ()Lspace/kscience/kmath/structures/MutableBufferFactory; - public fun getOne ()Ljava/lang/Double; - public synthetic fun getOne ()Ljava/lang/Object; - public fun getZero ()Ljava/lang/Double; - public synthetic fun getZero ()Ljava/lang/Object; - public fun ln (D)Ljava/lang/Double; - public synthetic fun ln (Ljava/lang/Object;)Ljava/lang/Object; - public fun minus (DD)Ljava/lang/Double; - public synthetic fun minus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun multiply (DD)Ljava/lang/Double; - public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun norm (D)Ljava/lang/Double; - public synthetic fun norm (Ljava/lang/Object;)Ljava/lang/Object; - public fun number (Ljava/lang/Number;)Ljava/lang/Double; - public synthetic fun number (Ljava/lang/Number;)Ljava/lang/Object; - public fun plus (DD)Ljava/lang/Double; - public synthetic fun plus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun power (DLjava/lang/Number;)Ljava/lang/Double; - public synthetic fun power (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; - public fun scale (DD)Ljava/lang/Double; - public synthetic fun scale (Ljava/lang/Object;D)Ljava/lang/Object; - public fun sin (D)Ljava/lang/Double; - public synthetic fun sin (Ljava/lang/Object;)Ljava/lang/Object; - public fun sinh (D)Ljava/lang/Double; - public synthetic fun sinh (Ljava/lang/Object;)Ljava/lang/Object; - public fun sqrt (D)Ljava/lang/Double; - public synthetic fun sqrt (Ljava/lang/Object;)Ljava/lang/Object; - public fun tan (D)Ljava/lang/Double; - public synthetic fun tan (Ljava/lang/Object;)Ljava/lang/Object; - public fun tanh (D)Ljava/lang/Double; - public synthetic fun tanh (Ljava/lang/Object;)Ljava/lang/Object; - public fun times (DD)Ljava/lang/Double; - public synthetic fun times (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun unaryMinus (D)Ljava/lang/Double; - public synthetic fun unaryMinus (Ljava/lang/Object;)Ljava/lang/Object; -} - -public final class space/kscience/kmath/jafama/StrictJafamaDoubleField : space/kscience/kmath/operations/ExtendedField, space/kscience/kmath/operations/Norm, space/kscience/kmath/operations/ScaleOperations { - public static final field INSTANCE Lspace/kscience/kmath/jafama/StrictJafamaDoubleField; - public fun acos (D)Ljava/lang/Double; - public synthetic fun acos (Ljava/lang/Object;)Ljava/lang/Object; - public fun acosh (D)Ljava/lang/Double; - public synthetic fun acosh (Ljava/lang/Object;)Ljava/lang/Object; - public fun add (DD)Ljava/lang/Double; - public synthetic fun add (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun asin (D)Ljava/lang/Double; - public synthetic fun asin (Ljava/lang/Object;)Ljava/lang/Object; - public fun asinh (D)Ljava/lang/Double; - public synthetic fun asinh (Ljava/lang/Object;)Ljava/lang/Object; - public fun atan (D)Ljava/lang/Double; - public synthetic fun atan (Ljava/lang/Object;)Ljava/lang/Object; - public fun atanh (D)Ljava/lang/Double; - public synthetic fun atanh (Ljava/lang/Object;)Ljava/lang/Object; - public fun binaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; - public fun cos (D)Ljava/lang/Double; - public synthetic fun cos (Ljava/lang/Object;)Ljava/lang/Object; - public fun cosh (D)Ljava/lang/Double; - public synthetic fun cosh (Ljava/lang/Object;)Ljava/lang/Object; - public fun div (DD)Ljava/lang/Double; - public synthetic fun div (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun divide (DD)Ljava/lang/Double; - public synthetic fun divide (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun exp (D)Ljava/lang/Double; - public synthetic fun exp (Ljava/lang/Object;)Ljava/lang/Object; - public fun getBufferFactory ()Lspace/kscience/kmath/structures/MutableBufferFactory; - public fun getOne ()Ljava/lang/Double; - public synthetic fun getOne ()Ljava/lang/Object; - public fun getZero ()Ljava/lang/Double; - public synthetic fun getZero ()Ljava/lang/Object; - public fun ln (D)Ljava/lang/Double; - public synthetic fun ln (Ljava/lang/Object;)Ljava/lang/Object; - public fun minus (DD)Ljava/lang/Double; - public synthetic fun minus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun multiply (DD)Ljava/lang/Double; - public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun norm (D)Ljava/lang/Double; - public synthetic fun norm (Ljava/lang/Object;)Ljava/lang/Object; - public fun number (Ljava/lang/Number;)Ljava/lang/Double; - public synthetic fun number (Ljava/lang/Number;)Ljava/lang/Object; - public fun plus (DD)Ljava/lang/Double; - public synthetic fun plus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun power (DLjava/lang/Number;)Ljava/lang/Double; - public synthetic fun power (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; - public fun scale (DD)Ljava/lang/Double; - public synthetic fun scale (Ljava/lang/Object;D)Ljava/lang/Object; - public fun sin (D)Ljava/lang/Double; - public synthetic fun sin (Ljava/lang/Object;)Ljava/lang/Object; - public fun sinh (D)Ljava/lang/Double; - public synthetic fun sinh (Ljava/lang/Object;)Ljava/lang/Object; - public fun sqrt (D)Ljava/lang/Double; - public synthetic fun sqrt (Ljava/lang/Object;)Ljava/lang/Object; - public fun tan (D)Ljava/lang/Double; - public synthetic fun tan (Ljava/lang/Object;)Ljava/lang/Object; - public fun tanh (D)Ljava/lang/Double; - public synthetic fun tanh (Ljava/lang/Object;)Ljava/lang/Object; - public fun times (DD)Ljava/lang/Double; - public synthetic fun times (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun unaryMinus (D)Ljava/lang/Double; - public synthetic fun unaryMinus (Ljava/lang/Object;)Ljava/lang/Object; -} - diff --git a/kmath-jafama/docs/README-TEMPLATE.md b/kmath-jafama/docs/README-TEMPLATE.md deleted file mode 100644 index 2973fca3b..000000000 --- a/kmath-jafama/docs/README-TEMPLATE.md +++ /dev/null @@ -1,30 +0,0 @@ -# Module kmath-jafama - -Integration with [Jafama](https://github.com/jeffhain/jafama). - -${features} - -${artifact} - -## Example usage - -All the `DoubleField` uses can be replaced with `JafamaDoubleField` or `StrictJafamaDoubleField`. - -```kotlin -import space.kscience.kmath.jafama.* -import space.kscience.kmath.operations.* - -fun main() { - val a = 2.0 - val b = StrictJafamaDoubleField { exp(a) } - println(JafamaDoubleField { b + a }) - println(StrictJafamaDoubleField { ln(b) }) -} -``` - -## Performance - -According to KMath benchmarks on GraalVM, Jafama functions are slower than JDK math; however, there are indications that -on Hotspot Jafama is a bit faster. - -${benchmarkJafamaDouble} diff --git a/kmath-jafama/src/main/kotlin/space/kscience/kmath/jafama/KMathJafama.kt b/kmath-jafama/src/main/kotlin/space/kscience/kmath/jafama/KMathJafama.kt deleted file mode 100644 index 87eef4331..000000000 --- a/kmath-jafama/src/main/kotlin/space/kscience/kmath/jafama/KMathJafama.kt +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright 2018-2024 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. - */ - -package space.kscience.kmath.jafama - -import net.jafama.FastMath -import net.jafama.StrictFastMath -import space.kscience.kmath.operations.* -import space.kscience.kmath.structures.Float64 -import space.kscience.kmath.structures.MutableBufferFactory - -/** - * A field for [Double] (using FastMath) without boxing. Does not produce appropriate field element. - */ -@Suppress("EXTENSION_SHADOWED_BY_MEMBER", "OVERRIDE_BY_INLINE", "NOTHING_TO_INLINE") -public object JafamaDoubleField : ExtendedField, Norm, ScaleOperations { - - override val bufferFactory: MutableBufferFactory get() = DoubleField.bufferFactory - - override inline val zero: Double get() = 0.0 - override inline val one: Double get() = 1.0 - - override inline fun number(value: Number): Double = value.toDouble() - - override fun binaryOperationFunction(operation: String): (left: Double, right: Double) -> Double = - when (operation) { - PowerOperations.POW_OPERATION -> ::power - else -> super.binaryOperationFunction(operation) - } - - override inline fun add(left: Double, right: Double): Double = left + right - - override inline fun multiply(left: Double, right: Double): Double = left * right - override inline fun divide(left: Double, right: Double): Double = left / right - - override inline fun scale(a: Double, value: Double): Double = a * value - - override inline fun sin(arg: Double): Double = FastMath.sin(arg) - override inline fun cos(arg: Double): Double = FastMath.cos(arg) - override inline fun tan(arg: Double): Double = FastMath.tan(arg) - override inline fun acos(arg: Double): Double = FastMath.acos(arg) - override inline fun asin(arg: Double): Double = FastMath.asin(arg) - override inline fun atan(arg: Double): Double = FastMath.atan(arg) - - override inline fun sinh(arg: Double): Double = FastMath.sinh(arg) - override inline fun cosh(arg: Double): Double = FastMath.cosh(arg) - override inline fun tanh(arg: Double): Double = FastMath.tanh(arg) - override inline fun asinh(arg: Double): Double = FastMath.asinh(arg) - override inline fun acosh(arg: Double): Double = FastMath.acosh(arg) - override inline fun atanh(arg: Double): Double = FastMath.atanh(arg) - - override inline fun sqrt(arg: Double): Double = FastMath.sqrt(arg) - override inline fun power(arg: Double, pow: Number): Double = FastMath.pow(arg, pow.toDouble()) - override inline fun exp(arg: Double): Double = FastMath.exp(arg) - override inline fun ln(arg: Double): Double = FastMath.log(arg) - - override inline fun norm(arg: Double): Double = FastMath.abs(arg) - - override inline fun Double.unaryMinus(): Double = -this - override inline fun Double.plus(arg: Double): Double = this + arg - override inline fun Double.minus(arg: Double): Double = this - arg - override inline fun Double.times(arg: Double): Double = this * arg - override inline fun Double.div(arg: Double): Double = this / arg -} - -/** - * A field for [Double] (using StrictMath) without boxing. Does not produce appropriate field element. - */ -@Suppress("EXTENSION_SHADOWED_BY_MEMBER", "OVERRIDE_BY_INLINE", "NOTHING_TO_INLINE") -public object StrictJafamaDoubleField : ExtendedField, Norm, ScaleOperations { - - override val bufferFactory: MutableBufferFactory get() = DoubleField.bufferFactory - - override inline val zero: Double get() = 0.0 - override inline val one: Double get() = 1.0 - - override inline fun number(value: Number): Double = value.toDouble() - - override fun binaryOperationFunction(operation: String): (left: Double, right: Double) -> Double = - when (operation) { - PowerOperations.POW_OPERATION -> ::power - else -> super.binaryOperationFunction(operation) - } - - override inline fun add(left: Double, right: Double): Double = left + right - - override inline fun multiply(left: Double, right: Double): Double = left * right - override inline fun divide(left: Double, right: Double): Double = left / right - - override inline fun scale(a: Double, value: Double): Double = a * value - - override inline fun sin(arg: Double): Double = StrictFastMath.sin(arg) - override inline fun cos(arg: Double): Double = StrictFastMath.cos(arg) - override inline fun tan(arg: Double): Double = StrictFastMath.tan(arg) - override inline fun acos(arg: Double): Double = StrictFastMath.acos(arg) - override inline fun asin(arg: Double): Double = StrictFastMath.asin(arg) - override inline fun atan(arg: Double): Double = StrictFastMath.atan(arg) - - override inline fun sinh(arg: Double): Double = StrictFastMath.sinh(arg) - override inline fun cosh(arg: Double): Double = StrictFastMath.cosh(arg) - override inline fun tanh(arg: Double): Double = StrictFastMath.tanh(arg) - override inline fun asinh(arg: Double): Double = StrictFastMath.asinh(arg) - override inline fun acosh(arg: Double): Double = StrictFastMath.acosh(arg) - override inline fun atanh(arg: Double): Double = StrictFastMath.atanh(arg) - - override inline fun sqrt(arg: Double): Double = StrictFastMath.sqrt(arg) - override inline fun power(arg: Double, pow: Number): Double = StrictFastMath.pow(arg, pow.toDouble()) - override inline fun exp(arg: Double): Double = StrictFastMath.exp(arg) - override inline fun ln(arg: Double): Double = StrictFastMath.log(arg) - - override inline fun norm(arg: Double): Double = StrictFastMath.abs(arg) - - override inline fun Double.unaryMinus(): Double = -this - override inline fun Double.plus(arg: Double): Double = this + arg - override inline fun Double.minus(arg: Double): Double = this - arg - override inline fun Double.times(arg: Double): Double = this * arg - override inline fun Double.div(arg: Double): Double = this / arg -}