Move attributes to separate project

This commit is contained in:
Alexander Nozik 2025-01-12 11:40:07 +03:00
parent 5c8e50c3df
commit da9608128b
7 changed files with 0 additions and 413 deletions

View File

@ -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")
}
```

View File

@ -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<T>(public val type: SafeType<T>) : Attribute<T> {
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 <T> Attributes.get(attributeKeyBuilder: () -> PolymorphicAttribute<T>): T? =
get(attributeKeyBuilder())
/**
* Set a polymorphic attribute using its factory
*/
@UnstableAttributesAPI
public operator fun <O, T> AttributesBuilder<O>.set(attributeKeyBuilder: () -> PolymorphicAttribute<T>, value: T) {
set(attributeKeyBuilder(), value)
}

View File

@ -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<out T> @PublishedApi internal constructor(public val kType: KType)
public inline fun <reified T> safeTypeOf(): SafeType<T> = SafeType(typeOf<T>())
/**
* Derive Kotlin [KClass] from this type and fail if the type is not a class (should not happen)
*/
@Suppress("UNCHECKED_CAST")
@UnstableAttributesAPI
public val <T> SafeType<T>.kClass: KClass<T & Any> get() = kType.classifier as KClass<T & Any>
/**
* An interface containing [type] for dynamic type checking.
*/
public interface WithType<out T> {
public val type: SafeType<T>
}

View File

@ -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**.

View File

@ -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;
}

View File

@ -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}

View File

@ -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<Float64>, Norm<Double, Double>, ScaleOperations<Float64> {
override val bufferFactory: MutableBufferFactory<Float64> 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<ExtendedField>.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<Float64>, Norm<Double, Double>, ScaleOperations<Float64> {
override val bufferFactory: MutableBufferFactory<Float64> 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<ExtendedField>.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
}