Cleanup doc mistakes, fix number fields corner cases
This commit is contained in:
parent
6ead822cc3
commit
895f788f75
@ -58,12 +58,10 @@ interface NumericAlgebra<T> : Algebra<T> {
|
|||||||
inline operator fun <A : Algebra<*>, R> A.invoke(block: A.() -> R): R = run(block)
|
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.
|
* 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 "semispace".
|
||||||
*
|
|
||||||
* @param T the type of element of this semigroup.
|
|
||||||
*/
|
*/
|
||||||
interface SpaceOperations<T> : Algebra<T> {
|
interface SpaceOperations<T> : Algebra<T> {
|
||||||
/**
|
/**
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package scientifik.kmath.operations
|
package scientifik.kmath.operations
|
||||||
|
|
||||||
|
import scientifik.kmath.operations.RealField.pow
|
||||||
import kotlin.math.abs
|
import kotlin.math.abs
|
||||||
import kotlin.math.pow as kpow
|
import kotlin.math.pow as kpow
|
||||||
|
|
||||||
@ -83,6 +84,11 @@ object RealField : ExtendedField<Double>, Norm<Double, Double> {
|
|||||||
override val one: Double
|
override val one: Double
|
||||||
get() = 1.0
|
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 add(a: Double, b: Double): Double = a + b
|
||||||
override inline fun multiply(a: Double, k: Number): Double = a * k.toDouble()
|
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
|
override val one: Float
|
||||||
get() = 1.0f
|
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 add(a: Float, b: Float): Float = a + b
|
||||||
override inline fun multiply(a: Float, k: Number): Float = a * k.toFloat()
|
override inline fun multiply(a: Float, k: Number): Float = a * k.toFloat()
|
||||||
|
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
package scientifik.kmath.operations
|
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.
|
* @param T the type of element of this structure.
|
||||||
* It also allows to override behavior for optional operations.
|
|
||||||
*/
|
*/
|
||||||
interface TrigonometricOperations<T> : Algebra<T> {
|
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)
|
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
|
* A container for hyperbolic trigonometric operations for specific type.
|
||||||
* fields.
|
|
||||||
*
|
*
|
||||||
* The operations are not exposed to class directly to avoid method bloat but instead are declared in the field. It
|
* @param T the type of element of this structure.
|
||||||
* also allows to override behavior for optional operations.
|
|
||||||
*/
|
*/
|
||||||
interface HyperbolicOperations<T> : Algebra<T> {
|
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.
|
* A context extension to include power operations based on exponentiation.
|
||||||
|
*
|
||||||
|
* @param T the type of element of this structure.
|
||||||
*/
|
*/
|
||||||
interface PowerOperations<T> : Algebra<T> {
|
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.
|
* A container for operations related to `exp` and `ln` functions.
|
||||||
|
*
|
||||||
|
* @param T the type of element of this structure.
|
||||||
*/
|
*/
|
||||||
interface ExponentialOperations<T> : Algebra<T> {
|
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.
|
* 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> {
|
interface Norm<in T : Any, out R> {
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user