Merge branch 'dev' into gsl-experiment

This commit is contained in:
Iaroslav Postovalov 2021-02-06 23:12:38 +07:00
commit 49da84b223
No known key found for this signature in database
GPG Key ID: 46E15E4A31B3BCD7
3 changed files with 19 additions and 25 deletions

View File

@ -488,15 +488,9 @@ public final class kscience/kmath/expressions/StringSymbol : kscience/kmath/expr
}
public abstract interface class kscience/kmath/expressions/Symbol {
public static final field Companion Lkscience/kmath/expressions/Symbol$Companion;
public abstract fun getIdentity ()Ljava/lang/String;
}
public final class kscience/kmath/expressions/Symbol$Companion : kotlin/properties/ReadOnlyProperty {
public synthetic fun getValue (Ljava/lang/Object;Lkotlin/reflect/KProperty;)Ljava/lang/Object;
public fun getValue (Ljava/lang/Object;Lkotlin/reflect/KProperty;)Lkscience/kmath/expressions/Symbol;
}
public abstract interface class kscience/kmath/expressions/SymbolIndexer {
public abstract fun get (Ljava/util/List;Lkscience/kmath/expressions/Symbol;)Ljava/lang/Object;
public abstract fun get (Lkscience/kmath/nd/Structure2D;Lkscience/kmath/expressions/Symbol;Lkscience/kmath/expressions/Symbol;)Ljava/lang/Object;

View File

@ -3,7 +3,6 @@ package kscience.kmath.expressions
import kscience.kmath.operations.Algebra
import kotlin.jvm.JvmName
import kotlin.properties.ReadOnlyProperty
import kotlin.reflect.KProperty
/**
* A marker interface for a symbol. A symbol mus have an identity
@ -13,13 +12,6 @@ public interface Symbol {
* Identity object for the symbol. Two symbols with the same identity are considered to be the same symbol.
*/
public val identity: String
public companion object : ReadOnlyProperty<Any?, Symbol> {
//TODO deprecate and replace by top level function after fix of https://youtrack.jetbrains.com/issue/KT-40121
override fun getValue(thisRef: Any?, property: KProperty<*>): Symbol {
return StringSymbol(property.name)
}
}
}
/**
@ -103,9 +95,9 @@ public fun <T, E> ExpressionAlgebra<T, E>.bind(symbol: Symbol): E =
/**
* A delegate to create a symbol with a string identity in this scope
*/
public val symbol: ReadOnlyProperty<Any?, Symbol> get() = Symbol
//TODO does not work directly on native due to https://youtrack.jetbrains.com/issue/KT-40121
public val symbol: ReadOnlyProperty<Any?, Symbol> = ReadOnlyProperty { thisRef, property ->
StringSymbol(property.name)
}
/**
* Bind a symbol by name inside the [ExpressionAlgebra]

View File

@ -29,8 +29,10 @@ public inline fun RealVector.map(transform: (Double) -> Double): RealVector =
public inline fun RealVector.mapIndexed(transform: (index: Int, value: Double) -> Double): RealVector =
Buffer.real(size) { transform(it, get(it)) }
public operator fun RealVector.plus(other: RealVector): RealVector =
mapIndexed { index, value -> value + other[index] }
public operator fun RealVector.plus(other: RealVector): RealVector {
require(size == other.size){"Vector size $size expected but ${other.size} found"}
return mapIndexed { index, value -> value + other[index] }
}
public operator fun RealVector.plus(number: Number): RealVector = map { it + number.toDouble() }
@ -38,22 +40,28 @@ public operator fun Number.plus(vector: RealVector): RealVector = vector + this
public operator fun RealVector.unaryMinus(): Buffer<Double> = map { -it }
public operator fun RealVector.minus(other: RealVector): RealVector =
mapIndexed { index, value -> value - other[index] }
public operator fun RealVector.minus(other: RealVector): RealVector {
require(size == other.size){"Vector size $size expected but ${other.size} found"}
return mapIndexed { index, value -> value - other[index] }
}
public operator fun RealVector.minus(number: Number): RealVector = map { it - number.toDouble() }
public operator fun Number.minus(vector: RealVector): RealVector = vector.map { toDouble() - it }
public operator fun RealVector.times(other: RealVector): RealVector =
mapIndexed { index, value -> value * other[index] }
public operator fun RealVector.times(other: RealVector): RealVector {
require(size == other.size){"Vector size $size expected but ${other.size} found"}
return mapIndexed { index, value -> value * other[index] }
}
public operator fun RealVector.times(number: Number): RealVector = map { it * number.toDouble() }
public operator fun Number.times(vector: RealVector): RealVector = vector * this
public operator fun RealVector.div(other: RealVector): RealVector =
mapIndexed { index, value -> value / other[index] }
public operator fun RealVector.div(other: RealVector): RealVector {
require(size == other.size){"Vector size $size expected but ${other.size} found"}
return mapIndexed { index, value -> value / other[index] }
}
public operator fun RealVector.div(number: Number): RealVector = map { it / number.toDouble() }