forked from kscience/kmath
Update typealiases usages; add optimization for exponentiation real complex numbers
This commit is contained in:
parent
badb7b1365
commit
77625cca2b
@ -104,7 +104,12 @@ object ComplexField : ExtendedField<Complex> {
|
||||
override fun asinh(arg: Complex): Complex = ln(sqrt((arg pow 2) + 1) + arg)
|
||||
override fun acosh(arg: Complex): Complex = ln(arg + sqrt((arg - 1) * (arg + 1)))
|
||||
override fun atanh(arg: Complex): Complex = (ln(arg + 1) - ln(1 - arg)) / 2
|
||||
override fun power(arg: Complex, pow: Number): Complex = exp(ln(arg) * pow)
|
||||
|
||||
override fun power(arg: Complex, pow: Number): Complex = if (arg.im == 0.0)
|
||||
arg.re.pow(pow.toDouble()).toComplex()
|
||||
else
|
||||
exp(pow * ln(arg))
|
||||
|
||||
override fun exp(arg: Complex): Complex = exp(arg.re) * (cos(arg.im) + i * sin(arg.im))
|
||||
override fun ln(arg: Complex): Complex = ln(arg.r) + i * atan2(arg.im, arg.re)
|
||||
|
||||
@ -145,9 +150,9 @@ data class Complex(val re: Double, val im: Double) : FieldElement<Complex, Compl
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a [Complex] with its real part of this double.
|
||||
* Creates a [Complex] with real part equal to this number.
|
||||
*/
|
||||
fun Double.toComplex(): Complex = Complex(this, 0.0)
|
||||
fun Number.toComplex(): Complex = Complex(this, 0.0)
|
||||
|
||||
inline fun Buffer.Companion.complex(size: Int, crossinline init: (Int) -> Complex): Buffer<Complex> =
|
||||
MemoryBuffer.create(Complex, size, init)
|
||||
|
@ -70,25 +70,25 @@ class ComplexNDField(override val shape: IntArray) :
|
||||
override fun NDBuffer<Complex>.toElement(): FieldElement<NDBuffer<Complex>, *, out BufferedNDField<Complex, ComplexField>> =
|
||||
BufferedNDFieldElement(this@ComplexNDField, buffer)
|
||||
|
||||
override fun power(arg: NDBuffer<Complex>, pow: Number): BufferedNDFieldElement<Complex, ComplexField> =
|
||||
override fun power(arg: NDBuffer<Complex>, pow: Number): ComplexNDElement =
|
||||
map(arg) { power(it, pow) }
|
||||
|
||||
override fun exp(arg: NDBuffer<Complex>): BufferedNDFieldElement<Complex, ComplexField> = map(arg) { exp(it) }
|
||||
override fun ln(arg: NDBuffer<Complex>): BufferedNDFieldElement<Complex, ComplexField> = map(arg) { ln(it) }
|
||||
override fun exp(arg: NDBuffer<Complex>): ComplexNDElement = map(arg) { exp(it) }
|
||||
override fun ln(arg: NDBuffer<Complex>): ComplexNDElement = map(arg) { ln(it) }
|
||||
|
||||
override fun sin(arg: NDBuffer<Complex>): BufferedNDFieldElement<Complex, ComplexField> = map(arg) { sin(it) }
|
||||
override fun cos(arg: NDBuffer<Complex>): BufferedNDFieldElement<Complex, ComplexField> = map(arg) { cos(it) }
|
||||
override fun tan(arg: NDBuffer<Complex>): BufferedNDFieldElement<Complex, ComplexField> = map(arg) { tan(it) }
|
||||
override fun asin(arg: NDBuffer<Complex>): BufferedNDFieldElement<Complex, ComplexField> = map(arg) { asin(it) }
|
||||
override fun acos(arg: NDBuffer<Complex>): BufferedNDFieldElement<Complex, ComplexField> = map(arg) { acos(it) }
|
||||
override fun atan(arg: NDBuffer<Complex>): BufferedNDFieldElement<Complex, ComplexField> = map(arg) { atan(it) }
|
||||
override fun sin(arg: NDBuffer<Complex>): ComplexNDElement = map(arg) { sin(it) }
|
||||
override fun cos(arg: NDBuffer<Complex>): ComplexNDElement = map(arg) { cos(it) }
|
||||
override fun tan(arg: NDBuffer<Complex>): ComplexNDElement = map(arg) { tan(it) }
|
||||
override fun asin(arg: NDBuffer<Complex>): ComplexNDElement = map(arg) { asin(it) }
|
||||
override fun acos(arg: NDBuffer<Complex>): ComplexNDElement = map(arg) { acos(it) }
|
||||
override fun atan(arg: NDBuffer<Complex>): ComplexNDElement = map(arg) { atan(it) }
|
||||
|
||||
override fun sinh(arg: NDBuffer<Complex>): BufferedNDFieldElement<Complex, ComplexField> = map(arg) { sinh(it) }
|
||||
override fun cosh(arg: NDBuffer<Complex>): BufferedNDFieldElement<Complex, ComplexField> = map(arg) { cosh(it) }
|
||||
override fun tanh(arg: NDBuffer<Complex>): BufferedNDFieldElement<Complex, ComplexField> = map(arg) { tanh(it) }
|
||||
override fun asinh(arg: NDBuffer<Complex>): BufferedNDFieldElement<Complex, ComplexField> = map(arg) { asinh(it) }
|
||||
override fun acosh(arg: NDBuffer<Complex>): BufferedNDFieldElement<Complex, ComplexField> = map(arg) { acosh(it) }
|
||||
override fun atanh(arg: NDBuffer<Complex>): BufferedNDFieldElement<Complex, ComplexField> = map(arg) { atanh(it) }
|
||||
override fun sinh(arg: NDBuffer<Complex>): ComplexNDElement = map(arg) { sinh(it) }
|
||||
override fun cosh(arg: NDBuffer<Complex>): ComplexNDElement = map(arg) { cosh(it) }
|
||||
override fun tanh(arg: NDBuffer<Complex>): ComplexNDElement = map(arg) { tanh(it) }
|
||||
override fun asinh(arg: NDBuffer<Complex>): ComplexNDElement = map(arg) { asinh(it) }
|
||||
override fun acosh(arg: NDBuffer<Complex>): ComplexNDElement = map(arg) { acosh(it) }
|
||||
override fun atanh(arg: NDBuffer<Complex>): ComplexNDElement = map(arg) { atanh(it) }
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user