Completely remove AlgebraElements.kt

This commit is contained in:
Alexander Nozik 2021-10-02 16:14:38 +03:00
parent 0f634688cc
commit 85aefb5380
6 changed files with 14 additions and 270 deletions

View File

@ -53,6 +53,7 @@
- Expression algebra builders - Expression algebra builders
- Complex and Quaternion no longer are elements. - Complex and Quaternion no longer are elements.
- Second generic from DifferentiableExpression - Second generic from DifferentiableExpression
- Algebra elements are completely removed. Use algebra contexts instead.
### Fixed ### Fixed
- Ring inherits RingOperations, not GroupOperations - Ring inherits RingOperations, not GroupOperations

View File

@ -240,10 +240,10 @@ public object EjmlLinearSpace${ops} : EjmlLinearSpace<${type}, ${kmathAlgebra},
} }
override val q: Matrix<${type}> by lazy { override val q: Matrix<${type}> by lazy {
qr.getQ(null, false).wrapMatrix() + OrthogonalFeature qr.getQ(null, false).wrapMatrix().withFeature(OrthogonalFeature)
} }
override val r: Matrix<${type}> by lazy { qr.getR(null, false).wrapMatrix() + UFeature } override val r: Matrix<${type}> by lazy { qr.getR(null, false).wrapMatrix().withFeature(UFeature) }
} }
CholeskyDecompositionFeature::class -> object : CholeskyDecompositionFeature<${type}> { CholeskyDecompositionFeature::class -> object : CholeskyDecompositionFeature<${type}> {
@ -251,7 +251,7 @@ public object EjmlLinearSpace${ops} : EjmlLinearSpace<${type}, ${kmathAlgebra},
val cholesky = val cholesky =
DecompositionFactory_${ops}.chol(structure.rowNum, true).apply { decompose(origin.copy()) } DecompositionFactory_${ops}.chol(structure.rowNum, true).apply { decompose(origin.copy()) }
cholesky.getT(null).wrapMatrix() + LFeature cholesky.getT(null).wrapMatrix().withFeature(LFeature)
} }
} }
@ -261,11 +261,11 @@ public object EjmlLinearSpace${ops} : EjmlLinearSpace<${type}, ${kmathAlgebra},
} }
override val l: Matrix<${type}> by lazy { override val l: Matrix<${type}> by lazy {
lup.getLower(null).wrapMatrix() + LFeature lup.getLower(null).wrapMatrix().withFeature(LFeature)
} }
override val u: Matrix<${type}> by lazy { override val u: Matrix<${type}> by lazy {
lup.getUpper(null).wrapMatrix() + UFeature lup.getUpper(null).wrapMatrix().withFeature(UFeature)
} }
override val p: Matrix<${type}> by lazy { lup.getRowPivot(null).wrapMatrix() } override val p: Matrix<${type}> by lazy { lup.getRowPivot(null).wrapMatrix() }
@ -275,10 +275,10 @@ public object EjmlLinearSpace${ops} : EjmlLinearSpace<${type}, ${kmathAlgebra},
} }
override val q: Matrix<${type}> by lazy { override val q: Matrix<${type}> by lazy {
qr.getQ(null, false).wrapMatrix() + OrthogonalFeature qr.getQ(null, false).wrapMatrix().withFeature(OrthogonalFeature)
} }
override val r: Matrix<${type}> by lazy { qr.getR(null, false).wrapMatrix() + UFeature } override val r: Matrix<${type}> by lazy { qr.getR(null, false).wrapMatrix().withFeature(UFeature) }
} }
CholeskyDecompositionFeature::class -> object : CholeskyDecompositionFeature<${type}> { CholeskyDecompositionFeature::class -> object : CholeskyDecompositionFeature<${type}> {
@ -286,7 +286,7 @@ public object EjmlLinearSpace${ops} : EjmlLinearSpace<${type}, ${kmathAlgebra},
val cholesky = val cholesky =
DecompositionFactory_${ops}.cholesky().apply { decompose(origin.copy()) } DecompositionFactory_${ops}.cholesky().apply { decompose(origin.copy()) }
(cholesky.getT(null) as ${ejmlMatrixParentTypeMatrix}).wrapMatrix() + LFeature (cholesky.getT(null) as ${ejmlMatrixParentTypeMatrix}).wrapMatrix().withFeature(LFeature)
} }
} }
@ -297,11 +297,11 @@ public object EjmlLinearSpace${ops} : EjmlLinearSpace<${type}, ${kmathAlgebra},
} }
override val l: Matrix<${type}> by lazy { override val l: Matrix<${type}> by lazy {
lu.getLower(null).wrapMatrix() + LFeature lu.getLower(null).wrapMatrix().withFeature(LFeature)
} }
override val u: Matrix<${type}> by lazy { override val u: Matrix<${type}> by lazy {
lu.getUpper(null).wrapMatrix() + UFeature lu.getUpper(null).wrapMatrix().withFeature(UFeature)
} }
override val inverse: Matrix<${type}> by lazy { override val inverse: Matrix<${type}> by lazy {

View File

@ -24,7 +24,7 @@ fun main() {
val time = measureTimeMillis { val time = measureTimeMillis {
with(Double.algebra.linearSpace) { with(Double.algebra.linearSpace) {
repeat(10) { repeat(10) {
val res = matrix1 dot matrix2 matrix1 dot matrix2
} }
} }
} }

View File

@ -1,128 +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 file.
*/
package space.kscience.kmath.operations
import space.kscience.kmath.misc.UnstableKMathAPI
/**
* The generic mathematics elements that is able to store its context
*
* @param C the type of mathematical context for this element.
* @param T the type wrapped by this wrapper.
*/
@UnstableKMathAPI
@Deprecated("AlgebraElements are considered odd and will be removed in future releases.")
public interface AlgebraElement<T, out C : Algebra<T>> {
/**
* The context this element belongs to.
*/
public val context: C
}
//
///**
// * Divides this element by number.
// *
// * @param k the divisor.
// * @return the quotient.
// */
//public operator fun <T : AlgebraElement<T, S>, S : Space<T>> T.div(k: Number): T =
// context.multiply(this, 1.0 / k.toDouble())
//
///**
// * Multiplies this element by number.
// *
// * @param k the multiplicand.
// * @return the product.
// */
//public operator fun <T : AlgebraElement<T, S>, S : Space<T>> T.times(k: Number): T =
// context.multiply(this, k.toDouble())
/**
* Subtracts element from this one.
*
* @param b the subtrahend.
* @return the difference.
*/
@UnstableKMathAPI
@Deprecated("AlgebraElements are considered odd and will be removed in future releases.")
public operator fun <T : AlgebraElement<T, S>, S : NumbersAddOperations<T>> T.minus(b: T): T =
context.add(this, context.run { -b })
/**
* Adds element to this one.
*
* @receiver the augend.
* @param b the addend.
* @return the sum.
*/
@UnstableKMathAPI
@Deprecated("AlgebraElements are considered odd and will be removed in future releases.")
public operator fun <T : AlgebraElement<T, S>, S : Ring<T>> T.plus(b: T): T =
context.add(this, b)
///**
// * Number times element
// */
//public operator fun <T : AlgebraElement<T, S>, S : Space<T>> Number.times(element: T): T =
// element.times(this)
/**
* Multiplies this element by another one.
*
* @receiver the multiplicand.
* @param b the multiplier.
* @return the product.
*/
@UnstableKMathAPI
@Deprecated("AlgebraElements are considered odd and will be removed in future releases.")
public operator fun <T : AlgebraElement<T, R>, R : Ring<T>> T.times(b: T): T =
context.multiply(this, b)
/**
* Divides this element by another one.
*
* @param b the divisor.
* @return the quotient.
*/
@UnstableKMathAPI
@Deprecated("AlgebraElements are considered odd and will be removed in future releases.")
public operator fun <T : AlgebraElement<T, F>, F : Field<T>> T.div(b: T): T =
context.divide(this, b)
/**
* The element of [Group].
*
* @param T the type of space operation results.
* @param I self type of the element. Needed for static type checking.
* @param S the type of space.
*/
@UnstableKMathAPI
@Deprecated("AlgebraElements are considered odd and will be removed in future releases.")
public interface GroupElement<T : GroupElement<T, S>, S : Group<T>> : AlgebraElement<T, S>
/**
* The element of [Ring].
*
* @param T the type of ring operation results.
* @param I self type of the element. Needed for static type checking.
* @param R the type of ring.
*/
@UnstableKMathAPI
@Deprecated("AlgebraElements are considered odd and will be removed in future releases.")
public interface RingElement<T : RingElement<T, R>, R : Ring<T>> : GroupElement<T, R>
/**
* The element of [Field].
*
* @param T the type of field operation results.
* @param I self type of the element. Needed for static type checking.
* @param F the type of field.
*/
@UnstableKMathAPI
@Deprecated("AlgebraElements are considered odd and will be removed in future releases.")
public interface FieldElement<T : FieldElement<T, F>, F : Field<T>> : RingElement<T, F>

View File

@ -5,8 +5,6 @@
package space.kscience.kmath.operations package space.kscience.kmath.operations
import space.kscience.kmath.misc.UnstableKMathAPI
/** /**
* A container for trigonometric operations for specific type. * A container for trigonometric operations for specific type.
* *
@ -76,48 +74,6 @@ public interface TrigonometricOperations<T> : Algebra<T> {
} }
} }
/**
* Computes the sine of [arg].
*/
@UnstableKMathAPI
@Deprecated("AlgebraElements are considered odd and will be removed in future releases.")
public fun <T : AlgebraElement<T, out TrigonometricOperations<T>>> sin(arg: T): T = arg.context.sin(arg)
/**
* Computes the cosine of [arg].
*/
@UnstableKMathAPI
@Deprecated("AlgebraElements are considered odd and will be removed in future releases.")
public fun <T : AlgebraElement<T, out TrigonometricOperations<T>>> cos(arg: T): T = arg.context.cos(arg)
/**
* Computes the tangent of [arg].
*/
@UnstableKMathAPI
@Deprecated("AlgebraElements are considered odd and will be removed in future releases.")
public fun <T : AlgebraElement<T, out TrigonometricOperations<T>>> tan(arg: T): T = arg.context.tan(arg)
/**
* Computes the inverse sine of [arg].
*/
@UnstableKMathAPI
@Deprecated("AlgebraElements are considered odd and will be removed in future releases.")
public fun <T : AlgebraElement<T, out TrigonometricOperations<T>>> asin(arg: T): T = arg.context.asin(arg)
/**
* Computes the inverse cosine of [arg].
*/
@UnstableKMathAPI
@Deprecated("AlgebraElements are considered odd and will be removed in future releases.")
public fun <T : AlgebraElement<T, out TrigonometricOperations<T>>> acos(arg: T): T = arg.context.acos(arg)
/**
* Computes the inverse tangent of [arg].
*/
@UnstableKMathAPI
@Deprecated("AlgebraElements are considered odd and will be removed in future releases.")
public fun <T : AlgebraElement<T, out TrigonometricOperations<T>>> atan(arg: T): T = arg.context.atan(arg)
/** /**
* A context extension to include power operations based on exponentiation. * A context extension to include power operations based on exponentiation.
* *
@ -152,31 +108,6 @@ public interface PowerOperations<T> : Algebra<T> {
} }
} }
/**
* Raises this element to the power [power].
*
* @receiver the base.
* @param power the exponent.
* @return the base raised to the power.
*/
@UnstableKMathAPI
@Deprecated("AlgebraElements are considered odd and will be removed in future releases.")
public infix fun <T : AlgebraElement<T, out PowerOperations<T>>> T.pow(power: Double): T = context.power(this, power)
/**
* Computes the square root of the value [arg].
*/
@UnstableKMathAPI
@Deprecated("AlgebraElements are considered odd and will be removed in future releases.")
public fun <T : AlgebraElement<T, out PowerOperations<T>>> sqrt(arg: T): T = arg pow 0.5
/**
* Computes the square of the value [arg].
*/
@UnstableKMathAPI
@Deprecated("AlgebraElements are considered odd and will be removed in future releases.")
public fun <T : AlgebraElement<T, out PowerOperations<T>>> sqr(arg: T): T = arg pow 2.0
/** /**
* A container for operations related to `exp` and `ln` functions. * A container for operations related to `exp` and `ln` functions.
* *
@ -266,62 +197,6 @@ public interface ExponentialOperations<T> : Algebra<T> {
} }
} }
/**
* The identifier of exponential function.
*/
@UnstableKMathAPI
@Deprecated("AlgebraElements are considered odd and will be removed in future releases.")
public fun <T : AlgebraElement<T, out ExponentialOperations<T>>> exp(arg: T): T = arg.context.exp(arg)
/**
* The identifier of natural logarithm.
*/
@UnstableKMathAPI
@Deprecated("AlgebraElements are considered odd and will be removed in future releases.")
public fun <T : AlgebraElement<T, out ExponentialOperations<T>>> ln(arg: T): T = arg.context.ln(arg)
/**
* Computes the hyperbolic sine of [arg].
*/
@UnstableKMathAPI
public fun <T : AlgebraElement<T, out ExponentialOperations<T>>> sinh(arg: T): T = arg.context.sinh(arg)
/**
* Computes the hyperbolic cosine of [arg].
*/
@UnstableKMathAPI
@Deprecated("AlgebraElements are considered odd and will be removed in future releases.")
public fun <T : AlgebraElement<T, out ExponentialOperations<T>>> cosh(arg: T): T = arg.context.cosh(arg)
/**
* Computes the hyperbolic tangent of [arg].
*/
@UnstableKMathAPI
@Deprecated("AlgebraElements are considered odd and will be removed in future releases.")
public fun <T : AlgebraElement<T, out ExponentialOperations<T>>> tanh(arg: T): T = arg.context.tanh(arg)
/**
* Computes the inverse hyperbolic sine of [arg].
*/
@UnstableKMathAPI
@Deprecated("AlgebraElements are considered odd and will be removed in future releases.")
public fun <T : AlgebraElement<T, ExponentialOperations<T>>> asinh(arg: T): T = arg.context.asinh(arg)
/**
* Computes the inverse hyperbolic cosine of [arg].
*/
@UnstableKMathAPI
@Deprecated("AlgebraElements are considered odd and will be removed in future releases.")
public fun <T : AlgebraElement<T, ExponentialOperations<T>>> acosh(arg: T): T = arg.context.acosh(arg)
/**
* Computes the inverse hyperbolic tangent of [arg].
*/
@UnstableKMathAPI
@Deprecated("AlgebraElements are considered odd and will be removed in future releases.")
public fun <T : AlgebraElement<T, out ExponentialOperations<T>>> atanh(arg: T): T = arg.context.atanh(arg)
/** /**
* A container for norm functional on element. * A container for norm functional on element.
* *
@ -335,8 +210,3 @@ public interface Norm<in T : Any, out R> {
public fun norm(arg: T): R public fun norm(arg: T): R
} }
/**
* Computes the norm of [arg] (i.e., absolute value or vector length).
*/
@UnstableKMathAPI
public fun <T : AlgebraElement<T, out Norm<T, R>>, R> norm(arg: T): R = arg.context.norm(arg)

View File

@ -13,9 +13,10 @@ import space.kscience.kmath.linear.*
import space.kscience.kmath.misc.UnstableKMathAPI import space.kscience.kmath.misc.UnstableKMathAPI
import space.kscience.kmath.misc.log import space.kscience.kmath.misc.log
import space.kscience.kmath.operations.DoubleField import space.kscience.kmath.operations.DoubleField
import space.kscience.kmath.operations.DoubleL2Norm
import space.kscience.kmath.operations.algebra import space.kscience.kmath.operations.algebra
import space.kscience.kmath.structures.DoubleBuffer import space.kscience.kmath.structures.DoubleBuffer
import space.kscience.kmath.structures.DoubleL2Norm
public class QowRuns(public val runs: Int) : OptimizationFeature { public class QowRuns(public val runs: Int) : OptimizationFeature {
init { init {