diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index cde58b6d6..78c1522c7 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -11,14 +11,14 @@ jobs:
matrix:
os: [ macOS-latest, windows-latest ]
runs-on: ${{matrix.os}}
- timeout-minutes: 40
+ timeout-minutes: 30
steps:
- name: Checkout the repo
uses: actions/checkout@v2
- name: Set up JDK 11
uses: DeLaGuardo/setup-graalvm@4.0
with:
- graalvm: 21.2.0
+ graalvm: 21.1.0
java: java11
arch: amd64
- name: Cache gradle
diff --git a/.github/workflows/pages.yml b/.github/workflows/pages.yml
index 23ed54357..86a0e130e 100644
--- a/.github/workflows/pages.yml
+++ b/.github/workflows/pages.yml
@@ -7,12 +7,11 @@ on:
jobs:
build:
runs-on: ubuntu-20.04
- timeout-minutes: 40
steps:
- uses: actions/checkout@v2
- uses: DeLaGuardo/setup-graalvm@4.0
with:
- graalvm: 21.2.0
+ graalvm: 21.1.0
java: java11
arch: amd64
- uses: actions/cache@v2
diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml
index c5075cb0f..dbc4a9473 100644
--- a/.github/workflows/publish.yml
+++ b/.github/workflows/publish.yml
@@ -19,7 +19,7 @@ jobs:
- name: Set up JDK 11
uses: DeLaGuardo/setup-graalvm@4.0
with:
- graalvm: 21.2.0
+ graalvm: 21.1.0
java: java11
arch: amd64
- name: Cache gradle
diff --git a/.idea/copyright/kmath.xml b/.idea/copyright/kmath.xml
index 1070e5d33..17e44e4d0 100644
--- a/.idea/copyright/kmath.xml
+++ b/.idea/copyright/kmath.xml
@@ -1,6 +1,6 @@
-
+
diff --git a/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/ArrayBenchmark.kt b/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/ArrayBenchmark.kt
index 17983e88c..ff933997f 100644
--- a/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/ArrayBenchmark.kt
+++ b/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/ArrayBenchmark.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.benchmarks
diff --git a/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/BigIntBenchmark.kt b/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/BigIntBenchmark.kt
index 6f501dedb..0eeee5177 100644
--- a/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/BigIntBenchmark.kt
+++ b/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/BigIntBenchmark.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.benchmarks
@@ -20,9 +20,9 @@ import java.math.BigInteger
internal class BigIntBenchmark {
val kmNumber = BigIntField.number(Int.MAX_VALUE)
- val jvmNumber = JBigIntegerField.number(Int.MAX_VALUE)
+ val jvmNumber = JBigIntegerRing.number(Int.MAX_VALUE)
val largeKmNumber = BigIntField { number(11).pow(100_000U) }
- val largeJvmNumber: BigInteger = JBigIntegerField { number(11).pow(100_000) }
+ val largeJvmNumber: BigInteger = JBigIntegerRing { number(11).pow(100_000) }
val bigExponent = 50_000
@Benchmark
@@ -31,7 +31,7 @@ internal class BigIntBenchmark {
}
@Benchmark
- fun jvmAdd(blackhole: Blackhole) = JBigIntegerField {
+ fun jvmAdd(blackhole: Blackhole) = JBigIntegerRing {
blackhole.consume(jvmNumber + jvmNumber + jvmNumber)
}
@@ -41,7 +41,7 @@ internal class BigIntBenchmark {
}
@Benchmark
- fun jvmAddLarge(blackhole: Blackhole) = JBigIntegerField {
+ fun jvmAddLarge(blackhole: Blackhole) = JBigIntegerRing {
blackhole.consume(largeJvmNumber + largeJvmNumber + largeJvmNumber)
}
@@ -56,12 +56,12 @@ internal class BigIntBenchmark {
}
@Benchmark
- fun jvmMultiply(blackhole: Blackhole) = JBigIntegerField {
+ fun jvmMultiply(blackhole: Blackhole) = JBigIntegerRing {
blackhole.consume(jvmNumber * jvmNumber * jvmNumber)
}
@Benchmark
- fun jvmMultiplyLarge(blackhole: Blackhole) = JBigIntegerField {
+ fun jvmMultiplyLarge(blackhole: Blackhole) = JBigIntegerRing {
blackhole.consume(largeJvmNumber*largeJvmNumber)
}
@@ -71,27 +71,27 @@ internal class BigIntBenchmark {
}
@Benchmark
- fun jvmPower(blackhole: Blackhole) = JBigIntegerField {
+ fun jvmPower(blackhole: Blackhole) = JBigIntegerRing {
blackhole.consume(jvmNumber.pow(bigExponent))
}
@Benchmark
- fun kmParsing16(blackhole: Blackhole) = JBigIntegerField {
+ fun kmParsing16(blackhole: Blackhole) = JBigIntegerRing {
blackhole.consume("0x7f57ed8b89c29a3b9a85c7a5b84ca3929c7b7488593".parseBigInteger())
}
@Benchmark
- fun kmParsing10(blackhole: Blackhole) = JBigIntegerField {
+ fun kmParsing10(blackhole: Blackhole) = JBigIntegerRing {
blackhole.consume("236656783929183747565738292847574838922010".parseBigInteger())
}
@Benchmark
- fun jvmParsing10(blackhole: Blackhole) = JBigIntegerField {
+ fun jvmParsing10(blackhole: Blackhole) = JBigIntegerRing {
blackhole.consume("236656783929183747565738292847574838922010".toBigInteger(10))
}
@Benchmark
- fun jvmParsing16(blackhole: Blackhole) = JBigIntegerField {
+ fun jvmParsing16(blackhole: Blackhole) = JBigIntegerRing {
blackhole.consume("7f57ed8b89c29a3b9a85c7a5b84ca3929c7b7488593".toBigInteger(16))
}
}
diff --git a/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/BufferBenchmark.kt b/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/BufferBenchmark.kt
index 5cf194b67..1c714278a 100644
--- a/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/BufferBenchmark.kt
+++ b/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/BufferBenchmark.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.benchmarks
@@ -17,7 +17,7 @@ import space.kscience.kmath.structures.MutableBuffer
internal class BufferBenchmark {
@Benchmark
fun genericDoubleBufferReadWrite() {
- val buffer = DoubleBuffer(size) { it.toDouble() }
+ val buffer = DoubleBuffer(size, Int::toDouble)
(0 until size).forEach {
buffer[it]
@@ -26,7 +26,8 @@ internal class BufferBenchmark {
@Benchmark
fun complexBufferReadWrite() {
- val buffer = MutableBuffer.complex(size / 2) { Complex(it.toDouble(), -it.toDouble()) }
+ val buffer =
+ MutableBuffer.complex(MutableBuffer.Companion::double, size / 2) { Complex(it.toDouble(), -it.toDouble()) }
(0 until size / 2).forEach {
buffer[it]
diff --git a/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/DotBenchmark.kt b/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/DotBenchmark.kt
index 629408479..2c5a03a97 100644
--- a/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/DotBenchmark.kt
+++ b/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/DotBenchmark.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.benchmarks
diff --git a/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/ExpressionsInterpretersBenchmark.kt b/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/ExpressionsInterpretersBenchmark.kt
index 8c3c8ec2b..0294f924b 100644
--- a/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/ExpressionsInterpretersBenchmark.kt
+++ b/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/ExpressionsInterpretersBenchmark.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.benchmarks
diff --git a/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/JafamaBenchmark.kt b/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/JafamaBenchmark.kt
index 9c6551302..5d4eee7c0 100644
--- a/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/JafamaBenchmark.kt
+++ b/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/JafamaBenchmark.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.benchmarks
diff --git a/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/MatrixInverseBenchmark.kt b/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/MatrixInverseBenchmark.kt
index 1072a55c3..e3179c05c 100644
--- a/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/MatrixInverseBenchmark.kt
+++ b/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/MatrixInverseBenchmark.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.benchmarks
diff --git a/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/NDFieldBenchmark.kt b/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/NDFieldBenchmark.kt
index 0cd9a46ab..c7cb0f8f7 100644
--- a/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/NDFieldBenchmark.kt
+++ b/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/NDFieldBenchmark.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.benchmarks
@@ -47,7 +47,7 @@ internal class NDFieldBenchmark {
private const val dim = 1000
private const val n = 100
private val autoField = AlgebraND.auto(DoubleField, dim, dim)
- private val specializedField = AlgebraND.real(dim, dim)
+ private val specializedField = AlgebraND.double(dim, dim)
private val genericField = AlgebraND.field(DoubleField, Buffer.Companion::boxing, dim, dim)
}
}
diff --git a/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/ViktorBenchmark.kt b/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/ViktorBenchmark.kt
index 1ddc79cf8..15ce382ad 100644
--- a/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/ViktorBenchmark.kt
+++ b/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/ViktorBenchmark.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.benchmarks
@@ -13,7 +13,7 @@ import org.jetbrains.bio.viktor.F64Array
import space.kscience.kmath.nd.AlgebraND
import space.kscience.kmath.nd.StructureND
import space.kscience.kmath.nd.auto
-import space.kscience.kmath.nd.real
+import space.kscience.kmath.nd.double
import space.kscience.kmath.operations.DoubleField
import space.kscience.kmath.viktor.ViktorNDField
@@ -60,7 +60,7 @@ internal class ViktorBenchmark {
// automatically build context most suited for given type.
private val autoField = AlgebraND.auto(DoubleField, dim, dim)
- private val realField = AlgebraND.real(dim, dim)
+ private val realField = AlgebraND.double(dim, dim)
private val viktorField = ViktorNDField(dim, dim)
}
}
diff --git a/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/ViktorLogBenchmark.kt b/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/ViktorLogBenchmark.kt
index 8622e8f30..0f65c717b 100644
--- a/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/ViktorLogBenchmark.kt
+++ b/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/ViktorLogBenchmark.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.benchmarks
@@ -12,7 +12,7 @@ import kotlinx.benchmark.State
import org.jetbrains.bio.viktor.F64Array
import space.kscience.kmath.nd.AlgebraND
import space.kscience.kmath.nd.auto
-import space.kscience.kmath.nd.real
+import space.kscience.kmath.nd.double
import space.kscience.kmath.operations.DoubleField
import space.kscience.kmath.viktor.ViktorFieldND
@@ -52,7 +52,7 @@ internal class ViktorLogBenchmark {
// automatically build context most suited for given type.
private val autoField = AlgebraND.auto(DoubleField, dim, dim)
- private val realNdField = AlgebraND.real(dim, dim)
+ private val realNdField = AlgebraND.double(dim, dim)
private val viktorField = ViktorFieldND(intArrayOf(dim, dim))
}
}
diff --git a/buildSrc/src/main/kotlin/space/kscience/kmath/benchmarks/JmhReport.kt b/buildSrc/src/main/kotlin/space/kscience/kmath/benchmarks/JmhReport.kt
index 6859de845..eaa0f59d8 100644
--- a/buildSrc/src/main/kotlin/space/kscience/kmath/benchmarks/JmhReport.kt
+++ b/buildSrc/src/main/kotlin/space/kscience/kmath/benchmarks/JmhReport.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.benchmarks
diff --git a/buildSrc/src/main/kotlin/space/kscience/kmath/benchmarks/addBenchmarkProperties.kt b/buildSrc/src/main/kotlin/space/kscience/kmath/benchmarks/addBenchmarkProperties.kt
index 72c9ff0ad..b55e1320e 100644
--- a/buildSrc/src/main/kotlin/space/kscience/kmath/benchmarks/addBenchmarkProperties.kt
+++ b/buildSrc/src/main/kotlin/space/kscience/kmath/benchmarks/addBenchmarkProperties.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.benchmarks
diff --git a/buildSrc/src/main/kotlin/space/kscience/kmath/ejml/codegen/ejmlCodegen.kt b/buildSrc/src/main/kotlin/space/kscience/kmath/ejml/codegen/ejmlCodegen.kt
index 68bb10428..a0d40c1ee 100644
--- a/buildSrc/src/main/kotlin/space/kscience/kmath/ejml/codegen/ejmlCodegen.kt
+++ b/buildSrc/src/main/kotlin/space/kscience/kmath/ejml/codegen/ejmlCodegen.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@file:Suppress("KDocUnresolvedReference")
@@ -362,7 +362,7 @@ fun ejmlCodegen(outputFile: String): Unit = File(outputFile).run {
writer().use {
it.appendLine("/*")
it.appendLine(" * Copyright 2018-2021 KMath contributors.")
- it.appendLine(" * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.")
+ it.appendLine(" * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.")
it.appendLine(" */")
it.appendLine()
it.appendLine("/* This file is generated with buildSrc/src/main/kotlin/space/kscience/kmath/ejml/codegen/ejmlCodegen.kt */")
diff --git a/docs/images/KM.svg b/docs/images/KM.svg
index f5ec452c7..83af21f35 100644
--- a/docs/images/KM.svg
+++ b/docs/images/KM.svg
@@ -1,9 +1,4 @@
-
-
-
-
-
-
-
-
+ val element = AlgebraND.double(2, 2).complex().produce { (i, j) ->
Complex(i.toDouble() - j.toDouble(), i.toDouble() + j.toDouble())
}
println(element)
// 1d element operation
- val result = with(AlgebraND.complex(8)) {
+ val result = with(AlgebraND.double(8).complex()) {
val a = produce { (it) -> i * it - it.toDouble() }
val b = 3
val c = Complex(1.0, 1.0)
diff --git a/examples/src/main/kotlin/space/kscience/kmath/stat/DistributionBenchmark.kt b/examples/src/main/kotlin/space/kscience/kmath/stat/DistributionBenchmark.kt
index 732c9a8e3..8e3cdf86f 100644
--- a/examples/src/main/kotlin/space/kscience/kmath/stat/DistributionBenchmark.kt
+++ b/examples/src/main/kotlin/space/kscience/kmath/stat/DistributionBenchmark.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.stat
diff --git a/examples/src/main/kotlin/space/kscience/kmath/stat/DistributionDemo.kt b/examples/src/main/kotlin/space/kscience/kmath/stat/DistributionDemo.kt
index 685214c39..bde83cea9 100644
--- a/examples/src/main/kotlin/space/kscience/kmath/stat/DistributionDemo.kt
+++ b/examples/src/main/kotlin/space/kscience/kmath/stat/DistributionDemo.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.stat
diff --git a/examples/src/main/kotlin/space/kscience/kmath/structures/ComplexND.kt b/examples/src/main/kotlin/space/kscience/kmath/structures/ComplexND.kt
index 752e00bdf..867415a20 100644
--- a/examples/src/main/kotlin/space/kscience/kmath/structures/ComplexND.kt
+++ b/examples/src/main/kotlin/space/kscience/kmath/structures/ComplexND.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@file:Suppress("unused")
@@ -12,19 +12,19 @@ import space.kscience.kmath.linear.transpose
import space.kscience.kmath.nd.AlgebraND
import space.kscience.kmath.nd.StructureND
import space.kscience.kmath.nd.as2D
-import space.kscience.kmath.nd.real
-import space.kscience.kmath.operations.invoke
+import space.kscience.kmath.nd.double
+import space.kscience.kmath.operations.*
import kotlin.system.measureTimeMillis
fun main() {
val dim = 1000
val n = 1000
- val realField = AlgebraND.real(dim, dim)
- val complexField: ComplexFieldND = AlgebraND.complex(dim, dim)
+ val doubleField = AlgebraND.double(dim, dim)
+ val complexField = doubleField.complex()
val realTime = measureTimeMillis {
- realField {
+ doubleField {
var res: StructureND = one
repeat(n) {
res += 1.0
@@ -36,9 +36,9 @@ fun main() {
val complexTime = measureTimeMillis {
complexField {
- var res: StructureND = one
+ var res: StructureND> = one
repeat(n) {
- res += 1.0
+ res += Complex(1.0, 0.0)
}
}
}
@@ -48,18 +48,16 @@ fun main() {
fun complexExample() {
//Create a context for 2-d structure with complex values
- ComplexField {
- nd(4, 8) {
- //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
+ AlgebraND.double(4, 8).complex().run {
+ //a constant real-valued structure
+ val x = one * 2.5
+ operator fun Number.plus(other: Complex) = Complex(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 + Complex(1.0,0.0)
- //Represent the sum as 2d-structure and transpose
- sum.as2D().transpose()
- }
+ //Represent the sum as 2d-structure and transpose
+ sum.as2D().transpose()
}
}
diff --git a/examples/src/main/kotlin/space/kscience/kmath/structures/NDField.kt b/examples/src/main/kotlin/space/kscience/kmath/structures/NDField.kt
index c842960be..7aee95395 100644
--- a/examples/src/main/kotlin/space/kscience/kmath/structures/NDField.kt
+++ b/examples/src/main/kotlin/space/kscience/kmath/structures/NDField.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.structures
@@ -32,8 +32,8 @@ fun main() {
// automatically build context most suited for given type.
val autoField = AlgebraND.auto(DoubleField, dim, dim)
- // specialized nd-field for Double. It works as generic Double field as well.
- val realField = AlgebraND.real(dim, dim)
+ // specialized nd-field for Double. It works as generic Double field as well
+ val realField = AlgebraND.double(dim, dim)
//A generic boxing field. It should be used for objects, not primitives.
val boxingField = AlgebraND.field(DoubleField, Buffer.Companion::boxing, dim, dim)
// Nd4j specialized field.
diff --git a/examples/src/main/kotlin/space/kscience/kmath/structures/StreamDoubleFieldND.kt b/examples/src/main/kotlin/space/kscience/kmath/structures/StreamDoubleFieldND.kt
index e443a588d..d53cfa9b9 100644
--- a/examples/src/main/kotlin/space/kscience/kmath/structures/StreamDoubleFieldND.kt
+++ b/examples/src/main/kotlin/space/kscience/kmath/structures/StreamDoubleFieldND.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.structures
diff --git a/examples/src/main/kotlin/space/kscience/kmath/structures/StructureReadBenchmark.kt b/examples/src/main/kotlin/space/kscience/kmath/structures/StructureReadBenchmark.kt
index 84dd6538c..0d5358354 100644
--- a/examples/src/main/kotlin/space/kscience/kmath/structures/StructureReadBenchmark.kt
+++ b/examples/src/main/kotlin/space/kscience/kmath/structures/StructureReadBenchmark.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.structures
diff --git a/examples/src/main/kotlin/space/kscience/kmath/structures/StructureWriteBenchmark.kt b/examples/src/main/kotlin/space/kscience/kmath/structures/StructureWriteBenchmark.kt
index 84644ddd9..dea7095a8 100644
--- a/examples/src/main/kotlin/space/kscience/kmath/structures/StructureWriteBenchmark.kt
+++ b/examples/src/main/kotlin/space/kscience/kmath/structures/StructureWriteBenchmark.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.structures
diff --git a/examples/src/main/kotlin/space/kscience/kmath/structures/typeSafeDimensions.kt b/examples/src/main/kotlin/space/kscience/kmath/structures/typeSafeDimensions.kt
index 853ebad32..c28b566b9 100644
--- a/examples/src/main/kotlin/space/kscience/kmath/structures/typeSafeDimensions.kt
+++ b/examples/src/main/kotlin/space/kscience/kmath/structures/typeSafeDimensions.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.structures
diff --git a/examples/src/main/kotlin/space/kscience/kmath/tensors/DataSetNormalization.kt b/examples/src/main/kotlin/space/kscience/kmath/tensors/DataSetNormalization.kt
index 3ef745da3..ad6890b15 100644
--- a/examples/src/main/kotlin/space/kscience/kmath/tensors/DataSetNormalization.kt
+++ b/examples/src/main/kotlin/space/kscience/kmath/tensors/DataSetNormalization.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.tensors
diff --git a/examples/src/main/kotlin/space/kscience/kmath/tensors/LinearSystemSolvingWithLUP.kt b/examples/src/main/kotlin/space/kscience/kmath/tensors/LinearSystemSolvingWithLUP.kt
index 27886413f..3e6a60c31 100644
--- a/examples/src/main/kotlin/space/kscience/kmath/tensors/LinearSystemSolvingWithLUP.kt
+++ b/examples/src/main/kotlin/space/kscience/kmath/tensors/LinearSystemSolvingWithLUP.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.tensors
diff --git a/examples/src/main/kotlin/space/kscience/kmath/tensors/NeuralNetwork.kt b/examples/src/main/kotlin/space/kscience/kmath/tensors/NeuralNetwork.kt
index 3025ff8a3..55a9aa67a 100644
--- a/examples/src/main/kotlin/space/kscience/kmath/tensors/NeuralNetwork.kt
+++ b/examples/src/main/kotlin/space/kscience/kmath/tensors/NeuralNetwork.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.tensors
diff --git a/examples/src/main/kotlin/space/kscience/kmath/tensors/OLSWithSVD.kt b/examples/src/main/kotlin/space/kscience/kmath/tensors/OLSWithSVD.kt
index a266d4849..b42602988 100644
--- a/examples/src/main/kotlin/space/kscience/kmath/tensors/OLSWithSVD.kt
+++ b/examples/src/main/kotlin/space/kscience/kmath/tensors/OLSWithSVD.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.tensors
diff --git a/examples/src/main/kotlin/space/kscience/kmath/tensors/PCA.kt b/examples/src/main/kotlin/space/kscience/kmath/tensors/PCA.kt
index 3302b49a8..b973abdef 100644
--- a/examples/src/main/kotlin/space/kscience/kmath/tensors/PCA.kt
+++ b/examples/src/main/kotlin/space/kscience/kmath/tensors/PCA.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.tensors
diff --git a/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/parser.kt b/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/parser.kt
index b02cc926b..5201fec38 100644
--- a/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/parser.kt
+++ b/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/parser.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.ast
diff --git a/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/LatexSyntaxRenderer.kt b/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/LatexSyntaxRenderer.kt
index bf5916fa5..2df3d3cc7 100644
--- a/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/LatexSyntaxRenderer.kt
+++ b/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/LatexSyntaxRenderer.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.ast.rendering
diff --git a/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/MathMLSyntaxRenderer.kt b/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/MathMLSyntaxRenderer.kt
index 5439c42fa..8b5819b84 100644
--- a/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/MathMLSyntaxRenderer.kt
+++ b/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/MathMLSyntaxRenderer.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.ast.rendering
diff --git a/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/MathRenderer.kt b/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/MathRenderer.kt
index 24bac425a..fdef35ebd 100644
--- a/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/MathRenderer.kt
+++ b/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/MathRenderer.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.ast.rendering
diff --git a/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/MathSyntax.kt b/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/MathSyntax.kt
index 81b7d2afb..ee23ab408 100644
--- a/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/MathSyntax.kt
+++ b/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/MathSyntax.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.ast.rendering
diff --git a/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/SyntaxRenderer.kt b/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/SyntaxRenderer.kt
index 2f285c600..362c07d72 100644
--- a/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/SyntaxRenderer.kt
+++ b/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/SyntaxRenderer.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.ast.rendering
diff --git a/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/features.kt b/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/features.kt
index a7a28d87f..8a4804916 100644
--- a/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/features.kt
+++ b/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/features.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.ast.rendering
diff --git a/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/multiplatformToString.kt b/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/multiplatformToString.kt
index 3e33d6415..291399cee 100644
--- a/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/multiplatformToString.kt
+++ b/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/multiplatformToString.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.ast.rendering
diff --git a/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/phases.kt b/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/phases.kt
index 3d05e03d6..574bb54f4 100644
--- a/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/phases.kt
+++ b/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/phases.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.ast.rendering
diff --git a/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/TestCompilerConsistencyWithInterpreter.kt b/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/TestCompilerConsistencyWithInterpreter.kt
index 802d4c10e..1edb5923e 100644
--- a/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/TestCompilerConsistencyWithInterpreter.kt
+++ b/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/TestCompilerConsistencyWithInterpreter.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.ast
diff --git a/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/TestCompilerOperations.kt b/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/TestCompilerOperations.kt
index f5b1e2842..929d17775 100644
--- a/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/TestCompilerOperations.kt
+++ b/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/TestCompilerOperations.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.ast
diff --git a/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/TestCompilerVariables.kt b/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/TestCompilerVariables.kt
index 8d9a2301f..af1a2e338 100644
--- a/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/TestCompilerVariables.kt
+++ b/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/TestCompilerVariables.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.ast
diff --git a/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/TestParser.kt b/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/TestParser.kt
index 4c834a9ca..0aadd8f6b 100644
--- a/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/TestParser.kt
+++ b/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/TestParser.kt
@@ -1,11 +1,12 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.ast
import space.kscience.kmath.complex.Complex
+import space.kscience.kmath.complex.ComplexDoubleField
import space.kscience.kmath.complex.ComplexField
import space.kscience.kmath.expressions.evaluate
import space.kscience.kmath.operations.Algebra
@@ -17,15 +18,15 @@ internal class TestParser {
@Test
fun evaluateParsedMst() {
val mst = "2+2*(2+2)".parseMath()
- val res = ComplexField.evaluate(mst)
+ val res = ComplexDoubleField.evaluate(mst)
assertEquals(Complex(10.0, 0.0), res)
}
@Test
fun evaluateMstSymbol() {
val mst = "i".parseMath()
- val res = ComplexField.evaluate(mst)
- assertEquals(ComplexField.i, res)
+ val res = ComplexDoubleField.evaluate(mst)
+ assertEquals(ComplexDoubleField.i, res)
}
diff --git a/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/TestParserPrecedence.kt b/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/TestParserPrecedence.kt
index 9776da45c..bb6bb3ce1 100644
--- a/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/TestParserPrecedence.kt
+++ b/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/TestParserPrecedence.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.ast
diff --git a/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/rendering/TestFeatures.kt b/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/rendering/TestFeatures.kt
index ae429d97e..a40c785b9 100644
--- a/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/rendering/TestFeatures.kt
+++ b/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/rendering/TestFeatures.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.ast.rendering
diff --git a/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/rendering/TestLatex.kt b/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/rendering/TestLatex.kt
index d8e432230..6322df25d 100644
--- a/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/rendering/TestLatex.kt
+++ b/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/rendering/TestLatex.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.ast.rendering
diff --git a/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/rendering/TestMathML.kt b/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/rendering/TestMathML.kt
index a7fcbc75b..2d7bfad19 100644
--- a/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/rendering/TestMathML.kt
+++ b/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/rendering/TestMathML.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.ast.rendering
diff --git a/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/rendering/TestStages.kt b/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/rendering/TestStages.kt
index 4485605a6..09ec127c7 100644
--- a/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/rendering/TestStages.kt
+++ b/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/rendering/TestStages.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.ast.rendering
diff --git a/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/rendering/TestUtils.kt b/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/rendering/TestUtils.kt
index 6b418821b..bf87b6fd0 100644
--- a/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/rendering/TestUtils.kt
+++ b/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/rendering/TestUtils.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.ast.rendering
diff --git a/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/utils.kt b/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/utils.kt
index ef9f3145a..ec7436188 100644
--- a/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/utils.kt
+++ b/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/utils.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.ast
diff --git a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/ast/rendering/multiplatformToString.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/ast/rendering/multiplatformToString.kt
index 2e69a536f..521907d2c 100644
--- a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/ast/rendering/multiplatformToString.kt
+++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/ast/rendering/multiplatformToString.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.ast.rendering
diff --git a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/estree.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/estree.kt
index 316fdeeff..0c15e994c 100644
--- a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/estree.kt
+++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/estree.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.estree
diff --git a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/internal/ESTreeBuilder.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/internal/ESTreeBuilder.kt
index 850f20be7..4907d8225 100644
--- a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/internal/ESTreeBuilder.kt
+++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/internal/ESTreeBuilder.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.estree.internal
diff --git a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/internal/astring/astring.typealises.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/internal/astring/astring.typealises.kt
index c7faf73e0..eb5c1e3dd 100644
--- a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/internal/astring/astring.typealises.kt
+++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/internal/astring/astring.typealises.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.estree.internal.astring
diff --git a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/astring/astring.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/astring/astring.kt
index c36860654..cca2d83af 100644
--- a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/astring/astring.kt
+++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/astring/astring.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@file:JsModule("astring")
diff --git a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/astring/astring.typealises.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/astring/astring.typealises.kt
index 0a5b059ba..93b4f6ce6 100644
--- a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/astring/astring.typealises.kt
+++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/astring/astring.typealises.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.internal.astring
diff --git a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/base64/base64.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/base64/base64.kt
index 26186c453..86e0cede7 100644
--- a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/base64/base64.kt
+++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/base64/base64.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@file:Suppress(
diff --git a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/binaryen/index.binaryen.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/binaryen/index.binaryen.kt
index 13e3a49e2..42b6ac7d8 100644
--- a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/binaryen/index.binaryen.kt
+++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/binaryen/index.binaryen.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@file:Suppress(
diff --git a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/binaryen/index.binaryen.typealiases.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/binaryen/index.binaryen.typealiases.kt
index 8e449627c..523b13b40 100644
--- a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/binaryen/index.binaryen.typealiases.kt
+++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/binaryen/index.binaryen.typealiases.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@file:Suppress("PackageDirectoryMismatch", "NO_EXPLICIT_VISIBILITY_IN_API_MODE_WARNING", "KDocMissingDocumentation")
diff --git a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/emitter/emitter.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/emitter/emitter.kt
index d85857de8..1f7b09af8 100644
--- a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/emitter/emitter.kt
+++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/emitter/emitter.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.internal.emitter
diff --git a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/estree/estree.extensions.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/estree/estree.extensions.kt
index 122a3a397..3aa31f921 100644
--- a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/estree/estree.extensions.kt
+++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/estree/estree.extensions.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.internal.estree
diff --git a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/estree/estree.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/estree/estree.kt
index ad079dbd0..b62b8c06c 100644
--- a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/estree/estree.kt
+++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/estree/estree.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@file:Suppress("ClassName")
diff --git a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/stream/stream.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/stream/stream.kt
index caab91731..52be5530f 100644
--- a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/stream/stream.kt
+++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/stream/stream.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.internal.stream
diff --git a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/tsstdlib/lib.es2015.iterable.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/tsstdlib/lib.es2015.iterable.kt
index 5c091e3a1..9c012e3a3 100644
--- a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/tsstdlib/lib.es2015.iterable.kt
+++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/tsstdlib/lib.es2015.iterable.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.internal.tsstdlib
diff --git a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/tsstdlib/lib.es5.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/tsstdlib/lib.es5.kt
index bb7fd44ca..0cd395f2c 100644
--- a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/tsstdlib/lib.es5.kt
+++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/tsstdlib/lib.es5.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@file:Suppress("UNUSED_TYPEALIAS_PARAMETER", "DEPRECATION")
diff --git a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/webassembly/lib.dom.WebAssembly.module_dukat.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/webassembly/lib.dom.WebAssembly.module_dukat.kt
index 52dd64a5e..3754c3eff 100644
--- a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/webassembly/lib.dom.WebAssembly.module_dukat.kt
+++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/webassembly/lib.dom.WebAssembly.module_dukat.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@file:JsQualifier("WebAssembly")
diff --git a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/webassembly/nonDeclarations.WebAssembly.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/webassembly/nonDeclarations.WebAssembly.kt
index d59a52701..c5023c384 100644
--- a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/webassembly/nonDeclarations.WebAssembly.kt
+++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/webassembly/nonDeclarations.WebAssembly.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@file:Suppress(
diff --git a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/wasm/internal/WasmBuilder.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/wasm/internal/WasmBuilder.kt
index 5b6cf65db..c89ad83c4 100644
--- a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/wasm/internal/WasmBuilder.kt
+++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/wasm/internal/WasmBuilder.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.wasm.internal
diff --git a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/wasm/internal/f64StandardFunctions.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/wasm/internal/f64StandardFunctions.kt
index fe9c22c18..21a88b5d0 100644
--- a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/wasm/internal/f64StandardFunctions.kt
+++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/wasm/internal/f64StandardFunctions.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.wasm.internal
diff --git a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/wasm/wasm.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/wasm/wasm.kt
index 5b28b8782..6ea8f26c1 100644
--- a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/wasm/wasm.kt
+++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/wasm/wasm.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.wasm
diff --git a/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/ast/TestExecutionTime.kt b/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/ast/TestExecutionTime.kt
index f8c429d5a..d0e8128b4 100644
--- a/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/ast/TestExecutionTime.kt
+++ b/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/ast/TestExecutionTime.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.ast
@@ -11,21 +11,19 @@ import space.kscience.kmath.operations.bindSymbol
import space.kscience.kmath.operations.invoke
import kotlin.math.sin
import kotlin.random.Random
-import kotlin.test.Ignore
import kotlin.test.Test
import kotlin.time.measureTime
import space.kscience.kmath.estree.compileToExpression as estreeCompileToExpression
import space.kscience.kmath.wasm.compileToExpression as wasmCompileToExpression
// TODO move to benchmarks when https://github.com/Kotlin/kotlinx-benchmark/pull/38 or similar feature is merged
-@Ignore
internal class TestExecutionTime {
private companion object {
private const val times = 1_000_000
private val x by symbol
private val algebra = DoubleField
- private val functional = algebra.expressionInExtendedField {
+ private val functional = DoubleField.expressionInExtendedField {
bindSymbol(x) * const(2.0) + const(2.0) / bindSymbol(x) - const(16.0) / sin(bindSymbol(x))
}
@@ -33,9 +31,9 @@ internal class TestExecutionTime {
x * number(2.0) + number(2.0) / x - number(16.0) / sin(x)
}
- private val mst = node.toExpression(algebra)
- private val wasm = node.wasmCompileToExpression(algebra)
- private val estree = node.estreeCompileToExpression(algebra)
+ private val mst = node.toExpression(DoubleField)
+ private val wasm = node.wasmCompileToExpression(DoubleField)
+ private val estree = node.estreeCompileToExpression(DoubleField)
// In JavaScript, the expression below is implemented like
// _no_name_provided__125.prototype.invoke_178 = function (args) {
@@ -46,7 +44,7 @@ internal class TestExecutionTime {
private val raw = Expression { args ->
val x = args[x]!!
- algebra { x * 2.0 + 2.0 / x - 16.0 / sin(x) }
+ x * 2.0 + 2.0 / x - 16.0 / sin(x)
}
private val justCalculate = { args: dynamic ->
diff --git a/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/ast/utils.kt b/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/ast/utils.kt
index 3c2a9bd13..0d896c6f6 100644
--- a/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/ast/utils.kt
+++ b/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/ast/utils.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.ast
diff --git a/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/wasm/TestWasmSpecific.kt b/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/wasm/TestWasmSpecific.kt
index 6c91df866..8ae5fcb36 100644
--- a/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/wasm/TestWasmSpecific.kt
+++ b/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/wasm/TestWasmSpecific.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.wasm
diff --git a/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/asm.kt b/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/asm.kt
index 2426d6ee4..4147324ee 100644
--- a/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/asm.kt
+++ b/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/asm.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.asm
diff --git a/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/internal/AsmBuilder.kt b/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/internal/AsmBuilder.kt
index de7da30df..a796ae2a5 100644
--- a/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/internal/AsmBuilder.kt
+++ b/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/internal/AsmBuilder.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.asm.internal
diff --git a/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/internal/codegenUtils.kt b/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/internal/codegenUtils.kt
index 5e2e7d8c6..06e040e93 100644
--- a/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/internal/codegenUtils.kt
+++ b/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/internal/codegenUtils.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.asm.internal
diff --git a/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/internal/mapIntrinsics.kt b/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/internal/mapIntrinsics.kt
index 56cfa4cbf..8f4daecf9 100644
--- a/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/internal/mapIntrinsics.kt
+++ b/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/internal/mapIntrinsics.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@file:JvmName("MapIntrinsics")
diff --git a/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/ast/rendering/multiplatformToString.kt b/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/ast/rendering/multiplatformToString.kt
index 3e5253084..556adbe7d 100644
--- a/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/ast/rendering/multiplatformToString.kt
+++ b/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/ast/rendering/multiplatformToString.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.ast.rendering
diff --git a/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/ast/utils.kt b/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/ast/utils.kt
index a0bdd68a0..a7f0bb3fb 100644
--- a/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/ast/utils.kt
+++ b/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/ast/utils.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.ast
diff --git a/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/expressions/DerivativeStructureExpression.kt b/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/expressions/DerivativeStructureExpression.kt
index 8fafabf19..d5473063a 100644
--- a/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/expressions/DerivativeStructureExpression.kt
+++ b/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/expressions/DerivativeStructureExpression.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.commons.expressions
diff --git a/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/integration/CMGaussRuleIntegrator.kt b/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/integration/CMGaussRuleIntegrator.kt
index 58b69b3d8..4e174723d 100644
--- a/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/integration/CMGaussRuleIntegrator.kt
+++ b/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/integration/CMGaussRuleIntegrator.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.commons.integration
diff --git a/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/integration/CMIntegrator.kt b/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/integration/CMIntegrator.kt
index ee7bda251..bcddccdc4 100644
--- a/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/integration/CMIntegrator.kt
+++ b/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/integration/CMIntegrator.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.commons.integration
diff --git a/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/linear/CMMatrix.kt b/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/linear/CMMatrix.kt
index 3f8dccf27..1997a633e 100644
--- a/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/linear/CMMatrix.kt
+++ b/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/linear/CMMatrix.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.commons.linear
diff --git a/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/linear/CMSolver.kt b/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/linear/CMSolver.kt
index c5144c482..ee602ca06 100644
--- a/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/linear/CMSolver.kt
+++ b/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/linear/CMSolver.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.commons.linear
diff --git a/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/optimization/CMOptimization.kt b/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/optimization/CMOptimization.kt
index 03a1abafb..bca106e68 100644
--- a/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/optimization/CMOptimization.kt
+++ b/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/optimization/CMOptimization.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.commons.optimization
diff --git a/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/optimization/cmFit.kt b/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/optimization/cmFit.kt
index 267f2f1f9..645c41291 100644
--- a/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/optimization/cmFit.kt
+++ b/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/optimization/cmFit.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.commons.optimization
diff --git a/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/random/CMRandomGeneratorWrapper.kt b/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/random/CMRandomGeneratorWrapper.kt
index 28294cf14..6aeebb68c 100644
--- a/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/random/CMRandomGeneratorWrapper.kt
+++ b/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/random/CMRandomGeneratorWrapper.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.commons.random
diff --git a/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/transform/Transformations.kt b/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/transform/Transformations.kt
index 1a99e9fc6..177bf5ef1 100644
--- a/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/transform/Transformations.kt
+++ b/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/transform/Transformations.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.commons.transform
@@ -15,12 +15,11 @@ import space.kscience.kmath.streaming.spread
import space.kscience.kmath.structures.*
-
/**
* Streaming and buffer transformations
*/
public object Transformations {
- private fun Buffer.toArray(): Array =
+ private fun Buffer>.toArray(): Array =
Array(size) { org.apache.commons.math3.complex.Complex(get(it).re, get(it).im) }
private fun Buffer.asArray() = if (this is DoubleBuffer) {
@@ -40,14 +39,14 @@ public object Transformations {
public fun fourier(
normalization: DftNormalization = DftNormalization.STANDARD,
direction: TransformType = TransformType.FORWARD,
- ): SuspendBufferTransform = {
+ ): SuspendBufferTransform, Complex> = {
FastFourierTransformer(normalization).transform(it.toArray(), direction).asBuffer()
}
public fun realFourier(
normalization: DftNormalization = DftNormalization.STANDARD,
direction: TransformType = TransformType.FORWARD,
- ): SuspendBufferTransform = {
+ ): SuspendBufferTransform> = {
FastFourierTransformer(normalization).transform(it.asArray(), direction).asBuffer()
}
@@ -76,10 +75,10 @@ public object Transformations {
* Process given [Flow] with commons-math fft transformation
*/
@FlowPreview
-public fun Flow>.FFT(
+public fun Flow>>.FFT(
normalization: DftNormalization = DftNormalization.STANDARD,
direction: TransformType = TransformType.FORWARD,
-): Flow> {
+): Flow>> {
val transform = Transformations.fourier(normalization, direction)
return map { transform(it) }
}
@@ -89,7 +88,7 @@ public fun Flow>.FFT(
public fun Flow>.FFT(
normalization: DftNormalization = DftNormalization.STANDARD,
direction: TransformType = TransformType.FORWARD,
-): Flow> {
+): Flow>> {
val transform = Transformations.realFourier(normalization, direction)
return map(transform)
}
@@ -103,10 +102,10 @@ public fun Flow.FFT(
bufferSize: Int = Int.MAX_VALUE,
normalization: DftNormalization = DftNormalization.STANDARD,
direction: TransformType = TransformType.FORWARD,
-): Flow = chunked(bufferSize).FFT(normalization, direction).spread()
+): Flow> = chunked(bufferSize).FFT(normalization, direction).spread()
/**
* Map a complex flow into real flow by taking real part of each number
*/
@FlowPreview
-public fun Flow.real(): Flow = map { it.re }
+public fun Flow>.real(): Flow = map { it.re }
diff --git a/kmath-commons/src/test/kotlin/space/kscience/kmath/commons/expressions/DerivativeStructureExpressionTest.kt b/kmath-commons/src/test/kotlin/space/kscience/kmath/commons/expressions/DerivativeStructureExpressionTest.kt
index 4ed4f808f..3c57f5467 100644
--- a/kmath-commons/src/test/kotlin/space/kscience/kmath/commons/expressions/DerivativeStructureExpressionTest.kt
+++ b/kmath-commons/src/test/kotlin/space/kscience/kmath/commons/expressions/DerivativeStructureExpressionTest.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.commons.expressions
diff --git a/kmath-commons/src/test/kotlin/space/kscience/kmath/commons/integration/IntegrationTest.kt b/kmath-commons/src/test/kotlin/space/kscience/kmath/commons/integration/IntegrationTest.kt
index bab3aecb6..c5573fef1 100644
--- a/kmath-commons/src/test/kotlin/space/kscience/kmath/commons/integration/IntegrationTest.kt
+++ b/kmath-commons/src/test/kotlin/space/kscience/kmath/commons/integration/IntegrationTest.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.commons.integration
diff --git a/kmath-commons/src/test/kotlin/space/kscience/kmath/commons/optimization/OptimizeTest.kt b/kmath-commons/src/test/kotlin/space/kscience/kmath/commons/optimization/OptimizeTest.kt
index 2f7f0c9f2..b0e5d7904 100644
--- a/kmath-commons/src/test/kotlin/space/kscience/kmath/commons/optimization/OptimizeTest.kt
+++ b/kmath-commons/src/test/kotlin/space/kscience/kmath/commons/optimization/OptimizeTest.kt
@@ -1,6 +1,6 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.commons.optimization
diff --git a/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/Complex.kt b/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/Complex.kt
index 08bd12205..eb9a3be7e 100644
--- a/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/Complex.kt
+++ b/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/Complex.kt
@@ -1,227 +1,252 @@
/*
* Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.complex
-import space.kscience.kmath.memory.MemoryReader
-import space.kscience.kmath.memory.MemorySpec
-import space.kscience.kmath.memory.MemoryWriter
-import space.kscience.kmath.misc.UnstableKMathAPI
-import space.kscience.kmath.operations.ExtendedField
-import space.kscience.kmath.operations.Norm
-import space.kscience.kmath.operations.NumbersAddOperations
-import space.kscience.kmath.operations.ScaleOperations
-import space.kscience.kmath.structures.Buffer
-import space.kscience.kmath.structures.MemoryBuffer
-import space.kscience.kmath.structures.MutableBuffer
-import space.kscience.kmath.structures.MutableMemoryBuffer
-import kotlin.math.*
+import space.kscience.kmath.operations.*
+import kotlin.js.JsName
+import kotlin.jvm.JvmName
/**
- * This complex's conjugate.
+ * Represents generic complex value consisting of real and imaginary part.
+ *
+ * @param T the type of components.
+ * @property re The real component.
+ * @property im The imaginary component.
*/
-public val Complex.conjugate: Complex
- get() = Complex(re, -im)
+public data class Complex(public val re: T, public val im: T) {
+ /**
+ * Converts this complex number to string formatted like `[re] + i * [im]`.
+ */
+ override fun toString(): String = "$re + i * $im"
+}
/**
- * This complex's reciprocal.
+ * The algebra of [Complex].
+ *
+ * @param T the type of components.
+ * @property algebra the algebra over [T].
*/
-public val Complex.reciprocal: Complex
- get() {
- val scale = re * re + im * im
- return Complex(re / scale, -im / scale)
- }
-
-/**
- * Absolute value of complex number.
- */
-public val Complex.r: Double
- get() = sqrt(re * re + im * im)
-
-/**
- * An angle between vector represented by complex number and X axis.
- */
-public val Complex.theta: Double
- get() = atan(im / re)
-
-private val PI_DIV_2 = Complex(PI / 2, 0)
-
-/**
- * A field of [Complex].
- */
-@OptIn(UnstableKMathAPI::class)
-public object ComplexField : ExtendedField, Norm, NumbersAddOperations,
- ScaleOperations {
- override val zero: Complex = 0.0.toComplex()
- override val one: Complex = 1.0.toComplex()
-
+public open class ComplexAlgebra(public open val algebra: NumericAlgebra) : NumericAlgebra> {
/**
* The imaginary unit.
*/
- public val i: Complex by lazy { Complex(0.0, 1.0) }
-
- override fun Complex.unaryMinus(): Complex = Complex(-re, -im)
-
- override fun number(value: Number): Complex = Complex(value.toDouble(), 0.0)
-
- override fun scale(a: Complex, value: Double): Complex = Complex(a.re * value, a.im * value)
-
- override fun add(a: Complex, b: Complex): Complex = Complex(a.re + b.re, a.im + b.im)
-// override fun multiply(a: Complex, k: Number): Complex = Complex(a.re * k.toDouble(), a.im * k.toDouble())
-
- 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 = when {
- abs(b.im) < abs(b.re) -> {
- val wr = b.im / b.re
- val wd = b.re + wr * b.im
-
- if (wd.isNaN() || wd == 0.0)
- throw ArithmeticException("Division by zero or infinity")
- else
- Complex((a.re + a.im * wr) / wd, (a.im - a.re * wr) / wd)
- }
-
- b.im == 0.0 -> throw ArithmeticException("Division by zero")
-
- else -> {
- val wr = b.re / b.im
- val wd = b.im + wr * b.re
-
- if (wd.isNaN() || wd == 0.0)
- throw ArithmeticException("Division by zero or infinity")
- else
- Complex((a.re * wr + a.im) / wd, (a.im * wr - a.re) / wd)
- }
+ public open val i: Complex by lazy {
+ algebra { Complex(number(0), number(1)) }
}
- override operator fun Complex.div(k: Number): Complex = Complex(re / k.toDouble(), im / k.toDouble())
+ override fun number(value: Number): Complex =
+ algebra { Complex(algebra.number(value), algebra.number(0)) }
- override fun sin(arg: Complex): Complex = i * (exp(-i * arg) - exp(i * arg)) / 2.0
- override fun cos(arg: Complex): Complex = (exp(-i * arg) + exp(i * arg)) / 2.0
+ override fun bindSymbol(value: String): Complex = if (value == "i") i else super.bindSymbol(value)
+}
- override fun tan(arg: Complex): Complex {
+/**
+ * The group of [Complex].
+ *
+ * @param T the type of components.
+ */
+public open class ComplexGroup(override val algebra: A) : ComplexAlgebra(algebra),
+ Group> where A : NumericAlgebra, A : Group {
+ override val zero: Complex by lazy {
+ algebra { Complex(zero, zero) }
+ }
+
+ /**
+ * This complex's conjugate.
+ */
+ public val Complex.conjugate: Complex
+ get() = Complex(re, algebra { -im })
+
+ override fun add(a: Complex, b: Complex): Complex = algebra { Complex(a.re + b.re, a.im + b.im) }
+
+ override fun Complex.unaryMinus(): Complex = algebra { Complex(-re, -im) }
+
+ @JsName("unaryMinus_T")
+ public operator fun T.unaryMinus(): Complex = algebra { Complex(-this@unaryMinus, zero) }
+
+ @JsName("unaryPlus_T")
+ public operator fun T.unaryPlus(): Complex = algebra { Complex(this@unaryPlus, zero) }
+
+ public operator fun T.plus(b: Complex): Complex = add(+this, b)
+ public operator fun Complex.plus(b: T): Complex = add(this, +b)
+ public operator fun T.minus(b: Complex): Complex = add(+this, -b)
+ public operator fun Complex.minus(b: T): Complex = add(this, -b)
+}
+
+/**
+ * The ring of [Complex].
+ *
+ * @param T the type of components.
+ */
+public open class ComplexRing(override val algebra: A) : ComplexGroup(algebra),
+ Ring> where A : NumericAlgebra, A : Ring {
+ override val one: Complex by lazy {
+ algebra { Complex(one, zero) }
+ }
+
+ override val i: Complex by lazy {
+ algebra { Complex(zero, one) }
+ }
+
+ override fun multiply(a: Complex, b: Complex): Complex =
+ algebra { Complex(a.re * b.re - a.im * b.im, a.im * b.re + a.re * b.im) }
+
+ public operator fun T.times(b: Complex): Complex = multiply(+this, b)
+ public operator fun Complex.times(b: T): Complex = multiply(this, +b)
+}
+
+/**
+ * [ComplexRing] instance for [ByteRing].
+ */
+public val ComplexByteRing: ComplexRing = ComplexRing(ByteRing)
+
+/**
+ * [ComplexRing] instance for [ShortRing].
+ */
+public val ComplexShortRing: ComplexRing = ComplexRing(ShortRing)
+
+/**
+ * [ComplexRing] instance for [IntRing].
+ */
+public val ComplexIntRing: ComplexRing = ComplexRing(IntRing)
+
+/**
+ * [ComplexRing] instance for [LongRing].
+ */
+public val ComplexLongRing: ComplexRing = ComplexRing(LongRing)
+
+/**
+ * The field of [Complex].
+ */
+public open class ComplexField(override val algebra: A) : ComplexRing(algebra),
+ Field> where A : Field {
+ /**
+ * This complex's reciprocal.
+ */
+ public val Complex.reciprocal: Complex
+ get() = algebra {
+ val scale = re * re + im * im
+ Complex(re / scale, -im / scale)
+ }
+
+ override fun divide(a: Complex, b: Complex): Complex = a * b.reciprocal
+
+ override fun number(value: Number): Complex = super.number(value)
+
+ override fun scale(a: Complex, value: Double): Complex =
+ algebra { Complex(a.re * value, a.im * value) }
+
+ override operator fun Complex.div(k: Number): Complex =
+ algebra { Complex(re / k.toDouble(), im / k.toDouble()) }
+
+ public operator fun T.div(b: Complex): Complex = divide(+this, b)
+ public operator fun Complex.div(b: T): Complex = divide(this, +b)
+
+ @JsName("scale_T")
+ public fun scale(a: T, value: Double): Complex = scale(+a, value)
+}
+
+
+/**
+ * [ComplexRing] instance for [BigIntField].
+ */
+public val ComplexBigIntField: ComplexField = ComplexField(BigIntField)
+
+
+/**
+ * The extended field of Complex.
+ */
+public open class ComplexExtendedField(override val algebra: A) : ComplexField(algebra),
+ ExtendedField>, Norm, T> where A : ExtendedField {
+ private val two by lazy { one + one }
+
+ /**
+ * The *r* component of the polar form of this number.
+ */
+ public val Complex.r: T
+ get() = norm(this)
+
+ /**
+ * The *θ* component of the polar form of this number.
+ */
+ public val Complex.theta: T
+ get() = algebra { atan(im / re) }
+
+ override fun bindSymbol(value: String): Complex =
+ if (value == "i") i else super.bindSymbol(value)
+
+ override fun sin(arg: Complex): Complex = i * (exp(-i * arg) - exp(i * arg)) / two
+ override fun cos(arg: Complex): Complex = (exp(-i * arg) + exp(i * arg)) / two
+
+ override fun tan(arg: Complex): Complex {
val e1 = exp(-i * arg)
val e2 = exp(i * arg)
return i * (e1 - e2) / (e1 + e2)
}
- override fun asin(arg: Complex): Complex = -i * ln(sqrt(1 - (arg * arg)) + i * arg)
- override fun acos(arg: Complex): Complex = PI_DIV_2 + i * ln(sqrt(1 - (arg * arg)) + i * arg)
+ override fun asin(arg: Complex): Complex = -i * ln(sqrt(one - (arg * arg)) + i * arg)
+ override fun acos(arg: Complex): Complex =
+ (pi / two) + i * ln(sqrt(one - (arg * arg)) + i * arg)
- override fun atan(arg: Complex): Complex {
+ override fun atan(arg: Complex): Complex = algebra {
val iArg = i * arg
- return i * (ln(1 - iArg) - ln(1 + iArg)) / 2
+ return i * (ln(this@ComplexExtendedField.one - iArg) - ln(this@ComplexExtendedField.one + iArg)) / 2
}
- 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 power(arg: Complex, pow: Number): Complex = algebra {
+ if (arg.im == 0.0)
+ Complex(arg.re.pow(pow.toDouble()), algebra.zero)
+ else
+ exp(pow * ln(arg))
+ }
- override fun exp(arg: Complex): Complex = exp(arg.re) * (cos(arg.im) + i * sin(arg.im))
+ override fun exp(arg: Complex): Complex =
+ Complex(algebra.exp(arg.re), algebra.zero) * Complex(algebra.cos(arg.im), algebra.sin(arg.im))
- override fun ln(arg: Complex): Complex = ln(arg.r) + i * atan2(arg.im, arg.re)
+ override fun ln(arg: Complex): Complex = algebra { Complex(ln(norm(arg)), atan(arg.im / arg.re)) }
+ override fun norm(arg: Complex): T = algebra { sqrt(arg.re * arg.re + arg.im * arg.im) }
- /**
- * Adds complex number to real one.
- *
- * @receiver the augend.
- * @param c the addend.
- * @return the sum.
- */
- public operator fun Double.plus(c: Complex): Complex = add(this.toComplex(), c)
+ @JsName("norm_T_3")
+ @JvmName("norm\$T")
+ public fun norm(arg: T): T = algebra { sqrt(arg * arg) }
- /**
- * Subtracts complex number from real one.
- *
- * @receiver the minuend.
- * @param c the subtrahend.
- * @return the difference.
- */
- public operator fun Double.minus(c: Complex): Complex = add(this.toComplex(), -c)
+ @JsName("sin_T")
+ public fun sin(arg: T): Complex = sin(+arg)
- /**
- * Adds real number to complex one.
- *
- * @receiver the augend.
- * @param d the addend.
- * @return the sum.
- */
- public operator fun Complex.plus(d: Double): Complex = d + this
+ @JsName("cos_T")
+ public fun cos(arg: T): Complex = cos(+arg)
- /**
- * Subtracts real number from complex one.
- *
- * @receiver the minuend.
- * @param d the subtrahend.
- * @return the difference.
- */
- public operator fun Complex.minus(d: Double): Complex = add(this, -d.toComplex())
+ @JsName("tan_T")
+ public fun tan(arg: T): Complex = tan(+arg)
- /**
- * Multiplies real number by complex one.
- *
- * @receiver the multiplier.
- * @param c the multiplicand.
- * @receiver the product.
- */
- public operator fun Double.times(c: Complex): Complex = Complex(c.re * this, c.im * this)
+ @JsName("asin_T")
+ public fun asin(arg: T): Complex = asin(+arg)
- override fun norm(arg: Complex): Complex = sqrt(arg.conjugate * arg)
+ @JsName("acos_T")
+ public fun acos(arg: T): Complex = acos(+arg)
- override fun bindSymbolOrNull(value: String): Complex? = if (value == "i") i else null
+ @JsName("atan_T")
+ public fun atan(arg: T): Complex = atan(+arg)
+
+ @JsName("power_T")
+ public fun power(arg: T, pow: Number): Complex = power(+arg, pow)
+
+ @JsName("exp_T")
+ public fun exp(arg: T): Complex = exp(+arg)
+
+ @JsName("ln_T")
+ public fun ln(arg: T): Complex = ln(+arg)
}
/**
- * Represents `double`-based complex number.
- *
- * @property re The real part.
- * @property im The imaginary part.
+ * [ComplexRing] instance for [DoubleField].
*/
-@OptIn(UnstableKMathAPI::class)
-public data class Complex(val re: Double, val im: Double) {
- public constructor(re: Number, im: Number) : this(re.toDouble(), im.toDouble())
- public constructor(re: Number) : this(re.toDouble(), 0.0)
-
- override fun toString(): String = "($re + i * $im)"
-
- public companion object : MemorySpec {
- override val objectSize: Int
- get() = 16
-
- override fun MemoryReader.read(offset: Int): Complex =
- Complex(readDouble(offset), readDouble(offset + 8))
-
- override fun MemoryWriter.write(offset: Int, value: Complex) {
- writeDouble(offset, value.re)
- writeDouble(offset + 8, value.im)
- }
- }
-}
-
+public val ComplexDoubleField: ComplexExtendedField = ComplexExtendedField(DoubleField)
/**
- * Creates a complex number with real part equal to this real.
- *
- * @receiver the real part.
- * @return the new complex number.
+ * [ComplexRing] instance for [FloatField].
*/
-public fun Number.toComplex(): Complex = Complex(this)
-
-/**
- * Creates a new buffer of complex numbers with the specified [size], where each element is calculated by calling the
- * specified [init] function.
- */
-public inline fun Buffer.Companion.complex(size: Int, init: (Int) -> Complex): Buffer =
- MemoryBuffer.create(Complex, size, init)
-
-/**
- * Creates a new buffer of complex numbers with the specified [size], where each element is calculated by calling the
- * specified [init] function.
- */
-public inline fun MutableBuffer.Companion.complex(size: Int, init: (Int) -> Complex): MutableBuffer =
- MutableMemoryBuffer.create(Complex, size, init)
+public val ComplexFloatField: ComplexExtendedField = ComplexExtendedField(DoubleField)
diff --git a/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/ComplexFieldND.kt b/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/ComplexFieldND.kt
deleted file mode 100644
index ae4e05631..000000000
--- a/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/ComplexFieldND.kt
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
- */
-
-package space.kscience.kmath.complex
-
-import space.kscience.kmath.misc.UnstableKMathAPI
-import space.kscience.kmath.nd.AlgebraND
-import space.kscience.kmath.nd.BufferND
-import space.kscience.kmath.nd.BufferedFieldND
-import space.kscience.kmath.nd.StructureND
-import space.kscience.kmath.operations.ExtendedField
-import space.kscience.kmath.operations.NumbersAddOperations
-import space.kscience.kmath.structures.Buffer
-import kotlin.contracts.InvocationKind
-import kotlin.contracts.contract
-
-
-/**
- * An optimized nd-field for complex numbers
- */
-@OptIn(UnstableKMathAPI::class)
-public class ComplexFieldND(
- shape: IntArray,
-) : BufferedFieldND(shape, ComplexField, Buffer.Companion::complex),
- NumbersAddOperations>,
- ExtendedField> {
-
- override val zero: BufferND by lazy { produce { zero } }
- override val one: BufferND by lazy { produce { one } }
-
- override fun number(value: Number): BufferND {
- val d = value.toComplex() // minimize conversions
- return produce { d }
- }
-
-//
-// @Suppress("OVERRIDE_BY_INLINE")
-// override inline fun map(
-// arg: AbstractNDBuffer,
-// transform: DoubleField.(Double) -> Double,
-// ): RealNDElement {
-// check(arg)
-// val array = RealBuffer(arg.strides.linearSize) { offset -> DoubleField.transform(arg.buffer[offset]) }
-// return BufferedNDFieldElement(this, array)
-// }
-//
-// @Suppress("OVERRIDE_BY_INLINE")
-// override inline fun produce(initializer: DoubleField.(IntArray) -> Double): RealNDElement {
-// val array = RealBuffer(strides.linearSize) { offset -> elementContext.initializer(strides.index(offset)) }
-// return BufferedNDFieldElement(this, array)
-// }
-//
-// @Suppress("OVERRIDE_BY_INLINE")
-// override inline fun mapIndexed(
-// arg: AbstractNDBuffer,
-// transform: DoubleField.(index: IntArray, Double) -> Double,
-// ): RealNDElement {
-// check(arg)
-// return BufferedNDFieldElement(
-// this,
-// RealBuffer(arg.strides.linearSize) { offset ->
-// elementContext.transform(
-// arg.strides.index(offset),
-// arg.buffer[offset]
-// )
-// })
-// }
-//
-// @Suppress("OVERRIDE_BY_INLINE")
-// override inline fun combine(
-// a: AbstractNDBuffer,
-// b: AbstractNDBuffer,
-// transform: DoubleField.(Double, Double) -> Double,
-// ): RealNDElement {
-// check(a, b)
-// val buffer = RealBuffer(strides.linearSize) { offset ->
-// elementContext.transform(a.buffer[offset], b.buffer[offset])
-// }
-// return BufferedNDFieldElement(this, buffer)
-// }
-
- override fun power(arg: StructureND, pow: Number): BufferND = arg.map { power(it, pow) }
-
- override fun exp(arg: StructureND): BufferND = arg.map { exp(it) }
-
- override fun ln(arg: StructureND): BufferND = arg.map { ln(it) }
-
- override fun sin(arg: StructureND): BufferND = arg.map { sin(it) }
- override fun cos(arg: StructureND): BufferND = arg.map { cos(it) }
- override fun tan(arg: StructureND): BufferND = arg.map { tan(it) }
- override fun asin(arg: StructureND): BufferND = arg.map { asin(it) }
- override fun acos(arg: StructureND): BufferND = arg.map { acos(it) }
- override fun atan(arg: StructureND): BufferND = arg.map { atan(it) }
-
- override fun sinh(arg: StructureND): BufferND = arg.map { sinh(it) }
- override fun cosh(arg: StructureND): BufferND = arg.map { cosh(it) }
- override fun tanh(arg: StructureND): BufferND = arg.map { tanh(it) }
- override fun asinh(arg: StructureND): BufferND = arg.map { asinh(it) }
- override fun acosh(arg: StructureND): BufferND = arg.map { acosh(it) }
- override fun atanh(arg: StructureND): BufferND = arg.map { atanh(it) }
-}
-
-
-/**
- * Fast element production using function inlining
- */
-public inline fun BufferedFieldND.produceInline(initializer: ComplexField.(Int) -> Complex): BufferND {
- contract { callsInPlace(initializer, InvocationKind.EXACTLY_ONCE) }
- val buffer = Buffer.complex(strides.linearSize) { offset -> ComplexField.initializer(offset) }
- return BufferND(strides, buffer)
-}
-
-
-public fun AlgebraND.Companion.complex(vararg shape: Int): ComplexFieldND = ComplexFieldND(shape)
-
-/**
- * Produce a context for n-dimensional operations inside this real field
- */
-public inline fun ComplexField.nd(vararg shape: Int, action: ComplexFieldND.() -> R): R {
- contract { callsInPlace(action, InvocationKind.EXACTLY_ONCE) }
- return ComplexFieldND(shape).action()
-}
diff --git a/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/DoubleQuaternion.kt b/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/DoubleQuaternion.kt
new file mode 100644
index 000000000..1857d48a1
--- /dev/null
+++ b/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/DoubleQuaternion.kt
@@ -0,0 +1,273 @@
+/*
+ * Copyright 2018-2021 KMath contributors.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ */
+
+package space.kscience.kmath.complex
+
+import space.kscience.kmath.memory.MemoryReader
+import space.kscience.kmath.memory.MemorySpec
+import space.kscience.kmath.memory.MemoryWriter
+import space.kscience.kmath.misc.UnstableKMathAPI
+import space.kscience.kmath.operations.*
+import space.kscience.kmath.structures.Buffer
+import space.kscience.kmath.structures.MemoryBuffer
+import space.kscience.kmath.structures.MutableBuffer
+import space.kscience.kmath.structures.MutableMemoryBuffer
+import kotlin.math.*
+
+/**
+ * This quaternion's conjugate.
+ */
+@UnstableKMathAPI
+public val DoubleQuaternion.conjugate: DoubleQuaternion
+ get() = DoubleQuaternionField { z - x * i - y * j - z * k }
+
+/**
+ * This quaternion's reciprocal.
+ */
+@UnstableKMathAPI
+public val DoubleQuaternion.reciprocal: DoubleQuaternion
+ get() = DoubleQuaternionField {
+ val n = norm(this@reciprocal)
+ return conjugate / (n * n)
+ }
+
+/**
+ * Absolute value of the quaternion.
+ */
+@UnstableKMathAPI
+public val DoubleQuaternion.r: Double
+ get() = sqrt(w * w + x * x + y * y + z * z)
+
+/**
+ * A field of [DoubleQuaternion].
+ */
+@UnstableKMathAPI
+public object DoubleQuaternionField : Field, Norm,
+ PowerOperations,
+ ExponentialOperations, NumbersAddOperations, ScaleOperations {
+ override val zero: DoubleQuaternion = DoubleQuaternion(0)
+ override val one: DoubleQuaternion = DoubleQuaternion(1)
+
+ /**
+ * The `i` quaternion unit.
+ */
+ public val i: DoubleQuaternion = DoubleQuaternion(0, 1)
+
+ /**
+ * The `j` quaternion unit.
+ */
+ public val j: DoubleQuaternion = DoubleQuaternion(0, 0, 1)
+
+ /**
+ * The `k` quaternion unit.
+ */
+ public val k: DoubleQuaternion = DoubleQuaternion(0, 0, 0, 1)
+
+ override fun add(a: DoubleQuaternion, b: DoubleQuaternion): DoubleQuaternion =
+ DoubleQuaternion(a.w + b.w, a.x + b.x, a.y + b.y, a.z + b.z)
+
+ override fun scale(a: DoubleQuaternion, value: Double): DoubleQuaternion =
+ DoubleQuaternion(a.w * value, a.x * value, a.y * value, a.z * value)
+
+ override fun multiply(a: DoubleQuaternion, b: DoubleQuaternion): DoubleQuaternion = DoubleQuaternion(
+ a.w * b.w - a.x * b.x - a.y * b.y - a.z * b.z,
+ a.w * b.x + a.x * b.w + a.y * b.z - a.z * b.y,
+ a.w * b.y - a.x * b.z + a.y * b.w + a.z * b.x,
+ a.w * b.z + a.x * b.y - a.y * b.x + a.z * b.w,
+ )
+
+ override fun divide(a: DoubleQuaternion, b: DoubleQuaternion): DoubleQuaternion {
+ val s = b.w * b.w + b.x * b.x + b.y * b.y + b.z * b.z
+
+ return DoubleQuaternion(
+ (b.w * a.w + b.x * a.x + b.y * a.y + b.z * a.z) / s,
+ (b.w * a.x - b.x * a.w - b.y * a.z + b.z * a.y) / s,
+ (b.w * a.y + b.x * a.z - b.y * a.w - b.z * a.x) / s,
+ (b.w * a.z - b.x * a.y + b.y * a.x - b.z * a.w) / s,
+ )
+ }
+
+ override fun power(arg: DoubleQuaternion, pow: Number): DoubleQuaternion {
+ if (pow is Int) return pwr(arg, pow)
+ if (floor(pow.toDouble()) == pow.toDouble()) return pwr(arg, pow.toInt())
+ return exp(pow * ln(arg))
+ }
+
+ private fun pwr(x: DoubleQuaternion, a: Int): DoubleQuaternion = when {
+ a < 0 -> -(pwr(x, -a))
+ a == 0 -> one
+ a == 1 -> x
+ a == 2 -> pwr2(x)
+ a == 3 -> pwr3(x)
+ a == 4 -> pwr4(x)
+
+ else -> {
+ val x4 = pwr4(x)
+ var y = x4
+ repeat((1 until a / 4).count()) { y *= x4 }
+ if (a % 4 == 3) y *= pwr3(x)
+ if (a % 4 == 2) y *= pwr2(x)
+ if (a % 4 == 1) y *= x
+ y
+ }
+ }
+
+ private fun pwr2(x: DoubleQuaternion): DoubleQuaternion {
+ val aa = 2 * x.w
+ return DoubleQuaternion(x.w * x.w - (x.x * x.x + x.y * x.y + x.z * x.z), aa * x.x, aa * x.y, aa * x.z)
+ }
+
+ private fun pwr3(x: DoubleQuaternion): DoubleQuaternion {
+ val a2 = x.w * x.w
+ val n1 = x.x * x.x + x.y * x.y + x.z * x.z
+ val n2 = 3.0 * a2 - n1
+ return DoubleQuaternion(x.w * (a2 - 3 * n1), x.x * n2, x.y * n2, x.z * n2)
+ }
+
+ private fun pwr4(x: DoubleQuaternion): DoubleQuaternion {
+ val a2 = x.w * x.w
+ val n1 = x.x * x.x + x.y * x.y + x.z * x.z
+ val n2 = 4 * x.w * (a2 - n1)
+ return DoubleQuaternion(a2 * a2 - 6 * a2 * n1 + n1 * n1, x.x * n2, x.y * n2, x.z * n2)
+ }
+
+ override fun exp(arg: DoubleQuaternion): DoubleQuaternion {
+ val un = arg.x * arg.x + arg.y * arg.y + arg.z * arg.z
+ if (un == 0.0) return DoubleQuaternion(exp(arg.w))
+ val n1 = sqrt(un)
+ val ea = exp(arg.w)
+ val n2 = ea * sin(n1) / n1
+ return DoubleQuaternion(ea * cos(n1), n2 * arg.x, n2 * arg.y, n2 * arg.z)
+ }
+
+ override fun ln(arg: DoubleQuaternion): DoubleQuaternion {
+ val nu2 = arg.x * arg.x + arg.y * arg.y + arg.z * arg.z
+
+ if (nu2 == 0.0)
+ return if (arg.w > 0)
+ DoubleQuaternion(ln(arg.w), 0, 0, 0)
+ else {
+ val l = ComplexDoubleField { ln(arg.w) }
+ DoubleQuaternion(l.re, l.im, 0, 0)
+ }
+
+ val a = arg.w
+ check(nu2 > 0)
+ val n = sqrt(a * a + nu2)
+ val th = acos(a / n) / sqrt(nu2)
+ return DoubleQuaternion(ln(n), th * arg.x, th * arg.y, th * arg.z)
+ }
+
+ override operator fun Number.plus(b: DoubleQuaternion): DoubleQuaternion =
+ DoubleQuaternion(toDouble() + b.w, b.x, b.y, b.z)
+
+ override operator fun Number.minus(b: DoubleQuaternion): DoubleQuaternion =
+ DoubleQuaternion(toDouble() - b.w, -b.x, -b.y, -b.z)
+
+ override operator fun DoubleQuaternion.plus(b: Number): DoubleQuaternion =
+ DoubleQuaternion(w + b.toDouble(), x, y, z)
+
+ override operator fun DoubleQuaternion.minus(b: Number): DoubleQuaternion =
+ DoubleQuaternion(w - b.toDouble(), x, y, z)
+
+ override operator fun Number.times(b: DoubleQuaternion): DoubleQuaternion =
+ DoubleQuaternion(toDouble() * b.w, toDouble() * b.x, toDouble() * b.y, toDouble() * b.z)
+
+ override fun DoubleQuaternion.unaryMinus(): DoubleQuaternion = DoubleQuaternion(-w, -x, -y, -z)
+ override fun norm(arg: DoubleQuaternion): DoubleQuaternion = sqrt(arg.conjugate * arg)
+
+ override fun bindSymbolOrNull(value: String): DoubleQuaternion? = when (value) {
+ "i" -> i
+ "j" -> j
+ "k" -> k
+ else -> null
+ }
+
+ override fun number(value: Number): DoubleQuaternion = DoubleQuaternion(value)
+
+ override fun sinh(arg: DoubleQuaternion): DoubleQuaternion = (exp(arg) - exp(-arg)) / 2.0
+ override fun cosh(arg: DoubleQuaternion): DoubleQuaternion = (exp(arg) + exp(-arg)) / 2.0
+ override fun tanh(arg: DoubleQuaternion): DoubleQuaternion = (exp(arg) - exp(-arg)) / (exp(-arg) + exp(arg))
+ override fun asinh(arg: DoubleQuaternion): DoubleQuaternion = ln(sqrt(arg * arg + one) + arg)
+ override fun acosh(arg: DoubleQuaternion): DoubleQuaternion = ln(arg + sqrt((arg - one) * (arg + one)))
+ override fun atanh(arg: DoubleQuaternion): DoubleQuaternion = (ln(arg + one) - ln(one - arg)) / 2.0
+}
+
+/**
+ * Represents `double`-based quaternion.
+ *
+ * @property w The first component.
+ * @property x The second component.
+ * @property y The third component.
+ * @property z The fourth component.
+ */
+@UnstableKMathAPI
+public data class DoubleQuaternion(
+ val w: Double, val x: Double, val y: Double, val z: Double,
+) {
+ public constructor(w: Number, x: Number, y: Number, z: Number) : this(
+ w.toDouble(),
+ x.toDouble(),
+ y.toDouble(),
+ z.toDouble(),
+ )
+
+ public constructor(w: Number, x: Number, y: Number) : this(w.toDouble(), x.toDouble(), y.toDouble(), 0.0)
+ public constructor(w: Number, x: Number) : this(w.toDouble(), x.toDouble(), 0.0, 0.0)
+ public constructor(w: Number) : this(w.toDouble(), 0.0, 0.0, 0.0)
+ public constructor(wx: Complex, yz: Complex) : this(wx.re, wx.im, yz.re, yz.im)
+ public constructor(wx: Complex) : this(wx.re, wx.im, 0, 0)
+
+ init {
+ require(!w.isNaN()) { "w-component of quaternion is not-a-number" }
+ require(!x.isNaN()) { "x-component of quaternion is not-a-number" }
+ require(!y.isNaN()) { "x-component of quaternion is not-a-number" }
+ require(!z.isNaN()) { "x-component of quaternion is not-a-number" }
+ }
+
+ /**
+ * Returns a string representation of this quaternion.
+ */
+ override fun toString(): String = "($w + $x * i + $y * j + $z * k)"
+
+ public companion object : MemorySpec {
+ override val objectSize: Int
+ get() = 32
+
+ override fun MemoryReader.read(offset: Int): DoubleQuaternion =
+ DoubleQuaternion(readDouble(offset),
+ readDouble(offset + 8),
+ readDouble(offset + 16),
+ readDouble(offset + 24))
+
+ override fun MemoryWriter.write(offset: Int, value: DoubleQuaternion) {
+ writeDouble(offset, value.w)
+ writeDouble(offset + 8, value.x)
+ writeDouble(offset + 16, value.y)
+ writeDouble(offset + 24, value.z)
+ }
+ }
+}
+
+/**
+ * Creates a new buffer of quaternions with the specified [size], where each element is calculated by calling the
+ * specified [init] function.
+ */
+@UnstableKMathAPI
+public inline fun Buffer.Companion.quaternion(size: Int, init: (Int) -> DoubleQuaternion): Buffer =
+ MemoryBuffer.create(DoubleQuaternion, size, init)
+
+/**
+ * Creates a new buffer of quaternions with the specified [size], where each element is calculated by calling the
+ * specified [init] function.
+ */
+@UnstableKMathAPI
+public inline fun MutableBuffer.Companion.quaternion(
+ size: Int,
+ init: (Int) -> DoubleQuaternion,
+): MutableBuffer =
+ MutableMemoryBuffer.create(DoubleQuaternion, size, init)
+
+
diff --git a/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/Quaternion.kt b/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/Quaternion.kt
deleted file mode 100644
index e5d7ebd1e..000000000
--- a/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/Quaternion.kt
+++ /dev/null
@@ -1,274 +0,0 @@
-/*
- * Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
- */
-
-package space.kscience.kmath.complex
-
-import space.kscience.kmath.memory.MemoryReader
-import space.kscience.kmath.memory.MemorySpec
-import space.kscience.kmath.memory.MemoryWriter
-import space.kscience.kmath.misc.UnstableKMathAPI
-import space.kscience.kmath.operations.*
-import space.kscience.kmath.structures.Buffer
-import space.kscience.kmath.structures.MemoryBuffer
-import space.kscience.kmath.structures.MutableBuffer
-import space.kscience.kmath.structures.MutableMemoryBuffer
-import kotlin.math.*
-
-/**
- * This quaternion's conjugate.
- */
-public val Quaternion.conjugate: Quaternion
- get() = QuaternionField { z - x * i - y * j - z * k }
-
-/**
- * This quaternion's reciprocal.
- */
-public val Quaternion.reciprocal: Quaternion
- get() {
- QuaternionField {
- val n = norm(this@reciprocal)
- return conjugate / (n * n)
- }
- }
-
-/**
- * Absolute value of the quaternion.
- */
-public val Quaternion.r: Double
- get() = sqrt(w * w + x * x + y * y + z * z)
-
-/**
- * A field of [Quaternion].
- */
-@OptIn(UnstableKMathAPI::class)
-public object QuaternionField : Field, Norm, PowerOperations,
- ExponentialOperations, NumbersAddOperations, ScaleOperations {
- override val zero: Quaternion = 0.toQuaternion()
- override val one: Quaternion = 1.toQuaternion()
-
- /**
- * The `i` quaternion unit.
- */
- public val i: Quaternion = Quaternion(0, 1)
-
- /**
- * The `j` quaternion unit.
- */
- public val j: Quaternion = Quaternion(0, 0, 1)
-
- /**
- * The `k` quaternion unit.
- */
- public val k: Quaternion = Quaternion(0, 0, 0, 1)
-
- override fun add(a: Quaternion, b: Quaternion): Quaternion =
- Quaternion(a.w + b.w, a.x + b.x, a.y + b.y, a.z + b.z)
-
- override fun scale(a: Quaternion, value: Double): Quaternion =
- Quaternion(a.w * value, a.x * value, a.y * value, a.z * value)
-
- override fun multiply(a: Quaternion, b: Quaternion): Quaternion = Quaternion(
- a.w * b.w - a.x * b.x - a.y * b.y - a.z * b.z,
- a.w * b.x + a.x * b.w + a.y * b.z - a.z * b.y,
- a.w * b.y - a.x * b.z + a.y * b.w + a.z * b.x,
- a.w * b.z + a.x * b.y - a.y * b.x + a.z * b.w,
- )
-
- override fun divide(a: Quaternion, b: Quaternion): Quaternion {
- val s = b.w * b.w + b.x * b.x + b.y * b.y + b.z * b.z
-
- return Quaternion(
- (b.w * a.w + b.x * a.x + b.y * a.y + b.z * a.z) / s,
- (b.w * a.x - b.x * a.w - b.y * a.z + b.z * a.y) / s,
- (b.w * a.y + b.x * a.z - b.y * a.w - b.z * a.x) / s,
- (b.w * a.z - b.x * a.y + b.y * a.x - b.z * a.w) / s,
- )
- }
-
- override fun power(arg: Quaternion, pow: Number): Quaternion {
- if (pow is Int) return pwr(arg, pow)
- if (floor(pow.toDouble()) == pow.toDouble()) return pwr(arg, pow.toInt())
- return exp(pow * ln(arg))
- }
-
- private fun pwr(x: Quaternion, a: Int): Quaternion = when {
- a < 0 -> -(pwr(x, -a))
- a == 0 -> one
- a == 1 -> x
- a == 2 -> pwr2(x)
- a == 3 -> pwr3(x)
- a == 4 -> pwr4(x)
-
- else -> {
- val x4 = pwr4(x)
- var y = x4
- repeat((1 until a / 4).count()) { y *= x4 }
- if (a % 4 == 3) y *= pwr3(x)
- if (a % 4 == 2) y *= pwr2(x)
- if (a % 4 == 1) y *= x
- y
- }
- }
-
- private fun pwr2(x: Quaternion): Quaternion {
- val aa = 2 * x.w
- return Quaternion(x.w * x.w - (x.x * x.x + x.y * x.y + x.z * x.z), aa * x.x, aa * x.y, aa * x.z)
- }
-
- private fun pwr3(x: Quaternion): Quaternion {
- val a2 = x.w * x.w
- val n1 = x.x * x.x + x.y * x.y + x.z * x.z
- val n2 = 3.0 * a2 - n1
- return Quaternion(x.w * (a2 - 3 * n1), x.x * n2, x.y * n2, x.z * n2)
- }
-
- private fun pwr4(x: Quaternion): Quaternion {
- val a2 = x.w * x.w
- val n1 = x.x * x.x + x.y * x.y + x.z * x.z
- val n2 = 4 * x.w * (a2 - n1)
- return Quaternion(a2 * a2 - 6 * a2 * n1 + n1 * n1, x.x * n2, x.y * n2, x.z * n2)
- }
-
- override fun exp(arg: Quaternion): Quaternion {
- val un = arg.x * arg.x + arg.y * arg.y + arg.z * arg.z
- if (un == 0.0) return exp(arg.w).toQuaternion()
- val n1 = sqrt(un)
- val ea = exp(arg.w)
- val n2 = ea * sin(n1) / n1
- return Quaternion(ea * cos(n1), n2 * arg.x, n2 * arg.y, n2 * arg.z)
- }
-
- override fun ln(arg: Quaternion): Quaternion {
- val nu2 = arg.x * arg.x + arg.y * arg.y + arg.z * arg.z
-
- if (nu2 == 0.0)
- return if (arg.w > 0)
- Quaternion(ln(arg.w), 0, 0, 0)
- else {
- val l = ComplexField { ln(arg.w.toComplex()) }
- Quaternion(l.re, l.im, 0, 0)
- }
-
- val a = arg.w
- check(nu2 > 0)
- val n = sqrt(a * a + nu2)
- val th = acos(a / n) / sqrt(nu2)
- return Quaternion(ln(n), th * arg.x, th * arg.y, th * arg.z)
- }
-
- override operator fun Number.plus(b: Quaternion): Quaternion = Quaternion(toDouble() + b.w, b.x, b.y, b.z)
-
- override operator fun Number.minus(b: Quaternion): Quaternion =
- Quaternion(toDouble() - b.w, -b.x, -b.y, -b.z)
-
- override operator fun Quaternion.plus(b: Number): Quaternion = Quaternion(w + b.toDouble(), x, y, z)
- override operator fun Quaternion.minus(b: Number): Quaternion = Quaternion(w - b.toDouble(), x, y, z)
-
- override operator fun Number.times(b: Quaternion): Quaternion =
- Quaternion(toDouble() * b.w, toDouble() * b.x, toDouble() * b.y, toDouble() * b.z)
-
- override fun Quaternion.unaryMinus(): Quaternion = Quaternion(-w, -x, -y, -z)
- override fun norm(arg: Quaternion): Quaternion = sqrt(arg.conjugate * arg)
-
- override fun bindSymbolOrNull(value: String): Quaternion? = when (value) {
- "i" -> i
- "j" -> j
- "k" -> k
- else -> null
- }
-
- override fun number(value: Number): Quaternion = value.toQuaternion()
-
- override fun sinh(arg: Quaternion): Quaternion = (exp(arg) - exp(-arg)) / 2.0
- override fun cosh(arg: Quaternion): Quaternion = (exp(arg) + exp(-arg)) / 2.0
- override fun tanh(arg: Quaternion): Quaternion = (exp(arg) - exp(-arg)) / (exp(-arg) + exp(arg))
- override fun asinh(arg: Quaternion): Quaternion = ln(sqrt(arg * arg + one) + arg)
- override fun acosh(arg: Quaternion): Quaternion = ln(arg + sqrt((arg - one) * (arg + one)))
- override fun atanh(arg: Quaternion): Quaternion = (ln(arg + one) - ln(one - arg)) / 2.0
-}
-
-/**
- * Represents `double`-based quaternion.
- *
- * @property w The first component.
- * @property x The second component.
- * @property y The third component.
- * @property z The fourth component.
- */
-@OptIn(UnstableKMathAPI::class)
-public data class Quaternion(
- val w: Double, val x: Double, val y: Double, val z: Double,
-) {
- public constructor(w: Number, x: Number, y: Number, z: Number) : this(
- w.toDouble(),
- x.toDouble(),
- y.toDouble(),
- z.toDouble(),
- )
-
- public constructor(w: Number, x: Number, y: Number) : this(w.toDouble(), x.toDouble(), y.toDouble(), 0.0)
- public constructor(w: Number, x: Number) : this(w.toDouble(), x.toDouble(), 0.0, 0.0)
- public constructor(w: Number) : this(w.toDouble(), 0.0, 0.0, 0.0)
- public constructor(wx: Complex, yz: Complex) : this(wx.re, wx.im, yz.re, yz.im)
- public constructor(wx: Complex) : this(wx.re, wx.im, 0, 0)
-
- init {
- require(!w.isNaN()) { "w-component of quaternion is not-a-number" }
- require(!x.isNaN()) { "x-component of quaternion is not-a-number" }
- require(!y.isNaN()) { "x-component of quaternion is not-a-number" }
- require(!z.isNaN()) { "x-component of quaternion is not-a-number" }
- }
-
- /**
- * Returns a string representation of this quaternion.
- */
- override fun toString(): String = "($w + $x * i + $y * j + $z * k)"
-
- public companion object : MemorySpec {
- override val objectSize: Int
- get() = 32
-
- override fun MemoryReader.read(offset: Int): Quaternion =
- Quaternion(readDouble(offset), readDouble(offset + 8), readDouble(offset + 16), readDouble(offset + 24))
-
- override fun MemoryWriter.write(offset: Int, value: Quaternion) {
- writeDouble(offset, value.w)
- writeDouble(offset + 8, value.x)
- writeDouble(offset + 16, value.y)
- writeDouble(offset + 24, value.z)
- }
- }
-}
-
-/**
- * Creates a quaternion with real part equal to this real.
- *
- * @receiver the real part.
- * @return a new quaternion.
- */
-public fun Number.toQuaternion(): Quaternion = Quaternion(this)
-
-/**
- * Creates a quaternion with `w`-component equal to `re`-component of given complex and `x`-component equal to
- * `im`-component of given complex.
- *
- * @receiver the complex number.
- * @return a new quaternion.
- */
-public fun Complex.toQuaternion(): Quaternion = Quaternion(this)
-
-/**
- * Creates a new buffer of quaternions with the specified [size], where each element is calculated by calling the
- * specified [init] function.
- */
-public inline fun Buffer.Companion.quaternion(size: Int, init: (Int) -> Quaternion): Buffer =
- MemoryBuffer.create(Quaternion, size, init)
-
-/**
- * Creates a new buffer of quaternions with the specified [size], where each element is calculated by calling the
- * specified [init] function.
- */
-public inline fun MutableBuffer.Companion.quaternion(size: Int, init: (Int) -> Quaternion): MutableBuffer =
- MutableMemoryBuffer.create(Quaternion, size, init)
diff --git a/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/complexBuffers.kt b/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/complexBuffers.kt
new file mode 100644
index 000000000..2dc03e83b
--- /dev/null
+++ b/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/complexBuffers.kt
@@ -0,0 +1,94 @@
+/*
+ * Copyright 2018-2021 KMath contributors.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ */
+
+package space.kscience.kmath.complex
+
+import space.kscience.kmath.structures.Buffer
+import space.kscience.kmath.structures.BufferFactory
+import space.kscience.kmath.structures.MutableBuffer
+import space.kscience.kmath.structures.MutableBufferFactory
+
+
+private class ComplexBuffer(factory: BufferFactory, override val size: Int, init: (Int) -> Complex) :
+ Buffer> {
+ private val re: Buffer
+ private val im: Buffer
+
+ init {
+ val tmp = Array(size, init)
+ re = factory(size) { tmp[it].re }
+ im = factory(size) { tmp[it].im }
+ }
+
+ override fun get(index: Int): Complex = Complex(re[index], im[index])
+
+ override fun iterator(): Iterator> = object : AbstractIterator>() {
+ private val a = re.iterator()
+ private val b = im.iterator()
+
+ override fun computeNext() = if (a.hasNext() && b.hasNext())
+ setNext(Complex(a.next(), b.next()))
+ else
+ done()
+ }
+}
+
+/**
+ * Creates a new buffer of complex elements with the specified [size], where each element is calculated by calling the
+ * specified [init] function.
+ */
+public fun Buffer.Companion.complex(
+ factory: BufferFactory,
+ size: Int,
+ init: (Int) -> Complex,
+): Buffer> = ComplexBuffer(factory, size, init)
+
+private class MutableComplexBuffer private constructor(
+ override val size: Int,
+ private val re: MutableBuffer,
+ private val im: MutableBuffer,
+) : MutableBuffer> {
+ private constructor(
+ factory: MutableBufferFactory,
+ size: Int,
+ tmp: Array>,
+ ) : this(size, factory(size) { tmp[it].re }, factory(size) { tmp[it].im })
+
+ constructor(
+ factory: MutableBufferFactory,
+ size: Int,
+ init: (Int) -> Complex,
+ ) : this(factory, size, Array(size, init))
+
+ override fun get(index: Int): Complex = Complex(re[index], im[index])
+
+ override fun set(index: Int, value: Complex) {
+ re[index] = value.re
+ im[index] = value.im
+ }
+
+ override fun iterator(): Iterator> = object : AbstractIterator>() {
+ private val a = re.iterator()
+ private val b = im.iterator()
+
+ override fun computeNext() = if (a.hasNext() && b.hasNext())
+ setNext(Complex(a.next(), b.next()))
+ else
+ done()
+ }
+
+ override fun copy(): MutableBuffer> = MutableComplexBuffer(size, re.copy(), im.copy())
+}
+
+
+/**
+ * Creates a new buffer of complex elements with the specified [size], where each element is calculated by calling the
+ * specified [init] function.
+ */
+public fun MutableBuffer.Companion.complex(
+ factory: MutableBufferFactory,
+ size: Int,
+ init: (Int) -> Complex,
+): MutableBuffer> = MutableComplexBuffer(factory, size, init)
diff --git a/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/complexLinearSpace.kt b/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/complexLinearSpace.kt
new file mode 100644
index 000000000..019eba835
--- /dev/null
+++ b/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/complexLinearSpace.kt
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2018-2021 KMath contributors.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ */
+
+package space.kscience.kmath.complex
+
+import space.kscience.kmath.linear.BufferedLinearSpace
+import space.kscience.kmath.operations.ExtendedField
+import space.kscience.kmath.operations.NumericAlgebra
+import space.kscience.kmath.operations.Ring
+import space.kscience.kmath.structures.Buffer
+import space.kscience.kmath.structures.BufferFactory
+
+public class ComplexLinearSpace(
+ elementContext: A,
+ bufferFactory: BufferFactory,
+) : BufferedLinearSpace, ComplexRing>(
+ ComplexRing(elementContext),
+ { size, init -> Buffer.complex(bufferFactory, size, init) },
+) where A : Ring, A : NumericAlgebra
+
+public fun BufferedLinearSpace.complex(): ComplexLinearSpace where A : ExtendedField, A : NumericAlgebra =
+ ComplexLinearSpace(elementAlgebra, bufferFactory)
diff --git a/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/complexNDAlgebra.kt b/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/complexNDAlgebra.kt
new file mode 100644
index 000000000..848f55676
--- /dev/null
+++ b/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/complexNDAlgebra.kt
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2018-2021 KMath contributors.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ */
+
+package space.kscience.kmath.complex
+
+import space.kscience.kmath.nd.BufferedExtendedFieldND
+import space.kscience.kmath.nd.BufferedFieldND
+import space.kscience.kmath.nd.BufferedGroupND
+import space.kscience.kmath.nd.BufferedRingND
+import space.kscience.kmath.operations.*
+import space.kscience.kmath.structures.Buffer
+import space.kscience.kmath.structures.BufferFactory
+
+public open class ComplexGroupND