From 206e4cbcf642a59792df62f71eb2d551df8b90ee Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Tue, 16 Mar 2021 21:17:26 +0300 Subject: [PATCH] Real -> Double --- CHANGELOG.md | 1 + docs/algebra.md | 2 +- docs/nd-structure.md | 4 +- .../kmath/benchmarks/BufferBenchmark.kt | 6 +- .../kscience/kmath/benchmarks/DotBenchmark.kt | 4 +- .../ExpressionsInterpretersBenchmark.kt | 4 +- .../kmath/benchmarks/NDFieldBenchmark.kt | 6 +- .../kmath/benchmarks/ViktorBenchmark.kt | 4 +- .../kmath/benchmarks/ViktorLogBenchmark.kt | 4 +- .../space/kscience/kmath/ast/expressions.kt | 4 +- .../kscience/kmath/ast/kotlingradSupport.kt | 6 +- .../kmath/commons/fit/fitWithAutoDiff.kt | 4 +- .../space/kscience/kmath/linear/gradient.kt | 10 +- .../kscience/kmath/structures/NDField.kt | 6 +- ...lRealNDField.kt => StreamDoubleFieldND.kt} | 36 +- .../structures/StructureReadBenchmark.kt | 2 +- .../structures/StructureWriteBenchmark.kt | 4 +- kmath-ast/README.md | 8 +- kmath-ast/docs/README-TEMPLATE.md | 8 +- .../TestESTreeConsistencyWithInterpreter.kt | 6 +- .../estree/TestESTreeOperationsSupport.kt | 10 +- .../kmath/estree/TestESTreeSpecialization.kt | 16 +- .../asm/TestAsmConsistencyWithInterpreter.kt | 6 +- .../kmath/asm/TestAsmOperationsSupport.kt | 10 +- .../kmath/asm/TestAsmSpecialization.kt | 16 +- .../kmath/ast/ParserPrecedenceTest.kt | 4 +- .../space/kscience/kmath/ast/ParserTest.kt | 4 +- .../kscience/kmath/commons/linear/CMMatrix.kt | 18 +- .../commons/transform/Transformations.kt | 3 +- .../commons/integration/IntegrationTest.kt | 2 +- .../kscience/kmath/complex/ComplexFieldND.kt | 10 +- kmath-core/api/kmath-core.api | 696 +++++++++--------- .../{RealDomain.kt => DoubleDomain.kt} | 2 +- .../kmath/domains/HyperSquareDomain.kt | 2 +- .../kmath/domains/UnconstrainedDomain.kt | 2 +- .../kmath/domains/UnivariateDomain.kt | 2 +- .../kmath/expressions/SimpleAutoDiff.kt | 2 +- .../kscience/kmath/linear/LinearSpace.kt | 4 +- .../kscience/kmath/linear/LupDecomposition.kt | 12 +- .../kscience/kmath/nd/BufferAlgebraND.kt | 2 +- .../nd/{RealFieldND.kt => DoubleFieldND.kt} | 46 +- .../kscience/kmath/operations/numbers.kt | 2 +- .../space/kscience/kmath/structures/Buffer.kt | 18 +- .../{RealBuffer.kt => DoubleBuffer.kt} | 22 +- .../kmath/structures/DoubleBufferField.kt | 272 +++++++ .../kmath/structures/FlaggedBuffer.kt | 4 +- .../kmath/structures/RealBufferField.kt | 272 ------- .../kmath/expressions/ExpressionFieldTest.kt | 8 +- .../kmath/expressions/SimpleAutoDiffTest.kt | 20 +- ...lLUSolverTest.kt => DoubleLUSolverTest.kt} | 2 +- .../{RealFieldTest.kt => DoubleFieldTest.kt} | 6 +- ...ingRealChain.kt => BlockingDoubleChain.kt} | 2 +- .../kscience/kmath/streaming/BufferFlow.kt | 12 +- .../kmath/structures/LazyStructureND.kt | 2 +- .../kscience/kmath/dimensions/Wrappers.kt | 8 +- .../kscience/kmath/ejml/EjmlLinearSpace.kt | 18 +- kmath-for-real/build.gradle.kts | 8 +- .../space/kscience/kmath/real/RealMatrix.kt | 16 +- .../space/kscience/kmath/real/RealVector.kt | 65 +- .../kotlin/space/kscience/kmath/real/grids.kt | 2 +- .../space/kscience/kmath/real/realND.kt | 10 +- ...{RealMatrixTest.kt => DoubleMatrixTest.kt} | 2 +- ...{RealVectorTest.kt => DoubleVectorTest.kt} | 14 +- .../interpolation/LinearInterpolatorTest.kt | 6 +- .../space/kscience/kmath/histogram/Counter.kt | 4 +- ...togramSpace.kt => DoubleHistogramSpace.kt} | 12 +- .../kscience/kmath/histogram/Histogram.kt | 6 +- .../histogram/MultivariateHistogramTest.kt | 15 +- .../kmath/kotlingrad/AdaptingTests.kt | 28 +- kmath-nd4j/docs/README-TEMPLATE.md | 6 +- .../kscience/kmath/nd4j/Nd4jArrayAlgebra.kt | 14 +- .../kscience/kmath/nd4j/Nd4jArrayIterator.kt | 4 +- .../kscience/kmath/nd4j/Nd4jArrayStructure.kt | 4 +- .../kmath/nd4j/Nd4jArrayAlgebraTest.kt | 4 +- .../kmath/nd4j/Nd4jArrayStructureTest.kt | 14 +- .../space/kscience/kmath/stat/Distribution.kt | 4 +- .../space/kscience/kmath/stat/Statistic.kt | 2 +- .../kscience/kmath/stat/distributions.kt | 6 +- kmath-viktor/api/kmath-viktor.api | 2 +- .../kmath/viktor/ViktorStructureND.kt | 22 +- 80 files changed, 968 insertions(+), 968 deletions(-) rename examples/src/main/kotlin/space/kscience/kmath/structures/{ParallelRealNDField.kt => StreamDoubleFieldND.kt} (76%) rename kmath-core/src/commonMain/kotlin/space/kscience/kmath/domains/{RealDomain.kt => DoubleDomain.kt} (95%) rename kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/{RealFieldND.kt => DoubleFieldND.kt} (67%) rename kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/{RealBuffer.kt => DoubleBuffer.kt} (53%) create mode 100644 kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/DoubleBufferField.kt delete mode 100644 kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/RealBufferField.kt rename kmath-core/src/commonTest/kotlin/space/kscience/kmath/linear/{RealLUSolverTest.kt => DoubleLUSolverTest.kt} (97%) rename kmath-core/src/commonTest/kotlin/space/kscience/kmath/operations/{RealFieldTest.kt => DoubleFieldTest.kt} (59%) rename kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/chains/{BlockingRealChain.kt => BlockingDoubleChain.kt} (82%) rename kmath-for-real/src/commonTest/kotlin/kaceince/kmath/real/{RealMatrixTest.kt => DoubleMatrixTest.kt} (99%) rename kmath-for-real/src/commonTest/kotlin/kaceince/kmath/real/{RealVectorTest.kt => DoubleVectorTest.kt} (67%) rename kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/{RealHistogramSpace.kt => DoubleHistogramSpace.kt} (92%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 17486bd2b..f9e3f963e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ - VectorSpace is now a vector space - Buffer factories for primitives moved to MutableBuffer.Companion - NDStructure and NDAlgebra to StructureND and AlgebraND respectively +- Real -> Double ### Deprecated diff --git a/docs/algebra.md b/docs/algebra.md index 6bfcde043..84693bb81 100644 --- a/docs/algebra.md +++ b/docs/algebra.md @@ -31,7 +31,7 @@ multiplication; - [Ring](http://mathworld.wolfram.com/Ring.html) adds multiplication and its neutral element (i.e. 1); - [Field](http://mathworld.wolfram.com/Field.html) adds division operation. -A typical implementation of `Field` is the `RealField` which works on doubles, and `VectorSpace` for `Space`. +A typical implementation of `Field` is the `DoubleField` which works on doubles, and `VectorSpace` for `Space`. In some cases algebra context can hold additional operations like `exp` or `sin`, and then it inherits appropriate interface. Also, contexts may have operations, which produce elements outside of the context. For example, `Matrix.dot` diff --git a/docs/nd-structure.md b/docs/nd-structure.md index 835304b9f..ec9b4d521 100644 --- a/docs/nd-structure.md +++ b/docs/nd-structure.md @@ -10,11 +10,11 @@ structures. In `kmath` performance depends on which particular context was used Let us consider following contexts: ```kotlin // automatically build context most suited for given type. - val autoField = NDField.auto(RealField, dim, dim) + val autoField = NDField.auto(DoubleField, dim, dim) // specialized nd-field for Double. It works as generic Double field as well val specializedField = NDField.real(dim, dim) //A generic boxing field. It should be used for objects, not primitives. - val genericField = NDField.buffered(RealField, dim, dim) + val genericField = NDField.buffered(DoubleField, dim, dim) ``` Now let us perform several tests and see which implementation is best suited for each case: diff --git a/examples/src/benchmarks/kotlin/space/kscience/kmath/benchmarks/BufferBenchmark.kt b/examples/src/benchmarks/kotlin/space/kscience/kmath/benchmarks/BufferBenchmark.kt index 1c3bbab75..1db1d77dc 100644 --- a/examples/src/benchmarks/kotlin/space/kscience/kmath/benchmarks/BufferBenchmark.kt +++ b/examples/src/benchmarks/kotlin/space/kscience/kmath/benchmarks/BufferBenchmark.kt @@ -5,14 +5,14 @@ import kotlinx.benchmark.Scope import kotlinx.benchmark.State import space.kscience.kmath.complex.Complex import space.kscience.kmath.complex.complex +import space.kscience.kmath.structures.DoubleBuffer import space.kscience.kmath.structures.MutableBuffer -import space.kscience.kmath.structures.RealBuffer @State(Scope.Benchmark) internal class BufferBenchmark { @Benchmark - fun genericRealBufferReadWrite() { - val buffer = RealBuffer(size) { it.toDouble() } + fun genericDoubleBufferReadWrite() { + val buffer = DoubleBuffer(size) { it.toDouble() } (0 until size).forEach { buffer[it] diff --git a/examples/src/benchmarks/kotlin/space/kscience/kmath/benchmarks/DotBenchmark.kt b/examples/src/benchmarks/kotlin/space/kscience/kmath/benchmarks/DotBenchmark.kt index dbf373929..6a2126dc1 100644 --- a/examples/src/benchmarks/kotlin/space/kscience/kmath/benchmarks/DotBenchmark.kt +++ b/examples/src/benchmarks/kotlin/space/kscience/kmath/benchmarks/DotBenchmark.kt @@ -8,7 +8,7 @@ import space.kscience.kmath.commons.linear.CMLinearSpace import space.kscience.kmath.ejml.EjmlLinearSpace import space.kscience.kmath.linear.LinearSpace import space.kscience.kmath.linear.invoke -import space.kscience.kmath.operations.RealField +import space.kscience.kmath.operations.DoubleField import kotlin.random.Random @State(Scope.Benchmark) @@ -51,7 +51,7 @@ internal class DotBenchmark { @Benchmark fun bufferedDot(blackhole: Blackhole) { - LinearSpace.auto(RealField).invoke { + LinearSpace.auto(DoubleField).invoke { blackhole.consume(matrix1 dot matrix2) } } diff --git a/examples/src/benchmarks/kotlin/space/kscience/kmath/benchmarks/ExpressionsInterpretersBenchmark.kt b/examples/src/benchmarks/kotlin/space/kscience/kmath/benchmarks/ExpressionsInterpretersBenchmark.kt index e5cfbf9f6..0899241f9 100644 --- a/examples/src/benchmarks/kotlin/space/kscience/kmath/benchmarks/ExpressionsInterpretersBenchmark.kt +++ b/examples/src/benchmarks/kotlin/space/kscience/kmath/benchmarks/ExpressionsInterpretersBenchmark.kt @@ -10,7 +10,7 @@ import space.kscience.kmath.expressions.Expression import space.kscience.kmath.expressions.expressionInField import space.kscience.kmath.expressions.invoke import space.kscience.kmath.expressions.symbol -import space.kscience.kmath.operations.RealField +import space.kscience.kmath.operations.DoubleField import space.kscience.kmath.operations.bindSymbol import kotlin.random.Random @@ -68,7 +68,7 @@ internal class ExpressionsInterpretersBenchmark { } private companion object { - private val algebra = RealField + private val algebra = DoubleField private val x by symbol } } diff --git a/examples/src/benchmarks/kotlin/space/kscience/kmath/benchmarks/NDFieldBenchmark.kt b/examples/src/benchmarks/kotlin/space/kscience/kmath/benchmarks/NDFieldBenchmark.kt index e381a1559..09c415d9a 100644 --- a/examples/src/benchmarks/kotlin/space/kscience/kmath/benchmarks/NDFieldBenchmark.kt +++ b/examples/src/benchmarks/kotlin/space/kscience/kmath/benchmarks/NDFieldBenchmark.kt @@ -5,7 +5,7 @@ import kotlinx.benchmark.Blackhole import kotlinx.benchmark.Scope import kotlinx.benchmark.State import space.kscience.kmath.nd.* -import space.kscience.kmath.operations.RealField +import space.kscience.kmath.operations.DoubleField import space.kscience.kmath.structures.Buffer @State(Scope.Benchmark) @@ -41,8 +41,8 @@ internal class NDFieldBenchmark { private companion object { private const val dim = 1000 private const val n = 100 - private val autoField = AlgebraND.auto(RealField, dim, dim) + private val autoField = AlgebraND.auto(DoubleField, dim, dim) private val specializedField = AlgebraND.real(dim, dim) - private val genericField = AlgebraND.field(RealField, Buffer.Companion::boxing, dim, dim) + private val genericField = AlgebraND.field(DoubleField, Buffer.Companion::boxing, dim, dim) } } diff --git a/examples/src/benchmarks/kotlin/space/kscience/kmath/benchmarks/ViktorBenchmark.kt b/examples/src/benchmarks/kotlin/space/kscience/kmath/benchmarks/ViktorBenchmark.kt index 21c29affd..fd0188bd6 100644 --- a/examples/src/benchmarks/kotlin/space/kscience/kmath/benchmarks/ViktorBenchmark.kt +++ b/examples/src/benchmarks/kotlin/space/kscience/kmath/benchmarks/ViktorBenchmark.kt @@ -9,7 +9,7 @@ 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.operations.RealField +import space.kscience.kmath.operations.DoubleField import space.kscience.kmath.viktor.ViktorNDField @State(Scope.Benchmark) @@ -54,7 +54,7 @@ internal class ViktorBenchmark { private const val n = 100 // automatically build context most suited for given type. - private val autoField = AlgebraND.auto(RealField, dim, dim) + private val autoField = AlgebraND.auto(DoubleField, dim, dim) private val realField = AlgebraND.real(dim, dim) private val viktorField = ViktorNDField(dim, dim) } diff --git a/examples/src/benchmarks/kotlin/space/kscience/kmath/benchmarks/ViktorLogBenchmark.kt b/examples/src/benchmarks/kotlin/space/kscience/kmath/benchmarks/ViktorLogBenchmark.kt index e964f9bff..b6bd036ba 100644 --- a/examples/src/benchmarks/kotlin/space/kscience/kmath/benchmarks/ViktorLogBenchmark.kt +++ b/examples/src/benchmarks/kotlin/space/kscience/kmath/benchmarks/ViktorLogBenchmark.kt @@ -8,7 +8,7 @@ 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.operations.RealField +import space.kscience.kmath.operations.DoubleField import space.kscience.kmath.viktor.ViktorFieldND @State(Scope.Benchmark) @@ -46,7 +46,7 @@ internal class ViktorLogBenchmark { private const val n = 100 // automatically build context most suited for given type. - private val autoField = AlgebraND.auto(RealField, dim, dim) + private val autoField = AlgebraND.auto(DoubleField, dim, dim) private val realNdField = AlgebraND.real(dim, dim) private val viktorField = ViktorFieldND(intArrayOf(dim, dim)) } diff --git a/examples/src/main/kotlin/space/kscience/kmath/ast/expressions.kt b/examples/src/main/kotlin/space/kscience/kmath/ast/expressions.kt index c342fc3ef..17c85eea5 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/ast/expressions.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/ast/expressions.kt @@ -1,10 +1,10 @@ package space.kscience.kmath.ast import space.kscience.kmath.expressions.invoke -import space.kscience.kmath.operations.RealField +import space.kscience.kmath.operations.DoubleField fun main() { - val expr = RealField.mstInField { + val expr = DoubleField.mstInField { val x = bindSymbol("x") x * 2.0 + number(2.0) / x - 16.0 } diff --git a/examples/src/main/kotlin/space/kscience/kmath/ast/kotlingradSupport.kt b/examples/src/main/kotlin/space/kscience/kmath/ast/kotlingradSupport.kt index 16304a458..23c9d5b41 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/ast/kotlingradSupport.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/ast/kotlingradSupport.kt @@ -5,7 +5,7 @@ import space.kscience.kmath.expressions.derivative import space.kscience.kmath.expressions.invoke import space.kscience.kmath.expressions.symbol import space.kscience.kmath.kotlingrad.differentiable -import space.kscience.kmath.operations.RealField +import space.kscience.kmath.operations.DoubleField /** * In this example, x^2-4*x-44 function is differentiated with Kotlin∇, and the autodiff result is compared with @@ -14,11 +14,11 @@ import space.kscience.kmath.operations.RealField fun main() { val x by symbol - val actualDerivative = MstExpression(RealField, "x^2-4*x-44".parseMath()) + val actualDerivative = MstExpression(DoubleField, "x^2-4*x-44".parseMath()) .differentiable() .derivative(x) .compile() - val expectedDerivative = MstExpression(RealField, "2*x-4".parseMath()).compile() + val expectedDerivative = MstExpression(DoubleField, "2*x-4".parseMath()).compile() assert(actualDerivative("x" to 123.0) == expectedDerivative("x" to 123.0)) } diff --git a/examples/src/main/kotlin/space/kscience/kmath/commons/fit/fitWithAutoDiff.kt b/examples/src/main/kotlin/space/kscience/kmath/commons/fit/fitWithAutoDiff.kt index c26fb34e9..ef0c29a2d 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/commons/fit/fitWithAutoDiff.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/commons/fit/fitWithAutoDiff.kt @@ -8,7 +8,7 @@ import kscience.plotly.models.TraceValues import space.kscience.kmath.commons.optimization.chiSquared import space.kscience.kmath.commons.optimization.minimize import space.kscience.kmath.expressions.symbol -import space.kscience.kmath.real.RealVector +import space.kscience.kmath.real.DoubleVector import space.kscience.kmath.real.map import space.kscience.kmath.real.step import space.kscience.kmath.stat.* @@ -26,7 +26,7 @@ private val c by symbol /** * Shortcut to use buffers in plotly */ -operator fun TraceValues.invoke(vector: RealVector) { +operator fun TraceValues.invoke(vector: DoubleVector) { numbers = vector.asIterable() } diff --git a/examples/src/main/kotlin/space/kscience/kmath/linear/gradient.kt b/examples/src/main/kotlin/space/kscience/kmath/linear/gradient.kt index 8dd3d7f6b..8940aeac9 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/linear/gradient.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/linear/gradient.kt @@ -1,11 +1,11 @@ package space.kscience.kmath.linear import space.kscience.kmath.real.* -import space.kscience.kmath.structures.RealBuffer +import space.kscience.kmath.structures.DoubleBuffer fun main() { - val x0 = Point(0.0, 0.0, 0.0) - val sigma = Point(1.0, 1.0, 1.0) + val x0 = DoubleVector(0.0, 0.0, 0.0) + val sigma = DoubleVector(1.0, 1.0, 1.0) val gaussian: (Point) -> Double = { x -> require(x.size == x0.size) @@ -14,9 +14,9 @@ fun main() { fun ((Point) -> Double).grad(x: Point): Point { require(x.size == x0.size) - return RealBuffer(x.size) { i -> + return DoubleBuffer(x.size) { i -> val h = sigma[i] / 5 - val dVector = RealBuffer(x.size) { if (it == i) h else 0.0 } + val dVector = DoubleBuffer(x.size) { if (it == i) h else 0.0 } val f1 = invoke(x + dVector / 2) val f0 = invoke(x - dVector / 2) (f1 - f0) / h 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 b884251c4..f7dc3280a 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/structures/NDField.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/structures/NDField.kt @@ -4,7 +4,7 @@ import kotlinx.coroutines.GlobalScope import org.nd4j.linalg.factory.Nd4j import space.kscience.kmath.nd.* import space.kscience.kmath.nd4j.Nd4jArrayField -import space.kscience.kmath.operations.RealField +import space.kscience.kmath.operations.DoubleField import space.kscience.kmath.operations.invoke import space.kscience.kmath.viktor.ViktorNDField import kotlin.contracts.InvocationKind @@ -24,11 +24,11 @@ fun main() { val n = 1000 // automatically build context most suited for given type. - val autoField = AlgebraND.auto(RealField, dim, dim) + 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) //A generic boxing field. It should be used for objects, not primitives. - val boxingField = AlgebraND.field(RealField, Buffer.Companion::boxing, dim, dim) + val boxingField = AlgebraND.field(DoubleField, Buffer.Companion::boxing, dim, dim) // Nd4j specialized field. val nd4jField = Nd4jArrayField.real(dim, dim) //viktor field diff --git a/examples/src/main/kotlin/space/kscience/kmath/structures/ParallelRealNDField.kt b/examples/src/main/kotlin/space/kscience/kmath/structures/StreamDoubleFieldND.kt similarity index 76% rename from examples/src/main/kotlin/space/kscience/kmath/structures/ParallelRealNDField.kt rename to examples/src/main/kotlin/space/kscience/kmath/structures/StreamDoubleFieldND.kt index 8b3c5dfbb..b4653b598 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/structures/ParallelRealNDField.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/structures/StreamDoubleFieldND.kt @@ -2,9 +2,9 @@ package space.kscience.kmath.structures import space.kscience.kmath.misc.UnstableKMathAPI import space.kscience.kmath.nd.* +import space.kscience.kmath.operations.DoubleField import space.kscience.kmath.operations.ExtendedField import space.kscience.kmath.operations.NumbersAddOperations -import space.kscience.kmath.operations.RealField import java.util.* import java.util.stream.IntStream @@ -12,14 +12,14 @@ import java.util.stream.IntStream * A demonstration implementation of NDField over Real using Java [DoubleStream] for parallel execution */ @OptIn(UnstableKMathAPI::class) -class StreamRealFieldND( +class StreamDoubleFieldND( override val shape: IntArray, -) : FieldND, +) : FieldND, NumbersAddOperations>, ExtendedField> { private val strides = DefaultStrides(shape) - override val elementContext: RealField get() = RealField + override val elementContext: DoubleField get() = DoubleField override val zero: NDBuffer by lazy { produce { zero } } override val one: NDBuffer by lazy { produce { one } } @@ -28,38 +28,38 @@ class StreamRealFieldND( return produce { d } } - private val StructureND.buffer: RealBuffer + private val StructureND.buffer: DoubleBuffer get() = when { - !shape.contentEquals(this@StreamRealFieldND.shape) -> throw ShapeMismatchException( - this@StreamRealFieldND.shape, + !shape.contentEquals(this@StreamDoubleFieldND.shape) -> throw ShapeMismatchException( + this@StreamDoubleFieldND.shape, shape ) - this is NDBuffer && this.strides == this@StreamRealFieldND.strides -> this.buffer as RealBuffer - else -> RealBuffer(strides.linearSize) { offset -> get(strides.index(offset)) } + this is NDBuffer && this.strides == this@StreamDoubleFieldND.strides -> this.buffer as DoubleBuffer + else -> DoubleBuffer(strides.linearSize) { offset -> get(strides.index(offset)) } } - override fun produce(initializer: RealField.(IntArray) -> Double): NDBuffer { + override fun produce(initializer: DoubleField.(IntArray) -> Double): NDBuffer { val array = IntStream.range(0, strides.linearSize).parallel().mapToDouble { offset -> val index = strides.index(offset) - RealField.initializer(index) + DoubleField.initializer(index) }.toArray() return NDBuffer(strides, array.asBuffer()) } override fun StructureND.map( - transform: RealField.(Double) -> Double, + transform: DoubleField.(Double) -> Double, ): NDBuffer { - val array = Arrays.stream(buffer.array).parallel().map { RealField.transform(it) }.toArray() + val array = Arrays.stream(buffer.array).parallel().map { DoubleField.transform(it) }.toArray() return NDBuffer(strides, array.asBuffer()) } override fun StructureND.mapIndexed( - transform: RealField.(index: IntArray, Double) -> Double, + transform: DoubleField.(index: IntArray, Double) -> Double, ): NDBuffer { val array = IntStream.range(0, strides.linearSize).parallel().mapToDouble { offset -> - RealField.transform( + DoubleField.transform( strides.index(offset), buffer.array[offset] ) @@ -71,10 +71,10 @@ class StreamRealFieldND( override fun combine( a: StructureND, b: StructureND, - transform: RealField.(Double, Double) -> Double, + transform: DoubleField.(Double, Double) -> Double, ): NDBuffer { val array = IntStream.range(0, strides.linearSize).parallel().mapToDouble { offset -> - RealField.transform(a.buffer.array[offset], b.buffer.array[offset]) + DoubleField.transform(a.buffer.array[offset], b.buffer.array[offset]) }.toArray() return NDBuffer(strides, array.asBuffer()) } @@ -104,4 +104,4 @@ class StreamRealFieldND( override fun atanh(arg: StructureND): NDBuffer = arg.map { atanh(it) } } -fun AlgebraND.Companion.realWithStream(vararg shape: Int): StreamRealFieldND = StreamRealFieldND(shape) \ No newline at end of file +fun AlgebraND.Companion.realWithStream(vararg shape: Int): StreamDoubleFieldND = StreamDoubleFieldND(shape) \ No newline at end of file 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 7f6d73394..89f984a5b 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/structures/StructureReadBenchmark.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/structures/StructureReadBenchmark.kt @@ -8,7 +8,7 @@ import kotlin.system.measureTimeMillis fun main() { val n = 6000 val array = DoubleArray(n * n) { 1.0 } - val buffer = RealBuffer(array) + val buffer = DoubleBuffer(array) val strides = DefaultStrides(intArrayOf(n, n)) val structure = NDBuffer(strides, buffer) 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 7aa5a07fd..27741be61 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/structures/StructureWriteBenchmark.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/structures/StructureWriteBenchmark.kt @@ -20,10 +20,10 @@ fun main() { println("Array mapping finished in $time2 millis") - val buffer = RealBuffer(DoubleArray(n * n) { 1.0 }) + val buffer = DoubleBuffer(DoubleArray(n * n) { 1.0 }) val time3 = measureTimeMillis { - val target = RealBuffer(DoubleArray(n * n)) + val target = DoubleBuffer(DoubleArray(n * n)) val res = array.forEachIndexed { index, value -> target[index] = value + 1 } diff --git a/kmath-ast/README.md b/kmath-ast/README.md index a88b6f696..1b3f70080 100644 --- a/kmath-ast/README.md +++ b/kmath-ast/README.md @@ -61,7 +61,7 @@ a special implementation of `Expression` with implemented `invoke` function. For example, the following builder: ```kotlin -RealField.mstInField { symbol("x") + 2 }.compile() +DoubleField.mstInField { symbol("x") + 2 }.compile() ``` … leads to generation of bytecode, which can be decompiled to the following Java class: @@ -94,8 +94,8 @@ public final class AsmCompiledExpression_45045_0 implements Expression { This API extends MST and MstExpression, so you may optimize as both of them: ```kotlin -RealField.mstInField { symbol("x") + 2 }.compile() -RealField.expression("x+2".parseMath()) +DoubleField.mstInField { symbol("x") + 2 }.compile() +DoubleField.expression("x+2".parseMath()) ``` #### Known issues @@ -109,7 +109,7 @@ RealField.expression("x+2".parseMath()) A similar feature is also available on JS. ```kotlin -RealField.mstInField { symbol("x") + 2 }.compile() +DoubleField.mstInField { symbol("x") + 2 }.compile() ``` The code above returns expression implemented with such a JS function: diff --git a/kmath-ast/docs/README-TEMPLATE.md b/kmath-ast/docs/README-TEMPLATE.md index 2712cba75..80e48008b 100644 --- a/kmath-ast/docs/README-TEMPLATE.md +++ b/kmath-ast/docs/README-TEMPLATE.md @@ -16,7 +16,7 @@ a special implementation of `Expression` with implemented `invoke` function. For example, the following builder: ```kotlin -RealField.mstInField { symbol("x") + 2 }.compile() +DoubleField.mstInField { symbol("x") + 2 }.compile() ``` … leads to generation of bytecode, which can be decompiled to the following Java class: @@ -49,8 +49,8 @@ public final class AsmCompiledExpression_45045_0 implements Expression { This API extends MST and MstExpression, so you may optimize as both of them: ```kotlin -RealField.mstInField { symbol("x") + 2 }.compile() -RealField.expression("x+2".parseMath()) +DoubleField.mstInField { symbol("x") + 2 }.compile() +DoubleField.expression("x+2".parseMath()) ``` #### Known issues @@ -64,7 +64,7 @@ RealField.expression("x+2".parseMath()) A similar feature is also available on JS. ```kotlin -RealField.mstInField { symbol("x") + 2 }.compile() +DoubleField.mstInField { symbol("x") + 2 }.compile() ``` The code above returns expression implemented with such a JS function: diff --git a/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/estree/TestESTreeConsistencyWithInterpreter.kt b/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/estree/TestESTreeConsistencyWithInterpreter.kt index bb34254b1..683c0337c 100644 --- a/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/estree/TestESTreeConsistencyWithInterpreter.kt +++ b/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/estree/TestESTreeConsistencyWithInterpreter.kt @@ -5,7 +5,7 @@ import space.kscience.kmath.complex.ComplexField import space.kscience.kmath.complex.toComplex import space.kscience.kmath.expressions.invoke import space.kscience.kmath.operations.ByteRing -import space.kscience.kmath.operations.RealField +import space.kscience.kmath.operations.DoubleField import kotlin.test.Test import kotlin.test.assertEquals @@ -73,7 +73,7 @@ internal class TestESTreeConsistencyWithInterpreter { @Test fun realField() { - val res1 = RealField.mstInField { + val res1 = DoubleField.mstInField { +(3 - 2 + 2 * number(1) + 1.0) + binaryOperationFunction("+")( (3.0 - (bindSymbol("x") + (scale(add(number(1.0), number(1.0)), 2.0) + 1.0))) * 3 - 1.0 + number(1), @@ -81,7 +81,7 @@ internal class TestESTreeConsistencyWithInterpreter { ) + zero }("x" to 2.0) - val res2 = RealField.mstInField { + val res2 = DoubleField.mstInField { +(3 - 2 + 2 * number(1) + 1.0) + binaryOperationFunction("+")( (3.0 - (bindSymbol("x") + (scale(add(number(1.0), number(1.0)), 2.0) + 1.0))) * 3 - 1.0 + number(1), diff --git a/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/estree/TestESTreeOperationsSupport.kt b/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/estree/TestESTreeOperationsSupport.kt index 590d0957d..d59c048b6 100644 --- a/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/estree/TestESTreeOperationsSupport.kt +++ b/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/estree/TestESTreeOperationsSupport.kt @@ -4,7 +4,7 @@ import space.kscience.kmath.ast.mstInExtendedField import space.kscience.kmath.ast.mstInField import space.kscience.kmath.ast.mstInGroup import space.kscience.kmath.expressions.invoke -import space.kscience.kmath.operations.RealField +import space.kscience.kmath.operations.DoubleField import kotlin.random.Random import kotlin.test.Test import kotlin.test.assertEquals @@ -12,28 +12,28 @@ import kotlin.test.assertEquals internal class TestESTreeOperationsSupport { @Test fun testUnaryOperationInvocation() { - val expression = RealField.mstInGroup { -bindSymbol("x") }.compile() + val expression = DoubleField.mstInGroup { -bindSymbol("x") }.compile() val res = expression("x" to 2.0) assertEquals(-2.0, res) } @Test fun testBinaryOperationInvocation() { - val expression = RealField.mstInGroup { -bindSymbol("x") + number(1.0) }.compile() + val expression = DoubleField.mstInGroup { -bindSymbol("x") + number(1.0) }.compile() val res = expression("x" to 2.0) assertEquals(-1.0, res) } @Test fun testConstProductInvocation() { - val res = RealField.mstInField { bindSymbol("x") * 2 }("x" to 2.0) + val res = DoubleField.mstInField { bindSymbol("x") * 2 }("x" to 2.0) assertEquals(4.0, res) } @Test fun testMultipleCalls() { val e = - RealField.mstInExtendedField { sin(bindSymbol("x")).pow(4) - 6 * bindSymbol("x") / tanh(bindSymbol("x")) } + DoubleField.mstInExtendedField { sin(bindSymbol("x")).pow(4) - 6 * bindSymbol("x") / tanh(bindSymbol("x")) } .compile() val r = Random(0) var s = 0.0 diff --git a/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/estree/TestESTreeSpecialization.kt b/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/estree/TestESTreeSpecialization.kt index c5e43241a..6be963175 100644 --- a/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/estree/TestESTreeSpecialization.kt +++ b/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/estree/TestESTreeSpecialization.kt @@ -2,50 +2,50 @@ package space.kscience.kmath.estree import space.kscience.kmath.ast.mstInField import space.kscience.kmath.expressions.invoke -import space.kscience.kmath.operations.RealField +import space.kscience.kmath.operations.DoubleField import kotlin.test.Test import kotlin.test.assertEquals internal class TestESTreeSpecialization { @Test fun testUnaryPlus() { - val expr = RealField.mstInField { unaryOperationFunction("+")(bindSymbol("x")) }.compile() + val expr = DoubleField.mstInField { unaryOperationFunction("+")(bindSymbol("x")) }.compile() assertEquals(2.0, expr("x" to 2.0)) } @Test fun testUnaryMinus() { - val expr = RealField.mstInField { unaryOperationFunction("-")(bindSymbol("x")) }.compile() + val expr = DoubleField.mstInField { unaryOperationFunction("-")(bindSymbol("x")) }.compile() assertEquals(-2.0, expr("x" to 2.0)) } @Test fun testAdd() { - val expr = RealField.mstInField { binaryOperationFunction("+")(bindSymbol("x"), bindSymbol("x")) }.compile() + val expr = DoubleField.mstInField { binaryOperationFunction("+")(bindSymbol("x"), bindSymbol("x")) }.compile() assertEquals(4.0, expr("x" to 2.0)) } @Test fun testSine() { - val expr = RealField.mstInField { unaryOperationFunction("sin")(bindSymbol("x")) }.compile() + val expr = DoubleField.mstInField { unaryOperationFunction("sin")(bindSymbol("x")) }.compile() assertEquals(0.0, expr("x" to 0.0)) } @Test fun testMinus() { - val expr = RealField.mstInField { binaryOperationFunction("-")(bindSymbol("x"), bindSymbol("x")) }.compile() + val expr = DoubleField.mstInField { binaryOperationFunction("-")(bindSymbol("x"), bindSymbol("x")) }.compile() assertEquals(0.0, expr("x" to 2.0)) } @Test fun testDivide() { - val expr = RealField.mstInField { binaryOperationFunction("/")(bindSymbol("x"), bindSymbol("x")) }.compile() + val expr = DoubleField.mstInField { binaryOperationFunction("/")(bindSymbol("x"), bindSymbol("x")) }.compile() assertEquals(1.0, expr("x" to 2.0)) } @Test fun testPower() { - val expr = RealField + val expr = DoubleField .mstInField { binaryOperationFunction("pow")(bindSymbol("x"), number(2)) } .compile() diff --git a/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/asm/TestAsmConsistencyWithInterpreter.kt b/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/asm/TestAsmConsistencyWithInterpreter.kt index 7cc1497d0..abc320360 100644 --- a/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/asm/TestAsmConsistencyWithInterpreter.kt +++ b/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/asm/TestAsmConsistencyWithInterpreter.kt @@ -5,7 +5,7 @@ import space.kscience.kmath.complex.ComplexField import space.kscience.kmath.complex.toComplex import space.kscience.kmath.expressions.invoke import space.kscience.kmath.operations.ByteRing -import space.kscience.kmath.operations.RealField +import space.kscience.kmath.operations.DoubleField import kotlin.test.Test import kotlin.test.assertEquals @@ -73,7 +73,7 @@ internal class TestAsmConsistencyWithInterpreter { @Test fun realField() { - val res1 = RealField.mstInField { + val res1 = DoubleField.mstInField { +(3 - 2 + 2 * number(1) + 1.0) + binaryOperationFunction("+")( (3.0 - (bindSymbol("x") + (scale(add(number(1.0), number(1.0)), 2.0) + 1.0))) * 3 - 1.0 + number(1), @@ -81,7 +81,7 @@ internal class TestAsmConsistencyWithInterpreter { ) + zero }("x" to 2.0) - val res2 = RealField.mstInField { + val res2 = DoubleField.mstInField { +(3 - 2 + 2 * number(1) + 1.0) + binaryOperationFunction("+")( (3.0 - (bindSymbol("x") + (scale(add(number(1.0), number(1.0)), 2.0) + 1.0))) * 3 - 1.0 + number(1), diff --git a/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/asm/TestAsmOperationsSupport.kt b/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/asm/TestAsmOperationsSupport.kt index 7047c824c..5d70cb76b 100644 --- a/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/asm/TestAsmOperationsSupport.kt +++ b/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/asm/TestAsmOperationsSupport.kt @@ -4,7 +4,7 @@ import space.kscience.kmath.ast.mstInExtendedField import space.kscience.kmath.ast.mstInField import space.kscience.kmath.ast.mstInGroup import space.kscience.kmath.expressions.invoke -import space.kscience.kmath.operations.RealField +import space.kscience.kmath.operations.DoubleField import kotlin.random.Random import kotlin.test.Test import kotlin.test.assertEquals @@ -12,28 +12,28 @@ import kotlin.test.assertEquals internal class TestAsmOperationsSupport { @Test fun testUnaryOperationInvocation() { - val expression = RealField.mstInGroup { -bindSymbol("x") }.compile() + val expression = DoubleField.mstInGroup { -bindSymbol("x") }.compile() val res = expression("x" to 2.0) assertEquals(-2.0, res) } @Test fun testBinaryOperationInvocation() { - val expression = RealField.mstInGroup { -bindSymbol("x") + number(1.0) }.compile() + val expression = DoubleField.mstInGroup { -bindSymbol("x") + number(1.0) }.compile() val res = expression("x" to 2.0) assertEquals(-1.0, res) } @Test fun testConstProductInvocation() { - val res = RealField.mstInField { bindSymbol("x") * 2 }("x" to 2.0) + val res = DoubleField.mstInField { bindSymbol("x") * 2 }("x" to 2.0) assertEquals(4.0, res) } @Test fun testMultipleCalls() { val e = - RealField.mstInExtendedField { sin(bindSymbol("x")).pow(4) - 6 * bindSymbol("x") / tanh(bindSymbol("x")) } + DoubleField.mstInExtendedField { sin(bindSymbol("x")).pow(4) - 6 * bindSymbol("x") / tanh(bindSymbol("x")) } .compile() val r = Random(0) var s = 0.0 diff --git a/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/asm/TestAsmSpecialization.kt b/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/asm/TestAsmSpecialization.kt index a214ca4ad..f485260c9 100644 --- a/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/asm/TestAsmSpecialization.kt +++ b/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/asm/TestAsmSpecialization.kt @@ -2,50 +2,50 @@ package space.kscience.kmath.asm import space.kscience.kmath.ast.mstInField import space.kscience.kmath.expressions.invoke -import space.kscience.kmath.operations.RealField +import space.kscience.kmath.operations.DoubleField import kotlin.test.Test import kotlin.test.assertEquals internal class TestAsmSpecialization { @Test fun testUnaryPlus() { - val expr = RealField.mstInField { unaryOperationFunction("+")(bindSymbol("x")) }.compile() + val expr = DoubleField.mstInField { unaryOperationFunction("+")(bindSymbol("x")) }.compile() assertEquals(2.0, expr("x" to 2.0)) } @Test fun testUnaryMinus() { - val expr = RealField.mstInField { unaryOperationFunction("-")(bindSymbol("x")) }.compile() + val expr = DoubleField.mstInField { unaryOperationFunction("-")(bindSymbol("x")) }.compile() assertEquals(-2.0, expr("x" to 2.0)) } @Test fun testAdd() { - val expr = RealField.mstInField { binaryOperationFunction("+")(bindSymbol("x"), bindSymbol("x")) }.compile() + val expr = DoubleField.mstInField { binaryOperationFunction("+")(bindSymbol("x"), bindSymbol("x")) }.compile() assertEquals(4.0, expr("x" to 2.0)) } @Test fun testSine() { - val expr = RealField.mstInField { unaryOperationFunction("sin")(bindSymbol("x")) }.compile() + val expr = DoubleField.mstInField { unaryOperationFunction("sin")(bindSymbol("x")) }.compile() assertEquals(0.0, expr("x" to 0.0)) } @Test fun testMinus() { - val expr = RealField.mstInField { binaryOperationFunction("-")(bindSymbol("x"), bindSymbol("x")) }.compile() + val expr = DoubleField.mstInField { binaryOperationFunction("-")(bindSymbol("x"), bindSymbol("x")) }.compile() assertEquals(0.0, expr("x" to 2.0)) } @Test fun testDivide() { - val expr = RealField.mstInField { binaryOperationFunction("/")(bindSymbol("x"), bindSymbol("x")) }.compile() + val expr = DoubleField.mstInField { binaryOperationFunction("/")(bindSymbol("x"), bindSymbol("x")) }.compile() assertEquals(1.0, expr("x" to 2.0)) } @Test fun testPower() { - val expr = RealField + val expr = DoubleField .mstInField { binaryOperationFunction("pow")(bindSymbol("x"), number(2)) } .compile() diff --git a/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/ast/ParserPrecedenceTest.kt b/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/ast/ParserPrecedenceTest.kt index 7153f4bfc..1450cab84 100644 --- a/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/ast/ParserPrecedenceTest.kt +++ b/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/ast/ParserPrecedenceTest.kt @@ -1,12 +1,12 @@ package space.kscience.kmath.ast +import space.kscience.kmath.operations.DoubleField import space.kscience.kmath.operations.Field -import space.kscience.kmath.operations.RealField import kotlin.test.Test import kotlin.test.assertEquals internal class ParserPrecedenceTest { - private val f: Field = RealField + private val f: Field = DoubleField @Test fun test1(): Unit = assertEquals(6.0, f.evaluate("2*2+2".parseMath())) diff --git a/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/ast/ParserTest.kt b/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/ast/ParserTest.kt index 6807d5c5d..3d5449043 100644 --- a/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/ast/ParserTest.kt +++ b/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/ast/ParserTest.kt @@ -4,7 +4,7 @@ import space.kscience.kmath.complex.Complex import space.kscience.kmath.complex.ComplexField import space.kscience.kmath.expressions.invoke import space.kscience.kmath.operations.Algebra -import space.kscience.kmath.operations.RealField +import space.kscience.kmath.operations.DoubleField import kotlin.test.Test import kotlin.test.assertEquals @@ -33,7 +33,7 @@ internal class ParserTest { @Test fun `evaluate MST with unary function`() { val mst = "sin(0)".parseMath() - val res = RealField.evaluate(mst) + val res = DoubleField.evaluate(mst) assertEquals(0.0, res) } 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 4e3a44a83..4efd8383b 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 @@ -4,8 +4,8 @@ import org.apache.commons.math3.linear.* import space.kscience.kmath.linear.* import space.kscience.kmath.misc.UnstableKMathAPI import space.kscience.kmath.nd.StructureND -import space.kscience.kmath.operations.RealField -import space.kscience.kmath.structures.RealBuffer +import space.kscience.kmath.operations.DoubleField +import space.kscience.kmath.structures.DoubleBuffer import kotlin.reflect.KClass import kotlin.reflect.cast @@ -34,15 +34,15 @@ public inline class CMVector(public val origin: RealVector) : Point { public fun RealVector.toPoint(): CMVector = CMVector(this) -public object CMLinearSpace : LinearSpace { - override val elementAlgebra: RealField get() = RealField +public object CMLinearSpace : LinearSpace { + override val elementAlgebra: DoubleField get() = DoubleField public override fun buildMatrix( rows: Int, columns: Int, - initializer: RealField.(i: Int, j: Int) -> Double, + initializer: DoubleField.(i: Int, j: Int) -> Double, ): CMMatrix { - val array = Array(rows) { i -> DoubleArray(columns) { j -> RealField.initializer(i, j) } } + val array = Array(rows) { i -> DoubleArray(columns) { j -> DoubleField.initializer(i, j) } } return CMMatrix(Array2DRowRealMatrix(array)) } @@ -64,8 +64,8 @@ public object CMLinearSpace : LinearSpace { internal fun RealMatrix.wrap(): CMMatrix = CMMatrix(this) internal fun RealVector.wrap(): CMVector = CMVector(this) - override fun buildVector(size: Int, initializer: RealField.(Int) -> Double): Point = - ArrayRealVector(DoubleArray(size) { RealField.initializer(it) }).wrap() + override fun buildVector(size: Int, initializer: DoubleField.(Int) -> Double): Point = + ArrayRealVector(DoubleArray(size) { DoubleField.initializer(it) }).wrap() override fun Matrix.plus(other: Matrix): CMMatrix = toCM().origin.add(other.toCM().origin).wrap() @@ -135,7 +135,7 @@ public object CMLinearSpace : LinearSpace { override val u: Matrix by lazy { CMMatrix(sv.u) } override val s: Matrix by lazy { CMMatrix(sv.s) } override val v: Matrix by lazy { CMMatrix(sv.v) } - override val singularValues: Point by lazy { RealBuffer(sv.singularValues) } + override val singularValues: Point by lazy { DoubleBuffer(sv.singularValues) } } else -> null }?.let(type::cast) 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 aaee594ad..ad6b6d8cd 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 @@ -6,7 +6,6 @@ import kotlinx.coroutines.flow.map import org.apache.commons.math3.transform.* import space.kscience.kmath.complex.Complex import space.kscience.kmath.streaming.chunked -import space.kscience.kmath.streaming.spread import space.kscience.kmath.structures.* @@ -17,7 +16,7 @@ public object Transformations { 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 RealBuffer) { + private fun Buffer.asArray() = if (this is DoubleBuffer) { array } else { DoubleArray(size) { i -> get(i) } 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 3693d5796..d163203f7 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 @@ -3,7 +3,7 @@ package space.kscience.kmath.commons.integration import org.junit.jupiter.api.Test import space.kscience.kmath.integration.integrate import space.kscience.kmath.misc.UnstableKMathAPI -import space.kscience.kmath.operations.RealField.sin +import space.kscience.kmath.operations.DoubleField.sin import kotlin.math.PI import kotlin.math.abs import kotlin.test.assertTrue 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 index 382410e45..e16962da7 100644 --- a/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/ComplexFieldND.kt +++ b/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/ComplexFieldND.kt @@ -34,15 +34,15 @@ public class ComplexFieldND( // @Suppress("OVERRIDE_BY_INLINE") // override inline fun map( // arg: AbstractNDBuffer, -// transform: RealField.(Double) -> Double, +// transform: DoubleField.(Double) -> Double, // ): RealNDElement { // check(arg) -// val array = RealBuffer(arg.strides.linearSize) { offset -> RealField.transform(arg.buffer[offset]) } +// 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: RealField.(IntArray) -> Double): RealNDElement { +// override inline fun produce(initializer: DoubleField.(IntArray) -> Double): RealNDElement { // val array = RealBuffer(strides.linearSize) { offset -> elementContext.initializer(strides.index(offset)) } // return BufferedNDFieldElement(this, array) // } @@ -50,7 +50,7 @@ public class ComplexFieldND( // @Suppress("OVERRIDE_BY_INLINE") // override inline fun mapIndexed( // arg: AbstractNDBuffer, -// transform: RealField.(index: IntArray, Double) -> Double, +// transform: DoubleField.(index: IntArray, Double) -> Double, // ): RealNDElement { // check(arg) // return BufferedNDFieldElement( @@ -67,7 +67,7 @@ public class ComplexFieldND( // override inline fun combine( // a: AbstractNDBuffer, // b: AbstractNDBuffer, -// transform: RealField.(Double, Double) -> Double, +// transform: DoubleField.(Double, Double) -> Double, // ): RealNDElement { // check(a, b) // val buffer = RealBuffer(strides.linearSize) { offset -> diff --git a/kmath-core/api/kmath-core.api b/kmath-core/api/kmath-core.api index 2fb28d73a..8be9ff115 100644 --- a/kmath-core/api/kmath-core.api +++ b/kmath-core/api/kmath-core.api @@ -825,6 +825,78 @@ public final class space/kscience/kmath/nd/DefaultStrides$Companion { public final fun invoke ([I)Lspace/kscience/kmath/nd/Strides; } +public final class space/kscience/kmath/nd/DoubleFieldND : space/kscience/kmath/nd/BufferedFieldND, space/kscience/kmath/operations/ExtendedField, space/kscience/kmath/operations/NumbersAddOperations, space/kscience/kmath/operations/ScaleOperations { + public fun ([I)V + public synthetic fun acos (Ljava/lang/Object;)Ljava/lang/Object; + public fun acos (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/NDBuffer; + public synthetic fun acosh (Ljava/lang/Object;)Ljava/lang/Object; + public fun acosh (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/NDBuffer; + public synthetic fun asin (Ljava/lang/Object;)Ljava/lang/Object; + public fun asin (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/NDBuffer; + public synthetic fun asinh (Ljava/lang/Object;)Ljava/lang/Object; + public fun asinh (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/NDBuffer; + public synthetic fun atan (Ljava/lang/Object;)Ljava/lang/Object; + public fun atan (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/NDBuffer; + public synthetic fun atanh (Ljava/lang/Object;)Ljava/lang/Object; + public fun atanh (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/NDBuffer; + public fun combine (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;Lkotlin/jvm/functions/Function3;)Lspace/kscience/kmath/nd/NDBuffer; + public synthetic fun combine (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;Lkotlin/jvm/functions/Function3;)Lspace/kscience/kmath/nd/StructureND; + public synthetic fun cos (Ljava/lang/Object;)Ljava/lang/Object; + public fun cos (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/NDBuffer; + public synthetic fun cosh (Ljava/lang/Object;)Ljava/lang/Object; + public fun cosh (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/NDBuffer; + public synthetic fun exp (Ljava/lang/Object;)Ljava/lang/Object; + public fun exp (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/NDBuffer; + public synthetic fun getBuffer (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/structures/Buffer; + public fun getBuffer-Udx-57Q (Lspace/kscience/kmath/nd/StructureND;)[D + public synthetic fun getOne ()Ljava/lang/Object; + public fun getOne ()Lspace/kscience/kmath/nd/NDBuffer; + public synthetic fun getZero ()Ljava/lang/Object; + public fun getZero ()Lspace/kscience/kmath/nd/NDBuffer; + public synthetic fun ln (Ljava/lang/Object;)Ljava/lang/Object; + public fun ln (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/NDBuffer; + public fun map (Lspace/kscience/kmath/nd/StructureND;Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/NDBuffer; + public synthetic fun map (Lspace/kscience/kmath/nd/StructureND;Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/StructureND; + public fun mapIndexed (Lspace/kscience/kmath/nd/StructureND;Lkotlin/jvm/functions/Function3;)Lspace/kscience/kmath/nd/NDBuffer; + public synthetic fun mapIndexed (Lspace/kscience/kmath/nd/StructureND;Lkotlin/jvm/functions/Function3;)Lspace/kscience/kmath/nd/StructureND; + public synthetic fun minus (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public fun minus (Ljava/lang/Number;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public synthetic fun minus (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun minus (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Number;)Lspace/kscience/kmath/nd/StructureND; + public synthetic fun number (Ljava/lang/Number;)Ljava/lang/Object; + public fun number (Ljava/lang/Number;)Lspace/kscience/kmath/nd/NDBuffer; + public synthetic fun number (Ljava/lang/Number;)Lspace/kscience/kmath/nd/StructureND; + public synthetic fun plus (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public fun plus (Ljava/lang/Number;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public synthetic fun plus (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun plus (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Number;)Lspace/kscience/kmath/nd/StructureND; + public synthetic fun pow (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun pow (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Number;)Lspace/kscience/kmath/nd/StructureND; + public synthetic fun power (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun power (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Number;)Lspace/kscience/kmath/nd/NDBuffer; + public fun produce (Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/NDBuffer; + public synthetic fun produce (Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/StructureND; + public fun rightSideNumberOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public synthetic fun scale (Ljava/lang/Object;D)Ljava/lang/Object; + public fun scale (Lspace/kscience/kmath/nd/StructureND;D)Lspace/kscience/kmath/nd/StructureND; + public synthetic fun sin (Ljava/lang/Object;)Ljava/lang/Object; + public fun sin (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/NDBuffer; + public synthetic fun sinh (Ljava/lang/Object;)Ljava/lang/Object; + public fun sinh (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/NDBuffer; + public synthetic fun sqrt (Ljava/lang/Object;)Ljava/lang/Object; + public fun sqrt (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public synthetic fun tan (Ljava/lang/Object;)Ljava/lang/Object; + public fun tan (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/NDBuffer; + public synthetic fun tanh (Ljava/lang/Object;)Ljava/lang/Object; + public fun tanh (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/NDBuffer; + public fun unaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function1; +} + +public final class space/kscience/kmath/nd/DoubleFieldNDKt { + public static final fun nd (Lspace/kscience/kmath/operations/DoubleField;[ILkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static final fun real (Lspace/kscience/kmath/nd/AlgebraND$Companion;[I)Lspace/kscience/kmath/nd/DoubleFieldND; +} + public abstract interface class space/kscience/kmath/nd/FieldND : space/kscience/kmath/nd/RingND, space/kscience/kmath/operations/Field, space/kscience/kmath/operations/ScaleOperations { public abstract fun div (Ljava/lang/Object;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; public abstract fun div (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Object;)Lspace/kscience/kmath/nd/StructureND; @@ -921,78 +993,6 @@ public class space/kscience/kmath/nd/NDBuffer : space/kscience/kmath/nd/Structur public fun toString ()Ljava/lang/String; } -public final class space/kscience/kmath/nd/RealFieldND : space/kscience/kmath/nd/BufferedFieldND, space/kscience/kmath/operations/ExtendedField, space/kscience/kmath/operations/NumbersAddOperations, space/kscience/kmath/operations/ScaleOperations { - public fun ([I)V - public synthetic fun acos (Ljava/lang/Object;)Ljava/lang/Object; - public fun acos (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/NDBuffer; - public synthetic fun acosh (Ljava/lang/Object;)Ljava/lang/Object; - public fun acosh (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/NDBuffer; - public synthetic fun asin (Ljava/lang/Object;)Ljava/lang/Object; - public fun asin (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/NDBuffer; - public synthetic fun asinh (Ljava/lang/Object;)Ljava/lang/Object; - public fun asinh (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/NDBuffer; - public synthetic fun atan (Ljava/lang/Object;)Ljava/lang/Object; - public fun atan (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/NDBuffer; - public synthetic fun atanh (Ljava/lang/Object;)Ljava/lang/Object; - public fun atanh (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/NDBuffer; - public fun combine (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;Lkotlin/jvm/functions/Function3;)Lspace/kscience/kmath/nd/NDBuffer; - public synthetic fun combine (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;Lkotlin/jvm/functions/Function3;)Lspace/kscience/kmath/nd/StructureND; - public synthetic fun cos (Ljava/lang/Object;)Ljava/lang/Object; - public fun cos (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/NDBuffer; - public synthetic fun cosh (Ljava/lang/Object;)Ljava/lang/Object; - public fun cosh (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/NDBuffer; - public synthetic fun exp (Ljava/lang/Object;)Ljava/lang/Object; - public fun exp (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/NDBuffer; - public synthetic fun getBuffer (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/structures/Buffer; - public fun getBuffer-LGjt3BI (Lspace/kscience/kmath/nd/StructureND;)[D - public synthetic fun getOne ()Ljava/lang/Object; - public fun getOne ()Lspace/kscience/kmath/nd/NDBuffer; - public synthetic fun getZero ()Ljava/lang/Object; - public fun getZero ()Lspace/kscience/kmath/nd/NDBuffer; - public synthetic fun ln (Ljava/lang/Object;)Ljava/lang/Object; - public fun ln (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/NDBuffer; - public fun map (Lspace/kscience/kmath/nd/StructureND;Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/NDBuffer; - public synthetic fun map (Lspace/kscience/kmath/nd/StructureND;Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/StructureND; - public fun mapIndexed (Lspace/kscience/kmath/nd/StructureND;Lkotlin/jvm/functions/Function3;)Lspace/kscience/kmath/nd/NDBuffer; - public synthetic fun mapIndexed (Lspace/kscience/kmath/nd/StructureND;Lkotlin/jvm/functions/Function3;)Lspace/kscience/kmath/nd/StructureND; - public synthetic fun minus (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; - public fun minus (Ljava/lang/Number;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; - public synthetic fun minus (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; - public fun minus (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Number;)Lspace/kscience/kmath/nd/StructureND; - public synthetic fun number (Ljava/lang/Number;)Ljava/lang/Object; - public fun number (Ljava/lang/Number;)Lspace/kscience/kmath/nd/NDBuffer; - public synthetic fun number (Ljava/lang/Number;)Lspace/kscience/kmath/nd/StructureND; - public synthetic fun plus (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; - public fun plus (Ljava/lang/Number;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; - public synthetic fun plus (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; - public fun plus (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Number;)Lspace/kscience/kmath/nd/StructureND; - public synthetic fun pow (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; - public fun pow (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Number;)Lspace/kscience/kmath/nd/StructureND; - public synthetic fun power (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; - public fun power (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Number;)Lspace/kscience/kmath/nd/NDBuffer; - public fun produce (Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/NDBuffer; - public synthetic fun produce (Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/StructureND; - public fun rightSideNumberOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; - public synthetic fun scale (Ljava/lang/Object;D)Ljava/lang/Object; - public fun scale (Lspace/kscience/kmath/nd/StructureND;D)Lspace/kscience/kmath/nd/StructureND; - public synthetic fun sin (Ljava/lang/Object;)Ljava/lang/Object; - public fun sin (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/NDBuffer; - public synthetic fun sinh (Ljava/lang/Object;)Ljava/lang/Object; - public fun sinh (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/NDBuffer; - public synthetic fun sqrt (Ljava/lang/Object;)Ljava/lang/Object; - public fun sqrt (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; - public synthetic fun tan (Ljava/lang/Object;)Ljava/lang/Object; - public fun tan (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/NDBuffer; - public synthetic fun tanh (Ljava/lang/Object;)Ljava/lang/Object; - public fun tanh (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/NDBuffer; - public fun unaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function1; -} - -public final class space/kscience/kmath/nd/RealFieldNDKt { - public static final fun nd (Lspace/kscience/kmath/operations/RealField;[ILkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static final fun real (Lspace/kscience/kmath/nd/AlgebraND$Companion;[I)Lspace/kscience/kmath/nd/RealFieldND; -} - public abstract interface class space/kscience/kmath/nd/RingND : space/kscience/kmath/nd/GroupND, space/kscience/kmath/operations/Ring { public static final field Companion Lspace/kscience/kmath/nd/RingND$Companion; public abstract fun multiply (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; @@ -1338,6 +1338,92 @@ public final class space/kscience/kmath/operations/ByteRing : space/kscience/kma public synthetic fun unaryPlus (Ljava/lang/Object;)Ljava/lang/Object; } +public final class space/kscience/kmath/operations/DoubleField : space/kscience/kmath/operations/ExtendedField, space/kscience/kmath/operations/Norm, space/kscience/kmath/operations/ScaleOperations { + public static final field INSTANCE Lspace/kscience/kmath/operations/DoubleField; + public fun acos (D)Ljava/lang/Double; + public synthetic fun acos (Ljava/lang/Object;)Ljava/lang/Object; + public fun acosh (D)Ljava/lang/Double; + public synthetic fun acosh (Ljava/lang/Object;)Ljava/lang/Object; + public fun add (DD)Ljava/lang/Double; + public synthetic fun add (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun asin (D)Ljava/lang/Double; + public synthetic fun asin (Ljava/lang/Object;)Ljava/lang/Object; + public fun asinh (D)Ljava/lang/Double; + public synthetic fun asinh (Ljava/lang/Object;)Ljava/lang/Object; + public fun atan (D)Ljava/lang/Double; + public synthetic fun atan (Ljava/lang/Object;)Ljava/lang/Object; + public fun atanh (D)Ljava/lang/Double; + public synthetic fun atanh (Ljava/lang/Object;)Ljava/lang/Object; + public fun binaryOperation (Ljava/lang/String;DD)Ljava/lang/Double; + public synthetic fun binaryOperation (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun binaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public fun bindSymbol (Ljava/lang/String;)Ljava/lang/Double; + public synthetic fun bindSymbol (Ljava/lang/String;)Ljava/lang/Object; + public fun cos (D)Ljava/lang/Double; + public synthetic fun cos (Ljava/lang/Object;)Ljava/lang/Object; + public fun cosh (D)Ljava/lang/Double; + public synthetic fun cosh (Ljava/lang/Object;)Ljava/lang/Object; + public fun div (DD)Ljava/lang/Double; + public fun div (DLjava/lang/Number;)Ljava/lang/Double; + public synthetic fun div (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public synthetic fun div (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun divide (DD)Ljava/lang/Double; + public synthetic fun divide (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun exp (D)Ljava/lang/Double; + public synthetic fun exp (Ljava/lang/Object;)Ljava/lang/Object; + public fun getOne ()Ljava/lang/Double; + public synthetic fun getOne ()Ljava/lang/Object; + public fun getZero ()Ljava/lang/Double; + public synthetic fun getZero ()Ljava/lang/Object; + public fun leftSideNumberOperation (Ljava/lang/String;Ljava/lang/Number;D)Ljava/lang/Double; + public synthetic fun leftSideNumberOperation (Ljava/lang/String;Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public fun leftSideNumberOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public fun ln (D)Ljava/lang/Double; + public synthetic fun ln (Ljava/lang/Object;)Ljava/lang/Object; + public fun minus (DD)Ljava/lang/Double; + public synthetic fun minus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun multiply (DD)Ljava/lang/Double; + public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun norm (D)Ljava/lang/Double; + public synthetic fun norm (Ljava/lang/Object;)Ljava/lang/Object; + public fun number (Ljava/lang/Number;)Ljava/lang/Double; + public synthetic fun number (Ljava/lang/Number;)Ljava/lang/Object; + public fun plus (DD)Ljava/lang/Double; + public synthetic fun plus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun pow (DLjava/lang/Number;)Ljava/lang/Double; + public synthetic fun pow (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun power (DLjava/lang/Number;)Ljava/lang/Double; + public synthetic fun power (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun rightSideNumberOperation (Ljava/lang/String;DLjava/lang/Number;)Ljava/lang/Double; + public synthetic fun rightSideNumberOperation (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun rightSideNumberOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public fun scale (DD)Ljava/lang/Double; + public synthetic fun scale (Ljava/lang/Object;D)Ljava/lang/Object; + public fun sin (D)Ljava/lang/Double; + public synthetic fun sin (Ljava/lang/Object;)Ljava/lang/Object; + public fun sinh (D)Ljava/lang/Double; + public synthetic fun sinh (Ljava/lang/Object;)Ljava/lang/Object; + public fun sqrt (D)Ljava/lang/Double; + public synthetic fun sqrt (Ljava/lang/Object;)Ljava/lang/Object; + public fun tan (D)Ljava/lang/Double; + public synthetic fun tan (Ljava/lang/Object;)Ljava/lang/Object; + public fun tanh (D)Ljava/lang/Double; + public synthetic fun tanh (Ljava/lang/Object;)Ljava/lang/Object; + public fun times (DD)Ljava/lang/Double; + public fun times (DLjava/lang/Number;)Ljava/lang/Double; + public fun times (Ljava/lang/Number;D)Ljava/lang/Double; + public synthetic fun times (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public synthetic fun times (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public synthetic fun times (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryMinus (D)Ljava/lang/Double; + public synthetic fun unaryMinus (Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryOperation (Ljava/lang/String;D)Ljava/lang/Double; + public synthetic fun unaryOperation (Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function1; + public fun unaryPlus (D)Ljava/lang/Double; + public synthetic fun unaryPlus (Ljava/lang/Object;)Ljava/lang/Object; +} + public abstract interface class space/kscience/kmath/operations/ExponentialOperations : space/kscience/kmath/operations/Algebra { public static final field ACOSH_OPERATION Ljava/lang/String; public static final field ASINH_OPERATION Ljava/lang/String; @@ -1877,92 +1963,6 @@ public final class space/kscience/kmath/operations/PowerOperations$DefaultImpls public static fun unaryOperationFunction (Lspace/kscience/kmath/operations/PowerOperations;Ljava/lang/String;)Lkotlin/jvm/functions/Function1; } -public final class space/kscience/kmath/operations/RealField : space/kscience/kmath/operations/ExtendedField, space/kscience/kmath/operations/Norm, space/kscience/kmath/operations/ScaleOperations { - public static final field INSTANCE Lspace/kscience/kmath/operations/RealField; - public fun acos (D)Ljava/lang/Double; - public synthetic fun acos (Ljava/lang/Object;)Ljava/lang/Object; - public fun acosh (D)Ljava/lang/Double; - public synthetic fun acosh (Ljava/lang/Object;)Ljava/lang/Object; - public fun add (DD)Ljava/lang/Double; - public synthetic fun add (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun asin (D)Ljava/lang/Double; - public synthetic fun asin (Ljava/lang/Object;)Ljava/lang/Object; - public fun asinh (D)Ljava/lang/Double; - public synthetic fun asinh (Ljava/lang/Object;)Ljava/lang/Object; - public fun atan (D)Ljava/lang/Double; - public synthetic fun atan (Ljava/lang/Object;)Ljava/lang/Object; - public fun atanh (D)Ljava/lang/Double; - public synthetic fun atanh (Ljava/lang/Object;)Ljava/lang/Object; - public fun binaryOperation (Ljava/lang/String;DD)Ljava/lang/Double; - public synthetic fun binaryOperation (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun binaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; - public fun bindSymbol (Ljava/lang/String;)Ljava/lang/Double; - public synthetic fun bindSymbol (Ljava/lang/String;)Ljava/lang/Object; - public fun cos (D)Ljava/lang/Double; - public synthetic fun cos (Ljava/lang/Object;)Ljava/lang/Object; - public fun cosh (D)Ljava/lang/Double; - public synthetic fun cosh (Ljava/lang/Object;)Ljava/lang/Object; - public fun div (DD)Ljava/lang/Double; - public fun div (DLjava/lang/Number;)Ljava/lang/Double; - public synthetic fun div (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; - public synthetic fun div (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun divide (DD)Ljava/lang/Double; - public synthetic fun divide (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun exp (D)Ljava/lang/Double; - public synthetic fun exp (Ljava/lang/Object;)Ljava/lang/Object; - public fun getOne ()Ljava/lang/Double; - public synthetic fun getOne ()Ljava/lang/Object; - public fun getZero ()Ljava/lang/Double; - public synthetic fun getZero ()Ljava/lang/Object; - public fun leftSideNumberOperation (Ljava/lang/String;Ljava/lang/Number;D)Ljava/lang/Double; - public synthetic fun leftSideNumberOperation (Ljava/lang/String;Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; - public fun leftSideNumberOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; - public fun ln (D)Ljava/lang/Double; - public synthetic fun ln (Ljava/lang/Object;)Ljava/lang/Object; - public fun minus (DD)Ljava/lang/Double; - public synthetic fun minus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun multiply (DD)Ljava/lang/Double; - public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun norm (D)Ljava/lang/Double; - public synthetic fun norm (Ljava/lang/Object;)Ljava/lang/Object; - public fun number (Ljava/lang/Number;)Ljava/lang/Double; - public synthetic fun number (Ljava/lang/Number;)Ljava/lang/Object; - public fun plus (DD)Ljava/lang/Double; - public synthetic fun plus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun pow (DLjava/lang/Number;)Ljava/lang/Double; - public synthetic fun pow (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; - public fun power (DLjava/lang/Number;)Ljava/lang/Double; - public synthetic fun power (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; - public fun rightSideNumberOperation (Ljava/lang/String;DLjava/lang/Number;)Ljava/lang/Double; - public synthetic fun rightSideNumberOperation (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; - public fun rightSideNumberOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; - public fun scale (DD)Ljava/lang/Double; - public synthetic fun scale (Ljava/lang/Object;D)Ljava/lang/Object; - public fun sin (D)Ljava/lang/Double; - public synthetic fun sin (Ljava/lang/Object;)Ljava/lang/Object; - public fun sinh (D)Ljava/lang/Double; - public synthetic fun sinh (Ljava/lang/Object;)Ljava/lang/Object; - public fun sqrt (D)Ljava/lang/Double; - public synthetic fun sqrt (Ljava/lang/Object;)Ljava/lang/Object; - public fun tan (D)Ljava/lang/Double; - public synthetic fun tan (Ljava/lang/Object;)Ljava/lang/Object; - public fun tanh (D)Ljava/lang/Double; - public synthetic fun tanh (Ljava/lang/Object;)Ljava/lang/Object; - public fun times (DD)Ljava/lang/Double; - public fun times (DLjava/lang/Number;)Ljava/lang/Double; - public fun times (Ljava/lang/Number;D)Ljava/lang/Double; - public synthetic fun times (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; - public synthetic fun times (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; - public synthetic fun times (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun unaryMinus (D)Ljava/lang/Double; - public synthetic fun unaryMinus (Ljava/lang/Object;)Ljava/lang/Object; - public fun unaryOperation (Ljava/lang/String;D)Ljava/lang/Double; - public synthetic fun unaryOperation (Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; - public fun unaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function1; - public fun unaryPlus (D)Ljava/lang/Double; - public synthetic fun unaryPlus (Ljava/lang/Object;)Ljava/lang/Object; -} - public abstract interface class space/kscience/kmath/operations/Ring : space/kscience/kmath/operations/Group, space/kscience/kmath/operations/RingOperations { public abstract fun getOne ()Ljava/lang/Object; } @@ -2135,6 +2135,193 @@ public final class space/kscience/kmath/structures/BufferOperationKt { public static final fun toList (Lspace/kscience/kmath/structures/Buffer;)Ljava/util/List; } +public final class space/kscience/kmath/structures/DoubleBuffer : space/kscience/kmath/structures/MutableBuffer { + public static final synthetic fun box-impl ([D)Lspace/kscience/kmath/structures/DoubleBuffer; + public static fun constructor-impl ([D)[D + public fun contentEquals (Lspace/kscience/kmath/structures/Buffer;)Z + public static fun contentEquals-impl ([DLspace/kscience/kmath/structures/Buffer;)Z + public synthetic fun copy ()Lspace/kscience/kmath/structures/MutableBuffer; + public fun copy-Dv3HvWU ()[D + public static fun copy-Dv3HvWU ([D)[D + public fun equals (Ljava/lang/Object;)Z + public static fun equals-impl ([DLjava/lang/Object;)Z + public static final fun equals-impl0 ([D[D)Z + public fun get (I)Ljava/lang/Double; + public synthetic fun get (I)Ljava/lang/Object; + public static fun get-impl ([DI)Ljava/lang/Double; + public final fun getArray ()[D + public fun getSize ()I + public static fun getSize-impl ([D)I + public fun hashCode ()I + public static fun hashCode-impl ([D)I + public synthetic fun iterator ()Ljava/util/Iterator; + public fun iterator ()Lkotlin/collections/DoubleIterator; + public static fun iterator-impl ([D)Lkotlin/collections/DoubleIterator; + public fun set (ID)V + public synthetic fun set (ILjava/lang/Object;)V + public static fun set-impl ([DID)V + public fun toString ()Ljava/lang/String; + public static fun toString-impl ([D)Ljava/lang/String; + public final synthetic fun unbox-impl ()[D +} + +public final class space/kscience/kmath/structures/DoubleBufferField : space/kscience/kmath/operations/ExtendedField { + public fun (I)V + public synthetic fun acos (Ljava/lang/Object;)Ljava/lang/Object; + public fun acos-Udx-57Q (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun acosh (Ljava/lang/Object;)Ljava/lang/Object; + public fun acosh-Udx-57Q (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun add (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun add-CZ9oacQ (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun asin (Ljava/lang/Object;)Ljava/lang/Object; + public fun asin-Udx-57Q (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun asinh (Ljava/lang/Object;)Ljava/lang/Object; + public fun asinh-Udx-57Q (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun atan (Ljava/lang/Object;)Ljava/lang/Object; + public fun atan-Udx-57Q (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun atanh (Ljava/lang/Object;)Ljava/lang/Object; + public fun atanh-Udx-57Q (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun binaryOperation (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun binaryOperation (Ljava/lang/String;Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public fun binaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public synthetic fun bindSymbol (Ljava/lang/String;)Ljava/lang/Object; + public fun bindSymbol (Ljava/lang/String;)Lspace/kscience/kmath/structures/Buffer; + public synthetic fun cos (Ljava/lang/Object;)Ljava/lang/Object; + public fun cos-Udx-57Q (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun cosh (Ljava/lang/Object;)Ljava/lang/Object; + public fun cosh-Udx-57Q (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun div (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public synthetic fun div (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun div (Lspace/kscience/kmath/structures/Buffer;Ljava/lang/Number;)Lspace/kscience/kmath/structures/Buffer; + public fun div (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public synthetic fun divide (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun divide-CZ9oacQ (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun exp (Ljava/lang/Object;)Ljava/lang/Object; + public fun exp-Udx-57Q (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun getOne ()Ljava/lang/Object; + public fun getOne ()Lspace/kscience/kmath/structures/Buffer; + public final fun getSize ()I + public synthetic fun getZero ()Ljava/lang/Object; + public fun getZero ()Lspace/kscience/kmath/structures/Buffer; + public synthetic fun leftSideNumberOperation (Ljava/lang/String;Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public fun leftSideNumberOperation (Ljava/lang/String;Ljava/lang/Number;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public fun leftSideNumberOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public synthetic fun ln (Ljava/lang/Object;)Ljava/lang/Object; + public fun ln-Udx-57Q (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun minus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun minus (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun multiply-CZ9oacQ (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun number (Ljava/lang/Number;)Ljava/lang/Object; + public fun number (Ljava/lang/Number;)Lspace/kscience/kmath/structures/Buffer; + public synthetic fun plus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun plus (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public synthetic fun pow (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun pow (Lspace/kscience/kmath/structures/Buffer;Ljava/lang/Number;)Lspace/kscience/kmath/structures/Buffer; + public synthetic fun power (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun power-CZ9oacQ (Lspace/kscience/kmath/structures/Buffer;Ljava/lang/Number;)[D + public synthetic fun rightSideNumberOperation (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun rightSideNumberOperation (Ljava/lang/String;Lspace/kscience/kmath/structures/Buffer;Ljava/lang/Number;)Lspace/kscience/kmath/structures/Buffer; + public fun rightSideNumberOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public synthetic fun scale (Ljava/lang/Object;D)Ljava/lang/Object; + public fun scale-CZ9oacQ (Lspace/kscience/kmath/structures/Buffer;D)[D + public synthetic fun sin (Ljava/lang/Object;)Ljava/lang/Object; + public fun sin-Udx-57Q (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun sinh (Ljava/lang/Object;)Ljava/lang/Object; + public fun sinh-Udx-57Q (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun sqrt (Ljava/lang/Object;)Ljava/lang/Object; + public fun sqrt (Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public synthetic fun tan (Ljava/lang/Object;)Ljava/lang/Object; + public fun tan-Udx-57Q (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun tanh (Ljava/lang/Object;)Ljava/lang/Object; + public fun tanh-Udx-57Q (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun times (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public fun times (Ljava/lang/Number;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public synthetic fun times (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public synthetic fun times (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun times (Lspace/kscience/kmath/structures/Buffer;Ljava/lang/Number;)Lspace/kscience/kmath/structures/Buffer; + public fun times (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public synthetic fun unaryMinus (Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryMinus (Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public synthetic fun unaryOperation (Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryOperation (Ljava/lang/String;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public fun unaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function1; + public synthetic fun unaryPlus (Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryPlus (Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; +} + +public final class space/kscience/kmath/structures/DoubleBufferFieldOperations : space/kscience/kmath/operations/ExtendedFieldOperations { + public static final field INSTANCE Lspace/kscience/kmath/structures/DoubleBufferFieldOperations; + public synthetic fun acos (Ljava/lang/Object;)Ljava/lang/Object; + public fun acos-Udx-57Q (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun acosh (Ljava/lang/Object;)Ljava/lang/Object; + public fun acosh-Udx-57Q (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun add (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun add-CZ9oacQ (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun asin (Ljava/lang/Object;)Ljava/lang/Object; + public fun asin-Udx-57Q (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun asinh (Ljava/lang/Object;)Ljava/lang/Object; + public fun asinh-Udx-57Q (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun atan (Ljava/lang/Object;)Ljava/lang/Object; + public fun atan-Udx-57Q (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun atanh (Ljava/lang/Object;)Ljava/lang/Object; + public fun atanh-Udx-57Q (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun binaryOperation (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun binaryOperation (Ljava/lang/String;Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public fun binaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public synthetic fun bindSymbol (Ljava/lang/String;)Ljava/lang/Object; + public fun bindSymbol (Ljava/lang/String;)Lspace/kscience/kmath/structures/Buffer; + public synthetic fun cos (Ljava/lang/Object;)Ljava/lang/Object; + public fun cos-Udx-57Q (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun cosh (Ljava/lang/Object;)Ljava/lang/Object; + public fun cosh-Udx-57Q (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun div (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun div (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public synthetic fun divide (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun divide-CZ9oacQ (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun exp (Ljava/lang/Object;)Ljava/lang/Object; + public fun exp-Udx-57Q (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun ln (Ljava/lang/Object;)Ljava/lang/Object; + public fun ln-Udx-57Q (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun minus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun minus (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun multiply-CZ9oacQ (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun plus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun plus (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public synthetic fun pow (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun pow (Lspace/kscience/kmath/structures/Buffer;Ljava/lang/Number;)Lspace/kscience/kmath/structures/Buffer; + public synthetic fun power (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun power-CZ9oacQ (Lspace/kscience/kmath/structures/Buffer;Ljava/lang/Number;)[D + public synthetic fun sin (Ljava/lang/Object;)Ljava/lang/Object; + public fun sin-Udx-57Q (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun sinh (Ljava/lang/Object;)Ljava/lang/Object; + public fun sinh-Udx-57Q (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun sqrt (Ljava/lang/Object;)Ljava/lang/Object; + public fun sqrt (Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public synthetic fun tan (Ljava/lang/Object;)Ljava/lang/Object; + public fun tan-Udx-57Q (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun tanh (Ljava/lang/Object;)Ljava/lang/Object; + public fun tanh-Udx-57Q (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun times (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun times (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public synthetic fun unaryMinus (Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryMinus-Udx-57Q (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun unaryOperation (Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryOperation (Ljava/lang/String;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public fun unaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function1; + public synthetic fun unaryPlus (Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryPlus (Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; +} + +public final class space/kscience/kmath/structures/DoubleBufferKt { + public static final fun DoubleBuffer (ILkotlin/jvm/functions/Function1;)[D + public static final fun DoubleBuffer ([D)[D + public static final fun asBuffer ([D)[D + public static final fun contentEquals-2c9zdjM ([D[D)Z + public static final fun toDoubleArray (Lspace/kscience/kmath/structures/Buffer;)[D +} + public abstract interface class space/kscience/kmath/structures/FlaggedBuffer : space/kscience/kmath/structures/Buffer { public abstract fun getFlag (I)B } @@ -2144,13 +2331,13 @@ public final class space/kscience/kmath/structures/FlaggedBuffer$DefaultImpls { } public final class space/kscience/kmath/structures/FlaggedBufferKt { - public static final fun forEachValid (Lspace/kscience/kmath/structures/FlaggedRealBuffer;Lkotlin/jvm/functions/Function1;)V + public static final fun forEachValid (Lspace/kscience/kmath/structures/FlaggedDoubleBuffer;Lkotlin/jvm/functions/Function1;)V public static final fun hasFlag (Lspace/kscience/kmath/structures/FlaggedBuffer;ILspace/kscience/kmath/structures/ValueFlag;)Z public static final fun isMissing (Lspace/kscience/kmath/structures/FlaggedBuffer;I)Z public static final fun isValid (Lspace/kscience/kmath/structures/FlaggedBuffer;I)Z } -public final class space/kscience/kmath/structures/FlaggedRealBuffer : space/kscience/kmath/structures/Buffer, space/kscience/kmath/structures/FlaggedBuffer { +public final class space/kscience/kmath/structures/FlaggedDoubleBuffer : space/kscience/kmath/structures/Buffer, space/kscience/kmath/structures/FlaggedBuffer { public fun ([D[B)V public fun contentEquals (Lspace/kscience/kmath/structures/Buffer;)Z public fun get (I)Ljava/lang/Double; @@ -2317,10 +2504,10 @@ public abstract interface class space/kscience/kmath/structures/MutableBuffer : public final class space/kscience/kmath/structures/MutableBuffer$Companion { public final fun auto (Lkotlin/reflect/KClass;ILkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/structures/MutableBuffer; public final fun boxing (ILkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/structures/MutableBuffer; + public final fun double-CZ9oacQ (ILkotlin/jvm/functions/Function1;)[D public final fun float-YxruXGw (ILkotlin/jvm/functions/Function1;)[F public final fun int-Ye6GY2U (ILkotlin/jvm/functions/Function1;)[I public final fun long-BuQOeTY (ILkotlin/jvm/functions/Function1;)[J - public final fun real-8hrHhI4 (ILkotlin/jvm/functions/Function1;)[D public final fun short-1yRgbGw (ILkotlin/jvm/functions/Function1;)[S } @@ -2388,193 +2575,6 @@ public final class space/kscience/kmath/structures/ReadOnlyBuffer : space/kscien public final synthetic fun unbox-impl ()Lspace/kscience/kmath/structures/MutableBuffer; } -public final class space/kscience/kmath/structures/RealBuffer : space/kscience/kmath/structures/MutableBuffer { - public static final synthetic fun box-impl ([D)Lspace/kscience/kmath/structures/RealBuffer; - public static fun constructor-impl ([D)[D - public fun contentEquals (Lspace/kscience/kmath/structures/Buffer;)Z - public static fun contentEquals-impl ([DLspace/kscience/kmath/structures/Buffer;)Z - public synthetic fun copy ()Lspace/kscience/kmath/structures/MutableBuffer; - public fun copy-88GwAag ()[D - public static fun copy-88GwAag ([D)[D - public fun equals (Ljava/lang/Object;)Z - public static fun equals-impl ([DLjava/lang/Object;)Z - public static final fun equals-impl0 ([D[D)Z - public fun get (I)Ljava/lang/Double; - public synthetic fun get (I)Ljava/lang/Object; - public static fun get-impl ([DI)Ljava/lang/Double; - public final fun getArray ()[D - public fun getSize ()I - public static fun getSize-impl ([D)I - public fun hashCode ()I - public static fun hashCode-impl ([D)I - public synthetic fun iterator ()Ljava/util/Iterator; - public fun iterator ()Lkotlin/collections/DoubleIterator; - public static fun iterator-impl ([D)Lkotlin/collections/DoubleIterator; - public fun set (ID)V - public synthetic fun set (ILjava/lang/Object;)V - public static fun set-impl ([DID)V - public fun toString ()Ljava/lang/String; - public static fun toString-impl ([D)Ljava/lang/String; - public final synthetic fun unbox-impl ()[D -} - -public final class space/kscience/kmath/structures/RealBufferField : space/kscience/kmath/operations/ExtendedField { - public fun (I)V - public synthetic fun acos (Ljava/lang/Object;)Ljava/lang/Object; - public fun acos-LGjt3BI (Lspace/kscience/kmath/structures/Buffer;)[D - public synthetic fun acosh (Ljava/lang/Object;)Ljava/lang/Object; - public fun acosh-LGjt3BI (Lspace/kscience/kmath/structures/Buffer;)[D - public synthetic fun add (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun add-8hrHhI4 (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)[D - public synthetic fun asin (Ljava/lang/Object;)Ljava/lang/Object; - public fun asin-LGjt3BI (Lspace/kscience/kmath/structures/Buffer;)[D - public synthetic fun asinh (Ljava/lang/Object;)Ljava/lang/Object; - public fun asinh-LGjt3BI (Lspace/kscience/kmath/structures/Buffer;)[D - public synthetic fun atan (Ljava/lang/Object;)Ljava/lang/Object; - public fun atan-LGjt3BI (Lspace/kscience/kmath/structures/Buffer;)[D - public synthetic fun atanh (Ljava/lang/Object;)Ljava/lang/Object; - public fun atanh-LGjt3BI (Lspace/kscience/kmath/structures/Buffer;)[D - public synthetic fun binaryOperation (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun binaryOperation (Ljava/lang/String;Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; - public fun binaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; - public synthetic fun bindSymbol (Ljava/lang/String;)Ljava/lang/Object; - public fun bindSymbol (Ljava/lang/String;)Lspace/kscience/kmath/structures/Buffer; - public synthetic fun cos (Ljava/lang/Object;)Ljava/lang/Object; - public fun cos-LGjt3BI (Lspace/kscience/kmath/structures/Buffer;)[D - public synthetic fun cosh (Ljava/lang/Object;)Ljava/lang/Object; - public fun cosh-LGjt3BI (Lspace/kscience/kmath/structures/Buffer;)[D - public synthetic fun div (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; - public synthetic fun div (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun div (Lspace/kscience/kmath/structures/Buffer;Ljava/lang/Number;)Lspace/kscience/kmath/structures/Buffer; - public fun div (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; - public synthetic fun divide (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun divide-8hrHhI4 (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)[D - public synthetic fun exp (Ljava/lang/Object;)Ljava/lang/Object; - public fun exp-LGjt3BI (Lspace/kscience/kmath/structures/Buffer;)[D - public synthetic fun getOne ()Ljava/lang/Object; - public fun getOne ()Lspace/kscience/kmath/structures/Buffer; - public final fun getSize ()I - public synthetic fun getZero ()Ljava/lang/Object; - public fun getZero ()Lspace/kscience/kmath/structures/Buffer; - public synthetic fun leftSideNumberOperation (Ljava/lang/String;Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; - public fun leftSideNumberOperation (Ljava/lang/String;Ljava/lang/Number;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; - public fun leftSideNumberOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; - public synthetic fun ln (Ljava/lang/Object;)Ljava/lang/Object; - public fun ln-LGjt3BI (Lspace/kscience/kmath/structures/Buffer;)[D - public synthetic fun minus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun minus (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; - public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun multiply-8hrHhI4 (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)[D - public synthetic fun number (Ljava/lang/Number;)Ljava/lang/Object; - public fun number (Ljava/lang/Number;)Lspace/kscience/kmath/structures/Buffer; - public synthetic fun plus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun plus (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; - public synthetic fun pow (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; - public fun pow (Lspace/kscience/kmath/structures/Buffer;Ljava/lang/Number;)Lspace/kscience/kmath/structures/Buffer; - public synthetic fun power (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; - public fun power-8hrHhI4 (Lspace/kscience/kmath/structures/Buffer;Ljava/lang/Number;)[D - public synthetic fun rightSideNumberOperation (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; - public fun rightSideNumberOperation (Ljava/lang/String;Lspace/kscience/kmath/structures/Buffer;Ljava/lang/Number;)Lspace/kscience/kmath/structures/Buffer; - public fun rightSideNumberOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; - public synthetic fun scale (Ljava/lang/Object;D)Ljava/lang/Object; - public fun scale-8hrHhI4 (Lspace/kscience/kmath/structures/Buffer;D)[D - public synthetic fun sin (Ljava/lang/Object;)Ljava/lang/Object; - public fun sin-LGjt3BI (Lspace/kscience/kmath/structures/Buffer;)[D - public synthetic fun sinh (Ljava/lang/Object;)Ljava/lang/Object; - public fun sinh-LGjt3BI (Lspace/kscience/kmath/structures/Buffer;)[D - public synthetic fun sqrt (Ljava/lang/Object;)Ljava/lang/Object; - public fun sqrt (Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; - public synthetic fun tan (Ljava/lang/Object;)Ljava/lang/Object; - public fun tan-LGjt3BI (Lspace/kscience/kmath/structures/Buffer;)[D - public synthetic fun tanh (Ljava/lang/Object;)Ljava/lang/Object; - public fun tanh-LGjt3BI (Lspace/kscience/kmath/structures/Buffer;)[D - public synthetic fun times (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; - public fun times (Ljava/lang/Number;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; - public synthetic fun times (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; - public synthetic fun times (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun times (Lspace/kscience/kmath/structures/Buffer;Ljava/lang/Number;)Lspace/kscience/kmath/structures/Buffer; - public fun times (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; - public synthetic fun unaryMinus (Ljava/lang/Object;)Ljava/lang/Object; - public fun unaryMinus (Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; - public synthetic fun unaryOperation (Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; - public fun unaryOperation (Ljava/lang/String;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; - public fun unaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function1; - public synthetic fun unaryPlus (Ljava/lang/Object;)Ljava/lang/Object; - public fun unaryPlus (Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; -} - -public final class space/kscience/kmath/structures/RealBufferFieldOperations : space/kscience/kmath/operations/ExtendedFieldOperations { - public static final field INSTANCE Lspace/kscience/kmath/structures/RealBufferFieldOperations; - public synthetic fun acos (Ljava/lang/Object;)Ljava/lang/Object; - public fun acos-LGjt3BI (Lspace/kscience/kmath/structures/Buffer;)[D - public synthetic fun acosh (Ljava/lang/Object;)Ljava/lang/Object; - public fun acosh-LGjt3BI (Lspace/kscience/kmath/structures/Buffer;)[D - public synthetic fun add (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun add-8hrHhI4 (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)[D - public synthetic fun asin (Ljava/lang/Object;)Ljava/lang/Object; - public fun asin-LGjt3BI (Lspace/kscience/kmath/structures/Buffer;)[D - public synthetic fun asinh (Ljava/lang/Object;)Ljava/lang/Object; - public fun asinh-LGjt3BI (Lspace/kscience/kmath/structures/Buffer;)[D - public synthetic fun atan (Ljava/lang/Object;)Ljava/lang/Object; - public fun atan-LGjt3BI (Lspace/kscience/kmath/structures/Buffer;)[D - public synthetic fun atanh (Ljava/lang/Object;)Ljava/lang/Object; - public fun atanh-LGjt3BI (Lspace/kscience/kmath/structures/Buffer;)[D - public synthetic fun binaryOperation (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun binaryOperation (Ljava/lang/String;Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; - public fun binaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; - public synthetic fun bindSymbol (Ljava/lang/String;)Ljava/lang/Object; - public fun bindSymbol (Ljava/lang/String;)Lspace/kscience/kmath/structures/Buffer; - public synthetic fun cos (Ljava/lang/Object;)Ljava/lang/Object; - public fun cos-LGjt3BI (Lspace/kscience/kmath/structures/Buffer;)[D - public synthetic fun cosh (Ljava/lang/Object;)Ljava/lang/Object; - public fun cosh-LGjt3BI (Lspace/kscience/kmath/structures/Buffer;)[D - public synthetic fun div (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun div (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; - public synthetic fun divide (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun divide-8hrHhI4 (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)[D - public synthetic fun exp (Ljava/lang/Object;)Ljava/lang/Object; - public fun exp-LGjt3BI (Lspace/kscience/kmath/structures/Buffer;)[D - public synthetic fun ln (Ljava/lang/Object;)Ljava/lang/Object; - public fun ln-LGjt3BI (Lspace/kscience/kmath/structures/Buffer;)[D - public synthetic fun minus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun minus (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; - public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun multiply-8hrHhI4 (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)[D - public synthetic fun plus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun plus (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; - public synthetic fun pow (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; - public fun pow (Lspace/kscience/kmath/structures/Buffer;Ljava/lang/Number;)Lspace/kscience/kmath/structures/Buffer; - public synthetic fun power (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; - public fun power-8hrHhI4 (Lspace/kscience/kmath/structures/Buffer;Ljava/lang/Number;)[D - public synthetic fun sin (Ljava/lang/Object;)Ljava/lang/Object; - public fun sin-LGjt3BI (Lspace/kscience/kmath/structures/Buffer;)[D - public synthetic fun sinh (Ljava/lang/Object;)Ljava/lang/Object; - public fun sinh-LGjt3BI (Lspace/kscience/kmath/structures/Buffer;)[D - public synthetic fun sqrt (Ljava/lang/Object;)Ljava/lang/Object; - public fun sqrt (Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; - public synthetic fun tan (Ljava/lang/Object;)Ljava/lang/Object; - public fun tan-LGjt3BI (Lspace/kscience/kmath/structures/Buffer;)[D - public synthetic fun tanh (Ljava/lang/Object;)Ljava/lang/Object; - public fun tanh-LGjt3BI (Lspace/kscience/kmath/structures/Buffer;)[D - public synthetic fun times (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun times (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; - public synthetic fun unaryMinus (Ljava/lang/Object;)Ljava/lang/Object; - public fun unaryMinus-LGjt3BI (Lspace/kscience/kmath/structures/Buffer;)[D - public synthetic fun unaryOperation (Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; - public fun unaryOperation (Ljava/lang/String;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; - public fun unaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function1; - public synthetic fun unaryPlus (Ljava/lang/Object;)Ljava/lang/Object; - public fun unaryPlus (Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; -} - -public final class space/kscience/kmath/structures/RealBufferKt { - public static final fun RealBuffer (ILkotlin/jvm/functions/Function1;)[D - public static final fun RealBuffer ([D)[D - public static final fun asBuffer ([D)[D - public static final fun contentEquals-2uVC2J0 ([D[D)Z - public static final fun toDoubleArray (Lspace/kscience/kmath/structures/Buffer;)[D -} - public final class space/kscience/kmath/structures/ShortBuffer : space/kscience/kmath/structures/MutableBuffer { public static final synthetic fun box-impl ([S)Lspace/kscience/kmath/structures/ShortBuffer; public static fun constructor-impl ([S)[S diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/domains/RealDomain.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/domains/DoubleDomain.kt similarity index 95% rename from kmath-core/src/commonMain/kotlin/space/kscience/kmath/domains/RealDomain.kt rename to kmath-core/src/commonMain/kotlin/space/kscience/kmath/domains/DoubleDomain.kt index c20cbfec1..057a4a344 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/domains/RealDomain.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/domains/DoubleDomain.kt @@ -23,7 +23,7 @@ import space.kscience.kmath.misc.UnstableKMathAPI * @author Alexander Nozik */ @UnstableKMathAPI -public interface RealDomain : Domain { +public interface DoubleDomain : Domain { /** * Global lower edge diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/domains/HyperSquareDomain.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/domains/HyperSquareDomain.kt index c948f8672..a15d04b4c 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/domains/HyperSquareDomain.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/domains/HyperSquareDomain.kt @@ -27,7 +27,7 @@ import space.kscience.kmath.structures.indices * @author Alexander Nozik */ @UnstableKMathAPI -public class HyperSquareDomain(private val lower: Buffer, private val upper: Buffer) : RealDomain { +public class HyperSquareDomain(private val lower: Buffer, private val upper: Buffer) : DoubleDomain { public override val dimension: Int get() = lower.size public override operator fun contains(point: Point): Boolean = point.indices.all { i -> diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/domains/UnconstrainedDomain.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/domains/UnconstrainedDomain.kt index 002caac50..79f33fe05 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/domains/UnconstrainedDomain.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/domains/UnconstrainedDomain.kt @@ -19,7 +19,7 @@ import space.kscience.kmath.linear.Point import space.kscience.kmath.misc.UnstableKMathAPI @UnstableKMathAPI -public class UnconstrainedDomain(public override val dimension: Int) : RealDomain { +public class UnconstrainedDomain(public override val dimension: Int) : DoubleDomain { public override operator fun contains(point: Point): Boolean = true public override fun getLowerBound(num: Int): Double = Double.NEGATIVE_INFINITY diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/domains/UnivariateDomain.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/domains/UnivariateDomain.kt index d20349960..6f737bd38 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/domains/UnivariateDomain.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/domains/UnivariateDomain.kt @@ -4,7 +4,7 @@ import space.kscience.kmath.linear.Point import space.kscience.kmath.misc.UnstableKMathAPI @UnstableKMathAPI -public inline class UnivariateDomain(public val range: ClosedFloatingPointRange) : RealDomain { +public inline class UnivariateDomain(public val range: ClosedFloatingPointRange) : DoubleDomain { public override val dimension: Int get() = 1 public operator fun contains(d: Double): Boolean = range.contains(d) diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/SimpleAutoDiff.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/SimpleAutoDiff.kt index 4b5b3311e..4b0d402ed 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/SimpleAutoDiff.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/SimpleAutoDiff.kt @@ -198,7 +198,7 @@ public open class SimpleAutoDiffField>( * Example: * ``` * val x by symbol // define variable(s) and their values - * val y = RealField.withAutoDiff() { sqr(x) + 5 * x + 3 } // write formulate in deriv context + * val y = DoubleField.withAutoDiff() { sqr(x) + 5 * x + 3 } // write formulate in deriv context * assertEquals(17.0, y.x) // the value of result (y) * assertEquals(9.0, x.d) // dy/dx * ``` diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/LinearSpace.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/LinearSpace.kt index e8c7d119b..6a587270b 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/LinearSpace.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/LinearSpace.kt @@ -5,7 +5,7 @@ import space.kscience.kmath.nd.* import space.kscience.kmath.operations.* import space.kscience.kmath.structures.Buffer import space.kscience.kmath.structures.BufferFactory -import space.kscience.kmath.structures.RealBuffer +import space.kscience.kmath.structures.DoubleBuffer import kotlin.reflect.KClass /** @@ -176,7 +176,7 @@ public interface LinearSpace> { bufferFactory: BufferFactory = Buffer.Companion::boxing, ): LinearSpace = BufferedLinearSpace(algebra, bufferFactory) - public val real: LinearSpace = buffered(RealField, ::RealBuffer) + public val real: LinearSpace = buffered(DoubleField, ::DoubleBuffer) /** * Automatic buffered matrix, unboxed if it is possible diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/LupDecomposition.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/LupDecomposition.kt index eed50ec28..7a6495638 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/LupDecomposition.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/LupDecomposition.kt @@ -4,9 +4,9 @@ import space.kscience.kmath.misc.UnstableKMathAPI import space.kscience.kmath.nd.getFeature import space.kscience.kmath.operations.* import space.kscience.kmath.structures.BufferAccessor2D +import space.kscience.kmath.structures.DoubleBuffer import space.kscience.kmath.structures.MutableBuffer import space.kscience.kmath.structures.MutableBufferFactory -import space.kscience.kmath.structures.RealBuffer /** * Common implementation of [LupDecompositionFeature]. @@ -151,8 +151,8 @@ public inline fun > LinearSpace>.lup( noinline checkSingular: (T) -> Boolean, ): LupDecomposition = lup(MutableBuffer.Companion::auto, matrix, checkSingular) -public fun LinearSpace.lup(matrix: Matrix): LupDecomposition = - lup(::RealBuffer, matrix) { it < 1e-11 } +public fun LinearSpace.lup(matrix: Matrix): LupDecomposition = + lup(::DoubleBuffer, matrix) { it < 1e-11 } public fun LupDecomposition.solveWithLup( factory: MutableBufferFactory, @@ -228,9 +228,9 @@ public inline fun > LinearSpace>.inverseWi @OptIn(UnstableKMathAPI::class) -public fun LinearSpace.solveWithLup(a: Matrix, b: Matrix): Matrix { +public fun LinearSpace.solveWithLup(a: Matrix, b: Matrix): Matrix { // Use existing decomposition if it is provided by matrix - val bufferFactory: MutableBufferFactory = ::RealBuffer + val bufferFactory: MutableBufferFactory = ::DoubleBuffer val decomposition: LupDecomposition = a.getFeature() ?: lup(bufferFactory, a) { it < 1e-11 } return decomposition.solveWithLup(bufferFactory, b) } @@ -238,5 +238,5 @@ public fun LinearSpace.solveWithLup(a: Matrix, b: Mat /** * Inverses a square matrix using LUP decomposition. Non square matrix will throw a error. */ -public fun LinearSpace.inverseWithLup(matrix: Matrix): Matrix = +public fun LinearSpace.inverseWithLup(matrix: Matrix): Matrix = solveWithLup(matrix, one(matrix.rowNum, matrix.colNum)) \ No newline at end of file diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/BufferAlgebraND.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/BufferAlgebraND.kt index cef43d06f..b81eb9519 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/BufferAlgebraND.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/BufferAlgebraND.kt @@ -123,7 +123,7 @@ public inline fun > AlgebraND.Companion.auto( field: A, vararg shape: Int, ): FieldND = when (field) { - RealField -> RealFieldND(shape) as FieldND + DoubleField -> DoubleFieldND(shape) as FieldND else -> BufferedFieldND(shape, field, Buffer.Companion::auto) } diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/RealFieldND.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/DoubleFieldND.kt similarity index 67% rename from kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/RealFieldND.kt rename to kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/DoubleFieldND.kt index 643eb2eb0..a7a9d8935 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/RealFieldND.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/DoubleFieldND.kt @@ -1,18 +1,18 @@ package space.kscience.kmath.nd import space.kscience.kmath.misc.UnstableKMathAPI +import space.kscience.kmath.operations.DoubleField import space.kscience.kmath.operations.ExtendedField import space.kscience.kmath.operations.NumbersAddOperations -import space.kscience.kmath.operations.RealField import space.kscience.kmath.operations.ScaleOperations -import space.kscience.kmath.structures.RealBuffer +import space.kscience.kmath.structures.DoubleBuffer import kotlin.contracts.InvocationKind import kotlin.contracts.contract @OptIn(UnstableKMathAPI::class) -public class RealFieldND( +public class DoubleFieldND( shape: IntArray, -) : BufferedFieldND(shape, RealField, ::RealBuffer), +) : BufferedFieldND(shape, DoubleField, ::DoubleBuffer), NumbersAddOperations>, ScaleOperations>, ExtendedField> { @@ -25,40 +25,40 @@ public class RealFieldND( return produce { d } } - override val StructureND.buffer: RealBuffer + override val StructureND.buffer: DoubleBuffer get() = when { - !shape.contentEquals(this@RealFieldND.shape) -> throw ShapeMismatchException( - this@RealFieldND.shape, + !shape.contentEquals(this@DoubleFieldND.shape) -> throw ShapeMismatchException( + this@DoubleFieldND.shape, shape ) - this is NDBuffer && this.strides == this@RealFieldND.strides -> this.buffer as RealBuffer - else -> RealBuffer(strides.linearSize) { offset -> get(strides.index(offset)) } + this is NDBuffer && this.strides == this@DoubleFieldND.strides -> this.buffer as DoubleBuffer + else -> DoubleBuffer(strides.linearSize) { offset -> get(strides.index(offset)) } } @Suppress("OVERRIDE_BY_INLINE") override inline fun StructureND.map( - transform: RealField.(Double) -> Double, + transform: DoubleField.(Double) -> Double, ): NDBuffer { - val buffer = RealBuffer(strides.linearSize) { offset -> RealField.transform(buffer.array[offset]) } + val buffer = DoubleBuffer(strides.linearSize) { offset -> DoubleField.transform(buffer.array[offset]) } return NDBuffer(strides, buffer) } @Suppress("OVERRIDE_BY_INLINE") - override inline fun produce(initializer: RealField.(IntArray) -> Double): NDBuffer { + override inline fun produce(initializer: DoubleField.(IntArray) -> Double): NDBuffer { val array = DoubleArray(strides.linearSize) { offset -> val index = strides.index(offset) - RealField.initializer(index) + DoubleField.initializer(index) } - return NDBuffer(strides, RealBuffer(array)) + return NDBuffer(strides, DoubleBuffer(array)) } @Suppress("OVERRIDE_BY_INLINE") override inline fun StructureND.mapIndexed( - transform: RealField.(index: IntArray, Double) -> Double, + transform: DoubleField.(index: IntArray, Double) -> Double, ): NDBuffer = NDBuffer( strides, - buffer = RealBuffer(strides.linearSize) { offset -> - RealField.transform( + buffer = DoubleBuffer(strides.linearSize) { offset -> + DoubleField.transform( strides.index(offset), buffer.array[offset] ) @@ -68,10 +68,10 @@ public class RealFieldND( override inline fun combine( a: StructureND, b: StructureND, - transform: RealField.(Double, Double) -> Double, + transform: DoubleField.(Double, Double) -> Double, ): NDBuffer { - val buffer = RealBuffer(strides.linearSize) { offset -> - RealField.transform(a.buffer.array[offset], b.buffer.array[offset]) + val buffer = DoubleBuffer(strides.linearSize) { offset -> + DoubleField.transform(a.buffer.array[offset], b.buffer.array[offset]) } return NDBuffer(strides, buffer) } @@ -99,12 +99,12 @@ public class RealFieldND( override fun atanh(arg: StructureND): NDBuffer = arg.map { atanh(it) } } -public fun AlgebraND.Companion.real(vararg shape: Int): RealFieldND = RealFieldND(shape) +public fun AlgebraND.Companion.real(vararg shape: Int): DoubleFieldND = DoubleFieldND(shape) /** * Produce a context for n-dimensional operations inside this real field */ -public inline fun RealField.nd(vararg shape: Int, action: RealFieldND.() -> R): R { +public inline fun DoubleField.nd(vararg shape: Int, action: DoubleFieldND.() -> R): R { contract { callsInPlace(action, InvocationKind.EXACTLY_ONCE) } - return RealFieldND(shape).run(action) + return DoubleFieldND(shape).run(action) } diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/numbers.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/numbers.kt index 4841e78d6..0101b058a 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/numbers.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/numbers.kt @@ -55,7 +55,7 @@ public interface ExtendedField : ExtendedFieldOperations, Field, Numeri * A field for [Double] without boxing. Does not produce appropriate field element. */ @Suppress("EXTENSION_SHADOWED_BY_MEMBER", "OVERRIDE_BY_INLINE", "NOTHING_TO_INLINE") -public object RealField : ExtendedField, Norm, ScaleOperations { +public object DoubleField : ExtendedField, Norm, ScaleOperations { public override val zero: Double = 0.0 public override val one: Double = 1.0 diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Buffer.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Buffer.kt index 1d40a2f2e..1c64bfcec 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Buffer.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Buffer.kt @@ -53,14 +53,14 @@ public interface Buffer { /** * Creates a [Buffer] of given [type]. If the type is primitive, specialized buffers are used ([IntBuffer], - * [RealBuffer], etc.), [ListBuffer] is returned otherwise. + * [DoubleBuffer], etc.), [ListBuffer] is returned otherwise. * * The [size] is specified, and each element is calculated by calling the specified [initializer] function. */ @Suppress("UNCHECKED_CAST") public inline fun auto(type: KClass, size: Int, initializer: (Int) -> T): Buffer = when (type) { - Double::class -> MutableBuffer.real(size) { initializer(it) as Double } as Buffer + Double::class -> MutableBuffer.double(size) { initializer(it) as Double } as Buffer Short::class -> MutableBuffer.short(size) { initializer(it) as Short } as Buffer Int::class -> MutableBuffer.int(size) { initializer(it) as Int } as Buffer Long::class -> MutableBuffer.long(size) { initializer(it) as Long } as Buffer @@ -70,7 +70,7 @@ public interface Buffer { /** * Creates a [Buffer] of given type [T]. If the type is primitive, specialized buffers are used ([IntBuffer], - * [RealBuffer], etc.), [ListBuffer] is returned otherwise. + * [DoubleBuffer], etc.), [ListBuffer] is returned otherwise. * * The [size] is specified, and each element is calculated by calling the specified [initializer] function. */ @@ -104,11 +104,11 @@ public interface MutableBuffer : Buffer { public companion object { /** - * Creates a [RealBuffer] with the specified [size], where each element is calculated by calling the specified + * Creates a [DoubleBuffer] with the specified [size], where each element is calculated by calling the specified * [initializer] function. */ - public inline fun real(size: Int, initializer: (Int) -> Double): RealBuffer = - RealBuffer(size, initializer) + public inline fun double(size: Int, initializer: (Int) -> Double): DoubleBuffer = + DoubleBuffer(size, initializer) /** * Creates a [ShortBuffer] with the specified [size], where each element is calculated by calling the specified @@ -148,14 +148,14 @@ public interface MutableBuffer : Buffer { /** * Creates a [MutableBuffer] of given [type]. If the type is primitive, specialized buffers are used - * ([IntBuffer], [RealBuffer], etc.), [ListBuffer] is returned otherwise. + * ([IntBuffer], [DoubleBuffer], etc.), [ListBuffer] is returned otherwise. * * The [size] is specified, and each element is calculated by calling the specified [initializer] function. */ @Suppress("UNCHECKED_CAST") public inline fun auto(type: KClass, size: Int, initializer: (Int) -> T): MutableBuffer = when (type) { - Double::class -> real(size) { initializer(it) as Double } as MutableBuffer + Double::class -> double(size) { initializer(it) as Double } as MutableBuffer Short::class -> short(size) { initializer(it) as Short } as MutableBuffer Int::class -> int(size) { initializer(it) as Int } as MutableBuffer Float::class -> float(size) { initializer(it) as Float } as MutableBuffer @@ -165,7 +165,7 @@ public interface MutableBuffer : Buffer { /** * Creates a [MutableBuffer] of given type [T]. If the type is primitive, specialized buffers are used - * ([IntBuffer], [RealBuffer], etc.), [ListBuffer] is returned otherwise. + * ([IntBuffer], [DoubleBuffer], etc.), [ListBuffer] is returned otherwise. * * The [size] is specified, and each element is calculated by calling the specified [initializer] function. */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/RealBuffer.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/DoubleBuffer.kt similarity index 53% rename from kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/RealBuffer.kt rename to kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/DoubleBuffer.kt index b56c03b76..0a23d31fe 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/RealBuffer.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/DoubleBuffer.kt @@ -6,7 +6,7 @@ package space.kscience.kmath.structures * @property array the underlying array. */ @Suppress("OVERRIDE_BY_INLINE") -public inline class RealBuffer(public val array: DoubleArray) : MutableBuffer { +public inline class DoubleBuffer(public val array: DoubleArray) : MutableBuffer { override val size: Int get() = array.size override operator fun get(index: Int): Double = array[index] @@ -17,40 +17,40 @@ public inline class RealBuffer(public val array: DoubleArray) : MutableBuffer Double): RealBuffer = RealBuffer(DoubleArray(size) { init(it) }) +public inline fun DoubleBuffer(size: Int, init: (Int) -> Double): DoubleBuffer = DoubleBuffer(DoubleArray(size) { init(it) }) /** - * Returns a new [RealBuffer] of given elements. + * Returns a new [DoubleBuffer] of given elements. */ -public fun RealBuffer(vararg doubles: Double): RealBuffer = RealBuffer(doubles) +public fun DoubleBuffer(vararg doubles: Double): DoubleBuffer = DoubleBuffer(doubles) /** - * Simplified [RealBuffer] to array comparison + * Simplified [DoubleBuffer] to array comparison */ -public fun RealBuffer.contentEquals(vararg doubles: Double): Boolean = array.contentEquals(doubles) +public fun DoubleBuffer.contentEquals(vararg doubles: Double): Boolean = array.contentEquals(doubles) /** * Returns a new [DoubleArray] containing all of the elements of this [Buffer]. */ public fun Buffer.toDoubleArray(): DoubleArray = when (this) { - is RealBuffer -> array.copyOf() + is DoubleBuffer -> array.copyOf() else -> DoubleArray(size, ::get) } /** - * Returns [RealBuffer] over this array. + * Returns [DoubleBuffer] over this array. * * @receiver the array. * @return the new buffer. */ -public fun DoubleArray.asBuffer(): RealBuffer = RealBuffer(this) +public fun DoubleArray.asBuffer(): DoubleBuffer = DoubleBuffer(this) diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/DoubleBufferField.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/DoubleBufferField.kt new file mode 100644 index 000000000..4a85219ac --- /dev/null +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/DoubleBufferField.kt @@ -0,0 +1,272 @@ +package space.kscience.kmath.structures + +import space.kscience.kmath.operations.ExtendedField +import space.kscience.kmath.operations.ExtendedFieldOperations +import kotlin.math.* + +/** + * [ExtendedFieldOperations] over [DoubleBuffer]. + */ +public object DoubleBufferFieldOperations : ExtendedFieldOperations> { + override fun Buffer.unaryMinus(): DoubleBuffer = if (this is DoubleBuffer) { + DoubleBuffer(size) { -array[it] } + } else { + DoubleBuffer(size) { -get(it) } + } + + public override fun add(a: Buffer, b: Buffer): DoubleBuffer { + require(b.size == a.size) { + "The size of the first buffer ${a.size} should be the same as for second one: ${b.size} " + } + + return if (a is DoubleBuffer && b is DoubleBuffer) { + val aArray = a.array + val bArray = b.array + DoubleBuffer(DoubleArray(a.size) { aArray[it] + bArray[it] }) + } else DoubleBuffer(DoubleArray(a.size) { a[it] + b[it] }) + } +// +// public override fun multiply(a: Buffer, k: Number): RealBuffer { +// val kValue = k.toDouble() +// +// return if (a is RealBuffer) { +// val aArray = a.array +// RealBuffer(DoubleArray(a.size) { aArray[it] * kValue }) +// } else RealBuffer(DoubleArray(a.size) { a[it] * kValue }) +// } +// +// public override fun divide(a: Buffer, k: Number): RealBuffer { +// val kValue = k.toDouble() +// +// return if (a is RealBuffer) { +// val aArray = a.array +// RealBuffer(DoubleArray(a.size) { aArray[it] / kValue }) +// } else RealBuffer(DoubleArray(a.size) { a[it] / kValue }) +// } + + public override fun multiply(a: Buffer, b: Buffer): DoubleBuffer { + require(b.size == a.size) { + "The size of the first buffer ${a.size} should be the same as for second one: ${b.size} " + } + + return if (a is DoubleBuffer && b is DoubleBuffer) { + val aArray = a.array + val bArray = b.array + DoubleBuffer(DoubleArray(a.size) { aArray[it] * bArray[it] }) + } else + DoubleBuffer(DoubleArray(a.size) { a[it] * b[it] }) + } + + public override fun divide(a: Buffer, b: Buffer): DoubleBuffer { + require(b.size == a.size) { + "The size of the first buffer ${a.size} should be the same as for second one: ${b.size} " + } + + return if (a is DoubleBuffer && b is DoubleBuffer) { + val aArray = a.array + val bArray = b.array + DoubleBuffer(DoubleArray(a.size) { aArray[it] / bArray[it] }) + } else DoubleBuffer(DoubleArray(a.size) { a[it] / b[it] }) + } + + public override fun sin(arg: Buffer): DoubleBuffer = if (arg is DoubleBuffer) { + val array = arg.array + DoubleBuffer(DoubleArray(arg.size) { sin(array[it]) }) + } else DoubleBuffer(DoubleArray(arg.size) { sin(arg[it]) }) + + public override fun cos(arg: Buffer): DoubleBuffer = if (arg is DoubleBuffer) { + val array = arg.array + DoubleBuffer(DoubleArray(arg.size) { cos(array[it]) }) + } else DoubleBuffer(DoubleArray(arg.size) { cos(arg[it]) }) + + public override fun tan(arg: Buffer): DoubleBuffer = if (arg is DoubleBuffer) { + val array = arg.array + DoubleBuffer(DoubleArray(arg.size) { tan(array[it]) }) + } else DoubleBuffer(DoubleArray(arg.size) { tan(arg[it]) }) + + public override fun asin(arg: Buffer): DoubleBuffer = if (arg is DoubleBuffer) { + val array = arg.array + DoubleBuffer(DoubleArray(arg.size) { asin(array[it]) }) + } else + DoubleBuffer(DoubleArray(arg.size) { asin(arg[it]) }) + + public override fun acos(arg: Buffer): DoubleBuffer = if (arg is DoubleBuffer) { + val array = arg.array + DoubleBuffer(DoubleArray(arg.size) { acos(array[it]) }) + } else + DoubleBuffer(DoubleArray(arg.size) { acos(arg[it]) }) + + public override fun atan(arg: Buffer): DoubleBuffer = if (arg is DoubleBuffer) { + val array = arg.array + DoubleBuffer(DoubleArray(arg.size) { atan(array[it]) }) + } else + DoubleBuffer(DoubleArray(arg.size) { atan(arg[it]) }) + + public override fun sinh(arg: Buffer): DoubleBuffer = if (arg is DoubleBuffer) { + val array = arg.array + DoubleBuffer(DoubleArray(arg.size) { sinh(array[it]) }) + } else + DoubleBuffer(DoubleArray(arg.size) { sinh(arg[it]) }) + + public override fun cosh(arg: Buffer): DoubleBuffer = if (arg is DoubleBuffer) { + val array = arg.array + DoubleBuffer(DoubleArray(arg.size) { cosh(array[it]) }) + } else + DoubleBuffer(DoubleArray(arg.size) { cosh(arg[it]) }) + + public override fun tanh(arg: Buffer): DoubleBuffer = if (arg is DoubleBuffer) { + val array = arg.array + DoubleBuffer(DoubleArray(arg.size) { tanh(array[it]) }) + } else + DoubleBuffer(DoubleArray(arg.size) { tanh(arg[it]) }) + + public override fun asinh(arg: Buffer): DoubleBuffer = if (arg is DoubleBuffer) { + val array = arg.array + DoubleBuffer(DoubleArray(arg.size) { asinh(array[it]) }) + } else + DoubleBuffer(DoubleArray(arg.size) { asinh(arg[it]) }) + + public override fun acosh(arg: Buffer): DoubleBuffer = if (arg is DoubleBuffer) { + val array = arg.array + DoubleBuffer(DoubleArray(arg.size) { acosh(array[it]) }) + } else + DoubleBuffer(DoubleArray(arg.size) { acosh(arg[it]) }) + + public override fun atanh(arg: Buffer): DoubleBuffer = if (arg is DoubleBuffer) { + val array = arg.array + DoubleBuffer(DoubleArray(arg.size) { atanh(array[it]) }) + } else + DoubleBuffer(DoubleArray(arg.size) { atanh(arg[it]) }) + + public override fun power(arg: Buffer, pow: Number): DoubleBuffer = if (arg is DoubleBuffer) { + val array = arg.array + DoubleBuffer(DoubleArray(arg.size) { array[it].pow(pow.toDouble()) }) + } else + DoubleBuffer(DoubleArray(arg.size) { arg[it].pow(pow.toDouble()) }) + + public override fun exp(arg: Buffer): DoubleBuffer = if (arg is DoubleBuffer) { + val array = arg.array + DoubleBuffer(DoubleArray(arg.size) { exp(array[it]) }) + } else DoubleBuffer(DoubleArray(arg.size) { exp(arg[it]) }) + + public override fun ln(arg: Buffer): DoubleBuffer = if (arg is DoubleBuffer) { + val array = arg.array + DoubleBuffer(DoubleArray(arg.size) { ln(array[it]) }) + } else + DoubleBuffer(DoubleArray(arg.size) { ln(arg[it]) }) +} + +/** + * [ExtendedField] over [DoubleBuffer]. + * + * @property size the size of buffers to operate on. + */ +public class DoubleBufferField(public val size: Int) : ExtendedField> { + public override val zero: Buffer by lazy { DoubleBuffer(size) { 0.0 } } + public override val one: Buffer by lazy { DoubleBuffer(size) { 1.0 } } + + override fun number(value: Number): Buffer = DoubleBuffer(size) { value.toDouble() } + + override fun Buffer.unaryMinus(): Buffer = DoubleBufferFieldOperations.run { + -this@unaryMinus + } + + public override fun add(a: Buffer, b: Buffer): DoubleBuffer { + require(a.size == size) { "The buffer size ${a.size} does not match context size $size" } + return DoubleBufferFieldOperations.add(a, b) + } + + public override fun scale(a: Buffer, value: Double): DoubleBuffer { + require(a.size == size) { "The buffer size ${a.size} does not match context size $size" } + + return if (a is DoubleBuffer) { + val aArray = a.array + DoubleBuffer(DoubleArray(a.size) { aArray[it] * value }) + } else DoubleBuffer(DoubleArray(a.size) { a[it] * value }) + } + + public override fun multiply(a: Buffer, b: Buffer): DoubleBuffer { + require(a.size == size) { "The buffer size ${a.size} does not match context size $size" } + return DoubleBufferFieldOperations.multiply(a, b) + } + + public override fun divide(a: Buffer, b: Buffer): DoubleBuffer { + require(a.size == size) { "The buffer size ${a.size} does not match context size $size" } + return DoubleBufferFieldOperations.divide(a, b) + } + + public override fun sin(arg: Buffer): DoubleBuffer { + require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } + return DoubleBufferFieldOperations.sin(arg) + } + + public override fun cos(arg: Buffer): DoubleBuffer { + require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } + return DoubleBufferFieldOperations.cos(arg) + } + + public override fun tan(arg: Buffer): DoubleBuffer { + require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } + return DoubleBufferFieldOperations.tan(arg) + } + + public override fun asin(arg: Buffer): DoubleBuffer { + require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } + return DoubleBufferFieldOperations.asin(arg) + } + + public override fun acos(arg: Buffer): DoubleBuffer { + require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } + return DoubleBufferFieldOperations.acos(arg) + } + + public override fun atan(arg: Buffer): DoubleBuffer { + require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } + return DoubleBufferFieldOperations.atan(arg) + } + + public override fun sinh(arg: Buffer): DoubleBuffer { + require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } + return DoubleBufferFieldOperations.sinh(arg) + } + + public override fun cosh(arg: Buffer): DoubleBuffer { + require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } + return DoubleBufferFieldOperations.cosh(arg) + } + + public override fun tanh(arg: Buffer): DoubleBuffer { + require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } + return DoubleBufferFieldOperations.tanh(arg) + } + + public override fun asinh(arg: Buffer): DoubleBuffer { + require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } + return DoubleBufferFieldOperations.asinh(arg) + } + + public override fun acosh(arg: Buffer): DoubleBuffer { + require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } + return DoubleBufferFieldOperations.acosh(arg) + } + + public override fun atanh(arg: Buffer): DoubleBuffer { + require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } + return DoubleBufferFieldOperations.atanh(arg) + } + + public override fun power(arg: Buffer, pow: Number): DoubleBuffer { + require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } + return DoubleBufferFieldOperations.power(arg, pow) + } + + public override fun exp(arg: Buffer): DoubleBuffer { + require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } + return DoubleBufferFieldOperations.exp(arg) + } + + public override fun ln(arg: Buffer): DoubleBuffer { + require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } + return DoubleBufferFieldOperations.ln(arg) + } +} diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/FlaggedBuffer.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/FlaggedBuffer.kt index 3326c1491..670a0c175 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/FlaggedBuffer.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/FlaggedBuffer.kt @@ -48,7 +48,7 @@ public fun FlaggedBuffer<*>.isMissing(index: Int): Boolean = hasFlag(index, Valu /** * A real buffer which supports flags for each value like NaN or Missing */ -public class FlaggedRealBuffer(public val values: DoubleArray, public val flags: ByteArray) : FlaggedBuffer, +public class FlaggedDoubleBuffer(public val values: DoubleArray, public val flags: ByteArray) : FlaggedBuffer, Buffer { init { require(values.size == flags.size) { "Values and flags must have the same dimensions" } @@ -65,7 +65,7 @@ public class FlaggedRealBuffer(public val values: DoubleArray, public val flags: }.iterator() } -public inline fun FlaggedRealBuffer.forEachValid(block: (Double) -> Unit) { +public inline fun FlaggedDoubleBuffer.forEachValid(block: (Double) -> Unit) { indices .asSequence() .filter(::isValid) diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/RealBufferField.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/RealBufferField.kt deleted file mode 100644 index 2a03a36e3..000000000 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/RealBufferField.kt +++ /dev/null @@ -1,272 +0,0 @@ -package space.kscience.kmath.structures - -import space.kscience.kmath.operations.ExtendedField -import space.kscience.kmath.operations.ExtendedFieldOperations -import kotlin.math.* - -/** - * [ExtendedFieldOperations] over [RealBuffer]. - */ -public object RealBufferFieldOperations : ExtendedFieldOperations> { - override fun Buffer.unaryMinus(): RealBuffer = if (this is RealBuffer) { - RealBuffer(size) { -array[it] } - } else { - RealBuffer(size) { -get(it) } - } - - public override fun add(a: Buffer, b: Buffer): RealBuffer { - require(b.size == a.size) { - "The size of the first buffer ${a.size} should be the same as for second one: ${b.size} " - } - - return if (a is RealBuffer && b is RealBuffer) { - val aArray = a.array - val bArray = b.array - RealBuffer(DoubleArray(a.size) { aArray[it] + bArray[it] }) - } else RealBuffer(DoubleArray(a.size) { a[it] + b[it] }) - } -// -// public override fun multiply(a: Buffer, k: Number): RealBuffer { -// val kValue = k.toDouble() -// -// return if (a is RealBuffer) { -// val aArray = a.array -// RealBuffer(DoubleArray(a.size) { aArray[it] * kValue }) -// } else RealBuffer(DoubleArray(a.size) { a[it] * kValue }) -// } -// -// public override fun divide(a: Buffer, k: Number): RealBuffer { -// val kValue = k.toDouble() -// -// return if (a is RealBuffer) { -// val aArray = a.array -// RealBuffer(DoubleArray(a.size) { aArray[it] / kValue }) -// } else RealBuffer(DoubleArray(a.size) { a[it] / kValue }) -// } - - public override fun multiply(a: Buffer, b: Buffer): RealBuffer { - require(b.size == a.size) { - "The size of the first buffer ${a.size} should be the same as for second one: ${b.size} " - } - - return if (a is RealBuffer && b is RealBuffer) { - val aArray = a.array - val bArray = b.array - RealBuffer(DoubleArray(a.size) { aArray[it] * bArray[it] }) - } else - RealBuffer(DoubleArray(a.size) { a[it] * b[it] }) - } - - public override fun divide(a: Buffer, b: Buffer): RealBuffer { - require(b.size == a.size) { - "The size of the first buffer ${a.size} should be the same as for second one: ${b.size} " - } - - return if (a is RealBuffer && b is RealBuffer) { - val aArray = a.array - val bArray = b.array - RealBuffer(DoubleArray(a.size) { aArray[it] / bArray[it] }) - } else RealBuffer(DoubleArray(a.size) { a[it] / b[it] }) - } - - public override fun sin(arg: Buffer): RealBuffer = if (arg is RealBuffer) { - val array = arg.array - RealBuffer(DoubleArray(arg.size) { sin(array[it]) }) - } else RealBuffer(DoubleArray(arg.size) { sin(arg[it]) }) - - public override fun cos(arg: Buffer): RealBuffer = if (arg is RealBuffer) { - val array = arg.array - RealBuffer(DoubleArray(arg.size) { cos(array[it]) }) - } else RealBuffer(DoubleArray(arg.size) { cos(arg[it]) }) - - public override fun tan(arg: Buffer): RealBuffer = if (arg is RealBuffer) { - val array = arg.array - RealBuffer(DoubleArray(arg.size) { tan(array[it]) }) - } else RealBuffer(DoubleArray(arg.size) { tan(arg[it]) }) - - public override fun asin(arg: Buffer): RealBuffer = if (arg is RealBuffer) { - val array = arg.array - RealBuffer(DoubleArray(arg.size) { asin(array[it]) }) - } else - RealBuffer(DoubleArray(arg.size) { asin(arg[it]) }) - - public override fun acos(arg: Buffer): RealBuffer = if (arg is RealBuffer) { - val array = arg.array - RealBuffer(DoubleArray(arg.size) { acos(array[it]) }) - } else - RealBuffer(DoubleArray(arg.size) { acos(arg[it]) }) - - public override fun atan(arg: Buffer): RealBuffer = if (arg is RealBuffer) { - val array = arg.array - RealBuffer(DoubleArray(arg.size) { atan(array[it]) }) - } else - RealBuffer(DoubleArray(arg.size) { atan(arg[it]) }) - - public override fun sinh(arg: Buffer): RealBuffer = if (arg is RealBuffer) { - val array = arg.array - RealBuffer(DoubleArray(arg.size) { sinh(array[it]) }) - } else - RealBuffer(DoubleArray(arg.size) { sinh(arg[it]) }) - - public override fun cosh(arg: Buffer): RealBuffer = if (arg is RealBuffer) { - val array = arg.array - RealBuffer(DoubleArray(arg.size) { cosh(array[it]) }) - } else - RealBuffer(DoubleArray(arg.size) { cosh(arg[it]) }) - - public override fun tanh(arg: Buffer): RealBuffer = if (arg is RealBuffer) { - val array = arg.array - RealBuffer(DoubleArray(arg.size) { tanh(array[it]) }) - } else - RealBuffer(DoubleArray(arg.size) { tanh(arg[it]) }) - - public override fun asinh(arg: Buffer): RealBuffer = if (arg is RealBuffer) { - val array = arg.array - RealBuffer(DoubleArray(arg.size) { asinh(array[it]) }) - } else - RealBuffer(DoubleArray(arg.size) { asinh(arg[it]) }) - - public override fun acosh(arg: Buffer): RealBuffer = if (arg is RealBuffer) { - val array = arg.array - RealBuffer(DoubleArray(arg.size) { acosh(array[it]) }) - } else - RealBuffer(DoubleArray(arg.size) { acosh(arg[it]) }) - - public override fun atanh(arg: Buffer): RealBuffer = if (arg is RealBuffer) { - val array = arg.array - RealBuffer(DoubleArray(arg.size) { atanh(array[it]) }) - } else - RealBuffer(DoubleArray(arg.size) { atanh(arg[it]) }) - - public override fun power(arg: Buffer, pow: Number): RealBuffer = if (arg is RealBuffer) { - val array = arg.array - RealBuffer(DoubleArray(arg.size) { array[it].pow(pow.toDouble()) }) - } else - RealBuffer(DoubleArray(arg.size) { arg[it].pow(pow.toDouble()) }) - - public override fun exp(arg: Buffer): RealBuffer = if (arg is RealBuffer) { - val array = arg.array - RealBuffer(DoubleArray(arg.size) { exp(array[it]) }) - } else RealBuffer(DoubleArray(arg.size) { exp(arg[it]) }) - - public override fun ln(arg: Buffer): RealBuffer = if (arg is RealBuffer) { - val array = arg.array - RealBuffer(DoubleArray(arg.size) { ln(array[it]) }) - } else - RealBuffer(DoubleArray(arg.size) { ln(arg[it]) }) -} - -/** - * [ExtendedField] over [RealBuffer]. - * - * @property size the size of buffers to operate on. - */ -public class RealBufferField(public val size: Int) : ExtendedField> { - public override val zero: Buffer by lazy { RealBuffer(size) { 0.0 } } - public override val one: Buffer by lazy { RealBuffer(size) { 1.0 } } - - override fun number(value: Number): Buffer = RealBuffer(size) { value.toDouble() } - - override fun Buffer.unaryMinus(): Buffer = RealBufferFieldOperations.run { - -this@unaryMinus - } - - public override fun add(a: Buffer, b: Buffer): RealBuffer { - require(a.size == size) { "The buffer size ${a.size} does not match context size $size" } - return RealBufferFieldOperations.add(a, b) - } - - public override fun scale(a: Buffer, value: Double): RealBuffer { - require(a.size == size) { "The buffer size ${a.size} does not match context size $size" } - - return if (a is RealBuffer) { - val aArray = a.array - RealBuffer(DoubleArray(a.size) { aArray[it] * value }) - } else RealBuffer(DoubleArray(a.size) { a[it] * value }) - } - - public override fun multiply(a: Buffer, b: Buffer): RealBuffer { - require(a.size == size) { "The buffer size ${a.size} does not match context size $size" } - return RealBufferFieldOperations.multiply(a, b) - } - - public override fun divide(a: Buffer, b: Buffer): RealBuffer { - require(a.size == size) { "The buffer size ${a.size} does not match context size $size" } - return RealBufferFieldOperations.divide(a, b) - } - - public override fun sin(arg: Buffer): RealBuffer { - require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } - return RealBufferFieldOperations.sin(arg) - } - - public override fun cos(arg: Buffer): RealBuffer { - require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } - return RealBufferFieldOperations.cos(arg) - } - - public override fun tan(arg: Buffer): RealBuffer { - require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } - return RealBufferFieldOperations.tan(arg) - } - - public override fun asin(arg: Buffer): RealBuffer { - require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } - return RealBufferFieldOperations.asin(arg) - } - - public override fun acos(arg: Buffer): RealBuffer { - require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } - return RealBufferFieldOperations.acos(arg) - } - - public override fun atan(arg: Buffer): RealBuffer { - require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } - return RealBufferFieldOperations.atan(arg) - } - - public override fun sinh(arg: Buffer): RealBuffer { - require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } - return RealBufferFieldOperations.sinh(arg) - } - - public override fun cosh(arg: Buffer): RealBuffer { - require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } - return RealBufferFieldOperations.cosh(arg) - } - - public override fun tanh(arg: Buffer): RealBuffer { - require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } - return RealBufferFieldOperations.tanh(arg) - } - - public override fun asinh(arg: Buffer): RealBuffer { - require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } - return RealBufferFieldOperations.asinh(arg) - } - - public override fun acosh(arg: Buffer): RealBuffer { - require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } - return RealBufferFieldOperations.acosh(arg) - } - - public override fun atanh(arg: Buffer): RealBuffer { - require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } - return RealBufferFieldOperations.atanh(arg) - } - - public override fun power(arg: Buffer, pow: Number): RealBuffer { - require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } - return RealBufferFieldOperations.power(arg, pow) - } - - public override fun exp(arg: Buffer): RealBuffer { - require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } - return RealBufferFieldOperations.exp(arg) - } - - public override fun ln(arg: Buffer): RealBuffer { - require(arg.size == size) { "The buffer size ${arg.size} does not match context size $size" } - return RealBufferFieldOperations.ln(arg) - } -} diff --git a/kmath-core/src/commonTest/kotlin/space/kscience/kmath/expressions/ExpressionFieldTest.kt b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/expressions/ExpressionFieldTest.kt index cf75eba3e..b1be0c392 100644 --- a/kmath-core/src/commonTest/kotlin/space/kscience/kmath/expressions/ExpressionFieldTest.kt +++ b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/expressions/ExpressionFieldTest.kt @@ -1,6 +1,6 @@ package space.kscience.kmath.expressions -import space.kscience.kmath.operations.RealField +import space.kscience.kmath.operations.DoubleField import space.kscience.kmath.operations.invoke import kotlin.test.Test import kotlin.test.assertEquals @@ -11,7 +11,7 @@ class ExpressionFieldTest { @Test fun testExpression() { - val expression = FunctionalExpressionField(RealField).invoke { + val expression = FunctionalExpressionField(DoubleField).invoke { val x by binding() x * x + 2 * x + one } @@ -27,7 +27,7 @@ class ExpressionFieldTest { return x * x + 2 * x + one } - val expression = FunctionalExpressionField(RealField).expression() + val expression = FunctionalExpressionField(DoubleField).expression() assertEquals(expression(x to 1.0), 4.0) } @@ -38,7 +38,7 @@ class ExpressionFieldTest { x * x + 2 * x + one } - val expression = FunctionalExpressionField(RealField).expressionBuilder() + val expression = FunctionalExpressionField(DoubleField).expressionBuilder() assertEquals(expression(x to 1.0), 4.0) } } diff --git a/kmath-core/src/commonTest/kotlin/space/kscience/kmath/expressions/SimpleAutoDiffTest.kt b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/expressions/SimpleAutoDiffTest.kt index ee7fffa4c..95b2b2d1c 100644 --- a/kmath-core/src/commonTest/kotlin/space/kscience/kmath/expressions/SimpleAutoDiffTest.kt +++ b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/expressions/SimpleAutoDiffTest.kt @@ -1,6 +1,6 @@ package space.kscience.kmath.expressions -import space.kscience.kmath.operations.RealField +import space.kscience.kmath.operations.DoubleField import space.kscience.kmath.structures.asBuffer import kotlin.math.E import kotlin.math.PI @@ -14,19 +14,19 @@ class SimpleAutoDiffTest { fun dx( xBinding: Pair, - body: SimpleAutoDiffField.(x: AutoDiffValue) -> AutoDiffValue, - ): DerivationResult = RealField.simpleAutoDiff(xBinding) { body(bindSymbol(xBinding.first)) } + body: SimpleAutoDiffField.(x: AutoDiffValue) -> AutoDiffValue, + ): DerivationResult = DoubleField.simpleAutoDiff(xBinding) { body(bindSymbol(xBinding.first)) } fun dxy( xBinding: Pair, yBinding: Pair, - body: SimpleAutoDiffField.(x: AutoDiffValue, y: AutoDiffValue) -> AutoDiffValue, - ): DerivationResult = RealField.simpleAutoDiff(xBinding, yBinding) { + body: SimpleAutoDiffField.(x: AutoDiffValue, y: AutoDiffValue) -> AutoDiffValue, + ): DerivationResult = DoubleField.simpleAutoDiff(xBinding, yBinding) { body(bindSymbol(xBinding.first), bindSymbol(yBinding.first)) } - fun diff(block: SimpleAutoDiffField.() -> AutoDiffValue): SimpleAutoDiffExpression { - return SimpleAutoDiffExpression(RealField, block) + fun diff(block: SimpleAutoDiffField.() -> AutoDiffValue): SimpleAutoDiffExpression { + return SimpleAutoDiffExpression(DoubleField, block) } val x by symbol @@ -35,7 +35,7 @@ class SimpleAutoDiffTest { @Test fun testPlusX2() { - val y = RealField.simpleAutoDiff(x to 3.0) { + val y = DoubleField.simpleAutoDiff(x to 3.0) { // diff w.r.t this x at 3 val x = bindSymbol(x) x + x @@ -58,7 +58,7 @@ class SimpleAutoDiffTest { @Test fun testPlus() { // two variables - val z = RealField.simpleAutoDiff(x to 2.0, y to 3.0) { + val z = DoubleField.simpleAutoDiff(x to 2.0, y to 3.0) { val x = bindSymbol(x) val y = bindSymbol(y) x + y @@ -71,7 +71,7 @@ class SimpleAutoDiffTest { @Test fun testMinus() { // two variables - val z = RealField.simpleAutoDiff(x to 7.0, y to 3.0) { + val z = DoubleField.simpleAutoDiff(x to 7.0, y to 3.0) { val x = bindSymbol(x) val y = bindSymbol(y) diff --git a/kmath-core/src/commonTest/kotlin/space/kscience/kmath/linear/RealLUSolverTest.kt b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/linear/DoubleLUSolverTest.kt similarity index 97% rename from kmath-core/src/commonTest/kotlin/space/kscience/kmath/linear/RealLUSolverTest.kt rename to kmath-core/src/commonTest/kotlin/space/kscience/kmath/linear/DoubleLUSolverTest.kt index e6efc6a8a..6761575f6 100644 --- a/kmath-core/src/commonTest/kotlin/space/kscience/kmath/linear/RealLUSolverTest.kt +++ b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/linear/DoubleLUSolverTest.kt @@ -5,7 +5,7 @@ import kotlin.test.Test import kotlin.test.assertEquals @UnstableKMathAPI -class RealLUSolverTest { +class DoubleLUSolverTest { @Test fun testInvertOne() { diff --git a/kmath-core/src/commonTest/kotlin/space/kscience/kmath/operations/RealFieldTest.kt b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/operations/DoubleFieldTest.kt similarity index 59% rename from kmath-core/src/commonTest/kotlin/space/kscience/kmath/operations/RealFieldTest.kt rename to kmath-core/src/commonTest/kotlin/space/kscience/kmath/operations/DoubleFieldTest.kt index bba612d12..fde4f4a9e 100644 --- a/kmath-core/src/commonTest/kotlin/space/kscience/kmath/operations/RealFieldTest.kt +++ b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/operations/DoubleFieldTest.kt @@ -4,13 +4,13 @@ import space.kscience.kmath.testutils.FieldVerifier import kotlin.test.Test import kotlin.test.assertEquals -internal class RealFieldTest { +internal class DoubleFieldTest { @Test - fun verify() = FieldVerifier(RealField, 42.0, 66.0, 2.0, 5).verify() + fun verify() = FieldVerifier(DoubleField, 42.0, 66.0, 2.0, 5).verify() @Test fun testSqrt() { - val sqrt = RealField { sqrt(25 * one) } + val sqrt = DoubleField { sqrt(25 * one) } assertEquals(5.0, sqrt) } } diff --git a/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/chains/BlockingRealChain.kt b/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/chains/BlockingDoubleChain.kt similarity index 82% rename from kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/chains/BlockingRealChain.kt rename to kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/chains/BlockingDoubleChain.kt index ac6b117dc..bc4508994 100644 --- a/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/chains/BlockingRealChain.kt +++ b/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/chains/BlockingDoubleChain.kt @@ -3,7 +3,7 @@ package space.kscience.kmath.chains /** * Performance optimized chain for real values */ -public abstract class BlockingRealChain : Chain { +public abstract class BlockingDoubleChain : Chain { public abstract fun nextDouble(): Double override suspend fun next(): Double = nextDouble() diff --git a/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/streaming/BufferFlow.kt b/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/streaming/BufferFlow.kt index 4df22c2ad..c271f8889 100644 --- a/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/streaming/BufferFlow.kt +++ b/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/streaming/BufferFlow.kt @@ -2,10 +2,10 @@ package space.kscience.kmath.streaming import kotlinx.coroutines.FlowPreview import kotlinx.coroutines.flow.* -import space.kscience.kmath.chains.BlockingRealChain +import space.kscience.kmath.chains.BlockingDoubleChain import space.kscience.kmath.structures.Buffer import space.kscience.kmath.structures.BufferFactory -import space.kscience.kmath.structures.RealBuffer +import space.kscience.kmath.structures.DoubleBuffer import space.kscience.kmath.structures.asBuffer /** @@ -45,10 +45,10 @@ public fun Flow.chunked(bufferSize: Int, bufferFactory: BufferFactory) /** * Specialized flow chunker for real buffer */ -public fun Flow.chunked(bufferSize: Int): Flow = flow { +public fun Flow.chunked(bufferSize: Int): Flow = flow { require(bufferSize > 0) { "Resulting chunk size must be more than zero" } - if (this@chunked is BlockingRealChain) { + if (this@chunked is BlockingDoubleChain) { // performance optimization for blocking primitive chain while (true) emit(nextBlock(bufferSize).asBuffer()) } else { @@ -60,13 +60,13 @@ public fun Flow.chunked(bufferSize: Int): Flow = flow { counter++ if (counter == bufferSize) { - val buffer = RealBuffer(array) + val buffer = DoubleBuffer(array) emit(buffer) counter = 0 } } - if (counter > 0) emit(RealBuffer(counter) { array[it] }) + if (counter > 0) emit(DoubleBuffer(counter) { array[it] }) } } diff --git a/kmath-coroutines/src/jvmMain/kotlin/space/kscience/kmath/structures/LazyStructureND.kt b/kmath-coroutines/src/jvmMain/kotlin/space/kscience/kmath/structures/LazyStructureND.kt index 468b90561..261f91aee 100644 --- a/kmath-coroutines/src/jvmMain/kotlin/space/kscience/kmath/structures/LazyStructureND.kt +++ b/kmath-coroutines/src/jvmMain/kotlin/space/kscience/kmath/structures/LazyStructureND.kt @@ -10,7 +10,7 @@ public class LazyStructureND( public override val shape: IntArray, public val function: suspend (IntArray) -> T, ) : StructureND { - private val cache: MutableMap> = hashMapOf() + private val cache: MutableMap> = HashMap() public fun deferred(index: IntArray): Deferred = cache.getOrPut(index) { scope.async(context = Dispatchers.Math) { function(index) } diff --git a/kmath-dimensions/src/commonMain/kotlin/space/kscience/kmath/dimensions/Wrappers.kt b/kmath-dimensions/src/commonMain/kotlin/space/kscience/kmath/dimensions/Wrappers.kt index 81b008b6a..dd85a97cb 100644 --- a/kmath-dimensions/src/commonMain/kotlin/space/kscience/kmath/dimensions/Wrappers.kt +++ b/kmath-dimensions/src/commonMain/kotlin/space/kscience/kmath/dimensions/Wrappers.kt @@ -5,7 +5,7 @@ import space.kscience.kmath.linear.Matrix import space.kscience.kmath.linear.Point import space.kscience.kmath.linear.transpose import space.kscience.kmath.nd.Structure2D -import space.kscience.kmath.operations.RealField +import space.kscience.kmath.operations.DoubleField import space.kscience.kmath.operations.Ring /** @@ -142,7 +142,7 @@ public inline class DMatrixContext>(public val context: context.run { (this@transpose as Matrix).transpose() }.coerce() public companion object { - public val real: DMatrixContext = DMatrixContext(LinearSpace.real) + public val real: DMatrixContext = DMatrixContext(LinearSpace.real) } } @@ -150,12 +150,12 @@ public inline class DMatrixContext>(public val context: /** * A square unit matrix */ -public inline fun DMatrixContext.one(): DMatrix = +public inline fun DMatrixContext.one(): DMatrix = produce { i, j -> if (i == j) 1.0 else 0.0 } -public inline fun DMatrixContext.zero(): DMatrix = +public inline fun DMatrixContext.zero(): DMatrix = produce { _, _ -> 0.0 } \ No newline at end of file diff --git a/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/EjmlLinearSpace.kt b/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/EjmlLinearSpace.kt index 452280295..a82fe933e 100644 --- a/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/EjmlLinearSpace.kt +++ b/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/EjmlLinearSpace.kt @@ -5,8 +5,8 @@ import org.ejml.simple.SimpleMatrix import space.kscience.kmath.linear.* import space.kscience.kmath.misc.UnstableKMathAPI import space.kscience.kmath.nd.getFeature -import space.kscience.kmath.operations.RealField -import space.kscience.kmath.structures.RealBuffer +import space.kscience.kmath.operations.DoubleField +import space.kscience.kmath.structures.DoubleBuffer import kotlin.reflect.KClass import kotlin.reflect.cast @@ -15,9 +15,9 @@ import kotlin.reflect.cast * * @author Iaroslav Postovalov */ -public object EjmlLinearSpace : LinearSpace { +public object EjmlLinearSpace : LinearSpace { - override val elementAlgebra: RealField get() = RealField + override val elementAlgebra: DoubleField get() = DoubleField /** * Converts this matrix to EJML one. @@ -38,16 +38,16 @@ public object EjmlLinearSpace : LinearSpace { }) } - override fun buildMatrix(rows: Int, columns: Int, initializer: RealField.(i: Int, j: Int) -> Double): EjmlMatrix = + override fun buildMatrix(rows: Int, columns: Int, initializer: DoubleField.(i: Int, j: Int) -> Double): EjmlMatrix = EjmlMatrix(SimpleMatrix(rows, columns).also { (0 until rows).forEach { row -> - (0 until columns).forEach { col -> it[row, col] = RealField.initializer(row, col) } + (0 until columns).forEach { col -> it[row, col] = DoubleField.initializer(row, col) } } }) - override fun buildVector(size: Int, initializer: RealField.(Int) -> Double): Point = + override fun buildVector(size: Int, initializer: DoubleField.(Int) -> Double): Point = EjmlVector(SimpleMatrix(size, 1).also { - (0 until it.numRows()).forEach { row -> it[row, 0] = RealField.initializer(row) } + (0 until it.numRows()).forEach { row -> it[row, 0] = DoubleField.initializer(row) } }) private fun SimpleMatrix.wrapMatrix() = EjmlMatrix(this) @@ -113,7 +113,7 @@ public object EjmlLinearSpace : LinearSpace { override val u: Matrix by lazy { EjmlMatrix(SimpleMatrix(svd.getU(null, false))) } override val s: Matrix by lazy { EjmlMatrix(SimpleMatrix(svd.getW(null))) } override val v: Matrix by lazy { EjmlMatrix(SimpleMatrix(svd.getV(null, false))) } - override val singularValues: Point by lazy { RealBuffer(svd.singularValues) } + override val singularValues: Point by lazy { DoubleBuffer(svd.singularValues) } } QRDecompositionFeature::class -> object : QRDecompositionFeature { diff --git a/kmath-for-real/build.gradle.kts b/kmath-for-real/build.gradle.kts index d095cac04..5fc6724f3 100644 --- a/kmath-for-real/build.gradle.kts +++ b/kmath-for-real/build.gradle.kts @@ -18,15 +18,15 @@ readme { propertyByTemplate("artifact", rootProject.file("docs/templates/ARTIFACT-TEMPLATE.md")) feature( - id = "RealVector", + id = "DoubleVector", description = "Numpy-like operations for Buffers/Points", - ref = "src/commonMain/kotlin/kscience/kmath/real/RealVector.kt" + ref = "src/commonMain/kotlin/kscience/kmath/real/DoubleVector.kt" ) feature( - id = "RealMatrix", + id = "DoubleMatrix", description = "Numpy-like operations for 2d real structures", - ref = "src/commonMain/kotlin/kscience/kmath/real/RealMatrix.kt" + ref = "src/commonMain/kotlin/kscience/kmath/real/DoubleMatrix.kt" ) feature( diff --git a/kmath-for-real/src/commonMain/kotlin/space/kscience/kmath/real/RealMatrix.kt b/kmath-for-real/src/commonMain/kotlin/space/kscience/kmath/real/RealMatrix.kt index 76c73ab16..a16d64234 100644 --- a/kmath-for-real/src/commonMain/kotlin/space/kscience/kmath/real/RealMatrix.kt +++ b/kmath-for-real/src/commonMain/kotlin/space/kscience/kmath/real/RealMatrix.kt @@ -2,9 +2,9 @@ package space.kscience.kmath.real import space.kscience.kmath.linear.* import space.kscience.kmath.misc.UnstableKMathAPI -import space.kscience.kmath.operations.RealField +import space.kscience.kmath.operations.DoubleField import space.kscience.kmath.structures.Buffer -import space.kscience.kmath.structures.RealBuffer +import space.kscience.kmath.structures.DoubleBuffer import space.kscience.kmath.structures.asIterable import kotlin.math.pow @@ -22,11 +22,11 @@ import kotlin.math.pow public typealias RealMatrix = Matrix -public fun realMatrix(rowNum: Int, colNum: Int, initializer: RealField.(i: Int, j: Int) -> Double): RealMatrix = +public fun realMatrix(rowNum: Int, colNum: Int, initializer: DoubleField.(i: Int, j: Int) -> Double): RealMatrix = LinearSpace.real.buildMatrix(rowNum, colNum, initializer) @OptIn(UnstableKMathAPI::class) -public fun realMatrix(rowNum: Int, colNum: Int): MatrixBuilder = +public fun realMatrix(rowNum: Int, colNum: Int): MatrixBuilder = LinearSpace.real.matrix(rowNum, colNum) public fun Array.toMatrix(): RealMatrix { @@ -120,19 +120,19 @@ public fun RealMatrix.extractColumns(columnRange: IntRange): RealMatrix = public fun RealMatrix.extractColumn(columnIndex: Int): RealMatrix = extractColumns(columnIndex..columnIndex) -public fun RealMatrix.sumByColumn(): RealBuffer = RealBuffer(colNum) { j -> +public fun RealMatrix.sumByColumn(): DoubleBuffer = DoubleBuffer(colNum) { j -> columns[j].asIterable().sum() } -public fun RealMatrix.minByColumn(): RealBuffer = RealBuffer(colNum) { j -> +public fun RealMatrix.minByColumn(): DoubleBuffer = DoubleBuffer(colNum) { j -> columns[j].asIterable().minOrNull() ?: error("Cannot produce min on empty column") } -public fun RealMatrix.maxByColumn(): RealBuffer = RealBuffer(colNum) { j -> +public fun RealMatrix.maxByColumn(): DoubleBuffer = DoubleBuffer(colNum) { j -> columns[j].asIterable().maxOrNull() ?: error("Cannot produce min on empty column") } -public fun RealMatrix.averageByColumn(): RealBuffer = RealBuffer(colNum) { j -> +public fun RealMatrix.averageByColumn(): DoubleBuffer = DoubleBuffer(colNum) { j -> columns[j].asIterable().average() } diff --git a/kmath-for-real/src/commonMain/kotlin/space/kscience/kmath/real/RealVector.kt b/kmath-for-real/src/commonMain/kotlin/space/kscience/kmath/real/RealVector.kt index 8cc128947..433e3c756 100644 --- a/kmath-for-real/src/commonMain/kotlin/space/kscience/kmath/real/RealVector.kt +++ b/kmath-for-real/src/commonMain/kotlin/space/kscience/kmath/real/RealVector.kt @@ -4,98 +4,99 @@ import space.kscience.kmath.linear.Point import space.kscience.kmath.misc.UnstableKMathAPI import space.kscience.kmath.operations.Norm import space.kscience.kmath.structures.Buffer -import space.kscience.kmath.structures.MutableBuffer.Companion.real +import space.kscience.kmath.structures.MutableBuffer.Companion.double import space.kscience.kmath.structures.asBuffer import space.kscience.kmath.structures.asIterable import space.kscience.kmath.structures.indices import kotlin.math.pow import kotlin.math.sqrt -public typealias RealVector = Point +public typealias DoubleVector = Point public object VectorL2Norm : Norm, Double> { override fun norm(arg: Point): Double = sqrt(arg.asIterable().sumByDouble(Number::toDouble)) } -public operator fun Buffer.Companion.invoke(vararg doubles: Double): RealVector = doubles.asBuffer() +@Suppress("FunctionName") +public fun DoubleVector(vararg doubles: Double): DoubleVector = doubles.asBuffer() /** * Fill the vector of given [size] with given [value] */ @UnstableKMathAPI -public fun Buffer.Companion.same(size: Int, value: Number): RealVector = real(size) { value.toDouble() } +public fun Buffer.Companion.same(size: Int, value: Number): DoubleVector = double(size) { value.toDouble() } // Transformation methods -public inline fun RealVector.map(transform: (Double) -> Double): RealVector = - real(size) { transform(get(it)) } +public inline fun DoubleVector.map(transform: (Double) -> Double): DoubleVector = + double(size) { transform(get(it)) } -public inline fun RealVector.mapIndexed(transform: (index: Int, value: Double) -> Double): RealVector = - real(size) { transform(it, get(it)) } +public inline fun DoubleVector.mapIndexed(transform: (index: Int, value: Double) -> Double): DoubleVector = + double(size) { transform(it, get(it)) } -public operator fun RealVector.plus(other: RealVector): RealVector { +public operator fun DoubleVector.plus(other: DoubleVector): DoubleVector { require(size == other.size) { "Vector size $size expected but ${other.size} found" } return mapIndexed { index, value -> value + other[index] } } -public operator fun RealVector.plus(number: Number): RealVector = map { it + number.toDouble() } +public operator fun DoubleVector.plus(number: Number): DoubleVector = map { it + number.toDouble() } -public operator fun Number.plus(vector: RealVector): RealVector = vector + this +public operator fun Number.plus(vector: DoubleVector): DoubleVector = vector + this -public operator fun RealVector.unaryMinus(): Buffer = map { -it } +public operator fun DoubleVector.unaryMinus(): Buffer = map { -it } -public operator fun RealVector.minus(other: RealVector): RealVector { +public operator fun DoubleVector.minus(other: DoubleVector): DoubleVector { require(size == other.size) { "Vector size $size expected but ${other.size} found" } return mapIndexed { index, value -> value - other[index] } } -public operator fun RealVector.minus(number: Number): RealVector = map { it - number.toDouble() } +public operator fun DoubleVector.minus(number: Number): DoubleVector = map { it - number.toDouble() } -public operator fun Number.minus(vector: RealVector): RealVector = vector.map { toDouble() - it } +public operator fun Number.minus(vector: DoubleVector): DoubleVector = vector.map { toDouble() - it } -public operator fun RealVector.times(other: RealVector): RealVector { +public operator fun DoubleVector.times(other: DoubleVector): DoubleVector { require(size == other.size) { "Vector size $size expected but ${other.size} found" } return mapIndexed { index, value -> value * other[index] } } -public operator fun RealVector.times(number: Number): RealVector = map { it * number.toDouble() } +public operator fun DoubleVector.times(number: Number): DoubleVector = map { it * number.toDouble() } -public operator fun Number.times(vector: RealVector): RealVector = vector * this +public operator fun Number.times(vector: DoubleVector): DoubleVector = vector * this -public operator fun RealVector.div(other: RealVector): RealVector { +public operator fun DoubleVector.div(other: DoubleVector): DoubleVector { require(size == other.size) { "Vector size $size expected but ${other.size} found" } return mapIndexed { index, value -> value / other[index] } } -public operator fun RealVector.div(number: Number): RealVector = map { it / number.toDouble() } +public operator fun DoubleVector.div(number: Number): DoubleVector = map { it / number.toDouble() } -public operator fun Number.div(vector: RealVector): RealVector = vector.map { toDouble() / it } +public operator fun Number.div(vector: DoubleVector): DoubleVector = vector.map { toDouble() / it } //extended operations -public fun RealVector.pow(p: Double): RealVector = map { it.pow(p) } +public fun DoubleVector.pow(p: Double): DoubleVector = map { it.pow(p) } -public fun RealVector.pow(p: Int): RealVector = map { it.pow(p) } +public fun DoubleVector.pow(p: Int): DoubleVector = map { it.pow(p) } -public fun exp(vector: RealVector): RealVector = vector.map { kotlin.math.exp(it) } +public fun exp(vector: DoubleVector): DoubleVector = vector.map { kotlin.math.exp(it) } -public fun sqrt(vector: RealVector): RealVector = vector.map { kotlin.math.sqrt(it) } +public fun sqrt(vector: DoubleVector): DoubleVector = vector.map { kotlin.math.sqrt(it) } -public fun RealVector.square(): RealVector = map { it.pow(2) } +public fun DoubleVector.square(): DoubleVector = map { it.pow(2) } -public fun sin(vector: RealVector): RealVector = vector.map { kotlin.math.sin(it) } +public fun sin(vector: DoubleVector): DoubleVector = vector.map { kotlin.math.sin(it) } -public fun cos(vector: RealVector): RealVector = vector.map { kotlin.math.cos(it) } +public fun cos(vector: DoubleVector): DoubleVector = vector.map { kotlin.math.cos(it) } -public fun tan(vector: RealVector): RealVector = vector.map { kotlin.math.tan(it) } +public fun tan(vector: DoubleVector): DoubleVector = vector.map { kotlin.math.tan(it) } -public fun ln(vector: RealVector): RealVector = vector.map { kotlin.math.ln(it) } +public fun ln(vector: DoubleVector): DoubleVector = vector.map { kotlin.math.ln(it) } -public fun log10(vector: RealVector): RealVector = vector.map { kotlin.math.log10(it) } +public fun log10(vector: DoubleVector): DoubleVector = vector.map { kotlin.math.log10(it) } // reductions methods -public fun RealVector.sum(): Double { +public fun DoubleVector.sum(): Double { var res = 0.0 for (i in indices) { res += get(i) diff --git a/kmath-for-real/src/commonMain/kotlin/space/kscience/kmath/real/grids.kt b/kmath-for-real/src/commonMain/kotlin/space/kscience/kmath/real/grids.kt index 8b4f1cd96..35297a3ac 100644 --- a/kmath-for-real/src/commonMain/kotlin/space/kscience/kmath/real/grids.kt +++ b/kmath-for-real/src/commonMain/kotlin/space/kscience/kmath/real/grids.kt @@ -33,7 +33,7 @@ public fun ClosedFloatingPointRange.toSequenceWithStep(step: Double): Se } } -public infix fun ClosedFloatingPointRange.step(step: Double): RealVector = +public infix fun ClosedFloatingPointRange.step(step: Double): DoubleVector = toSequenceWithStep(step).toList().asBuffer() /** diff --git a/kmath-for-real/src/commonMain/kotlin/space/kscience/kmath/real/realND.kt b/kmath-for-real/src/commonMain/kotlin/space/kscience/kmath/real/realND.kt index 492e40922..7655a4170 100644 --- a/kmath-for-real/src/commonMain/kotlin/space/kscience/kmath/real/realND.kt +++ b/kmath-for-real/src/commonMain/kotlin/space/kscience/kmath/real/realND.kt @@ -1,15 +1,15 @@ package space.kscience.kmath.real import space.kscience.kmath.nd.NDBuffer -import space.kscience.kmath.operations.RealField -import space.kscience.kmath.structures.RealBuffer +import space.kscience.kmath.operations.DoubleField +import space.kscience.kmath.structures.DoubleBuffer /** * Map one [NDBuffer] using function without indices. */ -public inline fun NDBuffer.mapInline(crossinline transform: RealField.(Double) -> Double): NDBuffer { - val array = DoubleArray(strides.linearSize) { offset -> RealField.transform(buffer[offset]) } - return NDBuffer(strides, RealBuffer(array)) +public inline fun NDBuffer.mapInline(crossinline transform: DoubleField.(Double) -> Double): NDBuffer { + val array = DoubleArray(strides.linearSize) { offset -> DoubleField.transform(buffer[offset]) } + return NDBuffer(strides, DoubleBuffer(array)) } /** diff --git a/kmath-for-real/src/commonTest/kotlin/kaceince/kmath/real/RealMatrixTest.kt b/kmath-for-real/src/commonTest/kotlin/kaceince/kmath/real/DoubleMatrixTest.kt similarity index 99% rename from kmath-for-real/src/commonTest/kotlin/kaceince/kmath/real/RealMatrixTest.kt rename to kmath-for-real/src/commonTest/kotlin/kaceince/kmath/real/DoubleMatrixTest.kt index 06135598e..c1d3ccf5f 100644 --- a/kmath-for-real/src/commonTest/kotlin/kaceince/kmath/real/RealMatrixTest.kt +++ b/kmath-for-real/src/commonTest/kotlin/kaceince/kmath/real/DoubleMatrixTest.kt @@ -10,7 +10,7 @@ import kotlin.test.assertEquals import kotlin.test.assertTrue @UnstableKMathAPI -internal class RealMatrixTest { +internal class DoubleMatrixTest { @Test fun testSum() { val m = realMatrix(10, 10) { i, j -> (i + j).toDouble() } diff --git a/kmath-for-real/src/commonTest/kotlin/kaceince/kmath/real/RealVectorTest.kt b/kmath-for-real/src/commonTest/kotlin/kaceince/kmath/real/DoubleVectorTest.kt similarity index 67% rename from kmath-for-real/src/commonTest/kotlin/kaceince/kmath/real/RealVectorTest.kt rename to kmath-for-real/src/commonTest/kotlin/kaceince/kmath/real/DoubleVectorTest.kt index 60d85fda3..669f88186 100644 --- a/kmath-for-real/src/commonTest/kotlin/kaceince/kmath/real/RealVectorTest.kt +++ b/kmath-for-real/src/commonTest/kotlin/kaceince/kmath/real/DoubleVectorTest.kt @@ -4,30 +4,30 @@ import space.kscience.kmath.linear.LinearSpace import space.kscience.kmath.linear.asMatrix import space.kscience.kmath.linear.transpose import space.kscience.kmath.real.plus -import space.kscience.kmath.structures.RealBuffer +import space.kscience.kmath.structures.DoubleBuffer import kotlin.test.Test import kotlin.test.assertEquals -internal class RealVectorTest { +internal class DoubleVectorTest { @Test fun testSum() { - val vector1 = RealBuffer(5) { it.toDouble() } - val vector2 = RealBuffer(5) { 5 - it.toDouble() } + val vector1 = DoubleBuffer(5) { it.toDouble() } + val vector2 = DoubleBuffer(5) { 5 - it.toDouble() } val sum = vector1 + vector2 assertEquals(5.0, sum[2]) } @Test fun testVectorToMatrix() { - val vector = RealBuffer(5) { it.toDouble() } + val vector = DoubleBuffer(5) { it.toDouble() } val matrix = vector.asMatrix() assertEquals(4.0, matrix[4, 0]) } @Test fun testDot() { - val vector1 = RealBuffer(5) { it.toDouble() } - val vector2 = RealBuffer(5) { 5 - it.toDouble() } + val vector1 = DoubleBuffer(5) { it.toDouble() } + val vector2 = DoubleBuffer(5) { 5 - it.toDouble() } val matrix1 = vector1.asMatrix() val matrix2 = vector2.asMatrix().transpose() val product = LinearSpace.real.run { matrix1 dot matrix2 } diff --git a/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/interpolation/LinearInterpolatorTest.kt b/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/interpolation/LinearInterpolatorTest.kt index 0b7b62147..476c035e9 100644 --- a/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/interpolation/LinearInterpolatorTest.kt +++ b/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/interpolation/LinearInterpolatorTest.kt @@ -2,7 +2,7 @@ package space.kscience.kmath.interpolation import space.kscience.kmath.functions.PiecewisePolynomial import space.kscience.kmath.functions.asFunction -import space.kscience.kmath.operations.RealField +import space.kscience.kmath.operations.DoubleField import kotlin.test.Test import kotlin.test.assertEquals @@ -16,8 +16,8 @@ internal class LinearInterpolatorTest { 3.0 to 4.0 ) - val polynomial: PiecewisePolynomial = LinearInterpolator(RealField).interpolatePolynomials(data) - val function = polynomial.asFunction(RealField) + val polynomial: PiecewisePolynomial = LinearInterpolator(DoubleField).interpolatePolynomials(data) + val function = polynomial.asFunction(DoubleField) assertEquals(null, function(-1.0)) assertEquals(0.5, function(0.5)) assertEquals(2.0, function(1.5)) diff --git a/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/Counter.kt b/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/Counter.kt index ca0eba52f..616a72fde 100644 --- a/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/Counter.kt +++ b/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/Counter.kt @@ -2,8 +2,8 @@ package space.kscience.kmath.histogram import kotlinx.atomicfu.atomic import kotlinx.atomicfu.getAndUpdate +import space.kscience.kmath.operations.DoubleField import space.kscience.kmath.operations.Group -import space.kscience.kmath.operations.RealField /** * Common representation for atomic counters @@ -13,7 +13,7 @@ public interface Counter { public val value: T public companion object { - public fun real(): ObjectCounter = ObjectCounter(RealField) + public fun real(): ObjectCounter = ObjectCounter(DoubleField) } } diff --git a/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/RealHistogramSpace.kt b/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/DoubleHistogramSpace.kt similarity index 92% rename from kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/RealHistogramSpace.kt rename to kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/DoubleHistogramSpace.kt index 1407470c1..fa9b67404 100644 --- a/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/RealHistogramSpace.kt +++ b/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/DoubleHistogramSpace.kt @@ -7,7 +7,7 @@ import space.kscience.kmath.nd.* import space.kscience.kmath.structures.* import kotlin.math.floor -public class RealHistogramSpace( +public class DoubleHistogramSpace( private val lower: Buffer, private val upper: Buffer, private val binNums: IntArray = IntArray(lower.size) { 20 }, @@ -23,10 +23,10 @@ public class RealHistogramSpace( public val dimension: Int get() = lower.size private val shape = IntArray(binNums.size) { binNums[it] + 2 } - override val histogramValueSpace: RealFieldND = AlgebraND.real(*shape) + override val histogramValueSpace: DoubleFieldND = AlgebraND.real(*shape) override val strides: Strides get() = histogramValueSpace.strides - private val binSize = RealBuffer(dimension) { (upper[it] - lower[it]) / binNums[it] } + private val binSize = DoubleBuffer(dimension) { (upper[it] - lower[it]) / binNums[it] } /** * Get internal [StructureND] bin index for given axis @@ -91,7 +91,7 @@ public class RealHistogramSpace( *) *``` */ - public fun fromRanges(vararg ranges: ClosedFloatingPointRange): RealHistogramSpace = RealHistogramSpace( + public fun fromRanges(vararg ranges: ClosedFloatingPointRange): DoubleHistogramSpace = DoubleHistogramSpace( ranges.map(ClosedFloatingPointRange::start).asBuffer(), ranges.map(ClosedFloatingPointRange::endInclusive).asBuffer() ) @@ -105,8 +105,8 @@ public class RealHistogramSpace( *) *``` */ - public fun fromRanges(vararg ranges: Pair, Int>): RealHistogramSpace = - RealHistogramSpace( + public fun fromRanges(vararg ranges: Pair, Int>): DoubleHistogramSpace = + DoubleHistogramSpace( ListBuffer( ranges .map(Pair, Int>::first) diff --git a/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/Histogram.kt b/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/Histogram.kt index ed76c7aa1..d680a9ad0 100644 --- a/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/Histogram.kt +++ b/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/Histogram.kt @@ -2,7 +2,7 @@ package space.kscience.kmath.histogram import space.kscience.kmath.domains.Domain import space.kscience.kmath.linear.Point -import space.kscience.kmath.structures.RealBuffer +import space.kscience.kmath.structures.DoubleBuffer import space.kscience.kmath.structures.asBuffer /** @@ -43,9 +43,9 @@ public fun > HistogramBuilder.put(point: Point): U public fun HistogramBuilder.put(vararg point: T): Unit = put(point.asBuffer()) public fun HistogramBuilder.put(vararg point: Number): Unit = - put(RealBuffer(point.map { it.toDouble() }.toDoubleArray())) + put(DoubleBuffer(point.map { it.toDouble() }.toDoubleArray())) -public fun HistogramBuilder.put(vararg point: Double): Unit = put(RealBuffer(point)) +public fun HistogramBuilder.put(vararg point: Double): Unit = put(DoubleBuffer(point)) public fun HistogramBuilder.fill(sequence: Iterable>): Unit = sequence.forEach { put(it) } /** diff --git a/kmath-histograms/src/commonTest/kotlin/space/kscience/kmath/histogram/MultivariateHistogramTest.kt b/kmath-histograms/src/commonTest/kotlin/space/kscience/kmath/histogram/MultivariateHistogramTest.kt index fc00c6cdf..feb87a7a7 100644 --- a/kmath-histograms/src/commonTest/kotlin/space/kscience/kmath/histogram/MultivariateHistogramTest.kt +++ b/kmath-histograms/src/commonTest/kotlin/space/kscience/kmath/histogram/MultivariateHistogramTest.kt @@ -1,15 +1,14 @@ package space.kscience.kmath.histogram import space.kscience.kmath.operations.invoke -import space.kscience.kmath.real.RealVector -import space.kscience.kmath.real.invoke +import space.kscience.kmath.real.DoubleVector import kotlin.random.Random import kotlin.test.* internal class MultivariateHistogramTest { @Test fun testSinglePutHistogram() { - val hSpace = RealHistogramSpace.fromRanges( + val hSpace = DoubleHistogramSpace.fromRanges( (-1.0..1.0), (-1.0..1.0) ) @@ -17,14 +16,14 @@ internal class MultivariateHistogramTest { put(0.55, 0.55) } val bin = histogram.bins.find { it.value.toInt() > 0 } ?: fail() - assertTrue { bin.contains(RealVector(0.55, 0.55)) } - assertTrue { bin.contains(RealVector(0.6, 0.5)) } - assertFalse { bin.contains(RealVector(-0.55, 0.55)) } + assertTrue { bin.contains(DoubleVector(0.55, 0.55)) } + assertTrue { bin.contains(DoubleVector(0.6, 0.5)) } + assertFalse { bin.contains(DoubleVector(-0.55, 0.55)) } } @Test fun testSequentialPut() { - val hSpace = RealHistogramSpace.fromRanges( + val hSpace = DoubleHistogramSpace.fromRanges( (-1.0..1.0), (-1.0..1.0), (-1.0..1.0) @@ -44,7 +43,7 @@ internal class MultivariateHistogramTest { @Test fun testHistogramAlgebra() { - RealHistogramSpace.fromRanges( + DoubleHistogramSpace.fromRanges( (-1.0..1.0), (-1.0..1.0), (-1.0..1.0) diff --git a/kmath-kotlingrad/src/test/kotlin/space/kscience/kmath/kotlingrad/AdaptingTests.kt b/kmath-kotlingrad/src/test/kotlin/space/kscience/kmath/kotlingrad/AdaptingTests.kt index ffdabaffb..7cd3276b8 100644 --- a/kmath-kotlingrad/src/test/kotlin/space/kscience/kmath/kotlingrad/AdaptingTests.kt +++ b/kmath-kotlingrad/src/test/kotlin/space/kscience/kmath/kotlingrad/AdaptingTests.kt @@ -6,7 +6,7 @@ import space.kscience.kmath.ast.MstAlgebra import space.kscience.kmath.ast.MstExpression import space.kscience.kmath.ast.parseMath import space.kscience.kmath.expressions.invoke -import space.kscience.kmath.operations.RealField +import space.kscience.kmath.operations.DoubleField import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertTrue @@ -16,8 +16,8 @@ internal class AdaptingTests { @Test fun symbol() { val c1 = MstAlgebra.bindSymbol("x") - assertTrue(c1.toSVar>().name == "x") - val c2 = "kitten".parseMath().toSFun>() + assertTrue(c1.toSVar>().name == "x") + val c2 = "kitten".parseMath().toSFun>() if (c2 is SVar) assertTrue(c2.name == "kitten") else fail() } @@ -25,15 +25,15 @@ internal class AdaptingTests { fun number() { val c1 = MstAlgebra.number(12354324) assertTrue(c1.toSConst().doubleValue == 12354324.0) - val c2 = "0.234".parseMath().toSFun>() + val c2 = "0.234".parseMath().toSFun>() if (c2 is SConst) assertTrue(c2.doubleValue == 0.234) else fail() - val c3 = "1e-3".parseMath().toSFun>() + val c3 = "1e-3".parseMath().toSFun>() if (c3 is SConst) assertEquals(0.001, c3.value) else fail() } @Test fun simpleFunctionShape() { - val linear = "2*x+16".parseMath().toSFun>() + val linear = "2*x+16".parseMath().toSFun>() if (linear !is Sum) fail() if (linear.left !is Prod) fail() if (linear.right !is SConst) fail() @@ -41,21 +41,21 @@ internal class AdaptingTests { @Test fun simpleFunctionDerivative() { - val x = MstAlgebra.bindSymbol("x").toSVar>() - val quadratic = "x^2-4*x-44".parseMath().toSFun>() - val actualDerivative = MstExpression(RealField, quadratic.d(x).toMst()).compile() - val expectedDerivative = MstExpression(RealField, "2*x-4".parseMath()).compile() + val x = MstAlgebra.bindSymbol("x").toSVar>() + val quadratic = "x^2-4*x-44".parseMath().toSFun>() + val actualDerivative = MstExpression(DoubleField, quadratic.d(x).toMst()).compile() + val expectedDerivative = MstExpression(DoubleField, "2*x-4".parseMath()).compile() assertEquals(actualDerivative("x" to 123.0), expectedDerivative("x" to 123.0)) } @Test fun moreComplexDerivative() { - val x = MstAlgebra.bindSymbol("x").toSVar>() - val composition = "-sqrt(sin(x^2)-cos(x)^2-16*x)".parseMath().toSFun>() - val actualDerivative = MstExpression(RealField, composition.d(x).toMst()).compile() + val x = MstAlgebra.bindSymbol("x").toSVar>() + val composition = "-sqrt(sin(x^2)-cos(x)^2-16*x)".parseMath().toSFun>() + val actualDerivative = MstExpression(DoubleField, composition.d(x).toMst()).compile() val expectedDerivative = MstExpression( - RealField, + DoubleField, "-(2*x*cos(x^2)+2*sin(x)*cos(x)-16)/(2*sqrt(sin(x^2)-16*x-cos(x)^2))".parseMath() ).compile() diff --git a/kmath-nd4j/docs/README-TEMPLATE.md b/kmath-nd4j/docs/README-TEMPLATE.md index 76ce8c9a7..9783e74be 100644 --- a/kmath-nd4j/docs/README-TEMPLATE.md +++ b/kmath-nd4j/docs/README-TEMPLATE.md @@ -15,7 +15,7 @@ import org.nd4j.linalg.factory.* import scientifik.kmath.nd4j.* import scientifik.kmath.structures.* -val array = Nd4j.ones(2, 2).asRealStructure() +val array = Nd4j.ones(2, 2).asDoubleStructure() println(array[0, 0]) // 1.0 array[intArrayOf(0, 0)] = 24.0 println(array[0, 0]) // 24.0 @@ -28,8 +28,8 @@ import org.nd4j.linalg.factory.* import scientifik.kmath.nd4j.* import scientifik.kmath.operations.* -val field = RealNd4jArrayField(intArrayOf(2, 2)) -val array = Nd4j.rand(2, 2).asRealStructure() +val field = DoubleNd4jArrayField(intArrayOf(2, 2)) +val array = Nd4j.rand(2, 2).asDoubleStructure() val res = field { (25.0 / array + 20) * 4 diff --git a/kmath-nd4j/src/main/kotlin/space/kscience/kmath/nd4j/Nd4jArrayAlgebra.kt b/kmath-nd4j/src/main/kotlin/space/kscience/kmath/nd4j/Nd4jArrayAlgebra.kt index bf73ec20f..8ea992bcb 100644 --- a/kmath-nd4j/src/main/kotlin/space/kscience/kmath/nd4j/Nd4jArrayAlgebra.kt +++ b/kmath-nd4j/src/main/kotlin/space/kscience/kmath/nd4j/Nd4jArrayAlgebra.kt @@ -172,7 +172,7 @@ public interface Nd4jArrayField> : FieldND, Nd4jArrayRing< private val floatNd4jArrayFieldCache: ThreadLocal> = ThreadLocal.withInitial { hashMapOf() } - private val realNd4jArrayFieldCache: ThreadLocal> = + private val doubleNd4JArrayFieldCache: ThreadLocal> = ThreadLocal.withInitial { hashMapOf() } /** @@ -184,8 +184,8 @@ public interface Nd4jArrayField> : FieldND, Nd4jArrayRing< /** * Creates an [FieldND] for [Double] values or pull it from cache if it was created previously. */ - public fun real(vararg shape: Int): Nd4jArrayRing = - realNd4jArrayFieldCache.get().getOrPut(shape) { RealNd4jArrayField(shape) } + public fun real(vararg shape: Int): Nd4jArrayRing = + doubleNd4JArrayFieldCache.get().getOrPut(shape) { DoubleNd4jArrayField(shape) } /** * Creates a most suitable implementation of [RingND] using reified class. @@ -200,12 +200,12 @@ public interface Nd4jArrayField> : FieldND, Nd4jArrayRing< } /** - * Represents [FieldND] over [Nd4jArrayRealStructure]. + * Represents [FieldND] over [Nd4jArrayDoubleStructure]. */ -public class RealNd4jArrayField(public override val shape: IntArray) : Nd4jArrayField { - public override val elementContext: RealField get() = RealField +public class DoubleNd4jArrayField(public override val shape: IntArray) : Nd4jArrayField { + public override val elementContext: DoubleField get() = DoubleField - public override fun INDArray.wrap(): Nd4jArrayStructure = checkShape(this).asRealStructure() + public override fun INDArray.wrap(): Nd4jArrayStructure = checkShape(this).asDoubleStructure() override fun scale(a: StructureND, value: Double): Nd4jArrayStructure { return a.ndArray.mul(value).wrap() diff --git a/kmath-nd4j/src/main/kotlin/space/kscience/kmath/nd4j/Nd4jArrayIterator.kt b/kmath-nd4j/src/main/kotlin/space/kscience/kmath/nd4j/Nd4jArrayIterator.kt index 521c8cab3..cfb900277 100644 --- a/kmath-nd4j/src/main/kotlin/space/kscience/kmath/nd4j/Nd4jArrayIterator.kt +++ b/kmath-nd4j/src/main/kotlin/space/kscience/kmath/nd4j/Nd4jArrayIterator.kt @@ -37,11 +37,11 @@ private sealed class Nd4jArrayIteratorBase(protected val iterateOver: INDArra } } -private class Nd4jArrayRealIterator(iterateOver: INDArray) : Nd4jArrayIteratorBase(iterateOver) { +private class Nd4jArrayDoubleIterator(iterateOver: INDArray) : Nd4jArrayIteratorBase(iterateOver) { override fun getSingle(indices: LongArray): Double = iterateOver.getDouble(*indices) } -internal fun INDArray.realIterator(): Iterator> = Nd4jArrayRealIterator(this) +internal fun INDArray.realIterator(): Iterator> = Nd4jArrayDoubleIterator(this) private class Nd4jArrayLongIterator(iterateOver: INDArray) : Nd4jArrayIteratorBase(iterateOver) { override fun getSingle(indices: LongArray) = iterateOver.getLong(*indices) diff --git a/kmath-nd4j/src/main/kotlin/space/kscience/kmath/nd4j/Nd4jArrayStructure.kt b/kmath-nd4j/src/main/kotlin/space/kscience/kmath/nd4j/Nd4jArrayStructure.kt index 9b4cc1a24..ec4cc9c56 100644 --- a/kmath-nd4j/src/main/kotlin/space/kscience/kmath/nd4j/Nd4jArrayStructure.kt +++ b/kmath-nd4j/src/main/kotlin/space/kscience/kmath/nd4j/Nd4jArrayStructure.kt @@ -45,7 +45,7 @@ private data class Nd4jArrayLongStructure(override val ndArray: INDArray) : Nd4j */ public fun INDArray.asLongStructure(): Nd4jArrayStructure = Nd4jArrayLongStructure(this) -private data class Nd4jArrayRealStructure(override val ndArray: INDArray) : Nd4jArrayStructure() { +private data class Nd4jArrayDoubleStructure(override val ndArray: INDArray) : Nd4jArrayStructure() { override fun elementsIterator(): Iterator> = ndArray.realIterator() override fun get(index: IntArray): Double = ndArray.getDouble(*index) override fun set(index: IntArray, value: Double): Unit = run { ndArray.putScalar(index, value) } @@ -54,7 +54,7 @@ private data class Nd4jArrayRealStructure(override val ndArray: INDArray) : Nd4j /** * Wraps this [INDArray] to [Nd4jArrayStructure]. */ -public fun INDArray.asRealStructure(): Nd4jArrayStructure = Nd4jArrayRealStructure(this) +public fun INDArray.asDoubleStructure(): Nd4jArrayStructure = Nd4jArrayDoubleStructure(this) private data class Nd4jArrayFloatStructure(override val ndArray: INDArray) : Nd4jArrayStructure() { override fun elementsIterator(): Iterator> = ndArray.floatIterator() diff --git a/kmath-nd4j/src/test/kotlin/space/kscience/kmath/nd4j/Nd4jArrayAlgebraTest.kt b/kmath-nd4j/src/test/kotlin/space/kscience/kmath/nd4j/Nd4jArrayAlgebraTest.kt index 6a8d8796c..e658275f5 100644 --- a/kmath-nd4j/src/test/kotlin/space/kscience/kmath/nd4j/Nd4jArrayAlgebraTest.kt +++ b/kmath-nd4j/src/test/kotlin/space/kscience/kmath/nd4j/Nd4jArrayAlgebraTest.kt @@ -8,8 +8,8 @@ import kotlin.test.fail internal class Nd4jArrayAlgebraTest { @Test fun testProduce() { - val res = with(RealNd4jArrayField(intArrayOf(2, 2))) { produce { it.sum().toDouble() } } - val expected = (Nd4j.create(2, 2) ?: fail()).asRealStructure() + val res = with(DoubleNd4jArrayField(intArrayOf(2, 2))) { produce { it.sum().toDouble() } } + val expected = (Nd4j.create(2, 2) ?: fail()).asDoubleStructure() expected[intArrayOf(0, 0)] = 0.0 expected[intArrayOf(0, 1)] = 1.0 expected[intArrayOf(1, 0)] = 1.0 diff --git a/kmath-nd4j/src/test/kotlin/space/kscience/kmath/nd4j/Nd4jArrayStructureTest.kt b/kmath-nd4j/src/test/kotlin/space/kscience/kmath/nd4j/Nd4jArrayStructureTest.kt index 5cf6dd26f..0c03270dd 100644 --- a/kmath-nd4j/src/test/kotlin/space/kscience/kmath/nd4j/Nd4jArrayStructureTest.kt +++ b/kmath-nd4j/src/test/kotlin/space/kscience/kmath/nd4j/Nd4jArrayStructureTest.kt @@ -11,7 +11,7 @@ internal class Nd4jArrayStructureTest { @Test fun testElements() { val nd = Nd4j.create(doubleArrayOf(1.0, 2.0, 3.0))!! - val struct = nd.asRealStructure() + val struct = nd.asDoubleStructure() val res = struct.elements().map(Pair::second).toList() assertEquals(listOf(1.0, 2.0, 3.0), res) } @@ -19,22 +19,22 @@ internal class Nd4jArrayStructureTest { @Test fun testShape() { val nd = Nd4j.rand(10, 2, 3, 6) ?: fail() - val struct = nd.asRealStructure() + val struct = nd.asDoubleStructure() assertEquals(intArrayOf(10, 2, 3, 6).toList(), struct.shape.toList()) } @Test fun testEquals() { val nd1 = Nd4j.create(doubleArrayOf(1.0, 2.0, 3.0)) ?: fail() - val struct1 = nd1.asRealStructure() + val struct1 = nd1.asDoubleStructure() assertEquals(struct1, struct1) assertNotEquals(struct1 as Any?, null) val nd2 = Nd4j.create(doubleArrayOf(1.0, 2.0, 3.0)) ?: fail() - val struct2 = nd2.asRealStructure() + val struct2 = nd2.asDoubleStructure() assertEquals(struct1, struct2) assertEquals(struct2, struct1) val nd3 = Nd4j.create(doubleArrayOf(1.0, 2.0, 3.0)) ?: fail() - val struct3 = nd3.asRealStructure() + val struct3 = nd3.asDoubleStructure() assertEquals(struct2, struct3) assertEquals(struct1, struct3) } @@ -42,9 +42,9 @@ internal class Nd4jArrayStructureTest { @Test fun testHashCode() { val nd1 = Nd4j.create(doubleArrayOf(1.0, 2.0, 3.0)) ?: fail() - val struct1 = nd1.asRealStructure() + val struct1 = nd1.asDoubleStructure() val nd2 = Nd4j.create(doubleArrayOf(1.0, 2.0, 3.0)) ?: fail() - val struct2 = nd2.asRealStructure() + val struct2 = nd2.asDoubleStructure() assertEquals(struct1.hashCode(), struct2.hashCode()) } diff --git a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/Distribution.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/Distribution.kt index dacf7a9cd..25f6a87b5 100644 --- a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/Distribution.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/Distribution.kt @@ -4,7 +4,7 @@ import space.kscience.kmath.chains.Chain import space.kscience.kmath.chains.collect import space.kscience.kmath.structures.Buffer import space.kscience.kmath.structures.BufferFactory -import space.kscience.kmath.structures.RealBuffer +import space.kscience.kmath.structures.DoubleBuffer public interface Sampler { public fun sample(generator: RandomGenerator): Chain @@ -75,4 +75,4 @@ public fun Sampler.sampleBuffer( * Generate a bunch of samples from real distributions */ public fun Sampler.sampleBuffer(generator: RandomGenerator, size: Int): Chain> = - sampleBuffer(generator, size, ::RealBuffer) + sampleBuffer(generator, size, ::DoubleBuffer) diff --git a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/Statistic.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/Statistic.kt index a9f7cd3e4..8bf6b09ef 100644 --- a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/Statistic.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/Statistic.kt @@ -81,7 +81,7 @@ public class Mean( public companion object { //TODO replace with optimized version which respects overflow - public val real: Mean = Mean(RealField) { sum, count -> sum / count } + public val real: Mean = Mean(DoubleField) { sum, count -> sum / count } public val int: Mean = Mean(IntRing) { sum, count -> sum / count } public val long: Mean = Mean(LongRing) { sum, count -> sum / count } } diff --git a/kmath-stat/src/jvmMain/kotlin/space/kscience/kmath/stat/distributions.kt b/kmath-stat/src/jvmMain/kotlin/space/kscience/kmath/stat/distributions.kt index 1be436a4f..8b5551a16 100644 --- a/kmath-stat/src/jvmMain/kotlin/space/kscience/kmath/stat/distributions.kt +++ b/kmath-stat/src/jvmMain/kotlin/space/kscience/kmath/stat/distributions.kt @@ -2,8 +2,8 @@ package space.kscience.kmath.stat import org.apache.commons.rng.UniformRandomProvider import org.apache.commons.rng.sampling.distribution.* +import space.kscience.kmath.chains.BlockingDoubleChain import space.kscience.kmath.chains.BlockingIntChain -import space.kscience.kmath.chains.BlockingRealChain import space.kscience.kmath.chains.Chain import kotlin.math.PI import kotlin.math.exp @@ -11,7 +11,7 @@ import kotlin.math.pow import kotlin.math.sqrt public abstract class ContinuousSamplerDistribution : Distribution { - private inner class ContinuousSamplerChain(val generator: RandomGenerator) : BlockingRealChain() { + private inner class ContinuousSamplerChain(val generator: RandomGenerator) : BlockingDoubleChain() { private val sampler = buildCMSampler(generator) override fun nextDouble(): Double = sampler.sample() @@ -20,7 +20,7 @@ public abstract class ContinuousSamplerDistribution : Distribution { protected abstract fun buildCMSampler(generator: RandomGenerator): ContinuousSampler - public override fun sample(generator: RandomGenerator): BlockingRealChain = ContinuousSamplerChain(generator) + public override fun sample(generator: RandomGenerator): BlockingDoubleChain = ContinuousSamplerChain(generator) } public abstract class DiscreteSamplerDistribution : Distribution { diff --git a/kmath-viktor/api/kmath-viktor.api b/kmath-viktor/api/kmath-viktor.api index d48a9f9c8..6fe6c9db7 100644 --- a/kmath-viktor/api/kmath-viktor.api +++ b/kmath-viktor/api/kmath-viktor.api @@ -67,7 +67,7 @@ public final class space/kscience/kmath/viktor/ViktorFieldND : space/kscience/km public synthetic fun exp (Ljava/lang/Object;)Ljava/lang/Object; public fun exp-8UOKELU (Lspace/kscience/kmath/nd/StructureND;)Lorg/jetbrains/bio/viktor/F64Array; public synthetic fun getElementContext ()Lspace/kscience/kmath/operations/Algebra; - public fun getElementContext ()Lspace/kscience/kmath/operations/RealField; + public fun getElementContext ()Lspace/kscience/kmath/operations/DoubleField; public final fun getF64Buffer (Lspace/kscience/kmath/nd/StructureND;)Lorg/jetbrains/bio/viktor/F64Array; public synthetic fun getOne ()Ljava/lang/Object; public fun getOne-6kW2wQc ()Lorg/jetbrains/bio/viktor/F64Array; diff --git a/kmath-viktor/src/main/kotlin/space/kscience/kmath/viktor/ViktorStructureND.kt b/kmath-viktor/src/main/kotlin/space/kscience/kmath/viktor/ViktorStructureND.kt index 9195415c5..2749f5431 100644 --- a/kmath-viktor/src/main/kotlin/space/kscience/kmath/viktor/ViktorStructureND.kt +++ b/kmath-viktor/src/main/kotlin/space/kscience/kmath/viktor/ViktorStructureND.kt @@ -3,9 +3,9 @@ package space.kscience.kmath.viktor import org.jetbrains.bio.viktor.F64Array import space.kscience.kmath.misc.UnstableKMathAPI import space.kscience.kmath.nd.* +import space.kscience.kmath.operations.DoubleField import space.kscience.kmath.operations.ExtendedField import space.kscience.kmath.operations.NumbersAddOperations -import space.kscience.kmath.operations.RealField import space.kscience.kmath.operations.ScaleOperations @Suppress("OVERRIDE_BY_INLINE", "NOTHING_TO_INLINE") @@ -26,7 +26,7 @@ public fun F64Array.asStructure(): ViktorStructureND = ViktorStructureND(this) @OptIn(UnstableKMathAPI::class) @Suppress("OVERRIDE_BY_INLINE", "NOTHING_TO_INLINE") -public class ViktorFieldND(public override val shape: IntArray) : FieldND, +public class ViktorFieldND(public override val shape: IntArray) : FieldND, NumbersAddOperations>, ExtendedField>, ScaleOperations> { @@ -46,39 +46,39 @@ public class ViktorFieldND(public override val shape: IntArray) : FieldND Double): ViktorStructureND = + public override fun produce(initializer: DoubleField.(IntArray) -> Double): ViktorStructureND = F64Array(*shape).apply { this@ViktorFieldND.strides.indices().forEach { index -> - set(value = RealField.initializer(index), indices = index) + set(value = DoubleField.initializer(index), indices = index) } }.asStructure() override fun StructureND.unaryMinus(): StructureND = -1 * this - public override fun StructureND.map(transform: RealField.(Double) -> Double): ViktorStructureND = + public override fun StructureND.map(transform: DoubleField.(Double) -> Double): ViktorStructureND = F64Array(*this@ViktorFieldND.shape).apply { this@ViktorFieldND.strides.indices().forEach { index -> - set(value = RealField.transform(this@map[index]), indices = index) + set(value = DoubleField.transform(this@map[index]), indices = index) } }.asStructure() public override fun StructureND.mapIndexed( - transform: RealField.(index: IntArray, Double) -> Double, + transform: DoubleField.(index: IntArray, Double) -> Double, ): ViktorStructureND = F64Array(*this@ViktorFieldND.shape).apply { this@ViktorFieldND.strides.indices().forEach { index -> - set(value = RealField.transform(index, this@mapIndexed[index]), indices = index) + set(value = DoubleField.transform(index, this@mapIndexed[index]), indices = index) } }.asStructure() public override fun combine( a: StructureND, b: StructureND, - transform: RealField.(Double, Double) -> Double, + transform: DoubleField.(Double, Double) -> Double, ): ViktorStructureND = F64Array(*shape).apply { this@ViktorFieldND.strides.indices().forEach { index -> - set(value = RealField.transform(a[index], b[index]), indices = index) + set(value = DoubleField.transform(a[index], b[index]), indices = index) } }.asStructure()