forked from kscience/kmath
Complex extensions
This commit is contained in:
parent
cddea1869d
commit
bb64012992
3
doc/contexts.md
Normal file
3
doc/contexts.md
Normal file
@ -0,0 +1,3 @@
|
||||
# Context-oriented programming
|
||||
|
||||
One of problems
|
@ -198,7 +198,6 @@ class RealLUDecomposition(matrix: RealMatrix, private val singularityThreshold:
|
||||
/** Specialized solver. */
|
||||
object RealLUSolver : LinearSolver<Double, DoubleField> {
|
||||
|
||||
|
||||
fun decompose(mat: Matrix<Double, DoubleField>, threshold: Double = 1e-11): RealLUDecomposition = RealLUDecomposition(mat, threshold)
|
||||
|
||||
override fun solve(a: RealMatrix, b: RealMatrix): RealMatrix {
|
||||
|
@ -6,12 +6,14 @@ package scientifik.kmath.operations
|
||||
object ComplexField : Field<Complex> {
|
||||
override val zero: Complex = Complex(0.0, 0.0)
|
||||
|
||||
override val one: Complex = Complex(1.0, 0.0)
|
||||
|
||||
val i = Complex(0.0, 1.0)
|
||||
|
||||
override fun add(a: Complex, b: Complex): Complex = Complex(a.re + b.re, a.im + b.im)
|
||||
|
||||
override fun multiply(a: Complex, k: Double): Complex = Complex(a.re * k, a.im * k)
|
||||
|
||||
override val one: Complex = Complex(1.0, 0.0)
|
||||
|
||||
override fun multiply(a: Complex, b: Complex): Complex = Complex(a.re * b.re - a.im * b.im, a.re * b.im + a.im * b.re)
|
||||
|
||||
override fun divide(a: Complex, b: Complex): Complex = Complex(a.re * b.re + a.im * b.im, a.re * b.im - a.im * b.re) / b.square
|
||||
@ -41,5 +43,16 @@ data class Complex(val re: Double, val im: Double) : FieldElement<Complex, Compl
|
||||
companion object {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
fun Double.toComplex() = Complex(this, 0.0)
|
||||
|
||||
operator fun Double.plus(c: Complex) = this.toComplex() + c
|
||||
|
||||
operator fun Double.minus(c: Complex) = this.toComplex() - c
|
||||
|
||||
operator fun Complex.plus(d: Double) = d + this
|
||||
|
||||
operator fun Complex.minus(d: Double) = this - d.toComplex()
|
||||
|
||||
operator fun Double.times(c: Complex) = Complex(c.re * this, c.im * this)
|
@ -68,8 +68,7 @@ class ArrayBuffer<T>(private val array: Array<T>) : MutableBuffer<T> {
|
||||
}
|
||||
|
||||
inline class DoubleBuffer(private val array: DoubleArray) : MutableBuffer<Double> {
|
||||
override val size: Int
|
||||
get() = array.size
|
||||
override val size: Int get() = array.size
|
||||
|
||||
override fun get(index: Int): Double = array[index]
|
||||
|
||||
@ -83,8 +82,7 @@ inline class DoubleBuffer(private val array: DoubleArray) : MutableBuffer<Double
|
||||
}
|
||||
|
||||
inline class IntBuffer(private val array: IntArray) : MutableBuffer<Int> {
|
||||
override val size: Int
|
||||
get() = array.size
|
||||
override val size: Int get() = array.size
|
||||
|
||||
override fun get(index: Int): Int = array[index]
|
||||
|
||||
|
@ -49,6 +49,9 @@ interface Strides {
|
||||
*/
|
||||
fun index(offset: Int): IntArray
|
||||
|
||||
/**
|
||||
* The size of linear buffer to accommodate all elements of ND-structure corresponding to strides
|
||||
*/
|
||||
val linearSize: Int
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user