Cleanup doc mistakes, fix number fields corner cases

This commit is contained in:
Iaroslav 2020-08-09 23:43:38 +07:00
parent 6ead822cc3
commit 895f788f75
No known key found for this signature in database
GPG Key ID: 46E15E4A31B3BCD7
3 changed files with 24 additions and 11 deletions

View File

@ -58,12 +58,10 @@ interface NumericAlgebra<T> : Algebra<T> {
inline operator fun <A : Algebra<*>, R> A.invoke(block: A.() -> R): R = run(block)
/**
* Represents semispace, i.e. algebraic structure with associative binary operation called "addition" as well as
* Represents "semispace", i.e. algebraic structure with associative binary operation called "addition" as well as
* multiplication by scalars.
*
* In KMath groups are called spaces, and also define multiplication of element by [Number].
*
* @param T the type of element of this semigroup.
* @param T the type of element of this "semispace".
*/
interface SpaceOperations<T> : Algebra<T> {
/**

View File

@ -1,5 +1,6 @@
package scientifik.kmath.operations
import scientifik.kmath.operations.RealField.pow
import kotlin.math.abs
import kotlin.math.pow as kpow
@ -83,6 +84,11 @@ object RealField : ExtendedField<Double>, Norm<Double, Double> {
override val one: Double
get() = 1.0
override fun binaryOperation(operation: String, left: Double, right: Double): Double = when (operation) {
PowerOperations.POW_OPERATION -> left pow right
else -> super.binaryOperation(operation, left, right)
}
override inline fun add(a: Double, b: Double): Double = a + b
override inline fun multiply(a: Double, k: Number): Double = a * k.toDouble()
@ -128,6 +134,11 @@ object FloatField : ExtendedField<Float>, Norm<Float, Float> {
override val one: Float
get() = 1.0f
override fun binaryOperation(operation: String, left: Float, right: Float): Float = when (operation) {
PowerOperations.POW_OPERATION -> left pow right
else -> super.binaryOperation(operation, left, right)
}
override inline fun add(a: Float, b: Float): Float = a + b
override inline fun multiply(a: Float, k: Number): Float = a * k.toFloat()

View File

@ -1,10 +1,9 @@
package scientifik.kmath.operations
/**
* A container for trigonometric operations for specific type. They are limited to semifields.
* A container for trigonometric operations for specific type.
*
* The operations are not exposed to class directly to avoid method bloat but instead are declared in the field.
* It also allows to override behavior for optional operations.
* @param T the type of element of this structure.
*/
interface TrigonometricOperations<T> : Algebra<T> {
/**
@ -101,11 +100,9 @@ fun <T : MathElement<out TrigonometricOperations<T>>> acos(arg: T): T = arg.cont
fun <T : MathElement<out TrigonometricOperations<T>>> atan(arg: T): T = arg.context.atan(arg)
/**
* A container for hyperbolic trigonometric operations for specific type. Trigonometric operations are limited to
* fields.
* A container for hyperbolic trigonometric operations for specific type.
*
* The operations are not exposed to class directly to avoid method bloat but instead are declared in the field. It
* also allows to override behavior for optional operations.
* @param T the type of element of this structure.
*/
interface HyperbolicOperations<T> : Algebra<T> {
/**
@ -203,6 +200,8 @@ fun <T : MathElement<out HyperbolicOperations<T>>> atanh(arg: T): T = arg.contex
/**
* A context extension to include power operations based on exponentiation.
*
* @param T the type of element of this structure.
*/
interface PowerOperations<T> : Algebra<T> {
/**
@ -254,6 +253,8 @@ fun <T : MathElement<out PowerOperations<T>>> sqr(arg: T): T = arg pow 2.0
/**
* A container for operations related to `exp` and `ln` functions.
*
* @param T the type of element of this structure.
*/
interface ExponentialOperations<T> : Algebra<T> {
/**
@ -291,6 +292,9 @@ fun <T : MathElement<out ExponentialOperations<T>>> ln(arg: T): T = arg.context.
/**
* A container for norm functional on element.
*
* @param T the type of element having norm defined.
* @param R the type of norm.
*/
interface Norm<in T : Any, out R> {
/**