new TensorFlow operations are added. Binary Logic functions were moved into separate interface from LinearAlgebra
This commit is contained in:
parent
2cdaa6989c
commit
0e8eb44670
@ -167,9 +167,9 @@ public object MstLogicAlgebra : LogicAlgebra<MST> {
|
||||
override fun bindSymbolOrNull(value: String): MST = super.bindSymbolOrNull(value) ?: StringSymbol(value)
|
||||
|
||||
override fun const(boolean: Boolean): Symbol = if (boolean) {
|
||||
LogicAlgebra.TRUE
|
||||
BinaryLogic.TRUE
|
||||
} else {
|
||||
LogicAlgebra.FALSE
|
||||
BinaryLogic.FALSE
|
||||
}
|
||||
|
||||
override fun MST.not(): MST = MST.Unary(Boolean::not.name, this)
|
||||
|
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* 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.operations
|
||||
|
||||
import space.kscience.kmath.expressions.Symbol
|
||||
import space.kscience.kmath.expressions.symbol
|
||||
|
||||
interface BinaryLogic<T : Any> {
|
||||
/**
|
||||
* Logic 'not'
|
||||
*/
|
||||
public operator fun T.not(): T
|
||||
|
||||
/**
|
||||
* Logic 'and'
|
||||
*/
|
||||
public infix fun T.and(other: T): T
|
||||
|
||||
/**
|
||||
* Logic 'or'
|
||||
*/
|
||||
public infix fun T.or(other: T): T
|
||||
|
||||
/**
|
||||
* Logic 'xor'
|
||||
*/
|
||||
public infix fun T.xor(other: T): T
|
||||
|
||||
companion object {
|
||||
public val TRUE: Symbol by symbol
|
||||
public val FALSE: Symbol by symbol
|
||||
}
|
||||
}
|
@ -5,16 +5,13 @@
|
||||
|
||||
package space.kscience.kmath.operations
|
||||
|
||||
import space.kscience.kmath.expressions.Symbol
|
||||
import space.kscience.kmath.expressions.symbol
|
||||
import space.kscience.kmath.misc.UnstableKMathAPI
|
||||
|
||||
/**
|
||||
* An algebra for generic boolean logic
|
||||
*/
|
||||
@UnstableKMathAPI
|
||||
public interface LogicAlgebra<T : Any> : Algebra<T> {
|
||||
|
||||
public interface LogicAlgebra<T : Any> : Algebra<T>, BinaryLogic<T> {
|
||||
/**
|
||||
* Represent constant [Boolean] as [T]
|
||||
*/
|
||||
@ -38,32 +35,6 @@ public interface LogicAlgebra<T : Any> : Algebra<T> {
|
||||
override fun binaryOperationFunction(operation: String): (left: T, right: T) -> T = { l, r ->
|
||||
binaryOperation(operation, l, r)
|
||||
}
|
||||
|
||||
/**
|
||||
* Logic 'not'
|
||||
*/
|
||||
public operator fun T.not(): T
|
||||
|
||||
/**
|
||||
* Logic 'and'
|
||||
*/
|
||||
public infix fun T.and(other: T): T
|
||||
|
||||
/**
|
||||
* Logic 'or'
|
||||
*/
|
||||
public infix fun T.or(other: T): T
|
||||
|
||||
/**
|
||||
* Logic 'xor'
|
||||
*/
|
||||
public infix fun T.xor(other: T): T
|
||||
|
||||
|
||||
public companion object {
|
||||
public val TRUE: Symbol by symbol
|
||||
public val FALSE: Symbol by symbol
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -21,3 +21,11 @@ public fun <T, TT : TNumber, A> TensorFlowAlgebra<T, TT, A>.sin(
|
||||
public fun <T, TT : TNumber, A> TensorFlowAlgebra<T, TT, A>.cos(
|
||||
arg: StructureND<T>,
|
||||
): TensorFlowOutput<T, TT> where A : TrigonometricOperations<T>, A : Ring<T> = arg.operate { ops.math.cos(it) }
|
||||
|
||||
public fun <T, TT : TNumber, A> TensorFlowAlgebra<T, TT, A>.tan(
|
||||
arg: StructureND<T>,
|
||||
): TensorFlowOutput<T, TT> where A : TrigonometricOperations<T>, A : Ring<T> = arg.operate { ops.math.tan(it) }
|
||||
|
||||
public fun <T, TT : TNumber, A> TensorFlowAlgebra<T, TT, A>.abs(
|
||||
arg: StructureND<T>,
|
||||
): TensorFlowOutput<T, TT> where A : TrigonometricOperations<T>, A : Ring<T> = arg.operate { ops.math.abs(it) }
|
Loading…
Reference in New Issue
Block a user