forked from kscience/kmath
Merge branch 'dev' into gsl-experiment
This commit is contained in:
commit
49da84b223
@ -488,15 +488,9 @@ public final class kscience/kmath/expressions/StringSymbol : kscience/kmath/expr
|
|||||||
}
|
}
|
||||||
|
|
||||||
public abstract interface class kscience/kmath/expressions/Symbol {
|
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 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 interface class kscience/kmath/expressions/SymbolIndexer {
|
||||||
public abstract fun get (Ljava/util/List;Lkscience/kmath/expressions/Symbol;)Ljava/lang/Object;
|
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;
|
public abstract fun get (Lkscience/kmath/nd/Structure2D;Lkscience/kmath/expressions/Symbol;Lkscience/kmath/expressions/Symbol;)Ljava/lang/Object;
|
||||||
|
@ -3,7 +3,6 @@ package kscience.kmath.expressions
|
|||||||
import kscience.kmath.operations.Algebra
|
import kscience.kmath.operations.Algebra
|
||||||
import kotlin.jvm.JvmName
|
import kotlin.jvm.JvmName
|
||||||
import kotlin.properties.ReadOnlyProperty
|
import kotlin.properties.ReadOnlyProperty
|
||||||
import kotlin.reflect.KProperty
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A marker interface for a symbol. A symbol mus have an identity
|
* 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.
|
* Identity object for the symbol. Two symbols with the same identity are considered to be the same symbol.
|
||||||
*/
|
*/
|
||||||
public val identity: String
|
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
|
* A delegate to create a symbol with a string identity in this scope
|
||||||
*/
|
*/
|
||||||
public val symbol: ReadOnlyProperty<Any?, Symbol> get() = Symbol
|
public val symbol: ReadOnlyProperty<Any?, Symbol> = ReadOnlyProperty { thisRef, property ->
|
||||||
//TODO does not work directly on native due to https://youtrack.jetbrains.com/issue/KT-40121
|
StringSymbol(property.name)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bind a symbol by name inside the [ExpressionAlgebra]
|
* Bind a symbol by name inside the [ExpressionAlgebra]
|
||||||
|
@ -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 =
|
public inline fun RealVector.mapIndexed(transform: (index: Int, value: Double) -> Double): RealVector =
|
||||||
Buffer.real(size) { transform(it, get(it)) }
|
Buffer.real(size) { transform(it, get(it)) }
|
||||||
|
|
||||||
public operator fun RealVector.plus(other: RealVector): RealVector =
|
public operator fun RealVector.plus(other: RealVector): RealVector {
|
||||||
mapIndexed { index, value -> value + other[index] }
|
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() }
|
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.unaryMinus(): Buffer<Double> = map { -it }
|
||||||
|
|
||||||
public operator fun RealVector.minus(other: RealVector): RealVector =
|
public operator fun RealVector.minus(other: RealVector): RealVector {
|
||||||
mapIndexed { index, value -> value - other[index] }
|
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 RealVector.minus(number: Number): RealVector = map { it - number.toDouble() }
|
||||||
|
|
||||||
public operator fun Number.minus(vector: RealVector): RealVector = vector.map { toDouble() - it }
|
public operator fun Number.minus(vector: RealVector): RealVector = vector.map { toDouble() - it }
|
||||||
|
|
||||||
public operator fun RealVector.times(other: RealVector): RealVector =
|
public operator fun RealVector.times(other: RealVector): RealVector {
|
||||||
mapIndexed { index, value -> value * other[index] }
|
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 RealVector.times(number: Number): RealVector = map { it * number.toDouble() }
|
||||||
|
|
||||||
public operator fun Number.times(vector: RealVector): RealVector = vector * this
|
public operator fun Number.times(vector: RealVector): RealVector = vector * this
|
||||||
|
|
||||||
public operator fun RealVector.div(other: RealVector): RealVector =
|
public operator fun RealVector.div(other: RealVector): RealVector {
|
||||||
mapIndexed { index, value -> value / other[index] }
|
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() }
|
public operator fun RealVector.div(number: Number): RealVector = map { it / number.toDouble() }
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user