v0.3.0-dev-9 #324

Merged
altavir merged 265 commits from dev into master 2021-05-08 17:16:29 +03:00
8 changed files with 35 additions and 68 deletions
Showing only changes of commit 6aa5b547b5 - Show all commits

View File

@ -32,6 +32,7 @@
- Number multiplication and division in main Algebra chain
- `contentEquals` from Buffer. It moved to the companion.
- MSTExpression
- Expression algebra builders
### Fixed
- Ring inherits RingOperations, not GroupOperations

View File

@ -45,13 +45,6 @@ public abstract interface class space/kscience/kmath/expressions/ExpressionAlgeb
public abstract fun const (Ljava/lang/Object;)Ljava/lang/Object;
}
public final class space/kscience/kmath/expressions/ExpressionBuildersKt {
public static final fun extendedFieldExpression (Lspace/kscience/kmath/operations/ExtendedField;Lkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/expressions/Expression;
public static final fun fieldExpression (Lspace/kscience/kmath/operations/Field;Lkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/expressions/Expression;
public static final fun ringExpression (Lspace/kscience/kmath/operations/Ring;Lkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/expressions/Expression;
public static final fun spaceExpression (Lspace/kscience/kmath/operations/Ring;Lkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/expressions/Expression;
}
public final class space/kscience/kmath/expressions/ExpressionKt {
public static final fun binding (Lspace/kscience/kmath/expressions/ExpressionAlgebra;)Lkotlin/properties/ReadOnlyProperty;
public static final fun callByString (Lspace/kscience/kmath/expressions/Expression;[Lkotlin/Pair;)Ljava/lang/Object;
@ -705,7 +698,11 @@ public final class space/kscience/kmath/misc/Symbol$Companion {
}
public final class space/kscience/kmath/misc/SymbolKt {
public static final fun get (Ljava/util/Map;Ljava/lang/String;)Ljava/lang/Object;
public static final fun get (Ljava/util/Map;Lspace/kscience/kmath/misc/Symbol;)Ljava/lang/Object;
public static final fun getSymbol ()Lkotlin/properties/ReadOnlyProperty;
public static final fun set (Ljava/util/Map;Ljava/lang/String;Ljava/lang/Object;)V
public static final fun set (Ljava/util/Map;Lspace/kscience/kmath/misc/Symbol;Ljava/lang/Object;)V
}
public abstract interface annotation class space/kscience/kmath/misc/UnstableKMathAPI : java/lang/annotation/Annotation {
@ -1209,7 +1206,6 @@ public abstract interface class space/kscience/kmath/operations/ExtendedField :
public fun acosh (Ljava/lang/Object;)Ljava/lang/Object;
public fun asinh (Ljava/lang/Object;)Ljava/lang/Object;
public fun atanh (Ljava/lang/Object;)Ljava/lang/Object;
public fun bindSymbol (Ljava/lang/String;)Ljava/lang/Object;
public fun cosh (Ljava/lang/Object;)Ljava/lang/Object;
public fun rightSideNumberOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2;
public fun sinh (Ljava/lang/Object;)Ljava/lang/Object;

View File

@ -33,12 +33,12 @@ public interface SymbolIndexer {
public operator fun DoubleArray.get(symbol: Symbol): Double {
require(size == symbols.size) { "The input array size for indexer should be ${symbols.size} but $size found" }
return get(this@SymbolIndexer.indexOf(symbol))
return get(indexOf(symbol))
}
public operator fun <T> Point<T>.get(symbol: Symbol): T {
require(size == symbols.size) { "The input buffer size for indexer should be ${symbols.size} but $size found" }
return get(this@SymbolIndexer.indexOf(symbol))
return get(indexOf(symbol))
}
public fun DoubleArray.toMap(): Map<Symbol, Double> {

View File

@ -1,45 +0,0 @@
/*
* Copyright 2018-2021 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.expressions
import space.kscience.kmath.operations.ExtendedField
import space.kscience.kmath.operations.Field
import space.kscience.kmath.operations.Ring
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract
/**
* Creates a functional expression with this [Ring].
*/
public inline fun <T> Ring<T>.spaceExpression(block: FunctionalExpressionGroup<T, Ring<T>>.() -> Expression<T>): Expression<T> {
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
return FunctionalExpressionGroup(this).block()
}
/**
* Creates a functional expression with this [Ring].
*/
public inline fun <T> Ring<T>.ringExpression(block: FunctionalExpressionRing<T, Ring<T>>.() -> Expression<T>): Expression<T> {
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
return FunctionalExpressionRing(this).block()
}
/**
* Creates a functional expression with this [Field].
*/
public inline fun <T> Field<T>.fieldExpression(block: FunctionalExpressionField<T, Field<T>>.() -> Expression<T>): Expression<T> {
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
return FunctionalExpressionField(this).block()
}
/**
* Creates a functional expression with this [ExtendedField].
*/
public inline fun <T> ExtendedField<T>.extendedFieldExpression(block: FunctionalExpressionExtendedField<T, ExtendedField<T>>.() -> Expression<T>): Expression<T> {
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
return FunctionalExpressionExtendedField(this).block()
}

View File

@ -32,10 +32,33 @@ public value class StringSymbol(override val identity: String) : Symbol {
override fun toString(): String = identity
}
/**
* A delegate to create a symbol with a string identity in this scope
*/
public val symbol: ReadOnlyProperty<Any?, Symbol> = ReadOnlyProperty { _, property ->
StringSymbol(property.name)
}
/**
* Ger a value from a [String]-keyed map by a [Symbol]
*/
public operator fun <T> Map<String, T>.get(symbol: Symbol): T? = get(symbol.identity)
/**
* Set a value of [String]-keyed map by a [Symbol]
*/
public operator fun <T> MutableMap<String, T>.set(symbol: Symbol, value: T){
set(symbol.identity, value)
}
/**
* Get a value from a [Symbol]-keyed map by a [String]
*/
public operator fun <T> Map<Symbol, T>.get(string: String): T? = get(StringSymbol(string))
/**
* Set a value of [String]-keyed map by a [Symbol]
*/
public operator fun <T> MutableMap<Symbol, T>.set(string: String, value: T){
set(StringSymbol(string), value)
}

View File

@ -44,9 +44,9 @@ public interface Algebra<T> {
/**
* Dynamically dispatches an unary operation with the certain name.
*
* This function must follow two properties:
* This function must has two features:
*
* 1. In case if operation is not defined in the structure, the function throws [kotlin.IllegalStateException].
* 1. In case operation is not defined in the structure, the function throws [kotlin.IllegalStateException].
* 2. This function is symmetric with second `unaryOperation` overload:
* i.e. `unaryOperationFunction(a)(b) == unaryOperation(a, b)`.
*

View File

@ -97,14 +97,12 @@ public interface NumericAlgebra<T> : Algebra<T> {
/**
* The &pi; mathematical constant.
*/
public val <T> NumericAlgebra<T>.pi: T
get() = bindSymbolOrNull("pi") ?: number(PI)
public val <T> NumericAlgebra<T>.pi: T get() = bindSymbolOrNull("pi") ?: number(PI)
/**
* The *e* mathematical constant.
*/
public val <T> NumericAlgebra<T>.e: T
get() = number(E)
public val <T> NumericAlgebra<T>.e: T get() = number(E)
/**
* Scale by scalar operations

View File

@ -49,12 +49,6 @@ public interface ExtendedField<T> : ExtendedFieldOperations<T>, Field<T>, Numeri
public override fun acosh(arg: T): T = ln(arg + sqrt((arg - one) * (arg + one)))
public override fun atanh(arg: T): T = (ln(arg + one) - ln(one - arg)) / 2.0
public override fun bindSymbol(value: String): T = when (value) {
"pi" -> pi
"e" -> e
else -> super<ExtendedFieldOperations>.bindSymbol(value)
}
public override fun rightSideNumberOperationFunction(operation: String): (left: T, right: Number) -> T =
when (operation) {
PowerOperations.POW_OPERATION -> ::power