forked from kscience/kmath
Added complex example for article
This commit is contained in:
parent
5a8a45cf6a
commit
88759807ab
@ -1,5 +1,8 @@
|
||||
package scientifik.kmath.structures
|
||||
|
||||
import scientifik.kmath.linear.transpose
|
||||
import scientifik.kmath.operations.Complex
|
||||
import scientifik.kmath.operations.toComplex
|
||||
import kotlin.system.measureTimeMillis
|
||||
|
||||
fun main() {
|
||||
@ -32,3 +35,23 @@ fun main() {
|
||||
|
||||
println("Complex addition completed in $complexTime millis")
|
||||
}
|
||||
|
||||
|
||||
fun complexExample() {
|
||||
//Create a context for 2-d structure with complex values
|
||||
NDField.complex(4, 8).run {
|
||||
//a constant real-valued structure
|
||||
val x = one * 2.5
|
||||
operator fun Number.plus(other: Complex) = Complex(this.toDouble() + other.re, other.im)
|
||||
//a structure generator specific to this context
|
||||
val matrix = produce { (k, l) ->
|
||||
k + l*i
|
||||
}
|
||||
|
||||
//Perform sum
|
||||
val sum = matrix + x + 1.0
|
||||
|
||||
//Represent the sum as 2d-structure and transpose
|
||||
sum.as2D().transpose()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user