From 875e32679bc53f7e27814b6d067594f38de53ba6 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Wed, 12 Apr 2023 11:39:28 +0300 Subject: [PATCH 01/40] [WIP] geometry refactor --- CHANGELOG.md | 1 + build.gradle.kts | 8 ++--- .../space/kscience/kmath/geometry/Circle2D.kt | 6 ++-- .../kmath/geometry/Euclidean2DSpace.kt | 7 +++-- .../kmath/geometry/Euclidean3DSpace.kt | 6 ++-- .../kscience/kmath/geometry/GeometrySpace.kt | 23 ++++++++------ .../space/kscience/kmath/geometry/Line.kt | 14 ++++----- .../kscience/kmath/geometry/projections.kt | 4 +-- .../{floatPrecision.kt => vectorPrecision.kt} | 31 ++++++------------- .../kscience/kmath/geometry/testUtils.kt | 6 ++-- .../kscience/kmath/geometry/lineExtensions.kt | 7 +++-- 11 files changed, 56 insertions(+), 57 deletions(-) rename kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/{floatPrecision.kt => vectorPrecision.kt} (51%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 998e6daae..073eaaba2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ - Algebra now has an obligatory `bufferFactory` (#477). ### Changed +- Removed marker `Vector` type for geometry - Geometry uses type-safe angles - Tensor operations switched to prefix notation - Row-wise and column-wise ND shapes in the core diff --git a/build.gradle.kts b/build.gradle.kts index ec67eaa54..e061d007c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -15,7 +15,7 @@ allprojects { } group = "space.kscience" - version = "0.3.1-dev-RC" + version = "0.3.2-dev-" } subprojects { @@ -66,10 +66,10 @@ ksciencePublish { } github("kmath", "SciProgCentre") space( - if (isInDevelopment) { - "https://maven.pkg.jetbrains.space/spc/p/sci/dev" - } else { + if (findProperty("production") == "true" || !isInDevelopment) { "https://maven.pkg.jetbrains.space/spc/p/sci/maven" + } else { + "https://maven.pkg.jetbrains.space/spc/p/sci/dev" } ) sonatype() diff --git a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Circle2D.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Circle2D.kt index d37ed45c0..1a4cb6734 100644 --- a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Circle2D.kt +++ b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Circle2D.kt @@ -6,8 +6,10 @@ package space.kscience.kmath.geometry import kotlinx.serialization.Serializable -import space.kscience.kmath.geometry.Euclidean2DSpace.distanceTo -import kotlin.math.* +import kotlin.math.PI + +interface Circle + /** * A circle in 2D space diff --git a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Euclidean2DSpace.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Euclidean2DSpace.kt index 3df8dba7b..012b5b73a 100644 --- a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Euclidean2DSpace.kt +++ b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Euclidean2DSpace.kt @@ -17,7 +17,7 @@ import space.kscience.kmath.operations.ScaleOperations import kotlin.math.pow import kotlin.math.sqrt -public interface Vector2D : Point, Vector { +public interface Vector2D : Point { public val x: T public val y: T override val size: Int get() = 2 @@ -47,7 +47,8 @@ public val Vector2D.r: Double get() = Euclidean2DSpace.norm(this) /** * 2D Euclidean space */ -public object Euclidean2DSpace : GeometrySpace, +public object Euclidean2DSpace : + GeometrySpace, ScaleOperations, Norm { @@ -87,4 +88,6 @@ public object Euclidean2DSpace : GeometrySpace, public val xAxis: DoubleVector2D = vector(1.0, 0.0) public val yAxis: DoubleVector2D = vector(0.0, 1.0) + + override val defaultPrecision: Double = 1e-6 } diff --git a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Euclidean3DSpace.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Euclidean3DSpace.kt index 3059cefe6..ce19d20a5 100644 --- a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Euclidean3DSpace.kt +++ b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Euclidean3DSpace.kt @@ -18,7 +18,7 @@ import space.kscience.kmath.structures.Buffer import kotlin.math.pow import kotlin.math.sqrt -public interface Vector3D : Point, Vector { +public interface Vector3D : Point { public val x: T public val y: T public val z: T @@ -55,7 +55,7 @@ public typealias Float64Vector3D = Vector3D public val DoubleVector3D.r: Double get() = Euclidean3DSpace.norm(this) -public object Euclidean3DSpace : GeometrySpace, ScaleOperations, +public object Euclidean3DSpace : GeometrySpace, ScaleOperations, Norm { @Serializable @@ -146,4 +146,6 @@ public object Euclidean3DSpace : GeometrySpace, ScaleOperations< public val xAxis: DoubleVector3D = vector(1.0, 0.0, 0.0) public val yAxis: DoubleVector3D = vector(0.0, 1.0, 0.0) public val zAxis: DoubleVector3D = vector(0.0, 0.0, 1.0) + + override val defaultPrecision: Double = 1e-6 } diff --git a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/GeometrySpace.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/GeometrySpace.kt index d6d7e5725..77c3b3a92 100644 --- a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/GeometrySpace.kt +++ b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/GeometrySpace.kt @@ -9,23 +9,26 @@ import space.kscience.kmath.operations.Group import space.kscience.kmath.operations.Norm import space.kscience.kmath.operations.ScaleOperations -public interface Vector - -public interface GeometrySpace : Group, ScaleOperations, Norm { +/** + * A geometry vector space + * @param V the type of vector object + * @param D the type of distance + */ +public interface GeometrySpace> : Group, ScaleOperations, Norm { /** * L2 distance */ - public fun V.distanceTo(other: V): Double + public fun V.distanceTo(other: V): D /** * Scalar product */ public infix fun V.dot(other: V): Double - public companion object{ - /** - * Default precision for geometry objects comparison - */ - internal const val DEFAULT_PRECISION = 1e-6 - } + /** + * Default precision for geometry objects comparison + */ + public val defaultPrecision: D + + public companion object } \ No newline at end of file diff --git a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Line.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Line.kt index a7f6ae35d..ed970b944 100644 --- a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Line.kt +++ b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Line.kt @@ -12,16 +12,16 @@ import kotlinx.serialization.Serializable * A line formed by [start] vector of start and a [direction] vector. Direction vector is not necessarily normalized, * but its length does not affect line properties */ -public interface Line { +public interface Line { public val start: V public val direction: V } @Serializable @SerialName("Line") -private data class LineImpl(override val start: V, override val direction: V): Line +private data class LineImpl(override val start: V, override val direction: V) : Line -public fun Line(base: V, direction: V): Line = LineImpl(base, direction) +public fun Line(base: V, direction: V): Line = LineImpl(base, direction) public typealias Line2D = Line public typealias Line3D = Line @@ -29,7 +29,7 @@ public typealias Line3D = Line /** * A directed line segment between [begin] and [end] */ -public interface LineSegment { +public interface LineSegment { public val begin: V public val end: V } @@ -39,11 +39,11 @@ public interface LineSegment { */ @Serializable @SerialName("LineSegment") -private data class LineSegmentImpl(override val begin: V, override val end: V) : LineSegment +private data class LineSegmentImpl(override val begin: V, override val end: V) : LineSegment -public fun LineSegment(begin: V, end: V): LineSegment = LineSegmentImpl(begin, end) +public fun LineSegment(begin: V, end: V): LineSegment = LineSegmentImpl(begin, end) -public fun LineSegment.line(algebra: GeometrySpace): Line = with(algebra) { +public fun LineSegment.line(algebra: GeometrySpace): Line = with(algebra) { Line(begin, end - begin) } diff --git a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/projections.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/projections.kt index c5c3487a1..a983e6837 100644 --- a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/projections.kt +++ b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/projections.kt @@ -12,7 +12,7 @@ package space.kscience.kmath.geometry * @param vector to project * @param line line to which vector should be projected */ -public fun GeometrySpace.projectToLine(vector: V, line: Line): V = with(line) { +public fun GeometrySpace.projectToLine(vector: V, line: Line): V = with(line) { start + (direction dot (vector - start)) / (direction dot direction) * direction } @@ -23,5 +23,5 @@ public fun GeometrySpace.projectToLine(vector: V, line: Line) * @param normal normal (perpendicular) vector to a hyper-plane to which vector should be projected * @param base point belonging to a hyper-plane to which vector should be projected */ -public fun GeometrySpace.projectAlong(vector: V, normal: V, base: V): V = +public fun GeometrySpace.projectAlong(vector: V, normal: V, base: V): V = vector + normal * ((base - vector) dot normal) / (normal dot normal) diff --git a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/floatPrecision.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/vectorPrecision.kt similarity index 51% rename from kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/floatPrecision.kt rename to kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/vectorPrecision.kt index ea46ab90f..0c6816186 100644 --- a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/floatPrecision.kt +++ b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/vectorPrecision.kt @@ -5,27 +5,14 @@ package space.kscience.kmath.geometry -import space.kscience.kmath.geometry.GeometrySpace.Companion.DEFAULT_PRECISION - -/** - * Float equality within given [precision] - */ -public fun Double.equalsFloat(other: Double, precision: Double = DEFAULT_PRECISION): Boolean = - kotlin.math.abs(this - other) < precision - -/** - * Float equality within given [precision] - */ -public fun Double.equalsFloat(other: Float, precision: Double = DEFAULT_PRECISION): Boolean = - kotlin.math.abs(this - other) < precision /** * Vector equality within given [precision] (using [GeometrySpace.norm] provided by the space */ -public fun V.equalsVector( - space: GeometrySpace, +public fun > V.equalsVector( + space: GeometrySpace, other: V, - precision: Double = DEFAULT_PRECISION, + precision: D = space.defaultPrecision, ): Boolean = with(space) { norm(this@equalsVector - other) < precision } @@ -35,22 +22,22 @@ public fun V.equalsVector( */ public fun Float64Vector2D.equalsVector( other: Float64Vector2D, - precision: Double = DEFAULT_PRECISION, + precision: Double = Euclidean3DSpace.defaultPrecision, ): Boolean = equalsVector(Euclidean2DSpace, other, precision) /** - * Vector equality using Euclidian L2 norm and given [precision] + * Vector equality using Euclidean L2 norm and given [precision] */ public fun Float64Vector3D.equalsVector( other: Float64Vector3D, - precision: Double = DEFAULT_PRECISION, + precision: Double = Euclidean3DSpace.defaultPrecision, ): Boolean = equalsVector(Euclidean3DSpace, other, precision) /** * Line equality using [GeometrySpace.norm] provided by the [space] and given [precision] */ -public fun LineSegment.equalsLine( - space: GeometrySpace, +public fun > LineSegment.equalsLine( + space: GeometrySpace, other: LineSegment, - precision: Double = DEFAULT_PRECISION, + precision: D = space.defaultPrecision, ): Boolean = begin.equalsVector(space, other.begin, precision) && end.equalsVector(space, other.end, precision) \ No newline at end of file diff --git a/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/testUtils.kt b/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/testUtils.kt index c62af3cd3..6796b291f 100644 --- a/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/testUtils.kt +++ b/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/testUtils.kt @@ -36,13 +36,13 @@ fun assertVectorEquals(expected: DoubleVector3D, actual: DoubleVector3D, absolut assertEquals(expected.z, actual.z, absoluteTolerance) } -fun GeometrySpace.isCollinear(a: V, b: V, absoluteTolerance: Double = 1e-6): Boolean { +fun > GeometrySpace.isCollinear(a: V, b: V, absoluteTolerance: D = defaultPrecision): Boolean { val aDist = a.distanceTo(zero) val bDist = b.distanceTo(zero) - return abs(aDist) < absoluteTolerance || abs(bDist) < absoluteTolerance || abs(abs((a dot b) / (aDist * bDist)) - 1) < absoluteTolerance + return aDist < absoluteTolerance || bDist < absoluteTolerance || abs(abs((a dot b) / (aDist * bDist)) - 1) < absoluteTolerance } -fun GeometrySpace.isOrthogonal(a: V, b: V, absoluteTolerance: Double = 1e-6): Boolean = +fun GeometrySpace.isOrthogonal(a: V, b: V, absoluteTolerance: Double = 1e-6): Boolean = abs(a dot b) < absoluteTolerance fun Double.equalFloat(other: Double, maxFloatDelta: Double = 0.000001): diff --git a/kmath-geometry/src/jvmMain/kotlin/space/kscience/kmath/geometry/lineExtensions.kt b/kmath-geometry/src/jvmMain/kotlin/space/kscience/kmath/geometry/lineExtensions.kt index 5fcd2b23e..cf204f080 100644 --- a/kmath-geometry/src/jvmMain/kotlin/space/kscience/kmath/geometry/lineExtensions.kt +++ b/kmath-geometry/src/jvmMain/kotlin/space/kscience/kmath/geometry/lineExtensions.kt @@ -6,15 +6,16 @@ import space.kscience.kmath.geometry.GeometrySpace import space.kscience.kmath.geometry.Line import space.kscience.kmath.geometry.LineSegment -import space.kscience.kmath.geometry.Vector import space.kscience.kmath.operations.Group /** * Get a line, containing this [LineSegment] */ -context(Group) public val LineSegment.line: Line get() = Line(begin, end - begin) +context(Group) +public val LineSegment.line: Line get() = Line(begin, end - begin) /** * Get a length of a line segment */ -context(GeometrySpace) public val LineSegment.length: Double get() = norm(end - begin) \ No newline at end of file +context(GeometrySpace) +public val LineSegment.length: Double get() = norm(end - begin) \ No newline at end of file From cdfddb75514a0a9f0f1118bce0b0f8c20438e026 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Fri, 21 Apr 2023 12:41:46 +0300 Subject: [PATCH 02/40] Explicit mutability for StructureND builders --- CHANGELOG.md | 1 + buildSrc/build.gradle.kts | 11 ++-- examples/build.gradle.kts | 2 +- .../kmath/operations/mixedNDOperations.kt | 7 +-- .../space/kscience/kmath/series/analyzeDif.kt | 5 +- .../kscience/kmath/series/seriesBuilder.kt | 50 +++++++++++++++++++ .../kmath/structures/StreamDoubleFieldND.kt | 9 ++++ .../kscience/kmath/structures/mutableNd.kt | 26 ++++++++++ gradle/wrapper/gradle-wrapper.properties | 2 +- kmath-core/build.gradle.kts | 4 +- .../space/kscience/kmath/nd/AlgebraND.kt | 10 +++- .../kscience/kmath/nd/BufferAlgebraND.kt | 13 ++++- .../space/kscience/kmath/nd/DoubleFieldND.kt | 4 +- .../space/kscience/kmath/nd/StructureND.kt | 1 + .../kscience/kmath/nd/algebraNDExtentions.kt | 6 +++ .../kmath/operations/BufferAlgebra.kt | 9 ++-- .../kmath/multik/MultikTensorAlgebra.kt | 6 +-- .../kscience/kmath/nd4j/Nd4jArrayAlgebra.kt | 2 +- .../kscience/kmath/nd4j/Nd4jTensorAlgebra.kt | 10 ++-- .../tensorflow/DoubleTensorFlowAlgebra.kt | 5 +- kmath-tensors/build.gradle.kts | 4 +- .../kmath/tensors/core/DoubleTensorAlgebra.kt | 2 +- .../kmath/tensors/core/IntTensorAlgebra.kt | 2 +- .../kmath/tensors/core/TestDoubleTensor.kt | 4 +- .../kscience/kmath/viktor/ViktorFieldOpsND.kt | 7 ++- 25 files changed, 159 insertions(+), 43 deletions(-) create mode 100644 examples/src/main/kotlin/space/kscience/kmath/series/seriesBuilder.kt create mode 100644 examples/src/main/kotlin/space/kscience/kmath/structures/mutableNd.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 073eaaba2..3ce57d5ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Unreleased ### Added +- Explicit `mutableStructureND` builders for mutable stucures ### Changed diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index afa36ed1e..734f60091 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -3,8 +3,6 @@ plugins { `version-catalog` } -java.targetCompatibility = JavaVersion.VERSION_11 - repositories { mavenLocal() maven("https://repo.kotlin.link") @@ -26,6 +24,11 @@ dependencies { implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.14.+") } -kotlin.sourceSets.all { - languageSettings.optIn("kotlin.OptIn") +kotlin{ + jvmToolchain{ + languageVersion.set(JavaLanguageVersion.of(11)) + } + sourceSets.all { + languageSettings.optIn("kotlin.OptIn") + } } diff --git a/examples/build.gradle.kts b/examples/build.gradle.kts index 50708eaa9..4047dfc5e 100644 --- a/examples/build.gradle.kts +++ b/examples/build.gradle.kts @@ -52,7 +52,7 @@ dependencies { implementation("org.slf4j:slf4j-simple:1.7.32") // plotting - implementation("space.kscience:plotlykt-server:0.5.0") + implementation("space.kscience:plotlykt-server:0.5.3-dev-1") } kotlin { diff --git a/examples/src/main/kotlin/space/kscience/kmath/operations/mixedNDOperations.kt b/examples/src/main/kotlin/space/kscience/kmath/operations/mixedNDOperations.kt index 4a5d783e1..6cbcd9943 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/operations/mixedNDOperations.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/operations/mixedNDOperations.kt @@ -8,14 +8,15 @@ package space.kscience.kmath.operations import space.kscience.kmath.commons.linear.CMLinearSpace import space.kscience.kmath.linear.matrix import space.kscience.kmath.nd.DoubleBufferND -import space.kscience.kmath.nd.ShapeND import space.kscience.kmath.nd.Structure2D +import space.kscience.kmath.nd.mutableStructureND import space.kscience.kmath.nd.ndAlgebra -import space.kscience.kmath.viktor.ViktorStructureND import space.kscience.kmath.viktor.viktorAlgebra +import kotlin.collections.component1 +import kotlin.collections.component2 fun main() { - val viktorStructure: ViktorStructureND = DoubleField.viktorAlgebra.structureND(ShapeND(2, 2)) { (i, j) -> + val viktorStructure = DoubleField.viktorAlgebra.mutableStructureND(2, 2) { (i, j) -> if (i == j) 2.0 else 0.0 } diff --git a/examples/src/main/kotlin/space/kscience/kmath/series/analyzeDif.kt b/examples/src/main/kotlin/space/kscience/kmath/series/analyzeDif.kt index 0e10f1a9a..e49adc82e 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/series/analyzeDif.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/series/analyzeDif.kt @@ -13,7 +13,10 @@ import space.kscience.kmath.structures.slice import space.kscience.plotly.* import kotlin.math.PI -fun main() = with(Double.algebra.bufferAlgebra.seriesAlgebra()) { +fun Double.Companion.seriesAlgebra() = Double.algebra.bufferAlgebra.seriesAlgebra() + + +fun main() = with(Double.seriesAlgebra()) { fun Plot.plotSeries(name: String, buffer: Buffer) { diff --git a/examples/src/main/kotlin/space/kscience/kmath/series/seriesBuilder.kt b/examples/src/main/kotlin/space/kscience/kmath/series/seriesBuilder.kt new file mode 100644 index 000000000..f8a8f1d0b --- /dev/null +++ b/examples/src/main/kotlin/space/kscience/kmath/series/seriesBuilder.kt @@ -0,0 +1,50 @@ +/* + * Copyright 2018-2023 KMath contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package space.kscience.kmath.series + + +import space.kscience.kmath.structures.Buffer +import space.kscience.kmath.structures.DoubleBuffer +import space.kscience.kmath.structures.asBuffer +import space.kscience.kmath.structures.toDoubleArray +import space.kscience.plotly.* +import space.kscience.plotly.models.Scatter +import space.kscience.plotly.models.ScatterMode +import kotlin.random.Random + +fun main(): Unit = with(Double.seriesAlgebra()) { + + val random = Random(1234) + + val arrayOfRandoms = DoubleArray(20) { random.nextDouble() } + + val series1: DoubleBuffer = arrayOfRandoms.asBuffer() + val series2: Series = series1.moveBy(3) + + val res = series2 - series1 + + println(res.size) + + println(res) + + fun Plot.series(name: String, buffer: Buffer, block: Scatter.() -> Unit = {}) { + scatter { + this.name = name + x.numbers = buffer.offsetIndices + y.doubles = buffer.toDoubleArray() + block() + } + } + + Plotly.plot { + series("series1", series1) + series("series2", series2) + series("dif", res){ + mode = ScatterMode.lines + line.color("magenta") + } + }.makeFile(resourceLocation = ResourceLocation.REMOTE) +} \ No newline at end of file diff --git a/examples/src/main/kotlin/space/kscience/kmath/structures/StreamDoubleFieldND.kt b/examples/src/main/kotlin/space/kscience/kmath/structures/StreamDoubleFieldND.kt index 2ce2c21a6..9877c41ad 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/structures/StreamDoubleFieldND.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/structures/StreamDoubleFieldND.kt @@ -52,6 +52,15 @@ class StreamDoubleFieldND(override val shape: ShapeND) : FieldND Double): MutableBufferND { + val array = IntStream.range(0, strides.linearSize).parallel().mapToDouble { offset -> + val index = strides.index(offset) + DoubleField.initializer(index) + }.toArray() + + return MutableBufferND(strides, array.asBuffer()) + } + @OptIn(PerformancePitfall::class) override fun StructureND.map( transform: DoubleField.(Double) -> Double, diff --git a/examples/src/main/kotlin/space/kscience/kmath/structures/mutableNd.kt b/examples/src/main/kotlin/space/kscience/kmath/structures/mutableNd.kt new file mode 100644 index 000000000..0b0a4cac1 --- /dev/null +++ b/examples/src/main/kotlin/space/kscience/kmath/structures/mutableNd.kt @@ -0,0 +1,26 @@ +/* + * Copyright 2018-2023 KMath contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package space.kscience.kmath.structures + +import space.kscience.kmath.PerformancePitfall +import space.kscience.kmath.nd.* +import space.kscience.kmath.operations.algebra + +@OptIn(PerformancePitfall::class) +fun main(): Unit = with(Double.algebra.ndAlgebra) { + val structure: MutableStructure2D = mutableStructureND(ShapeND(2, 2)) { (i, j) -> + i.toDouble() + j.toDouble() + }.as2D() + + structure[0, 1] = -2.0 + + val structure2 = mutableStructureND(2, 2) { (i, j) -> i.toDouble() + j.toDouble() }.as2D() + + structure2[0, 1] = 2.0 + + + println(structure + structure2) +} \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 070cb702f..59bc51a20 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/kmath-core/build.gradle.kts b/kmath-core/build.gradle.kts index 08411be59..600b0b8ce 100644 --- a/kmath-core/build.gradle.kts +++ b/kmath-core/build.gradle.kts @@ -37,8 +37,8 @@ kotlin.sourceSets { filter { it.name.contains("test", true) } .map(org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet::languageSettings) .forEach { - it.optIn("space.kscience.kmath.misc.PerformancePitfall") - it.optIn("space.kscience.kmath.misc.UnstableKMathAPI") + it.optIn("space.kscience.kmath.PerformancePitfall") + it.optIn("space.kscience.kmath.UnstableKMathAPI") } } diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/AlgebraND.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/AlgebraND.kt index 91e26cc1b..f6626432d 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/AlgebraND.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/AlgebraND.kt @@ -16,16 +16,22 @@ import kotlin.reflect.KClass * @param T the type of ND-structure element. * @param C the type of the element context. */ -public interface AlgebraND>: Algebra> { +public interface AlgebraND> : Algebra> { /** * The algebra over elements of ND structure. */ public val elementAlgebra: C + /** + * Produces a new [MutableStructureND] using given initializer function. + */ + public fun mutableStructureND(shape: ShapeND, initializer: C.(IntArray) -> T): MutableStructureND + /** * Produces a new [StructureND] using given initializer function. */ - public fun structureND(shape: ShapeND, initializer: C.(IntArray) -> T): StructureND + public fun structureND(shape: ShapeND, initializer: C.(IntArray) -> T): StructureND = + mutableStructureND(shape, initializer) /** * Maps elements from one structure to another one by applying [transform] to them. 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 74c63e6e2..78bc83826 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 @@ -16,9 +16,10 @@ public interface BufferAlgebraND> : AlgebraND { public val bufferAlgebra: BufferAlgebra override val elementAlgebra: A get() = bufferAlgebra.elementAlgebra - override fun structureND(shape: ShapeND, initializer: A.(IntArray) -> T): BufferND { + //TODO change AlgebraND contract to include this + override fun mutableStructureND(shape: ShapeND, initializer: A.(IntArray) -> T): MutableBufferND { val indexer = indexerBuilder(shape) - return BufferND( + return MutableBufferND( indexer, bufferAlgebra.buffer(indexer.linearSize) { offset -> elementAlgebra.initializer(indexer.index(offset)) @@ -26,6 +27,9 @@ public interface BufferAlgebraND> : AlgebraND { ) } + override fun structureND(shape: ShapeND, initializer: A.(IntArray) -> T): BufferND = + mutableStructureND(shape, initializer) + @OptIn(PerformancePitfall::class) public fun StructureND.toBufferND(): BufferND = when (this) { is BufferND -> this @@ -133,6 +137,11 @@ public fun > BufferAlgebraND.structureND( initializer: A.(IntArray) -> T, ): BufferND = structureND(ShapeND(shape), initializer) +public fun > BufferAlgebraND.mutableStructureND( + vararg shape: Int, + initializer: A.(IntArray) -> T, +): MutableBufferND = mutableStructureND(ShapeND(shape), initializer) + public fun , A> A.structureND( initializer: EA.(IntArray) -> T, ): BufferND where A : BufferAlgebraND, A : WithShape = structureND(shape, initializer) diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/DoubleFieldND.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/DoubleFieldND.kt index 265d1eec8..15048efa2 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/DoubleFieldND.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/DoubleFieldND.kt @@ -74,7 +74,7 @@ public sealed class DoubleFieldOpsND : BufferedFieldOpsND(D transform: DoubleField.(Double, Double) -> Double, ): BufferND = zipInline(left.toBufferND(), right.toBufferND()) { l, r -> DoubleField.transform(l, r) } - override fun structureND(shape: ShapeND, initializer: DoubleField.(IntArray) -> Double): DoubleBufferND { + override fun mutableStructureND(shape: ShapeND, initializer: DoubleField.(IntArray) -> Double): DoubleBufferND { val indexer = indexerBuilder(shape) return DoubleBufferND( indexer, @@ -225,7 +225,7 @@ public class DoubleFieldND(override val shape: ShapeND) : override fun number(value: Number): DoubleBufferND { val d = value.toDouble() // minimize conversions - return structureND(shape) { d } + return mutableStructureND(shape) { d } } } diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/StructureND.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/StructureND.kt index e643186ba..f0a258389 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/StructureND.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/StructureND.kt @@ -244,6 +244,7 @@ public interface MutableStructureND : StructureND { * Set value at specified indices */ @PerformancePitfall +@Deprecated("") public operator fun MutableStructureND.set(vararg index: Int, value: T) { set(index, value) } \ No newline at end of file diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/algebraNDExtentions.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/algebraNDExtentions.kt index f0d4bd7f5..506f82da4 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/algebraNDExtentions.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/algebraNDExtentions.kt @@ -17,6 +17,12 @@ public fun > AlgebraND.structureND( initializer: A.(IntArray) -> T ): StructureND = structureND(ShapeND(shapeFirst, *shapeRest), initializer) +public fun > AlgebraND.mutableStructureND( + shapeFirst: Int, + vararg shapeRest: Int, + initializer: A.(IntArray) -> T +): MutableStructureND = mutableStructureND(ShapeND(shapeFirst, *shapeRest), initializer) + public fun > AlgebraND.zero(shape: ShapeND): StructureND = structureND(shape) { zero } @JvmName("zeroVarArg") diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/BufferAlgebra.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/BufferAlgebra.kt index af0bc4d9b..26a4b0a53 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/BufferAlgebra.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/BufferAlgebra.kt @@ -6,7 +6,8 @@ package space.kscience.kmath.operations import space.kscience.kmath.structures.Buffer -import space.kscience.kmath.structures.BufferFactory +import space.kscience.kmath.structures.MutableBuffer +import space.kscience.kmath.structures.MutableBufferFactory public interface WithSize { public val size: Int @@ -17,7 +18,7 @@ public interface WithSize { */ public interface BufferAlgebra> : Algebra> { public val elementAlgebra: A - public val elementBufferFactory: BufferFactory get() = elementAlgebra.bufferFactory + public val elementBufferFactory: MutableBufferFactory get() = elementAlgebra.bufferFactory public fun buffer(size: Int, vararg elements: T): Buffer { require(elements.size == size) { "Expected $size elements but found ${elements.size}" } @@ -73,11 +74,11 @@ private inline fun > BufferAlgebra.zipInline( return elementBufferFactory(l.size) { elementAlgebra.block(l[it], r[it]) } } -public fun BufferAlgebra.buffer(size: Int, initializer: (Int) -> T): Buffer { +public fun BufferAlgebra.buffer(size: Int, initializer: (Int) -> T): MutableBuffer { return elementBufferFactory(size, initializer) } -public fun A.buffer(initializer: (Int) -> T): Buffer where A : BufferAlgebra, A : WithSize { +public fun A.buffer(initializer: (Int) -> T): MutableBuffer where A : BufferAlgebra, A : WithSize { return elementBufferFactory(size, initializer) } diff --git a/kmath-multik/src/commonMain/kotlin/space/kscience/kmath/multik/MultikTensorAlgebra.kt b/kmath-multik/src/commonMain/kotlin/space/kscience/kmath/multik/MultikTensorAlgebra.kt index c3a82b167..c5bbebfd8 100644 --- a/kmath-multik/src/commonMain/kotlin/space/kscience/kmath/multik/MultikTensorAlgebra.kt +++ b/kmath-multik/src/commonMain/kotlin/space/kscience/kmath/multik/MultikTensorAlgebra.kt @@ -33,7 +33,7 @@ public abstract class MultikTensorAlgebra>( protected val multikStat: Statistics = multikEngine.getStatistics() @OptIn(UnsafeKMathAPI::class) - override fun structureND(shape: ShapeND, initializer: A.(IntArray) -> T): MultikTensor { + override fun mutableStructureND(shape: ShapeND, initializer: A.(IntArray) -> T): MultikTensor { val strides = ColumnStrides(shape) val memoryView = initMemoryView(strides.linearSize, type) strides.asSequence().forEachIndexed { linearIndex, tensorIndex -> @@ -49,7 +49,7 @@ public abstract class MultikTensorAlgebra>( for (el in array) data[count++] = elementAlgebra.transform(el) NDArray(data, shape = shape.asArray(), dim = array.dim).wrap() } else { - structureND(shape) { index -> + mutableStructureND(shape) { index -> transform(get(index)) } } @@ -70,7 +70,7 @@ public abstract class MultikTensorAlgebra>( } NDArray(data, shape = array.shape, dim = array.dim).wrap() } else { - structureND(shape) { index -> + mutableStructureND(shape) { index -> transform(index, get(index)) } } 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 0eb147b6f..eab6672a1 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 @@ -34,7 +34,7 @@ public sealed interface Nd4jArrayAlgebra> : AlgebraND.ndArray: INDArray @OptIn(PerformancePitfall::class) - override fun structureND(shape: ShapeND, initializer: C.(IntArray) -> T): Nd4jArrayStructure { + override fun mutableStructureND(shape: ShapeND, initializer: C.(IntArray) -> T): Nd4jArrayStructure { @OptIn(UnsafeKMathAPI::class) val struct: Nd4jArrayStructure = Nd4j.create(*shape.asArray())!!.wrap() struct.indicesIterator().forEach { struct[it] = elementAlgebra.initializer(it) } diff --git a/kmath-nd4j/src/main/kotlin/space/kscience/kmath/nd4j/Nd4jTensorAlgebra.kt b/kmath-nd4j/src/main/kotlin/space/kscience/kmath/nd4j/Nd4jTensorAlgebra.kt index 5905739f8..44401ec53 100644 --- a/kmath-nd4j/src/main/kotlin/space/kscience/kmath/nd4j/Nd4jTensorAlgebra.kt +++ b/kmath-nd4j/src/main/kotlin/space/kscience/kmath/nd4j/Nd4jTensorAlgebra.kt @@ -37,20 +37,20 @@ public sealed interface Nd4jTensorAlgebra> : AnalyticTe */ public val StructureND.ndArray: INDArray - override fun structureND(shape: ShapeND, initializer: A.(IntArray) -> T): Nd4jArrayStructure + override fun mutableStructureND(shape: ShapeND, initializer: A.(IntArray) -> T): Nd4jArrayStructure @OptIn(PerformancePitfall::class) override fun StructureND.map(transform: A.(T) -> T): Nd4jArrayStructure = - structureND(shape) { index -> elementAlgebra.transform(get(index)) } + mutableStructureND(shape) { index -> elementAlgebra.transform(get(index)) } @OptIn(PerformancePitfall::class) override fun StructureND.mapIndexed(transform: A.(index: IntArray, T) -> T): Nd4jArrayStructure = - structureND(shape) { index -> elementAlgebra.transform(index, get(index)) } + mutableStructureND(shape) { index -> elementAlgebra.transform(index, get(index)) } @OptIn(PerformancePitfall::class) override fun zip(left: StructureND, right: StructureND, transform: A.(T, T) -> T): Nd4jArrayStructure { require(left.shape.contentEquals(right.shape)) - return structureND(left.shape) { index -> elementAlgebra.transform(left[index], right[index]) } + return mutableStructureND(left.shape) { index -> elementAlgebra.transform(left[index], right[index]) } } override fun T.plus(arg: StructureND): Nd4jArrayStructure = arg.ndArray.add(this).wrap() @@ -178,7 +178,7 @@ public object DoubleNd4jTensorAlgebra : Nd4jTensorAlgebra { override fun INDArray.wrap(): Nd4jArrayStructure = asDoubleStructure() @OptIn(UnsafeKMathAPI::class) - override fun structureND(shape: ShapeND, initializer: DoubleField.(IntArray) -> Double): Nd4jArrayStructure { + override fun mutableStructureND(shape: ShapeND, initializer: DoubleField.(IntArray) -> Double): Nd4jArrayStructure { val array: INDArray = Nd4j.zeros(*shape.asArray()) val indices = ColumnStrides(shape) indices.asSequence().forEach { index -> diff --git a/kmath-tensorflow/src/main/kotlin/space/kscience/kmath/tensorflow/DoubleTensorFlowAlgebra.kt b/kmath-tensorflow/src/main/kotlin/space/kscience/kmath/tensorflow/DoubleTensorFlowAlgebra.kt index 41c7c0b68..dceb0cb53 100644 --- a/kmath-tensorflow/src/main/kotlin/space/kscience/kmath/tensorflow/DoubleTensorFlowAlgebra.kt +++ b/kmath-tensorflow/src/main/kotlin/space/kscience/kmath/tensorflow/DoubleTensorFlowAlgebra.kt @@ -14,6 +14,7 @@ import space.kscience.kmath.PerformancePitfall import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.expressions.Symbol import space.kscience.kmath.nd.ColumnStrides +import space.kscience.kmath.nd.MutableStructureND import space.kscience.kmath.nd.ShapeND import space.kscience.kmath.nd.StructureND import space.kscience.kmath.operations.DoubleField @@ -36,10 +37,10 @@ public class DoubleTensorFlowAlgebra internal constructor( override val elementAlgebra: DoubleField get() = DoubleField - override fun structureND( + override fun mutableStructureND( shape: ShapeND, initializer: DoubleField.(IntArray) -> Double, - ): StructureND { + ): MutableStructureND { val res = TFloat64.tensorOf(org.tensorflow.ndarray.Shape.of(*shape.toLongArray())) { array -> ColumnStrides(shape).forEach { index -> array.setDouble(elementAlgebra.initializer(index), *index.toLongArray()) diff --git a/kmath-tensors/build.gradle.kts b/kmath-tensors/build.gradle.kts index d27faeeef..7a556ddb6 100644 --- a/kmath-tensors/build.gradle.kts +++ b/kmath-tensors/build.gradle.kts @@ -15,12 +15,12 @@ kscience{ kotlin.sourceSets { all { - languageSettings.optIn("space.kscience.kmath.misc.UnstableKMathAPI") + languageSettings.optIn("space.kscience.kmath.UnstableKMathAPI") } filter { it.name.contains("test", true) } .map(org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet::languageSettings) - .forEach { it.optIn("space.kscience.kmath.misc.PerformancePitfall") } + .forEach { it.optIn("space.kscience.kmath.PerformancePitfall") } commonMain { dependencies { diff --git a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/DoubleTensorAlgebra.kt b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/DoubleTensorAlgebra.kt index 70a3ef7e2..7a076b8b2 100644 --- a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/DoubleTensorAlgebra.kt +++ b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/DoubleTensorAlgebra.kt @@ -127,7 +127,7 @@ public open class DoubleTensorAlgebra : * @param initializer mapping tensor indices to values. * @return tensor with the [shape] shape and data generated by the [initializer]. */ - override fun structureND(shape: ShapeND, initializer: DoubleField.(IntArray) -> Double): DoubleTensor = fromArray( + override fun mutableStructureND(shape: ShapeND, initializer: DoubleField.(IntArray) -> Double): DoubleTensor = fromArray( shape, RowStrides(shape).asSequence().map { DoubleField.initializer(it) }.toMutableList().toDoubleArray() ) diff --git a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/IntTensorAlgebra.kt b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/IntTensorAlgebra.kt index d1cdc68d4..c20b1cd7d 100644 --- a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/IntTensorAlgebra.kt +++ b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/IntTensorAlgebra.kt @@ -118,7 +118,7 @@ public open class IntTensorAlgebra : TensorAlgebra { * @param initializer mapping tensor indices to values. * @return tensor with the [shape] shape and data generated by the [initializer]. */ - override fun structureND(shape: ShapeND, initializer: IntRing.(IntArray) -> Int): IntTensor = fromArray( + override fun mutableStructureND(shape: ShapeND, initializer: IntRing.(IntArray) -> Int): IntTensor = fromArray( shape, RowStrides(shape).asSequence().map { IntRing.initializer(it) }.toMutableList().toIntArray() ) diff --git a/kmath-tensors/src/commonTest/kotlin/space/kscience/kmath/tensors/core/TestDoubleTensor.kt b/kmath-tensors/src/commonTest/kotlin/space/kscience/kmath/tensors/core/TestDoubleTensor.kt index 811fc1117..1f3079bd0 100644 --- a/kmath-tensors/src/commonTest/kotlin/space/kscience/kmath/tensors/core/TestDoubleTensor.kt +++ b/kmath-tensors/src/commonTest/kotlin/space/kscience/kmath/tensors/core/TestDoubleTensor.kt @@ -92,7 +92,7 @@ internal class TestDoubleTensor { @Test fun test2D() = with(DoubleTensorAlgebra) { - val tensor: DoubleTensor = structureND(ShapeND(3, 3)) { (i, j) -> (i - j).toDouble() } + val tensor: DoubleTensor = mutableStructureND(ShapeND(3, 3)) { (i, j) -> (i - j).toDouble() } //println(tensor.toPrettyString()) val tensor2d = tensor.asDoubleTensor2D() assertBufferEquals(DoubleBuffer(1.0, 0.0, -1.0), tensor2d.rows[1]) @@ -101,7 +101,7 @@ internal class TestDoubleTensor { @Test fun testMatrixIteration() = with(DoubleTensorAlgebra) { - val tensor = structureND(ShapeND(3, 3, 3, 3)) { index -> index.sum().toDouble() } + val tensor = mutableStructureND(ShapeND(3, 3, 3, 3)) { index -> index.sum().toDouble() } tensor.forEachMatrix { index, matrix -> println(index.joinToString { it.toString() }) println(matrix) diff --git a/kmath-viktor/src/main/kotlin/space/kscience/kmath/viktor/ViktorFieldOpsND.kt b/kmath-viktor/src/main/kotlin/space/kscience/kmath/viktor/ViktorFieldOpsND.kt index 8c7d6d199..ed705d2cd 100644 --- a/kmath-viktor/src/main/kotlin/space/kscience/kmath/viktor/ViktorFieldOpsND.kt +++ b/kmath-viktor/src/main/kotlin/space/kscience/kmath/viktor/ViktorFieldOpsND.kt @@ -17,8 +17,7 @@ import space.kscience.kmath.operations.ExtendedFieldOps import space.kscience.kmath.operations.NumbersAddOps import space.kscience.kmath.operations.PowerOperations -@OptIn(UnstableKMathAPI::class, PerformancePitfall::class) -@Suppress("OVERRIDE_BY_INLINE", "NOTHING_TO_INLINE") +@OptIn(PerformancePitfall::class) public open class ViktorFieldOpsND : FieldOpsND, ExtendedFieldOps>, @@ -27,13 +26,13 @@ public open class ViktorFieldOpsND : public val StructureND.f64Buffer: F64Array get() = when (this) { is ViktorStructureND -> this.f64Buffer - else -> structureND(shape) { this@f64Buffer[it] }.f64Buffer + else -> mutableStructureND(shape) { this@f64Buffer[it] }.f64Buffer } override val elementAlgebra: DoubleField get() = DoubleField @OptIn(UnsafeKMathAPI::class) - override fun structureND(shape: ShapeND, initializer: DoubleField.(IntArray) -> Double): ViktorStructureND = + override fun mutableStructureND(shape: ShapeND, initializer: DoubleField.(IntArray) -> Double): ViktorStructureND = F64Array(*shape.asArray()).apply { ColumnStrides(shape).asSequence().forEach { index -> set(value = DoubleField.initializer(index), indices = index) From f09371a3f9d90e52c1826f1bf2a09d935987cb08 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sat, 22 Apr 2023 09:13:06 +0300 Subject: [PATCH 03/40] Explicit mutability for StructureND builders --- kmath-ast/build.gradle.kts | 2 +- .../src/jsTest/kotlin/space/kscience/kmath/ast/utils.kt | 2 ++ .../kotlin/space/kscience/kmath/wasm/TestWasmSpecific.kt | 2 ++ .../kotlin/space/kscience/kmath/geometry/Circle2D.kt | 2 +- .../kotlin/space/kscience/kmath/geometry/testUtils.kt | 2 +- .../space/kscience/kmath/geometry/lineExtensions.kt | 8 +++++--- 6 files changed, 12 insertions(+), 6 deletions(-) diff --git a/kmath-ast/build.gradle.kts b/kmath-ast/build.gradle.kts index c60977862..7cdb745f0 100644 --- a/kmath-ast/build.gradle.kts +++ b/kmath-ast/build.gradle.kts @@ -46,7 +46,7 @@ kotlin { sourceSets { filter { it.name.contains("test", true) } .map(org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet::languageSettings) - .forEach { it.optIn("space.kscience.kmath.misc.UnstableKMathAPI") } + .forEach { it.optIn("space.kscience.kmath.UnstableKMathAPI") } } } diff --git a/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/ast/utils.kt b/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/ast/utils.kt index c6b241e5c..f48f74ccd 100644 --- a/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/ast/utils.kt +++ b/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/ast/utils.kt @@ -5,6 +5,7 @@ package space.kscience.kmath.ast +import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.expressions.Expression import space.kscience.kmath.expressions.MST import space.kscience.kmath.expressions.Symbol @@ -17,6 +18,7 @@ import space.kscience.kmath.estree.compileToExpression as estreeCompileToExpress import space.kscience.kmath.wasm.compile as wasmCompile import space.kscience.kmath.wasm.compileToExpression as wasmCompileToExpression +@OptIn(UnstableKMathAPI::class) private object WasmCompilerTestContext : CompilerTestContext { override fun MST.compileToExpression(algebra: IntRing): Expression = wasmCompileToExpression(algebra) override fun MST.compile(algebra: IntRing, arguments: Map): Int = wasmCompile(algebra, arguments) diff --git a/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/wasm/TestWasmSpecific.kt b/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/wasm/TestWasmSpecific.kt index 0a85d5f24..132f9f1bd 100644 --- a/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/wasm/TestWasmSpecific.kt +++ b/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/wasm/TestWasmSpecific.kt @@ -5,6 +5,7 @@ package space.kscience.kmath.wasm +import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.expressions.MstExtendedField import space.kscience.kmath.expressions.MstRing import space.kscience.kmath.expressions.invoke @@ -15,6 +16,7 @@ import space.kscience.kmath.operations.invoke import kotlin.test.Test import kotlin.test.assertEquals +@OptIn(UnstableKMathAPI::class) internal class TestWasmSpecific { @Test fun int() { diff --git a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Circle2D.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Circle2D.kt index 1a4cb6734..202dab0c2 100644 --- a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Circle2D.kt +++ b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Circle2D.kt @@ -8,7 +8,7 @@ package space.kscience.kmath.geometry import kotlinx.serialization.Serializable import kotlin.math.PI -interface Circle +public interface Circle /** diff --git a/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/testUtils.kt b/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/testUtils.kt index 6796b291f..4c3bcc85e 100644 --- a/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/testUtils.kt +++ b/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/testUtils.kt @@ -36,7 +36,7 @@ fun assertVectorEquals(expected: DoubleVector3D, actual: DoubleVector3D, absolut assertEquals(expected.z, actual.z, absoluteTolerance) } -fun > GeometrySpace.isCollinear(a: V, b: V, absoluteTolerance: D = defaultPrecision): Boolean { +fun GeometrySpace.isCollinear(a: V, b: V, absoluteTolerance: Double = defaultPrecision): Boolean { val aDist = a.distanceTo(zero) val bDist = b.distanceTo(zero) return aDist < absoluteTolerance || bDist < absoluteTolerance || abs(abs((a dot b) / (aDist * bDist)) - 1) < absoluteTolerance diff --git a/kmath-geometry/src/jvmMain/kotlin/space/kscience/kmath/geometry/lineExtensions.kt b/kmath-geometry/src/jvmMain/kotlin/space/kscience/kmath/geometry/lineExtensions.kt index cf204f080..bec7e9799 100644 --- a/kmath-geometry/src/jvmMain/kotlin/space/kscience/kmath/geometry/lineExtensions.kt +++ b/kmath-geometry/src/jvmMain/kotlin/space/kscience/kmath/geometry/lineExtensions.kt @@ -12,10 +12,12 @@ import space.kscience.kmath.operations.Group * Get a line, containing this [LineSegment] */ context(Group) -public val LineSegment.line: Line get() = Line(begin, end - begin) +public val LineSegment.line: Line + get() = Line(begin, end - begin) /** * Get a length of a line segment */ -context(GeometrySpace) -public val LineSegment.length: Double get() = norm(end - begin) \ No newline at end of file +context(GeometrySpace) +public val > LineSegment.length: D + get() = norm(end - begin) \ No newline at end of file From 1316e6548ed71ff2ebd4fe3afeb910349af22310 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Tue, 9 May 2023 19:01:37 +0300 Subject: [PATCH 04/40] Remove vector type from polygon --- docs/templates/README-TEMPLATE.md | 13 +++++-------- .../kotlin/space/kscience/kmath/geometry/Polygon.kt | 4 ++-- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/docs/templates/README-TEMPLATE.md b/docs/templates/README-TEMPLATE.md index d7d5a806d..8988a887e 100644 --- a/docs/templates/README-TEMPLATE.md +++ b/docs/templates/README-TEMPLATE.md @@ -59,22 +59,21 @@ ${modules} KMath is developed as a multi-platform library, which means that most of the interfaces are declared in the [common source sets](/kmath-core/src/commonMain) and implemented there wherever it is possible. In some cases, features are delegated to platform-specific implementations even if they could be provided in the common module for performance -reasons. Currently, the Kotlin/JVM is the primary platform, however Kotlin/Native and Kotlin/JS contributions and +reasons. Currently, Kotlin/JVM is the primary platform, however, Kotlin/Native and Kotlin/JS contributions and feedback are also welcome. ## Performance -Calculation performance is one of major goals of KMath in the future, but in some cases it is impossible to achieve both +Calculation of performance is one of the major goals of KMath in the future, but in some cases it is impossible to achieve both performance and flexibility. -We expect to focus on creating convenient universal API first and then work on increasing performance for specific +We expect to focus on creating a convenient universal API first and then work on increasing performance for specific cases. We expect the worst KMath benchmarks will perform better than native Python, but worse than optimized native/SciPy (mostly due to boxing operations on primitive numbers). The best performance of optimized parts could be better than SciPy. ## Requirements -KMath currently relies on JDK 11 for compilation and execution of Kotlin-JVM part. We recommend to use GraalVM-CE 11 for -execution to get better performance. +KMath currently relies on JDK 11 for compilation and execution of Kotlin-JVM part. We recommend using GraalVM-CE 11/17 for execution to get better performance. ### Repositories @@ -94,11 +93,9 @@ dependencies { } ``` -Gradle `6.0+` is required for multiplatform artifacts. - ## Contributing The project requires a lot of additional work. The most important thing we need is a feedback about what features are required the most. Feel free to create feature requests. We are also welcome to code contributions, especially in issues marked with -[waiting for a hero](https://github.com/mipt-npm/kmath/labels/waiting%20for%20a%20hero) label. \ No newline at end of file +[good first issue](hhttps://github.com/SciProgCentre/kmath/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22) label. \ No newline at end of file diff --git a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Polygon.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Polygon.kt index 20f4a031e..0d82f865c 100644 --- a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Polygon.kt +++ b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Polygon.kt @@ -9,6 +9,6 @@ package space.kscience.kmath.geometry /** * A closed polygon in 2D space */ -public interface Polygon { - public val points: List> +public interface Polygon { + public val points: List } \ No newline at end of file From d3893ab7e6b38970c5761f4c14c949272331ebc7 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Tue, 20 Jun 2023 19:45:21 +0300 Subject: [PATCH 05/40] [WIP] moving from features to attributes --- attributes-kt/build.gradle.kts | 17 +++++ .../space/kscience/attributes/Attribute.kt | 28 ++++++++ .../kscience/attributes/AttributeContainer.kt | 13 ++++ .../space/kscience/attributes/Attributes.kt | 71 +++++++++++++++++++ .../kscience/attributes/AttributesBuilder.kt | 52 ++++++++++++++ build.gradle.kts | 2 +- buildSrc/settings.gradle.kts | 6 -- gradle.properties | 9 ++- .../kscience/kmath/commons/linear/CMMatrix.kt | 2 +- kmath-core/build.gradle.kts | 1 + .../kscience/kmath/linear/MatrixFeatures.kt | 37 +++++----- .../kscience/kmath/linear/MatrixWrapper.kt | 25 +++---- .../space/kscience/kmath/misc/Featured.kt | 61 ---------------- .../space/kscience/kmath/nd/AlgebraND.kt | 5 +- .../space/kscience/kmath/nd/StructureND.kt | 14 ++-- kmath-symja/build.gradle.kts | 2 +- settings.gradle.kts | 1 + 17 files changed, 219 insertions(+), 127 deletions(-) create mode 100644 attributes-kt/build.gradle.kts create mode 100644 attributes-kt/src/commonMain/kotlin/space/kscience/attributes/Attribute.kt create mode 100644 attributes-kt/src/commonMain/kotlin/space/kscience/attributes/AttributeContainer.kt create mode 100644 attributes-kt/src/commonMain/kotlin/space/kscience/attributes/Attributes.kt create mode 100644 attributes-kt/src/commonMain/kotlin/space/kscience/attributes/AttributesBuilder.kt delete mode 100644 kmath-core/src/commonMain/kotlin/space/kscience/kmath/misc/Featured.kt diff --git a/attributes-kt/build.gradle.kts b/attributes-kt/build.gradle.kts new file mode 100644 index 000000000..fe422f751 --- /dev/null +++ b/attributes-kt/build.gradle.kts @@ -0,0 +1,17 @@ +plugins { + id("space.kscience.gradle.mpp") +} + +kscience { + jvm() + js() + native() + wasm() +} + +readme { + maturity = space.kscience.gradle.Maturity.DEVELOPMENT + description = """ + An API and basic implementation for arranging objects in a continuous memory block. + """.trimIndent() +} diff --git a/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/Attribute.kt b/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/Attribute.kt new file mode 100644 index 000000000..4b9e27655 --- /dev/null +++ b/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/Attribute.kt @@ -0,0 +1,28 @@ +/* + * Copyright 2018-2023 KMath contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package space.kscience.attributes + +import kotlin.reflect.KType + +public interface Attribute + + +public interface AttributeWithDefault : Attribute { + public val default: T +} + +public interface SetAttribute : Attribute> + +/** + * An attribute that has a type parameter for value + */ +public abstract class PolymorphicAttribute(public val type: KType) : Attribute { + override fun equals(other: Any?): Boolean = (other as? PolymorphicAttribute<*>)?.type == this.type + + override fun hashCode(): Int { + return type.hashCode() + } +} diff --git a/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/AttributeContainer.kt b/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/AttributeContainer.kt new file mode 100644 index 000000000..69b050649 --- /dev/null +++ b/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/AttributeContainer.kt @@ -0,0 +1,13 @@ +/* + * Copyright 2018-2023 KMath contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package space.kscience.attributes + +/** + * A container for attributes. [attributes] could be made mutable by implementation + */ +public interface AttributeContainer { + public val attributes: Attributes +} \ No newline at end of file diff --git a/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/Attributes.kt b/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/Attributes.kt new file mode 100644 index 000000000..25767a686 --- /dev/null +++ b/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/Attributes.kt @@ -0,0 +1,71 @@ +/* + * Copyright 2018-2023 KMath contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package space.kscience.attributes + +import kotlin.jvm.JvmInline + +@JvmInline +public value class Attributes internal constructor(public val content: Map, Any>) { + + public val keys: Set> get() = content.keys + + @Suppress("UNCHECKED_CAST") + public operator fun get(attribute: Attribute): T? = content[attribute] as? T + + override fun toString(): String = "Attributes(value=${content.entries})" + + public companion object { + public val EMPTY: Attributes = Attributes(emptyMap()) + } +} + +public fun Attributes.isEmpty(): Boolean = content.isEmpty() + +public fun Attributes.getOrDefault(attribute: AttributeWithDefault): T = get(attribute) ?: attribute.default + +public fun > Attributes.withAttribute( + attribute: A, + attrValue: T?, +): Attributes = Attributes( + if (attrValue == null) { + content - attribute + } else { + content + (attribute to attrValue) + } +) + +/** + * Add an element to a [SetAttribute] + */ +public fun > Attributes.withAttributeElement( + attribute: A, + attrValue: T, +): Attributes { + val currentSet: Set = get(attribute) ?: emptySet() + return Attributes( + content + (attribute to (currentSet + attrValue)) + ) +} + +/** + * Remove an element from [SetAttribute] + */ +public fun > Attributes.withoutAttributeElement( + attribute: A, + attrValue: T, +): Attributes { + val currentSet: Set = get(attribute) ?: emptySet() + return Attributes( + content + (attribute to (currentSet - attrValue)) + ) +} + +public fun > Attributes( + attribute: A, + attrValue: T, +): Attributes = Attributes(mapOf(attribute to attrValue)) + +public operator fun Attributes.plus(other: Attributes): Attributes = Attributes(content + other.content) \ No newline at end of file diff --git a/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/AttributesBuilder.kt b/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/AttributesBuilder.kt new file mode 100644 index 000000000..588c789f5 --- /dev/null +++ b/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/AttributesBuilder.kt @@ -0,0 +1,52 @@ +/* + * Copyright 2018-2023 KMath contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package space.kscience.attributes + +/** + * A safe builder for [Attributes] + */ +public class AttributesBuilder internal constructor(private val map: MutableMap, Any> = mutableMapOf()) { + + @Suppress("UNCHECKED_CAST") + public operator fun get(attribute: Attribute): T? = map[attribute] as? T + + public operator fun Attribute.invoke(value: V?) { + if (value == null) { + map.remove(this) + } else { + map[this] = value + } + } + + public fun from(attributes: Attributes) { + map.putAll(attributes.content) + } + + public fun SetAttribute.add( + attrValue: V, + ) { + val currentSet: Set = get(this) ?: emptySet() + map[this] = currentSet + attrValue + } + + /** + * Remove an element from [SetAttribute] + */ + public fun SetAttribute.remove( + attrValue: V, + ) { + val currentSet: Set = get(this) ?: emptySet() + map[this] = currentSet - attrValue + } + + public fun build(): Attributes = Attributes(map) +} + +public fun AttributesBuilder( + attributes: Attributes, +): AttributesBuilder = AttributesBuilder(attributes.content.toMutableMap()) + +public fun Attributes(builder: AttributesBuilder.() -> Unit): Attributes = AttributesBuilder().apply(builder).build() \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index 043420577..a132f091c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -15,7 +15,7 @@ allprojects { } group = "space.kscience" - version = "0.3.2-dev-1" + version = "0.4.0-dev-1" } subprojects { diff --git a/buildSrc/settings.gradle.kts b/buildSrc/settings.gradle.kts index e6b69b0b3..38eebeecc 100644 --- a/buildSrc/settings.gradle.kts +++ b/buildSrc/settings.gradle.kts @@ -1,9 +1,3 @@ -/* - * Copyright 2018-2021 KMath contributors. - * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. - */ -rootProject.name = "kmath" - enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS") dependencyResolutionManagement { diff --git a/gradle.properties b/gradle.properties index fee75d428..162720167 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,11 +6,10 @@ kotlin.code.style=official kotlin.mpp.stability.nowarn=true kotlin.native.ignoreDisabledTargets=true -org.gradle.configureondemand=true -org.gradle.jvmargs=-Xmx4096m - -toolsVersion=0.14.8-kotlin-1.8.20 - +toolsVersion=0.14.9-kotlin-1.8.20 org.gradle.parallel=true org.gradle.workers.max=4 +org.gradle.configureondemand=true +org.gradle.jvmargs=-Xmx4096m + 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 d19bd1be0..e369effdf 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 @@ -106,7 +106,7 @@ public object CMLinearSpace : LinearSpace { val origin = structure.toCM().origin return when (type) { - DiagonalFeature::class -> if (origin is DiagonalMatrix) DiagonalFeature else null + IsDiagonal::class -> if (origin is DiagonalMatrix) IsDiagonal else null DeterminantFeature::class, LupDecompositionFeature::class -> object : DeterminantFeature, diff --git a/kmath-core/build.gradle.kts b/kmath-core/build.gradle.kts index 4ecff77aa..398465fbe 100644 --- a/kmath-core/build.gradle.kts +++ b/kmath-core/build.gradle.kts @@ -10,6 +10,7 @@ kscience{ dependencies { api(projects.kmathMemory) + api(projects.attributesKt) } testDependencies { diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixFeatures.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixFeatures.kt index ce7acdcba..62325b39d 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixFeatures.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixFeatures.kt @@ -5,54 +5,49 @@ package space.kscience.kmath.linear -import space.kscience.kmath.nd.StructureFeature +import space.kscience.attributes.Attribute /** * A marker interface representing some properties of matrices or additional transformations of them. Features are used * to optimize matrix operations performance in some cases or retrieve the APIs. */ -public interface MatrixFeature: StructureFeature +public interface MatrixFeature : Attribute /** - * Matrices with this feature are considered to have only diagonal non-null elements. + * Matrices with this feature are considered to have only diagonal non-zero elements. */ -public interface DiagonalFeature : MatrixFeature { - public companion object : DiagonalFeature +public interface IsDiagonal : MatrixFeature { + public companion object : IsDiagonal } /** * Matrices with this feature have all zero elements. */ -public object ZeroFeature : DiagonalFeature +public object IsZero : IsDiagonal /** * Matrices with this feature have unit elements on diagonal and zero elements in all other places. */ -public object UnitFeature : DiagonalFeature +public object IsUnit : IsDiagonal /** * Matrices with this feature can be inverted: *[inverse] = a−1* where *a* is the owning matrix. * * @param T the type of matrices' items. */ -public interface InverseMatrixFeature : MatrixFeature { - /** - * The inverse matrix of the matrix that owns this feature. - */ - public val inverse: Matrix +public class Inverted private constructor() : MatrixFeature> { + internal val instance: Inverted = Inverted() } +@Suppress("UNCHECKED_CAST") +public val LinearSpace.Inverted: Inverted get() = Inverted.instance as Inverted + /** * Matrices with this feature can compute their determinant. * * @param T the type of matrices' items. */ -public interface DeterminantFeature : MatrixFeature { - /** - * The determinant of the matrix that owns this feature. - */ - public val determinant: T -} +public class DeterminantFeature : MatrixFeature /** * Produces a [DeterminantFeature] where the [DeterminantFeature.determinant] is [determinant]. @@ -68,12 +63,12 @@ public fun DeterminantFeature(determinant: T): DeterminantFeature = /** * Matrices with this feature are lower triangular ones. */ -public object LFeature : MatrixFeature +public object LFeature : MatrixFeature /** * Matrices with this feature are upper triangular ones. */ -public object UFeature : MatrixFeature +public object UFeature : MatrixFeature /** * Matrices with this feature support LU factorization: *a = [l] · [u]* where *a* is the owning matrix. @@ -117,7 +112,7 @@ public interface LupDecompositionFeature : MatrixFeature { /** * Matrices with this feature are orthogonal ones: *a · aT = u* where *a* is the owning matrix, *u* - * is the unit matrix ([UnitFeature]). + * is the unit matrix ([IsUnit]). */ public object OrthogonalFeature : MatrixFeature diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixWrapper.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixWrapper.kt index 46454a584..b510cc697 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixWrapper.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixWrapper.kt @@ -5,11 +5,10 @@ package space.kscience.kmath.linear +import space.kscience.attributes.Attributes import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.misc.FeatureSet -import space.kscience.kmath.nd.StructureFeature import space.kscience.kmath.operations.Ring -import kotlin.reflect.KClass /** * A [Matrix] that holds [MatrixFeature] objects. @@ -18,18 +17,10 @@ import kotlin.reflect.KClass */ public class MatrixWrapper internal constructor( public val origin: Matrix, - public val features: FeatureSet, + public val attributes: Attributes, ) : Matrix by origin { - /** - * Get the first feature matching given class. Does not guarantee that matrix has only one feature matching the - * criteria. - */ - @Suppress("UNCHECKED_CAST") - override fun getFeature(type: KClass): F? = - features.getFeature(type) ?: origin.getFeature(type) - - override fun toString(): String = "MatrixWrapper(matrix=$origin, features=$features)" + override fun toString(): String = "MatrixWrapper(matrix=$origin, features=$attributes)" } /** @@ -44,7 +35,7 @@ public val Matrix.origin: Matrix * Add a single feature to a [Matrix] */ public fun Matrix.withFeature(newFeature: MatrixFeature): MatrixWrapper = if (this is MatrixWrapper) { - MatrixWrapper(origin, features.with(newFeature)) + MatrixWrapper(origin, attributes.with(newFeature)) } else { MatrixWrapper(this, FeatureSet.of(newFeature)) } @@ -57,20 +48,20 @@ public operator fun Matrix.plus(newFeature: MatrixFeature): MatrixW */ public fun Matrix.withFeatures(newFeatures: Iterable): MatrixWrapper = if (this is MatrixWrapper) { - MatrixWrapper(origin, features.with(newFeatures)) + MatrixWrapper(origin, attributes.with(newFeatures)) } else { MatrixWrapper(this, FeatureSet.of(newFeatures)) } /** - * Diagonal matrix of ones. The matrix is virtual no actual matrix is created. + * Diagonal matrix of ones. The matrix is virtual, no actual matrix is created. */ public fun LinearSpace>.one( rows: Int, columns: Int, ): Matrix = VirtualMatrix(rows, columns) { i, j -> if (i == j) elementAlgebra.one else elementAlgebra.zero -}.withFeature(UnitFeature) +}.withFeature(IsUnit) /** @@ -81,7 +72,7 @@ public fun LinearSpace>.zero( columns: Int, ): Matrix = VirtualMatrix(rows, columns) { _, _ -> elementAlgebra.zero -}.withFeature(ZeroFeature) +}.withFeature(IsZero) public class TransposedFeature(public val original: Matrix) : MatrixFeature diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/misc/Featured.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/misc/Featured.kt deleted file mode 100644 index bdda674dc..000000000 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/misc/Featured.kt +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2018-2022 KMath contributors. - * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. - */ - -package space.kscience.kmath.misc - -import kotlin.jvm.JvmInline -import kotlin.reflect.KClass - -/** - * An entity that contains a set of features defined by their types - */ -public interface Featured { - public fun getFeature(type: FeatureKey): T? -} - -public typealias FeatureKey = KClass - -public interface Feature> { - - /** - * A key used for extraction - */ - @Suppress("UNCHECKED_CAST") - public val key: FeatureKey - get() = this::class as FeatureKey -} - -/** - * A container for a set of features - */ -@JvmInline -public value class FeatureSet> private constructor(public val features: Map, F>) : Featured { - @Suppress("UNCHECKED_CAST") - override fun getFeature(type: FeatureKey): T? = features[type]?.let { it as T } - - public inline fun getFeature(): T? = getFeature(T::class) - - public fun with(feature: T, type: FeatureKey = feature.key): FeatureSet = - FeatureSet(features + (type to feature)) - - public fun with(other: FeatureSet): FeatureSet = FeatureSet(features + other.features) - - public fun with(vararg otherFeatures: F): FeatureSet = - FeatureSet(features + otherFeatures.associateBy { it.key }) - - public fun with(otherFeatures: Iterable): FeatureSet = - FeatureSet(features + otherFeatures.associateBy { it.key }) - - public operator fun iterator(): Iterator = features.values.iterator() - - override fun toString(): String = features.values.joinToString(prefix = "[ ", postfix = " ]") - - - public companion object { - public fun > of(vararg features: F): FeatureSet = FeatureSet(features.associateBy { it.key }) - public fun > of(features: Iterable): FeatureSet = - FeatureSet(features.associateBy { it.key }) - } -} diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/AlgebraND.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/AlgebraND.kt index f6626432d..a75807bad 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/AlgebraND.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/AlgebraND.kt @@ -114,7 +114,7 @@ public interface GroupOpsND> : GroupOps>, override fun add(left: StructureND, right: StructureND): StructureND = zip(left, right) { aValue, bValue -> add(aValue, bValue) } - // TODO move to extensions after KEEP-176 + // TODO implement using context receivers /** * Adds an ND structure to an element of it. @@ -181,8 +181,6 @@ public interface RingOpsND> : RingOps>, Gro override fun multiply(left: StructureND, right: StructureND): StructureND = zip(left, right) { aValue, bValue -> multiply(aValue, bValue) } - //TODO move to extensions with context receivers - /** * Multiplies an ND structure by an element of it. * @@ -232,7 +230,6 @@ public interface FieldOpsND> : override fun divide(left: StructureND, right: StructureND): StructureND = zip(left, right) { aValue, bValue -> divide(aValue, bValue) } - //TODO move to extensions after https://github.com/Kotlin/KEEP/blob/master/proposals/context-receivers.md /** * Divides an ND structure by an element of it. * diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/StructureND.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/StructureND.kt index f0a258389..e9814acbf 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/StructureND.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/StructureND.kt @@ -5,10 +5,10 @@ package space.kscience.kmath.nd +import space.kscience.attributes.Attribute +import space.kscience.attributes.AttributeContainer import space.kscience.kmath.PerformancePitfall import space.kscience.kmath.linear.LinearSpace -import space.kscience.kmath.misc.Feature -import space.kscience.kmath.misc.Featured import space.kscience.kmath.operations.Ring import space.kscience.kmath.operations.invoke import space.kscience.kmath.structures.Buffer @@ -17,7 +17,7 @@ import kotlin.jvm.JvmName import kotlin.math.abs import kotlin.reflect.KClass -public interface StructureFeature : Feature +public interface StructureFeature : Attribute /** * Represents n-dimensional structure i.e., multidimensional container of items of the same type and size. The number @@ -28,7 +28,7 @@ public interface StructureFeature : Feature * * @param T the type of items. */ -public interface StructureND : Featured, WithShape { +public interface StructureND : AttributeContainer, WithShape { /** * The shape of structure i.e., non-empty sequence of non-negative integers that specify sizes of dimensions of * this structure. @@ -57,12 +57,6 @@ public interface StructureND : Featured, WithShape { @PerformancePitfall public fun elements(): Sequence> = indices.asSequence().map { it to get(it) } - /** - * Feature is some additional structure information that allows to access it special properties or hints. - * If the feature is not present, `null` is returned. - */ - override fun getFeature(type: KClass): F? = null - public companion object { /** * Indicates whether some [StructureND] is equal to another one. diff --git a/kmath-symja/build.gradle.kts b/kmath-symja/build.gradle.kts index 8741de2ae..a996f3bec 100644 --- a/kmath-symja/build.gradle.kts +++ b/kmath-symja/build.gradle.kts @@ -10,7 +10,7 @@ plugins { description = "Symja integration module" dependencies { - api("org.matheclipse:matheclipse-core:2.0.0-SNAPSHOT") { + api("org.matheclipse:matheclipse-core:2.0.0") { // Incorrect transitive dependencies exclude("org.apfloat", "apfloat") exclude("org.hipparchus", "hipparchus-clustering") diff --git a/settings.gradle.kts b/settings.gradle.kts index f158f3444..e660bef85 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -21,6 +21,7 @@ dependencyResolutionManagement { include( ":test-utils", + ":attributes-kt", ":kmath-memory", ":kmath-complex", ":kmath-core", From 6da51b7794f9ccf6d24c29b85b5081bba1cedf65 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sun, 9 Jul 2023 15:51:50 +0300 Subject: [PATCH 06/40] [WIP] Features to Attributes refactoring --- CHANGELOG.md | 4 +- .../space/kscience/attributes/Attribute.kt | 21 +- .../space/kscience/attributes/Attributes.kt | 48 +- .../space/kscience/attributes/SafeType.kt | 26 + .../space/kscience/attributes/annotations.kt | 17 + buildSrc/settings.gradle.kts | 3 +- .../kmath/ejml/codegen/ejmlCodegen.kt | 2 + gradle.properties | 3 +- gradle/wrapper/gradle-wrapper.properties | 2 +- .../kscience/kmath/commons/linear/CMMatrix.kt | 31 +- .../kscience/kmath/expressions/DSAlgebra.kt | 2 + .../kmath/linear/BufferedLinearSpace.kt | 3 + .../kmath/linear/DoubleLinearSpace.kt | 4 +- .../kscience/kmath/linear/LinearSpace.kt | 40 +- .../kscience/kmath/linear/LupDecomposition.kt | 188 +-- .../kscience/kmath/linear/MatrixBuilder.kt | 7 +- .../kscience/kmath/linear/MatrixFeatures.kt | 158 +-- .../kscience/kmath/linear/MatrixWrapper.kt | 47 +- .../kscience/kmath/linear/VirtualMatrix.kt | 9 +- .../space/kscience/kmath/nd/AlgebraND.kt | 4 +- .../space/kscience/kmath/nd/BufferND.kt | 4 +- .../space/kscience/kmath/nd/Structure2D.kt | 2 +- .../space/kscience/kmath/nd/StructureND.kt | 22 +- .../kscience/kmath/operations/Algebra.kt | 10 +- .../kmath/operations/BufferAlgebra.kt | 4 + .../space/kscience/kmath/structures/Buffer.kt | 22 +- .../kmath/structures/BufferAccessor2D.kt | 9 +- .../kmath/structures/MutableBuffer.kt | 25 +- .../kscience/kmath/ejml/EjmlLinearSpace.kt | 4 +- .../space/kscience/kmath/ejml/_generated.kt | 1003 ----------------- .../kscience/kmath/ejml/EjmlMatrixTest.kt | 4 +- .../space/kscience/kmath/real/DoubleVector.kt | 1 - .../kscience/kmath/functions/Polynomial.kt | 21 +- .../kmath/distributions/NormalDistribution.kt | 7 +- 34 files changed, 457 insertions(+), 1300 deletions(-) create mode 100644 attributes-kt/src/commonMain/kotlin/space/kscience/attributes/SafeType.kt create mode 100644 attributes-kt/src/commonMain/kotlin/space/kscience/attributes/annotations.kt delete mode 100644 kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/_generated.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e1d9f530..bbfb68501 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,9 +3,11 @@ ## Unreleased ### Added -- Explicit `mutableStructureND` builders for mutable stucures +- New Attributes-kt module that could be used as stand-alone. It declares type-safe attributes containers. +- Explicit `mutableStructureND` builders for mutable structures ### Changed +- Features replaced with Attributes. ### Deprecated diff --git a/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/Attribute.kt b/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/Attribute.kt index 4b9e27655..6fa142180 100644 --- a/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/Attribute.kt +++ b/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/Attribute.kt @@ -9,20 +9,31 @@ import kotlin.reflect.KType public interface Attribute +/** + * An attribute that could be either present or absent + */ +public interface FlagAttribute : Attribute +/** + * An attribute with a default value + */ public interface AttributeWithDefault : Attribute { public val default: T } +/** + * Attribute containing a set of values + */ public interface SetAttribute : Attribute> /** * An attribute that has a type parameter for value + * @param type parameter-type */ -public abstract class PolymorphicAttribute(public val type: KType) : Attribute { - override fun equals(other: Any?): Boolean = (other as? PolymorphicAttribute<*>)?.type == this.type +public abstract class PolymorphicAttribute(public val type: SafeType) : Attribute { + override fun equals(other: Any?): Boolean = other != null && + (this::class == other::class) && + (other as? PolymorphicAttribute<*>)?.type == this.type - override fun hashCode(): Int { - return type.hashCode() - } + override fun hashCode(): Int = this::class.hashCode() + type.hashCode() } diff --git a/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/Attributes.kt b/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/Attributes.kt index 25767a686..f93b6446a 100644 --- a/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/Attributes.kt +++ b/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/Attributes.kt @@ -24,18 +24,45 @@ public value class Attributes internal constructor(public val content: Map Attributes.getOrDefault(attribute: AttributeWithDefault): T = get(attribute) ?: attribute.default -public fun > Attributes.withAttribute( +/** + * Check if there is an attribute that matches given key by type and adheres to [predicate]. + */ +@Suppress("UNCHECKED_CAST") +public inline fun > Attributes.any(predicate: (value: T) -> Boolean): Boolean = + content.any { (mapKey, mapValue) -> mapKey is A && predicate(mapValue as T) } + +/** + * Check if there is an attribute of given type (subtypes included) + */ +public inline fun > Attributes.any(): Boolean = + content.any { (mapKey, _) -> mapKey is A } + +/** + * Check if [Attributes] contains a flag. Multiple keys that are instances of a flag could be present + */ +public inline fun Attributes.has(): Boolean = + content.keys.any { it is A } + +/** + * Create [Attributes] with an added or replaced attribute key. + */ +public fun > Attributes.withAttribute( attribute: A, - attrValue: T?, -): Attributes = Attributes( - if (attrValue == null) { - content - attribute - } else { - content + (attribute to attrValue) - } -) + attrValue: T, +): Attributes = Attributes(content + (attribute to attrValue)) + +public fun > Attributes.withAttribute(attribute: A): Attributes = + withAttribute(attribute, Unit) + +/** + * Create new [Attributes] by removing [attribute] key + */ +public fun Attributes.withoutAttribute(attribute: Attribute<*>): Attributes = Attributes(content.minus(attribute)) /** * Add an element to a [SetAttribute] @@ -63,6 +90,9 @@ public fun > Attributes.withoutAttributeElement( ) } +/** + * Create [Attributes] with a single key + */ public fun > Attributes( attribute: A, attrValue: T, diff --git a/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/SafeType.kt b/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/SafeType.kt new file mode 100644 index 000000000..44ead89cb --- /dev/null +++ b/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/SafeType.kt @@ -0,0 +1,26 @@ +/* + * Copyright 2018-2023 KMath contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package space.kscience.attributes + +import kotlin.reflect.KClass +import kotlin.reflect.KType +import kotlin.reflect.typeOf + +/** + * Safe variant ok Kotlin [KType] that ensures that the type parameter is of the same type ask [kType] + * + * @param kType raw [KType] + */ +public class SafeType @PublishedApi internal constructor(public val kType: KType) + +public inline fun safeTypeOf(): SafeType = SafeType(typeOf()) + +/** + * Derive Kotlin [KClass] from this type and fail if the type is not a class (should not happen) + */ +@Suppress("UNCHECKED_CAST") +@UnstableAttributesAPI +public val SafeType.kClass: KClass get() = kType.classifier as KClass \ No newline at end of file diff --git a/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/annotations.kt b/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/annotations.kt new file mode 100644 index 000000000..80d93daaf --- /dev/null +++ b/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/annotations.kt @@ -0,0 +1,17 @@ +/* + * Copyright 2018-2023 KMath contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package space.kscience.attributes + +/** + * Marks declarations that are still experimental in the Attributes-kt APIs, which means that the design of the corresponding + * declarations has open issues that may (or may not) lead to their changes in the future. Roughly speaking, there is + * a chance of those declarations will be deprecated in the future or the semantics of their behavior may change + * in some way that may break some code. + */ +@MustBeDocumented +@Retention(value = AnnotationRetention.BINARY) +@RequiresOptIn("This API is unstable and could change in future", RequiresOptIn.Level.WARNING) +public annotation class UnstableAttributesAPI \ No newline at end of file diff --git a/buildSrc/settings.gradle.kts b/buildSrc/settings.gradle.kts index 38eebeecc..53c47a814 100644 --- a/buildSrc/settings.gradle.kts +++ b/buildSrc/settings.gradle.kts @@ -1,4 +1,4 @@ -enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS") +rootProject.name = "buildSrc" dependencyResolutionManagement { val projectProperties = java.util.Properties() @@ -13,6 +13,7 @@ dependencyResolutionManagement { val toolsVersion: String = projectProperties["toolsVersion"].toString() + @Suppress("UnstableApiUsage") repositories { mavenLocal() maven("https://repo.kotlin.link") diff --git a/buildSrc/src/main/kotlin/space/kscience/kmath/ejml/codegen/ejmlCodegen.kt b/buildSrc/src/main/kotlin/space/kscience/kmath/ejml/codegen/ejmlCodegen.kt index d973ebae4..22e86c2a2 100644 --- a/buildSrc/src/main/kotlin/space/kscience/kmath/ejml/codegen/ejmlCodegen.kt +++ b/buildSrc/src/main/kotlin/space/kscience/kmath/ejml/codegen/ejmlCodegen.kt @@ -56,6 +56,8 @@ public object EjmlLinearSpace${ops} : EjmlLinearSpace<${type}, ${kmathAlgebra}, */ override val elementAlgebra: $kmathAlgebra get() = $kmathAlgebra + override val elementType: KType get() = typeOf<$type>() + @Suppress("UNCHECKED_CAST") override fun Matrix<${type}>.toEjml(): Ejml${type}Matrix<${ejmlMatrixType}> = when { this is Ejml${type}Matrix<*> && origin is $ejmlMatrixType -> this as Ejml${type}Matrix<${ejmlMatrixType}> diff --git a/gradle.properties b/gradle.properties index 162720167..2f1a2a030 100644 --- a/gradle.properties +++ b/gradle.properties @@ -11,5 +11,4 @@ toolsVersion=0.14.9-kotlin-1.8.20 org.gradle.parallel=true org.gradle.workers.max=4 org.gradle.configureondemand=true -org.gradle.jvmargs=-Xmx4096m - +org.gradle.jvmargs=-Xmx4096m \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index fae08049a..15de90249 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists 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 e369effdf..85ff881ef 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 @@ -8,12 +8,14 @@ package space.kscience.kmath.commons.linear import org.apache.commons.math3.linear.* import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.linear.* -import space.kscience.kmath.nd.StructureFeature +import space.kscience.kmath.nd.StructureAttribute import space.kscience.kmath.operations.DoubleField import space.kscience.kmath.structures.Buffer import space.kscience.kmath.structures.DoubleBuffer import kotlin.reflect.KClass +import kotlin.reflect.KType import kotlin.reflect.cast +import kotlin.reflect.typeOf public class CMMatrix(public val origin: RealMatrix) : Matrix { override val rowNum: Int get() = origin.rowDimension @@ -38,6 +40,8 @@ public fun RealVector.toPoint(): CMVector = CMVector(this) public object CMLinearSpace : LinearSpace { override val elementAlgebra: DoubleField get() = DoubleField + override val elementType: KType = typeOf() + override fun buildMatrix( rows: Int, columns: Int, @@ -99,7 +103,7 @@ public object CMLinearSpace : LinearSpace { v * this @UnstableKMathAPI - override fun computeFeature(structure: Matrix, type: KClass): F? { + override fun computeFeature(structure: Matrix, type: KClass): F? { //Return the feature if it is intrinsic to the structure structure.getFeature(type)?.let { return it } @@ -108,36 +112,37 @@ public object CMLinearSpace : LinearSpace { return when (type) { IsDiagonal::class -> if (origin is DiagonalMatrix) IsDiagonal else null - DeterminantFeature::class, LupDecompositionFeature::class -> object : - DeterminantFeature, - LupDecompositionFeature { + Determinant::class, LupDecompositionAttribute::class -> object : + Determinant, + LupDecompositionAttribute { private val lup by lazy { LUDecomposition(origin) } override val determinant: Double by lazy { lup.determinant } - override val l: Matrix by lazy> { CMMatrix(lup.l).withFeature(LFeature) } - override val u: Matrix by lazy> { CMMatrix(lup.u).withFeature(UFeature) } + override val l: Matrix by lazy> { CMMatrix(lup.l).withAttribute(LowerTriangular) } + override val u: Matrix by lazy> { CMMatrix(lup.u).withAttribute(UpperTriangular) } override val p: Matrix by lazy { CMMatrix(lup.p) } } - CholeskyDecompositionFeature::class -> object : CholeskyDecompositionFeature { + CholeskyDecompositionAttribute::class -> object : CholeskyDecompositionAttribute { override val l: Matrix by lazy> { val cholesky = CholeskyDecomposition(origin) - CMMatrix(cholesky.l).withFeature(LFeature) + CMMatrix(cholesky.l).withAttribute(LowerTriangular) } } - QRDecompositionFeature::class -> object : QRDecompositionFeature { + QRDecompositionAttribute::class -> object : QRDecompositionAttribute { private val qr by lazy { QRDecomposition(origin) } - override val q: Matrix by lazy> { CMMatrix(qr.q).withFeature(OrthogonalFeature) } - override val r: Matrix by lazy> { CMMatrix(qr.r).withFeature(UFeature) } + override val q: Matrix by lazy> { CMMatrix(qr.q).withAttribute(OrthogonalAttribute) } + override val r: Matrix by lazy> { CMMatrix(qr.r).withAttribute(UpperTriangular) } } - SingularValueDecompositionFeature::class -> object : SingularValueDecompositionFeature { + SingularValueDecompositionAttribute::class -> object : SingularValueDecompositionAttribute { private val sv by lazy { SingularValueDecomposition(origin) } 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 { DoubleBuffer(sv.singularValues) } } + else -> null }?.let(type::cast) } diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/DSAlgebra.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/DSAlgebra.kt index 8c7cb0cf1..28546ab98 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/DSAlgebra.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/DSAlgebra.kt @@ -13,6 +13,8 @@ import space.kscience.kmath.structures.MutableBufferFactory import space.kscience.kmath.structures.asBuffer import kotlin.math.max import kotlin.math.min +import kotlin.reflect.KType +import kotlin.reflect.typeOf /** * Class representing both the value and the differentials of a function. diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/BufferedLinearSpace.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/BufferedLinearSpace.kt index 4bba47a91..6bfe7581b 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/BufferedLinearSpace.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/BufferedLinearSpace.kt @@ -5,12 +5,15 @@ package space.kscience.kmath.linear +import space.kscience.attributes.SafeType import space.kscience.kmath.PerformancePitfall import space.kscience.kmath.nd.* import space.kscience.kmath.operations.* import space.kscience.kmath.structures.Buffer import space.kscience.kmath.structures.VirtualBuffer import space.kscience.kmath.structures.indices +import kotlin.reflect.KType +import kotlin.reflect.typeOf public class BufferedLinearSpace>( diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/DoubleLinearSpace.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/DoubleLinearSpace.kt index 940af4a86..226ededce 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/DoubleLinearSpace.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/DoubleLinearSpace.kt @@ -12,6 +12,8 @@ import space.kscience.kmath.operations.DoubleField import space.kscience.kmath.operations.invoke import space.kscience.kmath.structures.Buffer import space.kscience.kmath.structures.DoubleBuffer +import kotlin.reflect.KType +import kotlin.reflect.typeOf public object DoubleLinearSpace : LinearSpace { @@ -20,7 +22,7 @@ public object DoubleLinearSpace : LinearSpace { override fun buildMatrix( rows: Int, columns: Int, - initializer: DoubleField.(i: Int, j: Int) -> Double + initializer: DoubleField.(i: Int, j: Int) -> Double, ): Matrix = DoubleFieldOpsND.structureND(ShapeND(rows, columns)) { (i, j) -> DoubleField.initializer(i, j) }.as2D() 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 a82bafe57..b83316e84 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,16 +5,15 @@ package space.kscience.kmath.linear +import space.kscience.attributes.SafeType import space.kscience.kmath.UnstableKMathAPI -import space.kscience.kmath.nd.MutableStructure2D -import space.kscience.kmath.nd.Structure2D -import space.kscience.kmath.nd.StructureFeature -import space.kscience.kmath.nd.as1D +import space.kscience.kmath.nd.* import space.kscience.kmath.operations.BufferRingOps import space.kscience.kmath.operations.Ring import space.kscience.kmath.operations.invoke import space.kscience.kmath.structures.Buffer -import kotlin.reflect.KClass +import kotlin.reflect.KType +import kotlin.reflect.typeOf /** * Alias for [Structure2D] with more familiar name. @@ -31,13 +30,19 @@ public typealias MutableMatrix = MutableStructure2D */ public typealias Point = Buffer +/** + * A marker interface for algebras that operate on matrices + * @param T type of matrix element + */ +public interface MatrixOperations + /** * Basic operations on matrices and vectors. * * @param T the type of items in the matrices. * @param A the type of ring over [T]. */ -public interface LinearSpace> { +public interface LinearSpace> : MatrixOperations { public val elementAlgebra: A /** @@ -167,16 +172,16 @@ public interface LinearSpace> { public operator fun T.times(v: Point): Point = v * this /** - * Compute a feature of the structure in this scope. Structure features take precedence other context features. + * Get an attribute value for the structure in this scope. Structure features take precedence other context features. * - * @param F the type of feature. + * @param A the type of feature. * @param structure the structure. - * @param type the [KClass] instance of [F]. + * @param attribute to be computed * @return a feature object or `null` if it isn't present. */ @UnstableKMathAPI - public fun computeFeature(structure: Matrix, type: KClass): F? = - structure.getFeature(type) + public fun > attributeFor(structure: StructureND<*>, attribute: A): T? = + structure.attributes[attribute] public companion object { @@ -184,23 +189,12 @@ public interface LinearSpace> { * A structured matrix with custom buffer */ public fun > buffered( - algebra: A + algebra: A, ): LinearSpace = BufferedLinearSpace(BufferRingOps(algebra)) } } -/** - * Get a feature of the structure in this scope. Structure features take precedence other context features. - * - * @param T the type of items in the matrices. - * @param F the type of feature. - * @return a feature object or `null` if it isn't present. - */ -@UnstableKMathAPI -public inline fun LinearSpace.computeFeature(structure: Matrix): F? = - computeFeature(structure, F::class) - public inline operator fun , R> LS.invoke(block: LS.() -> R): R = run(block) 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 650e7be5c..c44564231 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 @@ -3,67 +3,92 @@ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ +@file:Suppress("UnusedReceiverParameter") + package space.kscience.kmath.linear +import space.kscience.attributes.PolymorphicAttribute +import space.kscience.attributes.SafeType +import space.kscience.attributes.safeTypeOf import space.kscience.kmath.UnstableKMathAPI 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.* /** - * Common implementation of [LupDecompositionFeature]. + * Matrices with this feature support LU factorization with partial pivoting: *[p] · a = [l] · [u]* where + * *a* is the owning matrix. + * + * @param T the type of matrices' items. + * @param l The lower triangular matrix in this decomposition. It may have [LowerTriangular]. + * @param u The upper triangular matrix in this decomposition. It may have [UpperTriangular]. + * @param p he permutation matrix in this decomposition. May have [Determinant] attribute */ -public class LupDecomposition( - public val context: LinearSpace, - public val elementContext: Field, - public val lu: Matrix, - public val pivot: IntArray, - private val even: Boolean, -) : LupDecompositionFeature, DeterminantFeature { - /** - * Returns the matrix L of the decomposition. - * - * L is a lower-triangular matrix with [Ring.one] in diagonal - */ - override val l: Matrix = VirtualMatrix(lu.shape[0], lu.shape[1]) { i, j -> - when { - j < i -> lu[i, j] - j == i -> elementContext.one - else -> elementContext.zero - } - }.withFeature(LFeature) +public data class LupDecomposition( + public val l: Matrix, + public val u: Matrix, + public val p: Matrix, +) - /** - * Returns the matrix U of the decomposition. - * - * U is an upper-triangular matrix including the diagonal - */ - override val u: Matrix = VirtualMatrix(lu.shape[0], lu.shape[1]) { i, j -> - if (j >= i) lu[i, j] else elementContext.zero - }.withFeature(UFeature) +public class LupDecompositionAttribute(type: SafeType>) : + PolymorphicAttribute>(type), + MatrixAttribute> - /** - * Returns the P rows permutation matrix. - * - * P is a sparse matrix with exactly one element set to [Ring.one] in - * each row and each column, all other elements being set to [Ring.zero]. - */ - override val p: Matrix = VirtualMatrix(lu.shape[0], lu.shape[1]) { i, j -> - if (j == pivot[i]) elementContext.one else elementContext.zero - } +public val MatrixOperations.LUP: LupDecompositionAttribute + get() = LupDecompositionAttribute(safeTypeOf()) - /** - * Return the determinant of the matrix - * @return determinant of the matrix - */ - override val determinant: T by lazy { - elementContext { (0 until lu.shape[0]).fold(if (even) one else -one) { value, i -> value * lu[i, i] } } - } -} +///** +// * Common implementation of [LupDecomposition]. +// */ +//private class LupDecompositionImpl( +// public val elementContext: Field, +// public val lu: Matrix, +// public val pivot: IntBuffer, +// private val even: Boolean, +//) : LupDecomposition { +// /** +// * Returns the matrix L of the decomposition. +// * +// * L is a lower-triangular matrix with [Ring.one] in diagonal +// */ +// override val l: Matrix = VirtualMatrix(lu.shape[0], lu.shape[1]) { i, j -> +// when { +// j < i -> lu[i, j] +// j == i -> elementContext.one +// else -> elementContext.zero +// } +// }.withFeature(LowerTriangular) +// +// +// /** +// * Returns the matrix U of the decomposition. +// * +// * U is an upper-triangular matrix including the diagonal +// */ +// override val u: Matrix = VirtualMatrix(lu.shape[0], lu.shape[1]) { i, j -> +// if (j >= i) lu[i, j] else elementContext.zero +// }.withFeature(UpperTriangular) +// +// /** +// * Returns the P rows permutation matrix. +// * +// * P is a sparse matrix with exactly one element set to [Ring.one] in +// * each row and each column, all other elements being set to [Ring.zero]. +// */ +// override val p: Matrix = VirtualMatrix(lu.shape[0], lu.shape[1]) { i, j -> +// if (j == pivot[i]) elementContext.one else elementContext.zero +// } +// +// /** +// * Return the determinant of the matrix +// * @return determinant of the matrix +// */ +// override val determinant: T by lazy { +// elementContext { (0 until lu.shape[0]).fold(if(even) one else -one) { value, i -> value * lu[i, i] } } +// } +// +//} @PublishedApi internal fun > LinearSpace>.abs(value: T): T = @@ -73,7 +98,6 @@ internal fun > LinearSpace>.abs(value: T): T = * Create a lup decomposition of generic matrix. */ public fun > LinearSpace>.lup( - factory: MutableBufferFactory, matrix: Matrix, checkSingular: (T) -> Boolean, ): LupDecomposition { @@ -82,15 +106,15 @@ public fun > LinearSpace>.lup( val pivot = IntArray(matrix.rowNum) //TODO just waits for multi-receivers - BufferAccessor2D(matrix.rowNum, matrix.colNum, factory).run { + BufferAccessor2D(matrix.rowNum, matrix.colNum, elementAlgebra.bufferFactory).run { elementAlgebra { val lu = create(matrix) - // Initialize permutation array and parity + // Initialize the permutation array and parity for (row in 0 until m) pivot[row] = row var even = true - // Initialize permutation array and parity + // Initialize the permutation array and parity for (row in 0 until m) pivot[row] = row // Loop over columns @@ -145,46 +169,57 @@ public fun > LinearSpace>.lup( for (row in col + 1 until m) lu[row, col] /= luDiag } - return LupDecomposition(this@lup, elementAlgebra, lu.collect(), pivot, even) + val l: MatrixWrapper = VirtualMatrix(rowNum, colNum) { i, j -> + when { + j < i -> lu[i, j] + j == i -> one + else -> zero + } + }.withAttribute(LowerTriangular) + + val u = VirtualMatrix(rowNum, colNum) { i, j -> + if (j >= i) lu[i, j] else zero + }.withAttribute(UpperTriangular) + + val p = VirtualMatrix(rowNum, colNum) { i, j -> + if (j == pivot[i]) one else zero + }.withAttribute(Determinant, if (even) one else -one) + + return LupDecomposition(l, u, p) } } } -public inline fun > LinearSpace>.lup( - matrix: Matrix, - noinline checkSingular: (T) -> Boolean, -): LupDecomposition = lup(MutableBuffer.Companion::auto, matrix, checkSingular) public fun LinearSpace.lup( matrix: Matrix, singularityThreshold: Double = 1e-11, -): LupDecomposition = - lup(::DoubleBuffer, matrix) { it < singularityThreshold } +): LupDecomposition = lup(matrix) { it < singularityThreshold } -internal fun LupDecomposition.solve( - factory: MutableBufferFactory, +internal fun > LinearSpace.solve( + lup: LupDecomposition, matrix: Matrix, ): Matrix { - require(matrix.rowNum == pivot.size) { "Matrix dimension mismatch. Expected ${pivot.size}, but got ${matrix.colNum}" } + require(matrix.rowNum == lup.l.rowNum) { "Matrix dimension mismatch. Expected ${lup.l.rowNum}, but got ${matrix.colNum}" } - BufferAccessor2D(matrix.rowNum, matrix.colNum, factory).run { - elementContext { + BufferAccessor2D(matrix.rowNum, matrix.colNum, elementAlgebra.bufferFactory).run { + elementAlgebra { // Apply permutations to b val bp = create { _, _ -> zero } - for (row in pivot.indices) { + for (row in 0 until rowNum) { val bpRow = bp.row(row) val pRow = pivot[row] for (col in 0 until matrix.colNum) bpRow[col] = matrix[pRow, col] } // Solve LY = b - for (col in pivot.indices) { + for (col in 0 until colNum) { val bpCol = bp.row(col) - for (i in col + 1 until pivot.size) { + for (i in col + 1 until colNum) { val bpI = bp.row(i) - val luICol = lu[i, col] + val luICol = lup.l[i, col] for (j in 0 until matrix.colNum) { bpI[j] -= bpCol[j] * luICol } @@ -192,19 +227,19 @@ internal fun LupDecomposition.solve( } // Solve UX = Y - for (col in pivot.size - 1 downTo 0) { + for (col in colNum - 1 downTo 0) { val bpCol = bp.row(col) - val luDiag = lu[col, col] + val luDiag = lup.u[col, col] for (j in 0 until matrix.colNum) bpCol[j] /= luDiag for (i in 0 until col) { val bpI = bp.row(i) - val luICol = lu[i, col] + val luICol = lup.u[i, col] for (j in 0 until matrix.colNum) bpI[j] -= bpCol[j] * luICol } } - return context.buildMatrix(pivot.size, matrix.colNum) { i, j -> bp[i, j] } + return buildMatrix(matrix.rowNum, matrix.colNum) { i, j -> bp[i, j] } } } } @@ -214,17 +249,16 @@ internal fun LupDecomposition.solve( */ @OptIn(UnstableKMathAPI::class) public fun , F : Field> LinearSpace.lupSolver( - bufferFactory: MutableBufferFactory, singularityCheck: (T) -> Boolean, ): LinearSolver = object : LinearSolver { override fun solve(a: Matrix, b: Matrix): Matrix { // Use existing decomposition if it is provided by matrix - val decomposition = computeFeature(a) ?: lup(bufferFactory, a, singularityCheck) - return decomposition.solve(bufferFactory, b) + val decomposition = attributeFor(a, LUP) ?: lup(a, singularityCheck) + return solve(decomposition, b) } override fun inverse(matrix: Matrix): Matrix = solve(matrix, one(matrix.rowNum, matrix.colNum)) } public fun LinearSpace.lupSolver(singularityThreshold: Double = 1e-11): LinearSolver = - lupSolver(::DoubleBuffer) { it < singularityThreshold } + lupSolver { it < singularityThreshold } diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixBuilder.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixBuilder.kt index 4d2f01e68..7b6c36dfc 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixBuilder.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixBuilder.kt @@ -5,6 +5,7 @@ package space.kscience.kmath.linear +import space.kscience.attributes.FlagAttribute import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.operations.Ring import space.kscience.kmath.structures.BufferAccessor2D @@ -49,10 +50,10 @@ public inline fun LinearSpace>.column( public fun LinearSpace>.column(vararg values: T): Matrix = column(values.size, values::get) -public object SymmetricMatrixFeature : MatrixFeature +public object Symmetric : MatrixAttribute, FlagAttribute /** - * Naive implementation of a symmetric matrix builder, that adds a [SymmetricMatrixFeature] tag. The resulting matrix contains + * Naive implementation of a symmetric matrix builder, that adds a [Symmetric] tag. The resulting matrix contains * full `size^2` number of elements, but caches elements during calls to save [builder] calls. [builder] is always called in the * upper triangle region meaning that `i <= j` */ @@ -72,6 +73,6 @@ public fun > MatrixBuilder.symmetric( } else { cached } - }.withFeature(SymmetricMatrixFeature) + }.withAttribute(Symmetric) } } \ No newline at end of file diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixFeatures.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixFeatures.kt index 62325b39d..b494625c7 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixFeatures.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixFeatures.kt @@ -3,20 +3,27 @@ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ +@file:OptIn(UnstableKMathAPI::class) +@file:Suppress("UnusedReceiverParameter") + package space.kscience.kmath.linear -import space.kscience.attributes.Attribute +import space.kscience.attributes.* +import space.kscience.kmath.UnstableKMathAPI +import space.kscience.kmath.nd.StructureAttribute +import kotlin.reflect.KType +import kotlin.reflect.typeOf /** * A marker interface representing some properties of matrices or additional transformations of them. Features are used * to optimize matrix operations performance in some cases or retrieve the APIs. */ -public interface MatrixFeature : Attribute +public interface MatrixAttribute : StructureAttribute /** * Matrices with this feature are considered to have only diagonal non-zero elements. */ -public interface IsDiagonal : MatrixFeature { +public interface IsDiagonal : MatrixAttribute, FlagAttribute { public companion object : IsDiagonal } @@ -31,130 +38,110 @@ public object IsZero : IsDiagonal public object IsUnit : IsDiagonal /** - * Matrices with this feature can be inverted: *[inverse] = a−1* where *a* is the owning matrix. + * Matrices with this feature can be inverted. * * @param T the type of matrices' items. */ -public class Inverted private constructor() : MatrixFeature> { - internal val instance: Inverted = Inverted() -} +public class Inverted(type: SafeType>) : + PolymorphicAttribute>(type), + MatrixAttribute> -@Suppress("UNCHECKED_CAST") -public val LinearSpace.Inverted: Inverted get() = Inverted.instance as Inverted +public val MatrixOperations.Inverted: Inverted get() = Inverted(safeTypeOf()) /** * Matrices with this feature can compute their determinant. * * @param T the type of matrices' items. */ -public class DeterminantFeature : MatrixFeature +public class Determinant(type: SafeType) : + PolymorphicAttribute(type), + MatrixAttribute -/** - * Produces a [DeterminantFeature] where the [DeterminantFeature.determinant] is [determinant]. - * - * @param determinant the value of determinant. - * @return a new [DeterminantFeature]. - */ -@Suppress("FunctionName") -public fun DeterminantFeature(determinant: T): DeterminantFeature = object : DeterminantFeature { - override val determinant: T = determinant -} +public inline val MatrixOperations.Determinant: Determinant get() = Determinant(safeTypeOf()) /** * Matrices with this feature are lower triangular ones. */ -public object LFeature : MatrixFeature +public object LowerTriangular : MatrixAttribute, FlagAttribute /** * Matrices with this feature are upper triangular ones. */ -public object UFeature : MatrixFeature +public object UpperTriangular : MatrixAttribute, FlagAttribute + +/** + * Matrices with this feature support LU factorization: *a = [l] · [u]* where *a* is the owning matrix. + * @param l The lower triangular matrix in this decomposition. It may have [LowerTriangular]. + * @param u The upper triangular matrix in this decomposition. It may have [UpperTriangular]. + */ +public data class LUDecomposition(val l: Matrix, val u: Matrix) /** * Matrices with this feature support LU factorization: *a = [l] · [u]* where *a* is the owning matrix. * * @param T the type of matrices' items. */ -public interface LUDecompositionFeature : MatrixFeature { - /** - * The lower triangular matrix in this decomposition. It may have [LFeature]. - */ - public val l: Matrix +public class LuDecompositionAttribute(type: SafeType>) : + PolymorphicAttribute>(type), + MatrixAttribute> - /** - * The upper triangular matrix in this decomposition. It may have [UFeature]. - */ - public val u: Matrix -} +public val MatrixOperations.LU: LuDecompositionAttribute get() = LuDecompositionAttribute(safeTypeOf()) -/** - * Matrices with this feature support LU factorization with partial pivoting: *[p] · a = [l] · [u]* where - * *a* is the owning matrix. - * - * @param T the type of matrices' items. - */ -public interface LupDecompositionFeature : MatrixFeature { - /** - * The lower triangular matrix in this decomposition. It may have [LFeature]. - */ - public val l: Matrix - - /** - * The upper triangular matrix in this decomposition. It may have [UFeature]. - */ - public val u: Matrix - - /** - * The permutation matrix in this decomposition. - */ - public val p: Matrix -} /** * Matrices with this feature are orthogonal ones: *a · aT = u* where *a* is the owning matrix, *u* * is the unit matrix ([IsUnit]). */ -public object OrthogonalFeature : MatrixFeature +public object OrthogonalAttribute : MatrixAttribute, FlagAttribute -/** - * Matrices with this feature support QR factorization: *a = [q] · [r]* where *a* is the owning matrix. - * - * @param T the type of matrices' items. - */ -public interface QRDecompositionFeature : MatrixFeature { + +public interface QRDecomposition { /** - * The orthogonal matrix in this decomposition. It may have [OrthogonalFeature]. + * The orthogonal matrix in this decomposition. It may have [OrthogonalAttribute]. */ public val q: Matrix /** - * The upper triangular matrix in this decomposition. It may have [UFeature]. + * The upper triangular matrix in this decomposition. It may have [UpperTriangular]. */ public val r: Matrix } +/** + * Matrices with this feature support QR factorization: *a = [QR.q] · [QR.r]* where *a* is the owning matrix. + * + * @param T the type of matrices' items. + */ +public class QRDecompositionAttribute(type: SafeType>) : + PolymorphicAttribute>(type), + MatrixAttribute> + +public val MatrixOperations.QR: QRDecompositionAttribute + get() = QRDecompositionAttribute(safeTypeOf()) + +public interface CholeskyDecomposition { + /** + * The triangular matrix in this decomposition. It may have either [UpperTriangular] or [LowerTriangular]. + */ + public val l: Matrix +} + /** * Matrices with this feature support Cholesky factorization: *a = [l] · [l]H* where *a* is the * owning matrix. * * @param T the type of matrices' items. */ -public interface CholeskyDecompositionFeature : MatrixFeature { - /** - * The triangular matrix in this decomposition. It may have either [UFeature] or [LFeature]. - */ - public val l: Matrix -} +public class CholeskyDecompositionAttribute(type: SafeType>) : + PolymorphicAttribute>(type), + MatrixAttribute> -/** - * Matrices with this feature support SVD: *a = [u] · [s] · [v]H* where *a* is the owning - * matrix. - * - * @param T the type of matrices' items. - */ -public interface SingularValueDecompositionFeature : MatrixFeature { +public val MatrixOperations.Cholesky: CholeskyDecompositionAttribute + get() = CholeskyDecompositionAttribute(safeTypeOf()) + +public interface SingularValueDecomposition { /** - * The matrix in this decomposition. It is unitary, and it consists from left singular vectors. + * The matrix in this decomposition. It is unitary, and it consists of left singular vectors. */ public val u: Matrix @@ -164,14 +151,27 @@ public interface SingularValueDecompositionFeature : MatrixFeature public val s: Matrix /** - * The matrix in this decomposition. It is unitary, and it consists from right singular vectors. + * The matrix in this decomposition. It is unitary, and it consists of right singular vectors. */ public val v: Matrix /** - * The buffer of singular values of this SVD. + * The buffer of singular values for this SVD. */ public val singularValues: Point } +/** + * Matrices with this feature support SVD: *a = [u] · [s] · [v]H* where *a* is the owning + * matrix. + * + * @param T the type of matrices' items. + */ +public class SingularValueDecompositionAttribute(type: SafeType>) : + PolymorphicAttribute>(type), + MatrixAttribute> + +public val MatrixOperations.SVD: SingularValueDecompositionAttribute + get() = SingularValueDecompositionAttribute(safeTypeOf()) + //TODO add sparse matrix feature diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixWrapper.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixWrapper.kt index b510cc697..0f0c9ce3f 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixWrapper.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixWrapper.kt @@ -5,19 +5,20 @@ package space.kscience.kmath.linear +import space.kscience.attributes.Attribute import space.kscience.attributes.Attributes +import space.kscience.attributes.withAttribute import space.kscience.kmath.UnstableKMathAPI -import space.kscience.kmath.misc.FeatureSet import space.kscience.kmath.operations.Ring /** - * A [Matrix] that holds [MatrixFeature] objects. + * A [Matrix] that holds [MatrixAttribute] objects. * * @param T the type of items. */ public class MatrixWrapper internal constructor( public val origin: Matrix, - public val attributes: Attributes, + override val attributes: Attributes, ) : Matrix by origin { override fun toString(): String = "MatrixWrapper(matrix=$origin, features=$attributes)" @@ -34,23 +35,31 @@ public val Matrix.origin: Matrix /** * Add a single feature to a [Matrix] */ -public fun Matrix.withFeature(newFeature: MatrixFeature): MatrixWrapper = if (this is MatrixWrapper) { - MatrixWrapper(origin, attributes.with(newFeature)) +public fun > Matrix.withAttribute( + attribute: A, + attrValue: T, +): MatrixWrapper = if (this is MatrixWrapper) { + MatrixWrapper(origin, attributes.withAttribute(attribute,attrValue)) } else { - MatrixWrapper(this, FeatureSet.of(newFeature)) + MatrixWrapper(this, Attributes(attribute, attrValue)) } -@Deprecated("To be replaced by withFeature") -public operator fun Matrix.plus(newFeature: MatrixFeature): MatrixWrapper = withFeature(newFeature) +public fun > Matrix.withAttribute( + attribute: A, +): MatrixWrapper = if (this is MatrixWrapper) { + MatrixWrapper(origin, attributes.withAttribute(attribute)) +} else { + MatrixWrapper(this, Attributes(attribute, Unit)) +} /** - * Add a collection of features to a [Matrix] + * Modify matrix attributes */ -public fun Matrix.withFeatures(newFeatures: Iterable): MatrixWrapper = +public fun Matrix.modifyAttributes(modifier: (Attributes) -> Attributes): MatrixWrapper = if (this is MatrixWrapper) { - MatrixWrapper(origin, attributes.with(newFeatures)) + MatrixWrapper(origin, modifier(attributes)) } else { - MatrixWrapper(this, FeatureSet.of(newFeatures)) + MatrixWrapper(this, modifier(Attributes.EMPTY)) } /** @@ -59,9 +68,9 @@ public fun Matrix.withFeatures(newFeatures: Iterable public fun LinearSpace>.one( rows: Int, columns: Int, -): Matrix = VirtualMatrix(rows, columns) { i, j -> +): MatrixWrapper = VirtualMatrix(rows, columns) { i, j -> if (i == j) elementAlgebra.one else elementAlgebra.zero -}.withFeature(IsUnit) +}.withAttribute(IsUnit) /** @@ -70,16 +79,16 @@ public fun LinearSpace>.one( public fun LinearSpace>.zero( rows: Int, columns: Int, -): Matrix = VirtualMatrix(rows, columns) { _, _ -> +): MatrixWrapper = VirtualMatrix(rows, columns) { _, _ -> elementAlgebra.zero -}.withFeature(IsZero) +}.withAttribute(IsZero) -public class TransposedFeature(public val original: Matrix) : MatrixFeature +public class TransposedAttribute(public val original: Matrix) : MatrixAttribute /** * Create a virtual transposed matrix without copying anything. `A.transpose().transpose() === A` */ @Suppress("UNCHECKED_CAST") @OptIn(UnstableKMathAPI::class) -public fun Matrix.transpose(): Matrix = getFeature(TransposedFeature::class)?.original as? Matrix - ?: VirtualMatrix(colNum, rowNum) { i, j -> get(j, i) }.withFeature(TransposedFeature(this)) +public fun Matrix.transpose(): Matrix = getFeature(TransposedAttribute::class)?.original as? Matrix + ?: VirtualMatrix(colNum, rowNum) { i, j -> get(j, i) }.withAttribute(TransposedAttribute(this)) diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/VirtualMatrix.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/VirtualMatrix.kt index 55b970f4a..7927e4dba 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/VirtualMatrix.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/VirtualMatrix.kt @@ -5,6 +5,7 @@ package space.kscience.kmath.linear +import space.kscience.attributes.Attributes import space.kscience.kmath.nd.ShapeND @@ -16,6 +17,7 @@ import space.kscience.kmath.nd.ShapeND public class VirtualMatrix( override val rowNum: Int, override val colNum: Int, + override val attributes: Attributes = Attributes.EMPTY, public val generator: (i: Int, j: Int) -> T, ) : Matrix { @@ -24,5 +26,8 @@ public class VirtualMatrix( override operator fun get(i: Int, j: Int): T = generator(i, j) } -public fun MatrixBuilder.virtual(generator: (i: Int, j: Int) -> T): VirtualMatrix = - VirtualMatrix(rows, columns, generator) +public fun MatrixBuilder.virtual( + attributes: Attributes = Attributes.EMPTY, + generator: (i: Int, j: Int) -> T, +): VirtualMatrix = + VirtualMatrix(rows, columns, attributes, generator) diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/AlgebraND.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/AlgebraND.kt index a75807bad..3a9a1833a 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/AlgebraND.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/AlgebraND.kt @@ -79,7 +79,7 @@ public interface AlgebraND> : Algebra> { * @return a feature object or `null` if it isn't present. */ @UnstableKMathAPI - public fun getFeature(structure: StructureND, type: KClass): F? = + public fun getFeature(structure: StructureND, type: KClass): F? = structure.getFeature(type) public companion object @@ -93,7 +93,7 @@ public interface AlgebraND> : Algebra> { * @return a feature object or `null` if it isn't present. */ @UnstableKMathAPI -public inline fun AlgebraND.getFeature(structure: StructureND): F? = +public inline fun AlgebraND.getFeature(structure: StructureND): F? = getFeature(structure, F::class) /** diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/BufferND.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/BufferND.kt index 9217f6fdc..72ecc9ef0 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/BufferND.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/BufferND.kt @@ -34,9 +34,9 @@ public open class BufferND( /** * Create a generic [BufferND] using provided [initializer] */ -public fun BufferND( +public inline fun BufferND( shape: ShapeND, - bufferFactory: BufferFactory = BufferFactory.boxing(), + bufferFactory: BufferFactory = BufferFactory.auto(), initializer: (IntArray) -> T, ): BufferND { val strides = Strides(shape) diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Structure2D.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Structure2D.kt index e006d09eb..931730399 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Structure2D.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Structure2D.kt @@ -110,7 +110,7 @@ private value class Structure2DWrapper(val structure: StructureND) : S @PerformancePitfall override operator fun get(i: Int, j: Int): T = structure[i, j] - override fun getFeature(type: KClass): F? = structure.getFeature(type) + override fun getFeature(type: KClass): F? = structure.getFeature(type) @PerformancePitfall override fun elements(): Sequence> = structure.elements() diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/StructureND.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/StructureND.kt index e9814acbf..724cc6f69 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/StructureND.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/StructureND.kt @@ -7,6 +7,7 @@ package space.kscience.kmath.nd import space.kscience.attributes.Attribute import space.kscience.attributes.AttributeContainer +import space.kscience.attributes.SafeType import space.kscience.kmath.PerformancePitfall import space.kscience.kmath.linear.LinearSpace import space.kscience.kmath.operations.Ring @@ -15,9 +16,8 @@ import space.kscience.kmath.structures.Buffer import space.kscience.kmath.structures.BufferFactory import kotlin.jvm.JvmName import kotlin.math.abs -import kotlin.reflect.KClass -public interface StructureFeature : Attribute +public interface StructureAttribute : Attribute /** * Represents n-dimensional structure i.e., multidimensional container of items of the same type and size. The number @@ -122,9 +122,14 @@ public interface StructureND : AttributeContainer, WithShape { */ public fun buffered( strides: Strides, - bufferFactory: BufferFactory = BufferFactory.boxing(), initializer: (IntArray) -> T, - ): BufferND = BufferND(strides, bufferFactory(strides.linearSize) { i -> initializer(strides.index(i)) }) + ): BufferND = BufferND(strides, Buffer.boxing(strides.linearSize) { i -> initializer(strides.index(i)) }) + + + public fun buffered( + shape: ShapeND, + initializer: (IntArray) -> T, + ): BufferND = buffered(ColumnStrides(shape), initializer) /** * Inline create NDStructure with non-boxing buffer implementation if it is possible @@ -135,16 +140,11 @@ public interface StructureND : AttributeContainer, WithShape { ): BufferND = BufferND(strides, Buffer.auto(strides.linearSize) { i -> initializer(strides.index(i)) }) public inline fun auto( - type: KClass, + type: SafeType, strides: Strides, crossinline initializer: (IntArray) -> T, ): BufferND = BufferND(strides, Buffer.auto(type, strides.linearSize) { i -> initializer(strides.index(i)) }) - public fun buffered( - shape: ShapeND, - bufferFactory: BufferFactory = BufferFactory.boxing(), - initializer: (IntArray) -> T, - ): BufferND = buffered(ColumnStrides(shape), bufferFactory, initializer) public inline fun auto( shape: ShapeND, @@ -159,7 +159,7 @@ public interface StructureND : AttributeContainer, WithShape { auto(ColumnStrides(ShapeND(shape)), initializer) public inline fun auto( - type: KClass, + type: SafeType, vararg shape: Int, crossinline initializer: (IntArray) -> T, ): BufferND = auto(type, ColumnStrides(ShapeND(shape)), initializer) diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/Algebra.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/Algebra.kt index 0960ab023..e590dcc3d 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/Algebra.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/Algebra.kt @@ -9,14 +9,14 @@ import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.expressions.Symbol import space.kscience.kmath.operations.Ring.Companion.optimizedPower import space.kscience.kmath.structures.MutableBufferFactory +import kotlin.reflect.KType /** * Represents an algebraic structure. * - * @param T the type of element of this structure. + * @param T the type of element which Algebra operates on. */ public interface Algebra { - /** * Provide a factory for buffers, associated with this [Algebra] */ @@ -67,12 +67,12 @@ public interface Algebra { * * @param operation the name of operation. * @param arg the argument of operation. - * @return a result of operation. + * @return the result of the operation. */ public fun unaryOperation(operation: String, arg: T): T = unaryOperationFunction(operation)(arg) /** - * Dynamically dispatches a binary operation with the certain name. + * Dynamically dispatches a binary operation with a certain name. * * Implementations must fulfil the following requirements: * @@ -87,7 +87,7 @@ public interface Algebra { error("Binary operation '$operation' not defined in $this") /** - * Dynamically invokes a binary operation with the certain name. + * Dynamically invokes a binary operation with a certain name. * * Implementations must fulfil the following requirements: * diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/BufferAlgebra.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/BufferAlgebra.kt index 26a4b0a53..9047feb29 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/BufferAlgebra.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/BufferAlgebra.kt @@ -8,6 +8,7 @@ package space.kscience.kmath.operations import space.kscience.kmath.structures.Buffer import space.kscience.kmath.structures.MutableBuffer import space.kscience.kmath.structures.MutableBufferFactory +import kotlin.reflect.KType public interface WithSize { public val size: Int @@ -18,6 +19,9 @@ public interface WithSize { */ public interface BufferAlgebra> : Algebra> { public val elementAlgebra: A + + public val elementType: KType + public val elementBufferFactory: MutableBufferFactory get() = elementAlgebra.bufferFactory public fun buffer(size: Int, vararg elements: T): Buffer { 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 cef8d1d4d..d9ee25321 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 @@ -5,10 +5,12 @@ package space.kscience.kmath.structures +import space.kscience.attributes.SafeType +import space.kscience.attributes.safeTypeOf import space.kscience.kmath.operations.WithSize import space.kscience.kmath.operations.asSequence import kotlin.jvm.JvmInline -import kotlin.reflect.KClass +import kotlin.reflect.typeOf /** * Function that produces [Buffer] from its size and function that supplies values. @@ -99,13 +101,13 @@ public interface Buffer : WithSize { * 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.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 - Float::class -> MutableBuffer.float(size) { initializer(it) as Float } as Buffer + public inline fun auto(type: SafeType, size: Int, initializer: (Int) -> T): Buffer = + when (type.kType) { + typeOf() -> MutableBuffer.double(size) { initializer(it) as Double } as Buffer + typeOf() -> MutableBuffer.short(size) { initializer(it) as Short } as Buffer + typeOf() -> MutableBuffer.int(size) { initializer(it) as Int } as Buffer + typeOf() -> MutableBuffer.long(size) { initializer(it) as Long } as Buffer + typeOf() -> MutableBuffer.float(size) { initializer(it) as Float } as Buffer else -> boxing(size, initializer) } @@ -115,8 +117,8 @@ public interface Buffer : WithSize { * * The [size] is specified, and each element is calculated by calling the specified [initializer] function. */ - public inline fun auto(size: Int, initializer: (Int) -> T): Buffer = - auto(T::class, size, initializer) + public inline fun auto(size: Int, initializer: (Int) -> T): Buffer = + auto(safeTypeOf(), size, initializer) } } diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/BufferAccessor2D.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/BufferAccessor2D.kt index 48f3e919b..3edd7d3b1 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/BufferAccessor2D.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/BufferAccessor2D.kt @@ -27,12 +27,9 @@ internal class BufferAccessor2D( fun create(mat: Structure2D): MutableBuffer = create { i, j -> mat[i, j] } //TODO optimize wrapper - fun MutableBuffer.collect(): Structure2D = StructureND.buffered( - ColumnStrides(ShapeND(rowNum, colNum)), - factory - ) { (i, j) -> - get(i, j) - }.as2D() + fun MutableBuffer.toStructure2D(): Structure2D = StructureND.buffered( + ColumnStrides(ShapeND(rowNum, colNum)) + ) { (i, j) -> get(i, j) }.as2D() inner class Row(val buffer: MutableBuffer, val rowIndex: Int) : MutableBuffer { override val size: Int get() = colNum diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/MutableBuffer.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/MutableBuffer.kt index c0bfc6ecc..48b05e412 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/MutableBuffer.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/MutableBuffer.kt @@ -5,7 +5,9 @@ package space.kscience.kmath.structures -import kotlin.reflect.KClass +import space.kscience.attributes.SafeType +import space.kscience.attributes.safeTypeOf +import kotlin.reflect.typeOf /** * A generic mutable random-access structure for both primitives and objects. @@ -74,13 +76,13 @@ public interface MutableBuffer : Buffer { * 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 -> 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 - Long::class -> long(size) { initializer(it) as Long } as MutableBuffer + public inline fun auto(type: SafeType, size: Int, initializer: (Int) -> T): MutableBuffer = + when (type.kType) { + typeOf() -> double(size) { initializer(it) as Double } as MutableBuffer + typeOf() -> short(size) { initializer(it) as Short } as MutableBuffer + typeOf() -> int(size) { initializer(it) as Int } as MutableBuffer + typeOf() -> float(size) { initializer(it) as Float } as MutableBuffer + typeOf() -> long(size) { initializer(it) as Long } as MutableBuffer else -> boxing(size, initializer) } @@ -90,11 +92,10 @@ public interface MutableBuffer : Buffer { * * The [size] is specified, and each element is calculated by calling the specified [initializer] function. */ - @Suppress("UNCHECKED_CAST") - public inline fun auto(size: Int, initializer: (Int) -> T): MutableBuffer = - auto(T::class, size, initializer) + public inline fun auto(size: Int, initializer: (Int) -> T): MutableBuffer = + auto(safeTypeOf(), size, initializer) } } -public sealed interface PrimitiveBuffer: MutableBuffer \ No newline at end of file +public sealed interface PrimitiveBuffer : MutableBuffer \ 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 8925fb045..ec1883128 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 @@ -12,6 +12,8 @@ import space.kscience.kmath.linear.Matrix import space.kscience.kmath.linear.Point import space.kscience.kmath.nd.Structure2D import space.kscience.kmath.operations.Ring +import kotlin.reflect.KType +import kotlin.reflect.typeOf /** * [LinearSpace] implementation specialized for a certain EJML type. @@ -43,5 +45,5 @@ public abstract class EjmlLinearSpace, out M : org.ejml @Suppress("UNCHECKED_CAST") @UnstableKMathAPI public fun EjmlMatrix.inverse(): Structure2D = - computeFeature(this, InverseMatrixFeature::class)?.inverse as Structure2D + attributeFor(this, InverseMatrixFeature::class)?.inverse as Structure2D } diff --git a/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/_generated.kt b/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/_generated.kt deleted file mode 100644 index c56583fa8..000000000 --- a/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/_generated.kt +++ /dev/null @@ -1,1003 +0,0 @@ -/* - * Copyright 2018-2021 KMath contributors. - * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. - */ - -/* This file is generated with buildSrc/src/main/kotlin/space/kscience/kmath/ejml/codegen/ejmlCodegen.kt */ - -package space.kscience.kmath.ejml - -import org.ejml.data.* -import org.ejml.dense.row.CommonOps_DDRM -import org.ejml.dense.row.CommonOps_FDRM -import org.ejml.dense.row.factory.DecompositionFactory_DDRM -import org.ejml.dense.row.factory.DecompositionFactory_FDRM -import org.ejml.sparse.FillReducing -import org.ejml.sparse.csc.CommonOps_DSCC -import org.ejml.sparse.csc.CommonOps_FSCC -import org.ejml.sparse.csc.factory.DecompositionFactory_DSCC -import org.ejml.sparse.csc.factory.DecompositionFactory_FSCC -import org.ejml.sparse.csc.factory.LinearSolverFactory_DSCC -import org.ejml.sparse.csc.factory.LinearSolverFactory_FSCC -import space.kscience.kmath.UnstableKMathAPI -import space.kscience.kmath.linear.* -import space.kscience.kmath.linear.Matrix -import space.kscience.kmath.nd.StructureFeature -import space.kscience.kmath.operations.DoubleField -import space.kscience.kmath.operations.FloatField -import space.kscience.kmath.operations.invoke -import space.kscience.kmath.structures.DoubleBuffer -import space.kscience.kmath.structures.FloatBuffer -import kotlin.reflect.KClass -import kotlin.reflect.cast - -/** - * [EjmlVector] specialization for [Double]. - */ -public class EjmlDoubleVector(override val origin: M) : EjmlVector(origin) { - init { - require(origin.numRows == 1) { "The origin matrix must have only one row to form a vector" } - } - - override operator fun get(index: Int): Double = origin[0, index] -} - -/** - * [EjmlVector] specialization for [Float]. - */ -public class EjmlFloatVector(override val origin: M) : EjmlVector(origin) { - init { - require(origin.numRows == 1) { "The origin matrix must have only one row to form a vector" } - } - - override operator fun get(index: Int): Float = origin[0, index] -} - -/** - * [EjmlMatrix] specialization for [Double]. - */ -public class EjmlDoubleMatrix(override val origin: M) : EjmlMatrix(origin) { - override operator fun get(i: Int, j: Int): Double = origin[i, j] -} - -/** - * [EjmlMatrix] specialization for [Float]. - */ -public class EjmlFloatMatrix(override val origin: M) : EjmlMatrix(origin) { - override operator fun get(i: Int, j: Int): Float = origin[i, j] -} - -/** - * [EjmlLinearSpace] implementation based on [CommonOps_DDRM], [DecompositionFactory_DDRM] operations and - * [DMatrixRMaj] matrices. - */ -public object EjmlLinearSpaceDDRM : EjmlLinearSpace() { - /** - * The [DoubleField] reference. - */ - override val elementAlgebra: DoubleField get() = DoubleField - - @Suppress("UNCHECKED_CAST") - override fun Matrix.toEjml(): EjmlDoubleMatrix = when { - this is EjmlDoubleMatrix<*> && origin is DMatrixRMaj -> this as EjmlDoubleMatrix - else -> buildMatrix(rowNum, colNum) { i, j -> get(i, j) } - } - - @Suppress("UNCHECKED_CAST") - override fun Point.toEjml(): EjmlDoubleVector = when { - this is EjmlDoubleVector<*> && origin is DMatrixRMaj -> this as EjmlDoubleVector - else -> EjmlDoubleVector(DMatrixRMaj(size, 1).also { - (0 until it.numRows).forEach { row -> it[row, 0] = get(row) } - }) - } - - override fun buildMatrix( - rows: Int, - columns: Int, - initializer: DoubleField.(i: Int, j: Int) -> Double, - ): EjmlDoubleMatrix = DMatrixRMaj(rows, columns).also { - (0 until rows).forEach { row -> - (0 until columns).forEach { col -> it[row, col] = elementAlgebra.initializer(row, col) } - } - }.wrapMatrix() - - override fun buildVector( - size: Int, - initializer: DoubleField.(Int) -> Double, - ): EjmlDoubleVector = EjmlDoubleVector(DMatrixRMaj(size, 1).also { - (0 until it.numRows).forEach { row -> it[row, 0] = elementAlgebra.initializer(row) } - }) - - private fun T.wrapMatrix() = EjmlDoubleMatrix(this) - private fun T.wrapVector() = EjmlDoubleVector(this) - - override fun Matrix.unaryMinus(): Matrix = this * elementAlgebra { -one } - - override fun Matrix.dot(other: Matrix): EjmlDoubleMatrix { - val out = DMatrixRMaj(1, 1) - CommonOps_DDRM.mult(toEjml().origin, other.toEjml().origin, out) - return out.wrapMatrix() - } - - override fun Matrix.dot(vector: Point): EjmlDoubleVector { - val out = DMatrixRMaj(1, 1) - CommonOps_DDRM.mult(toEjml().origin, vector.toEjml().origin, out) - return out.wrapVector() - } - - override operator fun Matrix.minus(other: Matrix): EjmlDoubleMatrix { - val out = DMatrixRMaj(1, 1) - - CommonOps_DDRM.add( - elementAlgebra.one, - toEjml().origin, - elementAlgebra { -one }, - other.toEjml().origin, - out, - ) - - return out.wrapMatrix() - } - - override operator fun Matrix.times(value: Double): EjmlDoubleMatrix { - val res = DMatrixRMaj(1, 1) - CommonOps_DDRM.scale(value, toEjml().origin, res) - return res.wrapMatrix() - } - - override fun Point.unaryMinus(): EjmlDoubleVector { - val res = DMatrixRMaj(1, 1) - CommonOps_DDRM.changeSign(toEjml().origin, res) - return res.wrapVector() - } - - override fun Matrix.plus(other: Matrix): EjmlDoubleMatrix { - val out = DMatrixRMaj(1, 1) - - CommonOps_DDRM.add( - elementAlgebra.one, - toEjml().origin, - elementAlgebra.one, - other.toEjml().origin, - out, - ) - - return out.wrapMatrix() - } - - override fun Point.plus(other: Point): EjmlDoubleVector { - val out = DMatrixRMaj(1, 1) - - CommonOps_DDRM.add( - elementAlgebra.one, - toEjml().origin, - elementAlgebra.one, - other.toEjml().origin, - out, - ) - - return out.wrapVector() - } - - override fun Point.minus(other: Point): EjmlDoubleVector { - val out = DMatrixRMaj(1, 1) - - CommonOps_DDRM.add( - elementAlgebra.one, - toEjml().origin, - elementAlgebra { -one }, - other.toEjml().origin, - out, - ) - - return out.wrapVector() - } - - override fun Double.times(m: Matrix): EjmlDoubleMatrix = m * this - - override fun Point.times(value: Double): EjmlDoubleVector { - val res = DMatrixRMaj(1, 1) - CommonOps_DDRM.scale(value, toEjml().origin, res) - return res.wrapVector() - } - - override fun Double.times(v: Point): EjmlDoubleVector = v * this - - @UnstableKMathAPI - override fun computeFeature(structure: Matrix, type: KClass): F? { - structure.getFeature(type)?.let { return it } - val origin = structure.toEjml().origin - - return when (type) { - InverseMatrixFeature::class -> object : InverseMatrixFeature { - override val inverse: Matrix by lazy { - val res = origin.copy() - CommonOps_DDRM.invert(res) - res.wrapMatrix() - } - } - - DeterminantFeature::class -> object : DeterminantFeature { - override val determinant: Double by lazy { CommonOps_DDRM.det(origin) } - } - - SingularValueDecompositionFeature::class -> object : SingularValueDecompositionFeature { - private val svd by lazy { - DecompositionFactory_DDRM.svd(origin.numRows, origin.numCols, true, true, false) - .apply { decompose(origin.copy()) } - } - - override val u: Matrix by lazy { svd.getU(null, false).wrapMatrix() } - override val s: Matrix by lazy { svd.getW(null).wrapMatrix() } - override val v: Matrix by lazy { svd.getV(null, false).wrapMatrix() } - override val singularValues: Point by lazy { DoubleBuffer(svd.singularValues) } - } - - QRDecompositionFeature::class -> object : QRDecompositionFeature { - private val qr by lazy { - DecompositionFactory_DDRM.qr().apply { decompose(origin.copy()) } - } - - override val q: Matrix by lazy { - qr.getQ(null, false).wrapMatrix().withFeature(OrthogonalFeature) - } - - override val r: Matrix by lazy { qr.getR(null, false).wrapMatrix().withFeature(UFeature) } - } - - CholeskyDecompositionFeature::class -> object : CholeskyDecompositionFeature { - override val l: Matrix by lazy { - val cholesky = - DecompositionFactory_DDRM.chol(structure.rowNum, true).apply { decompose(origin.copy()) } - - cholesky.getT(null).wrapMatrix().withFeature(LFeature) - } - } - - LupDecompositionFeature::class -> object : LupDecompositionFeature { - private val lup by lazy { - DecompositionFactory_DDRM.lu(origin.numRows, origin.numCols).apply { decompose(origin.copy()) } - } - - override val l: Matrix by lazy { - lup.getLower(null).wrapMatrix().withFeature(LFeature) - } - - override val u: Matrix by lazy { - lup.getUpper(null).wrapMatrix().withFeature(UFeature) - } - - override val p: Matrix by lazy { lup.getRowPivot(null).wrapMatrix() } - } - - else -> null - }?.let{ - type.cast(it) - } - } - - /** - * Solves for *x* in the following equation: *x = [a] -1 · [b]*. - * - * @param a the base matrix. - * @param b n by p matrix. - * @return the solution for *x* that is n by p. - */ - public fun solve(a: Matrix, b: Matrix): EjmlDoubleMatrix { - val res = DMatrixRMaj(1, 1) - CommonOps_DDRM.solve(DMatrixRMaj(a.toEjml().origin), DMatrixRMaj(b.toEjml().origin), res) - return res.wrapMatrix() - } - - /** - * Solves for *x* in the following equation: *x = [a] -1 · [b]*. - * - * @param a the base matrix. - * @param b n by p vector. - * @return the solution for *x* that is n by p. - */ - public fun solve(a: Matrix, b: Point): EjmlDoubleVector { - val res = DMatrixRMaj(1, 1) - CommonOps_DDRM.solve(DMatrixRMaj(a.toEjml().origin), DMatrixRMaj(b.toEjml().origin), res) - return EjmlDoubleVector(res) - } -} - -/** - * [EjmlLinearSpace] implementation based on [CommonOps_FDRM], [DecompositionFactory_FDRM] operations and - * [FMatrixRMaj] matrices. - */ -public object EjmlLinearSpaceFDRM : EjmlLinearSpace() { - /** - * The [FloatField] reference. - */ - override val elementAlgebra: FloatField get() = FloatField - - @Suppress("UNCHECKED_CAST") - override fun Matrix.toEjml(): EjmlFloatMatrix = when { - this is EjmlFloatMatrix<*> && origin is FMatrixRMaj -> this as EjmlFloatMatrix - else -> buildMatrix(rowNum, colNum) { i, j -> get(i, j) } - } - - @Suppress("UNCHECKED_CAST") - override fun Point.toEjml(): EjmlFloatVector = when { - this is EjmlFloatVector<*> && origin is FMatrixRMaj -> this as EjmlFloatVector - else -> EjmlFloatVector(FMatrixRMaj(size, 1).also { - (0 until it.numRows).forEach { row -> it[row, 0] = get(row) } - }) - } - - override fun buildMatrix( - rows: Int, - columns: Int, - initializer: FloatField.(i: Int, j: Int) -> Float, - ): EjmlFloatMatrix = FMatrixRMaj(rows, columns).also { - (0 until rows).forEach { row -> - (0 until columns).forEach { col -> it[row, col] = elementAlgebra.initializer(row, col) } - } - }.wrapMatrix() - - override fun buildVector( - size: Int, - initializer: FloatField.(Int) -> Float, - ): EjmlFloatVector = EjmlFloatVector(FMatrixRMaj(size, 1).also { - (0 until it.numRows).forEach { row -> it[row, 0] = elementAlgebra.initializer(row) } - }) - - private fun T.wrapMatrix() = EjmlFloatMatrix(this) - private fun T.wrapVector() = EjmlFloatVector(this) - - override fun Matrix.unaryMinus(): Matrix = this * elementAlgebra { -one } - - override fun Matrix.dot(other: Matrix): EjmlFloatMatrix { - val out = FMatrixRMaj(1, 1) - CommonOps_FDRM.mult(toEjml().origin, other.toEjml().origin, out) - return out.wrapMatrix() - } - - override fun Matrix.dot(vector: Point): EjmlFloatVector { - val out = FMatrixRMaj(1, 1) - CommonOps_FDRM.mult(toEjml().origin, vector.toEjml().origin, out) - return out.wrapVector() - } - - override operator fun Matrix.minus(other: Matrix): EjmlFloatMatrix { - val out = FMatrixRMaj(1, 1) - - CommonOps_FDRM.add( - elementAlgebra.one, - toEjml().origin, - elementAlgebra { -one }, - other.toEjml().origin, - out, - ) - - return out.wrapMatrix() - } - - override operator fun Matrix.times(value: Float): EjmlFloatMatrix { - val res = FMatrixRMaj(1, 1) - CommonOps_FDRM.scale(value, toEjml().origin, res) - return res.wrapMatrix() - } - - override fun Point.unaryMinus(): EjmlFloatVector { - val res = FMatrixRMaj(1, 1) - CommonOps_FDRM.changeSign(toEjml().origin, res) - return res.wrapVector() - } - - override fun Matrix.plus(other: Matrix): EjmlFloatMatrix { - val out = FMatrixRMaj(1, 1) - - CommonOps_FDRM.add( - elementAlgebra.one, - toEjml().origin, - elementAlgebra.one, - other.toEjml().origin, - out, - ) - - return out.wrapMatrix() - } - - override fun Point.plus(other: Point): EjmlFloatVector { - val out = FMatrixRMaj(1, 1) - - CommonOps_FDRM.add( - elementAlgebra.one, - toEjml().origin, - elementAlgebra.one, - other.toEjml().origin, - out, - ) - - return out.wrapVector() - } - - override fun Point.minus(other: Point): EjmlFloatVector { - val out = FMatrixRMaj(1, 1) - - CommonOps_FDRM.add( - elementAlgebra.one, - toEjml().origin, - elementAlgebra { -one }, - other.toEjml().origin, - out, - ) - - return out.wrapVector() - } - - override fun Float.times(m: Matrix): EjmlFloatMatrix = m * this - - override fun Point.times(value: Float): EjmlFloatVector { - val res = FMatrixRMaj(1, 1) - CommonOps_FDRM.scale(value, toEjml().origin, res) - return res.wrapVector() - } - - override fun Float.times(v: Point): EjmlFloatVector = v * this - - @UnstableKMathAPI - override fun computeFeature(structure: Matrix, type: KClass): F? { - structure.getFeature(type)?.let { return it } - val origin = structure.toEjml().origin - - return when (type) { - InverseMatrixFeature::class -> object : InverseMatrixFeature { - override val inverse: Matrix by lazy { - val res = origin.copy() - CommonOps_FDRM.invert(res) - res.wrapMatrix() - } - } - - DeterminantFeature::class -> object : DeterminantFeature { - override val determinant: Float by lazy { CommonOps_FDRM.det(origin) } - } - - SingularValueDecompositionFeature::class -> object : SingularValueDecompositionFeature { - private val svd by lazy { - DecompositionFactory_FDRM.svd(origin.numRows, origin.numCols, true, true, false) - .apply { decompose(origin.copy()) } - } - - override val u: Matrix by lazy { svd.getU(null, false).wrapMatrix() } - override val s: Matrix by lazy { svd.getW(null).wrapMatrix() } - override val v: Matrix by lazy { svd.getV(null, false).wrapMatrix() } - override val singularValues: Point by lazy { FloatBuffer(svd.singularValues) } - } - - QRDecompositionFeature::class -> object : QRDecompositionFeature { - private val qr by lazy { - DecompositionFactory_FDRM.qr().apply { decompose(origin.copy()) } - } - - override val q: Matrix by lazy { - qr.getQ(null, false).wrapMatrix().withFeature(OrthogonalFeature) - } - - override val r: Matrix by lazy { qr.getR(null, false).wrapMatrix().withFeature(UFeature) } - } - - CholeskyDecompositionFeature::class -> object : CholeskyDecompositionFeature { - override val l: Matrix by lazy { - val cholesky = - DecompositionFactory_FDRM.chol(structure.rowNum, true).apply { decompose(origin.copy()) } - - cholesky.getT(null).wrapMatrix().withFeature(LFeature) - } - } - - LupDecompositionFeature::class -> object : LupDecompositionFeature { - private val lup by lazy { - DecompositionFactory_FDRM.lu(origin.numRows, origin.numCols).apply { decompose(origin.copy()) } - } - - override val l: Matrix by lazy { - lup.getLower(null).wrapMatrix().withFeature(LFeature) - } - - override val u: Matrix by lazy { - lup.getUpper(null).wrapMatrix().withFeature(UFeature) - } - - override val p: Matrix by lazy { lup.getRowPivot(null).wrapMatrix() } - } - - else -> null - }?.let{ - type.cast(it) - } - } - - /** - * Solves for *x* in the following equation: *x = [a] -1 · [b]*. - * - * @param a the base matrix. - * @param b n by p matrix. - * @return the solution for *x* that is n by p. - */ - public fun solve(a: Matrix, b: Matrix): EjmlFloatMatrix { - val res = FMatrixRMaj(1, 1) - CommonOps_FDRM.solve(FMatrixRMaj(a.toEjml().origin), FMatrixRMaj(b.toEjml().origin), res) - return res.wrapMatrix() - } - - /** - * Solves for *x* in the following equation: *x = [a] -1 · [b]*. - * - * @param a the base matrix. - * @param b n by p vector. - * @return the solution for *x* that is n by p. - */ - public fun solve(a: Matrix, b: Point): EjmlFloatVector { - val res = FMatrixRMaj(1, 1) - CommonOps_FDRM.solve(FMatrixRMaj(a.toEjml().origin), FMatrixRMaj(b.toEjml().origin), res) - return EjmlFloatVector(res) - } -} - -/** - * [EjmlLinearSpace] implementation based on [CommonOps_DSCC], [DecompositionFactory_DSCC] operations and - * [DMatrixSparseCSC] matrices. - */ -public object EjmlLinearSpaceDSCC : EjmlLinearSpace() { - /** - * The [DoubleField] reference. - */ - override val elementAlgebra: DoubleField get() = DoubleField - - @Suppress("UNCHECKED_CAST") - override fun Matrix.toEjml(): EjmlDoubleMatrix = when { - this is EjmlDoubleMatrix<*> && origin is DMatrixSparseCSC -> this as EjmlDoubleMatrix - else -> buildMatrix(rowNum, colNum) { i, j -> get(i, j) } - } - - @Suppress("UNCHECKED_CAST") - override fun Point.toEjml(): EjmlDoubleVector = when { - this is EjmlDoubleVector<*> && origin is DMatrixSparseCSC -> this as EjmlDoubleVector - else -> EjmlDoubleVector(DMatrixSparseCSC(size, 1).also { - (0 until it.numRows).forEach { row -> it[row, 0] = get(row) } - }) - } - - override fun buildMatrix( - rows: Int, - columns: Int, - initializer: DoubleField.(i: Int, j: Int) -> Double, - ): EjmlDoubleMatrix = DMatrixSparseCSC(rows, columns).also { - (0 until rows).forEach { row -> - (0 until columns).forEach { col -> it[row, col] = elementAlgebra.initializer(row, col) } - } - }.wrapMatrix() - - override fun buildVector( - size: Int, - initializer: DoubleField.(Int) -> Double, - ): EjmlDoubleVector = EjmlDoubleVector(DMatrixSparseCSC(size, 1).also { - (0 until it.numRows).forEach { row -> it[row, 0] = elementAlgebra.initializer(row) } - }) - - private fun T.wrapMatrix() = EjmlDoubleMatrix(this) - private fun T.wrapVector() = EjmlDoubleVector(this) - - override fun Matrix.unaryMinus(): Matrix = this * elementAlgebra { -one } - - override fun Matrix.dot(other: Matrix): EjmlDoubleMatrix { - val out = DMatrixSparseCSC(1, 1) - CommonOps_DSCC.mult(toEjml().origin, other.toEjml().origin, out) - return out.wrapMatrix() - } - - override fun Matrix.dot(vector: Point): EjmlDoubleVector { - val out = DMatrixSparseCSC(1, 1) - CommonOps_DSCC.mult(toEjml().origin, vector.toEjml().origin, out) - return out.wrapVector() - } - - override operator fun Matrix.minus(other: Matrix): EjmlDoubleMatrix { - val out = DMatrixSparseCSC(1, 1) - - CommonOps_DSCC.add( - elementAlgebra.one, - toEjml().origin, - elementAlgebra { -one }, - other.toEjml().origin, - out, - null, - null, - ) - - return out.wrapMatrix() - } - - override operator fun Matrix.times(value: Double): EjmlDoubleMatrix { - val res = DMatrixSparseCSC(1, 1) - CommonOps_DSCC.scale(value, toEjml().origin, res) - return res.wrapMatrix() - } - - override fun Point.unaryMinus(): EjmlDoubleVector { - val res = DMatrixSparseCSC(1, 1) - CommonOps_DSCC.changeSign(toEjml().origin, res) - return res.wrapVector() - } - - override fun Matrix.plus(other: Matrix): EjmlDoubleMatrix { - val out = DMatrixSparseCSC(1, 1) - - CommonOps_DSCC.add( - elementAlgebra.one, - toEjml().origin, - elementAlgebra.one, - other.toEjml().origin, - out, - null, - null, - ) - - return out.wrapMatrix() - } - - override fun Point.plus(other: Point): EjmlDoubleVector { - val out = DMatrixSparseCSC(1, 1) - - CommonOps_DSCC.add( - elementAlgebra.one, - toEjml().origin, - elementAlgebra.one, - other.toEjml().origin, - out, - null, - null, - ) - - return out.wrapVector() - } - - override fun Point.minus(other: Point): EjmlDoubleVector { - val out = DMatrixSparseCSC(1, 1) - - CommonOps_DSCC.add( - elementAlgebra.one, - toEjml().origin, - elementAlgebra { -one }, - other.toEjml().origin, - out, - null, - null, - ) - - return out.wrapVector() - } - - override fun Double.times(m: Matrix): EjmlDoubleMatrix = m * this - - override fun Point.times(value: Double): EjmlDoubleVector { - val res = DMatrixSparseCSC(1, 1) - CommonOps_DSCC.scale(value, toEjml().origin, res) - return res.wrapVector() - } - - override fun Double.times(v: Point): EjmlDoubleVector = v * this - - @UnstableKMathAPI - override fun computeFeature(structure: Matrix, type: KClass): F? { - structure.getFeature(type)?.let { return it } - val origin = structure.toEjml().origin - - return when (type) { - QRDecompositionFeature::class -> object : QRDecompositionFeature { - private val qr by lazy { - DecompositionFactory_DSCC.qr(FillReducing.NONE).apply { decompose(origin.copy()) } - } - - override val q: Matrix by lazy { - qr.getQ(null, false).wrapMatrix().withFeature(OrthogonalFeature) - } - - override val r: Matrix by lazy { qr.getR(null, false).wrapMatrix().withFeature(UFeature) } - } - - CholeskyDecompositionFeature::class -> object : CholeskyDecompositionFeature { - override val l: Matrix by lazy { - val cholesky = - DecompositionFactory_DSCC.cholesky().apply { decompose(origin.copy()) } - - (cholesky.getT(null) as DMatrix).wrapMatrix().withFeature(LFeature) - } - } - - LUDecompositionFeature::class, DeterminantFeature::class, InverseMatrixFeature::class -> object : - LUDecompositionFeature, DeterminantFeature, InverseMatrixFeature { - private val lu by lazy { - DecompositionFactory_DSCC.lu(FillReducing.NONE).apply { decompose(origin.copy()) } - } - - override val l: Matrix by lazy { - lu.getLower(null).wrapMatrix().withFeature(LFeature) - } - - override val u: Matrix by lazy { - lu.getUpper(null).wrapMatrix().withFeature(UFeature) - } - - override val inverse: Matrix by lazy { - var a = origin - val inverse = DMatrixRMaj(1, 1) - val solver = LinearSolverFactory_DSCC.lu(FillReducing.NONE) - if (solver.modifiesA()) a = a.copy() - val i = CommonOps_DDRM.identity(a.numRows) - solver.solve(i, inverse) - inverse.wrapMatrix() - } - - override val determinant: Double by lazy { elementAlgebra.number(lu.computeDeterminant().real) } - } - - else -> null - }?.let{ - type.cast(it) - } - } - - /** - * Solves for *x* in the following equation: *x = [a] -1 · [b]*. - * - * @param a the base matrix. - * @param b n by p matrix. - * @return the solution for *x* that is n by p. - */ - public fun solve(a: Matrix, b: Matrix): EjmlDoubleMatrix { - val res = DMatrixSparseCSC(1, 1) - CommonOps_DSCC.solve(DMatrixSparseCSC(a.toEjml().origin), DMatrixSparseCSC(b.toEjml().origin), res) - return res.wrapMatrix() - } - - /** - * Solves for *x* in the following equation: *x = [a] -1 · [b]*. - * - * @param a the base matrix. - * @param b n by p vector. - * @return the solution for *x* that is n by p. - */ - public fun solve(a: Matrix, b: Point): EjmlDoubleVector { - val res = DMatrixSparseCSC(1, 1) - CommonOps_DSCC.solve(DMatrixSparseCSC(a.toEjml().origin), DMatrixSparseCSC(b.toEjml().origin), res) - return EjmlDoubleVector(res) - } -} - -/** - * [EjmlLinearSpace] implementation based on [CommonOps_FSCC], [DecompositionFactory_FSCC] operations and - * [FMatrixSparseCSC] matrices. - */ -public object EjmlLinearSpaceFSCC : EjmlLinearSpace() { - /** - * The [FloatField] reference. - */ - override val elementAlgebra: FloatField get() = FloatField - - @Suppress("UNCHECKED_CAST") - override fun Matrix.toEjml(): EjmlFloatMatrix = when { - this is EjmlFloatMatrix<*> && origin is FMatrixSparseCSC -> this as EjmlFloatMatrix - else -> buildMatrix(rowNum, colNum) { i, j -> get(i, j) } - } - - @Suppress("UNCHECKED_CAST") - override fun Point.toEjml(): EjmlFloatVector = when { - this is EjmlFloatVector<*> && origin is FMatrixSparseCSC -> this as EjmlFloatVector - else -> EjmlFloatVector(FMatrixSparseCSC(size, 1).also { - (0 until it.numRows).forEach { row -> it[row, 0] = get(row) } - }) - } - - override fun buildMatrix( - rows: Int, - columns: Int, - initializer: FloatField.(i: Int, j: Int) -> Float, - ): EjmlFloatMatrix = FMatrixSparseCSC(rows, columns).also { - (0 until rows).forEach { row -> - (0 until columns).forEach { col -> it[row, col] = elementAlgebra.initializer(row, col) } - } - }.wrapMatrix() - - override fun buildVector( - size: Int, - initializer: FloatField.(Int) -> Float, - ): EjmlFloatVector = EjmlFloatVector(FMatrixSparseCSC(size, 1).also { - (0 until it.numRows).forEach { row -> it[row, 0] = elementAlgebra.initializer(row) } - }) - - private fun T.wrapMatrix() = EjmlFloatMatrix(this) - private fun T.wrapVector() = EjmlFloatVector(this) - - override fun Matrix.unaryMinus(): Matrix = this * elementAlgebra { -one } - - override fun Matrix.dot(other: Matrix): EjmlFloatMatrix { - val out = FMatrixSparseCSC(1, 1) - CommonOps_FSCC.mult(toEjml().origin, other.toEjml().origin, out) - return out.wrapMatrix() - } - - override fun Matrix.dot(vector: Point): EjmlFloatVector { - val out = FMatrixSparseCSC(1, 1) - CommonOps_FSCC.mult(toEjml().origin, vector.toEjml().origin, out) - return out.wrapVector() - } - - override operator fun Matrix.minus(other: Matrix): EjmlFloatMatrix { - val out = FMatrixSparseCSC(1, 1) - - CommonOps_FSCC.add( - elementAlgebra.one, - toEjml().origin, - elementAlgebra { -one }, - other.toEjml().origin, - out, - null, - null, - ) - - return out.wrapMatrix() - } - - override operator fun Matrix.times(value: Float): EjmlFloatMatrix { - val res = FMatrixSparseCSC(1, 1) - CommonOps_FSCC.scale(value, toEjml().origin, res) - return res.wrapMatrix() - } - - override fun Point.unaryMinus(): EjmlFloatVector { - val res = FMatrixSparseCSC(1, 1) - CommonOps_FSCC.changeSign(toEjml().origin, res) - return res.wrapVector() - } - - override fun Matrix.plus(other: Matrix): EjmlFloatMatrix { - val out = FMatrixSparseCSC(1, 1) - - CommonOps_FSCC.add( - elementAlgebra.one, - toEjml().origin, - elementAlgebra.one, - other.toEjml().origin, - out, - null, - null, - ) - - return out.wrapMatrix() - } - - override fun Point.plus(other: Point): EjmlFloatVector { - val out = FMatrixSparseCSC(1, 1) - - CommonOps_FSCC.add( - elementAlgebra.one, - toEjml().origin, - elementAlgebra.one, - other.toEjml().origin, - out, - null, - null, - ) - - return out.wrapVector() - } - - override fun Point.minus(other: Point): EjmlFloatVector { - val out = FMatrixSparseCSC(1, 1) - - CommonOps_FSCC.add( - elementAlgebra.one, - toEjml().origin, - elementAlgebra { -one }, - other.toEjml().origin, - out, - null, - null, - ) - - return out.wrapVector() - } - - override fun Float.times(m: Matrix): EjmlFloatMatrix = m * this - - override fun Point.times(value: Float): EjmlFloatVector { - val res = FMatrixSparseCSC(1, 1) - CommonOps_FSCC.scale(value, toEjml().origin, res) - return res.wrapVector() - } - - override fun Float.times(v: Point): EjmlFloatVector = v * this - - @UnstableKMathAPI - override fun computeFeature(structure: Matrix, type: KClass): F? { - structure.getFeature(type)?.let { return it } - val origin = structure.toEjml().origin - - return when (type) { - QRDecompositionFeature::class -> object : QRDecompositionFeature { - private val qr by lazy { - DecompositionFactory_FSCC.qr(FillReducing.NONE).apply { decompose(origin.copy()) } - } - - override val q: Matrix by lazy { - qr.getQ(null, false).wrapMatrix().withFeature(OrthogonalFeature) - } - - override val r: Matrix by lazy { qr.getR(null, false).wrapMatrix().withFeature(UFeature) } - } - - CholeskyDecompositionFeature::class -> object : CholeskyDecompositionFeature { - override val l: Matrix by lazy { - val cholesky = - DecompositionFactory_FSCC.cholesky().apply { decompose(origin.copy()) } - - (cholesky.getT(null) as FMatrix).wrapMatrix().withFeature(LFeature) - } - } - - LUDecompositionFeature::class, DeterminantFeature::class, InverseMatrixFeature::class -> object : - LUDecompositionFeature, DeterminantFeature, InverseMatrixFeature { - private val lu by lazy { - DecompositionFactory_FSCC.lu(FillReducing.NONE).apply { decompose(origin.copy()) } - } - - override val l: Matrix by lazy { - lu.getLower(null).wrapMatrix().withFeature(LFeature) - } - - override val u: Matrix by lazy { - lu.getUpper(null).wrapMatrix().withFeature(UFeature) - } - - override val inverse: Matrix by lazy { - var a = origin - val inverse = FMatrixRMaj(1, 1) - val solver = LinearSolverFactory_FSCC.lu(FillReducing.NONE) - if (solver.modifiesA()) a = a.copy() - val i = CommonOps_FDRM.identity(a.numRows) - solver.solve(i, inverse) - inverse.wrapMatrix() - } - - override val determinant: Float by lazy { elementAlgebra.number(lu.computeDeterminant().real) } - } - - else -> null - }?.let{ - type.cast(it) - } - } - - /** - * Solves for *x* in the following equation: *x = [a] -1 · [b]*. - * - * @param a the base matrix. - * @param b n by p matrix. - * @return the solution for *x* that is n by p. - */ - public fun solve(a: Matrix, b: Matrix): EjmlFloatMatrix { - val res = FMatrixSparseCSC(1, 1) - CommonOps_FSCC.solve(FMatrixSparseCSC(a.toEjml().origin), FMatrixSparseCSC(b.toEjml().origin), res) - return res.wrapMatrix() - } - - /** - * Solves for *x* in the following equation: *x = [a] -1 · [b]*. - * - * @param a the base matrix. - * @param b n by p vector. - * @return the solution for *x* that is n by p. - */ - public fun solve(a: Matrix, b: Point): EjmlFloatVector { - val res = FMatrixSparseCSC(1, 1) - CommonOps_FSCC.solve(FMatrixSparseCSC(a.toEjml().origin), FMatrixSparseCSC(b.toEjml().origin), res) - return EjmlFloatVector(res) - } -} - diff --git a/kmath-ejml/src/test/kotlin/space/kscience/kmath/ejml/EjmlMatrixTest.kt b/kmath-ejml/src/test/kotlin/space/kscience/kmath/ejml/EjmlMatrixTest.kt index e89810e0d..04cc69708 100644 --- a/kmath-ejml/src/test/kotlin/space/kscience/kmath/ejml/EjmlMatrixTest.kt +++ b/kmath-ejml/src/test/kotlin/space/kscience/kmath/ejml/EjmlMatrixTest.kt @@ -61,9 +61,9 @@ internal class EjmlMatrixTest { fun features() { val m = randomMatrix val w = EjmlDoubleMatrix(m) - val det: DeterminantFeature = EjmlLinearSpaceDDRM.computeFeature(w) ?: fail() + val det: Determinant = EjmlLinearSpaceDDRM.attributeFor(w) ?: fail() assertEquals(CommonOps_DDRM.det(m), det.determinant) - val lup: LupDecompositionFeature = EjmlLinearSpaceDDRM.computeFeature(w) ?: fail() + val lup: LupDecompositionAttribute = EjmlLinearSpaceDDRM.attributeFor(w) ?: fail() val ludecompositionF64 = DecompositionFactory_DDRM.lu(m.numRows, m.numCols) .also { it.decompose(m.copy()) } diff --git a/kmath-for-real/src/commonMain/kotlin/space/kscience/kmath/real/DoubleVector.kt b/kmath-for-real/src/commonMain/kotlin/space/kscience/kmath/real/DoubleVector.kt index 411a35188..08dc75789 100644 --- a/kmath-for-real/src/commonMain/kotlin/space/kscience/kmath/real/DoubleVector.kt +++ b/kmath-for-real/src/commonMain/kotlin/space/kscience/kmath/real/DoubleVector.kt @@ -16,7 +16,6 @@ import kotlin.math.pow public typealias DoubleVector = Point -@Suppress("FunctionName") public fun DoubleVector(vararg doubles: Double): DoubleVector = doubles.asBuffer() /** diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/Polynomial.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/Polynomial.kt index af84f47f2..b8a11c472 100644 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/Polynomial.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/Polynomial.kt @@ -7,11 +7,14 @@ package space.kscience.kmath.functions +import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.operations.Ring import space.kscience.kmath.operations.ScaleOperations import space.kscience.kmath.operations.invoke import kotlin.math.max import kotlin.math.min +import kotlin.reflect.KType +import kotlin.reflect.typeOf /** @@ -48,7 +51,7 @@ public data class Polynomial( * * @usesMathJax */ - public val coefficients: List + public val coefficients: List, ) { override fun toString(): String = "Polynomial$coefficients" } @@ -62,16 +65,17 @@ public data class Polynomial( * @param ring underlying ring of constants of type [A]. */ public open class PolynomialSpace( - /** - * Underlying ring of constants. Its operations on constants are used by local operations on constants and polynomials. - */ public val ring: A, ) : Ring>, ScaleOperations> where A : Ring, A : ScaleOperations { + @UnstableKMathAPI + override val elementType: KType get() = typeOf>() + /** * Instance of zero constant (zero of the underlying ring). */ public val constantZero: C get() = ring.zero + /** * Instance of unit constant (unit of the underlying ring). */ @@ -95,6 +99,7 @@ public open class PolynomialSpace( ) } } + /** * Returns difference between the constant represented as a polynomial and the polynomial. */ @@ -115,6 +120,7 @@ public open class PolynomialSpace( ) } } + /** * Returns product of the constant represented as a polynomial and the polynomial. */ @@ -147,6 +153,7 @@ public open class PolynomialSpace( ) } } + /** * Returns difference between the constant represented as a polynomial and the polynomial. */ @@ -165,6 +172,7 @@ public open class PolynomialSpace( ) } } + /** * Returns product of the constant represented as a polynomial and the polynomial. */ @@ -183,6 +191,7 @@ public open class PolynomialSpace( * Converts the constant [value] to polynomial. */ public fun number(value: C): Polynomial = Polynomial(listOf(value)) + /** * Converts the constant to polynomial. */ @@ -194,6 +203,7 @@ public open class PolynomialSpace( public override operator fun Polynomial.unaryMinus(): Polynomial = ring { Polynomial(coefficients.map { -it }) } + /** * Returns sum of the polynomials. */ @@ -210,6 +220,7 @@ public open class PolynomialSpace( } ) } + /** * Returns difference of the polynomials. */ @@ -226,6 +237,7 @@ public open class PolynomialSpace( } ) } + /** * Returns product of the polynomials. */ @@ -245,6 +257,7 @@ public open class PolynomialSpace( * Instance of zero polynomial (zero of the polynomial ring). */ override val zero: Polynomial = Polynomial(emptyList()) + /** * Instance of unit polynomial (unit of the polynomial ring). */ diff --git a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/distributions/NormalDistribution.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/distributions/NormalDistribution.kt index ae814254b..4cd1b89af 100644 --- a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/distributions/NormalDistribution.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/distributions/NormalDistribution.kt @@ -5,13 +5,12 @@ package space.kscience.kmath.distributions +import space.kscience.kmath.chains.BlockingDoubleChain import space.kscience.kmath.chains.Chain import space.kscience.kmath.operations.DoubleField.pow import space.kscience.kmath.random.RandomGenerator -import space.kscience.kmath.samplers.GaussianSampler +import space.kscience.kmath.samplers.* import space.kscience.kmath.samplers.InternalErf -import space.kscience.kmath.samplers.NormalizedGaussianSampler -import space.kscience.kmath.samplers.ZigguratNormalizedGaussianSampler import kotlin.math.* /** @@ -24,7 +23,7 @@ public class NormalDistribution(public val sampler: GaussianSampler) : Distribut return exp(-0.5 * x1 * x1 - (ln(sampler.standardDeviation) + 0.5 * ln(2 * PI))) } - override fun sample(generator: RandomGenerator): Chain = sampler.sample(generator) + override fun sample(generator: RandomGenerator): BlockingDoubleChain = sampler.sample(generator) override fun cumulative(arg: Double): Double { val dev = arg - sampler.mean From 4abe25c1888cb2ac5ddc1588cfa1d6e048a3855a Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Tue, 18 Jul 2023 10:13:36 +0300 Subject: [PATCH 07/40] [WIP] Features to Attributes refactoring --- CHANGELOG.md | 1 + .../space/kscience/attributes/SafeType.kt | 4 ++- .../kmath/structures/typeSafeDimensions.kt | 2 +- .../kmath/commons/optimization/CMOptimizer.kt | 2 +- .../kscience/kmath/linear/LinearSpace.kt | 3 +-- .../kscience/kmath/linear/LupDecomposition.kt | 15 ++++++----- .../kscience/kmath/linear/MatrixFeatures.kt | 9 +++---- .../kscience/kmath/linear/MatrixWrapper.kt | 10 -------- .../space/kscience/kmath/linear/Transposed.kt | 25 +++++++++++++++++++ .../kscience/kmath/linear/VirtualMatrix.kt | 3 +-- .../space/kscience/kmath/nd/AlgebraND.kt | 20 +++------------ .../space/kscience/kmath/nd/BufferND.kt | 4 +-- .../space/kscience/kmath/nd/Structure2D.kt | 4 ++- .../space/kscience/kmath/nd/StructureND.kt | 4 ++- .../kmath/operations/BufferAlgebra.kt | 2 -- .../space/kscience/kmath/structures/Buffer.kt | 2 +- .../kscience/kmath/dimensions/Wrappers.kt | 4 +-- .../kscience/dimensions/DMatrixContextTest.kt | 2 +- kmath-functions/build.gradle.kts | 2 -- .../kscience/kmath/functions/Polynomial.kt | 3 --- .../optimization/FunctionOptimization.kt | 25 +++++++++++++------ .../kmath/optimization/OptimizationProblem.kt | 16 +++--------- .../kscience/kmath/optimization/XYFit.kt | 4 +-- .../kmath/optimization/logLikelihood.kt | 4 +-- 24 files changed, 84 insertions(+), 86 deletions(-) create mode 100644 kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/Transposed.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index bbfb68501..e1ff7fbe7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ ### Changed - Features replaced with Attributes. +- Transposed refactored. ### Deprecated diff --git a/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/SafeType.kt b/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/SafeType.kt index 44ead89cb..7225d1a6b 100644 --- a/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/SafeType.kt +++ b/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/SafeType.kt @@ -5,6 +5,7 @@ package space.kscience.attributes +import kotlin.jvm.JvmInline import kotlin.reflect.KClass import kotlin.reflect.KType import kotlin.reflect.typeOf @@ -14,7 +15,8 @@ import kotlin.reflect.typeOf * * @param kType raw [KType] */ -public class SafeType @PublishedApi internal constructor(public val kType: KType) +@JvmInline +public value class SafeType @PublishedApi internal constructor(public val kType: KType) public inline fun safeTypeOf(): SafeType = SafeType(typeOf()) diff --git a/examples/src/main/kotlin/space/kscience/kmath/structures/typeSafeDimensions.kt b/examples/src/main/kotlin/space/kscience/kmath/structures/typeSafeDimensions.kt index 1ba0e3503..45677dcb5 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/structures/typeSafeDimensions.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/structures/typeSafeDimensions.kt @@ -15,7 +15,7 @@ private fun DMatrixContext.simple() { val m2 = produce { i, j -> (i + j).toDouble() } //Dimension-safe addition - m1.transpose() + m2 + m1.transposed() + m2 } private object D5 : Dimension { diff --git a/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/optimization/CMOptimizer.kt b/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/optimization/CMOptimizer.kt index c4dafb6a6..6e0000721 100644 --- a/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/optimization/CMOptimizer.kt +++ b/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/optimization/CMOptimizer.kt @@ -125,7 +125,7 @@ public object CMOptimizer : Optimizer> { val logger = problem.getFeature() - for (feature in problem.features) { + for (feature in problem.attributes) { when (feature) { is CMOptimizerData -> feature.data.forEach { dataBuilder -> addOptimizationData(dataBuilder()) 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 b83316e84..0780be29a 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 @@ -174,9 +174,8 @@ public interface LinearSpace> : MatrixOperations { /** * Get an attribute value for the structure in this scope. Structure features take precedence other context features. * - * @param A the type of feature. * @param structure the structure. - * @param attribute to be computed + * @param attribute to be computed. * @return a feature object or `null` if it isn't present. */ @UnstableKMathAPI 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 c44564231..468248c21 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 @@ -21,12 +21,11 @@ import space.kscience.kmath.structures.* * @param T the type of matrices' items. * @param l The lower triangular matrix in this decomposition. It may have [LowerTriangular]. * @param u The upper triangular matrix in this decomposition. It may have [UpperTriangular]. - * @param p he permutation matrix in this decomposition. May have [Determinant] attribute */ public data class LupDecomposition( public val l: Matrix, public val u: Matrix, - public val p: Matrix, + public val pivot: IntBuffer, ) @@ -180,12 +179,12 @@ public fun > LinearSpace>.lup( val u = VirtualMatrix(rowNum, colNum) { i, j -> if (j >= i) lu[i, j] else zero }.withAttribute(UpperTriangular) +// +// val p = VirtualMatrix(rowNum, colNum) { i, j -> +// if (j == pivot[i]) one else zero +// }.withAttribute(Determinant, if (even) one else -one) - val p = VirtualMatrix(rowNum, colNum) { i, j -> - if (j == pivot[i]) one else zero - }.withAttribute(Determinant, if (even) one else -one) - - return LupDecomposition(l, u, p) + return LupDecomposition(l, u, pivot.asBuffer()) } } } @@ -209,7 +208,7 @@ internal fun > LinearSpace.solve( for (row in 0 until rowNum) { val bpRow = bp.row(row) - val pRow = pivot[row] + val pRow = lup.pivot[row] for (col in 0 until matrix.colNum) bpRow[col] = matrix[pRow, col] } diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixFeatures.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixFeatures.kt index b494625c7..d109ef1bc 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixFeatures.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixFeatures.kt @@ -11,8 +11,6 @@ package space.kscience.kmath.linear import space.kscience.attributes.* import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.nd.StructureAttribute -import kotlin.reflect.KType -import kotlin.reflect.typeOf /** * A marker interface representing some properties of matrices or additional transformations of them. Features are used @@ -53,11 +51,9 @@ public val MatrixOperations.Inverted: Inverted get() = Inverted(safeTy * * @param T the type of matrices' items. */ -public class Determinant(type: SafeType) : - PolymorphicAttribute(type), - MatrixAttribute +public class Determinant : MatrixAttribute -public inline val MatrixOperations.Determinant: Determinant get() = Determinant(safeTypeOf()) +public val MatrixOperations.Determinant: Determinant get() = Determinant() /** * Matrices with this feature are lower triangular ones. @@ -174,4 +170,5 @@ public class SingularValueDecompositionAttribute(type: SafeType MatrixOperations.SVD: SingularValueDecompositionAttribute get() = SingularValueDecompositionAttribute(safeTypeOf()) + //TODO add sparse matrix feature diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixWrapper.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixWrapper.kt index 0f0c9ce3f..a129b04f0 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixWrapper.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixWrapper.kt @@ -82,13 +82,3 @@ public fun LinearSpace>.zero( ): MatrixWrapper = VirtualMatrix(rows, columns) { _, _ -> elementAlgebra.zero }.withAttribute(IsZero) - -public class TransposedAttribute(public val original: Matrix) : MatrixAttribute - -/** - * Create a virtual transposed matrix without copying anything. `A.transpose().transpose() === A` - */ -@Suppress("UNCHECKED_CAST") -@OptIn(UnstableKMathAPI::class) -public fun Matrix.transpose(): Matrix = getFeature(TransposedAttribute::class)?.original as? Matrix - ?: VirtualMatrix(colNum, rowNum) { i, j -> get(j, i) }.withAttribute(TransposedAttribute(this)) diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/Transposed.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/Transposed.kt new file mode 100644 index 000000000..3e93a2a23 --- /dev/null +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/Transposed.kt @@ -0,0 +1,25 @@ +/* + * Copyright 2018-2023 KMath contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package space.kscience.kmath.linear + +import space.kscience.attributes.Attributes + + +public class TransposedMatrix(public val origin: Matrix) : Matrix { + override val rowNum: Int get() = origin.colNum + override val colNum: Int get() = origin.rowNum + + override fun get(i: Int, j: Int): T = origin[j, i] + + override val attributes: Attributes get() = Attributes.EMPTY +} + + +/** + * Create a virtual transposed matrix without copying anything. `A.transpose().transpose() === A` + */ +public val Matrix.transposed: Matrix + get() = (this as? TransposedMatrix)?.origin ?: TransposedMatrix(this) \ No newline at end of file diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/VirtualMatrix.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/VirtualMatrix.kt index 7927e4dba..97de82c7a 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/VirtualMatrix.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/VirtualMatrix.kt @@ -29,5 +29,4 @@ public class VirtualMatrix( public fun MatrixBuilder.virtual( attributes: Attributes = Attributes.EMPTY, generator: (i: Int, j: Int) -> T, -): VirtualMatrix = - VirtualMatrix(rows, columns, attributes, generator) +): VirtualMatrix = VirtualMatrix(rows, columns, attributes, generator) diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/AlgebraND.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/AlgebraND.kt index 3a9a1833a..0611225c1 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/AlgebraND.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/AlgebraND.kt @@ -71,31 +71,19 @@ public interface AlgebraND> : Algebra> { structure.map { value -> this@invoke(value) } /** - * Get a feature of the structure in this scope. Structure features take precedence other context features. + * Get an attribute value for the structure in this scope. Structure features take precedence other context features. * - * @param F the type of feature. * @param structure the structure. - * @param type the [KClass] instance of [F]. + * @param attribute to be computed. * @return a feature object or `null` if it isn't present. */ @UnstableKMathAPI - public fun getFeature(structure: StructureND, type: KClass): F? = - structure.getFeature(type) + public fun > attributeFor(structure: StructureND<*>, attribute: A): T? = + structure.attributes[attribute] public companion object } -/** - * Get a feature of the structure in this scope. Structure features take precedence other context features. - * - * @param T the type of items in the matrices. - * @param F the type of feature. - * @return a feature object or `null` if it isn't present. - */ -@UnstableKMathAPI -public inline fun AlgebraND.getFeature(structure: StructureND): F? = - getFeature(structure, F::class) - /** * Space of [StructureND]. * diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/BufferND.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/BufferND.kt index 72ecc9ef0..461a82e0a 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/BufferND.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/BufferND.kt @@ -36,8 +36,8 @@ public open class BufferND( */ public inline fun BufferND( shape: ShapeND, - bufferFactory: BufferFactory = BufferFactory.auto(), - initializer: (IntArray) -> T, + bufferFactory: BufferFactory = BufferFactory.auto(), + crossinline initializer: (IntArray) -> T, ): BufferND { val strides = Strides(shape) return BufferND(strides, bufferFactory(strides.linearSize) { initializer(strides.index(it)) }) diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Structure2D.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Structure2D.kt index 931730399..eff58acc3 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Structure2D.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Structure2D.kt @@ -5,6 +5,7 @@ package space.kscience.kmath.nd +import space.kscience.attributes.Attributes import space.kscience.kmath.PerformancePitfall import space.kscience.kmath.structures.Buffer import space.kscience.kmath.structures.MutableBuffer @@ -110,7 +111,8 @@ private value class Structure2DWrapper(val structure: StructureND) : S @PerformancePitfall override operator fun get(i: Int, j: Int): T = structure[i, j] - override fun getFeature(type: KClass): F? = structure.getFeature(type) + override val attributes: Attributes + get() = structure.attributes @PerformancePitfall override fun elements(): Sequence> = structure.elements() diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/StructureND.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/StructureND.kt index 724cc6f69..993349487 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/StructureND.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/StructureND.kt @@ -7,13 +7,13 @@ package space.kscience.kmath.nd import space.kscience.attributes.Attribute import space.kscience.attributes.AttributeContainer +import space.kscience.attributes.Attributes import space.kscience.attributes.SafeType import space.kscience.kmath.PerformancePitfall import space.kscience.kmath.linear.LinearSpace import space.kscience.kmath.operations.Ring import space.kscience.kmath.operations.invoke import space.kscience.kmath.structures.Buffer -import space.kscience.kmath.structures.BufferFactory import kotlin.jvm.JvmName import kotlin.math.abs @@ -57,6 +57,8 @@ public interface StructureND : AttributeContainer, WithShape { @PerformancePitfall public fun elements(): Sequence> = indices.asSequence().map { it to get(it) } + override val attributes: Attributes get() = Attributes.EMPTY + public companion object { /** * Indicates whether some [StructureND] is equal to another one. diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/BufferAlgebra.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/BufferAlgebra.kt index 9047feb29..be371a56b 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/BufferAlgebra.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/BufferAlgebra.kt @@ -20,8 +20,6 @@ public interface WithSize { public interface BufferAlgebra> : Algebra> { public val elementAlgebra: A - public val elementType: KType - public val elementBufferFactory: MutableBufferFactory get() = elementAlgebra.bufferFactory public fun buffer(size: Int, vararg elements: T): Buffer { 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 d9ee25321..022886279 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 @@ -21,7 +21,7 @@ public fun interface BufferFactory { public operator fun invoke(size: Int, builder: (Int) -> T): Buffer public companion object{ - public inline fun auto(): BufferFactory = + public inline fun auto(): BufferFactory = BufferFactory(Buffer.Companion::auto) public fun boxing(): BufferFactory = 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 dde2d4fcf..6ff90ba7c 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 @@ -146,8 +146,8 @@ public value class DMatrixContext>(public val context: public inline operator fun DMatrix.unaryMinus(): DMatrix = context.run { this@unaryMinus.unaryMinus() }.coerce() - public inline fun DMatrix.transpose(): DMatrix = - context.run { (this@transpose as Matrix).transpose() }.coerce() + public inline fun DMatrix.transposed(): DMatrix = + context.run { (this@transposed as Matrix).transposed }.coerce() public companion object { public val real: DMatrixContext = DMatrixContext(Double.algebra.linearSpace) diff --git a/kmath-dimensions/src/commonTest/kotlin/space/kscience/dimensions/DMatrixContextTest.kt b/kmath-dimensions/src/commonTest/kotlin/space/kscience/dimensions/DMatrixContextTest.kt index e2793855b..65c4cf80b 100644 --- a/kmath-dimensions/src/commonTest/kotlin/space/kscience/dimensions/DMatrixContextTest.kt +++ b/kmath-dimensions/src/commonTest/kotlin/space/kscience/dimensions/DMatrixContextTest.kt @@ -30,7 +30,7 @@ internal class DMatrixContextTest { val m2 = produce { i, j -> (i + j).toDouble() } //Dimension-safe addition - m1.transpose() + m2 + m1.transposed() + m2 } } } diff --git a/kmath-functions/build.gradle.kts b/kmath-functions/build.gradle.kts index 4ec52f5ee..3c1fbb07c 100644 --- a/kmath-functions/build.gradle.kts +++ b/kmath-functions/build.gradle.kts @@ -9,8 +9,6 @@ kscience{ wasm() - - dependencies { api(projects.kmathCore) } diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/Polynomial.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/Polynomial.kt index b8a11c472..afd96aced 100644 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/Polynomial.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/Polynomial.kt @@ -68,9 +68,6 @@ public open class PolynomialSpace( public val ring: A, ) : Ring>, ScaleOperations> where A : Ring, A : ScaleOperations { - @UnstableKMathAPI - override val elementType: KType get() = typeOf>() - /** * Instance of zero constant (zero of the underlying ring). */ diff --git a/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/FunctionOptimization.kt b/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/FunctionOptimization.kt index 07146625c..fe5f0ca8a 100644 --- a/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/FunctionOptimization.kt +++ b/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/FunctionOptimization.kt @@ -5,21 +5,21 @@ package space.kscience.kmath.optimization +import space.kscience.attributes.* import space.kscience.kmath.expressions.DifferentiableExpression import space.kscience.kmath.expressions.Symbol -import space.kscience.kmath.misc.FeatureSet public class OptimizationValue(public val value: T) : OptimizationFeature { override fun toString(): String = "Value($value)" } -public enum class FunctionOptimizationTarget : OptimizationFeature { +public enum class FunctionOptimizationTarget { MAXIMIZE, MINIMIZE } public class FunctionOptimization( - override val features: FeatureSet, + override val attributes: Attributes, public val expression: DifferentiableExpression, ) : OptimizationProblem { @@ -30,25 +30,36 @@ public class FunctionOptimization( other as FunctionOptimization<*> - if (features != other.features) return false + if (attributes != other.attributes) return false if (expression != other.expression) return false return true } override fun hashCode(): Int { - var result = features.hashCode() + var result = attributes.hashCode() result = 31 * result + expression.hashCode() return result } - override fun toString(): String = "FunctionOptimization(features=$features)" + override fun toString(): String = "FunctionOptimization(features=$attributes)" + + public companion object } + + +public class OptimizationPrior(type: SafeType): + PolymorphicAttribute>(safeTypeOf()), + Attribute> + +public val FunctionOptimization.Companion.Optimization get() = + + public fun FunctionOptimization.withFeatures( vararg newFeature: OptimizationFeature, ): FunctionOptimization = FunctionOptimization( - features.with(*newFeature), + attributes.with(*newFeature), expression, ) diff --git a/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/OptimizationProblem.kt b/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/OptimizationProblem.kt index 9fdcfc53d..46ba8c1c0 100644 --- a/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/OptimizationProblem.kt +++ b/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/OptimizationProblem.kt @@ -5,21 +5,16 @@ package space.kscience.kmath.optimization +import space.kscience.attributes.* import space.kscience.kmath.expressions.DifferentiableExpression import space.kscience.kmath.expressions.NamedMatrix import space.kscience.kmath.expressions.Symbol import space.kscience.kmath.misc.* import kotlin.reflect.KClass -public interface OptimizationFeature : Feature { - // enforce toString override - override fun toString(): String -} +public interface OptimizationAttribute: Attribute -public interface OptimizationProblem : Featured { - public val features: FeatureSet - override fun getFeature(type: KClass): F? = features.getFeature(type) -} +public interface OptimizationProblem : AttributeContainer public inline fun OptimizationProblem<*>.getFeature(): F? = getFeature(F::class) @@ -27,11 +22,6 @@ public open class OptimizationStartPoint(public val point: Map) : override fun toString(): String = "StartPoint($point)" } - -public interface OptimizationPrior : OptimizationFeature, DifferentiableExpression { - override val key: FeatureKey get() = OptimizationPrior::class -} - /** * Covariance matrix for */ diff --git a/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/XYFit.kt b/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/XYFit.kt index 9e5396491..cda37af4f 100644 --- a/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/XYFit.kt +++ b/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/XYFit.kt @@ -79,7 +79,7 @@ public interface PointWeight : OptimizationFeature { public class XYFit( public val data: XYColumnarData, public val model: DifferentiableExpression, - override val features: FeatureSet, + override val attributes: FeatureSet, internal val pointToCurveDistance: PointToCurveDistance = PointToCurveDistance.byY, internal val pointWeight: PointWeight = PointWeight.byYSigma, public val xSymbol: Symbol = Symbol.x, @@ -90,7 +90,7 @@ public class XYFit( } public fun XYFit.withFeature(vararg features: OptimizationFeature): XYFit { - return XYFit(data, model, this.features.with(*features), pointToCurveDistance, pointWeight) + return XYFit(data, model, this.attributes.with(*features), pointToCurveDistance, pointWeight) } public suspend fun XYColumnarData.fitWith( diff --git a/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/logLikelihood.kt b/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/logLikelihood.kt index 8ab9de48d..40081ed81 100644 --- a/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/logLikelihood.kt +++ b/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/logLikelihood.kt @@ -53,9 +53,9 @@ internal fun XYFit.logLikelihood(): DifferentiableExpression = object : */ @UnstableKMathAPI public suspend fun Optimizer>.maximumLogLikelihood(problem: XYFit): XYFit { - val functionOptimization = FunctionOptimization(problem.features, problem.logLikelihood()) + val functionOptimization = FunctionOptimization(problem.attributes, problem.logLikelihood()) val result = optimize(functionOptimization.withFeatures(FunctionOptimizationTarget.MAXIMIZE)) - return XYFit(problem.data, problem.model, result.features) + return XYFit(problem.data, problem.model, result.attributes) } @UnstableKMathAPI From a3c65e5b178e361d66506b145e1e0a471ca7b3b4 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Tue, 18 Jul 2023 11:14:23 +0300 Subject: [PATCH 08/40] [WIP] Features to Attributes refactoring --- .../space/kscience/kmath/ejml/_generated.kt | 1011 +++++++++++++++++ 1 file changed, 1011 insertions(+) create mode 100644 kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/_generated.kt diff --git a/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/_generated.kt b/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/_generated.kt new file mode 100644 index 000000000..fa438775d --- /dev/null +++ b/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/_generated.kt @@ -0,0 +1,1011 @@ +/* + * Copyright 2018-2021 KMath contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. + */ + +/* This file is generated with buildSrc/src/main/kotlin/space/kscience/kmath/ejml/codegen/ejmlCodegen.kt */ + +package space.kscience.kmath.ejml + +import org.ejml.data.* +import org.ejml.dense.row.CommonOps_DDRM +import org.ejml.dense.row.CommonOps_FDRM +import org.ejml.dense.row.factory.DecompositionFactory_DDRM +import org.ejml.dense.row.factory.DecompositionFactory_FDRM +import org.ejml.sparse.FillReducing +import org.ejml.sparse.csc.CommonOps_DSCC +import org.ejml.sparse.csc.CommonOps_FSCC +import org.ejml.sparse.csc.factory.DecompositionFactory_DSCC +import org.ejml.sparse.csc.factory.DecompositionFactory_FSCC +import org.ejml.sparse.csc.factory.LinearSolverFactory_DSCC +import org.ejml.sparse.csc.factory.LinearSolverFactory_FSCC +import space.kscience.kmath.linear.* +import space.kscience.kmath.linear.Matrix +import space.kscience.kmath.UnstableKMathAPI +import space.kscience.kmath.nd.StructureFeature +import space.kscience.kmath.operations.DoubleField +import space.kscience.kmath.operations.FloatField +import space.kscience.kmath.operations.invoke +import space.kscience.kmath.structures.DoubleBuffer +import space.kscience.kmath.structures.FloatBuffer +import kotlin.reflect.KClass +import kotlin.reflect.cast + +/** + * [EjmlVector] specialization for [Double]. + */ +public class EjmlDoubleVector(override val origin: M) : EjmlVector(origin) { + init { + require(origin.numRows == 1) { "The origin matrix must have only one row to form a vector" } + } + + override operator fun get(index: Int): Double = origin[0, index] +} + +/** + * [EjmlVector] specialization for [Float]. + */ +public class EjmlFloatVector(override val origin: M) : EjmlVector(origin) { + init { + require(origin.numRows == 1) { "The origin matrix must have only one row to form a vector" } + } + + override operator fun get(index: Int): Float = origin[0, index] +} + +/** + * [EjmlMatrix] specialization for [Double]. + */ +public class EjmlDoubleMatrix(override val origin: M) : EjmlMatrix(origin) { + override operator fun get(i: Int, j: Int): Double = origin[i, j] +} + +/** + * [EjmlMatrix] specialization for [Float]. + */ +public class EjmlFloatMatrix(override val origin: M) : EjmlMatrix(origin) { + override operator fun get(i: Int, j: Int): Float = origin[i, j] +} + +/** + * [EjmlLinearSpace] implementation based on [CommonOps_DDRM], [DecompositionFactory_DDRM] operations and + * [DMatrixRMaj] matrices. + */ +public object EjmlLinearSpaceDDRM : EjmlLinearSpace() { + /** + * The [DoubleField] reference. + */ + override val elementAlgebra: DoubleField get() = DoubleField + + override val elementType: KType get() = typeOf() + + @Suppress("UNCHECKED_CAST") + override fun Matrix.toEjml(): EjmlDoubleMatrix = when { + this is EjmlDoubleMatrix<*> && origin is DMatrixRMaj -> this as EjmlDoubleMatrix + else -> buildMatrix(rowNum, colNum) { i, j -> get(i, j) } + } + + @Suppress("UNCHECKED_CAST") + override fun Point.toEjml(): EjmlDoubleVector = when { + this is EjmlDoubleVector<*> && origin is DMatrixRMaj -> this as EjmlDoubleVector + else -> EjmlDoubleVector(DMatrixRMaj(size, 1).also { + (0 until it.numRows).forEach { row -> it[row, 0] = get(row) } + }) + } + + override fun buildMatrix( + rows: Int, + columns: Int, + initializer: DoubleField.(i: Int, j: Int) -> Double, + ): EjmlDoubleMatrix = DMatrixRMaj(rows, columns).also { + (0 until rows).forEach { row -> + (0 until columns).forEach { col -> it[row, col] = elementAlgebra.initializer(row, col) } + } + }.wrapMatrix() + + override fun buildVector( + size: Int, + initializer: DoubleField.(Int) -> Double, + ): EjmlDoubleVector = EjmlDoubleVector(DMatrixRMaj(size, 1).also { + (0 until it.numRows).forEach { row -> it[row, 0] = elementAlgebra.initializer(row) } + }) + + private fun T.wrapMatrix() = EjmlDoubleMatrix(this) + private fun T.wrapVector() = EjmlDoubleVector(this) + + override fun Matrix.unaryMinus(): Matrix = this * elementAlgebra { -one } + + override fun Matrix.dot(other: Matrix): EjmlDoubleMatrix { + val out = DMatrixRMaj(1, 1) + CommonOps_DDRM.mult(toEjml().origin, other.toEjml().origin, out) + return out.wrapMatrix() + } + + override fun Matrix.dot(vector: Point): EjmlDoubleVector { + val out = DMatrixRMaj(1, 1) + CommonOps_DDRM.mult(toEjml().origin, vector.toEjml().origin, out) + return out.wrapVector() + } + + override operator fun Matrix.minus(other: Matrix): EjmlDoubleMatrix { + val out = DMatrixRMaj(1, 1) + + CommonOps_DDRM.add( + elementAlgebra.one, + toEjml().origin, + elementAlgebra { -one }, + other.toEjml().origin, + out, + ) + + return out.wrapMatrix() + } + + override operator fun Matrix.times(value: Double): EjmlDoubleMatrix { + val res = DMatrixRMaj(1, 1) + CommonOps_DDRM.scale(value, toEjml().origin, res) + return res.wrapMatrix() + } + + override fun Point.unaryMinus(): EjmlDoubleVector { + val res = DMatrixRMaj(1, 1) + CommonOps_DDRM.changeSign(toEjml().origin, res) + return res.wrapVector() + } + + override fun Matrix.plus(other: Matrix): EjmlDoubleMatrix { + val out = DMatrixRMaj(1, 1) + + CommonOps_DDRM.add( + elementAlgebra.one, + toEjml().origin, + elementAlgebra.one, + other.toEjml().origin, + out, + ) + + return out.wrapMatrix() + } + + override fun Point.plus(other: Point): EjmlDoubleVector { + val out = DMatrixRMaj(1, 1) + + CommonOps_DDRM.add( + elementAlgebra.one, + toEjml().origin, + elementAlgebra.one, + other.toEjml().origin, + out, + ) + + return out.wrapVector() + } + + override fun Point.minus(other: Point): EjmlDoubleVector { + val out = DMatrixRMaj(1, 1) + + CommonOps_DDRM.add( + elementAlgebra.one, + toEjml().origin, + elementAlgebra { -one }, + other.toEjml().origin, + out, + ) + + return out.wrapVector() + } + + override fun Double.times(m: Matrix): EjmlDoubleMatrix = m * this + + override fun Point.times(value: Double): EjmlDoubleVector { + val res = DMatrixRMaj(1, 1) + CommonOps_DDRM.scale(value, toEjml().origin, res) + return res.wrapVector() + } + + override fun Double.times(v: Point): EjmlDoubleVector = v * this + + @UnstableKMathAPI + override fun computeFeature(structure: Matrix, type: KClass): F? { + structure.getFeature(type)?.let { return it } + val origin = structure.toEjml().origin + + return when (type) { + InverseMatrixFeature::class -> object : InverseMatrixFeature { + override val inverse: Matrix by lazy { + val res = origin.copy() + CommonOps_DDRM.invert(res) + res.wrapMatrix() + } + } + + DeterminantFeature::class -> object : DeterminantFeature { + override val determinant: Double by lazy { CommonOps_DDRM.det(origin) } + } + + SingularValueDecompositionFeature::class -> object : SingularValueDecompositionFeature { + private val svd by lazy { + DecompositionFactory_DDRM.svd(origin.numRows, origin.numCols, true, true, false) + .apply { decompose(origin.copy()) } + } + + override val u: Matrix by lazy { svd.getU(null, false).wrapMatrix() } + override val s: Matrix by lazy { svd.getW(null).wrapMatrix() } + override val v: Matrix by lazy { svd.getV(null, false).wrapMatrix() } + override val singularValues: Point by lazy { DoubleBuffer(svd.singularValues) } + } + + QRDecompositionFeature::class -> object : QRDecompositionFeature { + private val qr by lazy { + DecompositionFactory_DDRM.qr().apply { decompose(origin.copy()) } + } + + override val q: Matrix by lazy { + qr.getQ(null, false).wrapMatrix().withFeature(OrthogonalFeature) + } + + override val r: Matrix by lazy { qr.getR(null, false).wrapMatrix().withFeature(UFeature) } + } + + CholeskyDecompositionFeature::class -> object : CholeskyDecompositionFeature { + override val l: Matrix by lazy { + val cholesky = + DecompositionFactory_DDRM.chol(structure.rowNum, true).apply { decompose(origin.copy()) } + + cholesky.getT(null).wrapMatrix().withFeature(LFeature) + } + } + + LupDecompositionFeature::class -> object : LupDecompositionFeature { + private val lup by lazy { + DecompositionFactory_DDRM.lu(origin.numRows, origin.numCols).apply { decompose(origin.copy()) } + } + + override val l: Matrix by lazy { + lup.getLower(null).wrapMatrix().withFeature(LFeature) + } + + override val u: Matrix by lazy { + lup.getUpper(null).wrapMatrix().withFeature(UFeature) + } + + override val p: Matrix by lazy { lup.getRowPivot(null).wrapMatrix() } + } + + else -> null + }?.let{ + type.cast(it) + } + } + + /** + * Solves for *x* in the following equation: *x = [a] -1 · [b]*. + * + * @param a the base matrix. + * @param b n by p matrix. + * @return the solution for *x* that is n by p. + */ + public fun solve(a: Matrix, b: Matrix): EjmlDoubleMatrix { + val res = DMatrixRMaj(1, 1) + CommonOps_DDRM.solve(DMatrixRMaj(a.toEjml().origin), DMatrixRMaj(b.toEjml().origin), res) + return res.wrapMatrix() + } + + /** + * Solves for *x* in the following equation: *x = [a] -1 · [b]*. + * + * @param a the base matrix. + * @param b n by p vector. + * @return the solution for *x* that is n by p. + */ + public fun solve(a: Matrix, b: Point): EjmlDoubleVector { + val res = DMatrixRMaj(1, 1) + CommonOps_DDRM.solve(DMatrixRMaj(a.toEjml().origin), DMatrixRMaj(b.toEjml().origin), res) + return EjmlDoubleVector(res) + } +} + +/** + * [EjmlLinearSpace] implementation based on [CommonOps_FDRM], [DecompositionFactory_FDRM] operations and + * [FMatrixRMaj] matrices. + */ +public object EjmlLinearSpaceFDRM : EjmlLinearSpace() { + /** + * The [FloatField] reference. + */ + override val elementAlgebra: FloatField get() = FloatField + + override val elementType: KType get() = typeOf() + + @Suppress("UNCHECKED_CAST") + override fun Matrix.toEjml(): EjmlFloatMatrix = when { + this is EjmlFloatMatrix<*> && origin is FMatrixRMaj -> this as EjmlFloatMatrix + else -> buildMatrix(rowNum, colNum) { i, j -> get(i, j) } + } + + @Suppress("UNCHECKED_CAST") + override fun Point.toEjml(): EjmlFloatVector = when { + this is EjmlFloatVector<*> && origin is FMatrixRMaj -> this as EjmlFloatVector + else -> EjmlFloatVector(FMatrixRMaj(size, 1).also { + (0 until it.numRows).forEach { row -> it[row, 0] = get(row) } + }) + } + + override fun buildMatrix( + rows: Int, + columns: Int, + initializer: FloatField.(i: Int, j: Int) -> Float, + ): EjmlFloatMatrix = FMatrixRMaj(rows, columns).also { + (0 until rows).forEach { row -> + (0 until columns).forEach { col -> it[row, col] = elementAlgebra.initializer(row, col) } + } + }.wrapMatrix() + + override fun buildVector( + size: Int, + initializer: FloatField.(Int) -> Float, + ): EjmlFloatVector = EjmlFloatVector(FMatrixRMaj(size, 1).also { + (0 until it.numRows).forEach { row -> it[row, 0] = elementAlgebra.initializer(row) } + }) + + private fun T.wrapMatrix() = EjmlFloatMatrix(this) + private fun T.wrapVector() = EjmlFloatVector(this) + + override fun Matrix.unaryMinus(): Matrix = this * elementAlgebra { -one } + + override fun Matrix.dot(other: Matrix): EjmlFloatMatrix { + val out = FMatrixRMaj(1, 1) + CommonOps_FDRM.mult(toEjml().origin, other.toEjml().origin, out) + return out.wrapMatrix() + } + + override fun Matrix.dot(vector: Point): EjmlFloatVector { + val out = FMatrixRMaj(1, 1) + CommonOps_FDRM.mult(toEjml().origin, vector.toEjml().origin, out) + return out.wrapVector() + } + + override operator fun Matrix.minus(other: Matrix): EjmlFloatMatrix { + val out = FMatrixRMaj(1, 1) + + CommonOps_FDRM.add( + elementAlgebra.one, + toEjml().origin, + elementAlgebra { -one }, + other.toEjml().origin, + out, + ) + + return out.wrapMatrix() + } + + override operator fun Matrix.times(value: Float): EjmlFloatMatrix { + val res = FMatrixRMaj(1, 1) + CommonOps_FDRM.scale(value, toEjml().origin, res) + return res.wrapMatrix() + } + + override fun Point.unaryMinus(): EjmlFloatVector { + val res = FMatrixRMaj(1, 1) + CommonOps_FDRM.changeSign(toEjml().origin, res) + return res.wrapVector() + } + + override fun Matrix.plus(other: Matrix): EjmlFloatMatrix { + val out = FMatrixRMaj(1, 1) + + CommonOps_FDRM.add( + elementAlgebra.one, + toEjml().origin, + elementAlgebra.one, + other.toEjml().origin, + out, + ) + + return out.wrapMatrix() + } + + override fun Point.plus(other: Point): EjmlFloatVector { + val out = FMatrixRMaj(1, 1) + + CommonOps_FDRM.add( + elementAlgebra.one, + toEjml().origin, + elementAlgebra.one, + other.toEjml().origin, + out, + ) + + return out.wrapVector() + } + + override fun Point.minus(other: Point): EjmlFloatVector { + val out = FMatrixRMaj(1, 1) + + CommonOps_FDRM.add( + elementAlgebra.one, + toEjml().origin, + elementAlgebra { -one }, + other.toEjml().origin, + out, + ) + + return out.wrapVector() + } + + override fun Float.times(m: Matrix): EjmlFloatMatrix = m * this + + override fun Point.times(value: Float): EjmlFloatVector { + val res = FMatrixRMaj(1, 1) + CommonOps_FDRM.scale(value, toEjml().origin, res) + return res.wrapVector() + } + + override fun Float.times(v: Point): EjmlFloatVector = v * this + + @UnstableKMathAPI + override fun computeFeature(structure: Matrix, type: KClass): F? { + structure.getFeature(type)?.let { return it } + val origin = structure.toEjml().origin + + return when (type) { + InverseMatrixFeature::class -> object : InverseMatrixFeature { + override val inverse: Matrix by lazy { + val res = origin.copy() + CommonOps_FDRM.invert(res) + res.wrapMatrix() + } + } + + DeterminantFeature::class -> object : DeterminantFeature { + override val determinant: Float by lazy { CommonOps_FDRM.det(origin) } + } + + SingularValueDecompositionFeature::class -> object : SingularValueDecompositionFeature { + private val svd by lazy { + DecompositionFactory_FDRM.svd(origin.numRows, origin.numCols, true, true, false) + .apply { decompose(origin.copy()) } + } + + override val u: Matrix by lazy { svd.getU(null, false).wrapMatrix() } + override val s: Matrix by lazy { svd.getW(null).wrapMatrix() } + override val v: Matrix by lazy { svd.getV(null, false).wrapMatrix() } + override val singularValues: Point by lazy { FloatBuffer(svd.singularValues) } + } + + QRDecompositionFeature::class -> object : QRDecompositionFeature { + private val qr by lazy { + DecompositionFactory_FDRM.qr().apply { decompose(origin.copy()) } + } + + override val q: Matrix by lazy { + qr.getQ(null, false).wrapMatrix().withFeature(OrthogonalFeature) + } + + override val r: Matrix by lazy { qr.getR(null, false).wrapMatrix().withFeature(UFeature) } + } + + CholeskyDecompositionFeature::class -> object : CholeskyDecompositionFeature { + override val l: Matrix by lazy { + val cholesky = + DecompositionFactory_FDRM.chol(structure.rowNum, true).apply { decompose(origin.copy()) } + + cholesky.getT(null).wrapMatrix().withFeature(LFeature) + } + } + + LupDecompositionFeature::class -> object : LupDecompositionFeature { + private val lup by lazy { + DecompositionFactory_FDRM.lu(origin.numRows, origin.numCols).apply { decompose(origin.copy()) } + } + + override val l: Matrix by lazy { + lup.getLower(null).wrapMatrix().withFeature(LFeature) + } + + override val u: Matrix by lazy { + lup.getUpper(null).wrapMatrix().withFeature(UFeature) + } + + override val p: Matrix by lazy { lup.getRowPivot(null).wrapMatrix() } + } + + else -> null + }?.let{ + type.cast(it) + } + } + + /** + * Solves for *x* in the following equation: *x = [a] -1 · [b]*. + * + * @param a the base matrix. + * @param b n by p matrix. + * @return the solution for *x* that is n by p. + */ + public fun solve(a: Matrix, b: Matrix): EjmlFloatMatrix { + val res = FMatrixRMaj(1, 1) + CommonOps_FDRM.solve(FMatrixRMaj(a.toEjml().origin), FMatrixRMaj(b.toEjml().origin), res) + return res.wrapMatrix() + } + + /** + * Solves for *x* in the following equation: *x = [a] -1 · [b]*. + * + * @param a the base matrix. + * @param b n by p vector. + * @return the solution for *x* that is n by p. + */ + public fun solve(a: Matrix, b: Point): EjmlFloatVector { + val res = FMatrixRMaj(1, 1) + CommonOps_FDRM.solve(FMatrixRMaj(a.toEjml().origin), FMatrixRMaj(b.toEjml().origin), res) + return EjmlFloatVector(res) + } +} + +/** + * [EjmlLinearSpace] implementation based on [CommonOps_DSCC], [DecompositionFactory_DSCC] operations and + * [DMatrixSparseCSC] matrices. + */ +public object EjmlLinearSpaceDSCC : EjmlLinearSpace() { + /** + * The [DoubleField] reference. + */ + override val elementAlgebra: DoubleField get() = DoubleField + + override val elementType: KType get() = typeOf() + + @Suppress("UNCHECKED_CAST") + override fun Matrix.toEjml(): EjmlDoubleMatrix = when { + this is EjmlDoubleMatrix<*> && origin is DMatrixSparseCSC -> this as EjmlDoubleMatrix + else -> buildMatrix(rowNum, colNum) { i, j -> get(i, j) } + } + + @Suppress("UNCHECKED_CAST") + override fun Point.toEjml(): EjmlDoubleVector = when { + this is EjmlDoubleVector<*> && origin is DMatrixSparseCSC -> this as EjmlDoubleVector + else -> EjmlDoubleVector(DMatrixSparseCSC(size, 1).also { + (0 until it.numRows).forEach { row -> it[row, 0] = get(row) } + }) + } + + override fun buildMatrix( + rows: Int, + columns: Int, + initializer: DoubleField.(i: Int, j: Int) -> Double, + ): EjmlDoubleMatrix = DMatrixSparseCSC(rows, columns).also { + (0 until rows).forEach { row -> + (0 until columns).forEach { col -> it[row, col] = elementAlgebra.initializer(row, col) } + } + }.wrapMatrix() + + override fun buildVector( + size: Int, + initializer: DoubleField.(Int) -> Double, + ): EjmlDoubleVector = EjmlDoubleVector(DMatrixSparseCSC(size, 1).also { + (0 until it.numRows).forEach { row -> it[row, 0] = elementAlgebra.initializer(row) } + }) + + private fun T.wrapMatrix() = EjmlDoubleMatrix(this) + private fun T.wrapVector() = EjmlDoubleVector(this) + + override fun Matrix.unaryMinus(): Matrix = this * elementAlgebra { -one } + + override fun Matrix.dot(other: Matrix): EjmlDoubleMatrix { + val out = DMatrixSparseCSC(1, 1) + CommonOps_DSCC.mult(toEjml().origin, other.toEjml().origin, out) + return out.wrapMatrix() + } + + override fun Matrix.dot(vector: Point): EjmlDoubleVector { + val out = DMatrixSparseCSC(1, 1) + CommonOps_DSCC.mult(toEjml().origin, vector.toEjml().origin, out) + return out.wrapVector() + } + + override operator fun Matrix.minus(other: Matrix): EjmlDoubleMatrix { + val out = DMatrixSparseCSC(1, 1) + + CommonOps_DSCC.add( + elementAlgebra.one, + toEjml().origin, + elementAlgebra { -one }, + other.toEjml().origin, + out, + null, + null, + ) + + return out.wrapMatrix() + } + + override operator fun Matrix.times(value: Double): EjmlDoubleMatrix { + val res = DMatrixSparseCSC(1, 1) + CommonOps_DSCC.scale(value, toEjml().origin, res) + return res.wrapMatrix() + } + + override fun Point.unaryMinus(): EjmlDoubleVector { + val res = DMatrixSparseCSC(1, 1) + CommonOps_DSCC.changeSign(toEjml().origin, res) + return res.wrapVector() + } + + override fun Matrix.plus(other: Matrix): EjmlDoubleMatrix { + val out = DMatrixSparseCSC(1, 1) + + CommonOps_DSCC.add( + elementAlgebra.one, + toEjml().origin, + elementAlgebra.one, + other.toEjml().origin, + out, + null, + null, + ) + + return out.wrapMatrix() + } + + override fun Point.plus(other: Point): EjmlDoubleVector { + val out = DMatrixSparseCSC(1, 1) + + CommonOps_DSCC.add( + elementAlgebra.one, + toEjml().origin, + elementAlgebra.one, + other.toEjml().origin, + out, + null, + null, + ) + + return out.wrapVector() + } + + override fun Point.minus(other: Point): EjmlDoubleVector { + val out = DMatrixSparseCSC(1, 1) + + CommonOps_DSCC.add( + elementAlgebra.one, + toEjml().origin, + elementAlgebra { -one }, + other.toEjml().origin, + out, + null, + null, + ) + + return out.wrapVector() + } + + override fun Double.times(m: Matrix): EjmlDoubleMatrix = m * this + + override fun Point.times(value: Double): EjmlDoubleVector { + val res = DMatrixSparseCSC(1, 1) + CommonOps_DSCC.scale(value, toEjml().origin, res) + return res.wrapVector() + } + + override fun Double.times(v: Point): EjmlDoubleVector = v * this + + @UnstableKMathAPI + override fun computeFeature(structure: Matrix, type: KClass): F? { + structure.getFeature(type)?.let { return it } + val origin = structure.toEjml().origin + + return when (type) { + QRDecompositionFeature::class -> object : QRDecompositionFeature { + private val qr by lazy { + DecompositionFactory_DSCC.qr(FillReducing.NONE).apply { decompose(origin.copy()) } + } + + override val q: Matrix by lazy { + qr.getQ(null, false).wrapMatrix().withFeature(OrthogonalFeature) + } + + override val r: Matrix by lazy { qr.getR(null, false).wrapMatrix().withFeature(UFeature) } + } + + CholeskyDecompositionFeature::class -> object : CholeskyDecompositionFeature { + override val l: Matrix by lazy { + val cholesky = + DecompositionFactory_DSCC.cholesky().apply { decompose(origin.copy()) } + + (cholesky.getT(null) as DMatrix).wrapMatrix().withFeature(LFeature) + } + } + + LUDecompositionFeature::class, DeterminantFeature::class, InverseMatrixFeature::class -> object : + LUDecompositionFeature, DeterminantFeature, InverseMatrixFeature { + private val lu by lazy { + DecompositionFactory_DSCC.lu(FillReducing.NONE).apply { decompose(origin.copy()) } + } + + override val l: Matrix by lazy { + lu.getLower(null).wrapMatrix().withFeature(LFeature) + } + + override val u: Matrix by lazy { + lu.getUpper(null).wrapMatrix().withFeature(UFeature) + } + + override val inverse: Matrix by lazy { + var a = origin + val inverse = DMatrixRMaj(1, 1) + val solver = LinearSolverFactory_DSCC.lu(FillReducing.NONE) + if (solver.modifiesA()) a = a.copy() + val i = CommonOps_DDRM.identity(a.numRows) + solver.solve(i, inverse) + inverse.wrapMatrix() + } + + override val determinant: Double by lazy { elementAlgebra.number(lu.computeDeterminant().real) } + } + + else -> null + }?.let{ + type.cast(it) + } + } + + /** + * Solves for *x* in the following equation: *x = [a] -1 · [b]*. + * + * @param a the base matrix. + * @param b n by p matrix. + * @return the solution for *x* that is n by p. + */ + public fun solve(a: Matrix, b: Matrix): EjmlDoubleMatrix { + val res = DMatrixSparseCSC(1, 1) + CommonOps_DSCC.solve(DMatrixSparseCSC(a.toEjml().origin), DMatrixSparseCSC(b.toEjml().origin), res) + return res.wrapMatrix() + } + + /** + * Solves for *x* in the following equation: *x = [a] -1 · [b]*. + * + * @param a the base matrix. + * @param b n by p vector. + * @return the solution for *x* that is n by p. + */ + public fun solve(a: Matrix, b: Point): EjmlDoubleVector { + val res = DMatrixSparseCSC(1, 1) + CommonOps_DSCC.solve(DMatrixSparseCSC(a.toEjml().origin), DMatrixSparseCSC(b.toEjml().origin), res) + return EjmlDoubleVector(res) + } +} + +/** + * [EjmlLinearSpace] implementation based on [CommonOps_FSCC], [DecompositionFactory_FSCC] operations and + * [FMatrixSparseCSC] matrices. + */ +public object EjmlLinearSpaceFSCC : EjmlLinearSpace() { + /** + * The [FloatField] reference. + */ + override val elementAlgebra: FloatField get() = FloatField + + override val elementType: KType get() = typeOf() + + @Suppress("UNCHECKED_CAST") + override fun Matrix.toEjml(): EjmlFloatMatrix = when { + this is EjmlFloatMatrix<*> && origin is FMatrixSparseCSC -> this as EjmlFloatMatrix + else -> buildMatrix(rowNum, colNum) { i, j -> get(i, j) } + } + + @Suppress("UNCHECKED_CAST") + override fun Point.toEjml(): EjmlFloatVector = when { + this is EjmlFloatVector<*> && origin is FMatrixSparseCSC -> this as EjmlFloatVector + else -> EjmlFloatVector(FMatrixSparseCSC(size, 1).also { + (0 until it.numRows).forEach { row -> it[row, 0] = get(row) } + }) + } + + override fun buildMatrix( + rows: Int, + columns: Int, + initializer: FloatField.(i: Int, j: Int) -> Float, + ): EjmlFloatMatrix = FMatrixSparseCSC(rows, columns).also { + (0 until rows).forEach { row -> + (0 until columns).forEach { col -> it[row, col] = elementAlgebra.initializer(row, col) } + } + }.wrapMatrix() + + override fun buildVector( + size: Int, + initializer: FloatField.(Int) -> Float, + ): EjmlFloatVector = EjmlFloatVector(FMatrixSparseCSC(size, 1).also { + (0 until it.numRows).forEach { row -> it[row, 0] = elementAlgebra.initializer(row) } + }) + + private fun T.wrapMatrix() = EjmlFloatMatrix(this) + private fun T.wrapVector() = EjmlFloatVector(this) + + override fun Matrix.unaryMinus(): Matrix = this * elementAlgebra { -one } + + override fun Matrix.dot(other: Matrix): EjmlFloatMatrix { + val out = FMatrixSparseCSC(1, 1) + CommonOps_FSCC.mult(toEjml().origin, other.toEjml().origin, out) + return out.wrapMatrix() + } + + override fun Matrix.dot(vector: Point): EjmlFloatVector { + val out = FMatrixSparseCSC(1, 1) + CommonOps_FSCC.mult(toEjml().origin, vector.toEjml().origin, out) + return out.wrapVector() + } + + override operator fun Matrix.minus(other: Matrix): EjmlFloatMatrix { + val out = FMatrixSparseCSC(1, 1) + + CommonOps_FSCC.add( + elementAlgebra.one, + toEjml().origin, + elementAlgebra { -one }, + other.toEjml().origin, + out, + null, + null, + ) + + return out.wrapMatrix() + } + + override operator fun Matrix.times(value: Float): EjmlFloatMatrix { + val res = FMatrixSparseCSC(1, 1) + CommonOps_FSCC.scale(value, toEjml().origin, res) + return res.wrapMatrix() + } + + override fun Point.unaryMinus(): EjmlFloatVector { + val res = FMatrixSparseCSC(1, 1) + CommonOps_FSCC.changeSign(toEjml().origin, res) + return res.wrapVector() + } + + override fun Matrix.plus(other: Matrix): EjmlFloatMatrix { + val out = FMatrixSparseCSC(1, 1) + + CommonOps_FSCC.add( + elementAlgebra.one, + toEjml().origin, + elementAlgebra.one, + other.toEjml().origin, + out, + null, + null, + ) + + return out.wrapMatrix() + } + + override fun Point.plus(other: Point): EjmlFloatVector { + val out = FMatrixSparseCSC(1, 1) + + CommonOps_FSCC.add( + elementAlgebra.one, + toEjml().origin, + elementAlgebra.one, + other.toEjml().origin, + out, + null, + null, + ) + + return out.wrapVector() + } + + override fun Point.minus(other: Point): EjmlFloatVector { + val out = FMatrixSparseCSC(1, 1) + + CommonOps_FSCC.add( + elementAlgebra.one, + toEjml().origin, + elementAlgebra { -one }, + other.toEjml().origin, + out, + null, + null, + ) + + return out.wrapVector() + } + + override fun Float.times(m: Matrix): EjmlFloatMatrix = m * this + + override fun Point.times(value: Float): EjmlFloatVector { + val res = FMatrixSparseCSC(1, 1) + CommonOps_FSCC.scale(value, toEjml().origin, res) + return res.wrapVector() + } + + override fun Float.times(v: Point): EjmlFloatVector = v * this + + @UnstableKMathAPI + override fun computeFeature(structure: Matrix, type: KClass): F? { + structure.getFeature(type)?.let { return it } + val origin = structure.toEjml().origin + + return when (type) { + QRDecompositionFeature::class -> object : QRDecompositionFeature { + private val qr by lazy { + DecompositionFactory_FSCC.qr(FillReducing.NONE).apply { decompose(origin.copy()) } + } + + override val q: Matrix by lazy { + qr.getQ(null, false).wrapMatrix().withFeature(OrthogonalFeature) + } + + override val r: Matrix by lazy { qr.getR(null, false).wrapMatrix().withFeature(UFeature) } + } + + CholeskyDecompositionFeature::class -> object : CholeskyDecompositionFeature { + override val l: Matrix by lazy { + val cholesky = + DecompositionFactory_FSCC.cholesky().apply { decompose(origin.copy()) } + + (cholesky.getT(null) as FMatrix).wrapMatrix().withFeature(LFeature) + } + } + + LUDecompositionFeature::class, DeterminantFeature::class, InverseMatrixFeature::class -> object : + LUDecompositionFeature, DeterminantFeature, InverseMatrixFeature { + private val lu by lazy { + DecompositionFactory_FSCC.lu(FillReducing.NONE).apply { decompose(origin.copy()) } + } + + override val l: Matrix by lazy { + lu.getLower(null).wrapMatrix().withFeature(LFeature) + } + + override val u: Matrix by lazy { + lu.getUpper(null).wrapMatrix().withFeature(UFeature) + } + + override val inverse: Matrix by lazy { + var a = origin + val inverse = FMatrixRMaj(1, 1) + val solver = LinearSolverFactory_FSCC.lu(FillReducing.NONE) + if (solver.modifiesA()) a = a.copy() + val i = CommonOps_FDRM.identity(a.numRows) + solver.solve(i, inverse) + inverse.wrapMatrix() + } + + override val determinant: Float by lazy { elementAlgebra.number(lu.computeDeterminant().real) } + } + + else -> null + }?.let{ + type.cast(it) + } + } + + /** + * Solves for *x* in the following equation: *x = [a] -1 · [b]*. + * + * @param a the base matrix. + * @param b n by p matrix. + * @return the solution for *x* that is n by p. + */ + public fun solve(a: Matrix, b: Matrix): EjmlFloatMatrix { + val res = FMatrixSparseCSC(1, 1) + CommonOps_FSCC.solve(FMatrixSparseCSC(a.toEjml().origin), FMatrixSparseCSC(b.toEjml().origin), res) + return res.wrapMatrix() + } + + /** + * Solves for *x* in the following equation: *x = [a] -1 · [b]*. + * + * @param a the base matrix. + * @param b n by p vector. + * @return the solution for *x* that is n by p. + */ + public fun solve(a: Matrix, b: Point): EjmlFloatVector { + val res = FMatrixSparseCSC(1, 1) + CommonOps_FSCC.solve(FMatrixSparseCSC(a.toEjml().origin), FMatrixSparseCSC(b.toEjml().origin), res) + return EjmlFloatVector(res) + } +} + From eff70eb69099ae3fedea5086cd9a1cda5f3c61c2 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sun, 13 Aug 2023 14:51:50 +0300 Subject: [PATCH 09/40] Refactor rotations. Add Rotation matrix to Euler conversion --- .../space/kscience/kmath/geometry/Vector2D.kt | 2 +- .../space/kscience/kmath/geometry/Vector3D.kt | 2 +- .../kmath/geometry/euclidean2d/Circle2D.kt | 4 +- .../geometry/euclidean2d/Float32Space2D.kt | 16 +- .../geometry/euclidean2d/Float64Space2D.kt | 11 +- .../geometry/euclidean3d/Float32Space3D.kt | 16 +- .../geometry/euclidean3d/Float64Space3D.kt | 8 +- .../kmath/geometry/euclidean3d/rotations3D.kt | 193 ++++++++++++++++-- .../kmath/geometry/quaternionOperations.kt | 55 ----- .../kmath/geometry/vectorPrecision.kt | 9 +- .../kscience/kmath/geometry/RotationTest.kt | 23 ++- 11 files changed, 228 insertions(+), 111 deletions(-) delete mode 100644 kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/quaternionOperations.kt diff --git a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Vector2D.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Vector2D.kt index 9eced7ba9..58069981e 100644 --- a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Vector2D.kt +++ b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Vector2D.kt @@ -7,7 +7,7 @@ package space.kscience.kmath.geometry import space.kscience.kmath.linear.Point -public interface Vector2D : Point, Vector { +public interface Vector2D : Point { public val x: T public val y: T override val size: Int get() = 2 diff --git a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Vector3D.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Vector3D.kt index 7e7c6c4ed..c7fb70fc6 100644 --- a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Vector3D.kt +++ b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Vector3D.kt @@ -8,7 +8,7 @@ package space.kscience.kmath.geometry import space.kscience.kmath.linear.Point import space.kscience.kmath.structures.Buffer -public interface Vector3D : Point, Vector { +public interface Vector3D : Point { public val x: T public val y: T public val z: T diff --git a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean2d/Circle2D.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean2d/Circle2D.kt index 077735b28..1c1305c8b 100644 --- a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean2d/Circle2D.kt +++ b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean2d/Circle2D.kt @@ -6,8 +6,6 @@ package space.kscience.kmath.geometry.euclidean2d import kotlinx.serialization.Serializable -import space.kscience.kmath.geometry.Euclidean2DSpace.distanceTo -import kotlin.math.* import kotlin.math.PI /** @@ -16,7 +14,7 @@ import kotlin.math.PI @Serializable public data class Circle2D( @Serializable(Float64Space2D.VectorSerializer::class) public val center: DoubleVector2D, - public val radius: Double + public val radius: Double, ) diff --git a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean2d/Float32Space2D.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean2d/Float32Space2D.kt index 89c3dc204..0cba56bb5 100644 --- a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean2d/Float32Space2D.kt +++ b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean2d/Float32Space2D.kt @@ -14,17 +14,15 @@ import kotlinx.serialization.encoding.Encoder import space.kscience.kmath.geometry.GeometrySpace import space.kscience.kmath.geometry.Vector2D import space.kscience.kmath.operations.Float32Field -import space.kscience.kmath.operations.ScaleOperations +import space.kscience.kmath.structures.Float32 import kotlin.math.pow import kotlin.math.sqrt @Serializable(Float32Space2D.VectorSerializer::class) -public interface Float32Vector2D: Vector2D +public interface Float32Vector2D : Vector2D -public object Float32Space2D : - GeometrySpace, - ScaleOperations { +public object Float32Space2D : GeometrySpace { @Serializable @SerialName("Float32Vector2D") @@ -53,13 +51,13 @@ public object Float32Space2D : override val zero: Float32Vector2D by lazy { vector(0f, 0f) } - override fun norm(arg: Float32Vector2D): Double = sqrt(arg.x.pow(2) + arg.y.pow(2)).toDouble() + override fun norm(arg: Float32Vector2D): Float32 = sqrt(arg.x.pow(2) + arg.y.pow(2)) - public fun Float32Vector2D.norm(): Double = norm(this) + public fun Float32Vector2D.norm(): Float32 = norm(this) override fun Float32Vector2D.unaryMinus(): Float32Vector2D = vector(-x, -y) - override fun Float32Vector2D.distanceTo(other: Float32Vector2D): Double = (this - other).norm() + override fun Float32Vector2D.distanceTo(other: Float32Vector2D): Float32 = (this - other).norm() override fun add(left: Float32Vector2D, right: Float32Vector2D): Float32Vector2D = vector(left.x + right.x, left.y + right.y) @@ -72,6 +70,8 @@ public object Float32Space2D : public val xAxis: Float32Vector2D = vector(1.0, 0.0) public val yAxis: Float32Vector2D = vector(0.0, 1.0) + + override val defaultPrecision: Float32 = 1e-3f } public fun Float32Vector2D(x: Number, y: Number): Float32Vector2D = Float32Space2D.vector(x, y) diff --git a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean2d/Float64Space2D.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean2d/Float64Space2D.kt index 320924fbf..ae7cefd8f 100644 --- a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean2d/Float64Space2D.kt +++ b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean2d/Float64Space2D.kt @@ -13,14 +13,12 @@ import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder import space.kscience.kmath.geometry.GeometrySpace import space.kscience.kmath.geometry.Vector2D +import space.kscience.kmath.linear.Float64LinearSpace import space.kscience.kmath.operations.Float64Field -import space.kscience.kmath.operations.Norm -import space.kscience.kmath.operations.ScaleOperations import kotlin.math.pow import kotlin.math.sqrt - public typealias DoubleVector2D = Vector2D public typealias Float64Vector2D = Vector2D @@ -30,10 +28,9 @@ public val Vector2D.r: Double get() = Float64Space2D.norm(this) /** * 2D Euclidean space */ -public object Float64Space2D : - GeometrySpace, - ScaleOperations, - Norm { +public object Float64Space2D : GeometrySpace { + + public val linearSpace: Float64LinearSpace = Float64LinearSpace @Serializable @SerialName("Float64Vector2D") diff --git a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean3d/Float32Space3D.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean3d/Float32Space3D.kt index 1413a885b..ce6bbd8fd 100644 --- a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean3d/Float32Space3D.kt +++ b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean3d/Float32Space3D.kt @@ -14,17 +14,15 @@ import kotlinx.serialization.encoding.Encoder import space.kscience.kmath.geometry.GeometrySpace import space.kscience.kmath.geometry.Vector3D import space.kscience.kmath.operations.Float32Field -import space.kscience.kmath.operations.ScaleOperations +import space.kscience.kmath.structures.Float32 import kotlin.math.pow import kotlin.math.sqrt @Serializable(Float32Space3D.VectorSerializer::class) -public interface Float32Vector3D: Vector3D +public interface Float32Vector3D : Vector3D -public object Float32Space3D : - GeometrySpace, - ScaleOperations{ +public object Float32Space3D : GeometrySpace { @Serializable @SerialName("Float32Vector3D") @@ -54,13 +52,13 @@ public object Float32Space3D : override val zero: Float32Vector3D by lazy { vector(0.0, 0.0, 0.0) } - override fun norm(arg: Float32Vector3D): Double = sqrt(arg.x.pow(2) + arg.y.pow(2) + arg.z.pow(2)).toDouble() + override fun norm(arg: Float32Vector3D): Float32 = sqrt(arg.x.pow(2) + arg.y.pow(2) + arg.z.pow(2)) - public fun Float32Vector3D.norm(): Double = norm(this) + public fun Float32Vector3D.norm(): Float32 = norm(this) override fun Float32Vector3D.unaryMinus(): Float32Vector3D = vector(-x, -y, -z) - override fun Float32Vector3D.distanceTo(other: Float32Vector3D): Double = (this - other).norm() + override fun Float32Vector3D.distanceTo(other: Float32Vector3D): Float32 = (this - other).norm() override fun add(left: Float32Vector3D, right: Float32Vector3D): Float32Vector3D = vector(left.x + right.x, left.y + right.y, left.z + right.z) @@ -101,6 +99,8 @@ public object Float32Space3D : public val xAxis: Float32Vector3D = vector(1.0, 0.0, 0.0) public val yAxis: Float32Vector3D = vector(0.0, 1.0, 0.0) public val zAxis: Float32Vector3D = vector(0.0, 0.0, 1.0) + + override val defaultPrecision: Float32 = 1e-3f } public fun Float32Vector3D(x: Number, y: Number, z: Number): Float32Vector3D = Float32Space3D.vector(x, y, z) diff --git a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean3d/Float64Space3D.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean3d/Float64Space3D.kt index b51796012..e808f6129 100644 --- a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean3d/Float64Space3D.kt +++ b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean3d/Float64Space3D.kt @@ -13,9 +13,8 @@ import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder import space.kscience.kmath.geometry.GeometrySpace import space.kscience.kmath.geometry.Vector3D +import space.kscience.kmath.linear.Float64LinearSpace import space.kscience.kmath.operations.Float64Field -import space.kscience.kmath.operations.Norm -import space.kscience.kmath.operations.ScaleOperations import kotlin.math.pow import kotlin.math.sqrt @@ -37,8 +36,9 @@ public typealias Float64Vector3D = Vector3D public val DoubleVector3D.r: Double get() = Float64Space3D.norm(this) -public object Float64Space3D : GeometrySpace, ScaleOperations, - Norm { +public object Float64Space3D : GeometrySpace{ + + public val linearSpace: Float64LinearSpace = Float64LinearSpace @Serializable @SerialName("Float64Vector3D") diff --git a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean3d/rotations3D.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean3d/rotations3D.kt index deb8b0a93..bf34e2ed2 100644 --- a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean3d/rotations3D.kt +++ b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean3d/rotations3D.kt @@ -6,20 +6,36 @@ package space.kscience.kmath.geometry.euclidean3d import space.kscience.kmath.UnstableKMathAPI -import space.kscience.kmath.complex.Quaternion -import space.kscience.kmath.complex.QuaternionAlgebra -import space.kscience.kmath.complex.normalized -import space.kscience.kmath.complex.reciprocal +import space.kscience.kmath.complex.* import space.kscience.kmath.geometry.* import space.kscience.kmath.linear.LinearSpace import space.kscience.kmath.linear.Matrix import space.kscience.kmath.linear.linearSpace import space.kscience.kmath.linear.matrix import space.kscience.kmath.operations.Float64Field -import kotlin.math.pow -import kotlin.math.sqrt +import kotlin.math.* -internal fun DoubleVector3D.toQuaternion(): Quaternion = Quaternion(0.0, x, y, z) +public operator fun Quaternion.times(other: Quaternion): Quaternion = QuaternionAlgebra.multiply(this, other) + +public operator fun Quaternion.div(other: Quaternion): Quaternion = QuaternionAlgebra.divide(this, other) + +public fun Quaternion.power(number: Number): Quaternion = QuaternionAlgebra.power(this, number) + +/** + * Linear interpolation between [from] and [to] in spherical space + */ +public fun QuaternionAlgebra.slerp(from: Quaternion, to: Quaternion, fraction: Double): Quaternion = + (to / from).pow(fraction) * from + +public fun QuaternionAlgebra.angleBetween(q1: Quaternion, q2: Quaternion): Angle = (q1.conjugate * q2).theta + +public infix fun Quaternion.dot(other: Quaternion): Double = w * other.w + x * other.x + y * other.y + z * other.z + + +/** + * Represent a vector as quaternion with zero a rotation angle. + */ +internal fun DoubleVector3D.asQuaternion(): Quaternion = Quaternion(0.0, x, y, z) /** * Angle in radians denoted by this quaternion rotation @@ -51,23 +67,30 @@ public val Quaternion.vector: DoubleVector3D } /** - * Rotate a vector in a [Float64Space3D] + * Rotate a vector in a [Float64Space3D] with [quaternion] */ -public fun Float64Space3D.rotate(vector: DoubleVector3D, q: Quaternion): DoubleVector3D = with(QuaternionAlgebra) { - val p = vector.toQuaternion() - (q * p * q.reciprocal).vector -} +public fun Float64Space3D.rotate(vector: DoubleVector3D, quaternion: Quaternion): DoubleVector3D = + with(QuaternionAlgebra) { + val p = vector.asQuaternion() + (quaternion * p * quaternion.reciprocal).vector + } /** * Use a composition of quaternions to create a rotation */ @UnstableKMathAPI -public fun Float64Space3D.rotate(vector: DoubleVector3D, composition: QuaternionAlgebra.() -> Quaternion): DoubleVector3D = +public fun Float64Space3D.rotate( + vector: DoubleVector3D, + composition: QuaternionAlgebra.() -> Quaternion, +): DoubleVector3D = rotate(vector, QuaternionAlgebra.composition()) +/** + * Rotate a [Float64] vector in 3D space with a rotation matrix + */ public fun Float64Space3D.rotate(vector: DoubleVector3D, matrix: Matrix): DoubleVector3D { require(matrix.colNum == 3 && matrix.rowNum == 3) { "Square 3x3 rotation matrix is required" } - return with(Float64Field.linearSpace) { matrix.dot(vector).asVector3D() } + return with(linearSpace) { (matrix dot vector).asVector3D() } } /** @@ -86,6 +109,8 @@ public fun Quaternion.toRotationMatrix( } /** + * Convert a quaternion to a rotation matrix + * * taken from https://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/ */ public fun Quaternion.Companion.fromRotationMatrix(matrix: Matrix): Quaternion { @@ -146,6 +171,8 @@ public enum class RotationOrder { } /** + * Create a quaternion from Euler angles + * * Based on https://github.com/mrdoob/three.js/blob/master/src/math/Quaternion.js */ public fun Quaternion.Companion.fromEuler( @@ -154,13 +181,13 @@ public fun Quaternion.Companion.fromEuler( c: Angle, rotationOrder: RotationOrder, ): Quaternion { - val c1 = cos (a / 2) - val c2 = cos (b / 2) - val c3 = cos (c / 2) + val c1 = cos(a / 2) + val c2 = cos(b / 2) + val c3 = cos(c / 2) - val s1 = sin (a / 2) - val s2 = sin (b / 2) - val s3 = sin (c / 2) + val s1 = sin(a / 2) + val s2 = sin(b / 2) + val s3 = sin(c / 2) return when (rotationOrder) { @@ -206,6 +233,130 @@ public fun Quaternion.Companion.fromEuler( c1 * s2 * c3 - s1 * c2 * s3, c1 * c2 * s3 + s1 * s2 * c3 ) - else -> TODO("Proper Euler rotation orders are not supported yet") + + else -> TODO("Proper Euler rotation orders are not supported yet") } +} + +/** + * A vector consisting of angles + */ +public data class AngleVector(override val x: Angle, override val y: Angle, override val z: Angle) : Vector3D { + public companion object +} + +public fun Quaternion.Companion.fromEuler( + angles: AngleVector, + rotationOrder: RotationOrder, +): Quaternion = fromEuler(angles.x, angles.y, angles.z, rotationOrder) + +/** + * Based on https://github.com/mrdoob/three.js/blob/master/src/math/Euler.js + */ +public fun AngleVector.Companion.fromRotationMatrix( + matrix: Matrix, + rotationOrder: RotationOrder, + gimbaldLockThreshold: Double = 0.9999999, +): AngleVector = when (rotationOrder) { + + RotationOrder.XYZ -> { + if (abs(matrix[0, 2]) < gimbaldLockThreshold) { + AngleVector( + atan2(-matrix[1, 2], matrix[2, 2]).radians, + asin(matrix[0, 2].coerceIn(-1.0, 1.0)).radians, + atan2(-matrix[0, 1], matrix[0, 0]).radians + ) + + } else { + AngleVector( + atan2(matrix[2, 1], matrix[1, 1]).radians, + asin(matrix[0, 2].coerceIn(-1.0, 1.0)).radians, + Angle.zero + ) + } + } + + RotationOrder.YXZ -> { + if (abs(matrix[1, 2]) < gimbaldLockThreshold) { + AngleVector( + x = asin(-matrix[1, 2].coerceIn(-1.0, 1.0)).radians, + y = atan2(matrix[0, 2], matrix[2, 2]).radians, + z = atan2(matrix[1, 0], matrix[1, 1]).radians, + ) + } else { + AngleVector( + x = asin(-matrix[1, 2].coerceIn(-1.0, 1.0)).radians, + y = atan2(-matrix[2, 0], matrix[0, 0]).radians, + z = Angle.zero, + ) + + } + } + + RotationOrder.ZXY -> { + if (abs(matrix[2, 1]) < gimbaldLockThreshold) { + AngleVector( + x = asin(matrix[2, 1].coerceIn(-1.0, 1.0)).radians, + y = atan2(-matrix[2, 0], matrix[2, 2]).radians, + z = atan2(-matrix[0, 1], matrix[1, 1]).radians, + ) + + } else { + AngleVector( + x = asin(matrix[2, 1].coerceIn(-1.0, 1.0)).radians, + y = Angle.zero, + z = atan2(matrix[1, 0], matrix[0, 0]).radians, + ) + } + } + + RotationOrder.ZYX -> { + if (abs(matrix[2, 0]) < gimbaldLockThreshold) { + AngleVector( + x = atan2(matrix[2, 1], matrix[2, 2]).radians, + y = asin(-matrix[2, 0].coerceIn(-1.0, 1.0)).radians, + z = atan2(matrix[1, 0], matrix[0, 0]).radians, + ) + } else { + AngleVector( + x = Angle.zero, + y = asin(-matrix[2, 0].coerceIn(-1.0, 1.0)).radians, + z = atan2(-matrix[0, 1], matrix[1, 1]).radians, + ) + } + } + + RotationOrder.YZX -> { + if (abs(matrix[1, 0]) < gimbaldLockThreshold) { + AngleVector( + x = atan2(-matrix[1, 2], matrix[1, 1]).radians, + y = atan2(-matrix[2, 0], matrix[0, 0]).radians, + z = asin(matrix[1, 0].coerceIn(-1.0, 1.0)).radians, + ) + } else { + AngleVector( + x = Angle.zero, + y = atan2(matrix[0, 2], matrix[2, 2]).radians, + z = asin(matrix[1, 0].coerceIn(-1.0, 1.0)).radians, + ) + } + } + + RotationOrder.XZY -> { + if (abs(matrix[0, 1]) < gimbaldLockThreshold) { + AngleVector( + x = atan2(matrix[2, 1], matrix[1, 1]).radians, + y = atan2(matrix[0, 2], matrix[0, 0]).radians, + z = asin(-matrix[0, 1].coerceIn(-1.0, 1.0)).radians, + ) + } else { + AngleVector( + x = atan2(-matrix[1, 2], matrix[2, 2]).radians, + y = Angle.zero, + z = asin(-matrix[0, 1].coerceIn(-1.0, 1.0)).radians, + ) + } + } + + else -> TODO("Proper Euler rotation orders are not supported yet") } \ No newline at end of file diff --git a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/quaternionOperations.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/quaternionOperations.kt deleted file mode 100644 index 49ceda04c..000000000 --- a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/quaternionOperations.kt +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2018-2023 KMath contributors. - * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. - */ - -package space.kscience.kmath.geometry - -import space.kscience.kmath.complex.Quaternion -import space.kscience.kmath.complex.QuaternionAlgebra -import space.kscience.kmath.complex.conjugate -import space.kscience.kmath.complex.normalized -import space.kscience.kmath.geometry.euclidean3d.Float32Space3D -import space.kscience.kmath.geometry.euclidean3d.Float32Vector3D -import space.kscience.kmath.geometry.euclidean3d.theta -import kotlin.math.asin -import kotlin.math.atan2 -import kotlin.math.pow - -public operator fun Quaternion.times(other: Quaternion): Quaternion = QuaternionAlgebra.multiply(this, other) - -public operator fun Quaternion.div(other: Quaternion): Quaternion = QuaternionAlgebra.divide(this, other) - -public fun Quaternion.power(number: Number): Quaternion = QuaternionAlgebra.power(this, number) - -/** - * Linear interpolation between [from] and [to] in spherical space - */ -public fun QuaternionAlgebra.slerp(from: Quaternion, to: Quaternion, fraction: Double): Quaternion = - (to / from).pow(fraction) * from - -public fun QuaternionAlgebra.angleBetween(q1: Quaternion, q2: Quaternion): Angle = (q1.conjugate * q2).theta - -public val Quaternion.inclination: Radians get() = asin(2 * (w * y - x * z)).radians - -public val Quaternion.azimuth: Angle get() = atan2(2 * (w * z + x * y), 1 - 2 * (y.pow(2) + z.pow(2))).radians.normalized() - -public infix fun Quaternion.dot(other: Quaternion): Double = w * other.w + x * other.x + y * other.y + z * other.z - - -private fun Quaternion.normalizedToEuler(): Float32Vector3D { - val roll = atan2(2 * y * w + 2 * x * z, 1 - 2 * y * y - 2 * z * z); - val pitch = atan2(2 * x * w - 2 * y * z, 1 - 2 * x * x - 2 * z * z); - val yaw = asin(2 * x * y + 2 * z * w); - - return Float32Vector3D(roll, pitch, yaw) -} - -/** - * Quaternion to XYZ Cardan angles - */ -public fun Quaternion.toEuler(): Float32Vector3D = if (QuaternionAlgebra.norm(this) == 0.0) { - Float32Space3D.zero -} else { - normalized().normalizedToEuler() -} \ No newline at end of file diff --git a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/vectorPrecision.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/vectorPrecision.kt index 7d3fc7867..dd82a2926 100644 --- a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/vectorPrecision.kt +++ b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/vectorPrecision.kt @@ -5,6 +5,11 @@ package space.kscience.kmath.geometry +import space.kscience.kmath.geometry.euclidean2d.Float64Space2D +import space.kscience.kmath.geometry.euclidean2d.Float64Vector2D +import space.kscience.kmath.geometry.euclidean3d.Float64Space3D +import space.kscience.kmath.geometry.euclidean3d.Float64Vector3D + /** * Vector equality within given [precision] (using [GeometrySpace.norm] provided by the space @@ -22,7 +27,7 @@ public fun > V.equalsVector( */ public fun Float64Vector2D.equalsVector( other: Float64Vector2D, - precision: Double = Euclidean3DSpace.defaultPrecision, + precision: Double = Float64Space2D.defaultPrecision, ): Boolean = equalsVector(Float64Space2D, other, precision) /** @@ -30,7 +35,7 @@ public fun Float64Vector2D.equalsVector( */ public fun Float64Vector3D.equalsVector( other: Float64Vector3D, - precision: Double = Euclidean3DSpace.defaultPrecision, + precision: Double = Float64Space3D.defaultPrecision, ): Boolean = equalsVector(Float64Space3D, other, precision) /** diff --git a/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/RotationTest.kt b/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/RotationTest.kt index 1d354bf72..7d1687ecb 100644 --- a/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/RotationTest.kt +++ b/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/RotationTest.kt @@ -6,6 +6,7 @@ package space.kscience.kmath.geometry import space.kscience.kmath.complex.Quaternion +import space.kscience.kmath.complex.QuaternionAlgebra import space.kscience.kmath.complex.normalized import space.kscience.kmath.geometry.euclidean3d.* import space.kscience.kmath.structures.Float64Buffer @@ -26,12 +27,31 @@ class RotationTest { } @Test - fun matrixConversion() { + fun matrixConversion() = with(QuaternionAlgebra){ val q = Quaternion(1.0, 2.0, -3.0, 4.0).normalized() val matrix = q.toRotationMatrix() + for (ro in listOf( + RotationOrder.XYZ, + RotationOrder.YXZ, + RotationOrder.ZXY, + RotationOrder.ZYX, + RotationOrder.YZX, + RotationOrder.XZY + )) { + val angles = AngleVector.fromRotationMatrix(matrix, ro) + + val reconstructed = Quaternion.fromEuler(angles, ro) + + if( reconstructed.w>0) { + assertBufferEquals(q, reconstructed) + } else{ + assertBufferEquals(q, -reconstructed) + } + } + assertBufferEquals(q, Quaternion.fromRotationMatrix(matrix)) } @@ -50,4 +70,5 @@ class RotationTest { val q1 = Quaternion.fromEuler(0.1.radians, 0.2.radians, 0.3.radians, RotationOrder.XYZ) assertBufferEquals(Float64Buffer(0.9818562, 0.0640713, 0.0911575, 0.1534393), q1) } + } \ No newline at end of file From 5196322b7a42ff9a629e4208fb0c0adac678ed4f Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sun, 13 Aug 2023 19:13:39 +0300 Subject: [PATCH 10/40] Update integration to use Attributes --- .../space/kscience/attributes/Attributes.kt | 8 ++ .../kscience/attributes/AttributesBuilder.kt | 7 +- .../kmath/commons/integration/CMIntegrator.kt | 19 ++--- .../kscience/kmath/commons/linear/CMMatrix.kt | 2 +- .../kscience/kmath/linear/LupDecomposition.kt | 9 +-- ...{MatrixFeatures.kt => matrixAttributes.kt} | 6 +- .../space/kscience/kmath/nd/StructureND.kt | 1 - .../kmath/functions/polynomialConstructors.kt | 7 +- .../kmath/integration/GaussIntegrator.kt | 34 +++++---- .../integration/GaussIntegratorRuleFactory.kt | 4 +- .../kscience/kmath/integration/Integrand.kt | 63 ++++++++-------- .../integration/MultivariateIntegrand.kt | 22 +++--- .../kmath/integration/SimpsonIntegrator.kt | 32 +++++--- .../kmath/integration/SplineIntegrator.kt | 22 ++++-- .../kmath/integration/UnivariateIntegrand.kt | 73 +++++++------------ .../kmath/integration/SimpsonIntegralTest.kt | 10 ++- .../kscience/kmath/geometry/testUtils.kt | 2 +- .../optimization/FunctionOptimization.kt | 2 +- .../core/LevenbergMarquardtAlgorithm.kt | 10 +-- 19 files changed, 173 insertions(+), 160 deletions(-) rename kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/{MatrixFeatures.kt => matrixAttributes.kt} (95%) diff --git a/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/Attributes.kt b/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/Attributes.kt index f93b6446a..705e61436 100644 --- a/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/Attributes.kt +++ b/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/Attributes.kt @@ -59,6 +59,14 @@ public fun > Attributes.withAttribute( public fun > Attributes.withAttribute(attribute: A): Attributes = withAttribute(attribute, Unit) +/** + * Create a new [Attributes] by modifying the current one + */ +public fun Attributes.modify(block: AttributesBuilder.() -> Unit): Attributes = Attributes { + from(this@modify) + block() +} + /** * Create new [Attributes] by removing [attribute] key */ diff --git a/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/AttributesBuilder.kt b/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/AttributesBuilder.kt index 588c789f5..d0aed08c9 100644 --- a/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/AttributesBuilder.kt +++ b/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/AttributesBuilder.kt @@ -8,7 +8,9 @@ package space.kscience.attributes /** * A safe builder for [Attributes] */ -public class AttributesBuilder internal constructor(private val map: MutableMap, Any> = mutableMapOf()) { +public class AttributesBuilder internal constructor(private val map: MutableMap, Any>) { + + public constructor() : this(mutableMapOf()) @Suppress("UNCHECKED_CAST") public operator fun get(attribute: Attribute): T? = map[attribute] as? T @@ -49,4 +51,5 @@ public fun AttributesBuilder( attributes: Attributes, ): AttributesBuilder = AttributesBuilder(attributes.content.toMutableMap()) -public fun Attributes(builder: AttributesBuilder.() -> Unit): Attributes = AttributesBuilder().apply(builder).build() \ No newline at end of file +public inline fun Attributes(builder: AttributesBuilder.() -> Unit): Attributes = + AttributesBuilder().apply(builder).build() \ No newline at end of file diff --git a/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/integration/CMIntegrator.kt b/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/integration/CMIntegrator.kt index c3e581d31..82a371100 100644 --- a/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/integration/CMIntegrator.kt +++ b/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/integration/CMIntegrator.kt @@ -20,10 +20,9 @@ public class CMIntegrator( override fun process(integrand: UnivariateIntegrand): UnivariateIntegrand { val integrator = integratorBuilder(integrand) - val maxCalls = integrand.getFeature()?.maxCalls ?: defaultMaxCalls + val maxCalls = integrand[IntegrandMaxCalls] ?: defaultMaxCalls val remainingCalls = maxCalls - integrand.calls - val range = integrand.getFeature()?.range - ?: error("Integration range is not provided") + val range = integrand[IntegrationRange] ?: error("Integration range is not provided") val res = integrator.integrate(remainingCalls, integrand.function, range.start, range.endInclusive) return integrand + @@ -39,11 +38,9 @@ public class CMIntegrator( * Create a Simpson integrator based on [SimpsonIntegrator] */ public fun simpson(defaultMaxCalls: Int = 200): CMIntegrator = CMIntegrator(defaultMaxCalls) { integrand -> - val absoluteAccuracy = integrand.getFeature()?.accuracy - ?: SimpsonIntegrator.DEFAULT_ABSOLUTE_ACCURACY - val relativeAccuracy = integrand.getFeature()?.accuracy - ?: SimpsonIntegrator.DEFAULT_ABSOLUTE_ACCURACY - val iterations = integrand.getFeature()?.range + val absoluteAccuracy = integrand[IntegrandAbsoluteAccuracy] ?: SimpsonIntegrator.DEFAULT_ABSOLUTE_ACCURACY + val relativeAccuracy = integrand[IntegrandRelativeAccuracy] ?: SimpsonIntegrator.DEFAULT_ABSOLUTE_ACCURACY + val iterations = integrand[IntegrandIterationsRange] ?: SimpsonIntegrator.DEFAULT_MIN_ITERATIONS_COUNT..SimpsonIntegrator.SIMPSON_MAX_ITERATIONS_COUNT @@ -55,11 +52,11 @@ public class CMIntegrator( */ public fun legandre(numPoints: Int, defaultMaxCalls: Int = numPoints * 5): CMIntegrator = CMIntegrator(defaultMaxCalls) { integrand -> - val absoluteAccuracy = integrand.getFeature()?.accuracy + val absoluteAccuracy = integrand[IntegrandAbsoluteAccuracy] ?: IterativeLegendreGaussIntegrator.DEFAULT_ABSOLUTE_ACCURACY - val relativeAccuracy = integrand.getFeature()?.accuracy + val relativeAccuracy = integrand[IntegrandRelativeAccuracy] ?: IterativeLegendreGaussIntegrator.DEFAULT_ABSOLUTE_ACCURACY - val iterations = integrand.getFeature()?.range + val iterations = integrand[IntegrandIterationsRange] ?: IterativeLegendreGaussIntegrator.DEFAULT_MIN_ITERATIONS_COUNT..IterativeLegendreGaussIntegrator.DEFAULT_MAX_ITERATIONS_COUNT IterativeLegendreGaussIntegrator( 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 ebf4dc65a..d29650e3f 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 @@ -135,7 +135,7 @@ public object CMLinearSpace : LinearSpace { override val r: Matrix by lazy> { CMMatrix(qr.r).withAttribute(UpperTriangular) } } - SingularValueDecompositionAttribute::class -> object : SingularValueDecompositionAttribute { + SVDAttribute::class -> object : SVDAttribute { private val sv by lazy { SingularValueDecomposition(origin) } override val u: Matrix by lazy { CMMatrix(sv.u) } override val s: Matrix by lazy { CMMatrix(sv.s) } 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 6ccafa5f1..9fe8397d8 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 @@ -13,10 +13,6 @@ import space.kscience.attributes.safeTypeOf import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.operations.* import space.kscience.kmath.structures.* -import space.kscience.kmath.structures.BufferAccessor2D -import space.kscience.kmath.structures.Float64Buffer -import space.kscience.kmath.structures.MutableBuffer -import space.kscience.kmath.structures.MutableBufferFactory /** * Matrices with this feature support LU factorization with partial pivoting: *[p] · a = [l] · [u]* where @@ -197,8 +193,7 @@ public fun > LinearSpace>.lup( public fun LinearSpace.lup( matrix: Matrix, singularityThreshold: Double = 1e-11, -): LupDecomposition = - lup(::Float64Buffer, matrix) { it < singularityThreshold } +): LupDecomposition = lup(matrix) { it < singularityThreshold } internal fun > LinearSpace.solve( lup: LupDecomposition, @@ -265,4 +260,4 @@ public fun , F : Field> LinearSpace.lupSolver( } public fun LinearSpace.lupSolver(singularityThreshold: Double = 1e-11): LinearSolver = - lupSolver(::Float64Buffer) { it < singularityThreshold } + lupSolver { it < singularityThreshold } diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixFeatures.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/matrixAttributes.kt similarity index 95% rename from kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixFeatures.kt rename to kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/matrixAttributes.kt index d109ef1bc..5bb35edef 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixFeatures.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/matrixAttributes.kt @@ -163,12 +163,12 @@ public interface SingularValueDecomposition { * * @param T the type of matrices' items. */ -public class SingularValueDecompositionAttribute(type: SafeType>) : +public class SVDAttribute(type: SafeType>) : PolymorphicAttribute>(type), MatrixAttribute> -public val MatrixOperations.SVD: SingularValueDecompositionAttribute - get() = SingularValueDecompositionAttribute(safeTypeOf()) +public val MatrixOperations.SVD: SVDAttribute + get() = SVDAttribute(safeTypeOf()) //TODO add sparse matrix feature diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/StructureND.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/StructureND.kt index 993349487..bc86f62ae 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/StructureND.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/StructureND.kt @@ -240,7 +240,6 @@ public interface MutableStructureND : StructureND { * Set value at specified indices */ @PerformancePitfall -@Deprecated("") public operator fun MutableStructureND.set(vararg index: Int, value: T) { set(index, value) } \ No newline at end of file diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/polynomialConstructors.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/polynomialConstructors.kt index 4e9791a87..e07ff764c 100644 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/polynomialConstructors.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/polynomialConstructors.kt @@ -20,9 +20,4 @@ public fun Polynomial(coefficients: List, reverse: Boolean = false): Poly */ @Suppress("FunctionName") public fun Polynomial(vararg coefficients: C, reverse: Boolean = false): Polynomial = - Polynomial(with(coefficients) { if (reverse) reversed() else toList() }) - -/** - * Represents [this] constant as a [Polynomial]. - */ -public fun C.asPolynomial() : Polynomial = Polynomial(listOf(this)) \ No newline at end of file + Polynomial(with(coefficients) { if (reverse) reversed() else toList() }) \ No newline at end of file diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/GaussIntegrator.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/GaussIntegrator.kt index f2ac0a296..f0aab2c6c 100644 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/GaussIntegrator.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/GaussIntegrator.kt @@ -4,6 +4,7 @@ */ package space.kscience.kmath.integration +import space.kscience.attributes.AttributesBuilder import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.operations.Field import space.kscience.kmath.structures.Buffer @@ -11,14 +12,14 @@ import space.kscience.kmath.structures.asBuffer import space.kscience.kmath.structures.indices /** - * A simple one-pass integrator based on Gauss rule - * Following integrand features are accepted: + * A simple one-pass integrator based on Gauss rule. + * The following integrand features are accepted: * * * [GaussIntegratorRuleFactory]—a factory for computing the Gauss integration rule. By default, uses * [GaussLegendreRuleFactory]. * * [IntegrationRange]—the univariate range of integration. By default, uses `0..1` interval. * * [IntegrandMaxCalls]—the maximum number of function calls during integration. For non-iterative rules, always - * uses the maximum number of points. By default, uses 10 points. + * use the maximum number of points. By default, uses 10 points. * * [UnivariateIntegrandRanges]—set of ranges and number of points per range. Defaults to given * [IntegrationRange] and [IntegrandMaxCalls]. */ @@ -27,11 +28,11 @@ public class GaussIntegrator( ) : UnivariateIntegrator { private fun buildRule(integrand: UnivariateIntegrand): Pair, Buffer> { - val factory = integrand.getFeature() ?: GaussLegendreRuleFactory - val predefinedRanges = integrand.getFeature() + val factory = integrand[GaussIntegratorRuleFactory] ?: GaussLegendreRuleFactory + val predefinedRanges = integrand[UnivariateIntegrandRanges] if (predefinedRanges == null || predefinedRanges.ranges.isEmpty()) { - val numPoints = integrand.getFeature()?.maxCalls ?: 100 - val range = integrand.getFeature()?.range ?: 0.0..1.0 + val numPoints = integrand[IntegrandMaxCalls] ?: 100 + val range = integrand[IntegrationRange] ?: 0.0..1.0 return factory.build(numPoints, range) } else { val ranges = predefinedRanges.ranges @@ -66,7 +67,10 @@ public class GaussIntegrator( c = t - res - y res = t } - return integrand + IntegrandValue(res) + IntegrandCallsPerformed(integrand.calls + points.size) + return integrand.modify { + value(res) + IntegrandCallsPerformed(integrand.calls + points.size) + } } public companion object @@ -88,7 +92,7 @@ public fun GaussIntegrator.integrate( range: ClosedRange, order: Int = 10, intervals: Int = 10, - vararg features: IntegrandFeature, + attributesBuilder: AttributesBuilder.() -> Unit, function: (Double) -> T, ): UnivariateIntegrand { require(range.endInclusive > range.start) { "The range upper bound should be higher than lower bound" } @@ -100,11 +104,13 @@ public fun GaussIntegrator.integrate( ) return process( UnivariateIntegrand( - function, - IntegrationRange(range), - GaussLegendreRuleFactory, - ranges, - *features + attributeBuilder = { + IntegrationRange(range) + GaussIntegratorRuleFactory(GaussLegendreRuleFactory) + UnivariateIntegrandRanges(ranges) + attributesBuilder() + }, + function = function, ) ) } \ No newline at end of file diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/GaussIntegratorRuleFactory.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/GaussIntegratorRuleFactory.kt index 975fcd3a8..91b3811c0 100644 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/GaussIntegratorRuleFactory.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/GaussIntegratorRuleFactory.kt @@ -12,10 +12,10 @@ import space.kscience.kmath.structures.asBuffer import kotlin.math.ulp import kotlin.native.concurrent.ThreadLocal -public interface GaussIntegratorRuleFactory : IntegrandFeature { +public interface GaussIntegratorRuleFactory { public fun build(numPoints: Int): Pair, Buffer> - public companion object { + public companion object: IntegrandAttribute{ public fun double(numPoints: Int, range: ClosedRange): Pair, Buffer> = GaussLegendreRuleFactory.build(numPoints, range) } diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/Integrand.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/Integrand.kt index 40fe78898..09c32aeff 100644 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/Integrand.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/Integrand.kt @@ -5,44 +5,49 @@ package space.kscience.kmath.integration -import space.kscience.kmath.misc.Feature -import space.kscience.kmath.misc.FeatureSet -import space.kscience.kmath.misc.Featured -import kotlin.reflect.KClass +import space.kscience.attributes.* +import kotlin.reflect.typeOf -public interface IntegrandFeature : Feature { - override fun toString(): String +public interface IntegrandAttribute : Attribute + +public interface Integrand : AttributeContainer { + + public fun modify(block: AttributesBuilder.() -> Unit): Integrand + + public fun withAttribute(attribute: Attribute, value: A): Integrand + + public companion object } -public interface Integrand : Featured { - public val features: FeatureSet - override fun getFeature(type: KClass): T? = features.getFeature(type) +public operator fun Integrand<*>.get(attribute: Attribute): T? = attributes[attribute] + +public class IntegrandValue(type: SafeType) : PolymorphicAttribute(type), IntegrandAttribute + +public inline val Integrand.Value: IntegrandValue get() = IntegrandValue(safeTypeOf()) + +public fun AttributesBuilder.value(value: T){ + val type: SafeType = typeOf() + IntegrandValue(type).invoke(value) } -public inline fun Integrand.getFeature(): T? = getFeature(T::class) +/** + * Value of the integrand if it is present or null + */ +public inline val Integrand.valueOrNull: T? get() = attributes[Value] -public class IntegrandValue(public val value: T) : IntegrandFeature { - override fun toString(): String = "Value($value)" -} +/** + * Value of the integrand or error + */ +public inline val Integrand.value: T get() = valueOrNull ?: error("No value in the integrand") -public class IntegrandRelativeAccuracy(public val accuracy: Double) : IntegrandFeature { - override fun toString(): String = "TargetRelativeAccuracy($accuracy)" -} +public object IntegrandRelativeAccuracy : IntegrandAttribute -public class IntegrandAbsoluteAccuracy(public val accuracy: Double) : IntegrandFeature { - override fun toString(): String = "TargetAbsoluteAccuracy($accuracy)" -} +public object IntegrandAbsoluteAccuracy : IntegrandAttribute -public class IntegrandCallsPerformed(public val calls: Int) : IntegrandFeature { - override fun toString(): String = "Calls($calls)" -} +public object IntegrandCallsPerformed : IntegrandAttribute -public val Integrand.calls: Int get() = getFeature()?.calls ?: 0 +public val Integrand<*>.calls: Int get() = attributes[IntegrandCallsPerformed] ?: 0 -public class IntegrandMaxCalls(public val maxCalls: Int) : IntegrandFeature { - override fun toString(): String = "MaxCalls($maxCalls)" -} +public object IntegrandMaxCalls : IntegrandAttribute -public class IntegrandIterationsRange(public val range: IntRange) : IntegrandFeature { - override fun toString(): String = "Iterations(${range.first}..${range.last})" -} +public object IntegrandIterationsRange : IntegrandAttribute diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/MultivariateIntegrand.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/MultivariateIntegrand.kt index 53a563086..a3b2ed44f 100644 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/MultivariateIntegrand.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/MultivariateIntegrand.kt @@ -5,22 +5,22 @@ package space.kscience.kmath.integration +import space.kscience.attributes.* import space.kscience.kmath.linear.Point -import space.kscience.kmath.misc.FeatureSet -public class MultivariateIntegrand internal constructor( - override val features: FeatureSet, +public class MultivariateIntegrand internal constructor( + override val attributes: Attributes, public val function: (Point) -> T, -) : Integrand { +) : Integrand { - public operator fun plus(feature: F): MultivariateIntegrand = - MultivariateIntegrand(features.with(feature), function) + override fun modify(block: AttributesBuilder.() -> Unit): MultivariateIntegrand = + MultivariateIntegrand(attributes.modify(block), function) + + override fun withAttribute(attribute: Attribute, value: A): MultivariateIntegrand = + MultivariateIntegrand(attributes.withAttribute(attribute, value), function) } -@Suppress("FunctionName") public fun MultivariateIntegrand( - vararg features: IntegrandFeature, + attributeBuilder: AttributesBuilder.() -> Unit, function: (Point) -> T, -): MultivariateIntegrand = MultivariateIntegrand(FeatureSet.of(*features), function) - -public val MultivariateIntegrand.value: T? get() = getFeature>()?.value +): MultivariateIntegrand = MultivariateIntegrand(Attributes(attributeBuilder), function) diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/SimpsonIntegrator.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/SimpsonIntegrator.kt index 35ce82351..16d71a743 100644 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/SimpsonIntegrator.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/SimpsonIntegrator.kt @@ -45,16 +45,22 @@ public class SimpsonIntegrator( } override fun process(integrand: UnivariateIntegrand): UnivariateIntegrand { - val ranges = integrand.getFeature() + val ranges = integrand[UnivariateIntegrandRanges] return if (ranges != null) { val res = algebra.sum(ranges.ranges.map { integrateRange(integrand, it.first, it.second) }) - integrand + IntegrandValue(res) + IntegrandCallsPerformed(integrand.calls + ranges.ranges.sumOf { it.second }) + integrand.modify { + value(res) + IntegrandCallsPerformed(integrand.calls + ranges.ranges.sumOf { it.second }) + } } else { - val numPoints = integrand.getFeature()?.maxCalls ?: 100 + val numPoints = integrand[IntegrandMaxCalls] ?: 100 require(numPoints >= 4) { "Simpson integrator requires at least 4 nodes" } - val range = integrand.getFeature()?.range ?: 0.0..1.0 + val range = integrand[IntegrationRange] ?: 0.0..1.0 val res = integrateRange(integrand, range, numPoints) - integrand + IntegrandValue(res) + IntegrandCallsPerformed(integrand.calls + numPoints) + integrand.modify { + value(res) + IntegrandCallsPerformed(integrand.calls + numPoints) + } } } } @@ -91,16 +97,22 @@ public object DoubleSimpsonIntegrator : UnivariateIntegrator { } override fun process(integrand: UnivariateIntegrand): UnivariateIntegrand { - val ranges = integrand.getFeature() + val ranges = integrand[UnivariateIntegrandRanges] return if (ranges != null) { val res = ranges.ranges.sumOf { integrateRange(integrand, it.first, it.second) } - integrand + IntegrandValue(res) + IntegrandCallsPerformed(integrand.calls + ranges.ranges.sumOf { it.second }) + integrand.modify { + value(res) + IntegrandCallsPerformed(integrand.calls + ranges.ranges.sumOf { it.second }) + } } else { - val numPoints = integrand.getFeature()?.maxCalls ?: 100 + val numPoints = integrand[IntegrandMaxCalls] ?: 100 require(numPoints >= 4) { "Simpson integrator requires at least 4 nodes" } - val range = integrand.getFeature()?.range ?: 0.0..1.0 + val range = integrand[IntegrationRange] ?: 0.0..1.0 val res = integrateRange(integrand, range, numPoints) - integrand + IntegrandValue(res) + IntegrandCallsPerformed(integrand.calls + numPoints) + integrand.modify { + value(res) + IntegrandCallsPerformed(integrand.calls + numPoints) + } } } } diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/SplineIntegrator.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/SplineIntegrator.kt index 1306e501f..bbec9ff45 100644 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/SplineIntegrator.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/SplineIntegrator.kt @@ -55,12 +55,12 @@ public class SplineIntegrator>( public val bufferFactory: MutableBufferFactory, ) : UnivariateIntegrator { override fun process(integrand: UnivariateIntegrand): UnivariateIntegrand = algebra { - val range = integrand.getFeature()?.range ?: 0.0..1.0 + val range = integrand[IntegrationRange] ?: 0.0..1.0 val interpolator: PolynomialInterpolator = SplineInterpolator(algebra, bufferFactory) - val nodes: Buffer = integrand.getFeature()?.nodes ?: run { - val numPoints = integrand.getFeature()?.maxCalls ?: 100 + val nodes: Buffer = integrand[UnivariateIntegrationNodes] ?: run { + val numPoints = integrand[IntegrandMaxCalls] ?: 100 val step = (range.endInclusive - range.start) / (numPoints - 1) Float64Buffer(numPoints) { i -> range.start + i * step } } @@ -71,7 +71,10 @@ public class SplineIntegrator>( values ) val res = polynomials.integrate(algebra, number(range.start)..number(range.endInclusive)) - integrand + IntegrandValue(res) + IntegrandCallsPerformed(integrand.calls + nodes.size) + integrand.modify { + value(res) + IntegrandCallsPerformed(integrand.calls + nodes.size) + } } } @@ -84,11 +87,11 @@ public class SplineIntegrator>( @UnstableKMathAPI public object DoubleSplineIntegrator : UnivariateIntegrator { override fun process(integrand: UnivariateIntegrand): UnivariateIntegrand { - val range = integrand.getFeature()?.range ?: 0.0..1.0 + val range = integrand[IntegrationRange] ?: 0.0..1.0 val interpolator: PolynomialInterpolator = SplineInterpolator(Float64Field, ::Float64Buffer) - val nodes: Buffer = integrand.getFeature()?.nodes ?: run { - val numPoints = integrand.getFeature()?.maxCalls ?: 100 + val nodes: Buffer = integrand[UnivariateIntegrationNodes] ?: run { + val numPoints = integrand[IntegrandMaxCalls] ?: 100 val step = (range.endInclusive - range.start) / (numPoints - 1) Float64Buffer(numPoints) { i -> range.start + i * step } } @@ -96,7 +99,10 @@ public object DoubleSplineIntegrator : UnivariateIntegrator { val values = nodes.mapToBuffer(::Float64Buffer) { integrand.function(it) } val polynomials = interpolator.interpolatePolynomials(nodes, values) val res = polynomials.integrate(Float64Field, range) - return integrand + IntegrandValue(res) + IntegrandCallsPerformed(integrand.calls + nodes.size) + return integrand.modify { + value(res) + IntegrandCallsPerformed(integrand.calls + nodes.size) + } } } diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/UnivariateIntegrand.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/UnivariateIntegrand.kt index e29a6c881..3c30f303e 100644 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/UnivariateIntegrand.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/UnivariateIntegrand.kt @@ -5,36 +5,38 @@ package space.kscience.kmath.integration +import space.kscience.attributes.* import space.kscience.kmath.UnstableKMathAPI -import space.kscience.kmath.misc.FeatureSet import space.kscience.kmath.structures.Buffer import space.kscience.kmath.structures.Float64Buffer public class UnivariateIntegrand internal constructor( - override val features: FeatureSet, + override val attributes: Attributes, public val function: (Double) -> T, -) : Integrand { - public operator fun plus(feature: F): UnivariateIntegrand = - UnivariateIntegrand(features.with(feature), function) +) : Integrand { + + override fun withAttribute(attribute: Attribute, value: A): UnivariateIntegrand = + UnivariateIntegrand(attributes.withAttribute(attribute, value), function) + + override fun modify(block: AttributesBuilder.() -> Unit): UnivariateIntegrand = + UnivariateIntegrand(attributes.modify(block), function) } -@Suppress("FunctionName") public fun UnivariateIntegrand( + attributeBuilder: AttributesBuilder.() -> Unit, function: (Double) -> T, - vararg features: IntegrandFeature, -): UnivariateIntegrand = UnivariateIntegrand(FeatureSet.of(*features), function) +): UnivariateIntegrand = UnivariateIntegrand(Attributes(attributeBuilder), function) public typealias UnivariateIntegrator = Integrator> -public class IntegrationRange(public val range: ClosedRange) : IntegrandFeature { - override fun toString(): String = "Range(${range.start}..${range.endInclusive})" -} +public object IntegrationRange : IntegrandAttribute> + /** * Set of univariate integration ranges. First components correspond to the ranges themselves, second components to - * number of integration nodes per range. + * the number of integration nodes per range. */ -public class UnivariateIntegrandRanges(public val ranges: List, Int>>) : IntegrandFeature { +public class UnivariateIntegrandRanges(public val ranges: List, Int>>) { public constructor(vararg pairs: Pair, Int>) : this(pairs.toList()) override fun toString(): String { @@ -43,45 +45,25 @@ public class UnivariateIntegrandRanges(public val ranges: List } -public class UnivariateIntegrationNodes(public val nodes: Buffer) : IntegrandFeature { - public constructor(vararg nodes: Double) : this(Float64Buffer(nodes)) +public object UnivariateIntegrationNodes : IntegrandAttribute> - override fun toString(): String = "UnivariateNodes($nodes)" +public fun AttributesBuilder.integrationNodes(vararg nodes: Double) { + UnivariateIntegrationNodes(Float64Buffer(nodes)) } - -/** - * Value of the integrand if it is present or null - */ -public val UnivariateIntegrand.valueOrNull: T? get() = getFeature>()?.value - -/** - * Value of the integrand or error - */ -public val UnivariateIntegrand.value: T get() = valueOrNull ?: error("No value in the integrand") - /** * A shortcut method to integrate a [function] with additional [features]. Range must be provided in features. * The [function] is placed in the end position to allow passing a lambda. */ @UnstableKMathAPI public fun UnivariateIntegrator.integrate( - vararg features: IntegrandFeature, + attributesBuilder: AttributesBuilder.() -> Unit, function: (Double) -> T, -): UnivariateIntegrand = process(UnivariateIntegrand(function, *features)) - -/** - * A shortcut method to integrate a [function] in [range] with additional [features]. - * The [function] is placed in the end position to allow passing a lambda. - */ -@UnstableKMathAPI -public fun UnivariateIntegrator.integrate( - range: ClosedRange, - vararg features: IntegrandFeature, - function: (Double) -> T, -): UnivariateIntegrand = process(UnivariateIntegrand(function, IntegrationRange(range), *features)) +): UnivariateIntegrand = process(UnivariateIntegrand(attributesBuilder, function)) /** * A shortcut method to integrate a [function] in [range] with additional features. @@ -90,13 +72,12 @@ public fun UnivariateIntegrator.integrate( @UnstableKMathAPI public fun UnivariateIntegrator.integrate( range: ClosedRange, - featureBuilder: MutableList.() -> Unit = {}, + attributeBuilder: AttributesBuilder.() -> Unit = {}, function: (Double) -> T, ): UnivariateIntegrand { - //TODO use dedicated feature builder class instead or add extensions to MutableList - val features = buildList { - featureBuilder() - add(IntegrationRange(range)) + val attributes = Attributes { + IntegrationRange(range) + attributeBuilder() } - return process(UnivariateIntegrand(function, *features.toTypedArray())) + return process(UnivariateIntegrand(attributes, function)) } diff --git a/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/integration/SimpsonIntegralTest.kt b/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/integration/SimpsonIntegralTest.kt index f5a79cdea..aafabf302 100644 --- a/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/integration/SimpsonIntegralTest.kt +++ b/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/integration/SimpsonIntegralTest.kt @@ -16,7 +16,10 @@ import kotlin.test.assertEquals class SimpsonIntegralTest { @Test fun gaussSin() { - val res = Float64Field.simpsonIntegrator.integrate(0.0..2 * PI, IntegrandMaxCalls(5)) { x -> + val res = Float64Field.simpsonIntegrator.integrate( + 0.0..2 * PI, + { IntegrandMaxCalls(5) } + ) { x -> sin(x) } assertEquals(0.0, res.value, 1e-2) @@ -24,7 +27,10 @@ class SimpsonIntegralTest { @Test fun gaussUniform() { - val res = Float64Field.simpsonIntegrator.integrate(35.0..100.0, IntegrandMaxCalls(20)) { x -> + val res = Float64Field.simpsonIntegrator.integrate( + 35.0..100.0, + { IntegrandMaxCalls(20) } + ) { x -> if (x in 30.0..50.0) { 1.0 } else { diff --git a/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/testUtils.kt b/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/testUtils.kt index ac72af10c..abc57eb42 100644 --- a/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/testUtils.kt +++ b/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/testUtils.kt @@ -27,7 +27,7 @@ fun grid( return xs.flatMap { x -> ys.map { y -> x to y } } } -fun assertVectorEquals(expected: DoubleVector2D, actual: DoubleVector2D, absoluteTolerance: Double = 1e-6) { +fun assertVectorEquals(expected: DoubleVector2D, actual: DoubleVector2D, absoluteTolerance: Double = 1e-3) { assertEquals(expected.x, actual.x, absoluteTolerance) assertEquals(expected.y, actual.y, absoluteTolerance) } diff --git a/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/FunctionOptimization.kt b/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/FunctionOptimization.kt index fe5f0ca8a..8025428e6 100644 --- a/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/FunctionOptimization.kt +++ b/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/FunctionOptimization.kt @@ -53,7 +53,7 @@ public class OptimizationPrior(type: SafeType): PolymorphicAttribute>(safeTypeOf()), Attribute> -public val FunctionOptimization.Companion.Optimization get() = +//public val FunctionOptimization.Companion.Optimization get() = public fun FunctionOptimization.withFeatures( diff --git a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/LevenbergMarquardtAlgorithm.kt b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/LevenbergMarquardtAlgorithm.kt index fc87ad1f3..8011b332e 100644 --- a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/LevenbergMarquardtAlgorithm.kt +++ b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/LevenbergMarquardtAlgorithm.kt @@ -6,7 +6,7 @@ package space.kscience.kmath.tensors.core import space.kscience.kmath.PerformancePitfall -import space.kscience.kmath.linear.transpose +import space.kscience.kmath.linear.transposed import space.kscience.kmath.nd.* import kotlin.math.abs import kotlin.math.max @@ -139,7 +139,7 @@ public fun DoubleTensorAlgebra.levenbergMarquardt(inputData: LMInput): LMResultI if (inputData.nargin < 5) { weight = fromArray( ShapeND(intArrayOf(1, 1)), - doubleArrayOf((inputData.realValues.transpose().dot(inputData.realValues)).as1D()[0]) + doubleArrayOf((inputData.realValues.transposed dot inputData.realValues).as1D()[0]) ).as2D() } @@ -266,12 +266,12 @@ public fun DoubleTensorAlgebra.levenbergMarquardt(inputData: LMInput): LMResultI settings.funcCalls += 1 // val tmp = deltaY.times(weight) - var X2Try = deltaY.as2D().transpose().dot(deltaY.times(weight)) // Chi-squared error criteria + var X2Try = deltaY.as2D().transposed dot deltaY.times(weight) // Chi-squared error criteria val alpha = 1.0 if (updateType == 2) { // Quadratic // One step of quadratic line update in the h direction for minimum X2 - val alphaTensor = (jtWdy.transpose() dot h) / ((X2Try - x2) / 2.0 + 2 * (jtWdy.transpose() dot h)) + val alphaTensor = (jtWdy.transposed dot h) / ((X2Try - x2) / 2.0 + 2 * (jtWdy.transposed dot h)) h = h dot alphaTensor pTry = (p + h).as2D() // update only [idx] elements pTry = smallestElementComparison( @@ -289,7 +289,7 @@ public fun DoubleTensorAlgebra.levenbergMarquardt(inputData: LMInput): LMResultI ) // residual error using p_try settings.funcCalls += 1 - X2Try = deltaY.as2D().transpose() dot deltaY * weight // Chi-squared error criteria + X2Try = deltaY.as2D().transposed dot deltaY * weight // Chi-squared error criteria } val rho = when (updateType) { // Nielsen From 9da14089e03939d940000df5a9628101be5dc01a Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Mon, 14 Aug 2023 10:06:23 +0300 Subject: [PATCH 11/40] Update integration to use Attributes --- .../integration/CMGaussRuleIntegrator.kt | 19 +++++----- .../kmath/commons/integration/CMIntegrator.kt | 14 ++++---- .../kscience/kmath/integration/Integrand.kt | 24 ++++++++----- .../integration/MultivariateIntegrand.kt | 13 +++---- .../kmath/integration/UnivariateIntegrand.kt | 36 +++++++++++-------- 5 files changed, 62 insertions(+), 44 deletions(-) diff --git a/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/integration/CMGaussRuleIntegrator.kt b/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/integration/CMGaussRuleIntegrator.kt index 263463d37..7befc60a3 100644 --- a/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/integration/CMGaussRuleIntegrator.kt +++ b/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/integration/CMGaussRuleIntegrator.kt @@ -13,26 +13,29 @@ import space.kscience.kmath.integration.* */ public class CMGaussRuleIntegrator( private val numpoints: Int, - private var type: GaussRule = GaussRule.LEGANDRE, + private var type: GaussRule = GaussRule.LEGENDRE, ) : UnivariateIntegrator { override fun process(integrand: UnivariateIntegrand): UnivariateIntegrand { - val range = integrand.getFeature()?.range + val range = integrand[IntegrationRange] ?: error("Integration range is not provided") val integrator: GaussIntegrator = getIntegrator(range) //TODO check performance val res: Double = integrator.integrate(integrand.function) - return integrand + IntegrandValue(res) + IntegrandCallsPerformed(integrand.calls + numpoints) + return integrand.modify { + IntegrandValue(res) + IntegrandCallsPerformed(integrand.calls + numpoints) + } } private fun getIntegrator(range: ClosedRange): GaussIntegrator { return when (type) { - GaussRule.LEGANDRE -> factory.legendre( + GaussRule.LEGENDRE -> factory.legendre( numpoints, range.start, range.endInclusive ) - GaussRule.LEGANDREHP -> factory.legendreHighPrecision( + GaussRule.LEGENDREHP -> factory.legendreHighPrecision( numpoints, range.start, range.endInclusive @@ -65,7 +68,7 @@ public class CMGaussRuleIntegrator( } public enum class GaussRule { - UNIFORM, LEGANDRE, LEGANDREHP + UNIFORM, LEGENDRE, LEGENDREHP } public companion object { @@ -74,10 +77,10 @@ public class CMGaussRuleIntegrator( public fun integrate( range: ClosedRange, numPoints: Int = 100, - type: GaussRule = GaussRule.LEGANDRE, + type: GaussRule = GaussRule.LEGENDRE, function: (Double) -> Double, ): Double = CMGaussRuleIntegrator(numPoints, type).process( - UnivariateIntegrand(function, IntegrationRange(range)) + UnivariateIntegrand({IntegrationRange(range)},function) ).value } } \ No newline at end of file diff --git a/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/integration/CMIntegrator.kt b/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/integration/CMIntegrator.kt index 82a371100..7a807c25f 100644 --- a/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/integration/CMIntegrator.kt +++ b/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/integration/CMIntegrator.kt @@ -9,13 +9,14 @@ import org.apache.commons.math3.analysis.integration.IterativeLegendreGaussInteg import org.apache.commons.math3.analysis.integration.SimpsonIntegrator import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.integration.* +import org.apache.commons.math3.analysis.integration.UnivariateIntegrator as CMUnivariateIntegrator /** * Integration wrapper for Common-maths UnivariateIntegrator */ public class CMIntegrator( private val defaultMaxCalls: Int = 200, - public val integratorBuilder: (Integrand) -> org.apache.commons.math3.analysis.integration.UnivariateIntegrator, + public val integratorBuilder: (Integrand) -> CMUnivariateIntegrator, ) : UnivariateIntegrator { override fun process(integrand: UnivariateIntegrand): UnivariateIntegrand { @@ -25,11 +26,12 @@ public class CMIntegrator( val range = integrand[IntegrationRange] ?: error("Integration range is not provided") val res = integrator.integrate(remainingCalls, integrand.function, range.start, range.endInclusive) - return integrand + - IntegrandValue(res) + - IntegrandAbsoluteAccuracy(integrator.absoluteAccuracy) + - IntegrandRelativeAccuracy(integrator.relativeAccuracy) + - IntegrandCallsPerformed(integrator.evaluations + integrand.calls) + return integrand.modify { + value(res) + IntegrandAbsoluteAccuracy(integrator.absoluteAccuracy) + IntegrandRelativeAccuracy(integrator.relativeAccuracy) + IntegrandCallsPerformed(integrator.evaluations + integrand.calls) + } } diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/Integrand.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/Integrand.kt index 09c32aeff..9e2b8d0d7 100644 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/Integrand.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/Integrand.kt @@ -5,13 +5,17 @@ package space.kscience.kmath.integration -import space.kscience.attributes.* -import kotlin.reflect.typeOf +import space.kscience.attributes.Attribute +import space.kscience.attributes.AttributeContainer +import space.kscience.attributes.AttributesBuilder +import space.kscience.attributes.SafeType public interface IntegrandAttribute : Attribute public interface Integrand : AttributeContainer { + public val type: SafeType + public fun modify(block: AttributesBuilder.() -> Unit): Integrand public fun withAttribute(attribute: Attribute, value: A): Integrand @@ -21,19 +25,21 @@ public interface Integrand : AttributeContainer { public operator fun Integrand<*>.get(attribute: Attribute): T? = attributes[attribute] -public class IntegrandValue(type: SafeType) : PolymorphicAttribute(type), IntegrandAttribute +public sealed class IntegrandValue private constructor(): IntegrandAttribute{ + public companion object: IntegrandValue(){ + @Suppress("UNCHECKED_CAST") + public fun forType(): IntegrandValue = this as IntegrandValue + } +} -public inline val Integrand.Value: IntegrandValue get() = IntegrandValue(safeTypeOf()) - -public fun AttributesBuilder.value(value: T){ - val type: SafeType = typeOf() - IntegrandValue(type).invoke(value) +public fun AttributesBuilder.value(value: T) { + IntegrandValue.forType().invoke(value) } /** * Value of the integrand if it is present or null */ -public inline val Integrand.valueOrNull: T? get() = attributes[Value] +public inline val Integrand.valueOrNull: T? get() = attributes[IntegrandValue.forType()] /** * Value of the integrand or error diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/MultivariateIntegrand.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/MultivariateIntegrand.kt index a3b2ed44f..f8937efd2 100644 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/MultivariateIntegrand.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/MultivariateIntegrand.kt @@ -8,19 +8,20 @@ package space.kscience.kmath.integration import space.kscience.attributes.* import space.kscience.kmath.linear.Point -public class MultivariateIntegrand internal constructor( +public class MultivariateIntegrand( + override val type: SafeType, override val attributes: Attributes, public val function: (Point) -> T, ) : Integrand { override fun modify(block: AttributesBuilder.() -> Unit): MultivariateIntegrand = - MultivariateIntegrand(attributes.modify(block), function) + MultivariateIntegrand(type, attributes.modify(block), function) override fun withAttribute(attribute: Attribute, value: A): MultivariateIntegrand = - MultivariateIntegrand(attributes.withAttribute(attribute, value), function) + MultivariateIntegrand(type, attributes.withAttribute(attribute, value), function) } -public fun MultivariateIntegrand( +public inline fun MultivariateIntegrand( attributeBuilder: AttributesBuilder.() -> Unit, - function: (Point) -> T, -): MultivariateIntegrand = MultivariateIntegrand(Attributes(attributeBuilder), function) + noinline function: (Point) -> T, +): MultivariateIntegrand = MultivariateIntegrand(safeTypeOf(), Attributes(attributeBuilder), function) diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/UnivariateIntegrand.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/UnivariateIntegrand.kt index 3c30f303e..a5291152a 100644 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/UnivariateIntegrand.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/UnivariateIntegrand.kt @@ -10,22 +10,23 @@ import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.structures.Buffer import space.kscience.kmath.structures.Float64Buffer -public class UnivariateIntegrand internal constructor( +public class UnivariateIntegrand( + override val type: SafeType, override val attributes: Attributes, public val function: (Double) -> T, ) : Integrand { override fun withAttribute(attribute: Attribute, value: A): UnivariateIntegrand = - UnivariateIntegrand(attributes.withAttribute(attribute, value), function) + UnivariateIntegrand(type, attributes.withAttribute(attribute, value), function) override fun modify(block: AttributesBuilder.() -> Unit): UnivariateIntegrand = - UnivariateIntegrand(attributes.modify(block), function) + UnivariateIntegrand(type, attributes.modify(block), function) } -public fun UnivariateIntegrand( +public inline fun UnivariateIntegrand( attributeBuilder: AttributesBuilder.() -> Unit, - function: (Double) -> T, -): UnivariateIntegrand = UnivariateIntegrand(Attributes(attributeBuilder), function) + noinline function: (Double) -> T, +): UnivariateIntegrand = UnivariateIntegrand(safeTypeOf(), Attributes(attributeBuilder), function) public typealias UnivariateIntegrator = Integrator> @@ -60,9 +61,9 @@ public fun AttributesBuilder.integrationNodes(vararg nodes: Double) { * The [function] is placed in the end position to allow passing a lambda. */ @UnstableKMathAPI -public fun UnivariateIntegrator.integrate( +public inline fun UnivariateIntegrator.integrate( attributesBuilder: AttributesBuilder.() -> Unit, - function: (Double) -> T, + noinline function: (Double) -> T, ): UnivariateIntegrand = process(UnivariateIntegrand(attributesBuilder, function)) /** @@ -70,14 +71,19 @@ public fun UnivariateIntegrator.integrate( * The [function] is placed in the end position to allow passing a lambda. */ @UnstableKMathAPI -public fun UnivariateIntegrator.integrate( +public inline fun UnivariateIntegrator.integrate( range: ClosedRange, attributeBuilder: AttributesBuilder.() -> Unit = {}, - function: (Double) -> T, + noinline function: (Double) -> T, ): UnivariateIntegrand { - val attributes = Attributes { - IntegrationRange(range) - attributeBuilder() - } - return process(UnivariateIntegrand(attributes, function)) + + return process( + UnivariateIntegrand( + attributeBuilder = { + IntegrationRange(range) + attributeBuilder() + }, + function = function + ) + ) } From dd3d38490ae5b1758ae4dff7b138cd866b321f30 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Wed, 13 Sep 2023 09:00:56 +0300 Subject: [PATCH 12/40] [WIP] refactor features to attributes --- .../kscience/attributes/AttributesBuilder.kt | 6 ++++- gradle.properties | 2 +- gradle/wrapper/gradle-wrapper.properties | 2 +- kmath-ast/build.gradle.kts | 2 +- .../integration/CMGaussRuleIntegrator.kt | 2 +- .../kmath/commons/integration/CMIntegrator.kt | 2 +- .../kmath/integration/GaussIntegrator.kt | 14 +++++------ .../kscience/kmath/integration/Integrand.kt | 14 +++++------ .../integration/MultivariateIntegrand.kt | 17 +++++++++---- .../kmath/integration/SimpsonIntegrator.kt | 8 +++---- .../kmath/integration/SplineIntegrator.kt | 4 ++-- .../kmath/integration/UnivariateIntegrand.kt | 24 ++++++++++++------- kmath-tensors/build.gradle.kts | 2 +- 13 files changed, 57 insertions(+), 42 deletions(-) diff --git a/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/AttributesBuilder.kt b/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/AttributesBuilder.kt index d0aed08c9..79df91c3e 100644 --- a/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/AttributesBuilder.kt +++ b/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/AttributesBuilder.kt @@ -7,8 +7,10 @@ package space.kscience.attributes /** * A safe builder for [Attributes] + * + * @param O type marker of an owner object, for which these attributes are made */ -public class AttributesBuilder internal constructor(private val map: MutableMap, Any>) { +public class TypedAttributesBuilder internal constructor(private val map: MutableMap, Any>) { public constructor() : this(mutableMapOf()) @@ -47,6 +49,8 @@ public class AttributesBuilder internal constructor(private val map: MutableMap< public fun build(): Attributes = Attributes(map) } +public typealias AttributesBuilder = TypedAttributesBuilder + public fun AttributesBuilder( attributes: Attributes, ): AttributesBuilder = AttributesBuilder(attributes.content.toMutableMap()) diff --git a/gradle.properties b/gradle.properties index 2f1a2a030..bcb32fede 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,7 +6,7 @@ kotlin.code.style=official kotlin.mpp.stability.nowarn=true kotlin.native.ignoreDisabledTargets=true -toolsVersion=0.14.9-kotlin-1.8.20 +toolsVersion=0.14.9-kotlin-1.9.0 org.gradle.parallel=true org.gradle.workers.max=4 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 15de90249..db9a6b825 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/kmath-ast/build.gradle.kts b/kmath-ast/build.gradle.kts index 7cdb745f0..fe10716af 100644 --- a/kmath-ast/build.gradle.kts +++ b/kmath-ast/build.gradle.kts @@ -31,7 +31,7 @@ kscience{ kotlin { js { nodejs { - testTask { + testTask{ useMocha().timeout = "0" } } diff --git a/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/integration/CMGaussRuleIntegrator.kt b/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/integration/CMGaussRuleIntegrator.kt index 7befc60a3..a3fc49d32 100644 --- a/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/integration/CMGaussRuleIntegrator.kt +++ b/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/integration/CMGaussRuleIntegrator.kt @@ -22,7 +22,7 @@ public class CMGaussRuleIntegrator( val integrator: GaussIntegrator = getIntegrator(range) //TODO check performance val res: Double = integrator.integrate(integrand.function) - return integrand.modify { + return integrand.withAttributes { IntegrandValue(res) IntegrandCallsPerformed(integrand.calls + numpoints) } diff --git a/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/integration/CMIntegrator.kt b/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/integration/CMIntegrator.kt index 7a807c25f..2cc60fb77 100644 --- a/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/integration/CMIntegrator.kt +++ b/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/integration/CMIntegrator.kt @@ -26,7 +26,7 @@ public class CMIntegrator( val range = integrand[IntegrationRange] ?: error("Integration range is not provided") val res = integrator.integrate(remainingCalls, integrand.function, range.start, range.endInclusive) - return integrand.modify { + return integrand.withAttributes { value(res) IntegrandAbsoluteAccuracy(integrator.absoluteAccuracy) IntegrandRelativeAccuracy(integrator.relativeAccuracy) diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/GaussIntegrator.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/GaussIntegrator.kt index f0aab2c6c..4753edcd0 100644 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/GaussIntegrator.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/GaussIntegrator.kt @@ -4,7 +4,7 @@ */ package space.kscience.kmath.integration -import space.kscience.attributes.AttributesBuilder +import space.kscience.attributes.TypedAttributesBuilder import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.operations.Field import space.kscience.kmath.structures.Buffer @@ -57,7 +57,7 @@ public class GaussIntegrator( override fun process(integrand: UnivariateIntegrand): UnivariateIntegrand = with(algebra) { val f = integrand.function val (points, weights) = buildRule(integrand) - var res = zero + var res: T = zero var c = zero for (i in points.indices) { val x = points[i] @@ -67,7 +67,7 @@ public class GaussIntegrator( c = t - res - y res = t } - return integrand.modify { + return integrand.withAttributes { value(res) IntegrandCallsPerformed(integrand.calls + points.size) } @@ -88,12 +88,12 @@ public val Field.gaussIntegrator: GaussIntegrator get() = GaussI * Integrate using [intervals] segments with Gauss-Legendre rule of [order] order. */ @UnstableKMathAPI -public fun GaussIntegrator.integrate( +public inline fun GaussIntegrator.integrate( range: ClosedRange, order: Int = 10, intervals: Int = 10, - attributesBuilder: AttributesBuilder.() -> Unit, - function: (Double) -> T, + attributesBuilder: TypedAttributesBuilder>.() -> Unit, + noinline function: (Double) -> T, ): UnivariateIntegrand { require(range.endInclusive > range.start) { "The range upper bound should be higher than lower bound" } require(order > 1) { "The order of polynomial must be more than 1" } @@ -103,7 +103,7 @@ public fun GaussIntegrator.integrate( (0 until intervals).map { i -> (range.start + rangeSize * i)..(range.start + rangeSize * (i + 1)) to order } ) return process( - UnivariateIntegrand( + UnivariateIntegrand( attributeBuilder = { IntegrationRange(range) GaussIntegratorRuleFactory(GaussLegendreRuleFactory) diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/Integrand.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/Integrand.kt index 9e2b8d0d7..d465e87c7 100644 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/Integrand.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/Integrand.kt @@ -5,10 +5,7 @@ package space.kscience.kmath.integration -import space.kscience.attributes.Attribute -import space.kscience.attributes.AttributeContainer -import space.kscience.attributes.AttributesBuilder -import space.kscience.attributes.SafeType +import space.kscience.attributes.* public interface IntegrandAttribute : Attribute @@ -16,9 +13,10 @@ public interface Integrand : AttributeContainer { public val type: SafeType - public fun modify(block: AttributesBuilder.() -> Unit): Integrand - - public fun withAttribute(attribute: Attribute, value: A): Integrand + /** + * Create a copy of this integrand with a new set of attributes + */ + public fun withAttributes(attributes: Attributes): Integrand public companion object } @@ -32,7 +30,7 @@ public sealed class IntegrandValue private constructor(): IntegrandAttribute< } } -public fun AttributesBuilder.value(value: T) { +public fun TypedAttributesBuilder>.value(value: T) { IntegrandValue.forType().invoke(value) } diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/MultivariateIntegrand.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/MultivariateIntegrand.kt index f8937efd2..2081947ec 100644 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/MultivariateIntegrand.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/MultivariateIntegrand.kt @@ -14,14 +14,21 @@ public class MultivariateIntegrand( public val function: (Point) -> T, ) : Integrand { - override fun modify(block: AttributesBuilder.() -> Unit): MultivariateIntegrand = - MultivariateIntegrand(type, attributes.modify(block), function) + override fun withAttributes(attributes: Attributes): MultivariateIntegrand = + MultivariateIntegrand(type, attributes, function) - override fun withAttribute(attribute: Attribute, value: A): MultivariateIntegrand = - MultivariateIntegrand(type, attributes.withAttribute(attribute, value), function) } +public fun MultivariateIntegrand.withAttribute( + attribute: Attribute, + value: A, +): MultivariateIntegrand = withAttributes(attributes.withAttribute(attribute, value)) + +public fun MultivariateIntegrand.withAttributes( + block: TypedAttributesBuilder>.() -> Unit, +): MultivariateIntegrand = withAttributes(attributes.modify(block)) + public inline fun MultivariateIntegrand( - attributeBuilder: AttributesBuilder.() -> Unit, + attributeBuilder: TypedAttributesBuilder>.() -> Unit, noinline function: (Point) -> T, ): MultivariateIntegrand = MultivariateIntegrand(safeTypeOf(), Attributes(attributeBuilder), function) diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/SimpsonIntegrator.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/SimpsonIntegrator.kt index 16d71a743..c0e4fb394 100644 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/SimpsonIntegrator.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/SimpsonIntegrator.kt @@ -48,7 +48,7 @@ public class SimpsonIntegrator( val ranges = integrand[UnivariateIntegrandRanges] return if (ranges != null) { val res = algebra.sum(ranges.ranges.map { integrateRange(integrand, it.first, it.second) }) - integrand.modify { + integrand.withAttributes { value(res) IntegrandCallsPerformed(integrand.calls + ranges.ranges.sumOf { it.second }) } @@ -57,7 +57,7 @@ public class SimpsonIntegrator( require(numPoints >= 4) { "Simpson integrator requires at least 4 nodes" } val range = integrand[IntegrationRange] ?: 0.0..1.0 val res = integrateRange(integrand, range, numPoints) - integrand.modify { + integrand.withAttributes { value(res) IntegrandCallsPerformed(integrand.calls + numPoints) } @@ -100,7 +100,7 @@ public object DoubleSimpsonIntegrator : UnivariateIntegrator { val ranges = integrand[UnivariateIntegrandRanges] return if (ranges != null) { val res = ranges.ranges.sumOf { integrateRange(integrand, it.first, it.second) } - integrand.modify { + integrand.withAttributes { value(res) IntegrandCallsPerformed(integrand.calls + ranges.ranges.sumOf { it.second }) } @@ -109,7 +109,7 @@ public object DoubleSimpsonIntegrator : UnivariateIntegrator { require(numPoints >= 4) { "Simpson integrator requires at least 4 nodes" } val range = integrand[IntegrationRange] ?: 0.0..1.0 val res = integrateRange(integrand, range, numPoints) - integrand.modify { + integrand.withAttributes { value(res) IntegrandCallsPerformed(integrand.calls + numPoints) } diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/SplineIntegrator.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/SplineIntegrator.kt index bbec9ff45..636ca5a74 100644 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/SplineIntegrator.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/SplineIntegrator.kt @@ -71,7 +71,7 @@ public class SplineIntegrator>( values ) val res = polynomials.integrate(algebra, number(range.start)..number(range.endInclusive)) - integrand.modify { + integrand.withAttributes { value(res) IntegrandCallsPerformed(integrand.calls + nodes.size) } @@ -99,7 +99,7 @@ public object DoubleSplineIntegrator : UnivariateIntegrator { val values = nodes.mapToBuffer(::Float64Buffer) { integrand.function(it) } val polynomials = interpolator.interpolatePolynomials(nodes, values) val res = polynomials.integrate(Float64Field, range) - return integrand.modify { + return integrand.withAttributes { value(res) IntegrandCallsPerformed(integrand.calls + nodes.size) } diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/UnivariateIntegrand.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/UnivariateIntegrand.kt index a5291152a..6a6d47667 100644 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/UnivariateIntegrand.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/UnivariateIntegrand.kt @@ -16,15 +16,21 @@ public class UnivariateIntegrand( public val function: (Double) -> T, ) : Integrand { - override fun withAttribute(attribute: Attribute, value: A): UnivariateIntegrand = - UnivariateIntegrand(type, attributes.withAttribute(attribute, value), function) - - override fun modify(block: AttributesBuilder.() -> Unit): UnivariateIntegrand = - UnivariateIntegrand(type, attributes.modify(block), function) + override fun withAttributes(attributes: Attributes): UnivariateIntegrand = + UnivariateIntegrand(type, attributes, function) } +public fun UnivariateIntegrand.withAttribute( + attribute: Attribute, + value: A, +): UnivariateIntegrand = withAttributes(attributes.withAttribute(attribute, value)) + +public fun UnivariateIntegrand.withAttributes( + block: TypedAttributesBuilder>.() -> Unit, +): UnivariateIntegrand = withAttributes(attributes.modify(block)) + public inline fun UnivariateIntegrand( - attributeBuilder: AttributesBuilder.() -> Unit, + attributeBuilder: TypedAttributesBuilder>.() -> Unit, noinline function: (Double) -> T, ): UnivariateIntegrand = UnivariateIntegrand(safeTypeOf(), Attributes(attributeBuilder), function) @@ -52,7 +58,7 @@ public class UnivariateIntegrandRanges(public val ranges: List> -public fun AttributesBuilder.integrationNodes(vararg nodes: Double) { +public fun TypedAttributesBuilder>.integrationNodes(vararg nodes: Double) { UnivariateIntegrationNodes(Float64Buffer(nodes)) } @@ -62,7 +68,7 @@ public fun AttributesBuilder.integrationNodes(vararg nodes: Double) { */ @UnstableKMathAPI public inline fun UnivariateIntegrator.integrate( - attributesBuilder: AttributesBuilder.() -> Unit, + attributesBuilder: TypedAttributesBuilder>.() -> Unit, noinline function: (Double) -> T, ): UnivariateIntegrand = process(UnivariateIntegrand(attributesBuilder, function)) @@ -73,7 +79,7 @@ public inline fun UnivariateIntegrator.integrate( @UnstableKMathAPI public inline fun UnivariateIntegrator.integrate( range: ClosedRange, - attributeBuilder: AttributesBuilder.() -> Unit = {}, + attributeBuilder: TypedAttributesBuilder>.() -> Unit = {}, noinline function: (Double) -> T, ): UnivariateIntegrand { diff --git a/kmath-tensors/build.gradle.kts b/kmath-tensors/build.gradle.kts index 2497314f0..8977183da 100644 --- a/kmath-tensors/build.gradle.kts +++ b/kmath-tensors/build.gradle.kts @@ -6,7 +6,7 @@ kscience{ jvm() js { browser { - testTask { + testTask{ useMocha().timeout = "0" } } From ea887b8c728b9a902c80d37a6a092cdf7e7b9a1e Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Wed, 1 Nov 2023 08:55:47 +0300 Subject: [PATCH 13/40] 0.4 WIP --- .../space/kscience/kmath/ejml/_generated.kt | 10 ++++- .../kmath/integration/GaussIntegrator.kt | 6 +-- .../kscience/kmath/integration/Integrator.kt | 4 +- .../kmath/integration/SimpsonIntegrator.kt | 12 +++--- .../kmath/integration/SplineIntegrator.kt | 8 ++-- .../kmath/integration/UnivariateIntegrand.kt | 6 +-- .../kmath/geometry/quaternionOperations.kt | 23 +--------- .../kmath/tensors/core/internal/linUtils.kt | 42 ++++++++----------- 8 files changed, 45 insertions(+), 66 deletions(-) diff --git a/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/_generated.kt b/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/_generated.kt index 881649d01..0cef96f49 100644 --- a/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/_generated.kt +++ b/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/_generated.kt @@ -19,13 +19,19 @@ import org.ejml.sparse.csc.factory.DecompositionFactory_DSCC import org.ejml.sparse.csc.factory.DecompositionFactory_FSCC import org.ejml.sparse.csc.factory.LinearSolverFactory_DSCC import org.ejml.sparse.csc.factory.LinearSolverFactory_FSCC -import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.linear.* import space.kscience.kmath.linear.Matrix +import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.nd.StructureFeature -import space.kscience.kmath.operations.Float32Field +import space.kscience.kmath.structures.Float64 +import space.kscience.kmath.structures.Float32 import space.kscience.kmath.operations.Float64Field +import space.kscience.kmath.operations.Float32Field +import space.kscience.kmath.operations.DoubleField +import space.kscience.kmath.operations.FloatField import space.kscience.kmath.operations.invoke +import space.kscience.kmath.structures.Float64Buffer +import space.kscience.kmath.structures.Float32Buffer import space.kscience.kmath.structures.DoubleBuffer import space.kscience.kmath.structures.FloatBuffer import kotlin.reflect.KClass diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/GaussIntegrator.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/GaussIntegrator.kt index 4753edcd0..7d37711cd 100644 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/GaussIntegrator.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/GaussIntegrator.kt @@ -54,7 +54,7 @@ public class GaussIntegrator( } } - override fun process(integrand: UnivariateIntegrand): UnivariateIntegrand = with(algebra) { + override fun integrate(integrand: UnivariateIntegrand): UnivariateIntegrand = with(algebra) { val f = integrand.function val (points, weights) = buildRule(integrand) var res: T = zero @@ -68,7 +68,7 @@ public class GaussIntegrator( res = t } return integrand.withAttributes { - value(res) + IntegrandValue(res) IntegrandCallsPerformed(integrand.calls + points.size) } } @@ -102,7 +102,7 @@ public inline fun GaussIntegrator.integrate( val ranges = UnivariateIntegrandRanges( (0 until intervals).map { i -> (range.start + rangeSize * i)..(range.start + rangeSize * (i + 1)) to order } ) - return process( + return integrate( UnivariateIntegrand( attributeBuilder = { IntegrationRange(range) diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/Integrator.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/Integrator.kt index 18c46b83b..76fcd0e29 100644 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/Integrator.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/Integrator.kt @@ -8,9 +8,9 @@ package space.kscience.kmath.integration /** * A general interface for all integrators. */ -public interface Integrator { +public interface Integrator> { /** * Runs one integration pass and return a new [Integrand] with a new set of features. */ - public fun process(integrand: I): I + public fun integrate(integrand: I): I } diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/SimpsonIntegrator.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/SimpsonIntegrator.kt index c0e4fb394..699d3f0ae 100644 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/SimpsonIntegrator.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/SimpsonIntegrator.kt @@ -44,12 +44,12 @@ public class SimpsonIntegrator( return res } - override fun process(integrand: UnivariateIntegrand): UnivariateIntegrand { + override fun integrate(integrand: UnivariateIntegrand): UnivariateIntegrand { val ranges = integrand[UnivariateIntegrandRanges] return if (ranges != null) { val res = algebra.sum(ranges.ranges.map { integrateRange(integrand, it.first, it.second) }) integrand.withAttributes { - value(res) + IntegrandValue(res) IntegrandCallsPerformed(integrand.calls + ranges.ranges.sumOf { it.second }) } } else { @@ -58,7 +58,7 @@ public class SimpsonIntegrator( val range = integrand[IntegrationRange] ?: 0.0..1.0 val res = integrateRange(integrand, range, numPoints) integrand.withAttributes { - value(res) + IntegrandValue(res) IntegrandCallsPerformed(integrand.calls + numPoints) } } @@ -96,12 +96,12 @@ public object DoubleSimpsonIntegrator : UnivariateIntegrator { return res } - override fun process(integrand: UnivariateIntegrand): UnivariateIntegrand { + override fun integrate(integrand: UnivariateIntegrand): UnivariateIntegrand { val ranges = integrand[UnivariateIntegrandRanges] return if (ranges != null) { val res = ranges.ranges.sumOf { integrateRange(integrand, it.first, it.second) } integrand.withAttributes { - value(res) + IntegrandValue(res) IntegrandCallsPerformed(integrand.calls + ranges.ranges.sumOf { it.second }) } } else { @@ -110,7 +110,7 @@ public object DoubleSimpsonIntegrator : UnivariateIntegrator { val range = integrand[IntegrationRange] ?: 0.0..1.0 val res = integrateRange(integrand, range, numPoints) integrand.withAttributes { - value(res) + IntegrandValue(res) IntegrandCallsPerformed(integrand.calls + numPoints) } } diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/SplineIntegrator.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/SplineIntegrator.kt index 636ca5a74..c03b248d4 100644 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/SplineIntegrator.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/SplineIntegrator.kt @@ -54,7 +54,7 @@ public class SplineIntegrator>( public val algebra: Field, public val bufferFactory: MutableBufferFactory, ) : UnivariateIntegrator { - override fun process(integrand: UnivariateIntegrand): UnivariateIntegrand = algebra { + override fun integrate(integrand: UnivariateIntegrand): UnivariateIntegrand = algebra { val range = integrand[IntegrationRange] ?: 0.0..1.0 val interpolator: PolynomialInterpolator = SplineInterpolator(algebra, bufferFactory) @@ -72,7 +72,7 @@ public class SplineIntegrator>( ) val res = polynomials.integrate(algebra, number(range.start)..number(range.endInclusive)) integrand.withAttributes { - value(res) + IntegrandValue(res) IntegrandCallsPerformed(integrand.calls + nodes.size) } } @@ -86,7 +86,7 @@ public class SplineIntegrator>( */ @UnstableKMathAPI public object DoubleSplineIntegrator : UnivariateIntegrator { - override fun process(integrand: UnivariateIntegrand): UnivariateIntegrand { + override fun integrate(integrand: UnivariateIntegrand): UnivariateIntegrand { val range = integrand[IntegrationRange] ?: 0.0..1.0 val interpolator: PolynomialInterpolator = SplineInterpolator(Float64Field, ::Float64Buffer) @@ -100,7 +100,7 @@ public object DoubleSplineIntegrator : UnivariateIntegrator { val polynomials = interpolator.interpolatePolynomials(nodes, values) val res = polynomials.integrate(Float64Field, range) return integrand.withAttributes { - value(res) + IntegrandValue(res) IntegrandCallsPerformed(integrand.calls + nodes.size) } } diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/UnivariateIntegrand.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/UnivariateIntegrand.kt index 6a6d47667..9c39e7edc 100644 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/UnivariateIntegrand.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/UnivariateIntegrand.kt @@ -34,7 +34,7 @@ public inline fun UnivariateIntegrand( noinline function: (Double) -> T, ): UnivariateIntegrand = UnivariateIntegrand(safeTypeOf(), Attributes(attributeBuilder), function) -public typealias UnivariateIntegrator = Integrator> +public typealias UnivariateIntegrator = Integrator> public object IntegrationRange : IntegrandAttribute> @@ -70,7 +70,7 @@ public fun TypedAttributesBuilder>.integrationNodes(varar public inline fun UnivariateIntegrator.integrate( attributesBuilder: TypedAttributesBuilder>.() -> Unit, noinline function: (Double) -> T, -): UnivariateIntegrand = process(UnivariateIntegrand(attributesBuilder, function)) +): UnivariateIntegrand = integrate(UnivariateIntegrand(attributesBuilder, function)) /** * A shortcut method to integrate a [function] in [range] with additional features. @@ -83,7 +83,7 @@ public inline fun UnivariateIntegrator.integrate( noinline function: (Double) -> T, ): UnivariateIntegrand { - return process( + return integrate( UnivariateIntegrand( attributeBuilder = { IntegrationRange(range) diff --git a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/quaternionOperations.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/quaternionOperations.kt index 859255004..4fb3a720c 100644 --- a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/quaternionOperations.kt +++ b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/quaternionOperations.kt @@ -30,25 +30,4 @@ public fun QuaternionAlgebra.angleBetween(q1: Quaternion, q2: Quaternion): Angle /** * Euclidean product of two quaternions */ -public infix fun Quaternion.dot(other: Quaternion): Double = w * other.w + x * other.x + y * other.y + z * other.z - -// -///** -// * Convert a quaternion to XYZ Cardan angles assuming it is normalized. -// */ -//private fun Quaternion.normalizedToEuler(): Float32Vector3D { -// val roll = atan2(2 * y * w + 2 * x * z, 1 - 2 * y * y - 2 * z * z) -// val pitch = atan2(2 * x * w - 2 * y * z, 1 - 2 * x * x - 2 * z * z) -// val yaw = asin(2 * x * y + 2 * z * w) -// -// return Float32Vector3D(roll, pitch, yaw) -//} - -///** -// * Quaternion to XYZ Cardan angles -// */ -//public fun Quaternion.toEuler(): Float32Vector3D = if (QuaternionAlgebra.norm(this) == 0.0) { -// Float32Space3D.zero -//} else { -// normalized().normalizedToEuler() -//} \ No newline at end of file +public infix fun Quaternion.dot(other: Quaternion): Double = w * other.w + x * other.x + y * other.y + z * other.z \ No newline at end of file diff --git a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/internal/linUtils.kt b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/internal/linUtils.kt index 272af41d5..66092a532 100644 --- a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/internal/linUtils.kt +++ b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/internal/linUtils.kt @@ -310,32 +310,26 @@ internal fun DoubleTensorAlgebra.svdHelper( } } -private fun pythag(a: Double, b: Double): Double { - val at: Double = abs(a) - val bt: Double = abs(b) - val ct: Double - val result: Double - if (at > bt) { - ct = bt / at - result = at * sqrt(1.0 + ct * ct) - } else if (bt > 0.0) { - ct = at / bt - result = bt * sqrt(1.0 + ct * ct) - } else result = 0.0 - return result -} - -private fun SIGN(a: Double, b: Double): Double { - if (b >= 0.0) - return abs(a) - else - return -abs(a) -} - internal fun MutableStructure2D.svdGolubKahanHelper( u: MutableStructure2D, w: BufferedTensor, v: MutableStructure2D, iterations: Int, epsilon: Double, ) { + fun pythag(a: Double, b: Double): Double { + val at: Double = abs(a) + val bt: Double = abs(b) + val ct: Double + val result: Double + if (at > bt) { + ct = bt / at + result = at * sqrt(1.0 + ct * ct) + } else if (bt > 0.0) { + ct = at / bt + result = bt * sqrt(1.0 + ct * ct) + } else result = 0.0 + return result + } + + val shape = this.shape val m = shape.component1() val n = shape.component2() @@ -553,7 +547,7 @@ internal fun MutableStructure2D.svdGolubKahanHelper( h = rv1[k] f = ((y - z) * (y + z) + (g - h) * (g + h)) / (2.0 * h * y) g = pythag(f, 1.0) - f = ((x - z) * (x + z) + h * ((y / (f + SIGN(g, f))) - h)) / x + f = ((x - z) * (x + z) + h * ((y / (f + if (f >= 0.0) abs(g) else -abs(g) )) - h)) / x c = 1.0 s = 1.0 @@ -563,7 +557,7 @@ internal fun MutableStructure2D.svdGolubKahanHelper( g = rv1[i] y = wBuffer[wStart + i] h = s * g - g = c * g + g *= c z = pythag(f, h) rv1[j] = z c = f / z From 46eacbb7506d40962fa91f70cc0a047d63ed5a17 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Fri, 3 Nov 2023 09:56:19 +0300 Subject: [PATCH 14/40] 0.4 WIP --- CHANGELOG.md | 9 +- .../space/kscience/attributes/SafeType.kt | 2 +- .../kscience/kmath/data/XYColumnarData.kt | 6 +- .../kscience/kmath/expressions/DSAlgebra.kt | 4 +- .../FunctionalExpressionAlgebra.kt | 4 + .../kscience/kmath/expressions/MstAlgebra.kt | 25 ++- .../kmath/expressions/SimpleAutoDiff.kt | 32 ++-- .../kscience/kmath/linear/LinearSpace.kt | 9 +- .../kscience/kmath/linear/LupDecomposition.kt | 26 ++- .../kscience/kmath/linear/MatrixBuilder.kt | 11 +- .../kscience/kmath/linear/MatrixWrapper.kt | 6 +- .../space/kscience/kmath/linear/Transposed.kt | 4 + .../kscience/kmath/linear/VirtualMatrix.kt | 6 +- .../kscience/kmath/linear/matrixAttributes.kt | 8 +- .../space/kscience/kmath/misc/sorting.kt | 17 +- .../space/kscience/kmath/nd/AlgebraND.kt | 4 +- .../kscience/kmath/nd/BufferAlgebraND.kt | 5 + .../space/kscience/kmath/nd/BufferND.kt | 11 +- .../kscience/kmath/nd/PermutedStructureND.kt | 4 + .../space/kscience/kmath/nd/Structure1D.kt | 15 +- .../space/kscience/kmath/nd/Structure2D.kt | 23 ++- .../space/kscience/kmath/nd/StructureND.kt | 105 ++++++------ .../kscience/kmath/nd/VirtualStructureND.kt | 7 +- .../space/kscience/kmath/nd/operationsND.kt | 4 +- .../kscience/kmath/operations/Algebra.kt | 26 ++- .../space/kscience/kmath/operations/BigInt.kt | 9 +- .../kmath/operations/BufferAlgebra.kt | 5 +- .../kscience/kmath/operations/LogicAlgebra.kt | 4 + .../kmath/operations/integerFields.kt | 12 +- .../kscience/kmath/operations/numbers.kt | 2 +- .../space/kscience/kmath/structures/Buffer.kt | 154 ++++++++++-------- .../kmath/structures/BufferAccessor2D.kt | 14 +- .../kmath/structures/FlaggedBuffer.kt | 5 + .../kmath/structures/Float32Buffer.kt | 5 + .../kmath/structures/Float64Buffer.kt | 5 + .../kscience/kmath/structures/Int16Buffer.kt | 4 + .../kscience/kmath/structures/Int32Buffer.kt | 5 + .../kscience/kmath/structures/Int64Buffer.kt | 5 + .../kscience/kmath/structures/Int8Buffer.kt | 5 + .../kscience/kmath/structures/ListBuffer.kt | 37 +++-- .../kmath/structures/MutableBuffer.kt | 60 +++---- .../kmath/linear/DoubleLUSolverTest.kt | 2 +- .../space/kscience/kmath/ejml/_generated.kt | 10 +- .../histogram/UniformHistogramGroupND.kt | 4 +- 44 files changed, 451 insertions(+), 269 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a1b23d817..ef5e0490c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,10 +3,11 @@ ## Unreleased ### Added -- Integer division algebras -- Float32 geometries -- New Attributes-kt module that could be used as stand-alone. It declares type-safe attributes containers. -- Explicit `mutableStructureND` builders for mutable structures +- Explicit `SafeType` for algebras and buffers. +- Integer division algebras. +- Float32 geometries. +- New Attributes-kt module that could be used as stand-alone. It declares. type-safe attributes containers. +- Explicit `mutableStructureND` builders for mutable structures. ### Changed - Default naming for algebra and buffers now uses IntXX/FloatXX notation instead of Java types. diff --git a/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/SafeType.kt b/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/SafeType.kt index 7225d1a6b..0fac2477c 100644 --- a/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/SafeType.kt +++ b/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/SafeType.kt @@ -16,7 +16,7 @@ import kotlin.reflect.typeOf * @param kType raw [KType] */ @JvmInline -public value class SafeType @PublishedApi internal constructor(public val kType: KType) +public value class SafeType @PublishedApi internal constructor(public val kType: KType) public inline fun safeTypeOf(): SafeType = SafeType(typeOf()) diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/data/XYColumnarData.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/data/XYColumnarData.kt index 23cbcd0c7..b06ce1349 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/data/XYColumnarData.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/data/XYColumnarData.kt @@ -52,10 +52,10 @@ public interface XYColumnarData : ColumnarData { * Create two-column data from a list of row-objects (zero-copy) */ @UnstableKMathAPI - public fun ofList( + public inline fun ofList( list: List, - xConverter: (I) -> X, - yConverter: (I) -> Y, + noinline xConverter: (I) -> X, + noinline yConverter: (I) -> Y, ): XYColumnarData = object : XYColumnarData { override val size: Int get() = list.size diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/DSAlgebra.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/DSAlgebra.kt index 63f96b0af..817f38ff0 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/DSAlgebra.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/DSAlgebra.kt @@ -13,8 +13,6 @@ import space.kscience.kmath.structures.MutableBufferFactory import space.kscience.kmath.structures.asBuffer import kotlin.math.max import kotlin.math.min -import kotlin.reflect.KType -import kotlin.reflect.typeOf /** * Class representing both the value and the differentials of a function. @@ -84,6 +82,8 @@ public abstract class DSAlgebra>( bindings: Map, ) : ExpressionAlgebra>, SymbolIndexer { + override val bufferFactory: MutableBufferFactory> = MutableBufferFactory() + /** * Get the compiler for number of free parameters and order. * diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/FunctionalExpressionAlgebra.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/FunctionalExpressionAlgebra.kt index 8e37f3d32..5b4dcd638 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/FunctionalExpressionAlgebra.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/FunctionalExpressionAlgebra.kt @@ -6,6 +6,7 @@ package space.kscience.kmath.expressions import space.kscience.kmath.operations.* +import space.kscience.kmath.structures.MutableBufferFactory import kotlin.contracts.InvocationKind import kotlin.contracts.contract @@ -17,6 +18,8 @@ import kotlin.contracts.contract public abstract class FunctionalExpressionAlgebra>( public val algebra: A, ) : ExpressionAlgebra> { + override val bufferFactory: MutableBufferFactory> = MutableBufferFactory>() + /** * Builds an Expression of constant expression that does not depend on arguments. */ @@ -49,6 +52,7 @@ public abstract class FunctionalExpressionAlgebra>( public open class FunctionalExpressionGroup>( algebra: A, ) : FunctionalExpressionAlgebra(algebra), Group> { + override val zero: Expression get() = const(algebra.zero) override fun Expression.unaryMinus(): Expression = diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/MstAlgebra.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/MstAlgebra.kt index c894cf00a..c568eece0 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/MstAlgebra.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/MstAlgebra.kt @@ -7,11 +7,14 @@ package space.kscience.kmath.expressions import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.operations.* +import space.kscience.kmath.structures.MutableBufferFactory /** * [Algebra] over [MST] nodes. */ public object MstNumericAlgebra : NumericAlgebra { + override val bufferFactory: MutableBufferFactory = MutableBufferFactory() + override fun number(value: Number): MST.Numeric = MST.Numeric(value) override fun bindSymbolOrNull(value: String): Symbol = StringSymbol(value) override fun bindSymbol(value: String): Symbol = bindSymbolOrNull(value) @@ -27,6 +30,9 @@ public object MstNumericAlgebra : NumericAlgebra { * [Group] over [MST] nodes. */ public object MstGroup : Group, NumericAlgebra, ScaleOperations { + + override val bufferFactory: MutableBufferFactory = MutableBufferFactory() + override val zero: MST.Numeric = number(0.0) override fun number(value: Number): MST.Numeric = MstNumericAlgebra.number(value) @@ -57,7 +63,11 @@ public object MstGroup : Group, NumericAlgebra, ScaleOperations { @Suppress("OVERRIDE_BY_INLINE") @OptIn(UnstableKMathAPI::class) public object MstRing : Ring, NumbersAddOps, ScaleOperations { + + override val bufferFactory: MutableBufferFactory = MutableBufferFactory() + override inline val zero: MST.Numeric get() = MstGroup.zero + override val one: MST.Numeric = number(1.0) override fun number(value: Number): MST.Numeric = MstGroup.number(value) @@ -87,7 +97,11 @@ public object MstRing : Ring, NumbersAddOps, ScaleOperations { @Suppress("OVERRIDE_BY_INLINE") @OptIn(UnstableKMathAPI::class) public object MstField : Field, NumbersAddOps, ScaleOperations { + + override val bufferFactory: MutableBufferFactory = MutableBufferFactory() + override inline val zero: MST.Numeric get() = MstRing.zero + override inline val one: MST.Numeric get() = MstRing.one override fun bindSymbolOrNull(value: String): Symbol = MstNumericAlgebra.bindSymbolOrNull(value) @@ -117,7 +131,11 @@ public object MstField : Field, NumbersAddOps, ScaleOperations { */ @Suppress("OVERRIDE_BY_INLINE") public object MstExtendedField : ExtendedField, NumericAlgebra { + + override val bufferFactory: MutableBufferFactory = MutableBufferFactory() + override inline val zero: MST.Numeric get() = MstField.zero + override inline val one: MST.Numeric get() = MstField.one override fun bindSymbolOrNull(value: String): Symbol = MstNumericAlgebra.bindSymbolOrNull(value) @@ -164,6 +182,9 @@ public object MstExtendedField : ExtendedField, NumericAlgebra { */ @UnstableKMathAPI public object MstLogicAlgebra : LogicAlgebra { + + override val bufferFactory: MutableBufferFactory = MutableBufferFactory() + override fun bindSymbolOrNull(value: String): MST = super.bindSymbolOrNull(value) ?: StringSymbol(value) override fun const(boolean: Boolean): Symbol = if (boolean) { @@ -176,7 +197,7 @@ public object MstLogicAlgebra : LogicAlgebra { override fun MST.and(other: MST): MST = MST.Binary(Boolean::and.name, this, other) - override fun MST.or(other: MST): MST = MST.Binary(Boolean::or.name, this, other) + override fun MST.or(other: MST): MST = MST.Binary(Boolean::or.name, this, other) - override fun MST.xor(other: MST): MST = MST.Binary(Boolean::xor.name, this, other) + override fun MST.xor(other: MST): MST = MST.Binary(Boolean::xor.name, this, other) } 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 2bb5043b7..6d22b18dc 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 @@ -5,9 +5,11 @@ package space.kscience.kmath.expressions +import space.kscience.attributes.SafeType import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.linear.Point import space.kscience.kmath.operations.* +import space.kscience.kmath.structures.MutableBufferFactory import space.kscience.kmath.structures.asBuffer import kotlin.contracts.InvocationKind import kotlin.contracts.contract @@ -30,9 +32,10 @@ public open class AutoDiffValue(public val value: T) */ public class DerivationResult( public val value: T, + override val type: SafeType, private val derivativeValues: Map, public val context: Field, -) { +) : WithType { /** * Returns derivative of [variable] or returns [Ring.zero] in [context]. */ @@ -49,19 +52,23 @@ public class DerivationResult( */ public fun DerivationResult.grad(vararg variables: Symbol): Point { check(variables.isNotEmpty()) { "Variable order is not provided for gradient construction" } - return variables.map(::derivative).asBuffer() + return variables.map(::derivative).asBuffer(type) } /** - * Represents field in context of which functions can be derived. + * Represents field. Function derivatives could be computed in this field */ @OptIn(UnstableKMathAPI::class) public open class SimpleAutoDiffField>( - public val context: F, + public val algebra: F, bindings: Map, ) : Field>, ExpressionAlgebra>, NumbersAddOps> { - override val zero: AutoDiffValue get() = const(context.zero) - override val one: AutoDiffValue get() = const(context.one) + + override val bufferFactory: MutableBufferFactory> = MutableBufferFactory>() + + override val zero: AutoDiffValue get() = const(algebra.zero) + + override val one: AutoDiffValue get() = const(algebra.one) // this stack contains pairs of blocks and values to apply them to private var stack: Array = arrayOfNulls(8) @@ -69,7 +76,7 @@ public open class SimpleAutoDiffField>( private val derivatives: MutableMap, T> = hashMapOf() private val bindings: Map> = bindings.entries.associate { - it.key.identity to AutoDiffVariableWithDerivative(it.key.identity, it.value, context.zero) + it.key.identity to AutoDiffVariableWithDerivative(it.key.identity, it.value, algebra.zero) } /** @@ -92,7 +99,7 @@ public open class SimpleAutoDiffField>( override fun bindSymbolOrNull(value: String): AutoDiffValue? = bindings[value] private fun getDerivative(variable: AutoDiffValue): T = - (variable as? AutoDiffVariableWithDerivative)?.d ?: derivatives[variable] ?: context.zero + (variable as? AutoDiffVariableWithDerivative)?.d ?: derivatives[variable] ?: algebra.zero private fun setDerivative(variable: AutoDiffValue, value: T) { if (variable is AutoDiffVariableWithDerivative) variable.d = value else derivatives[variable] = value @@ -103,7 +110,7 @@ public open class SimpleAutoDiffField>( while (sp > 0) { val value = stack[--sp] val block = stack[--sp] as F.(Any?) -> Unit - context.block(value) + algebra.block(value) } } @@ -130,7 +137,6 @@ public open class SimpleAutoDiffField>( * } * ``` */ - @Suppress("UNCHECKED_CAST") public fun derive(value: R, block: F.(R) -> Unit): R { // save block to stack for backward pass if (sp >= stack.size) stack = stack.copyOf(stack.size * 2) @@ -142,9 +148,9 @@ public open class SimpleAutoDiffField>( internal fun differentiate(function: SimpleAutoDiffField.() -> AutoDiffValue): DerivationResult { val result = function() - result.d = context.one // computing derivative w.r.t result + result.d = algebra.one // computing derivative w.r.t result runBackwardPass() - return DerivationResult(result.value, bindings.mapValues { it.value.d }, context) + return DerivationResult(result.value, algebra.type, bindings.mapValues { it.value.d }, algebra) } // // Overloads for Double constants @@ -194,7 +200,7 @@ public open class SimpleAutoDiffField>( public inline fun > SimpleAutoDiffField.const(block: F.() -> T): AutoDiffValue { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } - return const(context.block()) + return const(algebra.block()) } 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 0780be29a..ddf4f17d4 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 @@ -10,10 +10,9 @@ import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.nd.* import space.kscience.kmath.operations.BufferRingOps import space.kscience.kmath.operations.Ring +import space.kscience.kmath.operations.WithType import space.kscience.kmath.operations.invoke import space.kscience.kmath.structures.Buffer -import kotlin.reflect.KType -import kotlin.reflect.typeOf /** * Alias for [Structure2D] with more familiar name. @@ -34,7 +33,7 @@ public typealias Point = Buffer * A marker interface for algebras that operate on matrices * @param T type of matrix element */ -public interface MatrixOperations +public interface MatrixOperations : WithType /** * Basic operations on matrices and vectors. @@ -45,6 +44,8 @@ public interface MatrixOperations public interface LinearSpace> : MatrixOperations { public val elementAlgebra: A + override val type: SafeType get() = elementAlgebra.type + /** * Produces a matrix with this context and given dimensions. */ @@ -212,4 +213,4 @@ public fun Matrix.asVector(): Point = * @receiver a buffer. * @return the new matrix. */ -public fun Point.asMatrix(): VirtualMatrix = VirtualMatrix(size, 1) { i, _ -> get(i) } \ No newline at end of file +public fun Point.asMatrix(): VirtualMatrix = VirtualMatrix(type, size, 1) { i, _ -> get(i) } \ No newline at end of file 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 9fe8397d8..1ac2ca5c6 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 @@ -22,11 +22,27 @@ import space.kscience.kmath.structures.* * @param l The lower triangular matrix in this decomposition. It may have [LowerTriangular]. * @param u The upper triangular matrix in this decomposition. It may have [UpperTriangular]. */ -public data class LupDecomposition( +public class LupDecomposition( + public val linearSpace: LinearSpace>, public val l: Matrix, public val u: Matrix, public val pivot: IntBuffer, -) +) { + public val elementAlgebra: Ring get() = linearSpace.elementAlgebra + + public val pivotMatrix: VirtualMatrix + get() = VirtualMatrix(linearSpace.type, l.rowNum, l.colNum) { row, column -> + if (column == pivot[row]) elementAlgebra.one else elementAlgebra.zero + } + + public val LupDecomposition.determinant by lazy { + elementAlgebra { (0 until l.shape[0]).fold(if (even) one else -one) { value, i -> value * lu[i, i] } } + } + +} + + + public class LupDecompositionAttribute(type: SafeType>) : @@ -168,7 +184,7 @@ public fun > LinearSpace>.lup( for (row in col + 1 until m) lu[row, col] /= luDiag } - val l: MatrixWrapper = VirtualMatrix(rowNum, colNum) { i, j -> + val l: MatrixWrapper = VirtualMatrix(type, rowNum, colNum) { i, j -> when { j < i -> lu[i, j] j == i -> one @@ -176,7 +192,7 @@ public fun > LinearSpace>.lup( } }.withAttribute(LowerTriangular) - val u = VirtualMatrix(rowNum, colNum) { i, j -> + val u = VirtualMatrix(type, rowNum, colNum) { i, j -> if (j >= i) lu[i, j] else zero }.withAttribute(UpperTriangular) // @@ -184,7 +200,7 @@ public fun > LinearSpace>.lup( // if (j == pivot[i]) one else zero // }.withAttribute(Determinant, if (even) one else -one) - return LupDecomposition(l, u, pivot.asBuffer()) + return LupDecomposition(this@lup, l, u, pivot.asBuffer()) } } } diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixBuilder.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixBuilder.kt index 7b6c36dfc..9543555e0 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixBuilder.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixBuilder.kt @@ -6,16 +6,21 @@ package space.kscience.kmath.linear import space.kscience.attributes.FlagAttribute +import space.kscience.attributes.SafeType import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.operations.Ring +import space.kscience.kmath.operations.WithType import space.kscience.kmath.structures.BufferAccessor2D -import space.kscience.kmath.structures.MutableBuffer +import space.kscience.kmath.structures.MutableBufferFactory public class MatrixBuilder>( public val linearSpace: LinearSpace, public val rows: Int, public val columns: Int, -) { +) : WithType { + + override val type: SafeType get() = linearSpace.type + public operator fun invoke(vararg elements: T): Matrix { require(rows * columns == elements.size) { "The number of elements ${elements.size} is not equal $rows * $columns" } return linearSpace.buildMatrix(rows, columns) { i, j -> elements[i * columns + j] } @@ -61,7 +66,7 @@ public fun > MatrixBuilder.symmetric( builder: (i: Int, j: Int) -> T, ): Matrix { require(columns == rows) { "In order to build symmetric matrix, number of rows $rows should be equal to number of columns $columns" } - return with(BufferAccessor2D(rows, rows, MutableBuffer.Companion::boxing)) { + return with(BufferAccessor2D(rows, rows, MutableBufferFactory(type))) { val cache = factory(rows * rows) { null } linearSpace.buildMatrix(rows, rows) { i, j -> val cached = cache[i, j] diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixWrapper.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixWrapper.kt index a129b04f0..9d89f7636 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixWrapper.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixWrapper.kt @@ -39,7 +39,7 @@ public fun > Matrix.withAttribute( attribute: A, attrValue: T, ): MatrixWrapper = if (this is MatrixWrapper) { - MatrixWrapper(origin, attributes.withAttribute(attribute,attrValue)) + MatrixWrapper(origin, attributes.withAttribute(attribute, attrValue)) } else { MatrixWrapper(this, Attributes(attribute, attrValue)) } @@ -68,7 +68,7 @@ public fun Matrix.modifyAttributes(modifier: (Attributes) -> Attrib public fun LinearSpace>.one( rows: Int, columns: Int, -): MatrixWrapper = VirtualMatrix(rows, columns) { i, j -> +): MatrixWrapper = VirtualMatrix(type, rows, columns) { i, j -> if (i == j) elementAlgebra.one else elementAlgebra.zero }.withAttribute(IsUnit) @@ -79,6 +79,6 @@ public fun LinearSpace>.one( public fun LinearSpace>.zero( rows: Int, columns: Int, -): MatrixWrapper = VirtualMatrix(rows, columns) { _, _ -> +): MatrixWrapper = VirtualMatrix(type, rows, columns) { _, _ -> elementAlgebra.zero }.withAttribute(IsZero) diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/Transposed.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/Transposed.kt index 3e93a2a23..2cc566f92 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/Transposed.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/Transposed.kt @@ -6,10 +6,14 @@ package space.kscience.kmath.linear import space.kscience.attributes.Attributes +import space.kscience.attributes.SafeType public class TransposedMatrix(public val origin: Matrix) : Matrix { + override val type: SafeType get() = origin.type + override val rowNum: Int get() = origin.colNum + override val colNum: Int get() = origin.rowNum override fun get(i: Int, j: Int): T = origin[j, i] diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/VirtualMatrix.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/VirtualMatrix.kt index 97de82c7a..9cb7c5771 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/VirtualMatrix.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/VirtualMatrix.kt @@ -6,6 +6,7 @@ package space.kscience.kmath.linear import space.kscience.attributes.Attributes +import space.kscience.attributes.SafeType import space.kscience.kmath.nd.ShapeND @@ -14,7 +15,8 @@ import space.kscience.kmath.nd.ShapeND * * @property generator the function that provides elements. */ -public class VirtualMatrix( +public class VirtualMatrix( + override val type: SafeType, override val rowNum: Int, override val colNum: Int, override val attributes: Attributes = Attributes.EMPTY, @@ -29,4 +31,4 @@ public class VirtualMatrix( public fun MatrixBuilder.virtual( attributes: Attributes = Attributes.EMPTY, generator: (i: Int, j: Int) -> T, -): VirtualMatrix = VirtualMatrix(rows, columns, attributes, generator) +): VirtualMatrix = VirtualMatrix(type, rows, columns, attributes, generator) diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/matrixAttributes.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/matrixAttributes.kt index 5bb35edef..8787d0e09 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/matrixAttributes.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/matrixAttributes.kt @@ -3,13 +3,11 @@ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ -@file:OptIn(UnstableKMathAPI::class) @file:Suppress("UnusedReceiverParameter") package space.kscience.kmath.linear import space.kscience.attributes.* -import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.nd.StructureAttribute /** @@ -51,9 +49,11 @@ public val MatrixOperations.Inverted: Inverted get() = Inverted(safeTy * * @param T the type of matrices' items. */ -public class Determinant : MatrixAttribute +public class Determinant(type: SafeType) : + PolymorphicAttribute(type), + MatrixAttribute -public val MatrixOperations.Determinant: Determinant get() = Determinant() +public val MatrixOperations.Determinant: Determinant get() = Determinant(type) /** * Matrices with this feature are lower triangular ones. diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/misc/sorting.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/misc/sorting.kt index f369f0614..0c0ef82fb 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/misc/sorting.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/misc/sorting.kt @@ -4,6 +4,8 @@ */ +@file:OptIn(UnstableKMathAPI::class) + package space.kscience.kmath.misc import space.kscience.kmath.UnstableKMathAPI @@ -22,10 +24,9 @@ public fun > Buffer.indicesSorted(): IntArray = permSortInd /** * Create a zero-copy virtual buffer that contains the same elements but in ascending order */ -@OptIn(UnstableKMathAPI::class) public fun > Buffer.sorted(): Buffer { val permutations = indicesSorted() - return VirtualBuffer(size) { this[permutations[it]] } + return VirtualBuffer(type, size) { this[permutations[it]] } } @UnstableKMathAPI @@ -35,30 +36,27 @@ public fun > Buffer.indicesSortedDescending(): IntArray = /** * Create a zero-copy virtual buffer that contains the same elements but in descending order */ -@OptIn(UnstableKMathAPI::class) public fun > Buffer.sortedDescending(): Buffer { val permutations = indicesSortedDescending() - return VirtualBuffer(size) { this[permutations[it]] } + return VirtualBuffer(type, size) { this[permutations[it]] } } @UnstableKMathAPI public fun > Buffer.indicesSortedBy(selector: (V) -> C): IntArray = permSortIndicesWith(compareBy { selector(get(it)) }) -@OptIn(UnstableKMathAPI::class) public fun > Buffer.sortedBy(selector: (V) -> C): Buffer { val permutations = indicesSortedBy(selector) - return VirtualBuffer(size) { this[permutations[it]] } + return VirtualBuffer(type, size) { this[permutations[it]] } } @UnstableKMathAPI public fun > Buffer.indicesSortedByDescending(selector: (V) -> C): IntArray = permSortIndicesWith(compareByDescending { selector(get(it)) }) -@OptIn(UnstableKMathAPI::class) public fun > Buffer.sortedByDescending(selector: (V) -> C): Buffer { val permutations = indicesSortedByDescending(selector) - return VirtualBuffer(size) { this[permutations[it]] } + return VirtualBuffer(type, size) { this[permutations[it]] } } @UnstableKMathAPI @@ -68,10 +66,9 @@ public fun Buffer.indicesSortedWith(comparator: Comparator): IntArray /** * Create virtual zero-copy buffer with elements sorted by [comparator] */ -@OptIn(UnstableKMathAPI::class) public fun Buffer.sortedWith(comparator: Comparator): Buffer { val permutations = indicesSortedWith(comparator) - return VirtualBuffer(size) { this[permutations[it]] } + return VirtualBuffer(type,size) { this[permutations[it]] } } private fun Buffer.permSortIndicesWith(comparator: Comparator): IntArray { diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/AlgebraND.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/AlgebraND.kt index 0611225c1..88aa52387 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/AlgebraND.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/AlgebraND.kt @@ -8,7 +8,7 @@ package space.kscience.kmath.nd import space.kscience.kmath.PerformancePitfall import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.operations.* -import kotlin.reflect.KClass +import space.kscience.kmath.structures.MutableBufferFactory /** * The base interface for all ND-algebra implementations. @@ -91,6 +91,8 @@ public interface AlgebraND> : Algebra> { * @param A the type of group over structure elements. */ public interface GroupOpsND> : GroupOps>, AlgebraND { + override val bufferFactory: MutableBufferFactory> get() = MutableBufferFactory>() + /** * Element-wise addition. * 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 78bc83826..365d013f9 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 @@ -7,6 +7,8 @@ package space.kscience.kmath.nd +import space.kscience.attributes.SafeType +import space.kscience.attributes.safeTypeOf import space.kscience.kmath.PerformancePitfall import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.operations.* @@ -105,6 +107,9 @@ public open class BufferedGroupNDOps>( override val bufferAlgebra: BufferAlgebra, override val indexerBuilder: (ShapeND) -> ShapeIndexer = BufferAlgebraND.defaultIndexerBuilder, ) : GroupOpsND, BufferAlgebraND { + + override val type: SafeType> get() = safeTypeOf>() + override fun StructureND.unaryMinus(): StructureND = map { -it } } diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/BufferND.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/BufferND.kt index 461a82e0a..1caf0c662 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/BufferND.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/BufferND.kt @@ -5,6 +5,7 @@ package space.kscience.kmath.nd +import space.kscience.attributes.SafeType import space.kscience.kmath.PerformancePitfall import space.kscience.kmath.structures.Buffer import space.kscience.kmath.structures.BufferFactory @@ -23,6 +24,8 @@ public open class BufferND( public open val buffer: Buffer, ) : StructureND { + override val type: SafeType get() = buffer.type + @PerformancePitfall override operator fun get(index: IntArray): T = buffer[indices.offset(index)] @@ -36,7 +39,7 @@ public open class BufferND( */ public inline fun BufferND( shape: ShapeND, - bufferFactory: BufferFactory = BufferFactory.auto(), + bufferFactory: BufferFactory = BufferFactory(), crossinline initializer: (IntArray) -> T, ): BufferND { val strides = Strides(shape) @@ -84,10 +87,10 @@ public open class MutableBufferND( /** * Create a generic [BufferND] using provided [initializer] */ -public fun MutableBufferND( +public inline fun MutableBufferND( shape: ShapeND, - bufferFactory: MutableBufferFactory = MutableBufferFactory.boxing(), - initializer: (IntArray) -> T, + bufferFactory: MutableBufferFactory = MutableBufferFactory(), + crossinline initializer: (IntArray) -> T, ): MutableBufferND { val strides = Strides(shape) return MutableBufferND(strides, bufferFactory(strides.linearSize) { initializer(strides.index(it)) }) diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/PermutedStructureND.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/PermutedStructureND.kt index 6c35e2f44..56ccf2df8 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/PermutedStructureND.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/PermutedStructureND.kt @@ -5,6 +5,7 @@ package space.kscience.kmath.nd +import space.kscience.attributes.SafeType import space.kscience.kmath.PerformancePitfall @@ -13,6 +14,8 @@ public class PermutedStructureND( public val permutation: (IntArray) -> IntArray, ) : StructureND { + override val type: SafeType get() = origin.type + override val shape: ShapeND get() = origin.shape @@ -32,6 +35,7 @@ public class PermutedMutableStructureND( public val permutation: (IntArray) -> IntArray, ) : MutableStructureND { + override val type: SafeType get() = origin.type @OptIn(PerformancePitfall::class) override fun set(index: IntArray, value: T) { diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Structure1D.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Structure1D.kt index 984b5ad0f..ee9eff8dc 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Structure1D.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Structure1D.kt @@ -5,6 +5,7 @@ package space.kscience.kmath.nd +import space.kscience.attributes.SafeType import space.kscience.kmath.PerformancePitfall import space.kscience.kmath.operations.asSequence import space.kscience.kmath.structures.Buffer @@ -46,6 +47,9 @@ public interface MutableStructure1D : Structure1D, MutableStructureND, */ @JvmInline private value class Structure1DWrapper(val structure: StructureND) : Structure1D { + + override val type: SafeType get() = structure.type + override val shape: ShapeND get() = structure.shape override val size: Int get() = structure.shape[0] @@ -60,6 +64,9 @@ private value class Structure1DWrapper(val structure: StructureND) : S * A 1D wrapper for a mutable nd-structure */ private class MutableStructure1DWrapper(val structure: MutableStructureND) : MutableStructure1D { + + override val type: SafeType get() = structure.type + override val shape: ShapeND get() = structure.shape override val size: Int get() = structure.shape[0] @@ -79,7 +86,7 @@ private class MutableStructure1DWrapper(val structure: MutableStructureND) .elements() .map(Pair::second) .toMutableList() - .asMutableBuffer() + .asMutableBuffer(type) override fun toString(): String = Buffer.toString(this) } @@ -90,6 +97,9 @@ private class MutableStructure1DWrapper(val structure: MutableStructureND) */ @JvmInline private value class Buffer1DWrapper(val buffer: Buffer) : Structure1D { + + override val type: SafeType get() = buffer.type + override val shape: ShapeND get() = ShapeND(buffer.size) override val size: Int get() = buffer.size @@ -102,6 +112,9 @@ private value class Buffer1DWrapper(val buffer: Buffer) : Structure1D< } internal class MutableBuffer1DWrapper(val buffer: MutableBuffer) : MutableStructure1D { + + override val type: SafeType get() = buffer.type + override val shape: ShapeND get() = ShapeND(buffer.size) override val size: Int get() = buffer.size diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Structure2D.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Structure2D.kt index eff58acc3..49e8c7dd7 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Structure2D.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Structure2D.kt @@ -6,13 +6,12 @@ package space.kscience.kmath.nd import space.kscience.attributes.Attributes +import space.kscience.attributes.SafeType import space.kscience.kmath.PerformancePitfall import space.kscience.kmath.structures.Buffer import space.kscience.kmath.structures.MutableBuffer -import space.kscience.kmath.structures.MutableListBuffer import space.kscience.kmath.structures.VirtualBuffer import kotlin.jvm.JvmInline -import kotlin.reflect.KClass /** * A structure that is guaranteed to be two-dimensional. @@ -33,18 +32,18 @@ public interface Structure2D : StructureND { override val shape: ShapeND get() = ShapeND(rowNum, colNum) /** - * The buffer of rows of this structure. It gets elements from the structure dynamically. + * The buffer of rows for this structure. It gets elements from the structure dynamically. */ @PerformancePitfall public val rows: List> - get() = List(rowNum) { i -> VirtualBuffer(colNum) { j -> get(i, j) } } + get() = List(rowNum) { i -> VirtualBuffer(type, colNum) { j -> get(i, j) } } /** - * The buffer of columns of this structure. It gets elements from the structure dynamically. + * The buffer of columns for this structure. It gets elements from the structure dynamically. */ @PerformancePitfall public val columns: List> - get() = List(colNum) { j -> VirtualBuffer(rowNum) { i -> get(i, j) } } + get() = List(colNum) { j -> VirtualBuffer(type, rowNum) { i -> get(i, j) } } /** * Retrieves an element from the structure by two indices. @@ -88,14 +87,14 @@ public interface MutableStructure2D : Structure2D, MutableStructureND { */ @PerformancePitfall override val rows: List> - get() = List(rowNum) { i -> MutableListBuffer(colNum) { j -> get(i, j) } } + get() = List(rowNum) { i -> MutableBuffer(type, colNum) { j -> get(i, j) } } /** - * The buffer of columns of this structure. It gets elements from the structure dynamically. + * The buffer of columns for this structure. It gets elements from the structure dynamically. */ @PerformancePitfall override val columns: List> - get() = List(colNum) { j -> MutableListBuffer(rowNum) { i -> get(i, j) } } + get() = List(colNum) { j -> MutableBuffer(type, rowNum) { i -> get(i, j) } } } /** @@ -103,6 +102,9 @@ public interface MutableStructure2D : Structure2D, MutableStructureND { */ @JvmInline private value class Structure2DWrapper(val structure: StructureND) : Structure2D { + + override val type: SafeType get() = structure.type + override val shape: ShapeND get() = structure.shape override val rowNum: Int get() = shape[0] @@ -122,6 +124,9 @@ private value class Structure2DWrapper(val structure: StructureND) : S * A 2D wrapper for a mutable nd-structure */ private class MutableStructure2DWrapper(val structure: MutableStructureND) : MutableStructure2D { + + override val type: SafeType get() = structure.type + override val shape: ShapeND get() = structure.shape override val rowNum: Int get() = shape[0] diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/StructureND.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/StructureND.kt index bc86f62ae..d0d078609 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/StructureND.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/StructureND.kt @@ -12,6 +12,7 @@ import space.kscience.attributes.SafeType import space.kscience.kmath.PerformancePitfall import space.kscience.kmath.linear.LinearSpace import space.kscience.kmath.operations.Ring +import space.kscience.kmath.operations.WithType import space.kscience.kmath.operations.invoke import space.kscience.kmath.structures.Buffer import kotlin.jvm.JvmName @@ -28,9 +29,9 @@ public interface StructureAttribute : Attribute * * @param T the type of items. */ -public interface StructureND : AttributeContainer, WithShape { +public interface StructureND : AttributeContainer, WithShape, WithType { /** - * The shape of structure i.e., non-empty sequence of non-negative integers that specify sizes of dimensions of + * The shape of structure i.e., non-empty sequence of non-negative integers that specify sizes of dimensions for * this structure. */ override val shape: ShapeND @@ -117,57 +118,61 @@ public interface StructureND : AttributeContainer, WithShape { return "$className(shape=${structure.shape}, buffer=$bufferRepr)" } - /** - * Creates a NDStructure with explicit buffer factory. - * - * Strides should be reused if possible. - */ - public fun buffered( - strides: Strides, - initializer: (IntArray) -> T, - ): BufferND = BufferND(strides, Buffer.boxing(strides.linearSize) { i -> initializer(strides.index(i)) }) - - - public fun buffered( - shape: ShapeND, - initializer: (IntArray) -> T, - ): BufferND = buffered(ColumnStrides(shape), initializer) - - /** - * Inline create NDStructure with non-boxing buffer implementation if it is possible - */ - public inline fun auto( - strides: Strides, - crossinline initializer: (IntArray) -> T, - ): BufferND = BufferND(strides, Buffer.auto(strides.linearSize) { i -> initializer(strides.index(i)) }) - - public inline fun auto( - type: SafeType, - strides: Strides, - crossinline initializer: (IntArray) -> T, - ): BufferND = BufferND(strides, Buffer.auto(type, strides.linearSize) { i -> initializer(strides.index(i)) }) - - - public inline fun auto( - shape: ShapeND, - crossinline initializer: (IntArray) -> T, - ): BufferND = auto(ColumnStrides(shape), initializer) - - @JvmName("autoVarArg") - public inline fun auto( - vararg shape: Int, - crossinline initializer: (IntArray) -> T, - ): BufferND = - auto(ColumnStrides(ShapeND(shape)), initializer) - - public inline fun auto( - type: SafeType, - vararg shape: Int, - crossinline initializer: (IntArray) -> T, - ): BufferND = auto(type, ColumnStrides(ShapeND(shape)), initializer) } } + +/** + * Creates a NDStructure with explicit buffer factory. + * + * Strides should be reused if possible. + */ +public fun BufferND( + type: SafeType, + strides: Strides, + initializer: (IntArray) -> T, +): BufferND = BufferND(strides, Buffer(type, strides.linearSize) { i -> initializer(strides.index(i)) }) + + +public fun BufferND( + type: SafeType, + shape: ShapeND, + initializer: (IntArray) -> T, +): BufferND = BufferND(type, ColumnStrides(shape), initializer) + +/** + * Inline create NDStructure with non-boxing buffer implementation if it is possible + */ +public inline fun BufferND( + strides: Strides, + crossinline initializer: (IntArray) -> T, +): BufferND = BufferND(strides, Buffer(strides.linearSize) { i -> initializer(strides.index(i)) }) + +public inline fun BufferND( + type: SafeType, + strides: Strides, + crossinline initializer: (IntArray) -> T, +): BufferND = BufferND(strides, Buffer(type, strides.linearSize) { i -> initializer(strides.index(i)) }) + + +public inline fun BufferND( + shape: ShapeND, + crossinline initializer: (IntArray) -> T, +): BufferND = BufferND(ColumnStrides(shape), initializer) + +@JvmName("autoVarArg") +public inline fun BufferND( + vararg shape: Int, + crossinline initializer: (IntArray) -> T, +): BufferND = BufferND(ColumnStrides(ShapeND(shape)), initializer) + +public inline fun BufferND( + type: SafeType, + vararg shape: Int, + crossinline initializer: (IntArray) -> T, +): BufferND = BufferND(type, ColumnStrides(ShapeND(shape)), initializer) + + /** * Indicates whether some [StructureND] is equal to another one. */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/VirtualStructureND.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/VirtualStructureND.kt index 606b9a631..824d82b06 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/VirtualStructureND.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/VirtualStructureND.kt @@ -5,10 +5,13 @@ package space.kscience.kmath.nd +import space.kscience.attributes.SafeType +import space.kscience.attributes.safeTypeOf import space.kscience.kmath.PerformancePitfall import space.kscience.kmath.UnstableKMathAPI public open class VirtualStructureND( + override val type: SafeType, override val shape: ShapeND, public val producer: (IntArray) -> T, ) : StructureND { @@ -24,10 +27,10 @@ public open class VirtualStructureND( public class VirtualDoubleStructureND( shape: ShapeND, producer: (IntArray) -> Double, -) : VirtualStructureND(shape, producer) +) : VirtualStructureND(safeTypeOf(), shape, producer) @UnstableKMathAPI public class VirtualIntStructureND( shape: ShapeND, producer: (IntArray) -> Int, -) : VirtualStructureND(shape, producer) \ No newline at end of file +) : VirtualStructureND(safeTypeOf(), shape, producer) \ No newline at end of file diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/operationsND.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/operationsND.kt index 40db5187f..0376da116 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/operationsND.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/operationsND.kt @@ -10,7 +10,7 @@ import space.kscience.kmath.PerformancePitfall @OptIn(PerformancePitfall::class) public fun StructureND.roll(axis: Int, step: Int = 1): StructureND { require(axis in shape.indices) { "Axis $axis is outside of shape dimensions: [0, ${shape.size})" } - return VirtualStructureND(shape) { index -> + return VirtualStructureND(type, shape) { index -> val newIndex: IntArray = IntArray(index.size) { indexAxis -> if (indexAxis == axis) { (index[indexAxis] + step).mod(shape[indexAxis]) @@ -26,7 +26,7 @@ public fun StructureND.roll(axis: Int, step: Int = 1): StructureND { public fun StructureND.roll(pair: Pair, vararg others: Pair): StructureND { val axisMap: Map = mapOf(pair, *others) require(axisMap.keys.all { it in shape.indices }) { "Some of axes ${axisMap.keys} is outside of shape dimensions: [0, ${shape.size})" } - return VirtualStructureND(shape) { index -> + return VirtualStructureND(type, shape) { index -> val newIndex: IntArray = IntArray(index.size) { indexAxis -> val offset = axisMap[indexAxis] ?: 0 (index[indexAxis] + offset).mod(shape[indexAxis]) diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/Algebra.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/Algebra.kt index ca8a4f59d..44e9a0b17 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/Algebra.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/Algebra.kt @@ -5,22 +5,32 @@ package space.kscience.kmath.operations +import space.kscience.attributes.SafeType import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.expressions.Symbol import space.kscience.kmath.operations.Ring.Companion.optimizedPower import space.kscience.kmath.structures.MutableBufferFactory -import kotlin.reflect.KType + +/** + * An interface containing [type] for dynamic type checking. + */ +public interface WithType { + public val type: SafeType +} + /** * Represents an algebraic structure. * * @param T the type of element which Algebra operates on. */ -public interface Algebra { +public interface Algebra : WithType { /** * Provide a factory for buffers, associated with this [Algebra] */ - public val bufferFactory: MutableBufferFactory get() = MutableBufferFactory.boxing() + public val bufferFactory: MutableBufferFactory + + override val type: SafeType get() = bufferFactory.type /** * Wraps a raw string to [T] object. This method is designed for three purposes: @@ -265,7 +275,7 @@ public interface Ring : Group, RingOps { */ public fun power(arg: T, pow: UInt): T = optimizedPower(arg, pow) - public companion object{ + public companion object { /** * Raises [arg] to the non-negative integer power [exponent]. * @@ -348,7 +358,7 @@ public interface Field : Ring, FieldOps, ScaleOperations, NumericAlg public fun power(arg: T, pow: Int): T = optimizedPower(arg, pow) - public companion object{ + public companion object { /** * Raises [arg] to the integer power [exponent]. * @@ -361,7 +371,11 @@ public interface Field : Ring, FieldOps, ScaleOperations, NumericAlg * @author Iaroslav Postovalov, Evgeniy Zhelenskiy */ private fun Field.optimizedPower(arg: T, exponent: Int): T = when { - exponent < 0 -> one / (this as Ring).optimizedPower(arg, if (exponent == Int.MIN_VALUE) Int.MAX_VALUE.toUInt().inc() else (-exponent).toUInt()) + exponent < 0 -> one / (this as Ring).optimizedPower( + arg, + if (exponent == Int.MIN_VALUE) Int.MAX_VALUE.toUInt().inc() else (-exponent).toUInt() + ) + else -> (this as Ring).optimizedPower(arg, exponent.toUInt()) } } diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/BigInt.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/BigInt.kt index 34a6d4a80..25554477c 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/BigInt.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/BigInt.kt @@ -5,6 +5,8 @@ package space.kscience.kmath.operations +import space.kscience.attributes.SafeType +import space.kscience.attributes.safeTypeOf import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.nd.BufferedRingOpsND import space.kscience.kmath.operations.BigInt.Companion.BASE @@ -26,6 +28,9 @@ private typealias TBase = ULong */ @OptIn(UnstableKMathAPI::class) public object BigIntField : Field, NumbersAddOps, ScaleOperations { + + override val type: SafeType = safeTypeOf() + override val zero: BigInt = BigInt.ZERO override val one: BigInt = BigInt.ONE @@ -528,10 +533,10 @@ public fun String.parseBigInteger(): BigInt? { public val BigInt.algebra: BigIntField get() = BigIntField public inline fun BigInt.Companion.buffer(size: Int, initializer: (Int) -> BigInt): Buffer = - Buffer.boxing(size, initializer) + Buffer(size, initializer) public inline fun BigInt.Companion.mutableBuffer(size: Int, initializer: (Int) -> BigInt): Buffer = - Buffer.boxing(size, initializer) + Buffer(size, initializer) public val BigIntField.nd: BufferedRingOpsND get() = BufferedRingOpsND(BufferRingOps(BigIntField)) diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/BufferAlgebra.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/BufferAlgebra.kt index 526d024ca..5a8b26571 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/BufferAlgebra.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/BufferAlgebra.kt @@ -5,10 +5,11 @@ package space.kscience.kmath.operations +import space.kscience.attributes.SafeType +import space.kscience.attributes.safeTypeOf import space.kscience.kmath.structures.Buffer import space.kscience.kmath.structures.MutableBuffer import space.kscience.kmath.structures.MutableBufferFactory -import kotlin.reflect.KType public interface WithSize { public val size: Int @@ -20,6 +21,8 @@ public interface WithSize { public interface BufferAlgebra> : Algebra> { public val elementAlgebra: A + override val type: SafeType> get() = safeTypeOf>() + public val elementBufferFactory: MutableBufferFactory get() = elementAlgebra.bufferFactory public fun buffer(size: Int, vararg elements: T): Buffer { diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/LogicAlgebra.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/LogicAlgebra.kt index d8bf0fb57..312fd1396 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/LogicAlgebra.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/LogicAlgebra.kt @@ -5,6 +5,8 @@ package space.kscience.kmath.operations +import space.kscience.attributes.SafeType +import space.kscience.attributes.safeTypeOf import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.expressions.Symbol @@ -72,6 +74,8 @@ public interface LogicAlgebra : Algebra { @Suppress("EXTENSION_SHADOWED_BY_MEMBER") public object BooleanAlgebra : LogicAlgebra { + override val type: SafeType get() = safeTypeOf() + override fun const(boolean: Boolean): Boolean = boolean override fun Boolean.not(): Boolean = !this diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/integerFields.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/integerFields.kt index 72e33c523..a3a819a9b 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/integerFields.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/integerFields.kt @@ -8,7 +8,10 @@ package space.kscience.kmath.operations import space.kscience.kmath.operations.Int16Field.div import space.kscience.kmath.operations.Int32Field.div import space.kscience.kmath.operations.Int64Field.div -import space.kscience.kmath.structures.* +import space.kscience.kmath.structures.Int16 +import space.kscience.kmath.structures.Int32 +import space.kscience.kmath.structures.Int64 +import space.kscience.kmath.structures.MutableBufferFactory import kotlin.math.roundToInt import kotlin.math.roundToLong @@ -22,7 +25,7 @@ import kotlin.math.roundToLong */ @Suppress("EXTENSION_SHADOWED_BY_MEMBER") public object Int16Field : Field, Norm, NumericAlgebra { - override val bufferFactory: MutableBufferFactory = MutableBufferFactory(::Int16Buffer) + override val bufferFactory: MutableBufferFactory = MutableBufferFactory() override val zero: Int16 get() = 0 override val one: Int16 get() = 1 @@ -45,7 +48,8 @@ public object Int16Field : Field, Norm, NumericAlgebra, Norm, NumericAlgebra { - override val bufferFactory: MutableBufferFactory = MutableBufferFactory(::Int32Buffer) + override val bufferFactory: MutableBufferFactory = MutableBufferFactory() + override val zero: Int get() = 0 override val one: Int get() = 1 @@ -68,7 +72,7 @@ public object Int32Field : Field, Norm, NumericAlgebra, Norm, NumericAlgebra { - override val bufferFactory: MutableBufferFactory = MutableBufferFactory(::Int64Buffer) + override val bufferFactory: MutableBufferFactory = MutableBufferFactory() override val zero: Int64 get() = 0L override val one: Int64 get() = 1L 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 0b7bef852..7d8e12139 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 @@ -67,7 +67,7 @@ public interface ExtendedField : ExtendedFieldOps, Field, NumericAlgebr */ @Suppress("EXTENSION_SHADOWED_BY_MEMBER") public object Float64Field : ExtendedField, Norm, ScaleOperations { - override val bufferFactory: MutableBufferFactory = MutableBufferFactory(::Float64Buffer) + override val bufferFactory: MutableBufferFactory = MutableBufferFactory() override val zero: Double get() = 0.0 override val one: Double get() = 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 91baac2bf..c3dbfbfe2 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 @@ -8,8 +8,8 @@ package space.kscience.kmath.structures import space.kscience.attributes.SafeType import space.kscience.attributes.safeTypeOf import space.kscience.kmath.operations.WithSize +import space.kscience.kmath.operations.WithType import space.kscience.kmath.operations.asSequence -import kotlin.jvm.JvmInline import kotlin.reflect.typeOf /** @@ -17,35 +17,46 @@ import kotlin.reflect.typeOf * * @param T the type of buffer. */ -public fun interface BufferFactory { +public interface BufferFactory : WithType { + public operator fun invoke(size: Int, builder: (Int) -> T): Buffer - - public companion object{ - public inline fun auto(): BufferFactory = - BufferFactory(Buffer.Companion::auto) - - public fun boxing(): BufferFactory = - BufferFactory(Buffer.Companion::boxing) - } } +/** + * Create a [BufferFactory] for given [type], using primitive storage if possible + */ +public fun BufferFactory(type: SafeType): BufferFactory = object : BufferFactory { + override val type: SafeType = type + override fun invoke(size: Int, builder: (Int) -> T): Buffer = Buffer(type, size, builder) +} + +/** + * Create [BufferFactory] using the reified type + */ +public inline fun BufferFactory(): BufferFactory = BufferFactory(safeTypeOf()) + /** * Function that produces [MutableBuffer] from its size and function that supplies values. * * @param T the type of buffer. */ -public fun interface MutableBufferFactory : BufferFactory { +public interface MutableBufferFactory : BufferFactory { override fun invoke(size: Int, builder: (Int) -> T): MutableBuffer - - public companion object { - public inline fun auto(): MutableBufferFactory = - MutableBufferFactory(MutableBuffer.Companion::auto) - - public fun boxing(): MutableBufferFactory = - MutableBufferFactory(MutableBuffer.Companion::boxing) - } } +/** + * Create a [MutableBufferFactory] for given [type], using primitive storage if possible + */ +public fun MutableBufferFactory(type: SafeType): MutableBufferFactory = object : MutableBufferFactory { + override val type: SafeType = type + override fun invoke(size: Int, builder: (Int) -> T): MutableBuffer = MutableBuffer(type, size, builder) +} + +/** + * Create [BufferFactory] using the reified type + */ +public inline fun MutableBufferFactory(): MutableBufferFactory = MutableBufferFactory(safeTypeOf()) + /** * A generic read-only random-access structure for both primitives and objects. * @@ -53,14 +64,14 @@ public fun interface MutableBufferFactory : BufferFactory { * * @param T the type of elements contained in the buffer. */ -public interface Buffer : WithSize { +public interface Buffer : WithSize, WithType { /** * The size of this buffer. */ override val size: Int /** - * Gets element at given index. + * Gets an element at given index. */ public operator fun get(index: Int): T @@ -87,41 +98,48 @@ public interface Buffer : WithSize { return true } - /** - * Creates a [ListBuffer] of given type [T] with given [size]. Each element is calculated by calling the - * specified [initializer] function. - */ - public inline fun boxing(size: Int, initializer: (Int) -> T): Buffer = - List(size, initializer).asBuffer() - - /** - * Creates a [Buffer] of given [type]. If the type is primitive, specialized buffers are used ([Int32Buffer], - * [Float64Buffer], 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: SafeType, size: Int, initializer: (Int) -> T): Buffer = - when (type.kType) { - typeOf() -> MutableBuffer.double(size) { initializer(it) as Double } as Buffer - typeOf() -> MutableBuffer.short(size) { initializer(it) as Short } as Buffer - typeOf() -> MutableBuffer.int(size) { initializer(it) as Int } as Buffer - typeOf() -> MutableBuffer.long(size) { initializer(it) as Long } as Buffer - typeOf() -> MutableBuffer.float(size) { initializer(it) as Float } as Buffer - else -> boxing(size, initializer) - } - - /** - * Creates a [Buffer] of given type [T]. If the type is primitive, specialized buffers are used ([Int32Buffer], - * [Float64Buffer], etc.), [ListBuffer] is returned otherwise. - * - * The [size] is specified, and each element is calculated by calling the specified [initializer] function. - */ - public inline fun auto(size: Int, initializer: (Int) -> T): Buffer = - auto(safeTypeOf(), size, initializer) } } +/** + * Creates a [Buffer] of given type [T]. If the type is primitive, specialized buffers are used ([Int32Buffer], + * [Float64Buffer], 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 Buffer(size: Int, initializer: (Int) -> T): Buffer { + val type = safeTypeOf() + return when (type.kType) { + typeOf() -> MutableBuffer.double(size) { initializer(it) as Double } as Buffer + typeOf() -> MutableBuffer.short(size) { initializer(it) as Short } as Buffer + typeOf() -> MutableBuffer.int(size) { initializer(it) as Int } as Buffer + typeOf() -> MutableBuffer.long(size) { initializer(it) as Long } as Buffer + typeOf() -> MutableBuffer.float(size) { initializer(it) as Float } as Buffer + else -> List(size, initializer).asBuffer(type) + } +} + +/** + * Creates a [Buffer] of given [type]. If the type is primitive, specialized buffers are used ([Int32Buffer], + * [Float64Buffer], etc.), [ListBuffer] is returned otherwise. + * + * The [size] is specified, and each element is calculated by calling the specified [initializer] function. + */ +@Suppress("UNCHECKED_CAST") +public fun Buffer( + type: SafeType, + size: Int, + initializer: (Int) -> T, +): Buffer = when (type.kType) { + typeOf() -> MutableBuffer.double(size) { initializer(it) as Double } as Buffer + typeOf() -> MutableBuffer.short(size) { initializer(it) as Short } as Buffer + typeOf() -> MutableBuffer.int(size) { initializer(it) as Int } as Buffer + typeOf() -> MutableBuffer.long(size) { initializer(it) as Long } as Buffer + typeOf() -> MutableBuffer.float(size) { initializer(it) as Float } as Buffer + else -> List(size, initializer).asBuffer(type) +} + /** * Returns an [IntRange] of the valid indices for this [Buffer]. */ @@ -144,28 +162,17 @@ public fun Buffer.last(): T { return get(size - 1) } -/** - * Immutable wrapper for [MutableBuffer]. - * - * @param T the type of elements contained in the buffer. - * @property buffer The underlying buffer. - */ -@JvmInline -public value class ReadOnlyBuffer(public val buffer: MutableBuffer) : Buffer { - override val size: Int get() = buffer.size - - override operator fun get(index: Int): T = buffer[index] - - override operator fun iterator(): Iterator = buffer.iterator() -} - /** * A buffer with content calculated on-demand. The calculated content is not stored, so it is recalculated on each call. - * Useful when one needs single element from the buffer. + * Useful when one needs a single element from the buffer. * * @param T the type of elements provided by the buffer. */ -public class VirtualBuffer(override val size: Int, private val generator: (Int) -> T) : Buffer { +public class VirtualBuffer( + override val type: SafeType, + override val size: Int, + private val generator: (Int) -> T, +) : Buffer { override operator fun get(index: Int): T { if (index < 0 || index >= size) throw IndexOutOfBoundsException("Expected index from 0 to ${size - 1}, but found $index") return generator(index) @@ -177,6 +184,9 @@ public class VirtualBuffer(override val size: Int, private val generator: } /** - * Convert this buffer to read-only buffer. + * Inline builder for [VirtualBuffer] */ -public fun Buffer.asReadOnly(): Buffer = if (this is MutableBuffer) ReadOnlyBuffer(this) else this \ No newline at end of file +public inline fun VirtualBuffer( + size: Int, + noinline generator: (Int) -> T, +): VirtualBuffer = VirtualBuffer(safeTypeOf(), size, generator) diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/BufferAccessor2D.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/BufferAccessor2D.kt index 3edd7d3b1..a2f01137c 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/BufferAccessor2D.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/BufferAccessor2D.kt @@ -5,7 +5,13 @@ package space.kscience.kmath.structures -import space.kscience.kmath.nd.* +import space.kscience.attributes.SafeType +import space.kscience.kmath.nd.BufferND +import space.kscience.kmath.nd.ShapeND +import space.kscience.kmath.nd.Structure2D +import space.kscience.kmath.nd.as2D +import kotlin.collections.component1 +import kotlin.collections.component2 /** * A context that allows to operate on a [MutableBuffer] as on 2d array @@ -27,11 +33,13 @@ internal class BufferAccessor2D( fun create(mat: Structure2D): MutableBuffer = create { i, j -> mat[i, j] } //TODO optimize wrapper - fun MutableBuffer.toStructure2D(): Structure2D = StructureND.buffered( - ColumnStrides(ShapeND(rowNum, colNum)) + fun MutableBuffer.toStructure2D(): Structure2D = BufferND( + type, ShapeND(rowNum, colNum) ) { (i, j) -> get(i, j) }.as2D() inner class Row(val buffer: MutableBuffer, val rowIndex: Int) : MutableBuffer { + override val type: SafeType get() = buffer.type + override val size: Int get() = colNum override operator fun get(index: Int): T = buffer[rowIndex, index] 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 d99e02996..10419a074 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 @@ -5,6 +5,8 @@ package space.kscience.kmath.structures +import space.kscience.attributes.SafeType +import space.kscience.attributes.safeTypeOf import kotlin.experimental.and /** @@ -57,6 +59,9 @@ public class FlaggedDoubleBuffer( public val values: DoubleArray, public val flags: ByteArray ) : FlaggedBuffer, Buffer { + + override val type: SafeType = safeTypeOf() + init { require(values.size == flags.size) { "Values and flags must have the same dimensions" } } diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Float32Buffer.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Float32Buffer.kt index 44ef4dcf0..b8fbe3436 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Float32Buffer.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Float32Buffer.kt @@ -5,6 +5,8 @@ package space.kscience.kmath.structures +import space.kscience.attributes.SafeType +import space.kscience.attributes.safeTypeOf import kotlin.jvm.JvmInline /** @@ -15,6 +17,9 @@ import kotlin.jvm.JvmInline */ @JvmInline public value class Float32Buffer(public val array: FloatArray) : PrimitiveBuffer { + + override val type: SafeType get() = safeTypeOf() + override val size: Int get() = array.size override operator fun get(index: Int): Float = array[index] diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Float64Buffer.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Float64Buffer.kt index 0542c1bf4..5837adf83 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Float64Buffer.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Float64Buffer.kt @@ -5,6 +5,8 @@ package space.kscience.kmath.structures +import space.kscience.attributes.SafeType +import space.kscience.attributes.safeTypeOf import space.kscience.kmath.operations.BufferTransform import kotlin.jvm.JvmInline @@ -15,6 +17,9 @@ import kotlin.jvm.JvmInline */ @JvmInline public value class Float64Buffer(public val array: DoubleArray) : PrimitiveBuffer { + + override val type: SafeType get() = safeTypeOf() + override val size: Int get() = array.size override operator fun get(index: Int): Double = array[index] diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Int16Buffer.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Int16Buffer.kt index 1ba40c934..cf3af61a7 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Int16Buffer.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Int16Buffer.kt @@ -5,6 +5,8 @@ package space.kscience.kmath.structures +import space.kscience.attributes.SafeType +import space.kscience.attributes.safeTypeOf import kotlin.jvm.JvmInline /** @@ -14,6 +16,8 @@ import kotlin.jvm.JvmInline */ @JvmInline public value class Int16Buffer(public val array: ShortArray) : MutableBuffer { + + override val type: SafeType get() = safeTypeOf() override val size: Int get() = array.size override operator fun get(index: Int): Short = array[index] diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Int32Buffer.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Int32Buffer.kt index afd94e9cd..365ec8688 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Int32Buffer.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Int32Buffer.kt @@ -5,6 +5,8 @@ package space.kscience.kmath.structures +import space.kscience.attributes.SafeType +import space.kscience.attributes.safeTypeOf import kotlin.jvm.JvmInline /** @@ -14,6 +16,9 @@ import kotlin.jvm.JvmInline */ @JvmInline public value class Int32Buffer(public val array: IntArray) : PrimitiveBuffer { + + override val type: SafeType get() = safeTypeOf() + override val size: Int get() = array.size override operator fun get(index: Int): Int = array[index] diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Int64Buffer.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Int64Buffer.kt index c67d109aa..5f831ed3e 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Int64Buffer.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Int64Buffer.kt @@ -5,6 +5,8 @@ package space.kscience.kmath.structures +import space.kscience.attributes.SafeType +import space.kscience.attributes.safeTypeOf import kotlin.jvm.JvmInline /** @@ -14,6 +16,9 @@ import kotlin.jvm.JvmInline */ @JvmInline public value class Int64Buffer(public val array: LongArray) : PrimitiveBuffer { + + override val type: SafeType get() = safeTypeOf() + override val size: Int get() = array.size override operator fun get(index: Int): Long = array[index] diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Int8Buffer.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Int8Buffer.kt index 923fbec06..e61056979 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Int8Buffer.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Int8Buffer.kt @@ -5,6 +5,8 @@ package space.kscience.kmath.structures +import space.kscience.attributes.SafeType +import space.kscience.attributes.safeTypeOf import kotlin.jvm.JvmInline /** @@ -14,6 +16,9 @@ import kotlin.jvm.JvmInline */ @JvmInline public value class Int8Buffer(public val array: ByteArray) : MutableBuffer { + + override val type: SafeType get() = safeTypeOf() + override val size: Int get() = array.size override operator fun get(index: Int): Byte = array[index] diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/ListBuffer.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/ListBuffer.kt index fbc9a489b..ad065a0c3 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/ListBuffer.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/ListBuffer.kt @@ -5,7 +5,8 @@ package space.kscience.kmath.structures -import kotlin.jvm.JvmInline +import space.kscience.attributes.SafeType +import space.kscience.attributes.safeTypeOf /** * [Buffer] implementation over [List]. @@ -13,9 +14,7 @@ import kotlin.jvm.JvmInline * @param T the type of elements contained in the buffer. * @property list The underlying list. */ -public class ListBuffer(public val list: List) : Buffer { - - public constructor(size: Int, initializer: (Int) -> T) : this(List(size, initializer)) +public class ListBuffer(override val type: SafeType, public val list: List) : Buffer { override val size: Int get() = list.size @@ -29,7 +28,12 @@ public class ListBuffer(public val list: List) : Buffer { /** * Returns an [ListBuffer] that wraps the original list. */ -public fun List.asBuffer(): ListBuffer = ListBuffer(this) +public fun List.asBuffer(type: SafeType): ListBuffer = ListBuffer(type, this) + +/** + * Returns an [ListBuffer] that wraps the original list. + */ +public inline fun List.asBuffer(): ListBuffer = asBuffer(safeTypeOf()) /** * [MutableBuffer] implementation over [MutableList]. @@ -37,10 +41,7 @@ public fun List.asBuffer(): ListBuffer = ListBuffer(this) * @param T the type of elements contained in the buffer. * @property list The underlying list. */ -@JvmInline -public value class MutableListBuffer(public val list: MutableList) : MutableBuffer { - - public constructor(size: Int, initializer: (Int) -> T) : this(MutableList(size, initializer)) +public class MutableListBuffer(override val type: SafeType, public val list: MutableList) : MutableBuffer { override val size: Int get() = list.size @@ -51,10 +52,24 @@ public value class MutableListBuffer(public val list: MutableList) : Mutab } override operator fun iterator(): Iterator = list.iterator() - override fun copy(): MutableBuffer = MutableListBuffer(ArrayList(list)) + override fun copy(): MutableBuffer = MutableListBuffer(type, ArrayList(list)) + + override fun toString(): String = Buffer.toString(this) } + /** * Returns an [MutableListBuffer] that wraps the original list. */ -public fun MutableList.asMutableBuffer(): MutableListBuffer = MutableListBuffer(this) +public fun MutableList.asMutableBuffer(type: SafeType): MutableListBuffer = MutableListBuffer( + type, + this +) + +/** + * Returns an [MutableListBuffer] that wraps the original list. + */ +public inline fun MutableList.asMutableBuffer(): MutableListBuffer = MutableListBuffer( + safeTypeOf(), + this +) diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/MutableBuffer.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/MutableBuffer.kt index eb0074734..21d3f9c6f 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/MutableBuffer.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/MutableBuffer.kt @@ -61,41 +61,35 @@ public interface MutableBuffer : Buffer { */ public inline fun float(size: Int, initializer: (Int) -> Float): Float32Buffer = Float32Buffer(size, initializer) - - - /** - * Create a boxing mutable buffer of given type - */ - public inline fun boxing(size: Int, initializer: (Int) -> T): MutableBuffer = - MutableListBuffer(MutableList(size, initializer)) - - /** - * Creates a [MutableBuffer] of given [type]. If the type is primitive, specialized buffers are used - * ([Int32Buffer], [Float64Buffer], 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: SafeType, size: Int, initializer: (Int) -> T): MutableBuffer = - when (type.kType) { - typeOf() -> double(size) { initializer(it) as Double } as MutableBuffer - typeOf() -> short(size) { initializer(it) as Short } as MutableBuffer - typeOf() -> int(size) { initializer(it) as Int } as MutableBuffer - typeOf() -> float(size) { initializer(it) as Float } as MutableBuffer - typeOf() -> long(size) { initializer(it) as Long } as MutableBuffer - else -> boxing(size, initializer) - } - - /** - * Creates a [MutableBuffer] of given type [T]. If the type is primitive, specialized buffers are used - * ([Int32Buffer], [Float64Buffer], etc.), [ListBuffer] is returned otherwise. - * - * The [size] is specified, and each element is calculated by calling the specified [initializer] function. - */ - public inline fun auto(size: Int, initializer: (Int) -> T): MutableBuffer = - auto(safeTypeOf(), size, initializer) } } +/** + * Creates a [MutableBuffer] of given [type]. If the type is primitive, specialized buffers are used + * ([Int32Buffer], [Float64Buffer], 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 MutableBuffer(type: SafeType, size: Int, initializer: (Int) -> T): MutableBuffer = + when (type.kType) { + typeOf() -> MutableBuffer.double(size) { initializer(it) as Double } as MutableBuffer + typeOf() -> MutableBuffer.short(size) { initializer(it) as Short } as MutableBuffer + typeOf() -> MutableBuffer.int(size) { initializer(it) as Int } as MutableBuffer + typeOf() -> MutableBuffer.float(size) { initializer(it) as Float } as MutableBuffer + typeOf() -> MutableBuffer.long(size) { initializer(it) as Long } as MutableBuffer + else -> MutableListBuffer(type, MutableList(size, initializer)) + } + +/** + * Creates a [MutableBuffer] of given type [T]. If the type is primitive, specialized buffers are used + * ([Int32Buffer], [Float64Buffer], etc.), [ListBuffer] is returned otherwise. + * + * The [size] is specified, and each element is calculated by calling the specified [initializer] function. + */ +public inline fun MutableBuffer(size: Int, initializer: (Int) -> T): MutableBuffer = + MutableBuffer(safeTypeOf(), size, initializer) + + public sealed interface PrimitiveBuffer : MutableBuffer \ No newline at end of file diff --git a/kmath-core/src/commonTest/kotlin/space/kscience/kmath/linear/DoubleLUSolverTest.kt b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/linear/DoubleLUSolverTest.kt index 4d05f9043..17b6d69b8 100644 --- a/kmath-core/src/commonTest/kotlin/space/kscience/kmath/linear/DoubleLUSolverTest.kt +++ b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/linear/DoubleLUSolverTest.kt @@ -40,7 +40,7 @@ class DoubleLUSolverTest { //Check determinant assertEquals(7.0, lup.determinant) - assertMatrixEquals(lup.p dot matrix, lup.l dot lup.u) + assertMatrixEquals(lup.pivotMatrix dot matrix, lup.l dot lup.u) } @Test diff --git a/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/_generated.kt b/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/_generated.kt index 0cef96f49..881649d01 100644 --- a/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/_generated.kt +++ b/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/_generated.kt @@ -19,19 +19,13 @@ import org.ejml.sparse.csc.factory.DecompositionFactory_DSCC import org.ejml.sparse.csc.factory.DecompositionFactory_FSCC import org.ejml.sparse.csc.factory.LinearSolverFactory_DSCC import org.ejml.sparse.csc.factory.LinearSolverFactory_FSCC +import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.linear.* import space.kscience.kmath.linear.Matrix -import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.nd.StructureFeature -import space.kscience.kmath.structures.Float64 -import space.kscience.kmath.structures.Float32 -import space.kscience.kmath.operations.Float64Field import space.kscience.kmath.operations.Float32Field -import space.kscience.kmath.operations.DoubleField -import space.kscience.kmath.operations.FloatField +import space.kscience.kmath.operations.Float64Field import space.kscience.kmath.operations.invoke -import space.kscience.kmath.structures.Float64Buffer -import space.kscience.kmath.structures.Float32Buffer import space.kscience.kmath.structures.DoubleBuffer import space.kscience.kmath.structures.FloatBuffer import kotlin.reflect.KClass diff --git a/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/UniformHistogramGroupND.kt b/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/UniformHistogramGroupND.kt index f7094f7a9..f9e2e14f2 100644 --- a/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/UniformHistogramGroupND.kt +++ b/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/UniformHistogramGroupND.kt @@ -147,12 +147,12 @@ public fun > Histogram.Companion.uniformNDFromRanges( bufferFactory: BufferFactory = valueAlgebraND.elementAlgebra.bufferFactory, ): UniformHistogramGroupND = UniformHistogramGroupND( valueAlgebraND, - ListBuffer( + DoubleBuffer( ranges .map(Pair, Int>::first) .map(ClosedFloatingPointRange::start) ), - ListBuffer( + DoubleBuffer( ranges .map(Pair, Int>::first) .map(ClosedFloatingPointRange::endInclusive) From 2386ecba41ff00e234bf5a282e71deda3ec135aa Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sat, 4 Nov 2023 11:49:31 +0300 Subject: [PATCH 15/40] 0.4 WIP --- .../space/kscience/attributes/Attributes.kt | 7 + .../space/kscience/attributes/SafeType.kt | 9 +- .../benchmarks/MatrixInverseBenchmark.kt | 2 +- .../space/kscience/kmath/ast/TestParser.kt | 3 + kmath-complex/build.gradle.kts | 1 + .../space/kscience/kmath/complex/Complex.kt | 23 +- .../kscience/kmath/complex/Quaternion.kt | 16 +- kmath-core/build.gradle.kts | 1 - .../space/kscience/kmath/annotations.kt | 0 .../kscience/kmath/expressions/DSAlgebra.kt | 2 +- .../kmath/expressions/SimpleAutoDiff.kt | 1 + .../kmath/linear/BufferedLinearSpace.kt | 3 - .../kscience/kmath/linear/LinearSpace.kt | 8 +- .../kscience/kmath/linear/LupDecomposition.kt | 210 +++++++----------- .../kscience/kmath/linear/MatrixBuilder.kt | 2 +- .../kscience/kmath/linear/MatrixWrapper.kt | 2 +- .../space/kscience/kmath/nd/StructureND.kt | 19 +- .../kscience/kmath/operations/Algebra.kt | 9 +- .../space/kscience/kmath/operations/BigInt.kt | 6 +- .../kmath/operations/BufferAlgebra.kt | 6 +- .../kscience/kmath/operations/LogicAlgebra.kt | 5 +- .../kscience/kmath/operations/numbers.kt | 12 +- .../kscience/kmath/structures/ArrayBuffer.kt | 13 +- .../space/kscience/kmath/structures/Buffer.kt | 2 +- .../kscience/kmath/structures/BufferView.kt | 7 +- .../kmath/structures/MutableBuffer.kt | 24 +- .../space/kscience/kmath/linear/MatrixTest.kt | 9 +- .../kscience/kmath/operations/BigNumbers.kt | 4 + .../kscience/kmath/chains/BlockingChain.kt | 4 +- .../kscience/kmath/streaming/BufferFlow.kt | 5 +- .../kscience/kmath/streaming/RingBuffer.kt | 42 ++-- .../kmath/structures/LazyStructureND.kt | 12 +- .../kscience/kmath/dimensions/Wrappers.kt | 10 +- .../kscience/kmath/ejml/EjmlLinearSpace.kt | 14 +- .../space/kscience/kmath/ejml/_generated.kt | 56 ++--- .../kscience/kmath/ejml/EjmlMatrixTest.kt | 2 +- .../space/kscience/kmath/real/RealMatrix.kt | 2 +- .../kscience/kmath/functions/Polynomial.kt | 5 +- .../integration/GaussIntegratorRuleFactory.kt | 5 +- .../kmath/integration/SplineIntegrator.kt | 4 +- .../kmath/interpolation/Interpolator.kt | 10 +- .../kmath/interpolation/SplineInterpolator.kt | 3 +- kmath-memory/build.gradle.kts | 4 + .../kscience/kmath/memory}/MemoryBuffer.kt | 17 +- .../space/kscience/kmath/memory/MemorySpec.kt | 5 +- 45 files changed, 297 insertions(+), 309 deletions(-) rename {kmath-memory => kmath-core}/src/commonMain/kotlin/space/kscience/kmath/annotations.kt (100%) rename {kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures => kmath-memory/src/commonMain/kotlin/space/kscience/kmath/memory}/MemoryBuffer.kt (84%) diff --git a/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/Attributes.kt b/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/Attributes.kt index 705e61436..a1bccc211 100644 --- a/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/Attributes.kt +++ b/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/Attributes.kt @@ -106,4 +106,11 @@ public fun > Attributes( attrValue: T, ): Attributes = Attributes(mapOf(attribute to attrValue)) +/** + * Create Attributes with a single [Unit] valued attribute + */ +public fun > Attributes( + attribute: A +): Attributes = Attributes(mapOf(attribute to Unit)) + public operator fun Attributes.plus(other: Attributes): Attributes = Attributes(content + other.content) \ No newline at end of file diff --git a/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/SafeType.kt b/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/SafeType.kt index 0fac2477c..1c7b0991a 100644 --- a/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/SafeType.kt +++ b/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/SafeType.kt @@ -25,4 +25,11 @@ public inline fun safeTypeOf(): SafeType = SafeType(typeOf()) */ @Suppress("UNCHECKED_CAST") @UnstableAttributesAPI -public val SafeType.kClass: KClass get() = kType.classifier as KClass \ No newline at end of file +public val SafeType.kClass: KClass get() = kType.classifier as KClass + +/** + * An interface containing [type] for dynamic type checking. + */ +public interface WithType { + public val type: SafeType +} \ No newline at end of file diff --git a/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/MatrixInverseBenchmark.kt b/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/MatrixInverseBenchmark.kt index f7aac8199..16e017432 100644 --- a/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/MatrixInverseBenchmark.kt +++ b/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/MatrixInverseBenchmark.kt @@ -47,7 +47,7 @@ internal class MatrixInverseBenchmark { @Benchmark fun ejmlInverse(blackhole: Blackhole) { EjmlLinearSpaceDDRM { - blackhole.consume(matrix.toEjml().inverse()) + blackhole.consume(matrix.toEjml().inverted()) } } } diff --git a/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/TestParser.kt b/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/TestParser.kt index 784dcece9..045890e71 100644 --- a/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/TestParser.kt +++ b/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/TestParser.kt @@ -10,6 +10,7 @@ import space.kscience.kmath.complex.ComplexField import space.kscience.kmath.expressions.interpret import space.kscience.kmath.operations.Algebra import space.kscience.kmath.operations.Float64Field +import space.kscience.kmath.structures.MutableBufferFactory import kotlin.test.Test import kotlin.test.assertEquals @@ -39,6 +40,8 @@ internal class TestParser { @Test fun evaluateMstBinary() { val magicalAlgebra = object : Algebra { + override val bufferFactory: MutableBufferFactory get() = MutableBufferFactory() + override fun bindSymbolOrNull(value: String): String = value override fun unaryOperationFunction(operation: String): (arg: String) -> String { diff --git a/kmath-complex/build.gradle.kts b/kmath-complex/build.gradle.kts index 3e8b3b75e..9ac2d5ab4 100644 --- a/kmath-complex/build.gradle.kts +++ b/kmath-complex/build.gradle.kts @@ -10,6 +10,7 @@ kscience { dependencies { api(projects.kmathCore) + api(projects.kmathMemory) } testDependencies { diff --git a/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/Complex.kt b/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/Complex.kt index b5f1aabe7..3a524bbb3 100644 --- a/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/Complex.kt +++ b/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/Complex.kt @@ -5,12 +5,14 @@ package space.kscience.kmath.complex +import space.kscience.attributes.SafeType +import space.kscience.attributes.safeTypeOf import space.kscience.kmath.UnstableKMathAPI -import space.kscience.kmath.memory.MemoryReader -import space.kscience.kmath.memory.MemorySpec -import space.kscience.kmath.memory.MemoryWriter +import space.kscience.kmath.memory.* import space.kscience.kmath.operations.* -import space.kscience.kmath.structures.* +import space.kscience.kmath.structures.Buffer +import space.kscience.kmath.structures.MutableBuffer +import space.kscience.kmath.structures.MutableBufferFactory import kotlin.math.* /** @@ -51,8 +53,11 @@ public object ComplexField : Norm, NumbersAddOps, ScaleOperations { - override val bufferFactory: MutableBufferFactory = MutableBufferFactory { size, init -> - MutableMemoryBuffer.create(Complex, size, init) + override val bufferFactory: MutableBufferFactory = object : MutableBufferFactory { + override fun invoke(size: Int, builder: (Int) -> Complex): MutableBuffer = + MutableMemoryBuffer.create(Complex, size, builder) + + override val type: SafeType = safeTypeOf() } override val zero: Complex = 0.0.toComplex() @@ -202,8 +207,10 @@ public data class Complex(val re: Double, val im: Double) { override fun toString(): String = "($re + i * $im)" public companion object : MemorySpec { - override val objectSize: Int - get() = 16 + + override val type: SafeType get() = safeTypeOf() + + override val objectSize: Int get() = 16 override fun MemoryReader.read(offset: Int): Complex = Complex(readDouble(offset), readDouble(offset + 8)) diff --git a/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/Quaternion.kt b/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/Quaternion.kt index 8f3d15a26..f6f9e9047 100644 --- a/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/Quaternion.kt +++ b/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/Quaternion.kt @@ -5,15 +5,14 @@ package space.kscience.kmath.complex +import space.kscience.attributes.SafeType +import space.kscience.attributes.safeTypeOf import space.kscience.kmath.UnstableKMathAPI -import space.kscience.kmath.memory.MemoryReader -import space.kscience.kmath.memory.MemorySpec -import space.kscience.kmath.memory.MemoryWriter +import space.kscience.kmath.memory.* import space.kscience.kmath.operations.* import space.kscience.kmath.structures.Buffer -import space.kscience.kmath.structures.MemoryBuffer import space.kscience.kmath.structures.MutableBuffer -import space.kscience.kmath.structures.MutableMemoryBuffer +import space.kscience.kmath.structures.MutableBufferFactory import kotlin.math.* /** @@ -37,6 +36,8 @@ public class Quaternion( require(!z.isNaN()) { "z-component of quaternion is not-a-number" } } + override val type: SafeType get() = safeTypeOf() + /** * Returns a string representation of this quaternion. */ @@ -78,6 +79,7 @@ public class Quaternion( public companion object : MemorySpec { override val objectSize: Int get() = 32 + override val type: SafeType get() = safeTypeOf() override fun MemoryReader.read(offset: Int): Quaternion = Quaternion( readDouble(offset), @@ -122,7 +124,7 @@ public val Quaternion.reciprocal: Quaternion /** * Produce a normalized version of this quaternion */ -public fun Quaternion.normalized(): Quaternion = with(QuaternionAlgebra){ this@normalized / norm(this@normalized) } +public fun Quaternion.normalized(): Quaternion = with(QuaternionAlgebra) { this@normalized / norm(this@normalized) } /** * A field of [Quaternion]. @@ -131,6 +133,8 @@ public fun Quaternion.normalized(): Quaternion = with(QuaternionAlgebra){ this@n public object QuaternionAlgebra : Group, Norm, PowerOperations, ExponentialOperations, NumbersAddOps, ScaleOperations { + override val bufferFactory: MutableBufferFactory = MutableBufferFactory() + override val zero: Quaternion = Quaternion(0.0) public val one: Quaternion = Quaternion(1.0) diff --git a/kmath-core/build.gradle.kts b/kmath-core/build.gradle.kts index 398465fbe..23fedbda4 100644 --- a/kmath-core/build.gradle.kts +++ b/kmath-core/build.gradle.kts @@ -9,7 +9,6 @@ kscience{ wasm() dependencies { - api(projects.kmathMemory) api(projects.attributesKt) } diff --git a/kmath-memory/src/commonMain/kotlin/space/kscience/kmath/annotations.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/annotations.kt similarity index 100% rename from kmath-memory/src/commonMain/kotlin/space/kscience/kmath/annotations.kt rename to kmath-core/src/commonMain/kotlin/space/kscience/kmath/annotations.kt diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/DSAlgebra.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/DSAlgebra.kt index 817f38ff0..8ef751859 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/DSAlgebra.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/DSAlgebra.kt @@ -188,7 +188,7 @@ public abstract class DSAlgebra>( vararg derivatives: T, ): DS { require(derivatives.size == compiler.size) { "dimension mismatch: ${derivatives.size} and ${compiler.size}" } - val data = derivatives.asBuffer() + val data = derivatives.asList().asBuffer(algebra.type) return DS(data) } 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 6d22b18dc..fd7bf9fdc 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 @@ -6,6 +6,7 @@ package space.kscience.kmath.expressions import space.kscience.attributes.SafeType +import space.kscience.attributes.WithType import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.linear.Point import space.kscience.kmath.operations.* diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/BufferedLinearSpace.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/BufferedLinearSpace.kt index 6bfe7581b..4bba47a91 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/BufferedLinearSpace.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/BufferedLinearSpace.kt @@ -5,15 +5,12 @@ package space.kscience.kmath.linear -import space.kscience.attributes.SafeType import space.kscience.kmath.PerformancePitfall import space.kscience.kmath.nd.* import space.kscience.kmath.operations.* import space.kscience.kmath.structures.Buffer import space.kscience.kmath.structures.VirtualBuffer import space.kscience.kmath.structures.indices -import kotlin.reflect.KType -import kotlin.reflect.typeOf public class BufferedLinearSpace>( 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 ddf4f17d4..00ebad5ee 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 @@ -6,11 +6,11 @@ package space.kscience.kmath.linear import space.kscience.attributes.SafeType +import space.kscience.attributes.WithType import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.nd.* import space.kscience.kmath.operations.BufferRingOps import space.kscience.kmath.operations.Ring -import space.kscience.kmath.operations.WithType import space.kscience.kmath.operations.invoke import space.kscience.kmath.structures.Buffer @@ -173,15 +173,15 @@ public interface LinearSpace> : MatrixOperations { public operator fun T.times(v: Point): Point = v * this /** - * Get an attribute value for the structure in this scope. Structure features take precedence other context features. + * Get an attribute value for the structure in this scope. Structure attributes are preferred to computed attributes. * * @param structure the structure. * @param attribute to be computed. * @return a feature object or `null` if it isn't present. */ @UnstableKMathAPI - public fun > attributeFor(structure: StructureND<*>, attribute: A): T? = - structure.attributes[attribute] + public fun > attributeFor(structure: StructureND<*>, attribute: A): T = + structure.attributes[attribute] ?: error("Can't compute attribute $attribute for $structure") public companion object { 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 1ac2ca5c6..6592a3da4 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 @@ -7,6 +7,7 @@ package space.kscience.kmath.linear +import space.kscience.attributes.Attributes import space.kscience.attributes.PolymorphicAttribute import space.kscience.attributes.SafeType import space.kscience.attributes.safeTypeOf @@ -19,32 +20,42 @@ import space.kscience.kmath.structures.* * *a* is the owning matrix. * * @param T the type of matrices' items. - * @param l The lower triangular matrix in this decomposition. It may have [LowerTriangular]. - * @param u The upper triangular matrix in this decomposition. It may have [UpperTriangular]. + * @param lu combined L and U matrix */ public class LupDecomposition( public val linearSpace: LinearSpace>, - public val l: Matrix, - public val u: Matrix, + private val lu: Matrix, public val pivot: IntBuffer, + private val even: Boolean, ) { public val elementAlgebra: Ring get() = linearSpace.elementAlgebra - public val pivotMatrix: VirtualMatrix + public val l: Matrix + get() = VirtualMatrix(lu.type, lu.rowNum, lu.colNum, attributes = Attributes(LowerTriangular)) { i, j -> + when { + j < i -> lu[i, j] + j == i -> elementAlgebra.one + else -> elementAlgebra.zero + } + } + + public val u: Matrix + get() = VirtualMatrix(lu.type, lu.rowNum, lu.colNum, attributes = Attributes(UpperTriangular)) { i, j -> + if (j >= i) lu[i, j] else elementAlgebra.zero + } + + public val pivotMatrix: Matrix get() = VirtualMatrix(linearSpace.type, l.rowNum, l.colNum) { row, column -> if (column == pivot[row]) elementAlgebra.one else elementAlgebra.zero } - public val LupDecomposition.determinant by lazy { + public val determinant: T by lazy { elementAlgebra { (0 until l.shape[0]).fold(if (even) one else -one) { value, i -> value * lu[i, i] } } } } - - - public class LupDecompositionAttribute(type: SafeType>) : PolymorphicAttribute>(type), MatrixAttribute> @@ -52,59 +63,6 @@ public class LupDecompositionAttribute(type: SafeType>) : public val MatrixOperations.LUP: LupDecompositionAttribute get() = LupDecompositionAttribute(safeTypeOf()) - -///** -// * Common implementation of [LupDecomposition]. -// */ -//private class LupDecompositionImpl( -// public val elementContext: Field, -// public val lu: Matrix, -// public val pivot: IntBuffer, -// private val even: Boolean, -//) : LupDecomposition { -// /** -// * Returns the matrix L of the decomposition. -// * -// * L is a lower-triangular matrix with [Ring.one] in diagonal -// */ -// override val l: Matrix = VirtualMatrix(lu.shape[0], lu.shape[1]) { i, j -> -// when { -// j < i -> lu[i, j] -// j == i -> elementContext.one -// else -> elementContext.zero -// } -// }.withFeature(LowerTriangular) -// -// -// /** -// * Returns the matrix U of the decomposition. -// * -// * U is an upper-triangular matrix including the diagonal -// */ -// override val u: Matrix = VirtualMatrix(lu.shape[0], lu.shape[1]) { i, j -> -// if (j >= i) lu[i, j] else elementContext.zero -// }.withFeature(UpperTriangular) -// -// /** -// * Returns the P rows permutation matrix. -// * -// * P is a sparse matrix with exactly one element set to [Ring.one] in -// * each row and each column, all other elements being set to [Ring.zero]. -// */ -// override val p: Matrix = VirtualMatrix(lu.shape[0], lu.shape[1]) { i, j -> -// if (j == pivot[i]) elementContext.one else elementContext.zero -// } -// -// /** -// * Return the determinant of the matrix -// * @return determinant of the matrix -// */ -// override val determinant: T by lazy { -// elementContext { (0 until lu.shape[0]).fold(if(even) one else -one) { value, i -> value * lu[i, i] } } -// } -// -//} - @PublishedApi internal fun > LinearSpace>.abs(value: T): T = if (value > elementAlgebra.zero) value else elementAlgebra { -value } @@ -115,97 +73,81 @@ internal fun > LinearSpace>.abs(value: T): T = public fun > LinearSpace>.lup( matrix: Matrix, checkSingular: (T) -> Boolean, -): LupDecomposition { +): LupDecomposition = elementAlgebra { require(matrix.rowNum == matrix.colNum) { "LU decomposition supports only square matrices" } val m = matrix.colNum val pivot = IntArray(matrix.rowNum) //TODO just waits for multi-receivers - BufferAccessor2D(matrix.rowNum, matrix.colNum, elementAlgebra.bufferFactory).run { - elementAlgebra { - val lu = create(matrix) + with(BufferAccessor2D(matrix.rowNum, matrix.colNum, elementAlgebra.bufferFactory)){ - // Initialize the permutation array and parity - for (row in 0 until m) pivot[row] = row - var even = true + val lu = create(matrix) - // Initialize the permutation array and parity - for (row in 0 until m) pivot[row] = row + // Initialize the permutation array and parity + for (row in 0 until m) pivot[row] = row + var even = true - // Loop over columns - for (col in 0 until m) { - // upper - for (row in 0 until col) { - val luRow = lu.row(row) - var sum = luRow[col] - for (i in 0 until row) sum -= luRow[i] * lu[i, col] - luRow[col] = sum - } + // Initialize the permutation array and parity + for (row in 0 until m) pivot[row] = row - // lower - var max = col // permutation row - var largest = -one - - for (row in col until m) { - val luRow = lu.row(row) - var sum = luRow[col] - for (i in 0 until col) sum -= luRow[i] * lu[i, col] - luRow[col] = sum - - // maintain the best permutation choice - if (abs(sum) > largest) { - largest = abs(sum) - max = row - } - } - - // Singularity check - check(!checkSingular(abs(lu[max, col]))) { "The matrix is singular" } - - // Pivot if necessary - if (max != col) { - val luMax = lu.row(max) - val luCol = lu.row(col) - - for (i in 0 until m) { - val tmp = luMax[i] - luMax[i] = luCol[i] - luCol[i] = tmp - } - - val temp = pivot[max] - pivot[max] = pivot[col] - pivot[col] = temp - even = !even - } - - // Divide the lower elements by the "winning" diagonal elt. - val luDiag = lu[col, col] - for (row in col + 1 until m) lu[row, col] /= luDiag + // Loop over columns + for (col in 0 until m) { + // upper + for (row in 0 until col) { + val luRow = lu.row(row) + var sum = luRow[col] + for (i in 0 until row) sum -= luRow[i] * lu[i, col] + luRow[col] = sum } - val l: MatrixWrapper = VirtualMatrix(type, rowNum, colNum) { i, j -> - when { - j < i -> lu[i, j] - j == i -> one - else -> zero + // lower + var max = col // permutation row + var largest = -one + + for (row in col until m) { + val luRow = lu.row(row) + var sum = luRow[col] + for (i in 0 until col) sum -= luRow[i] * lu[i, col] + luRow[col] = sum + + // maintain the best permutation choice + if (abs(sum) > largest) { + largest = abs(sum) + max = row } - }.withAttribute(LowerTriangular) + } - val u = VirtualMatrix(type, rowNum, colNum) { i, j -> - if (j >= i) lu[i, j] else zero - }.withAttribute(UpperTriangular) -// -// val p = VirtualMatrix(rowNum, colNum) { i, j -> -// if (j == pivot[i]) one else zero -// }.withAttribute(Determinant, if (even) one else -one) + // Singularity check + check(!checkSingular(abs(lu[max, col]))) { "The matrix is singular" } - return LupDecomposition(this@lup, l, u, pivot.asBuffer()) + // Pivot if necessary + if (max != col) { + val luMax = lu.row(max) + val luCol = lu.row(col) + + for (i in 0 until m) { + val tmp = luMax[i] + luMax[i] = luCol[i] + luCol[i] = tmp + } + + val temp = pivot[max] + pivot[max] = pivot[col] + pivot[col] = temp + even = !even + } + + // Divide the lower elements by the "winning" diagonal elt. + val luDiag = lu[col, col] + for (row in col + 1 until m) lu[row, col] /= luDiag } + + return LupDecomposition(this@lup, lu.toStructure2D(), pivot.asBuffer(), even) } } + public fun LinearSpace.lup( matrix: Matrix, singularityThreshold: Double = 1e-11, diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixBuilder.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixBuilder.kt index 9543555e0..b15d4883c 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixBuilder.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixBuilder.kt @@ -7,9 +7,9 @@ package space.kscience.kmath.linear import space.kscience.attributes.FlagAttribute import space.kscience.attributes.SafeType +import space.kscience.attributes.WithType import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.operations.Ring -import space.kscience.kmath.operations.WithType import space.kscience.kmath.structures.BufferAccessor2D import space.kscience.kmath.structures.MutableBufferFactory diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixWrapper.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixWrapper.kt index 9d89f7636..eb14de3c7 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixWrapper.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixWrapper.kt @@ -16,7 +16,7 @@ import space.kscience.kmath.operations.Ring * * @param T the type of items. */ -public class MatrixWrapper internal constructor( +public class MatrixWrapper internal constructor( public val origin: Matrix, override val attributes: Attributes, ) : Matrix by origin { diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/StructureND.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/StructureND.kt index d0d078609..1456d5ed8 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/StructureND.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/StructureND.kt @@ -5,17 +5,12 @@ package space.kscience.kmath.nd -import space.kscience.attributes.Attribute -import space.kscience.attributes.AttributeContainer -import space.kscience.attributes.Attributes -import space.kscience.attributes.SafeType +import space.kscience.attributes.* import space.kscience.kmath.PerformancePitfall import space.kscience.kmath.linear.LinearSpace import space.kscience.kmath.operations.Ring -import space.kscience.kmath.operations.WithType import space.kscience.kmath.operations.invoke import space.kscience.kmath.structures.Buffer -import kotlin.jvm.JvmName import kotlin.math.abs public interface StructureAttribute : Attribute @@ -148,28 +143,20 @@ public inline fun BufferND( crossinline initializer: (IntArray) -> T, ): BufferND = BufferND(strides, Buffer(strides.linearSize) { i -> initializer(strides.index(i)) }) -public inline fun BufferND( - type: SafeType, - strides: Strides, - crossinline initializer: (IntArray) -> T, -): BufferND = BufferND(strides, Buffer(type, strides.linearSize) { i -> initializer(strides.index(i)) }) - - public inline fun BufferND( shape: ShapeND, crossinline initializer: (IntArray) -> T, ): BufferND = BufferND(ColumnStrides(shape), initializer) -@JvmName("autoVarArg") public inline fun BufferND( vararg shape: Int, crossinline initializer: (IntArray) -> T, ): BufferND = BufferND(ColumnStrides(ShapeND(shape)), initializer) -public inline fun BufferND( +public fun BufferND( type: SafeType, vararg shape: Int, - crossinline initializer: (IntArray) -> T, + initializer: (IntArray) -> T, ): BufferND = BufferND(type, ColumnStrides(ShapeND(shape)), initializer) diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/Algebra.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/Algebra.kt index 44e9a0b17..310daa65b 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/Algebra.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/Algebra.kt @@ -6,19 +6,12 @@ package space.kscience.kmath.operations import space.kscience.attributes.SafeType +import space.kscience.attributes.WithType import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.expressions.Symbol import space.kscience.kmath.operations.Ring.Companion.optimizedPower import space.kscience.kmath.structures.MutableBufferFactory -/** - * An interface containing [type] for dynamic type checking. - */ -public interface WithType { - public val type: SafeType -} - - /** * Represents an algebraic structure. * diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/BigInt.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/BigInt.kt index 25554477c..eee991d27 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/BigInt.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/BigInt.kt @@ -5,20 +5,18 @@ package space.kscience.kmath.operations -import space.kscience.attributes.SafeType -import space.kscience.attributes.safeTypeOf import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.nd.BufferedRingOpsND import space.kscience.kmath.operations.BigInt.Companion.BASE import space.kscience.kmath.operations.BigInt.Companion.BASE_SIZE import space.kscience.kmath.structures.Buffer +import space.kscience.kmath.structures.MutableBufferFactory import kotlin.math.log2 import kotlin.math.max import kotlin.math.min import kotlin.math.sign private typealias Magnitude = UIntArray -private typealias TBase = ULong /** * Kotlin Multiplatform implementation of Big Integer numbers (KBigInteger). @@ -29,7 +27,7 @@ private typealias TBase = ULong @OptIn(UnstableKMathAPI::class) public object BigIntField : Field, NumbersAddOps, ScaleOperations { - override val type: SafeType = safeTypeOf() + override val bufferFactory: MutableBufferFactory = MutableBufferFactory() override val zero: BigInt = BigInt.ZERO override val one: BigInt = BigInt.ONE diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/BufferAlgebra.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/BufferAlgebra.kt index 5a8b26571..42e2d9876 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/BufferAlgebra.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/BufferAlgebra.kt @@ -5,8 +5,6 @@ package space.kscience.kmath.operations -import space.kscience.attributes.SafeType -import space.kscience.attributes.safeTypeOf import space.kscience.kmath.structures.Buffer import space.kscience.kmath.structures.MutableBuffer import space.kscience.kmath.structures.MutableBufferFactory @@ -21,10 +19,10 @@ public interface WithSize { public interface BufferAlgebra> : Algebra> { public val elementAlgebra: A - override val type: SafeType> get() = safeTypeOf>() - public val elementBufferFactory: MutableBufferFactory get() = elementAlgebra.bufferFactory + override val bufferFactory: MutableBufferFactory> get() = MutableBufferFactory() + public fun buffer(size: Int, vararg elements: T): Buffer { require(elements.size == size) { "Expected $size elements but found ${elements.size}" } return elementBufferFactory(size) { elements[it] } diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/LogicAlgebra.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/LogicAlgebra.kt index 312fd1396..1538b096b 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/LogicAlgebra.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/LogicAlgebra.kt @@ -5,10 +5,9 @@ package space.kscience.kmath.operations -import space.kscience.attributes.SafeType -import space.kscience.attributes.safeTypeOf import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.expressions.Symbol +import space.kscience.kmath.structures.MutableBufferFactory /** * An algebra for generic boolean logic @@ -74,7 +73,7 @@ public interface LogicAlgebra : Algebra { @Suppress("EXTENSION_SHADOWED_BY_MEMBER") public object BooleanAlgebra : LogicAlgebra { - override val type: SafeType get() = safeTypeOf() + override val bufferFactory: MutableBufferFactory get() = MutableBufferFactory() override fun const(boolean: Boolean): Boolean = boolean 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 7d8e12139..28b87aa2f 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 @@ -4,7 +4,7 @@ */ package space.kscience.kmath.operations -import space.kscience.kmath.structures.* +import space.kscience.kmath.structures.MutableBufferFactory import kotlin.math.pow as kpow @@ -129,7 +129,7 @@ public val Double.Companion.algebra: Float64Field get() = Float64Field */ @Suppress("EXTENSION_SHADOWED_BY_MEMBER") public object Float32Field : ExtendedField, Norm { - override val bufferFactory: MutableBufferFactory = MutableBufferFactory(::Float32Buffer) + override val bufferFactory: MutableBufferFactory = MutableBufferFactory() override val zero: Float get() = 0.0f override val one: Float get() = 1.0f @@ -187,7 +187,7 @@ public val Float.Companion.algebra: Float32Field get() = Float32Field */ @Suppress("EXTENSION_SHADOWED_BY_MEMBER") public object Int32Ring : Ring, Norm, NumericAlgebra { - override val bufferFactory: MutableBufferFactory = MutableBufferFactory(::Int32Buffer) + override val bufferFactory: MutableBufferFactory = MutableBufferFactory() override val zero: Int get() = 0 override val one: Int get() = 1 @@ -212,7 +212,7 @@ public val Int.Companion.algebra: Int32Ring get() = Int32Ring */ @Suppress("EXTENSION_SHADOWED_BY_MEMBER") public object Int16Ring : Ring, Norm, NumericAlgebra { - override val bufferFactory: MutableBufferFactory = MutableBufferFactory(::Int16Buffer) + override val bufferFactory: MutableBufferFactory = MutableBufferFactory() override val zero: Short get() = 0 override val one: Short get() = 1 @@ -237,7 +237,7 @@ public val Short.Companion.algebra: Int16Ring get() = Int16Ring */ @Suppress("EXTENSION_SHADOWED_BY_MEMBER") public object Int8Ring : Ring, Norm, NumericAlgebra { - override val bufferFactory: MutableBufferFactory = MutableBufferFactory(::Int8Buffer) + override val bufferFactory: MutableBufferFactory = MutableBufferFactory() override val zero: Byte get() = 0 override val one: Byte get() = 1 @@ -262,7 +262,7 @@ public val Byte.Companion.algebra: Int8Ring get() = Int8Ring */ @Suppress("EXTENSION_SHADOWED_BY_MEMBER") public object Int64Ring : Ring, Norm, NumericAlgebra { - override val bufferFactory: MutableBufferFactory = MutableBufferFactory(::Int64Buffer) + override val bufferFactory: MutableBufferFactory = MutableBufferFactory() override val zero: Long get() = 0L override val one: Long get() = 1L diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/ArrayBuffer.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/ArrayBuffer.kt index 8e81dd941..47817661f 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/ArrayBuffer.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/ArrayBuffer.kt @@ -5,13 +5,16 @@ package space.kscience.kmath.structures +import space.kscience.attributes.SafeType +import space.kscience.attributes.safeTypeOf + /** * [MutableBuffer] implementation over [Array]. * * @param T the type of elements contained in the buffer. * @property array The underlying array. */ -public class ArrayBuffer(internal val array: Array) : MutableBuffer { +public class ArrayBuffer(override val type: SafeType, internal val array: Array) : MutableBuffer { // Can't inline because array is invariant override val size: Int get() = array.size @@ -22,13 +25,17 @@ public class ArrayBuffer(internal val array: Array) : MutableBuffer { } override operator fun iterator(): Iterator = array.iterator() - override fun copy(): MutableBuffer = ArrayBuffer(array.copyOf()) + override fun copy(): MutableBuffer = ArrayBuffer(type, array.copyOf()) override fun toString(): String = Buffer.toString(this) } +/** + * Returns an [ArrayBuffer] that wraps the original array. + */ +public fun Array.asBuffer(type: SafeType): ArrayBuffer = ArrayBuffer(type, this) /** * Returns an [ArrayBuffer] that wraps the original array. */ -public fun Array.asBuffer(): ArrayBuffer = ArrayBuffer(this) \ No newline at end of file +public inline fun Array.asBuffer(): ArrayBuffer = ArrayBuffer(safeTypeOf(), this) \ No newline at end of file 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 c3dbfbfe2..26e238145 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 @@ -6,9 +6,9 @@ package space.kscience.kmath.structures import space.kscience.attributes.SafeType +import space.kscience.attributes.WithType import space.kscience.attributes.safeTypeOf import space.kscience.kmath.operations.WithSize -import space.kscience.kmath.operations.WithType import space.kscience.kmath.operations.asSequence import kotlin.reflect.typeOf diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/BufferView.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/BufferView.kt index f538fdd01..db22bd41a 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/BufferView.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/BufferView.kt @@ -1,5 +1,6 @@ package space.kscience.kmath.structures +import space.kscience.attributes.SafeType import space.kscience.kmath.UnstableKMathAPI /** @@ -8,6 +9,8 @@ import space.kscience.kmath.UnstableKMathAPI public interface BufferView : Buffer { public val origin: Buffer + override val type: SafeType get() = origin.type + /** * Get the index in [origin] buffer from index in this buffer. * Return -1 if element not present in the original buffer @@ -36,6 +39,7 @@ public class BufferSlice( } } + override fun get(index: Int): T = if (index >= size) { throw IndexOutOfBoundsException("$index is out of ${0 until size} rage") } else { @@ -100,7 +104,8 @@ public fun Buffer.slice(range: IntRange): BufferView = if (this is Buf * Dynamically create a range from the initial range */ @UnstableKMathAPI -public inline fun Buffer.slice(rangeBuilder: IntRange.() -> IntRange): BufferView = slice(rangeBuilder(indices)) +public inline fun Buffer.slice(rangeBuilder: IntRange.() -> IntRange): BufferView = + slice(rangeBuilder(indices)) /** * Resize original buffer to a given range using given [range], filling additional segments with [defaultValue]. diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/MutableBuffer.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/MutableBuffer.kt index 21d3f9c6f..0a2117d5d 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/MutableBuffer.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/MutableBuffer.kt @@ -72,15 +72,21 @@ public interface MutableBuffer : Buffer { * The [size] is specified, and each element is calculated by calling the specified [initializer] function. */ @Suppress("UNCHECKED_CAST") -public inline fun MutableBuffer(type: SafeType, size: Int, initializer: (Int) -> T): MutableBuffer = - when (type.kType) { - typeOf() -> MutableBuffer.double(size) { initializer(it) as Double } as MutableBuffer - typeOf() -> MutableBuffer.short(size) { initializer(it) as Short } as MutableBuffer - typeOf() -> MutableBuffer.int(size) { initializer(it) as Int } as MutableBuffer - typeOf() -> MutableBuffer.float(size) { initializer(it) as Float } as MutableBuffer - typeOf() -> MutableBuffer.long(size) { initializer(it) as Long } as MutableBuffer - else -> MutableListBuffer(type, MutableList(size, initializer)) - } +public inline fun MutableBuffer( + type: SafeType, + size: Int, + initializer: (Int) -> T, +): MutableBuffer = when (type.kType) { + typeOf() -> TODO() + typeOf() -> Int8Buffer(size) { initializer(it) as Int8 } as MutableBuffer + typeOf() -> MutableBuffer.short(size) { initializer(it) as Int16 } as MutableBuffer + typeOf() -> MutableBuffer.int(size) { initializer(it) as Int32 } as MutableBuffer + typeOf() -> MutableBuffer.long(size) { initializer(it) as Int64 } as MutableBuffer + typeOf() -> MutableBuffer.float(size) { initializer(it) as Float } as MutableBuffer + typeOf() -> MutableBuffer.double(size) { initializer(it) as Double } as MutableBuffer + //TODO add unsigned types + else -> MutableListBuffer(type, MutableList(size, initializer)) +} /** * Creates a [MutableBuffer] of given type [T]. If the type is primitive, specialized buffers are used diff --git a/kmath-core/src/commonTest/kotlin/space/kscience/kmath/linear/MatrixTest.kt b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/linear/MatrixTest.kt index 531aee259..d0e5fa884 100644 --- a/kmath-core/src/commonTest/kotlin/space/kscience/kmath/linear/MatrixTest.kt +++ b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/linear/MatrixTest.kt @@ -8,7 +8,6 @@ package space.kscience.kmath.linear import space.kscience.kmath.PerformancePitfall import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.nd.StructureND -import space.kscience.kmath.nd.as2D import space.kscience.kmath.operations.algebra import kotlin.test.Test import kotlin.test.assertEquals @@ -22,7 +21,7 @@ class MatrixTest { @Test fun testTranspose() = Double.algebra.linearSpace.run { val matrix = one(3, 3) - val transposed = matrix.transpose() + val transposed = matrix.transposed assertTrue { StructureND.contentEquals(matrix, transposed) } } @@ -38,7 +37,7 @@ class MatrixTest { @Test fun testMatrixExtension() = Double.algebra.linearSpace.run { - val transitionMatrix: Matrix = VirtualMatrix(6, 6) { row, col -> + val transitionMatrix: Matrix = VirtualMatrix(type,6, 6) { row, col -> when { col == 0 -> .50 row + 1 == col -> .50 @@ -60,8 +59,8 @@ class MatrixTest { @Test fun test2DDot() = Double.algebra.linearSpace.run { - val firstMatrix = StructureND.auto(2, 3) { (i, j) -> (i + j).toDouble() }.as2D() - val secondMatrix = StructureND.auto(3, 2) { (i, j) -> (i + j).toDouble() }.as2D() + val firstMatrix = buildMatrix(2, 3) { i, j -> (i + j).toDouble() } + val secondMatrix = buildMatrix(3, 2) { i, j -> (i + j).toDouble() } // val firstMatrix = produce(2, 3) { i, j -> (i + j).toDouble() } // val secondMatrix = produce(3, 2) { i, j -> (i + j).toDouble() } diff --git a/kmath-core/src/jvmMain/kotlin/space/kscience/kmath/operations/BigNumbers.kt b/kmath-core/src/jvmMain/kotlin/space/kscience/kmath/operations/BigNumbers.kt index 584748bd7..59c4380ab 100644 --- a/kmath-core/src/jvmMain/kotlin/space/kscience/kmath/operations/BigNumbers.kt +++ b/kmath-core/src/jvmMain/kotlin/space/kscience/kmath/operations/BigNumbers.kt @@ -5,6 +5,7 @@ package space.kscience.kmath.operations +import space.kscience.kmath.structures.MutableBufferFactory import java.math.BigDecimal import java.math.BigInteger import java.math.MathContext @@ -13,6 +14,8 @@ import java.math.MathContext * A field over [BigInteger]. */ public object JBigIntegerField : Ring, NumericAlgebra { + + override val bufferFactory: MutableBufferFactory = MutableBufferFactory() override val zero: BigInteger get() = BigInteger.ZERO override val one: BigInteger get() = BigInteger.ONE @@ -33,6 +36,7 @@ public object JBigIntegerField : Ring, NumericAlgebra { public abstract class JBigDecimalFieldBase internal constructor( private val mathContext: MathContext = MathContext.DECIMAL64, ) : Field, PowerOperations, NumericAlgebra, ScaleOperations { + override val bufferFactory: MutableBufferFactory = MutableBufferFactory() override val zero: BigDecimal get() = BigDecimal.ZERO diff --git a/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/chains/BlockingChain.kt b/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/chains/BlockingChain.kt index 2e9a15eed..c1fb097d9 100644 --- a/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/chains/BlockingChain.kt +++ b/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/chains/BlockingChain.kt @@ -43,7 +43,7 @@ public interface BlockingBufferChain : BlockingChain, BufferChain { public suspend inline fun Chain.nextBuffer(size: Int): Buffer = if (this is BufferChain) { nextBuffer(size) } else { - Buffer.auto(size) { next() } + Buffer(size) { next() } } public inline fun BlockingChain.nextBufferBlocking( @@ -51,5 +51,5 @@ public inline fun BlockingChain.nextBufferBlocking( ): Buffer = if (this is BlockingBufferChain) { nextBufferBlocking(size) } else { - Buffer.auto(size) { nextBlocking() } + Buffer(size) { nextBlocking() } } \ No newline at end of file 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 c52b6c3d5..5ab03cc4a 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 @@ -14,6 +14,7 @@ import kotlinx.coroutines.flow.asFlow import kotlinx.coroutines.flow.flatMapConcat import kotlinx.coroutines.flow.flow import space.kscience.kmath.chains.BlockingDoubleChain +import space.kscience.kmath.operations.Group import space.kscience.kmath.structures.Buffer import space.kscience.kmath.structures.BufferFactory import space.kscience.kmath.structures.Float64Buffer @@ -84,9 +85,9 @@ public fun Flow.chunked(bufferSize: Int): Flow = flow { * Map a flow to a moving window buffer. The window step is one. * To get different steps, one could use skip operation. */ -public fun Flow.windowed(window: Int): Flow> = flow { +public fun Flow.windowed(window: Int, algebra: Group): Flow> = flow { require(window > 1) { "Window size must be more than one" } - val ringBuffer = RingBuffer.boxing(window) + val ringBuffer = RingBuffer(window, algebra) this@windowed.collect { element -> ringBuffer.push(element) diff --git a/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/streaming/RingBuffer.kt b/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/streaming/RingBuffer.kt index bb07fede1..57f42819e 100644 --- a/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/streaming/RingBuffer.kt +++ b/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/streaming/RingBuffer.kt @@ -7,6 +7,8 @@ package space.kscience.kmath.streaming import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock +import space.kscience.attributes.SafeType +import space.kscience.kmath.operations.Group import space.kscience.kmath.structures.Buffer import space.kscience.kmath.structures.MutableBuffer import space.kscience.kmath.structures.VirtualBuffer @@ -14,12 +16,14 @@ import space.kscience.kmath.structures.VirtualBuffer /** * Thread-safe ring buffer */ -@Suppress("UNCHECKED_CAST") public class RingBuffer( - private val buffer: MutableBuffer, + private val buffer: MutableBuffer, private var startIndex: Int = 0, size: Int = 0, ) : Buffer { + + override val type: SafeType get() = buffer.type + private val mutex: Mutex = Mutex() override var size: Int = size @@ -28,7 +32,7 @@ public class RingBuffer( override operator fun get(index: Int): T { require(index >= 0) { "Index must be positive" } require(index < size) { "Index $index is out of circular buffer size $size" } - return buffer[startIndex.forward(index)] as T + return buffer[startIndex.forward(index)] } public fun isFull(): Boolean = size == buffer.size @@ -43,7 +47,7 @@ public class RingBuffer( override fun computeNext() { if (count == 0) done() else { - setNext(copy[index] as T) + setNext(copy[index]) index = index.forward(1) count-- } @@ -55,7 +59,7 @@ public class RingBuffer( */ public suspend fun snapshot(): Buffer = mutex.withLock { val copy = buffer.copy() - VirtualBuffer(size) { i -> copy[startIndex.forward(i)] as T } + VirtualBuffer(type, size) { i -> copy[startIndex.forward(i)] } } public suspend fun push(element: T) { @@ -68,19 +72,17 @@ public class RingBuffer( private fun Int.forward(n: Int): Int = (this + n) % (buffer.size) override fun toString(): String = Buffer.toString(this) - - public companion object { - public inline fun build(size: Int, empty: T): RingBuffer { - val buffer = MutableBuffer.auto(size) { empty } as MutableBuffer - return RingBuffer(buffer) - } - - /** - * Slow yet universal buffer - */ - public fun boxing(size: Int): RingBuffer { - val buffer: MutableBuffer = MutableBuffer.boxing(size) { null } - return RingBuffer(buffer) - } - } +} + +public inline fun RingBuffer(size: Int, empty: T): RingBuffer { + val buffer = MutableBuffer(size) { empty } + return RingBuffer(buffer) +} + +/** + * Slow yet universal buffer + */ +public fun RingBuffer(size: Int, algebra: Group): RingBuffer { + val buffer: MutableBuffer = MutableBuffer(algebra.type, size) { algebra.zero } + return RingBuffer(buffer) } 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 22c2ac3ff..d87335a9b 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 @@ -6,6 +6,8 @@ package space.kscience.kmath.structures import kotlinx.coroutines.* +import space.kscience.attributes.SafeType +import space.kscience.attributes.safeTypeOf import space.kscience.kmath.PerformancePitfall import space.kscience.kmath.coroutines.Math import space.kscience.kmath.nd.ColumnStrides @@ -14,9 +16,11 @@ import space.kscience.kmath.nd.StructureND public class LazyStructureND( public val scope: CoroutineScope, + override val type: SafeType, override val shape: ShapeND, public val function: suspend (IntArray) -> T, ) : StructureND { + private val cache: MutableMap> = HashMap() public fun async(index: IntArray): Deferred = cache.getOrPut(index) { @@ -47,13 +51,13 @@ public suspend fun StructureND.await(index: IntArray): T = * PENDING would benefit from KEEP-176 */ @OptIn(PerformancePitfall::class) -public inline fun StructureND.mapAsyncIndexed( +public inline fun StructureND.mapAsyncIndexed( scope: CoroutineScope, crossinline function: suspend (T, index: IntArray) -> R, -): LazyStructureND = LazyStructureND(scope, shape) { index -> function(get(index), index) } +): LazyStructureND = LazyStructureND(scope, safeTypeOf(), shape) { index -> function(get(index), index) } @OptIn(PerformancePitfall::class) -public inline fun StructureND.mapAsync( +public inline fun StructureND.mapAsync( scope: CoroutineScope, crossinline function: suspend (T) -> R, -): LazyStructureND = LazyStructureND(scope, shape) { index -> function(get(index)) } +): LazyStructureND = LazyStructureND(scope, safeTypeOf(), shape) { index -> function(get(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 f9d0f624d..fe8896075 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,6 +5,7 @@ package space.kscience.kmath.dimensions +import space.kscience.attributes.SafeType import space.kscience.kmath.linear.* import space.kscience.kmath.nd.ShapeND import space.kscience.kmath.nd.Structure2D @@ -48,6 +49,9 @@ public interface DMatrix : Structure2D { public value class DMatrixWrapper( private val structure: Structure2D, ) : DMatrix { + + override val type: SafeType get() = structure.type + override val shape: ShapeND get() = structure.shape override val rowNum: Int get() = shape[0] override val colNum: Int get() = shape[1] @@ -75,8 +79,10 @@ public interface DPoint : Point { * Dimension-safe point wrapper */ @JvmInline -public value class DPointWrapper(public val point: Point) : - DPoint { +public value class DPointWrapper(public val point: Point) : DPoint { + + override val type: SafeType get() = point.type + override val size: Int get() = point.size override operator fun get(index: Int): T = point[index] 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 ec1883128..a8f316650 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 @@ -6,14 +6,9 @@ package space.kscience.kmath.ejml import space.kscience.kmath.UnstableKMathAPI -import space.kscience.kmath.linear.InverseMatrixFeature -import space.kscience.kmath.linear.LinearSpace -import space.kscience.kmath.linear.Matrix -import space.kscience.kmath.linear.Point -import space.kscience.kmath.nd.Structure2D +import space.kscience.kmath.linear.* +import space.kscience.kmath.operations.Float64Field import space.kscience.kmath.operations.Ring -import kotlin.reflect.KType -import kotlin.reflect.typeOf /** * [LinearSpace] implementation specialized for a certain EJML type. @@ -42,8 +37,7 @@ public abstract class EjmlLinearSpace, out M : org.ejml public abstract override fun buildVector(size: Int, initializer: A.(Int) -> T): EjmlVector - @Suppress("UNCHECKED_CAST") @UnstableKMathAPI - public fun EjmlMatrix.inverse(): Structure2D = - attributeFor(this, InverseMatrixFeature::class)?.inverse as Structure2D + public fun EjmlMatrix.inverted(): Matrix = + attributeFor(this, Float64Field.linearSpace.Inverted) } diff --git a/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/_generated.kt b/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/_generated.kt index 881649d01..bf797fed4 100644 --- a/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/_generated.kt +++ b/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/_generated.kt @@ -131,10 +131,10 @@ public object EjmlLinearSpaceDDRM : EjmlLinearSpace.plus(other: Matrix): EjmlDoubleMatrix { val out = DMatrixRMaj(1, 1) - + CommonOps_DDRM.add( elementAlgebra.one, toEjml().origin, elementAlgebra.one, - other.toEjml().origin, + other.toEjml().origin, out, ) @@ -369,10 +369,10 @@ public object EjmlLinearSpaceFDRM : EjmlLinearSpace.plus(other: Matrix): EjmlFloatMatrix { val out = FMatrixRMaj(1, 1) - + CommonOps_FDRM.add( elementAlgebra.one, toEjml().origin, elementAlgebra.one, - other.toEjml().origin, + other.toEjml().origin, out, ) @@ -607,12 +607,12 @@ public object EjmlLinearSpaceDSCC : EjmlLinearSpace.plus(other: Matrix): EjmlDoubleMatrix { val out = DMatrixSparseCSC(1, 1) - + CommonOps_DSCC.add( elementAlgebra.one, toEjml().origin, elementAlgebra.one, - other.toEjml().origin, + other.toEjml().origin, out, - null, + null, null, ) @@ -656,7 +656,7 @@ public object EjmlLinearSpaceDSCC : EjmlLinearSpace.plus(other: Matrix): EjmlFloatMatrix { val out = FMatrixSparseCSC(1, 1) - + CommonOps_FSCC.add( elementAlgebra.one, toEjml().origin, elementAlgebra.one, - other.toEjml().origin, + other.toEjml().origin, out, - null, + null, null, ) @@ -889,7 +889,7 @@ public object EjmlLinearSpaceFSCC : EjmlLinearSpace if (i <= j) random.nextDouble() else 0.0 } val l = space.buildMatrix(dim, dim) { i, j -> if (i >= j) random.nextDouble() else 0.0 } val matrix = space { l dot u } - val inverted = matrix.toEjml().inverse() + val inverted = matrix.toEjml().inverted() val res = matrix dot inverted 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 fe5593eaa..9b71e2500 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 @@ -48,7 +48,7 @@ public fun Sequence.toMatrix(): RealMatrix = toList().let { } public fun RealMatrix.repeatStackVertical(n: Int): RealMatrix = - VirtualMatrix(rowNum * n, colNum) { row, col -> + VirtualMatrix(type, rowNum * n, colNum) { row, col -> get(if (row == 0) 0 else row % rowNum, col) } diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/Polynomial.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/Polynomial.kt index afd96aced..d4a414a5e 100644 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/Polynomial.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/Polynomial.kt @@ -7,14 +7,12 @@ package space.kscience.kmath.functions -import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.operations.Ring import space.kscience.kmath.operations.ScaleOperations import space.kscience.kmath.operations.invoke +import space.kscience.kmath.structures.MutableBufferFactory import kotlin.math.max import kotlin.math.min -import kotlin.reflect.KType -import kotlin.reflect.typeOf /** @@ -67,6 +65,7 @@ public data class Polynomial( public open class PolynomialSpace( public val ring: A, ) : Ring>, ScaleOperations> where A : Ring, A : ScaleOperations { + override val bufferFactory: MutableBufferFactory> get() = MutableBufferFactory() /** * Instance of zero constant (zero of the underlying ring). diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/GaussIntegratorRuleFactory.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/GaussIntegratorRuleFactory.kt index 91b3811c0..22dea15da 100644 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/GaussIntegratorRuleFactory.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/GaussIntegratorRuleFactory.kt @@ -5,6 +5,7 @@ package space.kscience.kmath.integration +import space.kscience.kmath.operations.Float64Field import space.kscience.kmath.operations.mapToBuffer import space.kscience.kmath.structures.Buffer import space.kscience.kmath.structures.Float64Buffer @@ -32,11 +33,11 @@ public fun GaussIntegratorRuleFactory.build( val normalized: Pair, Buffer> = build(numPoints) val length = range.endInclusive - range.start - val points = normalized.first.mapToBuffer(::Float64Buffer) { + val points = normalized.first.mapToBuffer(Float64Field.bufferFactory) { range.start + length / 2 + length / 2 * it } - val weights = normalized.second.mapToBuffer(::Float64Buffer) { + val weights = normalized.second.mapToBuffer(Float64Field.bufferFactory) { it * length / 2 } diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/SplineIntegrator.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/SplineIntegrator.kt index c03b248d4..f9a6edcb5 100644 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/SplineIntegrator.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/SplineIntegrator.kt @@ -88,7 +88,7 @@ public class SplineIntegrator>( public object DoubleSplineIntegrator : UnivariateIntegrator { override fun integrate(integrand: UnivariateIntegrand): UnivariateIntegrand { val range = integrand[IntegrationRange] ?: 0.0..1.0 - val interpolator: PolynomialInterpolator = SplineInterpolator(Float64Field, ::Float64Buffer) + val interpolator: PolynomialInterpolator = SplineInterpolator(Float64Field, Float64Field.bufferFactory) val nodes: Buffer = integrand[UnivariateIntegrationNodes] ?: run { val numPoints = integrand[IntegrandMaxCalls] ?: 100 @@ -96,7 +96,7 @@ public object DoubleSplineIntegrator : UnivariateIntegrator { Float64Buffer(numPoints) { i -> range.start + i * step } } - val values = nodes.mapToBuffer(::Float64Buffer) { integrand.function(it) } + val values = nodes.mapToBuffer(Float64Field.bufferFactory) { integrand.function(it) } val polynomials = interpolator.interpolatePolynomials(nodes, values) val res = polynomials.integrate(Float64Field, range) return integrand.withAttributes { diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/interpolation/Interpolator.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/interpolation/Interpolator.kt index 191e7dfd9..a65a41a62 100644 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/interpolation/Interpolator.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/interpolation/Interpolator.kt @@ -7,6 +7,8 @@ package space.kscience.kmath.interpolation +import space.kscience.attributes.SafeType +import space.kscience.attributes.WithType import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.data.XYColumnarData import space.kscience.kmath.functions.PiecewisePolynomial @@ -26,9 +28,11 @@ public fun interface Interpolator { /** * And interpolator returning [PiecewisePolynomial] function */ -public interface PolynomialInterpolator> : Interpolator { +public interface PolynomialInterpolator> : Interpolator, WithType { public val algebra: Ring + override val type: SafeType get() = algebra.type + public fun getDefaultValue(): T = error("Out of bounds") public fun interpolatePolynomials(points: XYColumnarData): PiecewisePolynomial @@ -50,14 +54,14 @@ public fun > PolynomialInterpolator.interpolatePolynomials( public fun > PolynomialInterpolator.interpolatePolynomials( data: Map, ): PiecewisePolynomial { - val pointSet = XYColumnarData.of(data.keys.toList().asBuffer(), data.values.toList().asBuffer()) + val pointSet = XYColumnarData.of(data.keys.toList().asBuffer(type), data.values.toList().asBuffer(type)) return interpolatePolynomials(pointSet) } public fun > PolynomialInterpolator.interpolatePolynomials( data: List>, ): PiecewisePolynomial { - val pointSet = XYColumnarData.of(data.map { it.first }.asBuffer(), data.map { it.second }.asBuffer()) + val pointSet = XYColumnarData.of(data.map { it.first }.asBuffer(type), data.map { it.second }.asBuffer(type)) return interpolatePolynomials(pointSet) } diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/interpolation/SplineInterpolator.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/interpolation/SplineInterpolator.kt index ed4657d53..e43e18050 100644 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/interpolation/SplineInterpolator.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/interpolation/SplineInterpolator.kt @@ -12,7 +12,6 @@ import space.kscience.kmath.functions.Polynomial import space.kscience.kmath.operations.Field import space.kscience.kmath.operations.Float64Field import space.kscience.kmath.operations.invoke -import space.kscience.kmath.structures.Float64Buffer import space.kscience.kmath.structures.MutableBufferFactory /** @@ -80,4 +79,4 @@ public fun > Field.splineInterpolator( ): SplineInterpolator = SplineInterpolator(this, bufferFactory) public val Float64Field.splineInterpolator: SplineInterpolator - get() = SplineInterpolator(this, ::Float64Buffer) \ No newline at end of file + get() = SplineInterpolator(this, bufferFactory) \ No newline at end of file diff --git a/kmath-memory/build.gradle.kts b/kmath-memory/build.gradle.kts index f1dff3b75..d2e50b10b 100644 --- a/kmath-memory/build.gradle.kts +++ b/kmath-memory/build.gradle.kts @@ -7,6 +7,10 @@ kscience { js() native() wasm() + + dependencies { + api(projects.kmathCore) + } } readme { diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/MemoryBuffer.kt b/kmath-memory/src/commonMain/kotlin/space/kscience/kmath/memory/MemoryBuffer.kt similarity index 84% rename from kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/MemoryBuffer.kt rename to kmath-memory/src/commonMain/kotlin/space/kscience/kmath/memory/MemoryBuffer.kt index cbfd6b9cd..f462be40e 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/MemoryBuffer.kt +++ b/kmath-memory/src/commonMain/kotlin/space/kscience/kmath/memory/MemoryBuffer.kt @@ -1,11 +1,13 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2023 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ -package space.kscience.kmath.structures +package space.kscience.kmath.memory -import space.kscience.kmath.memory.* +import space.kscience.attributes.SafeType +import space.kscience.kmath.structures.Buffer +import space.kscience.kmath.structures.MutableBuffer /** * A non-boxing buffer over [Memory] object. @@ -15,6 +17,9 @@ import space.kscience.kmath.memory.* * @property spec the spec of [T] type. */ public open class MemoryBuffer(protected val memory: Memory, protected val spec: MemorySpec) : Buffer { + + override val type: SafeType get() = spec.type + override val size: Int get() = memory.size / spec.objectSize override operator fun get(index: Int): T = memory.read { read(spec, spec.objectSize * index) } @@ -43,8 +48,10 @@ public open class MemoryBuffer(protected val memory: Memory, protected * @property memory the underlying memory segment. * @property spec the spec of [T] type. */ -public class MutableMemoryBuffer(memory: Memory, spec: MemorySpec) : MemoryBuffer(memory, spec), - MutableBuffer { +public class MutableMemoryBuffer( + memory: Memory, + spec: MemorySpec, +) : MemoryBuffer(memory, spec), MutableBuffer { private val writer: MemoryWriter = memory.writer() diff --git a/kmath-memory/src/commonMain/kotlin/space/kscience/kmath/memory/MemorySpec.kt b/kmath-memory/src/commonMain/kotlin/space/kscience/kmath/memory/MemorySpec.kt index 19bc3bae4..a1d2b1f28 100644 --- a/kmath-memory/src/commonMain/kotlin/space/kscience/kmath/memory/MemorySpec.kt +++ b/kmath-memory/src/commonMain/kotlin/space/kscience/kmath/memory/MemorySpec.kt @@ -5,12 +5,15 @@ package space.kscience.kmath.memory +import space.kscience.attributes.WithType + /** * A specification to read or write custom objects with fixed size in bytes. * * @param T the type of object this spec manages. */ -public interface MemorySpec { +public interface MemorySpec: WithType { + /** * Size of [T] in bytes after serialization. */ From 2f2f5526488b0606832fdb50e143ea8202583329 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sat, 11 Nov 2023 10:19:09 +0300 Subject: [PATCH 16/40] 0.4 WIP --- .../space/kscience/attributes/Attribute.kt | 2 - .../space/kscience/attributes/Attributes.kt | 6 +- .../kscience/attributes/AttributesBuilder.kt | 2 +- .../kscience/kmath/linear/LinearSpace.kt | 35 ++++++++++-- .../kscience/kmath/linear/LupDecomposition.kt | 4 +- .../kscience/kmath/ejml/EjmlLinearSpace.kt | 2 +- .../space/kscience/kmath/ejml/_generated.kt | 56 +++++++++---------- .../kscience/kmath/ejml/EjmlMatrixTest.kt | 4 +- .../space/kscience/kmath/samplers/Sampler.kt | 17 ++---- .../kscience/kmath/samplers/SamplerAlgebra.kt | 3 + .../kscience/kmath/stat/ValueAndErrorField.kt | 48 ++++++++++++++++ 11 files changed, 121 insertions(+), 58 deletions(-) diff --git a/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/Attribute.kt b/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/Attribute.kt index 6fa142180..a507cd698 100644 --- a/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/Attribute.kt +++ b/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/Attribute.kt @@ -5,8 +5,6 @@ package space.kscience.attributes -import kotlin.reflect.KType - public interface Attribute /** diff --git a/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/Attributes.kt b/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/Attributes.kt index a1bccc211..b50436dd2 100644 --- a/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/Attributes.kt +++ b/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/Attributes.kt @@ -8,7 +8,7 @@ package space.kscience.attributes import kotlin.jvm.JvmInline @JvmInline -public value class Attributes internal constructor(public val content: Map, Any>) { +public value class Attributes internal constructor(public val content: Map, Any?>) { public val keys: Set> get() = content.keys @@ -51,7 +51,7 @@ public inline fun Attributes.has(): Boolean = /** * Create [Attributes] with an added or replaced attribute key. */ -public fun > Attributes.withAttribute( +public fun > Attributes.withAttribute( attribute: A, attrValue: T, ): Attributes = Attributes(content + (attribute to attrValue)) @@ -101,7 +101,7 @@ public fun > Attributes.withoutAttributeElement( /** * Create [Attributes] with a single key */ -public fun > Attributes( +public fun > Attributes( attribute: A, attrValue: T, ): Attributes = Attributes(mapOf(attribute to attrValue)) diff --git a/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/AttributesBuilder.kt b/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/AttributesBuilder.kt index 79df91c3e..6d74b90c1 100644 --- a/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/AttributesBuilder.kt +++ b/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/AttributesBuilder.kt @@ -10,7 +10,7 @@ package space.kscience.attributes * * @param O type marker of an owner object, for which these attributes are made */ -public class TypedAttributesBuilder internal constructor(private val map: MutableMap, Any>) { +public class TypedAttributesBuilder internal constructor(private val map: MutableMap, Any?>) { public constructor() : this(mutableMapOf()) 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 00ebad5ee..6b547e2c5 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,8 +5,10 @@ package space.kscience.kmath.linear +import space.kscience.attributes.Attributes import space.kscience.attributes.SafeType import space.kscience.attributes.WithType +import space.kscience.attributes.withAttribute import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.nd.* import space.kscience.kmath.operations.BufferRingOps @@ -173,15 +175,36 @@ public interface LinearSpace> : MatrixOperations { public operator fun T.times(v: Point): Point = v * this /** - * Get an attribute value for the structure in this scope. Structure attributes are preferred to computed attributes. + * Compute an [attribute] value for given [structure]. Return null if the attribute could not be computed. + */ + public fun > computeAttribute(structure: StructureND<*>, attribute: A): V? = null + + @UnstableKMathAPI + public fun > StructureND<*>.getOrComputeAttribute(attribute: A): V? { + return attributes[attribute] ?: computeAttribute(this, attribute) + } + + /** + * If the structure holds given [attribute] return itself. Otherwise, return a new [Matrix] that contains a computed attribute. * - * @param structure the structure. - * @param attribute to be computed. - * @return a feature object or `null` if it isn't present. + * This method is used to compute and cache attribute inside the structure. If one needs an attribute only once, + * better use [StructureND.getOrComputeAttribute]. */ @UnstableKMathAPI - public fun > attributeFor(structure: StructureND<*>, attribute: A): T = - structure.attributes[attribute] ?: error("Can't compute attribute $attribute for $structure") + public fun > Matrix.compute( + attribute: A, + ): Matrix? { + return if (attributes[attribute] != null) { + this + } else { + val value = computeAttribute(this, attribute) ?: return null + if (this is MatrixWrapper) { + MatrixWrapper(this, attributes.withAttribute(attribute, value)) + } else { + MatrixWrapper(this, Attributes(attribute, value)) + } + } + } public companion object { 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 6592a3da4..fab4ef3db 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 @@ -209,8 +209,8 @@ public fun , F : Field> LinearSpace.lupSolver( singularityCheck: (T) -> Boolean, ): LinearSolver = object : LinearSolver { override fun solve(a: Matrix, b: Matrix): Matrix { - // Use existing decomposition if it is provided by matrix - val decomposition = attributeFor(a, LUP) ?: lup(a, singularityCheck) + // Use existing decomposition if it is provided by matrix or linear space itself + val decomposition = a.getOrComputeAttribute(LUP) ?: lup(a, singularityCheck) return solve(decomposition, b) } 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 a8f316650..37b14f8d1 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 @@ -39,5 +39,5 @@ public abstract class EjmlLinearSpace, out M : org.ejml @UnstableKMathAPI public fun EjmlMatrix.inverted(): Matrix = - attributeFor(this, Float64Field.linearSpace.Inverted) + attributeForOrNull(this, Float64Field.linearSpace.Inverted) } diff --git a/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/_generated.kt b/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/_generated.kt index bf797fed4..881649d01 100644 --- a/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/_generated.kt +++ b/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/_generated.kt @@ -131,10 +131,10 @@ public object EjmlLinearSpaceDDRM : EjmlLinearSpace.plus(other: Matrix): EjmlDoubleMatrix { val out = DMatrixRMaj(1, 1) - + CommonOps_DDRM.add( elementAlgebra.one, toEjml().origin, elementAlgebra.one, - other.toEjml().origin, + other.toEjml().origin, out, ) @@ -369,10 +369,10 @@ public object EjmlLinearSpaceFDRM : EjmlLinearSpace.plus(other: Matrix): EjmlFloatMatrix { val out = FMatrixRMaj(1, 1) - + CommonOps_FDRM.add( elementAlgebra.one, toEjml().origin, elementAlgebra.one, - other.toEjml().origin, + other.toEjml().origin, out, ) @@ -607,12 +607,12 @@ public object EjmlLinearSpaceDSCC : EjmlLinearSpace.plus(other: Matrix): EjmlDoubleMatrix { val out = DMatrixSparseCSC(1, 1) - + CommonOps_DSCC.add( elementAlgebra.one, toEjml().origin, elementAlgebra.one, - other.toEjml().origin, + other.toEjml().origin, out, - null, + null, null, ) @@ -656,7 +656,7 @@ public object EjmlLinearSpaceDSCC : EjmlLinearSpace.plus(other: Matrix): EjmlFloatMatrix { val out = FMatrixSparseCSC(1, 1) - + CommonOps_FSCC.add( elementAlgebra.one, toEjml().origin, elementAlgebra.one, - other.toEjml().origin, + other.toEjml().origin, out, - null, + null, null, ) @@ -889,7 +889,7 @@ public object EjmlLinearSpaceFSCC : EjmlLinearSpace = EjmlLinearSpaceDDRM.attributeFor(w) ?: fail() + val det: Determinant = EjmlLinearSpaceDDRM.attributeForOrNull(w) ?: fail() assertEquals(CommonOps_DDRM.det(m), det.determinant) - val lup: LupDecompositionAttribute = EjmlLinearSpaceDDRM.attributeFor(w) ?: fail() + val lup: LupDecompositionAttribute = EjmlLinearSpaceDDRM.attributeForOrNull(w) ?: fail() val ludecompositionF64 = DecompositionFactory_DDRM.lu(m.numRows, m.numCols) .also { it.decompose(m.copy()) } diff --git a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/Sampler.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/Sampler.kt index 34355dca7..c064641a9 100644 --- a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/Sampler.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/Sampler.kt @@ -12,8 +12,6 @@ import space.kscience.kmath.chains.combine import space.kscience.kmath.random.RandomGenerator import space.kscience.kmath.structures.Buffer import space.kscience.kmath.structures.BufferFactory -import space.kscience.kmath.structures.Float64Buffer -import space.kscience.kmath.structures.Int32Buffer import kotlin.jvm.JvmName /** @@ -36,7 +34,7 @@ public fun interface Sampler { public fun Sampler.sampleBuffer( generator: RandomGenerator, size: Int, - bufferFactory: BufferFactory = BufferFactory.boxing(), + bufferFactory: BufferFactory ): Chain> { require(size > 1) //creating temporary storage once @@ -58,18 +56,11 @@ public fun Sampler.sampleBuffer( public suspend fun Sampler.next(generator: RandomGenerator): T = sample(generator).first() /** - * Generates [size] real samples and chunks them into some buffers. + * Generates [size] samples and chunks them into some buffers. */ @JvmName("sampleRealBuffer") -public fun Sampler.sampleBuffer(generator: RandomGenerator, size: Int): Chain> = - sampleBuffer(generator, size, ::Float64Buffer) - -/** - * Generates [size] integer samples and chunks them into some buffers. - */ -@JvmName("sampleIntBuffer") -public fun Sampler.sampleBuffer(generator: RandomGenerator, size: Int): Chain> = - sampleBuffer(generator, size, ::Int32Buffer) +public inline fun Sampler.sampleBuffer(generator: RandomGenerator, size: Int): Chain> = + sampleBuffer(generator, size, BufferFactory()) /** diff --git a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/SamplerAlgebra.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/SamplerAlgebra.kt index 44b87a431..e23b5928e 100644 --- a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/SamplerAlgebra.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/SamplerAlgebra.kt @@ -14,6 +14,7 @@ import space.kscience.kmath.operations.ScaleOperations import space.kscience.kmath.operations.invoke import space.kscience.kmath.random.RandomGenerator import space.kscience.kmath.stat.Sampler +import space.kscience.kmath.structures.MutableBufferFactory /** * Implements [Sampler] by sampling only certain [value]. @@ -41,6 +42,8 @@ public class BasicSampler(public val chainBuilder: (RandomGenerator public class SamplerSpace(public val algebra: S) : Group>, ScaleOperations> where S : Group, S : ScaleOperations { + override val bufferFactory: MutableBufferFactory> = MutableBufferFactory() + override val zero: Sampler = ConstantSampler(algebra.zero) override fun add(left: Sampler, right: Sampler): Sampler = BasicSampler { generator -> diff --git a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/ValueAndErrorField.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/ValueAndErrorField.kt index 38cd5f900..53df87947 100644 --- a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/ValueAndErrorField.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/ValueAndErrorField.kt @@ -5,10 +5,14 @@ package space.kscience.kmath.stat +import space.kscience.attributes.SafeType +import space.kscience.attributes.safeTypeOf import space.kscience.kmath.operations.Field +import space.kscience.kmath.structures.* import kotlin.math.pow import kotlin.math.sqrt + /** * A combination of a random [value] and its [dispersion]. * @@ -53,4 +57,48 @@ public object ValueAndErrorField : Field { override fun scale(a: ValueAndError, value: Double): ValueAndError = ValueAndError(a.value * value, a.dispersion * value.pow(2)) + + + private class ValueAndErrorBuffer(val values: DoubleBuffer, val ds: DoubleBuffer) : MutableBuffer { + init { + require(values.size == ds.size) + } + + override val type: SafeType get() = safeTypeOf() + override val size: Int + get() = values.size + + override fun get(index: Int): ValueAndError = ValueAndError(values[index], ds[index]) + + override fun toString(): String = Buffer.toString(this) + + override fun set(index: Int, value: ValueAndError) { + values[index] = value.value + values[index] = value.dispersion + } + + override fun copy(): MutableBuffer = ValueAndErrorBuffer(values.copy(), ds.copy()) + } + + override val bufferFactory: MutableBufferFactory = object : MutableBufferFactory { + override fun invoke( + size: Int, + builder: (Int) -> ValueAndError, + ): MutableBuffer { + val values: DoubleArray = DoubleArray(size) + val ds = DoubleArray(size) + repeat(size){ + val (v, d) = builder(it) + values[it] = v + ds[it] = d + } + return ValueAndErrorBuffer( + values.asBuffer(), + ds.asBuffer() + ) + } + + override val type: SafeType get() = safeTypeOf() + + } } \ No newline at end of file From 5c82a5e1fa2dced56af94a12cd5ca8f4e0a0ff51 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sat, 18 Nov 2023 22:29:59 +0300 Subject: [PATCH 17/40] 0.4 WIP --- CHANGELOG.md | 3 +- .../space/kscience/attributes/Attribute.kt | 11 --- .../kscience/attributes/AttributeContainer.kt | 10 +- .../space/kscience/attributes/Attributes.kt | 42 ++++---- .../kscience/attributes/AttributesBuilder.kt | 33 ++++--- .../attributes/PolymorphicAttribute.kt | 31 ++++++ .../kmath/ejml/codegen/ejmlCodegen.kt | 12 ++- .../space/kscience/kmath/fit/chiSquared.kt | 4 +- .../kotlin/space/kscience/kmath/fit/qowFit.kt | 4 +- .../space/kscience/kmath/ast/TypedMst.kt | 36 +++++-- .../kscience/kmath/ast/evaluateConstants.kt | 9 +- .../space/kscience/kmath/estree/estree.kt | 4 +- .../kmath/estree/internal/ESTreeBuilder.kt | 15 ++- .../kotlin/space/kscience/kmath/asm/asm.kt | 2 +- .../commons/expressions/CmDsExpression.kt | 19 +++- .../integration/CMGaussRuleIntegrator.kt | 4 +- .../kmath/commons/integration/CMIntegrator.kt | 17 ++-- .../kscience/kmath/commons/linear/CMMatrix.kt | 38 ++++---- .../kmath/commons/optimization/CMOptimizer.kt | 35 +++---- .../commons/optimization/OptimizeTest.kt | 4 +- .../kscience/kmath/expressions/DSAlgebra.kt | 11 ++- .../kscience/kmath/expressions/Expression.kt | 29 +++++- .../expressions/ExpressionWithDefault.kt | 8 ++ .../FunctionalExpressionAlgebra.kt | 19 ++-- .../space/kscience/kmath/expressions/MST.kt | 2 +- .../kmath/expressions/SimpleAutoDiff.kt | 5 +- .../kscience/kmath/linear/LinearSolver.kt | 2 +- .../kscience/kmath/linear/LinearSpace.kt | 21 ++-- .../kscience/kmath/linear/LupDecomposition.kt | 41 ++++---- .../kscience/kmath/linear/MatrixWrapper.kt | 10 +- .../kscience/kmath/linear/matrixAttributes.kt | 44 +++++---- .../kscience/kmath/ejml/EjmlLinearSpace.kt | 2 +- .../space/kscience/kmath/ejml/_generated.kt | 39 +++++++- .../kmath/integration/GaussIntegrator.kt | 4 +- .../kscience/kmath/integration/Integrand.kt | 2 +- .../integration/MultivariateIntegrand.kt | 4 +- .../kmath/integration/UnivariateIntegrand.kt | 10 +- kmath-jafama/build.gradle.kts | 2 +- .../kscience/kmath/jafama/KMathJafama.kt | 12 ++- .../kmath/multik/MultikDoubleAlgebra.kt | 2 +- .../kmath/multik/MultikFloatAlgebra.kt | 2 +- .../kscience/kmath/multik/MultikIntAlgebra.kt | 2 +- .../kmath/multik/MultikLongAlgebra.kt | 2 +- .../kmath/multik/MultikShortAlgebra.kt | 2 +- .../kscience/kmath/multik/MultikTensor.kt | 20 ++++ .../kmath/multik/MultikTensorAlgebra.kt | 14 +-- .../optimization/FunctionOptimization.kt | 53 ++++++---- .../kmath/optimization/OptimizationBuilder.kt | 96 ------------------- .../kmath/optimization/OptimizationProblem.kt | 61 +++++------- .../kmath/optimization/QowOptimizer.kt | 27 +++--- .../kscience/kmath/optimization/XYFit.kt | 64 ++++++++----- .../kmath/optimization/logLikelihood.kt | 19 +++- .../kmath/tensors/core/DoubleTensor.kt | 4 + .../kscience/kmath/tensors/core/IntTensor.kt | 6 ++ 54 files changed, 541 insertions(+), 433 deletions(-) create mode 100644 attributes-kt/src/commonMain/kotlin/space/kscience/attributes/PolymorphicAttribute.kt delete mode 100644 kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/OptimizationBuilder.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index ef5e0490c..58df6f1bb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ ## Unreleased ### Added -- Explicit `SafeType` for algebras and buffers. +- Reification. Explicit `SafeType` for algebras and buffers. - Integer division algebras. - Float32 geometries. - New Attributes-kt module that could be used as stand-alone. It declares. type-safe attributes containers. @@ -16,6 +16,7 @@ - kmath-geometry is split into `euclidean2d` and `euclidean3d` - Features replaced with Attributes. - Transposed refactored. +- Kmath-memory is moved on top of core. ### Deprecated diff --git a/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/Attribute.kt b/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/Attribute.kt index a507cd698..dda7c6ed5 100644 --- a/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/Attribute.kt +++ b/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/Attribute.kt @@ -24,14 +24,3 @@ public interface AttributeWithDefault : Attribute { */ public interface SetAttribute : Attribute> -/** - * An attribute that has a type parameter for value - * @param type parameter-type - */ -public abstract class PolymorphicAttribute(public val type: SafeType) : Attribute { - override fun equals(other: Any?): Boolean = other != null && - (this::class == other::class) && - (other as? PolymorphicAttribute<*>)?.type == this.type - - override fun hashCode(): Int = this::class.hashCode() + type.hashCode() -} diff --git a/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/AttributeContainer.kt b/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/AttributeContainer.kt index 69b050649..19e5c224a 100644 --- a/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/AttributeContainer.kt +++ b/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/AttributeContainer.kt @@ -6,8 +6,14 @@ package space.kscience.attributes /** - * A container for attributes. [attributes] could be made mutable by implementation + * A container for [Attributes] */ public interface AttributeContainer { public val attributes: Attributes -} \ No newline at end of file +} + +/** + * A scope, where attribute keys could be resolved + */ +public interface AttributeScope + diff --git a/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/Attributes.kt b/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/Attributes.kt index b50436dd2..6c8dabc50 100644 --- a/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/Attributes.kt +++ b/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/Attributes.kt @@ -7,21 +7,27 @@ package space.kscience.attributes import kotlin.jvm.JvmInline -@JvmInline -public value class Attributes internal constructor(public val content: Map, Any?>) { +/** + * A set of attributes. The implementation must guarantee that [content] keys correspond to its value types. + */ +public interface Attributes { + public val content: Map, Any?> public val keys: Set> get() = content.keys @Suppress("UNCHECKED_CAST") public operator fun get(attribute: Attribute): T? = content[attribute] as? T - override fun toString(): String = "Attributes(value=${content.entries})" - public companion object { - public val EMPTY: Attributes = Attributes(emptyMap()) + public val EMPTY: Attributes = AttributesImpl(emptyMap()) } } +@JvmInline +internal value class AttributesImpl(override val content: Map, Any?>) : Attributes { + override fun toString(): String = "Attributes(value=${content.entries})" +} + public fun Attributes.isEmpty(): Boolean = content.isEmpty() /** @@ -33,19 +39,19 @@ public fun Attributes.getOrDefault(attribute: AttributeWithDefault): T = * Check if there is an attribute that matches given key by type and adheres to [predicate]. */ @Suppress("UNCHECKED_CAST") -public inline fun > Attributes.any(predicate: (value: T) -> Boolean): Boolean = +public inline fun > Attributes.hasAny(predicate: (value: T) -> Boolean): Boolean = content.any { (mapKey, mapValue) -> mapKey is A && predicate(mapValue as T) } /** * Check if there is an attribute of given type (subtypes included) */ -public inline fun > Attributes.any(): Boolean = +public inline fun > Attributes.hasAny(): Boolean = content.any { (mapKey, _) -> mapKey is A } /** * Check if [Attributes] contains a flag. Multiple keys that are instances of a flag could be present */ -public inline fun Attributes.has(): Boolean = +public inline fun Attributes.hasFlag(): Boolean = content.keys.any { it is A } /** @@ -54,7 +60,7 @@ public inline fun Attributes.has(): Boolean = public fun > Attributes.withAttribute( attribute: A, attrValue: T, -): Attributes = Attributes(content + (attribute to attrValue)) +): Attributes = AttributesImpl(content + (attribute to attrValue)) public fun > Attributes.withAttribute(attribute: A): Attributes = withAttribute(attribute, Unit) @@ -62,7 +68,7 @@ public fun > Attributes.withAttribute(attribute: A): Attribu /** * Create a new [Attributes] by modifying the current one */ -public fun Attributes.modify(block: AttributesBuilder.() -> Unit): Attributes = Attributes { +public fun Attributes.modify(block: AttributesBuilder.() -> Unit): Attributes = Attributes { from(this@modify) block() } @@ -70,7 +76,7 @@ public fun Attributes.modify(block: AttributesBuilder.() -> Unit): Attributes = /** * Create new [Attributes] by removing [attribute] key */ -public fun Attributes.withoutAttribute(attribute: Attribute<*>): Attributes = Attributes(content.minus(attribute)) +public fun Attributes.withoutAttribute(attribute: Attribute<*>): Attributes = AttributesImpl(content.minus(attribute)) /** * Add an element to a [SetAttribute] @@ -80,7 +86,7 @@ public fun > Attributes.withAttributeElement( attrValue: T, ): Attributes { val currentSet: Set = get(attribute) ?: emptySet() - return Attributes( + return AttributesImpl( content + (attribute to (currentSet + attrValue)) ) } @@ -93,9 +99,7 @@ public fun > Attributes.withoutAttributeElement( attrValue: T, ): Attributes { val currentSet: Set = get(attribute) ?: emptySet() - return Attributes( - content + (attribute to (currentSet - attrValue)) - ) + return AttributesImpl(content + (attribute to (currentSet - attrValue))) } /** @@ -104,13 +108,13 @@ public fun > Attributes.withoutAttributeElement( public fun > Attributes( attribute: A, attrValue: T, -): Attributes = Attributes(mapOf(attribute to attrValue)) +): Attributes = AttributesImpl(mapOf(attribute to attrValue)) /** * Create Attributes with a single [Unit] valued attribute */ public fun > Attributes( - attribute: A -): Attributes = Attributes(mapOf(attribute to Unit)) + attribute: A, +): Attributes = AttributesImpl(mapOf(attribute to Unit)) -public operator fun Attributes.plus(other: Attributes): Attributes = Attributes(content + other.content) \ No newline at end of file +public operator fun Attributes.plus(other: Attributes): Attributes = AttributesImpl(content + other.content) \ No newline at end of file diff --git a/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/AttributesBuilder.kt b/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/AttributesBuilder.kt index 6d74b90c1..0acf4e004 100644 --- a/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/AttributesBuilder.kt +++ b/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/AttributesBuilder.kt @@ -10,19 +10,24 @@ package space.kscience.attributes * * @param O type marker of an owner object, for which these attributes are made */ -public class TypedAttributesBuilder internal constructor(private val map: MutableMap, Any?>) { +public class AttributesBuilder internal constructor( + private val map: MutableMap, Any?>, +) : Attributes { public constructor() : this(mutableMapOf()) - @Suppress("UNCHECKED_CAST") - public operator fun get(attribute: Attribute): T? = map[attribute] as? T + override val content: Map, Any?> get() = map + + public operator fun set(attribute: Attribute, value: T?) { + if (value == null) { + map.remove(attribute) + } else { + map[attribute] = value + } + } public operator fun Attribute.invoke(value: V?) { - if (value == null) { - map.remove(this) - } else { - map[this] = value - } + set(this, value) } public fun from(attributes: Attributes) { @@ -46,14 +51,8 @@ public class TypedAttributesBuilder internal constructor(private val map: map[this] = currentSet - attrValue } - public fun build(): Attributes = Attributes(map) + public fun build(): Attributes = AttributesImpl(map) } -public typealias AttributesBuilder = TypedAttributesBuilder - -public fun AttributesBuilder( - attributes: Attributes, -): AttributesBuilder = AttributesBuilder(attributes.content.toMutableMap()) - -public inline fun Attributes(builder: AttributesBuilder.() -> Unit): Attributes = - AttributesBuilder().apply(builder).build() \ No newline at end of file +public inline fun Attributes(builder: AttributesBuilder.() -> Unit): Attributes = + AttributesBuilder().apply(builder).build() \ No newline at end of file diff --git a/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/PolymorphicAttribute.kt b/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/PolymorphicAttribute.kt new file mode 100644 index 000000000..b61d4c477 --- /dev/null +++ b/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/PolymorphicAttribute.kt @@ -0,0 +1,31 @@ +/* + * Copyright 2018-2023 KMath contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package space.kscience.attributes + +/** + * An attribute that has a type parameter for value + * @param type parameter-type + */ +public abstract class PolymorphicAttribute(public val type: SafeType) : Attribute { + override fun equals(other: Any?): Boolean = other != null && + (this::class == other::class) && + (other as? PolymorphicAttribute<*>)?.type == this.type + + override fun hashCode(): Int = this::class.hashCode() + type.hashCode() +} + + +/** + * Get a polymorphic attribute using attribute factory + */ +public operator fun Attributes.get(attributeKeyBuilder: () -> PolymorphicAttribute): T? = get(attributeKeyBuilder()) + +/** + * Set a polymorphic attribute using its factory + */ +public operator fun AttributesBuilder.set(attributeKeyBuilder: () -> PolymorphicAttribute, value: T) { + set(attributeKeyBuilder(), value) +} diff --git a/buildSrc/src/main/kotlin/space/kscience/kmath/ejml/codegen/ejmlCodegen.kt b/buildSrc/src/main/kotlin/space/kscience/kmath/ejml/codegen/ejmlCodegen.kt index b8c895196..bb46a085b 100644 --- a/buildSrc/src/main/kotlin/space/kscience/kmath/ejml/codegen/ejmlCodegen.kt +++ b/buildSrc/src/main/kotlin/space/kscience/kmath/ejml/codegen/ejmlCodegen.kt @@ -19,6 +19,8 @@ public class Ejml${type}Vector(override val origin: M) require(origin.numRows == 1) { "The origin matrix must have only one row to form a vector" } } + override val type: SafeType<${type}> get() = safeTypeOf() + override operator fun get(index: Int): $type = origin[0, index] }""" appendLine(text) @@ -30,6 +32,8 @@ private fun Appendable.appendEjmlMatrix(type: String, ejmlMatrixType: String) { * [EjmlMatrix] specialization for [$type]. */ public class Ejml${type}Matrix(override val origin: M) : EjmlMatrix<$type, M>(origin) { + override val type: SafeType<${type}> get() = safeTypeOf() + override operator fun get(i: Int, j: Int): $type = origin[i, j] }""" appendLine(text) @@ -46,7 +50,9 @@ private fun Appendable.appendEjmlLinearSpace( denseOps: String, isDense: Boolean, ) { - @Language("kotlin") val text = """/** + @Language("kotlin") val text = """ + +/** * [EjmlLinearSpace] implementation based on [CommonOps_$ops], [DecompositionFactory_${ops}] operations and * [${ejmlMatrixType}] matrices. */ @@ -56,7 +62,7 @@ public object EjmlLinearSpace${ops} : EjmlLinearSpace<${type}, ${kmathAlgebra}, */ override val elementAlgebra: $kmathAlgebra get() = $kmathAlgebra - override val elementType: KType get() = typeOf<$type>() + override val type: SafeType<${type}> get() = safeTypeOf() @Suppress("UNCHECKED_CAST") override fun Matrix<${type}>.toEjml(): Ejml${type}Matrix<${ejmlMatrixType}> = when { @@ -385,6 +391,8 @@ import org.ejml.sparse.csc.factory.DecompositionFactory_DSCC import org.ejml.sparse.csc.factory.DecompositionFactory_FSCC import org.ejml.sparse.csc.factory.LinearSolverFactory_DSCC import org.ejml.sparse.csc.factory.LinearSolverFactory_FSCC +import space.kscience.attributes.SafeType +import space.kscience.attributes.safeTypeOf import space.kscience.kmath.linear.* import space.kscience.kmath.linear.Matrix import space.kscience.kmath.UnstableKMathAPI diff --git a/examples/src/main/kotlin/space/kscience/kmath/fit/chiSquared.kt b/examples/src/main/kotlin/space/kscience/kmath/fit/chiSquared.kt index 258ed0c84..f2c0c7cf4 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/fit/chiSquared.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/fit/chiSquared.kt @@ -15,7 +15,7 @@ import space.kscience.kmath.operations.asIterable import space.kscience.kmath.operations.toList import space.kscience.kmath.optimization.FunctionOptimizationTarget import space.kscience.kmath.optimization.optimizeWith -import space.kscience.kmath.optimization.resultPoint +import space.kscience.kmath.optimization.result import space.kscience.kmath.optimization.resultValue import space.kscience.kmath.random.RandomGenerator import space.kscience.kmath.real.DoubleVector @@ -98,7 +98,7 @@ suspend fun main() { scatter { mode = ScatterMode.lines x(x) - y(x.map { result.resultPoint[a]!! * it.pow(2) + result.resultPoint[b]!! * it + 1 }) + y(x.map { result.result[a]!! * it.pow(2) + result.result[b]!! * it + 1 }) name = "fit" } } diff --git a/examples/src/main/kotlin/space/kscience/kmath/fit/qowFit.kt b/examples/src/main/kotlin/space/kscience/kmath/fit/qowFit.kt index fe7f48b72..a092b8870 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/fit/qowFit.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/fit/qowFit.kt @@ -94,13 +94,13 @@ suspend fun main() { scatter { mode = ScatterMode.lines x(x) - y(x.map { result.model(result.startPoint + result.resultPoint + (Symbol.x to it)) }) + y(x.map { result.model(result.startPoint + result.result + (Symbol.x to it)) }) name = "fit" } } br() h3 { - +"Fit result: ${result.resultPoint}" + +"Fit result: ${result.result}" } h3 { +"Chi2/dof = ${result.chiSquaredOrNull!! / result.dof}" diff --git a/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/TypedMst.kt b/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/TypedMst.kt index e82f7a3ab..d824a652e 100644 --- a/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/TypedMst.kt +++ b/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/TypedMst.kt @@ -5,6 +5,8 @@ package space.kscience.kmath.ast +import space.kscience.attributes.SafeType +import space.kscience.attributes.WithType import space.kscience.kmath.expressions.Expression import space.kscience.kmath.expressions.Symbol import space.kscience.kmath.operations.Algebra @@ -15,7 +17,7 @@ import space.kscience.kmath.operations.NumericAlgebra * * @param T the type. */ -public sealed interface TypedMst { +public sealed interface TypedMst : WithType { /** * A node containing a unary operation. * @@ -24,8 +26,13 @@ public sealed interface TypedMst { * @property function The function implementing this operation. * @property value The argument of this operation. */ - public class Unary(public val operation: String, public val function: (T) -> T, public val value: TypedMst) : - TypedMst { + public class Unary( + public val operation: String, + public val function: (T) -> T, + public val value: TypedMst, + ) : TypedMst { + override val type: SafeType get() = value.type + override fun equals(other: Any?): Boolean { if (this === other) return true if (other == null || this::class != other::class) return false @@ -59,6 +66,13 @@ public sealed interface TypedMst { public val left: TypedMst, public val right: TypedMst, ) : TypedMst { + + init { + require(left.type==right.type){"Left and right expressions must be of the same type"} + } + + override val type: SafeType get() = left.type + override fun equals(other: Any?): Boolean { if (this === other) return true if (other == null || this::class != other::class) return false @@ -89,7 +103,12 @@ public sealed interface TypedMst { * @property value The held value. * @property number The number this value corresponds. */ - public class Constant(public val value: T, public val number: Number?) : TypedMst { + public class Constant( + override val type: SafeType, + public val value: T, + public val number: Number?, + ) : TypedMst { + override fun equals(other: Any?): Boolean { if (this === other) return true if (other == null || this::class != other::class) return false @@ -114,7 +133,7 @@ public sealed interface TypedMst { * @param T the type. * @property symbol The symbol of the variable. */ - public class Variable(public val symbol: Symbol) : TypedMst { + public class Variable(override val type: SafeType, public val symbol: Symbol) : TypedMst { override fun equals(other: Any?): Boolean { if (this === other) return true if (other == null || this::class != other::class) return false @@ -167,6 +186,7 @@ public fun TypedMst.interpret(algebra: Algebra, vararg arguments: Pair /** * Interpret this [TypedMst] node as expression. */ -public fun TypedMst.toExpression(algebra: Algebra): Expression = Expression { arguments -> - interpret(algebra, arguments) -} +public fun TypedMst.toExpression(algebra: Algebra): Expression = + Expression(algebra.type) { arguments -> + interpret(algebra, arguments) + } diff --git a/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/evaluateConstants.kt b/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/evaluateConstants.kt index 8fc5a6aaf..4298a9788 100644 --- a/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/evaluateConstants.kt +++ b/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/evaluateConstants.kt @@ -16,6 +16,7 @@ import space.kscience.kmath.operations.bindSymbolOrNull */ public fun MST.evaluateConstants(algebra: Algebra): TypedMst = when (this) { is MST.Numeric -> TypedMst.Constant( + algebra.type, (algebra as? NumericAlgebra)?.number(value) ?: error("Numeric nodes are not supported by $algebra"), value, ) @@ -27,7 +28,7 @@ public fun MST.evaluateConstants(algebra: Algebra): TypedMst = when (t arg.value, ) - TypedMst.Constant(value, if (value is Number) value else null) + TypedMst.Constant(algebra.type, value, if (value is Number) value else null) } else -> TypedMst.Unary(operation, algebra.unaryOperationFunction(operation), arg) @@ -59,7 +60,7 @@ public fun MST.evaluateConstants(algebra: Algebra): TypedMst = when (t ) } - TypedMst.Constant(value, if (value is Number) value else null) + TypedMst.Constant(algebra.type, value, if (value is Number) value else null) } algebra is NumericAlgebra && left is TypedMst.Constant && left.number != null -> TypedMst.Binary( @@ -84,8 +85,8 @@ public fun MST.evaluateConstants(algebra: Algebra): TypedMst = when (t val boundSymbol = algebra.bindSymbolOrNull(this) if (boundSymbol != null) - TypedMst.Constant(boundSymbol, if (boundSymbol is Number) boundSymbol else null) + TypedMst.Constant(algebra.type, boundSymbol, if (boundSymbol is Number) boundSymbol else null) else - TypedMst.Variable(this) + TypedMst.Variable(algebra.type, this) } } diff --git a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/estree.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/estree.kt index 87c2df2d2..33626eaa1 100644 --- a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/estree.kt +++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/estree.kt @@ -22,7 +22,7 @@ import space.kscience.kmath.operations.Algebra @OptIn(UnstableKMathAPI::class) public fun MST.compileToExpression(algebra: Algebra): Expression { val typed = evaluateConstants(algebra) - if (typed is TypedMst.Constant) return Expression { typed.value } + if (typed is TypedMst.Constant) return Expression(algebra.type) { typed.value } fun ESTreeBuilder.visit(node: TypedMst): BaseExpression = when (node) { is TypedMst.Constant -> constant(node.value) @@ -36,7 +36,7 @@ public fun MST.compileToExpression(algebra: Algebra): Expression ) } - return ESTreeBuilder { visit(typed) }.instance + return ESTreeBuilder(algebra.type) { visit(typed) }.instance } /** diff --git a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/internal/ESTreeBuilder.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/internal/ESTreeBuilder.kt index 1517cdef2..ed2b62336 100644 --- a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/internal/ESTreeBuilder.kt +++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/internal/ESTreeBuilder.kt @@ -5,13 +5,22 @@ package space.kscience.kmath.estree.internal +import space.kscience.attributes.SafeType +import space.kscience.attributes.WithType import space.kscience.kmath.expressions.Expression import space.kscience.kmath.expressions.Symbol import space.kscience.kmath.internal.astring.generate import space.kscience.kmath.internal.estree.* -internal class ESTreeBuilder(val bodyCallback: ESTreeBuilder.() -> BaseExpression) { - private class GeneratedExpression(val executable: dynamic, val constants: Array) : Expression { +internal class ESTreeBuilder( + override val type: SafeType, + val bodyCallback: ESTreeBuilder.() -> BaseExpression, +) : WithType { + private class GeneratedExpression( + override val type: SafeType, + val executable: dynamic, + val constants: Array, + ) : Expression { @Suppress("UNUSED_VARIABLE") override fun invoke(arguments: Map): T { val e = executable @@ -30,7 +39,7 @@ internal class ESTreeBuilder(val bodyCallback: ESTreeBuilder.() -> BaseExp ) val code = generate(node) - GeneratedExpression(js("new Function('constants', 'arguments_0', code)"), constants.toTypedArray()) + GeneratedExpression(type, js("new Function('constants', 'arguments_0', code)"), constants.toTypedArray()) } private val constants = mutableListOf() diff --git a/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/asm.kt b/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/asm.kt index 97fe91ee4..50e6a2001 100644 --- a/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/asm.kt +++ b/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/asm.kt @@ -29,7 +29,7 @@ import space.kscience.kmath.operations.Int64Ring @PublishedApi internal fun MST.compileWith(type: Class, algebra: Algebra): Expression { val typed = evaluateConstants(algebra) - if (typed is TypedMst.Constant) return Expression { typed.value } + if (typed is TypedMst.Constant) return Expression(algebra.type) { typed.value } fun GenericAsmBuilder.variablesVisitor(node: TypedMst): Unit = when (node) { is TypedMst.Unary -> variablesVisitor(node.value) diff --git a/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/expressions/CmDsExpression.kt b/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/expressions/CmDsExpression.kt index 38eaf8868..65ae8dd2d 100644 --- a/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/expressions/CmDsExpression.kt +++ b/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/expressions/CmDsExpression.kt @@ -8,10 +8,13 @@ package space.kscience.kmath.commons.expressions import org.apache.commons.math3.analysis.differentiation.DerivativeStructure +import space.kscience.attributes.SafeType import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.expressions.* +import space.kscience.kmath.operations.DoubleField import space.kscience.kmath.operations.ExtendedField import space.kscience.kmath.operations.NumbersAddOps +import space.kscience.kmath.structures.MutableBufferFactory /** * A field over commons-math [DerivativeStructure]. @@ -26,6 +29,9 @@ public class CmDsField( bindings: Map, ) : ExtendedField, ExpressionAlgebra, NumbersAddOps { + + override val bufferFactory: MutableBufferFactory = MutableBufferFactory() + public val numberOfVariables: Int = bindings.size override val zero: DerivativeStructure by lazy { DerivativeStructure(numberOfVariables, order) } @@ -77,7 +83,9 @@ public class CmDsField( override fun scale(a: DerivativeStructure, value: Double): DerivativeStructure = a.multiply(value) - override fun multiply(left: DerivativeStructure, right: DerivativeStructure): DerivativeStructure = left.multiply(right) + override fun multiply(left: DerivativeStructure, right: DerivativeStructure): DerivativeStructure = + left.multiply(right) + override fun divide(left: DerivativeStructure, right: DerivativeStructure): DerivativeStructure = left.divide(right) override fun sin(arg: DerivativeStructure): DerivativeStructure = arg.sin() override fun cos(arg: DerivativeStructure): DerivativeStructure = arg.cos() @@ -113,8 +121,8 @@ public class CmDsField( */ @Deprecated("Use generic DSAlgebra from the core") public object CmDsProcessor : AutoDiffProcessor { - override fun differentiate( - function: CmDsField.() -> DerivativeStructure, + override fun differentiate( + function: CmDsField.() -> DerivativeStructure, ): CmDsExpression = CmDsExpression(function) } @@ -125,13 +133,16 @@ public object CmDsProcessor : AutoDiffProcessor DerivativeStructure, ) : DifferentiableExpression { + + override val type: SafeType get() = DoubleField.type + override operator fun invoke(arguments: Map): Double = CmDsField(0, arguments).function().value /** * Get the derivative expression with given orders */ - override fun derivativeOrNull(symbols: List): Expression = Expression { arguments -> + override fun derivativeOrNull(symbols: List): Expression = Expression(type) { arguments -> with(CmDsField(symbols.size, arguments)) { function().derivative(symbols) } } } diff --git a/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/integration/CMGaussRuleIntegrator.kt b/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/integration/CMGaussRuleIntegrator.kt index a3fc49d32..f087987bf 100644 --- a/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/integration/CMGaussRuleIntegrator.kt +++ b/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/integration/CMGaussRuleIntegrator.kt @@ -16,7 +16,7 @@ public class CMGaussRuleIntegrator( private var type: GaussRule = GaussRule.LEGENDRE, ) : UnivariateIntegrator { - override fun process(integrand: UnivariateIntegrand): UnivariateIntegrand { + override fun integrate(integrand: UnivariateIntegrand): UnivariateIntegrand { val range = integrand[IntegrationRange] ?: error("Integration range is not provided") val integrator: GaussIntegrator = getIntegrator(range) @@ -79,7 +79,7 @@ public class CMGaussRuleIntegrator( numPoints: Int = 100, type: GaussRule = GaussRule.LEGENDRE, function: (Double) -> Double, - ): Double = CMGaussRuleIntegrator(numPoints, type).process( + ): Double = CMGaussRuleIntegrator(numPoints, type).integrate( UnivariateIntegrand({IntegrationRange(range)},function) ).value } diff --git a/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/integration/CMIntegrator.kt b/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/integration/CMIntegrator.kt index 2cc60fb77..ce3dabd08 100644 --- a/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/integration/CMIntegrator.kt +++ b/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/integration/CMIntegrator.kt @@ -7,6 +7,7 @@ package space.kscience.kmath.commons.integration import org.apache.commons.math3.analysis.integration.IterativeLegendreGaussIntegrator import org.apache.commons.math3.analysis.integration.SimpsonIntegrator +import space.kscience.attributes.Attributes import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.integration.* import org.apache.commons.math3.analysis.integration.UnivariateIntegrator as CMUnivariateIntegrator @@ -19,7 +20,7 @@ public class CMIntegrator( public val integratorBuilder: (Integrand) -> CMUnivariateIntegrator, ) : UnivariateIntegrator { - override fun process(integrand: UnivariateIntegrand): UnivariateIntegrand { + override fun integrate(integrand: UnivariateIntegrand): UnivariateIntegrand { val integrator = integratorBuilder(integrand) val maxCalls = integrand[IntegrandMaxCalls] ?: defaultMaxCalls val remainingCalls = maxCalls - integrand.calls @@ -73,15 +74,9 @@ public class CMIntegrator( } @UnstableKMathAPI -public var MutableList.targetAbsoluteAccuracy: Double? - get() = filterIsInstance().lastOrNull()?.accuracy - set(value) { - value?.let { add(IntegrandAbsoluteAccuracy(value)) } - } +public val Attributes.targetAbsoluteAccuracy: Double? + get() = get(IntegrandAbsoluteAccuracy) @UnstableKMathAPI -public var MutableList.targetRelativeAccuracy: Double? - get() = filterIsInstance().lastOrNull()?.accuracy - set(value) { - value?.let { add(IntegrandRelativeAccuracy(value)) } - } \ No newline at end of file +public val Attributes.targetRelativeAccuracy: Double? + get() = get(IntegrandRelativeAccuracy) diff --git a/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/linear/CMMatrix.kt b/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/linear/CMMatrix.kt index d29650e3f..625e7292a 100644 --- a/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/linear/CMMatrix.kt +++ b/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/linear/CMMatrix.kt @@ -6,18 +6,20 @@ package space.kscience.kmath.commons.linear import org.apache.commons.math3.linear.* +import org.apache.commons.math3.linear.LUDecomposition +import space.kscience.attributes.SafeType import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.linear.* +import space.kscience.kmath.nd.Structure2D import space.kscience.kmath.nd.StructureAttribute +import space.kscience.kmath.operations.DoubleField import space.kscience.kmath.operations.Float64Field import space.kscience.kmath.structures.Buffer import space.kscience.kmath.structures.Float64Buffer -import kotlin.reflect.KClass -import kotlin.reflect.KType import kotlin.reflect.cast -import kotlin.reflect.typeOf public class CMMatrix(public val origin: RealMatrix) : Matrix { + override val type: SafeType get() = DoubleField.type override val rowNum: Int get() = origin.rowDimension override val colNum: Int get() = origin.columnDimension @@ -26,6 +28,7 @@ public class CMMatrix(public val origin: RealMatrix) : Matrix { @JvmInline public value class CMVector(public val origin: RealVector) : Point { + override val type: SafeType get() = DoubleField.type override val size: Int get() = origin.dimension override operator fun get(index: Int): Double = origin.getEntry(index) @@ -40,7 +43,7 @@ public fun RealVector.toPoint(): CMVector = CMVector(this) public object CMLinearSpace : LinearSpace { override val elementAlgebra: Float64Field get() = Float64Field - override val elementType: KType = typeOf() + override val type: SafeType get() = DoubleField.type override fun buildMatrix( rows: Int, @@ -102,19 +105,14 @@ public object CMLinearSpace : LinearSpace { override fun Double.times(v: Point): CMVector = v * this - @UnstableKMathAPI - override fun computeFeature(structure: Matrix, type: KClass): F? { - //Return the feature if it is intrinsic to the structure - structure.getFeature(type)?.let { return it } + override fun > computeAttribute(structure: Structure2D, attribute: A): V? { val origin = structure.toCM().origin - return when (type) { - IsDiagonal::class -> if (origin is DiagonalMatrix) IsDiagonal else null - - Determinant::class, LupDecompositionAttribute::class -> object : - Determinant, - LupDecompositionAttribute { + return when (attribute) { + IsDiagonal -> if (origin is DiagonalMatrix) IsDiagonal else null + Determinant -> LUDecomposition(origin).determinant + LUP -> GenericLupDecomposition { private val lup by lazy { LUDecomposition(origin) } override val determinant: Double by lazy { lup.determinant } override val l: Matrix by lazy> { CMMatrix(lup.l).withAttribute(LowerTriangular) } @@ -122,20 +120,24 @@ public object CMLinearSpace : LinearSpace { override val p: Matrix by lazy { CMMatrix(lup.p) } } - CholeskyDecompositionAttribute::class -> object : CholeskyDecompositionAttribute { + CholeskyDecompositionAttribute -> object : CholeskyDecompositionAttribute { override val l: Matrix by lazy> { val cholesky = CholeskyDecomposition(origin) CMMatrix(cholesky.l).withAttribute(LowerTriangular) } } - QRDecompositionAttribute::class -> object : QRDecompositionAttribute { + QRDecompositionAttribute -> object : QRDecompositionAttribute { private val qr by lazy { QRDecomposition(origin) } - override val q: Matrix by lazy> { CMMatrix(qr.q).withAttribute(OrthogonalAttribute) } + override val q: Matrix by lazy> { + CMMatrix(qr.q).withAttribute( + OrthogonalAttribute + ) + } override val r: Matrix by lazy> { CMMatrix(qr.r).withAttribute(UpperTriangular) } } - SVDAttribute::class -> object : SVDAttribute { + SVDAttribute -> object : SVDAttribute { private val sv by lazy { SingularValueDecomposition(origin) } override val u: Matrix by lazy { CMMatrix(sv.u) } override val s: Matrix by lazy { CMMatrix(sv.s) } diff --git a/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/optimization/CMOptimizer.kt b/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/optimization/CMOptimizer.kt index 6e0000721..e834d404b 100644 --- a/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/optimization/CMOptimizer.kt +++ b/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/optimization/CMOptimizer.kt @@ -13,6 +13,8 @@ import org.apache.commons.math3.optim.nonlinear.scalar.ObjectiveFunctionGradient import org.apache.commons.math3.optim.nonlinear.scalar.gradient.NonLinearConjugateGradientOptimizer import org.apache.commons.math3.optim.nonlinear.scalar.noderiv.NelderMeadSimplex import org.apache.commons.math3.optim.nonlinear.scalar.noderiv.SimplexOptimizer +import space.kscience.attributes.AttributesBuilder +import space.kscience.attributes.SetAttribute import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.expressions.Symbol import space.kscience.kmath.expressions.SymbolIndexer @@ -26,34 +28,25 @@ import kotlin.reflect.KClass public operator fun PointValuePair.component1(): DoubleArray = point public operator fun PointValuePair.component2(): Double = value -public class CMOptimizerEngine(public val optimizerBuilder: () -> MultivariateOptimizer) : OptimizationFeature { - override fun toString(): String = "CMOptimizer($optimizerBuilder)" -} +public object CMOptimizerEngine: OptimizationAttribute<() -> MultivariateOptimizer> /** * Specify a Commons-maths optimization engine */ -public fun FunctionOptimizationBuilder.cmEngine(optimizerBuilder: () -> MultivariateOptimizer) { - addFeature(CMOptimizerEngine(optimizerBuilder)) +public fun AttributesBuilder>.cmEngine(optimizerBuilder: () -> MultivariateOptimizer) { + set(CMOptimizerEngine, optimizerBuilder) } -public class CMOptimizerData(public val data: List OptimizationData>) : OptimizationFeature { - public constructor(vararg data: (SymbolIndexer.() -> OptimizationData)) : this(data.toList()) - - override fun toString(): String = "CMOptimizerData($data)" -} +public object CMOptimizerData: SetAttribute OptimizationData> /** * Specify Commons-maths optimization data. */ -public fun FunctionOptimizationBuilder.cmOptimizationData(data: SymbolIndexer.() -> OptimizationData) { - updateFeature { - val newData = (it?.data ?: emptyList()) + data - CMOptimizerData(newData) - } +public fun AttributesBuilder>.cmOptimizationData(data: SymbolIndexer.() -> OptimizationData) { + CMOptimizerData.add(data) } -public fun FunctionOptimizationBuilder.simplexSteps(vararg steps: Pair) { +public fun AttributesBuilder>.simplexSteps(vararg steps: Pair) { //TODO use convergence checker from features cmEngine { SimplexOptimizer(CMOptimizer.defaultConvergenceChecker) } cmOptimizationData { NelderMeadSimplex(mapOf(*steps).toDoubleArray()) } @@ -78,8 +71,8 @@ public object CMOptimizer : Optimizer> { ): FunctionOptimization { val startPoint = problem.startPoint - val parameters = problem.getFeature()?.symbols - ?: problem.getFeature>()?.point?.keys + val parameters = problem.attributes[OptimizationParameters] + ?: problem.attributes[OptimizationStartPoint()]?.keys ?: startPoint.keys @@ -90,7 +83,7 @@ public object CMOptimizer : Optimizer> { DEFAULT_MAX_ITER ) - val cmOptimizer: MultivariateOptimizer = problem.getFeature()?.optimizerBuilder?.invoke() + val cmOptimizer: MultivariateOptimizer = problem.attributes[CMOptimizerEngine]?.invoke() ?: NonLinearConjugateGradientOptimizer( NonLinearConjugateGradientOptimizer.Formula.FLETCHER_REEVES, convergenceChecker @@ -123,7 +116,7 @@ public object CMOptimizer : Optimizer> { } addOptimizationData(gradientFunction) - val logger = problem.getFeature() + val logger = problem.attributes[OptimizationLog] for (feature in problem.attributes) { when (feature) { @@ -139,7 +132,7 @@ public object CMOptimizer : Optimizer> { } val (point, value) = cmOptimizer.optimize(*optimizationData.values.toTypedArray()) - return problem.withFeatures(OptimizationResult(point.toMap()), OptimizationValue(value)) + return problem.withAttributes(OptimizationResult(point.toMap()), OptimizationValue(value)) } } } diff --git a/kmath-commons/src/jvmTest/kotlin/space/kscience/kmath/commons/optimization/OptimizeTest.kt b/kmath-commons/src/jvmTest/kotlin/space/kscience/kmath/commons/optimization/OptimizeTest.kt index 5933d0d36..5b8c7868a 100644 --- a/kmath-commons/src/jvmTest/kotlin/space/kscience/kmath/commons/optimization/OptimizeTest.kt +++ b/kmath-commons/src/jvmTest/kotlin/space/kscience/kmath/commons/optimization/OptimizeTest.kt @@ -31,7 +31,7 @@ internal class OptimizeTest { @Test fun testGradientOptimization() = runBlocking { val result = normal.optimizeWith(CMOptimizer, x to 1.0, y to 1.0) - println(result.resultPoint) + println(result.result) println(result.resultValue) } @@ -42,7 +42,7 @@ internal class OptimizeTest { //this sets simplex optimizer } - println(result.resultPoint) + println(result.result) println(result.resultValue) } diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/DSAlgebra.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/DSAlgebra.kt index 8ef751859..3e9f8707e 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/DSAlgebra.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/DSAlgebra.kt @@ -5,6 +5,7 @@ package space.kscience.kmath.expressions +import space.kscience.attributes.SafeType import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.operations.* import space.kscience.kmath.structures.Buffer @@ -331,10 +332,13 @@ public class DerivativeStructureRingExpression( public val elementBufferFactory: MutableBufferFactory = algebra.bufferFactory, public val function: DSRing.() -> DS, ) : DifferentiableExpression where A : Ring, A : ScaleOperations, A : NumericAlgebra { + + override val type: SafeType get() = elementBufferFactory.type + override operator fun invoke(arguments: Map): T = DSRing(algebra, 0, arguments).function().value - override fun derivativeOrNull(symbols: List): Expression = Expression { arguments -> + override fun derivativeOrNull(symbols: List): Expression = Expression(type) { arguments -> with( DSRing( algebra, @@ -443,10 +447,13 @@ public class DSFieldExpression>( public val algebra: A, public val function: DSField.() -> DS, ) : DifferentiableExpression { + + override val type: SafeType get() = algebra.type + override operator fun invoke(arguments: Map): T = DSField(algebra, 0, arguments).function().value - override fun derivativeOrNull(symbols: List): Expression = Expression { arguments -> + override fun derivativeOrNull(symbols: List): Expression = Expression(type) { arguments -> DSField( algebra, symbols.size, diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/Expression.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/Expression.kt index f350303bc..81ceaae8a 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/Expression.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/Expression.kt @@ -5,8 +5,13 @@ package space.kscience.kmath.expressions +import space.kscience.attributes.SafeType +import space.kscience.attributes.WithType import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.operations.Algebra +import space.kscience.kmath.operations.DoubleField +import space.kscience.kmath.operations.IntRing +import space.kscience.kmath.operations.LongRing import kotlin.jvm.JvmName import kotlin.properties.ReadOnlyProperty @@ -15,7 +20,7 @@ import kotlin.properties.ReadOnlyProperty * * @param T the type this expression takes as argument and returns. */ -public fun interface Expression { +public interface Expression : WithType { /** * Calls this expression from arguments. * @@ -25,11 +30,20 @@ public fun interface Expression { public operator fun invoke(arguments: Map): T } +public fun Expression(type: SafeType, block: (Map) -> T): Expression = object : Expression { + override fun invoke(arguments: Map): T = block(arguments) + + override val type: SafeType = type +} + /** * Specialization of [Expression] for [Double] allowing better performance because of using array. */ @UnstableKMathAPI public interface DoubleExpression : Expression { + + override val type: SafeType get() = DoubleField.type + /** * The indexer of this expression's arguments that should be used to build array for [invoke]. * @@ -49,7 +63,7 @@ public interface DoubleExpression : Expression { */ public operator fun invoke(arguments: DoubleArray): Double - public companion object{ + public companion object { internal val EMPTY_DOUBLE_ARRAY = DoubleArray(0) } } @@ -59,6 +73,9 @@ public interface DoubleExpression : Expression { */ @UnstableKMathAPI public interface IntExpression : Expression { + + override val type: SafeType get() = IntRing.type + /** * The indexer of this expression's arguments that should be used to build array for [invoke]. * @@ -78,7 +95,7 @@ public interface IntExpression : Expression { */ public operator fun invoke(arguments: IntArray): Int - public companion object{ + public companion object { internal val EMPTY_INT_ARRAY = IntArray(0) } } @@ -88,6 +105,9 @@ public interface IntExpression : Expression { */ @UnstableKMathAPI public interface LongExpression : Expression { + + override val type: SafeType get() = LongRing.type + /** * The indexer of this expression's arguments that should be used to build array for [invoke]. * @@ -107,7 +127,7 @@ public interface LongExpression : Expression { */ public operator fun invoke(arguments: LongArray): Long - public companion object{ + public companion object { internal val EMPTY_LONG_ARRAY = LongArray(0) } } @@ -158,7 +178,6 @@ public operator fun Expression.invoke(vararg pairs: Pair): T = ) - /** * Calls this expression without providing any arguments. * diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/ExpressionWithDefault.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/ExpressionWithDefault.kt index c802fe04c..8045817e6 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/ExpressionWithDefault.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/ExpressionWithDefault.kt @@ -5,10 +5,15 @@ package space.kscience.kmath.expressions +import space.kscience.attributes.SafeType + public class ExpressionWithDefault( private val origin: Expression, private val defaultArgs: Map, ) : Expression { + override val type: SafeType + get() = origin.type + override fun invoke(arguments: Map): T = origin.invoke(defaultArgs + arguments) } @@ -21,6 +26,9 @@ public class DiffExpressionWithDefault( private val defaultArgs: Map, ) : DifferentiableExpression { + override val type: SafeType + get() = origin.type + override fun invoke(arguments: Map): T = origin.invoke(defaultArgs + arguments) override fun derivativeOrNull(symbols: List): Expression? = diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/FunctionalExpressionAlgebra.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/FunctionalExpressionAlgebra.kt index 5b4dcd638..5ff408732 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/FunctionalExpressionAlgebra.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/FunctionalExpressionAlgebra.kt @@ -23,26 +23,27 @@ public abstract class FunctionalExpressionAlgebra>( /** * Builds an Expression of constant expression that does not depend on arguments. */ - override fun const(value: T): Expression = Expression { value } + override fun const(value: T): Expression = Expression(algebra.type) { value } /** * Builds an Expression to access a variable. */ - override fun bindSymbolOrNull(value: String): Expression? = Expression { arguments -> + override fun bindSymbolOrNull(value: String): Expression? = Expression(algebra.type) { arguments -> algebra.bindSymbolOrNull(value) ?: arguments[StringSymbol(value)] ?: error("Symbol '$value' is not supported in $this") } - override fun binaryOperationFunction(operation: String): (left: Expression, right: Expression) -> Expression = - { left, right -> - Expression { arguments -> - algebra.binaryOperationFunction(operation)(left(arguments), right(arguments)) - } + override fun binaryOperationFunction( + operation: String, + ): (left: Expression, right: Expression) -> Expression = { left, right -> + Expression(algebra.type) { arguments -> + algebra.binaryOperationFunction(operation)(left(arguments), right(arguments)) } + } override fun unaryOperationFunction(operation: String): (arg: Expression) -> Expression = { arg -> - Expression { arguments -> algebra.unaryOperation(operation, arg(arguments)) } + Expression(algebra.type) { arguments -> algebra.unaryOperation(operation, arg(arguments)) } } } @@ -124,7 +125,7 @@ public open class FunctionalExpressionField>( super.binaryOperationFunction(operation) override fun scale(a: Expression, value: Double): Expression = algebra { - Expression { args -> a(args) * value } + Expression(algebra.type) { args -> a(args) * value } } override fun bindSymbolOrNull(value: String): Expression? = diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/MST.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/MST.kt index 9705a3f03..7ceb23b37 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/MST.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/MST.kt @@ -108,4 +108,4 @@ public fun MST.interpret(algebra: Algebra, vararg arguments: Pair MST.toExpression(algebra: Algebra): Expression = - Expression { arguments -> interpret(algebra, arguments) } + Expression(algebra.type) { arguments -> interpret(algebra, arguments) } 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 fd7bf9fdc..7a67e12cc 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 @@ -243,12 +243,15 @@ public class SimpleAutoDiffExpression>( public val field: F, public val function: SimpleAutoDiffField.() -> AutoDiffValue, ) : FirstDerivativeExpression() { + + override val type: SafeType get() = this.field.type + override operator fun invoke(arguments: Map): T { //val bindings = arguments.entries.map { it.key.bind(it.value) } return SimpleAutoDiffField(field, arguments).function().value } - override fun derivativeOrNull(symbol: Symbol): Expression = Expression { arguments -> + override fun derivativeOrNull(symbol: Symbol): Expression = Expression(type) { arguments -> //val bindings = arguments.entries.map { it.key.bind(it.value) } val derivationResult = SimpleAutoDiffField(field, arguments).differentiate(function) derivationResult.derivative(symbol) diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/LinearSolver.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/LinearSolver.kt index af9ebb463..93d84025f 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/LinearSolver.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/LinearSolver.kt @@ -11,7 +11,7 @@ package space.kscience.kmath.linear * * @param T the type of items. */ -public interface LinearSolver { +public interface LinearSolver { /** * Solve a dot x = b matrix equation and return x */ 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 6b547e2c5..789164e02 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,10 +5,7 @@ package space.kscience.kmath.linear -import space.kscience.attributes.Attributes -import space.kscience.attributes.SafeType -import space.kscience.attributes.WithType -import space.kscience.attributes.withAttribute +import space.kscience.attributes.* import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.nd.* import space.kscience.kmath.operations.BufferRingOps @@ -31,19 +28,13 @@ public typealias MutableMatrix = MutableStructure2D */ public typealias Point = Buffer -/** - * A marker interface for algebras that operate on matrices - * @param T type of matrix element - */ -public interface MatrixOperations : WithType - /** * Basic operations on matrices and vectors. * * @param T the type of items in the matrices. * @param A the type of ring over [T]. */ -public interface LinearSpace> : MatrixOperations { +public interface LinearSpace> : MatrixScope { public val elementAlgebra: A override val type: SafeType get() = elementAlgebra.type @@ -177,10 +168,10 @@ public interface LinearSpace> : MatrixOperations { /** * Compute an [attribute] value for given [structure]. Return null if the attribute could not be computed. */ - public fun > computeAttribute(structure: StructureND<*>, attribute: A): V? = null + public fun > computeAttribute(structure: Structure2D, attribute: A): V? = null @UnstableKMathAPI - public fun > StructureND<*>.getOrComputeAttribute(attribute: A): V? { + public fun > Structure2D.getOrComputeAttribute(attribute: A): V? { return attributes[attribute] ?: computeAttribute(this, attribute) } @@ -225,7 +216,7 @@ public inline operator fun , R> LS.invoke(block: LS.() -> /** * Convert matrix to vector if it is possible. */ -public fun Matrix.asVector(): Point = +public fun Matrix.asVector(): Point = if (this.colNum == 1) as1D() else error("Can't convert matrix with more than one column to vector") @@ -236,4 +227,4 @@ public fun Matrix.asVector(): Point = * @receiver a buffer. * @return the new matrix. */ -public fun Point.asMatrix(): VirtualMatrix = VirtualMatrix(type, size, 1) { i, _ -> get(i) } \ No newline at end of file +public fun Point.asMatrix(): VirtualMatrix = VirtualMatrix(type, size, 1) { i, _ -> get(i) } \ No newline at end of file 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 fab4ef3db..bf595d332 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 @@ -9,12 +9,20 @@ package space.kscience.kmath.linear import space.kscience.attributes.Attributes import space.kscience.attributes.PolymorphicAttribute -import space.kscience.attributes.SafeType import space.kscience.attributes.safeTypeOf import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.operations.* import space.kscience.kmath.structures.* +public interface LupDecomposition { + public val linearSpace: LinearSpace> + public val elementAlgebra: Field get() = linearSpace.elementAlgebra + + public val pivot: IntBuffer + public val l: Matrix + public val u: Matrix +} + /** * Matrices with this feature support LU factorization with partial pivoting: *[p] · a = [l] · [u]* where * *a* is the owning matrix. @@ -22,15 +30,14 @@ import space.kscience.kmath.structures.* * @param T the type of matrices' items. * @param lu combined L and U matrix */ -public class LupDecomposition( - public val linearSpace: LinearSpace>, +public class GenericLupDecomposition( + override val linearSpace: LinearSpace>, private val lu: Matrix, - public val pivot: IntBuffer, + override val pivot: IntBuffer, private val even: Boolean, -) { - public val elementAlgebra: Ring get() = linearSpace.elementAlgebra +) : LupDecomposition { - public val l: Matrix + override val l: Matrix get() = VirtualMatrix(lu.type, lu.rowNum, lu.colNum, attributes = Attributes(LowerTriangular)) { i, j -> when { j < i -> lu[i, j] @@ -39,7 +46,7 @@ public class LupDecomposition( } } - public val u: Matrix + override val u: Matrix get() = VirtualMatrix(lu.type, lu.rowNum, lu.colNum, attributes = Attributes(UpperTriangular)) { i, j -> if (j >= i) lu[i, j] else elementAlgebra.zero } @@ -55,13 +62,12 @@ public class LupDecomposition( } - -public class LupDecompositionAttribute(type: SafeType>) : - PolymorphicAttribute>(type), +public class LupDecompositionAttribute : + PolymorphicAttribute>(safeTypeOf()), MatrixAttribute> -public val MatrixOperations.LUP: LupDecompositionAttribute - get() = LupDecompositionAttribute(safeTypeOf()) +public val MatrixScope.LUP: LupDecompositionAttribute + get() = LupDecompositionAttribute() @PublishedApi internal fun > LinearSpace>.abs(value: T): T = @@ -79,7 +85,7 @@ public fun > LinearSpace>.lup( val pivot = IntArray(matrix.rowNum) //TODO just waits for multi-receivers - with(BufferAccessor2D(matrix.rowNum, matrix.colNum, elementAlgebra.bufferFactory)){ + with(BufferAccessor2D(matrix.rowNum, matrix.colNum, elementAlgebra.bufferFactory)) { val lu = create(matrix) @@ -142,18 +148,17 @@ public fun > LinearSpace>.lup( for (row in col + 1 until m) lu[row, col] /= luDiag } - return LupDecomposition(this@lup, lu.toStructure2D(), pivot.asBuffer(), even) + return GenericLupDecomposition(this@lup, lu.toStructure2D(), pivot.asBuffer(), even) } } - public fun LinearSpace.lup( matrix: Matrix, singularityThreshold: Double = 1e-11, ): LupDecomposition = lup(matrix) { it < singularityThreshold } -internal fun > LinearSpace.solve( +internal fun LinearSpace>.solve( lup: LupDecomposition, matrix: Matrix, ): Matrix { @@ -205,7 +210,7 @@ internal fun > LinearSpace.solve( * Produce a generic solver based on LUP decomposition */ @OptIn(UnstableKMathAPI::class) -public fun , F : Field> LinearSpace.lupSolver( +public fun > LinearSpace>.lupSolver( singularityCheck: (T) -> Boolean, ): LinearSolver = object : LinearSolver { override fun solve(a: Matrix, b: Matrix): Matrix { diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixWrapper.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixWrapper.kt index eb14de3c7..4707f6cfe 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixWrapper.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixWrapper.kt @@ -35,7 +35,7 @@ public val Matrix.origin: Matrix /** * Add a single feature to a [Matrix] */ -public fun > Matrix.withAttribute( +public fun > Matrix.withAttribute( attribute: A, attrValue: T, ): MatrixWrapper = if (this is MatrixWrapper) { @@ -44,7 +44,7 @@ public fun > Matrix.withAttribute( MatrixWrapper(this, Attributes(attribute, attrValue)) } -public fun > Matrix.withAttribute( +public fun > Matrix.withAttribute( attribute: A, ): MatrixWrapper = if (this is MatrixWrapper) { MatrixWrapper(origin, attributes.withAttribute(attribute)) @@ -55,7 +55,7 @@ public fun > Matrix.withAttribute( /** * Modify matrix attributes */ -public fun Matrix.modifyAttributes(modifier: (Attributes) -> Attributes): MatrixWrapper = +public fun Matrix.modifyAttributes(modifier: (Attributes) -> Attributes): MatrixWrapper = if (this is MatrixWrapper) { MatrixWrapper(origin, modifier(attributes)) } else { @@ -65,7 +65,7 @@ public fun Matrix.modifyAttributes(modifier: (Attributes) -> Attrib /** * Diagonal matrix of ones. The matrix is virtual, no actual matrix is created. */ -public fun LinearSpace>.one( +public fun LinearSpace>.one( rows: Int, columns: Int, ): MatrixWrapper = VirtualMatrix(type, rows, columns) { i, j -> @@ -76,7 +76,7 @@ public fun LinearSpace>.one( /** * A virtual matrix of zeroes */ -public fun LinearSpace>.zero( +public fun LinearSpace>.zero( rows: Int, columns: Int, ): MatrixWrapper = VirtualMatrix(type, rows, columns) { _, _ -> diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/matrixAttributes.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/matrixAttributes.kt index 8787d0e09..dadb2f3d7 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/matrixAttributes.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/matrixAttributes.kt @@ -10,6 +10,13 @@ package space.kscience.kmath.linear import space.kscience.attributes.* import space.kscience.kmath.nd.StructureAttribute + +/** + * A marker interface for algebras that operate on matrices + * @param T type of matrix element + */ +public interface MatrixScope : AttributeScope>, WithType + /** * A marker interface representing some properties of matrices or additional transformations of them. Features are used * to optimize matrix operations performance in some cases or retrieve the APIs. @@ -38,11 +45,11 @@ public object IsUnit : IsDiagonal * * @param T the type of matrices' items. */ -public class Inverted(type: SafeType>) : - PolymorphicAttribute>(type), +public class Inverted() : + PolymorphicAttribute>(safeTypeOf()), MatrixAttribute> -public val MatrixOperations.Inverted: Inverted get() = Inverted(safeTypeOf()) +public val MatrixScope.Inverted: Inverted get() = Inverted() /** * Matrices with this feature can compute their determinant. @@ -53,7 +60,7 @@ public class Determinant(type: SafeType) : PolymorphicAttribute(type), MatrixAttribute -public val MatrixOperations.Determinant: Determinant get() = Determinant(type) +public val MatrixScope.Determinant: Determinant get() = Determinant(type) /** * Matrices with this feature are lower triangular ones. @@ -77,11 +84,11 @@ public data class LUDecomposition(val l: Matrix, val u: Matrix) * * @param T the type of matrices' items. */ -public class LuDecompositionAttribute(type: SafeType>) : - PolymorphicAttribute>(type), +public class LuDecompositionAttribute : + PolymorphicAttribute>(safeTypeOf()), MatrixAttribute> -public val MatrixOperations.LU: LuDecompositionAttribute get() = LuDecompositionAttribute(safeTypeOf()) +public val MatrixScope.LU: LuDecompositionAttribute get() = LuDecompositionAttribute() /** @@ -108,12 +115,12 @@ public interface QRDecomposition { * * @param T the type of matrices' items. */ -public class QRDecompositionAttribute(type: SafeType>) : - PolymorphicAttribute>(type), +public class QRDecompositionAttribute() : + PolymorphicAttribute>(safeTypeOf()), MatrixAttribute> -public val MatrixOperations.QR: QRDecompositionAttribute - get() = QRDecompositionAttribute(safeTypeOf()) +public val MatrixScope.QR: QRDecompositionAttribute + get() = QRDecompositionAttribute() public interface CholeskyDecomposition { /** @@ -128,12 +135,12 @@ public interface CholeskyDecomposition { * * @param T the type of matrices' items. */ -public class CholeskyDecompositionAttribute(type: SafeType>) : - PolymorphicAttribute>(type), +public class CholeskyDecompositionAttribute : + PolymorphicAttribute>(safeTypeOf()), MatrixAttribute> -public val MatrixOperations.Cholesky: CholeskyDecompositionAttribute - get() = CholeskyDecompositionAttribute(safeTypeOf()) +public val MatrixScope.Cholesky: CholeskyDecompositionAttribute + get() = CholeskyDecompositionAttribute() public interface SingularValueDecomposition { /** @@ -163,12 +170,11 @@ public interface SingularValueDecomposition { * * @param T the type of matrices' items. */ -public class SVDAttribute(type: SafeType>) : - PolymorphicAttribute>(type), +public class SVDAttribute() : + PolymorphicAttribute>(safeTypeOf()), MatrixAttribute> -public val MatrixOperations.SVD: SVDAttribute - get() = SVDAttribute(safeTypeOf()) +public val MatrixScope.SVD: SVDAttribute get() = SVDAttribute() //TODO add sparse matrix feature 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 37b14f8d1..47a4b686f 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 @@ -39,5 +39,5 @@ public abstract class EjmlLinearSpace, out M : org.ejml @UnstableKMathAPI public fun EjmlMatrix.inverted(): Matrix = - attributeForOrNull(this, Float64Field.linearSpace.Inverted) + computeAttribute(this, Float64Field.linearSpace.Inverted)!! } diff --git a/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/_generated.kt b/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/_generated.kt index 881649d01..882df9536 100644 --- a/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/_generated.kt +++ b/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/_generated.kt @@ -19,9 +19,13 @@ import org.ejml.sparse.csc.factory.DecompositionFactory_DSCC import org.ejml.sparse.csc.factory.DecompositionFactory_FSCC import org.ejml.sparse.csc.factory.LinearSolverFactory_DSCC import org.ejml.sparse.csc.factory.LinearSolverFactory_FSCC +import space.kscience.attributes.SafeType +import space.kscience.attributes.safeTypeOf import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.linear.* import space.kscience.kmath.linear.Matrix +import space.kscience.kmath.nd.Structure2D +import space.kscience.kmath.nd.StructureAttribute import space.kscience.kmath.nd.StructureFeature import space.kscience.kmath.operations.Float32Field import space.kscience.kmath.operations.Float64Field @@ -39,6 +43,8 @@ public class EjmlDoubleVector(override val origin: M) : EjmlVec require(origin.numRows == 1) { "The origin matrix must have only one row to form a vector" } } + override val type: SafeType get() = safeTypeOf() + override operator fun get(index: Int): Double = origin[0, index] } @@ -50,6 +56,8 @@ public class EjmlFloatVector(override val origin: M) : EjmlVect require(origin.numRows == 1) { "The origin matrix must have only one row to form a vector" } } + override val type: SafeType get() = safeTypeOf() + override operator fun get(index: Int): Float = origin[0, index] } @@ -57,6 +65,8 @@ public class EjmlFloatVector(override val origin: M) : EjmlVect * [EjmlMatrix] specialization for [Double]. */ public class EjmlDoubleMatrix(override val origin: M) : EjmlMatrix(origin) { + override val type: SafeType get() = safeTypeOf() + override operator fun get(i: Int, j: Int): Double = origin[i, j] } @@ -64,9 +74,12 @@ public class EjmlDoubleMatrix(override val origin: M) : EjmlMat * [EjmlMatrix] specialization for [Float]. */ public class EjmlFloatMatrix(override val origin: M) : EjmlMatrix(origin) { + override val type: SafeType get() = safeTypeOf() + override operator fun get(i: Int, j: Int): Float = origin[i, j] } + /** * [EjmlLinearSpace] implementation based on [CommonOps_DDRM], [DecompositionFactory_DDRM] operations and * [DMatrixRMaj] matrices. @@ -77,7 +90,7 @@ public object EjmlLinearSpaceDDRM : EjmlLinearSpace() + override val type: SafeType get() = safeTypeOf() @Suppress("UNCHECKED_CAST") override fun Matrix.toEjml(): EjmlDoubleMatrix = when { @@ -205,6 +218,18 @@ public object EjmlLinearSpaceDDRM : EjmlLinearSpace): EjmlDoubleVector = v * this + override fun > computeAttribute(structure: Structure2D, attribute: A): V? { + val origin = structure.toEjml().origin + return when(attribute){ + Inverted -> { + val res = origin.copy() + CommonOps_DDRM.invert(res) + res.wrapMatrix() + } + else-> + } + } + @UnstableKMathAPI override fun computeFeature(structure: Matrix, type: KClass): F? { structure.getFeature(type)?.let { return it } @@ -305,6 +330,8 @@ public object EjmlLinearSpaceDDRM : EjmlLinearSpace() + override val type: SafeType get() = safeTypeOf() @Suppress("UNCHECKED_CAST") override fun Matrix.toEjml(): EjmlFloatMatrix = when { @@ -543,6 +570,8 @@ public object EjmlLinearSpaceFDRM : EjmlLinearSpace() + override val type: SafeType get() = safeTypeOf() @Suppress("UNCHECKED_CAST") override fun Matrix.toEjml(): EjmlDoubleMatrix = when { @@ -776,6 +805,8 @@ public object EjmlLinearSpaceDSCC : EjmlLinearSpace() + override val type: SafeType get() = safeTypeOf() @Suppress("UNCHECKED_CAST") override fun Matrix.toEjml(): EjmlFloatMatrix = when { diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/GaussIntegrator.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/GaussIntegrator.kt index 7d37711cd..16b7a90f8 100644 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/GaussIntegrator.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/GaussIntegrator.kt @@ -4,7 +4,7 @@ */ package space.kscience.kmath.integration -import space.kscience.attributes.TypedAttributesBuilder +import space.kscience.attributes.AttributesBuilder import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.operations.Field import space.kscience.kmath.structures.Buffer @@ -92,7 +92,7 @@ public inline fun GaussIntegrator.integrate( range: ClosedRange, order: Int = 10, intervals: Int = 10, - attributesBuilder: TypedAttributesBuilder>.() -> Unit, + attributesBuilder: AttributesBuilder>.() -> Unit, noinline function: (Double) -> T, ): UnivariateIntegrand { require(range.endInclusive > range.start) { "The range upper bound should be higher than lower bound" } diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/Integrand.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/Integrand.kt index d465e87c7..d8f102b2f 100644 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/Integrand.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/Integrand.kt @@ -30,7 +30,7 @@ public sealed class IntegrandValue private constructor(): IntegrandAttribute< } } -public fun TypedAttributesBuilder>.value(value: T) { +public fun AttributesBuilder>.value(value: T) { IntegrandValue.forType().invoke(value) } diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/MultivariateIntegrand.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/MultivariateIntegrand.kt index 2081947ec..5c8a21f61 100644 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/MultivariateIntegrand.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/MultivariateIntegrand.kt @@ -25,10 +25,10 @@ public fun MultivariateIntegrand.withAttribute( ): MultivariateIntegrand = withAttributes(attributes.withAttribute(attribute, value)) public fun MultivariateIntegrand.withAttributes( - block: TypedAttributesBuilder>.() -> Unit, + block: AttributesBuilder>.() -> Unit, ): MultivariateIntegrand = withAttributes(attributes.modify(block)) public inline fun MultivariateIntegrand( - attributeBuilder: TypedAttributesBuilder>.() -> Unit, + attributeBuilder: AttributesBuilder>.() -> Unit, noinline function: (Point) -> T, ): MultivariateIntegrand = MultivariateIntegrand(safeTypeOf(), Attributes(attributeBuilder), function) diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/UnivariateIntegrand.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/UnivariateIntegrand.kt index 9c39e7edc..05a765858 100644 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/UnivariateIntegrand.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/UnivariateIntegrand.kt @@ -26,11 +26,11 @@ public fun UnivariateIntegrand.withAttribute( ): UnivariateIntegrand = withAttributes(attributes.withAttribute(attribute, value)) public fun UnivariateIntegrand.withAttributes( - block: TypedAttributesBuilder>.() -> Unit, + block: AttributesBuilder>.() -> Unit, ): UnivariateIntegrand = withAttributes(attributes.modify(block)) public inline fun UnivariateIntegrand( - attributeBuilder: TypedAttributesBuilder>.() -> Unit, + attributeBuilder: AttributesBuilder>.() -> Unit, noinline function: (Double) -> T, ): UnivariateIntegrand = UnivariateIntegrand(safeTypeOf(), Attributes(attributeBuilder), function) @@ -58,7 +58,7 @@ public class UnivariateIntegrandRanges(public val ranges: List> -public fun TypedAttributesBuilder>.integrationNodes(vararg nodes: Double) { +public fun AttributesBuilder>.integrationNodes(vararg nodes: Double) { UnivariateIntegrationNodes(Float64Buffer(nodes)) } @@ -68,7 +68,7 @@ public fun TypedAttributesBuilder>.integrationNodes(varar */ @UnstableKMathAPI public inline fun UnivariateIntegrator.integrate( - attributesBuilder: TypedAttributesBuilder>.() -> Unit, + attributesBuilder: AttributesBuilder>.() -> Unit, noinline function: (Double) -> T, ): UnivariateIntegrand = integrate(UnivariateIntegrand(attributesBuilder, function)) @@ -79,7 +79,7 @@ public inline fun UnivariateIntegrator.integrate( @UnstableKMathAPI public inline fun UnivariateIntegrator.integrate( range: ClosedRange, - attributeBuilder: TypedAttributesBuilder>.() -> Unit = {}, + attributeBuilder: AttributesBuilder>.() -> Unit = {}, noinline function: (Double) -> T, ): UnivariateIntegrand { diff --git a/kmath-jafama/build.gradle.kts b/kmath-jafama/build.gradle.kts index 5a77a97ed..0390224ba 100644 --- a/kmath-jafama/build.gradle.kts +++ b/kmath-jafama/build.gradle.kts @@ -14,7 +14,7 @@ repositories { } readme { - maturity = space.kscience.gradle.Maturity.PROTOTYPE + maturity = space.kscience.gradle.Maturity.DEPRECATED propertyByTemplate("artifact", rootProject.file("docs/templates/ARTIFACT-TEMPLATE.md")) feature("jafama-double", "src/main/kotlin/space/kscience/kmath/jafama/") { diff --git a/kmath-jafama/src/main/kotlin/space/kscience/kmath/jafama/KMathJafama.kt b/kmath-jafama/src/main/kotlin/space/kscience/kmath/jafama/KMathJafama.kt index f9b8287b4..1c52456f3 100644 --- a/kmath-jafama/src/main/kotlin/space/kscience/kmath/jafama/KMathJafama.kt +++ b/kmath-jafama/src/main/kotlin/space/kscience/kmath/jafama/KMathJafama.kt @@ -7,16 +7,17 @@ package space.kscience.kmath.jafama import net.jafama.FastMath import net.jafama.StrictFastMath -import space.kscience.kmath.operations.ExtendedField -import space.kscience.kmath.operations.Norm -import space.kscience.kmath.operations.PowerOperations -import space.kscience.kmath.operations.ScaleOperations +import space.kscience.kmath.operations.* +import space.kscience.kmath.structures.MutableBufferFactory /** * A field for [Double] (using FastMath) without boxing. Does not produce appropriate field element. */ @Suppress("EXTENSION_SHADOWED_BY_MEMBER", "OVERRIDE_BY_INLINE", "NOTHING_TO_INLINE") public object JafamaDoubleField : ExtendedField, Norm, ScaleOperations { + + override val bufferFactory: MutableBufferFactory get() = DoubleField.bufferFactory + override inline val zero: Double get() = 0.0 override inline val one: Double get() = 1.0 @@ -68,6 +69,9 @@ public object JafamaDoubleField : ExtendedField, Norm, S */ @Suppress("EXTENSION_SHADOWED_BY_MEMBER", "OVERRIDE_BY_INLINE", "NOTHING_TO_INLINE") public object StrictJafamaDoubleField : ExtendedField, Norm, ScaleOperations { + + override val bufferFactory: MutableBufferFactory get() = DoubleField.bufferFactory + override inline val zero: Double get() = 0.0 override inline val one: Double get() = 1.0 diff --git a/kmath-multik/src/commonMain/kotlin/space/kscience/kmath/multik/MultikDoubleAlgebra.kt b/kmath-multik/src/commonMain/kotlin/space/kscience/kmath/multik/MultikDoubleAlgebra.kt index 8b463a230..60413f88c 100644 --- a/kmath-multik/src/commonMain/kotlin/space/kscience/kmath/multik/MultikDoubleAlgebra.kt +++ b/kmath-multik/src/commonMain/kotlin/space/kscience/kmath/multik/MultikDoubleAlgebra.kt @@ -20,7 +20,7 @@ public class MultikDoubleAlgebra( ) : MultikDivisionTensorAlgebra(multikEngine), TrigonometricOperations>, ExponentialOperations> { override val elementAlgebra: Float64Field get() = Float64Field - override val type: DataType get() = DataType.DoubleDataType + override val dataType: DataType get() = DataType.DoubleDataType override fun sin(arg: StructureND): MultikTensor = multikMath.mathEx.sin(arg.asMultik().array).wrap() diff --git a/kmath-multik/src/commonMain/kotlin/space/kscience/kmath/multik/MultikFloatAlgebra.kt b/kmath-multik/src/commonMain/kotlin/space/kscience/kmath/multik/MultikFloatAlgebra.kt index 7a3dda94b..26331bd6b 100644 --- a/kmath-multik/src/commonMain/kotlin/space/kscience/kmath/multik/MultikFloatAlgebra.kt +++ b/kmath-multik/src/commonMain/kotlin/space/kscience/kmath/multik/MultikFloatAlgebra.kt @@ -15,7 +15,7 @@ public class MultikFloatAlgebra( multikEngine: Engine ) : MultikDivisionTensorAlgebra(multikEngine) { override val elementAlgebra: Float32Field get() = Float32Field - override val type: DataType get() = DataType.FloatDataType + override val dataType: DataType get() = DataType.FloatDataType override fun scalar(value: Float): MultikTensor = Multik.ndarrayOf(value).wrap() } diff --git a/kmath-multik/src/commonMain/kotlin/space/kscience/kmath/multik/MultikIntAlgebra.kt b/kmath-multik/src/commonMain/kotlin/space/kscience/kmath/multik/MultikIntAlgebra.kt index 5bd1b3388..46acbdf9d 100644 --- a/kmath-multik/src/commonMain/kotlin/space/kscience/kmath/multik/MultikIntAlgebra.kt +++ b/kmath-multik/src/commonMain/kotlin/space/kscience/kmath/multik/MultikIntAlgebra.kt @@ -15,7 +15,7 @@ public class MultikIntAlgebra( multikEngine: Engine ) : MultikTensorAlgebra(multikEngine) { override val elementAlgebra: Int32Ring get() = Int32Ring - override val type: DataType get() = DataType.IntDataType + override val dataType: DataType get() = DataType.IntDataType override fun scalar(value: Int): MultikTensor = Multik.ndarrayOf(value).wrap() } diff --git a/kmath-multik/src/commonMain/kotlin/space/kscience/kmath/multik/MultikLongAlgebra.kt b/kmath-multik/src/commonMain/kotlin/space/kscience/kmath/multik/MultikLongAlgebra.kt index 69a8ec042..97e86d86a 100644 --- a/kmath-multik/src/commonMain/kotlin/space/kscience/kmath/multik/MultikLongAlgebra.kt +++ b/kmath-multik/src/commonMain/kotlin/space/kscience/kmath/multik/MultikLongAlgebra.kt @@ -15,7 +15,7 @@ public class MultikLongAlgebra( multikEngine: Engine ) : MultikTensorAlgebra(multikEngine) { override val elementAlgebra: Int64Ring get() = Int64Ring - override val type: DataType get() = DataType.LongDataType + override val dataType: DataType get() = DataType.LongDataType override fun scalar(value: Long): MultikTensor = Multik.ndarrayOf(value).wrap() } diff --git a/kmath-multik/src/commonMain/kotlin/space/kscience/kmath/multik/MultikShortAlgebra.kt b/kmath-multik/src/commonMain/kotlin/space/kscience/kmath/multik/MultikShortAlgebra.kt index 7c8740665..27d43f7b8 100644 --- a/kmath-multik/src/commonMain/kotlin/space/kscience/kmath/multik/MultikShortAlgebra.kt +++ b/kmath-multik/src/commonMain/kotlin/space/kscience/kmath/multik/MultikShortAlgebra.kt @@ -15,7 +15,7 @@ public class MultikShortAlgebra( multikEngine: Engine ) : MultikTensorAlgebra(multikEngine) { override val elementAlgebra: Int16Ring get() = Int16Ring - override val type: DataType get() = DataType.ShortDataType + override val dataType: DataType get() = DataType.ShortDataType override fun scalar(value: Short): MultikTensor = Multik.ndarrayOf(value).wrap() } diff --git a/kmath-multik/src/commonMain/kotlin/space/kscience/kmath/multik/MultikTensor.kt b/kmath-multik/src/commonMain/kotlin/space/kscience/kmath/multik/MultikTensor.kt index 59a9a1bf3..5ed8ea767 100644 --- a/kmath-multik/src/commonMain/kotlin/space/kscience/kmath/multik/MultikTensor.kt +++ b/kmath-multik/src/commonMain/kotlin/space/kscience/kmath/multik/MultikTensor.kt @@ -6,13 +6,33 @@ package space.kscience.kmath.multik import org.jetbrains.kotlinx.multik.ndarray.data.* +import space.kscience.attributes.SafeType +import space.kscience.attributes.safeTypeOf import space.kscience.kmath.PerformancePitfall +import space.kscience.kmath.complex.ComplexField import space.kscience.kmath.nd.ShapeND +import space.kscience.kmath.operations.* import space.kscience.kmath.tensors.api.Tensor import kotlin.jvm.JvmInline +public val DataType.type: SafeType<*> + get() = when (this) { + DataType.ByteDataType -> ByteRing.type + DataType.ShortDataType -> ShortRing.type + DataType.IntDataType -> IntRing.type + DataType.LongDataType -> LongRing.type + DataType.FloatDataType -> Float32Field.type + DataType.DoubleDataType -> Float64Field.type + DataType.ComplexFloatDataType -> safeTypeOf>() + DataType.ComplexDoubleDataType -> ComplexField.type + } + + @JvmInline public value class MultikTensor(public val array: MutableMultiArray) : Tensor { + @Suppress("UNCHECKED_CAST") + override val type: SafeType get() = array.dtype.type as SafeType + override val shape: ShapeND get() = ShapeND(array.shape) @PerformancePitfall diff --git a/kmath-multik/src/commonMain/kotlin/space/kscience/kmath/multik/MultikTensorAlgebra.kt b/kmath-multik/src/commonMain/kotlin/space/kscience/kmath/multik/MultikTensorAlgebra.kt index c5bbebfd8..468f1652d 100644 --- a/kmath-multik/src/commonMain/kotlin/space/kscience/kmath/multik/MultikTensorAlgebra.kt +++ b/kmath-multik/src/commonMain/kotlin/space/kscience/kmath/multik/MultikTensorAlgebra.kt @@ -26,7 +26,7 @@ public abstract class MultikTensorAlgebra>( private val multikEngine: Engine, ) : TensorAlgebra where T : Number, T : Comparable { - public abstract val type: DataType + public abstract val dataType: DataType protected val multikMath: Math = multikEngine.getMath() protected val multikLinAl: LinAlg = multikEngine.getLinAlg() @@ -35,7 +35,7 @@ public abstract class MultikTensorAlgebra>( @OptIn(UnsafeKMathAPI::class) override fun mutableStructureND(shape: ShapeND, initializer: A.(IntArray) -> T): MultikTensor { val strides = ColumnStrides(shape) - val memoryView = initMemoryView(strides.linearSize, type) + val memoryView = initMemoryView(strides.linearSize, dataType) strides.asSequence().forEachIndexed { linearIndex, tensorIndex -> memoryView[linearIndex] = elementAlgebra.initializer(tensorIndex) } @@ -44,7 +44,7 @@ public abstract class MultikTensorAlgebra>( @OptIn(PerformancePitfall::class, UnsafeKMathAPI::class) override fun StructureND.map(transform: A.(T) -> T): MultikTensor = if (this is MultikTensor) { - val data = initMemoryView(array.size, type) + val data = initMemoryView(array.size, dataType) var count = 0 for (el in array) data[count++] = elementAlgebra.transform(el) NDArray(data, shape = shape.asArray(), dim = array.dim).wrap() @@ -58,7 +58,7 @@ public abstract class MultikTensorAlgebra>( override fun StructureND.mapIndexed(transform: A.(index: IntArray, T) -> T): MultikTensor = if (this is MultikTensor) { val array = asMultik().array - val data = initMemoryView(array.size, type) + val data = initMemoryView(array.size, dataType) val indexIter = array.multiIndices.iterator() var index = 0 for (item in array) { @@ -95,7 +95,7 @@ public abstract class MultikTensorAlgebra>( require(left.shape.contentEquals(right.shape)) { "ND array shape mismatch" } //TODO replace by ShapeMismatchException val leftArray = left.asMultik().array val rightArray = right.asMultik().array - val data = initMemoryView(leftArray.size, type) + val data = initMemoryView(leftArray.size, dataType) var counter = 0 val leftIterator = leftArray.iterator() val rightIterator = rightArray.iterator() @@ -114,7 +114,7 @@ public abstract class MultikTensorAlgebra>( public fun StructureND.asMultik(): MultikTensor = if (this is MultikTensor) { this } else { - val res = mk.zeros(shape.asArray(), type).asDNArray() + val res = mk.zeros(shape.asArray(), dataType).asDNArray() for (index in res.multiIndices) { res[index] = this[index] } @@ -296,7 +296,7 @@ public abstract class MultikDivisionTensorAlgebra>( @OptIn(UnsafeKMathAPI::class) override fun T.div(arg: StructureND): MultikTensor = - Multik.ones(arg.shape.asArray(), type).apply { divAssign(arg.asMultik().array) }.wrap() + Multik.ones(arg.shape.asArray(), dataType).apply { divAssign(arg.asMultik().array) }.wrap() override fun StructureND.div(arg: T): MultikTensor = asMultik().array.div(arg).wrap() diff --git a/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/FunctionOptimization.kt b/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/FunctionOptimization.kt index 8025428e6..527c8abae 100644 --- a/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/FunctionOptimization.kt +++ b/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/FunctionOptimization.kt @@ -9,20 +9,21 @@ import space.kscience.attributes.* import space.kscience.kmath.expressions.DifferentiableExpression import space.kscience.kmath.expressions.Symbol -public class OptimizationValue(public val value: T) : OptimizationFeature { - override fun toString(): String = "Value($value)" -} +public class OptimizationValue(type: SafeType) : PolymorphicAttribute(type) -public enum class FunctionOptimizationTarget { +public enum class OptimizationDirection { MAXIMIZE, MINIMIZE } +public object FunctionOptimizationTarget: OptimizationAttribute + public class FunctionOptimization( - override val attributes: Attributes, public val expression: DifferentiableExpression, + override val attributes: Attributes, ) : OptimizationProblem { + override val type: SafeType get() = expression.type override fun equals(other: Any?): Boolean { if (this === other) return true @@ -47,36 +48,52 @@ public class FunctionOptimization( public companion object } +public fun FunctionOptimization( + expression: DifferentiableExpression, + attributeBuilder: AttributesBuilder>.() -> Unit, +): FunctionOptimization = FunctionOptimization(expression, Attributes(attributeBuilder)) - -public class OptimizationPrior(type: SafeType): +public class OptimizationPrior : PolymorphicAttribute>(safeTypeOf()), Attribute> -//public val FunctionOptimization.Companion.Optimization get() = - - -public fun FunctionOptimization.withFeatures( - vararg newFeature: OptimizationFeature, +public fun FunctionOptimization.withAttributes( + modifier: AttributesBuilder>.() -> Unit, ): FunctionOptimization = FunctionOptimization( - attributes.with(*newFeature), expression, + attributes.modify(modifier), ) /** * Optimizes differentiable expression using specific [optimizer] form given [startingPoint]. */ -public suspend fun DifferentiableExpression.optimizeWith( +public suspend fun DifferentiableExpression.optimizeWith( optimizer: Optimizer>, startingPoint: Map, - vararg features: OptimizationFeature, + modifier: AttributesBuilder>.() -> Unit = {}, ): FunctionOptimization { - val problem = FunctionOptimization(FeatureSet.of(OptimizationStartPoint(startingPoint), *features), this) + val problem = FunctionOptimization(this){ + startAt(startingPoint) + modifier() + } return optimizer.optimize(problem) } public val FunctionOptimization.resultValueOrNull: T? - get() = getFeature>()?.point?.let { expression(it) } + get() = attributes[OptimizationResult()]?.let { expression(it) } public val FunctionOptimization.resultValue: T - get() = resultValueOrNull ?: error("Result is not present in $this") \ No newline at end of file + get() = resultValueOrNull ?: error("Result is not present in $this") + + +public suspend fun DifferentiableExpression.optimizeWith( + optimizer: Optimizer>, + vararg startingPoint: Pair, + builder: AttributesBuilder>.() -> Unit = {}, +): FunctionOptimization { + val problem = FunctionOptimization(this) { + startAt(mapOf(*startingPoint)) + builder() + } + return optimizer.optimize(problem) +} diff --git a/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/OptimizationBuilder.kt b/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/OptimizationBuilder.kt deleted file mode 100644 index 0459d46ee..000000000 --- a/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/OptimizationBuilder.kt +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright 2018-2022 KMath contributors. - * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. - */ - -package space.kscience.kmath.optimization - -import space.kscience.kmath.UnstableKMathAPI -import space.kscience.kmath.data.XYColumnarData -import space.kscience.kmath.expressions.DifferentiableExpression -import space.kscience.kmath.expressions.Symbol -import space.kscience.kmath.misc.FeatureSet - -public abstract class OptimizationBuilder> { - public val features: MutableList = ArrayList() - - public fun addFeature(feature: OptimizationFeature) { - features.add(feature) - } - - public inline fun updateFeature(update: (T?) -> T) { - val existing = features.find { it.key == T::class } as? T - val new = update(existing) - if (existing != null) { - features.remove(existing) - } - addFeature(new) - } - - public abstract fun build(): R -} - -public fun OptimizationBuilder.startAt(startingPoint: Map) { - addFeature(OptimizationStartPoint(startingPoint)) -} - -public class FunctionOptimizationBuilder( - private val expression: DifferentiableExpression, -) : OptimizationBuilder>() { - override fun build(): FunctionOptimization = FunctionOptimization(FeatureSet.of(features), expression) -} - -public fun FunctionOptimization( - expression: DifferentiableExpression, - builder: FunctionOptimizationBuilder.() -> Unit, -): FunctionOptimization = FunctionOptimizationBuilder(expression).apply(builder).build() - -public suspend fun DifferentiableExpression.optimizeWith( - optimizer: Optimizer>, - startingPoint: Map, - builder: FunctionOptimizationBuilder.() -> Unit = {}, -): FunctionOptimization { - val problem = FunctionOptimization(this) { - startAt(startingPoint) - builder() - } - return optimizer.optimize(problem) -} - -public suspend fun DifferentiableExpression.optimizeWith( - optimizer: Optimizer>, - vararg startingPoint: Pair, - builder: FunctionOptimizationBuilder.() -> Unit = {}, -): FunctionOptimization { - val problem = FunctionOptimization(this) { - startAt(mapOf(*startingPoint)) - builder() - } - return optimizer.optimize(problem) -} - - -@OptIn(UnstableKMathAPI::class) -public class XYOptimizationBuilder( - public val data: XYColumnarData, - public val model: DifferentiableExpression, -) : OptimizationBuilder() { - - public var pointToCurveDistance: PointToCurveDistance = PointToCurveDistance.byY - public var pointWeight: PointWeight = PointWeight.byYSigma - - override fun build(): XYFit = XYFit( - data, - model, - FeatureSet.of(features), - pointToCurveDistance, - pointWeight - ) -} - -@OptIn(UnstableKMathAPI::class) -public fun XYOptimization( - data: XYColumnarData, - model: DifferentiableExpression, - builder: XYOptimizationBuilder.() -> Unit, -): XYFit = XYOptimizationBuilder(data, model).apply(builder).build() \ No newline at end of file diff --git a/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/OptimizationProblem.kt b/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/OptimizationProblem.kt index 46ba8c1c0..49f3bb266 100644 --- a/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/OptimizationProblem.kt +++ b/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/OptimizationProblem.kt @@ -6,64 +6,53 @@ package space.kscience.kmath.optimization import space.kscience.attributes.* -import space.kscience.kmath.expressions.DifferentiableExpression import space.kscience.kmath.expressions.NamedMatrix import space.kscience.kmath.expressions.Symbol -import space.kscience.kmath.misc.* -import kotlin.reflect.KClass +import space.kscience.kmath.misc.Loggable -public interface OptimizationAttribute: Attribute +public interface OptimizationAttribute : Attribute -public interface OptimizationProblem : AttributeContainer +public interface OptimizationProblem : AttributeContainer, WithType -public inline fun OptimizationProblem<*>.getFeature(): F? = getFeature(F::class) - -public open class OptimizationStartPoint(public val point: Map) : OptimizationFeature { - override fun toString(): String = "StartPoint($point)" -} - -/** - * Covariance matrix for - */ -public class OptimizationCovariance(public val covariance: NamedMatrix) : OptimizationFeature { - override fun toString(): String = "Covariance($covariance)" -} +public class OptimizationStartPoint : OptimizationAttribute>, + PolymorphicAttribute>(safeTypeOf()) /** * Get the starting point for optimization. Throws error if not defined. */ public val OptimizationProblem.startPoint: Map - get() = getFeature>()?.point - ?: error("Starting point not defined in $this") + get() = attributes[OptimizationStartPoint()] ?: error("Starting point not defined in $this") -public open class OptimizationResult(public val point: Map) : OptimizationFeature { - override fun toString(): String = "Result($point)" +public fun AttributesBuilder>.startAt(startingPoint: Map) { + set(::OptimizationStartPoint, startingPoint) } -public val OptimizationProblem.resultPointOrNull: Map? - get() = getFeature>()?.point -public val OptimizationProblem.resultPoint: Map - get() = resultPointOrNull ?: error("Result is not present in $this") +/** + * Covariance matrix for optimization + */ +public class OptimizationCovariance : OptimizationAttribute>, + PolymorphicAttribute>(safeTypeOf()) -public class OptimizationLog(private val loggable: Loggable) : Loggable by loggable, OptimizationFeature { - override fun toString(): String = "Log($loggable)" -} + +public class OptimizationResult() : OptimizationAttribute>, + PolymorphicAttribute>(safeTypeOf()) + +public val OptimizationProblem.resultOrNull: Map? get() = attributes[OptimizationResult()] + +public val OptimizationProblem.result: Map + get() = resultOrNull ?: error("Result is not present in $this") + +public object OptimizationLog : OptimizationAttribute /** * Free parameters of the optimization */ -public class OptimizationParameters(public val symbols: List) : OptimizationFeature { - public constructor(vararg symbols: Symbol) : this(listOf(*symbols)) - - override fun toString(): String = "Parameters($symbols)" -} +public object OptimizationParameters : OptimizationAttribute> /** * Maximum allowed number of iterations */ -public class OptimizationIterations(public val maxIterations: Int) : OptimizationFeature { - override fun toString(): String = "Iterations($maxIterations)" -} +public object OptimizationIterations : OptimizationAttribute diff --git a/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/QowOptimizer.kt b/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/QowOptimizer.kt index e922fd423..9b715f95d 100644 --- a/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/QowOptimizer.kt +++ b/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/QowOptimizer.kt @@ -16,13 +16,7 @@ import space.kscience.kmath.structures.Float64Buffer import kotlin.math.abs -public class QowRuns(public val runs: Int) : OptimizationFeature { - init { - require(runs >= 1) { "Number of runs must be more than zero" } - } - - override fun toString(): String = "QowRuns(runs=$runs)" -} +public object QowRuns: OptimizationAttribute /** @@ -69,7 +63,7 @@ public object QowOptimizer : Optimizer { } val prior: DifferentiableExpression? - get() = problem.getFeature>()?.withDefaultArgs(allParameters) + get() = problem.attributes[OptimizationPrior()]?.withDefaultArgs(allParameters) override fun toString(): String = freeParameters.toString() } @@ -176,7 +170,7 @@ public object QowOptimizer : Optimizer { fast: Boolean = false, ): QoWeight { - val logger = problem.getFeature() + val logger = problem.attributes[OptimizationLog] var dis: Double //discrepancy value @@ -231,7 +225,7 @@ public object QowOptimizer : Optimizer { } private fun QoWeight.covariance(): NamedMatrix { - val logger = problem.getFeature() + val logger = problem.attributes[OptimizationLog] logger?.log { """ @@ -257,11 +251,11 @@ public object QowOptimizer : Optimizer { } override suspend fun optimize(problem: XYFit): XYFit { - val qowRuns = problem.getFeature()?.runs ?: 2 - val iterations = problem.getFeature()?.maxIterations ?: 50 + val qowRuns = problem.attributes[QowRuns] ?: 2 + val iterations = problem.attributes[OptimizationIterations] ?: 50 - val freeParameters: Map = problem.getFeature()?.let { op -> - problem.startPoint.filterKeys { it in op.symbols } + val freeParameters: Map = problem.attributes[OptimizationParameters]?.let { symbols -> + problem.startPoint.filterKeys { it in symbols } } ?: problem.startPoint var qow = QoWeight(problem, freeParameters) @@ -271,6 +265,9 @@ public object QowOptimizer : Optimizer { res = qow.newtonianRun(maxSteps = iterations) } val covariance = res.covariance() - return res.problem.withFeature(OptimizationResult(res.freeParameters), OptimizationCovariance(covariance)) + return res.problem.withAttributes { + set(OptimizationResult(), res.freeParameters) + set(OptimizationCovariance(), covariance) + } } } \ No newline at end of file diff --git a/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/XYFit.kt b/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/XYFit.kt index cda37af4f..59143c338 100644 --- a/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/XYFit.kt +++ b/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/XYFit.kt @@ -2,37 +2,41 @@ * Copyright 2018-2022 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ -@file:OptIn(UnstableKMathAPI::class) +@file:OptIn(UnstableKMathAPI::class, UnstableKMathAPI::class) package space.kscience.kmath.optimization +import space.kscience.attributes.* import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.data.XYColumnarData import space.kscience.kmath.data.indices import space.kscience.kmath.expressions.* -import space.kscience.kmath.misc.FeatureSet import space.kscience.kmath.misc.Loggable +import space.kscience.kmath.operations.DoubleField import space.kscience.kmath.operations.ExtendedField +import space.kscience.kmath.operations.Float64Field import space.kscience.kmath.operations.bindSymbol import kotlin.math.pow /** * Specify the way to compute distance from point to the curve as DifferentiableExpression */ -public interface PointToCurveDistance : OptimizationFeature { +public interface PointToCurveDistance { public fun distance(problem: XYFit, index: Int): DifferentiableExpression - public companion object { + public companion object : OptimizationAttribute { public val byY: PointToCurveDistance = object : PointToCurveDistance { override fun distance(problem: XYFit, index: Int): DifferentiableExpression { val x = problem.data.x[index] val y = problem.data.y[index] return object : DifferentiableExpression { + override val type: SafeType get() = DoubleField.type + override fun derivativeOrNull( symbols: List, ): Expression? = problem.model.derivativeOrNull(symbols)?.let { derivExpression -> - Expression { arguments -> + Expression(DoubleField.type) { arguments -> derivExpression.invoke(arguments + (Symbol.x to x)) } } @@ -51,18 +55,21 @@ public interface PointToCurveDistance : OptimizationFeature { * Compute a wight of the point. The more the weight, the more impact this point will have on the fit. * By default, uses Dispersion^-1 */ -public interface PointWeight : OptimizationFeature { +public interface PointWeight { public fun weight(problem: XYFit, index: Int): DifferentiableExpression - public companion object { + public companion object : OptimizationAttribute { public fun bySigma(sigmaSymbol: Symbol): PointWeight = object : PointWeight { override fun weight(problem: XYFit, index: Int): DifferentiableExpression = object : DifferentiableExpression { + override val type: SafeType get() = DoubleField.type + override fun invoke(arguments: Map): Double { return problem.data[sigmaSymbol]?.get(index)?.pow(-2) ?: 1.0 } - override fun derivativeOrNull(symbols: List): Expression = Expression { 0.0 } + override fun derivativeOrNull(symbols: List): Expression = + Expression(DoubleField.type) { 0.0 } } override fun toString(): String = "PointWeightBySigma($sigmaSymbol)" @@ -79,41 +86,52 @@ public interface PointWeight : OptimizationFeature { public class XYFit( public val data: XYColumnarData, public val model: DifferentiableExpression, - override val attributes: FeatureSet, + override val attributes: Attributes, internal val pointToCurveDistance: PointToCurveDistance = PointToCurveDistance.byY, internal val pointWeight: PointWeight = PointWeight.byYSigma, public val xSymbol: Symbol = Symbol.x, ) : OptimizationProblem { + + override val type: SafeType get() = Float64Field.type + public fun distance(index: Int): DifferentiableExpression = pointToCurveDistance.distance(this, index) public fun weight(index: Int): DifferentiableExpression = pointWeight.weight(this, index) } -public fun XYFit.withFeature(vararg features: OptimizationFeature): XYFit { - return XYFit(data, model, this.attributes.with(*features), pointToCurveDistance, pointWeight) -} + +public fun XYOptimization( + data: XYColumnarData, + model: DifferentiableExpression, + builder: AttributesBuilder.() -> Unit, +): XYFit = XYFit(data, model, Attributes(builder)) + +public fun XYFit.withAttributes( + modifier: AttributesBuilder.() -> Unit, +): XYFit = XYFit(data, model, attributes.modify(modifier), pointToCurveDistance, pointWeight, xSymbol) public suspend fun XYColumnarData.fitWith( optimizer: Optimizer, modelExpression: DifferentiableExpression, startingPoint: Map, - vararg features: OptimizationFeature = emptyArray(), + attributes: Attributes = Attributes.EMPTY, xSymbol: Symbol = Symbol.x, pointToCurveDistance: PointToCurveDistance = PointToCurveDistance.byY, pointWeight: PointWeight = PointWeight.byYSigma, ): XYFit { - var actualFeatures = FeatureSet.of(*features, OptimizationStartPoint(startingPoint)) - if (actualFeatures.getFeature() == null) { - actualFeatures = actualFeatures.with(OptimizationLog(Loggable.console)) - } val problem = XYFit( this, modelExpression, - actualFeatures, + attributes.modify { + set(::OptimizationStartPoint, startingPoint) + if (!hasAny()) { + set(OptimizationLog, Loggable.console) + } + }, pointToCurveDistance, pointWeight, - xSymbol + xSymbol, ) return optimizer.optimize(problem) } @@ -125,7 +143,7 @@ public suspend fun XYColumnarData.fitWith( optimizer: Optimizer, processor: AutoDiffProcessor, startingPoint: Map, - vararg features: OptimizationFeature = emptyArray(), + attributes: Attributes = Attributes.EMPTY, xSymbol: Symbol = Symbol.x, pointToCurveDistance: PointToCurveDistance = PointToCurveDistance.byY, pointWeight: PointWeight = PointWeight.byYSigma, @@ -140,7 +158,7 @@ public suspend fun XYColumnarData.fitWith( optimizer = optimizer, modelExpression = modelExpression, startingPoint = startingPoint, - features = features, + attributes = attributes, xSymbol = xSymbol, pointToCurveDistance = pointToCurveDistance, pointWeight = pointWeight @@ -152,7 +170,7 @@ public suspend fun XYColumnarData.fitWith( */ public val XYFit.chiSquaredOrNull: Double? get() { - val result = startPoint + (resultPointOrNull ?: return null) + val result = startPoint + (resultOrNull ?: return null) return data.indices.sumOf { index -> @@ -167,4 +185,4 @@ public val XYFit.chiSquaredOrNull: Double? } public val XYFit.dof: Int - get() = data.size - (getFeature()?.symbols?.size ?: startPoint.size) \ No newline at end of file + get() = data.size - (attributes[OptimizationParameters]?.size ?: startPoint.size) \ No newline at end of file diff --git a/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/logLikelihood.kt b/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/logLikelihood.kt index 40081ed81..aa77cdda6 100644 --- a/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/logLikelihood.kt +++ b/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/logLikelihood.kt @@ -5,6 +5,8 @@ package space.kscience.kmath.optimization +import space.kscience.attributes.AttributesBuilder +import space.kscience.attributes.SafeType import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.data.XYColumnarData import space.kscience.kmath.data.indices @@ -12,6 +14,7 @@ import space.kscience.kmath.expressions.DifferentiableExpression import space.kscience.kmath.expressions.Expression import space.kscience.kmath.expressions.Symbol import space.kscience.kmath.expressions.derivative +import space.kscience.kmath.operations.Float64Field import kotlin.math.PI import kotlin.math.ln import kotlin.math.pow @@ -22,7 +25,9 @@ private val oneOver2Pi = 1.0 / sqrt(2 * PI) @UnstableKMathAPI internal fun XYFit.logLikelihood(): DifferentiableExpression = object : DifferentiableExpression { - override fun derivativeOrNull(symbols: List): Expression = Expression { arguments -> + override val type: SafeType get() = Float64Field.type + + override fun derivativeOrNull(symbols: List): Expression = Expression(type) { arguments -> data.indices.sumOf { index -> val d = distance(index)(arguments) val weight = weight(index)(arguments) @@ -53,14 +58,18 @@ internal fun XYFit.logLikelihood(): DifferentiableExpression = object : */ @UnstableKMathAPI public suspend fun Optimizer>.maximumLogLikelihood(problem: XYFit): XYFit { - val functionOptimization = FunctionOptimization(problem.attributes, problem.logLikelihood()) - val result = optimize(functionOptimization.withFeatures(FunctionOptimizationTarget.MAXIMIZE)) - return XYFit(problem.data, problem.model, result.attributes) + val functionOptimization = FunctionOptimization(problem.logLikelihood(), problem.attributes) + val result = optimize( + functionOptimization.withAttributes { + FunctionOptimizationTarget(OptimizationDirection.MAXIMIZE) + } + ) + return XYFit(problem.data,problem.model, result.attributes) } @UnstableKMathAPI public suspend fun Optimizer>.maximumLogLikelihood( data: XYColumnarData, model: DifferentiableExpression, - builder: XYOptimizationBuilder.() -> Unit, + builder: AttributesBuilder.() -> Unit, ): XYFit = maximumLogLikelihood(XYOptimization(data, model, builder)) diff --git a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/DoubleTensor.kt b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/DoubleTensor.kt index 8a97114c3..d960fe210 100644 --- a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/DoubleTensor.kt +++ b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/DoubleTensor.kt @@ -5,10 +5,12 @@ package space.kscience.kmath.tensors.core +import space.kscience.attributes.SafeType import space.kscience.kmath.PerformancePitfall import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.nd.MutableStructureNDOfDouble import space.kscience.kmath.nd.ShapeND +import space.kscience.kmath.operations.DoubleField import space.kscience.kmath.structures.* import space.kscience.kmath.tensors.core.internal.toPrettyString @@ -88,6 +90,8 @@ public open class DoubleTensor( final override val source: OffsetDoubleBuffer, ) : BufferedTensor(shape), MutableStructureNDOfDouble { + override val type: SafeType get() = DoubleField.type + init { require(linearSize == source.size) { "Source buffer size must be equal tensor size" } } diff --git a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/IntTensor.kt b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/IntTensor.kt index 1066793a7..005bf5d2a 100644 --- a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/IntTensor.kt +++ b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/IntTensor.kt @@ -5,8 +5,10 @@ package space.kscience.kmath.tensors.core +import space.kscience.attributes.SafeType import space.kscience.kmath.PerformancePitfall import space.kscience.kmath.nd.ShapeND +import space.kscience.kmath.operations.IntRing import space.kscience.kmath.structures.* /** @@ -24,6 +26,8 @@ public class OffsetIntBuffer( require(offset + size <= source.size) { "Maximum index must be inside source dimension" } } + override val type: SafeType get() = IntRing.type + override fun set(index: Int, value: Int) { require(index in 0 until size) { "Index must be in [0, size)" } source[index + offset] = value @@ -83,6 +87,8 @@ public class IntTensor( require(linearSize == source.size) { "Source buffer size must be equal tensor size" } } + override val type: SafeType get() = IntRing.type + public constructor(shape: ShapeND, buffer: Int32Buffer) : this(shape, OffsetIntBuffer(buffer, 0, buffer.size)) @OptIn(PerformancePitfall::class) From 24b934eab7c43c43a5748071ace91f80d4350c22 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Wed, 22 Nov 2023 14:32:56 +0300 Subject: [PATCH 18/40] Add `Buffer.asList()` --- CHANGELOG.md | 1 + .../space/kscience/kmath/structures/Buffer.kt | 41 +++++----- .../kscience/kmath/structures/BufferList.kt | 81 +++++++++++++++++++ .../space/kscience/kmath/ejml/_generated.kt | 21 +---- 4 files changed, 107 insertions(+), 37 deletions(-) create mode 100644 kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/BufferList.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 58df6f1bb..9498cc4ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - Float32 geometries. - New Attributes-kt module that could be used as stand-alone. It declares. type-safe attributes containers. - Explicit `mutableStructureND` builders for mutable structures. +- `Buffer.asList()` zero-copy transformation. ### Changed - Default naming for algebra and buffers now uses IntXX/FloatXX notation instead of Java types. 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 26e238145..df9d3c0eb 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 @@ -101,32 +101,13 @@ public interface Buffer : WithSize, WithType { } } -/** - * Creates a [Buffer] of given type [T]. If the type is primitive, specialized buffers are used ([Int32Buffer], - * [Float64Buffer], 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 Buffer(size: Int, initializer: (Int) -> T): Buffer { - val type = safeTypeOf() - return when (type.kType) { - typeOf() -> MutableBuffer.double(size) { initializer(it) as Double } as Buffer - typeOf() -> MutableBuffer.short(size) { initializer(it) as Short } as Buffer - typeOf() -> MutableBuffer.int(size) { initializer(it) as Int } as Buffer - typeOf() -> MutableBuffer.long(size) { initializer(it) as Long } as Buffer - typeOf() -> MutableBuffer.float(size) { initializer(it) as Float } as Buffer - else -> List(size, initializer).asBuffer(type) - } -} - /** * Creates a [Buffer] of given [type]. If the type is primitive, specialized buffers are used ([Int32Buffer], * [Float64Buffer], etc.), [ListBuffer] is returned otherwise. * * The [size] is specified, and each element is calculated by calling the specified [initializer] function. */ -@Suppress("UNCHECKED_CAST") +@Suppress("UNCHECKED_CAST", "DuplicatedCode") public fun Buffer( type: SafeType, size: Int, @@ -140,6 +121,26 @@ public fun Buffer( else -> List(size, initializer).asBuffer(type) } +/** + * Creates a [Buffer] of given type [T]. If the type is primitive, specialized buffers are used ([Int32Buffer], + * [Float64Buffer], etc.), [ListBuffer] is returned otherwise. + * + * The [size] is specified, and each element is calculated by calling the specified [initializer] function. + */ +@Suppress("UNCHECKED_CAST", "DuplicatedCode") +public inline fun Buffer(size: Int, initializer: (Int) -> T): Buffer { + //code duplication here because we want to inline initializers + val type = safeTypeOf() + return when (type.kType) { + typeOf() -> MutableBuffer.double(size) { initializer(it) as Double } as Buffer + typeOf() -> MutableBuffer.short(size) { initializer(it) as Short } as Buffer + typeOf() -> MutableBuffer.int(size) { initializer(it) as Int } as Buffer + typeOf() -> MutableBuffer.long(size) { initializer(it) as Long } as Buffer + typeOf() -> MutableBuffer.float(size) { initializer(it) as Float } as Buffer + else -> List(size, initializer).asBuffer(type) + } +} + /** * Returns an [IntRange] of the valid indices for this [Buffer]. */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/BufferList.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/BufferList.kt new file mode 100644 index 000000000..ff668589e --- /dev/null +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/BufferList.kt @@ -0,0 +1,81 @@ +/* + * Copyright 2018-2023 KMath contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package space.kscience.kmath.structures + +import kotlin.jvm.JvmInline + +@JvmInline +private value class BufferList(val buffer: Buffer) : List { + override val size: Int get() = buffer.size + + override fun get(index: Int): T = buffer[index] + + override fun isEmpty(): Boolean = buffer.size == 0 + + override fun iterator(): Iterator = buffer.iterator() + + override fun listIterator(index: Int): ListIterator = object : ListIterator { + var currentIndex = index + + override fun hasNext(): Boolean = currentIndex < buffer.size - 1 + + override fun hasPrevious(): Boolean = currentIndex > 0 + + override fun next(): T { + if (!hasNext()) throw NoSuchElementException() + return get(currentIndex++) + } + + override fun nextIndex(): Int = currentIndex + + override fun previous(): T { + if (!hasPrevious()) throw NoSuchElementException() + return get(--currentIndex) + } + + override fun previousIndex(): Int = currentIndex - 1 + + } + + override fun listIterator(): ListIterator = listIterator(0) + + override fun subList(fromIndex: Int, toIndex: Int): List = + buffer.slice(fromIndex..toIndex).asList() + + override fun lastIndexOf(element: T): Int { + for (i in buffer.indices.reversed()) { + if (buffer[i] == element) return i + } + return -1 + } + + override fun indexOf(element: T): Int { + for (i in buffer.indices) { + if (buffer[i] == element) return i + } + return -1 + } + + override fun containsAll(elements: Collection): Boolean { + val remainingElements = HashSet(elements) + for (e in buffer) { + if (e in remainingElements) { + remainingElements.remove(e) + } + if (remainingElements.isEmpty()) { + return true + } + } + return false + } + + override fun contains(element: T): Boolean = indexOf(element) >= 0 +} + +/** + * Returns a zero-copy list that reflects the content of the buffer. + */ +public fun Buffer.asList(): List = BufferList(this) \ No newline at end of file diff --git a/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/_generated.kt b/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/_generated.kt index 882df9536..3a44a9e64 100644 --- a/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/_generated.kt +++ b/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/_generated.kt @@ -24,8 +24,6 @@ import space.kscience.attributes.safeTypeOf import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.linear.* import space.kscience.kmath.linear.Matrix -import space.kscience.kmath.nd.Structure2D -import space.kscience.kmath.nd.StructureAttribute import space.kscience.kmath.nd.StructureFeature import space.kscience.kmath.operations.Float32Field import space.kscience.kmath.operations.Float64Field @@ -80,6 +78,7 @@ public class EjmlFloatMatrix(override val origin: M) : EjmlMatr } + /** * [EjmlLinearSpace] implementation based on [CommonOps_DDRM], [DecompositionFactory_DDRM] operations and * [DMatrixRMaj] matrices. @@ -218,18 +217,6 @@ public object EjmlLinearSpaceDDRM : EjmlLinearSpace): EjmlDoubleVector = v * this - override fun > computeAttribute(structure: Structure2D, attribute: A): V? { - val origin = structure.toEjml().origin - return when(attribute){ - Inverted -> { - val res = origin.copy() - CommonOps_DDRM.invert(res) - res.wrapMatrix() - } - else-> - } - } - @UnstableKMathAPI override fun computeFeature(structure: Matrix, type: KClass): F? { structure.getFeature(type)?.let { return it } @@ -330,7 +317,7 @@ public object EjmlLinearSpaceDDRM : EjmlLinearSpace Date: Fri, 5 Jan 2024 01:50:27 +0300 Subject: [PATCH 19/40] Update/Add copyright comments. Regenerate code for kmath-ejml. --- .../benchmarks/ExpressionsInterpretersBenchmark.kt | 2 +- .../kscience/kmath/benchmarks/ArrayBenchmark.kt | 2 +- .../kscience/kmath/benchmarks/BigIntBenchmark.kt | 2 +- .../kscience/kmath/benchmarks/BufferBenchmark.kt | 2 +- .../kscience/kmath/benchmarks/DotBenchmark.kt | 2 +- .../benchmarks/ExpressionsInterpretersBenchmark.kt | 2 +- .../kmath/benchmarks/IntegrationBenchmark.kt | 2 +- .../kscience/kmath/benchmarks/JafamaBenchmark.kt | 2 +- .../kmath/benchmarks/MatrixInverseBenchmark.kt | 2 +- .../kscience/kmath/benchmarks/NDFieldBenchmark.kt | 2 +- .../kmath/benchmarks/TensorAlgebraBenchmark.kt | 2 +- .../kscience/kmath/benchmarks/ViktorBenchmark.kt | 2 +- .../kmath/benchmarks/ViktorLogBenchmark.kt | 2 +- .../space/kscience/kmath/benchmarks/globals.kt | 2 +- .../space/kscience/kmath/benchmarks/JmhReport.kt | 2 +- .../kmath/benchmarks/addBenchmarkProperties.kt | 2 +- .../kscience/kmath/ejml/codegen/ejmlCodegen.kt | 6 +++--- docs/images/KM.svg | 2 +- docs/images/KM_mono.svg | 2 +- docs/images/KMath.svg | 2 +- docs/images/KMath_mono.svg | 2 +- .../space/kscience/kmath/ast/astRendering.kt | 2 +- .../kotlin/space/kscience/kmath/ast/expressions.kt | 2 +- .../space/kscience/kmath/ast/kotlingradSupport.kt | 2 +- .../space/kscience/kmath/ast/symjaSupport.kt | 2 +- .../space/kscience/kmath/expressions/autodiff.kt | 2 +- .../kotlin/space/kscience/kmath/fit/chiSquared.kt | 2 +- .../main/kotlin/space/kscience/kmath/fit/qowFit.kt | 2 +- .../space/kscience/kmath/functions/integrate.kt | 2 +- .../space/kscience/kmath/functions/interpolate.kt | 2 +- .../kscience/kmath/functions/interpolateSquare.kt | 2 +- .../kscience/kmath/functions/matrixIntegration.kt | 2 +- .../space/kscience/kmath/jafama/JafamaDemo.kt | 2 +- .../space/kscience/kmath/linear/dotPerformance.kt | 2 +- .../kotlin/space/kscience/kmath/linear/gradient.kt | 2 +- .../space/kscience/kmath/operations/BigIntDemo.kt | 2 +- .../space/kscience/kmath/operations/complexDemo.kt | 2 +- .../kscience/kmath/operations/mixedNDOperations.kt | 2 +- .../space/kscience/kmath/series/DateTimeSeries.kt | 2 +- .../space/kscience/kmath/series/analyzeDif.kt | 5 +++++ .../kscience/kmath/stat/DistributionBenchmark.kt | 2 +- .../space/kscience/kmath/stat/DistributionDemo.kt | 2 +- .../space/kscience/kmath/structures/ComplexND.kt | 2 +- .../space/kscience/kmath/structures/NDField.kt | 2 +- .../kmath/structures/StreamDoubleFieldND.kt | 2 +- .../kmath/structures/StructureReadBenchmark.kt | 2 +- .../kmath/structures/StructureWriteBenchmark.kt | 2 +- .../space/kscience/kmath/structures/buffers.kt | 2 +- .../kmath/structures/typeSafeDimensions.kt | 2 +- .../StaticLm/staticDifficultTest.kt | 2 +- .../LevenbergMarquardt/StaticLm/staticEasyTest.kt | 2 +- .../StaticLm/staticMiddleTest.kt | 2 +- .../LevenbergMarquardt/StreamingLm/streamLm.kt | 2 +- .../StreamingLm/streamingLmTest.kt | 2 +- .../LevenbergMarquardt/functionsToOptimize.kt | 2 +- .../space/kscience/kmath/tensors/OLSWithSVD.kt | 2 +- .../kotlin/space/kscience/kmath/tensors/PCA.kt | 2 +- .../kscience/kmath/tensors/dataSetNormalization.kt | 2 +- .../kmath/tensors/linearSystemSolvingWithLUP.kt | 2 +- .../kotlin/space/kscience/kmath/tensors/multik.kt | 2 +- .../space/kscience/kmath/tensors/neuralNetwork.kt | 2 +- .../kotlin/space/kscience/kmath/ast/TypedMst.kt | 2 +- .../space/kscience/kmath/ast/evaluateConstants.kt | 2 +- .../kotlin/space/kscience/kmath/ast/parser.kt | 2 +- .../kmath/ast/rendering/LatexSyntaxRenderer.kt | 2 +- .../kmath/ast/rendering/MathMLSyntaxRenderer.kt | 2 +- .../kscience/kmath/ast/rendering/MathRenderer.kt | 2 +- .../kscience/kmath/ast/rendering/MathSyntax.kt | 2 +- .../kscience/kmath/ast/rendering/SyntaxRenderer.kt | 2 +- .../space/kscience/kmath/ast/rendering/features.kt | 2 +- .../kmath/ast/rendering/multiplatformToString.kt | 2 +- .../space/kscience/kmath/ast/rendering/phases.kt | 2 +- .../ast/TestCompilerConsistencyWithInterpreter.kt | 2 +- .../kscience/kmath/ast/TestCompilerOperations.kt | 2 +- .../kscience/kmath/ast/TestCompilerVariables.kt | 2 +- .../kotlin/space/kscience/kmath/ast/TestFolding.kt | 2 +- .../kotlin/space/kscience/kmath/ast/TestParser.kt | 2 +- .../kscience/kmath/ast/TestParserPrecedence.kt | 2 +- .../kscience/kmath/ast/rendering/TestFeatures.kt | 2 +- .../kscience/kmath/ast/rendering/TestLatex.kt | 2 +- .../kscience/kmath/ast/rendering/TestMathML.kt | 2 +- .../kscience/kmath/ast/rendering/TestStages.kt | 2 +- .../kscience/kmath/ast/rendering/TestUtils.kt | 2 +- .../kotlin/space/kscience/kmath/ast/utils.kt | 2 +- .../kmath/ast/rendering/multiplatformToString.kt | 2 +- .../kotlin/space/kscience/kmath/estree/estree.kt | 2 +- .../kmath/estree/internal/ESTreeBuilder.kt | 2 +- .../estree/internal/astring/astring.typealises.kt | 2 +- .../kscience/kmath/internal/astring/astring.kt | 2 +- .../kmath/internal/astring/astring.typealises.kt | 2 +- .../space/kscience/kmath/internal/base64/base64.kt | 2 +- .../kmath/internal/binaryen/index.binaryen.kt | 2 +- .../binaryen/index.binaryen.typealiases.kt | 2 +- .../kscience/kmath/internal/emitter/emitter.kt | 2 +- .../kmath/internal/estree/estree.extensions.kt | 2 +- .../space/kscience/kmath/internal/estree/estree.kt | 2 +- .../space/kscience/kmath/internal/stream/stream.kt | 2 +- .../kmath/internal/tsstdlib/lib.es2015.iterable.kt | 2 +- .../kscience/kmath/internal/tsstdlib/lib.es5.kt | 2 +- .../lib.dom.WebAssembly.module_dukat.kt | 2 +- .../webassembly/nonDeclarations.WebAssembly.kt | 2 +- .../kscience/kmath/wasm/internal/WasmBuilder.kt | 2 +- .../kmath/wasm/internal/f64StandardFunctions.kt | 2 +- .../kotlin/space/kscience/kmath/wasm/wasm.kt | 2 +- .../kotlin/space/kscience/kmath/ast/utils.kt | 2 +- .../space/kscience/kmath/wasm/TestWasmSpecific.kt | 2 +- .../jvmMain/kotlin/space/kscience/kmath/asm/asm.kt | 2 +- .../kscience/kmath/asm/internal/AsmBuilder.kt | 2 +- .../kmath/asm/internal/GenericAsmBuilder.kt | 2 +- .../kmath/asm/internal/PrimitiveAsmBuilder.kt | 2 +- .../kscience/kmath/asm/internal/codegenUtils.kt | 2 +- .../kscience/kmath/asm/internal/mapIntrinsics.kt | 2 +- .../kmath/ast/rendering/multiplatformToString.kt | 2 +- .../kotlin/space/kscience/kmath/ast/utils.kt | 2 +- .../kmath/ast/rendering/multiplatformToString.kt | 2 +- .../space/kscience/kmath/ast/runCompilerTest.kt | 2 +- .../kmath/commons/expressions/CmDsExpression.kt | 2 +- .../commons/integration/CMGaussRuleIntegrator.kt | 2 +- .../kmath/commons/integration/CMIntegrator.kt | 2 +- .../kscience/kmath/commons/linear/CMMatrix.kt | 2 +- .../kscience/kmath/commons/linear/CMSolver.kt | 2 +- .../kmath/commons/optimization/CMOptimizer.kt | 2 +- .../commons/random/CMRandomGeneratorWrapper.kt | 2 +- .../kmath/commons/transform/Transformations.kt | 2 +- .../DerivativeStructureExpressionTest.kt | 2 +- .../kmath/commons/integration/IntegrationTest.kt | 2 +- .../kmath/commons/optimization/OptimizeTest.kt | 2 +- .../kotlin/space/kscience/kmath/complex/Complex.kt | 2 +- .../space/kscience/kmath/complex/ComplexFieldND.kt | 2 +- .../space/kscience/kmath/complex/Quaternion.kt | 2 +- .../kmath/complex/ComplexBufferSpecTest.kt | 2 +- .../kscience/kmath/complex/ComplexFieldTest.kt | 2 +- .../space/kscience/kmath/complex/ComplexTest.kt | 2 +- .../kmath/complex/ExpressionFieldForComplexTest.kt | 2 +- .../space/kscience/kmath/complex/QuaternionTest.kt | 2 +- .../space/kscience/kmath/data/ColumnarData.kt | 2 +- .../space/kscience/kmath/data/XYColumnarData.kt | 2 +- .../kscience/kmath/data/XYErrorColumnarData.kt | 2 +- .../space/kscience/kmath/data/XYZColumnarData.kt | 2 +- .../kotlin/space/kscience/kmath/domains/Domain.kt | 2 +- .../space/kscience/kmath/domains/Domain1D.kt | 2 +- .../space/kscience/kmath/domains/Float64Domain.kt | 2 +- .../kscience/kmath/domains/HyperSquareDomain.kt | 2 +- .../kscience/kmath/domains/UnconstrainedDomain.kt | 2 +- .../space/kscience/kmath/expressions/DSAlgebra.kt | 2 +- .../space/kscience/kmath/expressions/DSCompiler.kt | 2 +- .../kmath/expressions/DifferentiableExpression.kt | 2 +- .../space/kscience/kmath/expressions/Expression.kt | 2 +- .../kmath/expressions/ExpressionWithDefault.kt | 2 +- .../expressions/FunctionalExpressionAlgebra.kt | 2 +- .../kotlin/space/kscience/kmath/expressions/MST.kt | 2 +- .../space/kscience/kmath/expressions/MstAlgebra.kt | 2 +- .../kscience/kmath/expressions/NamedMatrix.kt | 2 +- .../kscience/kmath/expressions/SimpleAutoDiff.kt | 2 +- .../space/kscience/kmath/expressions/Symbol.kt | 2 +- .../kscience/kmath/expressions/SymbolIndexer.kt | 2 +- .../kscience/kmath/linear/BufferedLinearSpace.kt | 2 +- .../kscience/kmath/linear/Float64LinearSpace.kt | 2 +- .../space/kscience/kmath/linear/LinearSolver.kt | 2 +- .../space/kscience/kmath/linear/LinearSpace.kt | 2 +- .../kscience/kmath/linear/LupDecomposition.kt | 2 +- .../space/kscience/kmath/linear/MatrixBuilder.kt | 2 +- .../space/kscience/kmath/linear/MatrixFeatures.kt | 2 +- .../space/kscience/kmath/linear/MatrixWrapper.kt | 2 +- .../space/kscience/kmath/linear/VirtualMatrix.kt | 2 +- .../kotlin/space/kscience/kmath/misc/Featured.kt | 2 +- .../space/kscience/kmath/misc/collections.kt | 2 +- .../kotlin/space/kscience/kmath/misc/cumulative.kt | 2 +- .../kotlin/space/kscience/kmath/misc/logging.kt | 2 +- .../kotlin/space/kscience/kmath/misc/numbers.kt | 2 +- .../kotlin/space/kscience/kmath/misc/sorting.kt | 2 +- .../kotlin/space/kscience/kmath/nd/AlgebraND.kt | 2 +- .../space/kscience/kmath/nd/BufferAlgebraND.kt | 2 +- .../kotlin/space/kscience/kmath/nd/BufferND.kt | 2 +- .../space/kscience/kmath/nd/Float64FieldND.kt | 2 +- .../kotlin/space/kscience/kmath/nd/Int16RingND.kt | 2 +- .../kotlin/space/kscience/kmath/nd/IntRingND.kt | 2 +- .../space/kscience/kmath/nd/PermutedStructureND.kt | 2 +- .../kotlin/space/kscience/kmath/nd/ShapeIndices.kt | 2 +- .../kotlin/space/kscience/kmath/nd/ShapeND.kt | 2 +- .../kotlin/space/kscience/kmath/nd/Structure1D.kt | 2 +- .../kotlin/space/kscience/kmath/nd/Structure2D.kt | 2 +- .../kotlin/space/kscience/kmath/nd/StructureND.kt | 2 +- .../space/kscience/kmath/nd/VirtualStructureND.kt | 2 +- .../space/kscience/kmath/nd/algebraNDExtentions.kt | 2 +- .../kotlin/space/kscience/kmath/nd/operationsND.kt | 2 +- .../kscience/kmath/nd/primitiveStructureND.kt | 2 +- .../space/kscience/kmath/operations/Algebra.kt | 2 +- .../space/kscience/kmath/operations/BigInt.kt | 2 +- .../kscience/kmath/operations/BufferAlgebra.kt | 2 +- .../kmath/operations/Float64BufferField.kt | 2 +- .../kscience/kmath/operations/Float64BufferOps.kt | 2 +- .../kscience/kmath/operations/LogicAlgebra.kt | 2 +- .../kscience/kmath/operations/NumericAlgebra.kt | 2 +- .../kmath/operations/OptionalOperations.kt | 2 +- .../kscience/kmath/operations/algebraExtensions.kt | 2 +- .../kscience/kmath/operations/integerFields.kt | 2 +- .../space/kscience/kmath/operations/numbers.kt | 2 +- .../space/kscience/kmath/structures/ArrayBuffer.kt | 2 +- .../space/kscience/kmath/structures/Buffer.kt | 2 +- .../kscience/kmath/structures/BufferAccessor2D.kt | 2 +- .../space/kscience/kmath/structures/BufferView.kt | 5 +++++ .../kscience/kmath/structures/FlaggedBuffer.kt | 2 +- .../kscience/kmath/structures/Float32Buffer.kt | 2 +- .../kscience/kmath/structures/Float64Buffer.kt | 2 +- .../space/kscience/kmath/structures/Int16Buffer.kt | 2 +- .../space/kscience/kmath/structures/Int32Buffer.kt | 2 +- .../space/kscience/kmath/structures/Int64Buffer.kt | 2 +- .../space/kscience/kmath/structures/Int8Buffer.kt | 2 +- .../space/kscience/kmath/structures/ListBuffer.kt | 2 +- .../kscience/kmath/structures/MemoryBuffer.kt | 2 +- .../kscience/kmath/structures/MutableBuffer.kt | 2 +- .../kscience/kmath/structures/bufferExtensions.kt | 2 +- .../kmath/structures/bufferPrimitiveAccess.kt | 5 +++++ .../space/kscience/kmath/structures/types.kt | 2 +- .../space/kscience/kmath/expressions/DSTest.kt | 2 +- .../kmath/expressions/ExpressionFieldTest.kt | 2 +- .../kscience/kmath/expressions/InterpretTest.kt | 2 +- .../kmath/expressions/SimpleAutoDiffTest.kt | 2 +- .../kscience/kmath/linear/DoubleLUSolverTest.kt | 2 +- .../space/kscience/kmath/linear/MatrixTest.kt | 2 +- .../space/kscience/kmath/misc/CumulativeKtTest.kt | 2 +- .../space/kscience/kmath/misc/PermSortTest.kt | 2 +- .../space/kscience/kmath/nd/NdOperationsTest.kt | 2 +- .../kotlin/space/kscience/kmath/nd/StridesTest.kt | 2 +- .../kscience/kmath/operations/BigIntAlgebraTest.kt | 2 +- .../kmath/operations/BigIntConstructorTest.kt | 2 +- .../kmath/operations/BigIntConversionsTest.kt | 2 +- .../kmath/operations/BigIntOperationsTest.kt | 2 +- .../kscience/kmath/operations/DoubleFieldTest.kt | 2 +- .../kmath/structures/BufferExpandedTest.kt | 5 +++++ .../space/kscience/kmath/structures/NDFieldTest.kt | 2 +- .../kscience/kmath/structures/NumberNDFieldTest.kt | 2 +- .../kotlin/space/kscience/kmath/misc/numbers.kt | 2 +- .../space/kscience/kmath/operations/isInteger.kt | 2 +- .../kotlin/space/kscience/kmath/misc/numbersJVM.kt | 2 +- .../space/kscience/kmath/operations/BigNumbers.kt | 2 +- .../space/kscience/kmath/operations/isInteger.kt | 2 +- .../kotlin/space/kscience/kmath/misc/JBigTest.kt | 2 +- .../kotlin/space/kscience/kmath/misc/numbers.kt | 2 +- .../space/kscience/kmath/operations/isInteger.kt | 2 +- .../kotlin/space/kscience/kmath/misc/numbers.kt | 2 +- .../space/kscience/kmath/operations/isInteger.kt | 2 +- .../space/kscience/kmath/chains/BlockingChain.kt | 2 +- .../kscience/kmath/chains/BlockingDoubleChain.kt | 2 +- .../kscience/kmath/chains/BlockingIntChain.kt | 2 +- .../kotlin/space/kscience/kmath/chains/Chain.kt | 2 +- .../space/kscience/kmath/chains/flowExtra.kt | 2 +- .../kscience/kmath/coroutines/coroutinesExtra.kt | 2 +- .../space/kscience/kmath/streaming/BufferFlow.kt | 2 +- .../space/kscience/kmath/streaming/RingBuffer.kt | 2 +- .../kotlin/space/kscience/kmath/chains/ChainExt.kt | 2 +- .../kscience/kmath/structures/LazyStructureND.kt | 2 +- .../kscience/kmath/streaming/BufferFlowTest.kt | 2 +- .../kscience/kmath/streaming/RingBufferTest.kt | 2 +- .../space/kscience/kmath/dimensions/Dimension.kt | 2 +- .../space/kscience/kmath/dimensions/Wrappers.kt | 2 +- .../kscience/dimensions/DMatrixContextTest.kt | 2 +- .../space/kscience/kmath/dimensions/Dimension.kt | 2 +- .../space/kscience/kmath/dimensions/Dimension.kt | 2 +- .../space/kscience/kmath/dimensions/Dimension.kt | 2 +- .../space/kscience/kmath/ejml/EjmlLinearSpace.kt | 2 +- .../kotlin/space/kscience/kmath/ejml/EjmlMatrix.kt | 2 +- .../kotlin/space/kscience/kmath/ejml/EjmlVector.kt | 2 +- .../kotlin/space/kscience/kmath/ejml/_generated.kt | 14 ++++++++++---- .../space/kscience/kmath/ejml/EjmlMatrixTest.kt | 2 +- .../space/kscience/kmath/ejml/EjmlVectorTest.kt | 2 +- .../space/kscience/kmath/real/DoubleVector.kt | 2 +- .../kotlin/space/kscience/kmath/real/RealMatrix.kt | 2 +- .../kotlin/space/kscience/kmath/real/dot.kt | 2 +- .../kotlin/space/kscience/kmath/real/grids.kt | 2 +- .../kotlin/space/kscience/kmath/real/realND.kt | 2 +- .../space/kscience/kmath/real/DoubleMatrixTest.kt | 2 +- .../space/kscience/kmath/real/DoubleVectorTest.kt | 2 +- .../kotlin/space/kscience/kmath/real/GridTest.kt | 2 +- .../space/kscience/kmath/functions/Piecewise.kt | 2 +- .../space/kscience/kmath/functions/Polynomial.kt | 2 +- .../kscience/kmath/functions/functionTypes.kt | 2 +- .../kmath/functions/polynomialConstructors.kt | 2 +- .../kscience/kmath/functions/polynomialUtil.kt | 2 +- .../kscience/kmath/integration/GaussIntegrator.kt | 2 +- .../integration/GaussIntegratorRuleFactory.kt | 2 +- .../space/kscience/kmath/integration/Integrand.kt | 2 +- .../space/kscience/kmath/integration/Integrator.kt | 2 +- .../kmath/integration/MultivariateIntegrand.kt | 2 +- .../kmath/integration/SimpsonIntegrator.kt | 2 +- .../kscience/kmath/integration/SplineIntegrator.kt | 2 +- .../kmath/integration/UnivariateIntegrand.kt | 2 +- .../kscience/kmath/interpolation/Interpolator.kt | 2 +- .../kmath/interpolation/LinearInterpolator.kt | 2 +- .../kmath/interpolation/SplineInterpolator.kt | 2 +- .../kscience/kmath/functions/PolynomialTest.kt | 2 +- .../kscience/kmath/functions/PolynomialUtilTest.kt | 2 +- .../kmath/functions/testUtils/IntModulo.kt | 2 +- .../kmath/functions/testUtils/IntModuloUtils.kt | 2 +- .../kscience/kmath/functions/testUtils/Rational.kt | 2 +- .../kscience/kmath/functions/testUtils/misc.kt | 2 +- .../kmath/integration/GaussIntegralTest.kt | 2 +- .../kmath/integration/SimpsonIntegralTest.kt | 2 +- .../kmath/integration/SplineIntegralTest.kt | 2 +- .../kmath/interpolation/LinearInterpolatorTest.kt | 2 +- .../kmath/interpolation/SplineInterpolatorTest.kt | 2 +- .../space/kscience/kmath/geometry/GeometrySpace.kt | 2 +- .../kotlin/space/kscience/kmath/geometry/Line.kt | 2 +- .../kscience/kmath/geometry/ReferenceFrame.kt | 2 +- .../space/kscience/kmath/geometry/Vector2D.kt | 2 +- .../space/kscience/kmath/geometry/Vector3D.kt | 2 +- .../kotlin/space/kscience/kmath/geometry/angles.kt | 2 +- .../kmath/geometry/euclidean2d/Circle2D.kt | 2 +- .../kmath/geometry/euclidean2d/Float32Space2D.kt | 2 +- .../kmath/geometry/euclidean2d/Float64Space2D.kt | 2 +- .../kscience/kmath/geometry/euclidean2d/Polygon.kt | 2 +- .../kmath/geometry/euclidean3d/Float32Space3D.kt | 2 +- .../kmath/geometry/euclidean3d/Float64Space3D.kt | 2 +- .../kmath/geometry/euclidean3d/rotations3D.kt | 2 +- .../kscience/kmath/geometry/floatPrecision.kt | 2 +- .../space/kscience/kmath/geometry/projections.kt | 2 +- .../kmath/geometry/quaternionOperations.kt | 2 +- .../space/kscience/kmath/geometry/AngleTest.kt | 5 +++++ .../kmath/geometry/Euclidean2DSpaceTest.kt | 2 +- .../kmath/geometry/Euclidean3DSpaceTest.kt | 2 +- .../kscience/kmath/geometry/ProjectionAlongTest.kt | 2 +- .../kmath/geometry/ProjectionOntoLineTest.kt | 2 +- .../space/kscience/kmath/geometry/RotationTest.kt | 2 +- .../space/kscience/kmath/geometry/Vector2DTest.kt | 2 +- .../space/kscience/kmath/geometry/Vector3DTest.kt | 2 +- .../space/kscience/kmath/geometry/testUtils.kt | 2 +- .../kscience/kmath/geometry/lineExtensions.kt | 2 +- .../space/kscience/kmath/histogram/Counter.kt | 2 +- .../space/kscience/kmath/histogram/Histogram.kt | 2 +- .../space/kscience/kmath/histogram/Histogram1D.kt | 2 +- .../space/kscience/kmath/histogram/HistogramND.kt | 2 +- .../kscience/kmath/histogram/UniformHistogram1D.kt | 2 +- .../kmath/histogram/UniformHistogramGroupND.kt | 2 +- .../kmath/histogram/MultivariateHistogramTest.kt | 2 +- .../kmath/histogram/UniformHistogram1DTest.kt | 2 +- .../kscience/kmath/histogram/TreeHistogramGroup.kt | 2 +- .../kscience/kmath/histogram/TreeHistogramTest.kt | 2 +- .../space/kscience/kmath/jafama/KMathJafama.kt | 2 +- .../space/kscience/kmath/jupyter/KMathJupyter.kt | 2 +- .../space/kscience/kmath/kotlingrad/KMathNumber.kt | 2 +- .../kmath/kotlingrad/KotlingradExpression.kt | 2 +- .../kscience/kmath/kotlingrad/scalarsAdapters.kt | 2 +- .../kscience/kmath/kotlingrad/AdaptingTests.kt | 2 +- .../kotlin/space/kscience/kmath/annotations.kt | 2 +- .../kotlin/space/kscience/kmath/memory/Memory.kt | 2 +- .../space/kscience/kmath/memory/MemorySpec.kt | 2 +- .../space/kscience/kmath/memory/MemoryTest.kt | 2 +- .../space/kscience/kmath/memory/DataViewMemory.kt | 2 +- .../kscience/kmath/memory/ByteBufferMemory.kt | 2 +- .../space/kscience/kmath/memory/NativeMemory.kt | 2 +- .../kscience/kmath/memory/WasmDataViewMemory.kt | 2 +- .../kscience/kmath/multik/MultikDoubleAlgebra.kt | 2 +- .../kscience/kmath/multik/MultikFloatAlgebra.kt | 2 +- .../kscience/kmath/multik/MultikIntAlgebra.kt | 2 +- .../kscience/kmath/multik/MultikLongAlgebra.kt | 2 +- .../kscience/kmath/multik/MultikShortAlgebra.kt | 2 +- .../space/kscience/kmath/multik/MultikTensor.kt | 2 +- .../kscience/kmath/multik/MultikTensorAlgebra.kt | 2 +- .../space/kscience/kmath/multik/MultikNDTest.kt | 2 +- .../space/kscience/kmath/nd4j/Nd4jArrayAlgebra.kt | 2 +- .../space/kscience/kmath/nd4j/Nd4jArrayIterator.kt | 2 +- .../kscience/kmath/nd4j/Nd4jArrayStructure.kt | 2 +- .../space/kscience/kmath/nd4j/Nd4jTensorAlgebra.kt | 2 +- .../kotlin/space/kscience/kmath/nd4j/arrays.kt | 2 +- .../kscience/kmath/nd4j/Nd4jArrayAlgebraTest.kt | 2 +- .../kscience/kmath/nd4j/Nd4jArrayStructureTest.kt | 2 +- .../kmath/optimization/FunctionOptimization.kt | 2 +- .../kmath/optimization/OptimizationBuilder.kt | 2 +- .../kmath/optimization/OptimizationProblem.kt | 2 +- .../space/kscience/kmath/optimization/Optimizer.kt | 2 +- .../kscience/kmath/optimization/QowOptimizer.kt | 2 +- .../space/kscience/kmath/optimization/XYFit.kt | 2 +- .../kscience/kmath/optimization/logLikelihood.kt | 2 +- .../kscience/kmath/distributions/Distribution.kt | 2 +- .../kmath/distributions/FactorizedDistribution.kt | 2 +- .../kmath/distributions/NormalDistribution.kt | 2 +- .../kmath/distributions/UniformDistribution.kt | 2 +- .../kotlin/space/kscience/kmath/random/MCScope.kt | 2 +- .../space/kscience/kmath/random/RandomChain.kt | 2 +- .../space/kscience/kmath/random/RandomGenerator.kt | 2 +- .../samplers/AhrensDieterExponentialSampler.kt | 2 +- .../AhrensDieterMarsagliaTsangGammaSampler.kt | 2 +- .../kmath/samplers/AliasMethodDiscreteSampler.kt | 2 +- .../kscience/kmath/samplers/BoxMullerSampler.kt | 2 +- .../kscience/kmath/samplers/GaussianSampler.kt | 2 +- .../space/kscience/kmath/samplers/InternalErf.kt | 2 +- .../space/kscience/kmath/samplers/InternalGamma.kt | 2 +- .../space/kscience/kmath/samplers/InternalUtils.kt | 2 +- .../kmath/samplers/KempSmallMeanPoissonSampler.kt | 2 +- .../samplers/MarsagliaNormalizedGaussianSampler.kt | 2 +- .../kmath/samplers/NormalizedGaussianSampler.kt | 2 +- .../kscience/kmath/samplers/PoissonSampler.kt | 2 +- .../space/kscience/kmath/samplers/Sampler.kt | 2 +- .../kscience/kmath/samplers/SamplerAlgebra.kt | 2 +- .../samplers/ZigguratNormalizedGaussianSampler.kt | 2 +- .../kmath/series/MonotonicSeriesAlgebra.kt | 2 +- .../space/kscience/kmath/series/SeriesAlgebra.kt | 5 +++++ .../kscience/kmath/series/VarianceRatioTest.kt | 2 +- .../space/kscience/kmath/series/resampling.kt | 2 +- .../kscience/kmath/series/seriesExtensions.kt | 5 +++++ .../kotlin/space/kscience/kmath/stat/Mean.kt | 2 +- .../kotlin/space/kscience/kmath/stat/Median.kt | 2 +- .../kotlin/space/kscience/kmath/stat/Rank.kt | 5 +++++ .../kotlin/space/kscience/kmath/stat/Statistic.kt | 2 +- .../kscience/kmath/stat/StatisticalAlgebra.kt | 5 +++++ .../kscience/kmath/stat/ValueAndErrorField.kt | 2 +- .../kscience/kmath/stat/chiSquaredExpression.kt | 2 +- .../space/kscience/kmath/series/TestSeries.kt | 2 +- .../kscience/kmath/series/TestVarianceRatioTest.kt | 2 +- .../kscience/kmath/stat/TestBasicStatistics.kt | 2 +- .../kscience/kmath/stat/RandomSourceGenerator.kt | 2 +- .../kmath/stat/CommonsDistributionsTest.kt | 2 +- .../space/kscience/kmath/stat/MCScopeTest.kt | 2 +- .../space/kscience/kmath/stat/SamplerTest.kt | 2 +- .../space/kscience/kmath/stat/StatisticTest.kt | 2 +- .../space/kscience/kmath/symja/SymjaExpression.kt | 2 +- .../kotlin/space/kscience/kmath/symja/adapters.kt | 2 +- .../kmath/tensorflow/DoubleTensorFlowAlgebra.kt | 2 +- .../kmath/tensorflow/IntTensorFlowAlgebra.kt | 2 +- .../kscience/kmath/tensorflow/TensorFlowAlgebra.kt | 2 +- .../kscience/kmath/tensorflow/tfOperations.kt | 2 +- .../kmath/tensorflow/DoubleTensorFlowOps.kt | 2 +- .../kmath/tensors/api/AnalyticTensorAlgebra.kt | 2 +- .../kmath/tensors/api/LinearOpsTensorAlgebra.kt | 2 +- .../space/kscience/kmath/tensors/api/Tensor.kt | 2 +- .../kscience/kmath/tensors/api/TensorAlgebra.kt | 2 +- .../tensors/api/TensorPartialDivisionAlgebra.kt | 2 +- .../tensors/core/BroadcastDoubleTensorAlgebra.kt | 2 +- .../kscience/kmath/tensors/core/BufferedTensor.kt | 2 +- .../kscience/kmath/tensors/core/DoubleTensor.kt | 2 +- .../kscience/kmath/tensors/core/DoubleTensor1D.kt | 2 +- .../kscience/kmath/tensors/core/DoubleTensor2D.kt | 2 +- .../kmath/tensors/core/DoubleTensorAlgebra.kt | 2 +- .../space/kscience/kmath/tensors/core/IntTensor.kt | 2 +- .../kmath/tensors/core/IntTensorAlgebra.kt | 2 +- .../tensors/core/LevenbergMarquardtAlgorithm.kt | 2 +- .../kmath/tensors/core/internal/broadcastUtils.kt | 2 +- .../kscience/kmath/tensors/core/internal/checks.kt | 2 +- .../tensors/core/internal/doubleTensorHelpers.kt | 2 +- .../tensors/core/internal/intTensorHelpers.kt | 2 +- .../kmath/tensors/core/internal/linUtils.kt | 2 +- .../kscience/kmath/tensors/core/internal/utils.kt | 2 +- .../kmath/tensors/core/tensorAlgebraExtensions.kt | 2 +- .../space/kscience/kmath/tensors/core/tensorOps.kt | 2 +- .../kscience/kmath/tensors/core/tensorTransform.kt | 2 +- .../kmath/tensors/core/TestBroadcasting.kt | 2 +- .../core/TestDoubleAnalyticTensorAlgebra.kt | 2 +- .../tensors/core/TestDoubleLinearOpsAlgebra.kt | 2 +- .../kmath/tensors/core/TestDoubleTensor.kt | 2 +- .../kmath/tensors/core/TestDoubleTensorAlgebra.kt | 2 +- .../kmath/tensors/core/offsetBufferEquality.kt | 2 +- .../kscience/kmath/tensors/core/TestLmAlgorithm.kt | 2 +- .../space/kscience/kmath/viktor/ViktorBuffer.kt | 2 +- .../kscience/kmath/viktor/ViktorFieldOpsND.kt | 2 +- .../kscience/kmath/viktor/ViktorStructureND.kt | 2 +- .../src/commonMain/kotlin/AlgebraicVerifier.kt | 2 +- test-utils/src/commonMain/kotlin/FieldVerifier.kt | 2 +- test-utils/src/commonMain/kotlin/RingVerifier.kt | 2 +- test-utils/src/commonMain/kotlin/SpaceVerifier.kt | 2 +- test-utils/src/commonMain/kotlin/asserts.kt | 2 +- test-utils/src/commonMain/kotlin/bufferEquality.kt | 2 +- 462 files changed, 509 insertions(+), 458 deletions(-) diff --git a/benchmarks/src/jsMain/kotlin/space/kscience/kmath/benchmarks/ExpressionsInterpretersBenchmark.kt b/benchmarks/src/jsMain/kotlin/space/kscience/kmath/benchmarks/ExpressionsInterpretersBenchmark.kt index a3cfce52f..d930c90c0 100644 --- a/benchmarks/src/jsMain/kotlin/space/kscience/kmath/benchmarks/ExpressionsInterpretersBenchmark.kt +++ b/benchmarks/src/jsMain/kotlin/space/kscience/kmath/benchmarks/ExpressionsInterpretersBenchmark.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/ArrayBenchmark.kt b/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/ArrayBenchmark.kt index abfc8cbf2..f04f0a46d 100644 --- a/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/ArrayBenchmark.kt +++ b/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/ArrayBenchmark.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/BigIntBenchmark.kt b/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/BigIntBenchmark.kt index d07b7b4df..a67f52b67 100644 --- a/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/BigIntBenchmark.kt +++ b/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/BigIntBenchmark.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/BufferBenchmark.kt b/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/BufferBenchmark.kt index 1675216eb..9f665709c 100644 --- a/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/BufferBenchmark.kt +++ b/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/BufferBenchmark.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/DotBenchmark.kt b/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/DotBenchmark.kt index 5784c32b1..51be23192 100644 --- a/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/DotBenchmark.kt +++ b/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/DotBenchmark.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/ExpressionsInterpretersBenchmark.kt b/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/ExpressionsInterpretersBenchmark.kt index def90ba22..45b3916dc 100644 --- a/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/ExpressionsInterpretersBenchmark.kt +++ b/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/ExpressionsInterpretersBenchmark.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/IntegrationBenchmark.kt b/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/IntegrationBenchmark.kt index 6cc649fe9..021c654a1 100644 --- a/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/IntegrationBenchmark.kt +++ b/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/IntegrationBenchmark.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2023 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/JafamaBenchmark.kt b/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/JafamaBenchmark.kt index 355f54c65..69479200d 100644 --- a/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/JafamaBenchmark.kt +++ b/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/JafamaBenchmark.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/MatrixInverseBenchmark.kt b/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/MatrixInverseBenchmark.kt index f7aac8199..d8052a9dc 100644 --- a/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/MatrixInverseBenchmark.kt +++ b/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/MatrixInverseBenchmark.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/NDFieldBenchmark.kt b/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/NDFieldBenchmark.kt index ec7f940a0..297dce8b9 100644 --- a/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/NDFieldBenchmark.kt +++ b/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/NDFieldBenchmark.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/TensorAlgebraBenchmark.kt b/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/TensorAlgebraBenchmark.kt index 8bdb101f6..64efaf640 100644 --- a/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/TensorAlgebraBenchmark.kt +++ b/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/TensorAlgebraBenchmark.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/ViktorBenchmark.kt b/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/ViktorBenchmark.kt index b424491f6..bd5c2006a 100644 --- a/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/ViktorBenchmark.kt +++ b/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/ViktorBenchmark.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/ViktorLogBenchmark.kt b/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/ViktorLogBenchmark.kt index b6a485821..65d159e54 100644 --- a/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/ViktorLogBenchmark.kt +++ b/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/ViktorLogBenchmark.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/globals.kt b/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/globals.kt index f6d278d83..ff5157f81 100644 --- a/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/globals.kt +++ b/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/globals.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/buildSrc/src/main/kotlin/space/kscience/kmath/benchmarks/JmhReport.kt b/buildSrc/src/main/kotlin/space/kscience/kmath/benchmarks/JmhReport.kt index 3a4fcdc79..98778e009 100644 --- a/buildSrc/src/main/kotlin/space/kscience/kmath/benchmarks/JmhReport.kt +++ b/buildSrc/src/main/kotlin/space/kscience/kmath/benchmarks/JmhReport.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/buildSrc/src/main/kotlin/space/kscience/kmath/benchmarks/addBenchmarkProperties.kt b/buildSrc/src/main/kotlin/space/kscience/kmath/benchmarks/addBenchmarkProperties.kt index 83cb786e3..fc04c82cf 100644 --- a/buildSrc/src/main/kotlin/space/kscience/kmath/benchmarks/addBenchmarkProperties.kt +++ b/buildSrc/src/main/kotlin/space/kscience/kmath/benchmarks/addBenchmarkProperties.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/buildSrc/src/main/kotlin/space/kscience/kmath/ejml/codegen/ejmlCodegen.kt b/buildSrc/src/main/kotlin/space/kscience/kmath/ejml/codegen/ejmlCodegen.kt index 41b88f093..3c24c24cb 100644 --- a/buildSrc/src/main/kotlin/space/kscience/kmath/ejml/codegen/ejmlCodegen.kt +++ b/buildSrc/src/main/kotlin/space/kscience/kmath/ejml/codegen/ejmlCodegen.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -363,8 +363,8 @@ fun ejmlCodegen(outputFile: String): Unit = File(outputFile).run { writer().use { it.appendLine("/*") - it.appendLine(" * Copyright 2018-2021 KMath contributors.") - it.appendLine(" * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.") + it.appendLine(" * Copyright 2018-2024 KMath contributors.") + it.appendLine(" * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.") it.appendLine(" */") it.appendLine() it.appendLine("/* This file is generated with buildSrc/src/main/kotlin/space/kscience/kmath/ejml/codegen/ejmlCodegen.kt */") diff --git a/docs/images/KM.svg b/docs/images/KM.svg index 55a4339b1..f9003c5bb 100644 --- a/docs/images/KM.svg +++ b/docs/images/KM.svg @@ -1,6 +1,6 @@ diff --git a/docs/images/KM_mono.svg b/docs/images/KM_mono.svg index f1194f887..057968d0e 100644 --- a/docs/images/KM_mono.svg +++ b/docs/images/KM_mono.svg @@ -1,6 +1,6 @@ diff --git a/docs/images/KMath.svg b/docs/images/KMath.svg index 509a184bc..4e1e8a783 100644 --- a/docs/images/KMath.svg +++ b/docs/images/KMath.svg @@ -1,6 +1,6 @@ diff --git a/docs/images/KMath_mono.svg b/docs/images/KMath_mono.svg index e781979e2..5b93d45b7 100644 --- a/docs/images/KMath_mono.svg +++ b/docs/images/KMath_mono.svg @@ -1,6 +1,6 @@ diff --git a/examples/src/main/kotlin/space/kscience/kmath/ast/astRendering.kt b/examples/src/main/kotlin/space/kscience/kmath/ast/astRendering.kt index e85bab8d8..d792a4ec6 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/ast/astRendering.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/ast/astRendering.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ 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 784fed63e..a8150eb83 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/ast/expressions.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/ast/expressions.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ 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 f7b169e0b..fc6cbb752 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/ast/kotlingradSupport.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/ast/kotlingradSupport.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/examples/src/main/kotlin/space/kscience/kmath/ast/symjaSupport.kt b/examples/src/main/kotlin/space/kscience/kmath/ast/symjaSupport.kt index 9a4300f82..549b96cf1 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/ast/symjaSupport.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/ast/symjaSupport.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/examples/src/main/kotlin/space/kscience/kmath/expressions/autodiff.kt b/examples/src/main/kotlin/space/kscience/kmath/expressions/autodiff.kt index 863d6be7a..7bcb80da0 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/expressions/autodiff.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/expressions/autodiff.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2023 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/examples/src/main/kotlin/space/kscience/kmath/fit/chiSquared.kt b/examples/src/main/kotlin/space/kscience/kmath/fit/chiSquared.kt index 258ed0c84..be4982d59 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/fit/chiSquared.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/fit/chiSquared.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/examples/src/main/kotlin/space/kscience/kmath/fit/qowFit.kt b/examples/src/main/kotlin/space/kscience/kmath/fit/qowFit.kt index fe7f48b72..0a0626149 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/fit/qowFit.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/fit/qowFit.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/examples/src/main/kotlin/space/kscience/kmath/functions/integrate.kt b/examples/src/main/kotlin/space/kscience/kmath/functions/integrate.kt index 493a89387..07bacc45d 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/functions/integrate.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/functions/integrate.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/examples/src/main/kotlin/space/kscience/kmath/functions/interpolate.kt b/examples/src/main/kotlin/space/kscience/kmath/functions/interpolate.kt index 6908eebdd..817f33dbe 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/functions/interpolate.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/functions/interpolate.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/examples/src/main/kotlin/space/kscience/kmath/functions/interpolateSquare.kt b/examples/src/main/kotlin/space/kscience/kmath/functions/interpolateSquare.kt index e621cda08..29a40498b 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/functions/interpolateSquare.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/functions/interpolateSquare.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/examples/src/main/kotlin/space/kscience/kmath/functions/matrixIntegration.kt b/examples/src/main/kotlin/space/kscience/kmath/functions/matrixIntegration.kt index baba2eb28..0680f42b0 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/functions/matrixIntegration.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/functions/matrixIntegration.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/examples/src/main/kotlin/space/kscience/kmath/jafama/JafamaDemo.kt b/examples/src/main/kotlin/space/kscience/kmath/jafama/JafamaDemo.kt index 52451e9f3..b4afa37e4 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/jafama/JafamaDemo.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/jafama/JafamaDemo.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/examples/src/main/kotlin/space/kscience/kmath/linear/dotPerformance.kt b/examples/src/main/kotlin/space/kscience/kmath/linear/dotPerformance.kt index 79eddc6c3..8874ca685 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/linear/dotPerformance.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/linear/dotPerformance.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ 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 eb170e7fa..6ebd1d221 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/linear/gradient.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/linear/gradient.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/examples/src/main/kotlin/space/kscience/kmath/operations/BigIntDemo.kt b/examples/src/main/kotlin/space/kscience/kmath/operations/BigIntDemo.kt index 2447d06ed..903388c2f 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/operations/BigIntDemo.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/operations/BigIntDemo.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/examples/src/main/kotlin/space/kscience/kmath/operations/complexDemo.kt b/examples/src/main/kotlin/space/kscience/kmath/operations/complexDemo.kt index 77cfca4ae..a9c363dd6 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/operations/complexDemo.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/operations/complexDemo.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/examples/src/main/kotlin/space/kscience/kmath/operations/mixedNDOperations.kt b/examples/src/main/kotlin/space/kscience/kmath/operations/mixedNDOperations.kt index bb69c6aff..4df577b8b 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/operations/mixedNDOperations.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/operations/mixedNDOperations.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/examples/src/main/kotlin/space/kscience/kmath/series/DateTimeSeries.kt b/examples/src/main/kotlin/space/kscience/kmath/series/DateTimeSeries.kt index ca10fc290..35435b64e 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/series/DateTimeSeries.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/series/DateTimeSeries.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2023 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/examples/src/main/kotlin/space/kscience/kmath/series/analyzeDif.kt b/examples/src/main/kotlin/space/kscience/kmath/series/analyzeDif.kt index 0e10f1a9a..ca3754c8a 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/series/analyzeDif.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/series/analyzeDif.kt @@ -1,3 +1,8 @@ +/* + * Copyright 2018-2024 KMath contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + package space.kscience.kmath.series diff --git a/examples/src/main/kotlin/space/kscience/kmath/stat/DistributionBenchmark.kt b/examples/src/main/kotlin/space/kscience/kmath/stat/DistributionBenchmark.kt index 031955e15..19b763113 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/stat/DistributionBenchmark.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/stat/DistributionBenchmark.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/examples/src/main/kotlin/space/kscience/kmath/stat/DistributionDemo.kt b/examples/src/main/kotlin/space/kscience/kmath/stat/DistributionDemo.kt index 8e6d096ed..2f8e9d959 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/stat/DistributionDemo.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/stat/DistributionDemo.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/examples/src/main/kotlin/space/kscience/kmath/structures/ComplexND.kt b/examples/src/main/kotlin/space/kscience/kmath/structures/ComplexND.kt index f71f248d9..c97ba8383 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/structures/ComplexND.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/structures/ComplexND.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ 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 375d4e182..9ec8719ad 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/structures/NDField.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/structures/NDField.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/examples/src/main/kotlin/space/kscience/kmath/structures/StreamDoubleFieldND.kt b/examples/src/main/kotlin/space/kscience/kmath/structures/StreamDoubleFieldND.kt index a0e25b81b..4097b7283 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/structures/StreamDoubleFieldND.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/structures/StreamDoubleFieldND.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ 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 1e50ef7da..4d52c4258 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/structures/StructureReadBenchmark.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/structures/StructureReadBenchmark.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ 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 4aa7b74dd..9304e9f4c 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/structures/StructureWriteBenchmark.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/structures/StructureWriteBenchmark.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/examples/src/main/kotlin/space/kscience/kmath/structures/buffers.kt b/examples/src/main/kotlin/space/kscience/kmath/structures/buffers.kt index 8785fa6f2..aafd43fd9 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/structures/buffers.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/structures/buffers.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/examples/src/main/kotlin/space/kscience/kmath/structures/typeSafeDimensions.kt b/examples/src/main/kotlin/space/kscience/kmath/structures/typeSafeDimensions.kt index 1ba0e3503..06f1a21c8 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/structures/typeSafeDimensions.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/structures/typeSafeDimensions.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/examples/src/main/kotlin/space/kscience/kmath/tensors/LevenbergMarquardt/StaticLm/staticDifficultTest.kt b/examples/src/main/kotlin/space/kscience/kmath/tensors/LevenbergMarquardt/StaticLm/staticDifficultTest.kt index e6f575262..a6903baca 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/tensors/LevenbergMarquardt/StaticLm/staticDifficultTest.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/tensors/LevenbergMarquardt/StaticLm/staticDifficultTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2023 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/examples/src/main/kotlin/space/kscience/kmath/tensors/LevenbergMarquardt/StaticLm/staticEasyTest.kt b/examples/src/main/kotlin/space/kscience/kmath/tensors/LevenbergMarquardt/StaticLm/staticEasyTest.kt index 507943031..ab50d17e1 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/tensors/LevenbergMarquardt/StaticLm/staticEasyTest.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/tensors/LevenbergMarquardt/StaticLm/staticEasyTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2023 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/examples/src/main/kotlin/space/kscience/kmath/tensors/LevenbergMarquardt/StaticLm/staticMiddleTest.kt b/examples/src/main/kotlin/space/kscience/kmath/tensors/LevenbergMarquardt/StaticLm/staticMiddleTest.kt index 0659db103..aa8aa73f8 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/tensors/LevenbergMarquardt/StaticLm/staticMiddleTest.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/tensors/LevenbergMarquardt/StaticLm/staticMiddleTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2023 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/examples/src/main/kotlin/space/kscience/kmath/tensors/LevenbergMarquardt/StreamingLm/streamLm.kt b/examples/src/main/kotlin/space/kscience/kmath/tensors/LevenbergMarquardt/StreamingLm/streamLm.kt index b2818ef2a..f77adab7e 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/tensors/LevenbergMarquardt/StreamingLm/streamLm.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/tensors/LevenbergMarquardt/StreamingLm/streamLm.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2023 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/examples/src/main/kotlin/space/kscience/kmath/tensors/LevenbergMarquardt/StreamingLm/streamingLmTest.kt b/examples/src/main/kotlin/space/kscience/kmath/tensors/LevenbergMarquardt/StreamingLm/streamingLmTest.kt index c9dd5029e..2c53146b7 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/tensors/LevenbergMarquardt/StreamingLm/streamingLmTest.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/tensors/LevenbergMarquardt/StreamingLm/streamingLmTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2023 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/examples/src/main/kotlin/space/kscience/kmath/tensors/LevenbergMarquardt/functionsToOptimize.kt b/examples/src/main/kotlin/space/kscience/kmath/tensors/LevenbergMarquardt/functionsToOptimize.kt index 7ccb37ed0..4aefa1e0a 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/tensors/LevenbergMarquardt/functionsToOptimize.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/tensors/LevenbergMarquardt/functionsToOptimize.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2023 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/examples/src/main/kotlin/space/kscience/kmath/tensors/OLSWithSVD.kt b/examples/src/main/kotlin/space/kscience/kmath/tensors/OLSWithSVD.kt index 2c570ea34..8de4ab527 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/tensors/OLSWithSVD.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/tensors/OLSWithSVD.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/examples/src/main/kotlin/space/kscience/kmath/tensors/PCA.kt b/examples/src/main/kotlin/space/kscience/kmath/tensors/PCA.kt index fb774a39d..10edcd03a 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/tensors/PCA.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/tensors/PCA.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/examples/src/main/kotlin/space/kscience/kmath/tensors/dataSetNormalization.kt b/examples/src/main/kotlin/space/kscience/kmath/tensors/dataSetNormalization.kt index 45c2ff120..e804e5818 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/tensors/dataSetNormalization.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/tensors/dataSetNormalization.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/examples/src/main/kotlin/space/kscience/kmath/tensors/linearSystemSolvingWithLUP.kt b/examples/src/main/kotlin/space/kscience/kmath/tensors/linearSystemSolvingWithLUP.kt index 238696cf9..d5b04e153 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/tensors/linearSystemSolvingWithLUP.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/tensors/linearSystemSolvingWithLUP.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/examples/src/main/kotlin/space/kscience/kmath/tensors/multik.kt b/examples/src/main/kotlin/space/kscience/kmath/tensors/multik.kt index 67e0631e7..f8bf65ad7 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/tensors/multik.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/tensors/multik.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/examples/src/main/kotlin/space/kscience/kmath/tensors/neuralNetwork.kt b/examples/src/main/kotlin/space/kscience/kmath/tensors/neuralNetwork.kt index 8fd5ae5ad..78f27c304 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/tensors/neuralNetwork.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/tensors/neuralNetwork.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/TypedMst.kt b/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/TypedMst.kt index e82f7a3ab..4d1c00a29 100644 --- a/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/TypedMst.kt +++ b/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/TypedMst.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/evaluateConstants.kt b/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/evaluateConstants.kt index 8fc5a6aaf..10146146e 100644 --- a/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/evaluateConstants.kt +++ b/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/evaluateConstants.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/parser.kt b/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/parser.kt index 2c9a2a9ad..40bc60f4d 100644 --- a/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/parser.kt +++ b/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/parser.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/LatexSyntaxRenderer.kt b/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/LatexSyntaxRenderer.kt index 5a338afed..89464af32 100644 --- a/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/LatexSyntaxRenderer.kt +++ b/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/LatexSyntaxRenderer.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/MathMLSyntaxRenderer.kt b/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/MathMLSyntaxRenderer.kt index bfd9aeef9..8e6cada95 100644 --- a/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/MathMLSyntaxRenderer.kt +++ b/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/MathMLSyntaxRenderer.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/MathRenderer.kt b/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/MathRenderer.kt index f88a5b319..4590cebea 100644 --- a/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/MathRenderer.kt +++ b/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/MathRenderer.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/MathSyntax.kt b/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/MathSyntax.kt index 0196be3b6..8cc29b993 100644 --- a/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/MathSyntax.kt +++ b/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/MathSyntax.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/SyntaxRenderer.kt b/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/SyntaxRenderer.kt index 16957bdd2..8e0b00d10 100644 --- a/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/SyntaxRenderer.kt +++ b/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/SyntaxRenderer.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/features.kt b/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/features.kt index 4deffc83c..9fcabefbc 100644 --- a/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/features.kt +++ b/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/features.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/multiplatformToString.kt b/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/multiplatformToString.kt index dce99cc5a..b3844728b 100644 --- a/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/multiplatformToString.kt +++ b/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/multiplatformToString.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/phases.kt b/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/phases.kt index 0d26621d3..dae330916 100644 --- a/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/phases.kt +++ b/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/rendering/phases.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/TestCompilerConsistencyWithInterpreter.kt b/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/TestCompilerConsistencyWithInterpreter.kt index 77f6a191d..b2fe94589 100644 --- a/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/TestCompilerConsistencyWithInterpreter.kt +++ b/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/TestCompilerConsistencyWithInterpreter.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/TestCompilerOperations.kt b/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/TestCompilerOperations.kt index 30bb7291d..0fb3002f1 100644 --- a/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/TestCompilerOperations.kt +++ b/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/TestCompilerOperations.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/TestCompilerVariables.kt b/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/TestCompilerVariables.kt index 3dbdf063a..6fc3341b6 100644 --- a/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/TestCompilerVariables.kt +++ b/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/TestCompilerVariables.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/TestFolding.kt b/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/TestFolding.kt index 61a37944a..74fd4b56c 100644 --- a/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/TestFolding.kt +++ b/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/TestFolding.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/TestParser.kt b/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/TestParser.kt index 784dcece9..3c4fbb98c 100644 --- a/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/TestParser.kt +++ b/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/TestParser.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/TestParserPrecedence.kt b/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/TestParserPrecedence.kt index 504ec9bd0..227c0844a 100644 --- a/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/TestParserPrecedence.kt +++ b/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/TestParserPrecedence.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/rendering/TestFeatures.kt b/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/rendering/TestFeatures.kt index bb6d39204..158abbdeb 100644 --- a/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/rendering/TestFeatures.kt +++ b/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/rendering/TestFeatures.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/rendering/TestLatex.kt b/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/rendering/TestLatex.kt index 66c0ae1ae..12c11f89c 100644 --- a/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/rendering/TestLatex.kt +++ b/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/rendering/TestLatex.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/rendering/TestMathML.kt b/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/rendering/TestMathML.kt index 8bc014c54..abf761d23 100644 --- a/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/rendering/TestMathML.kt +++ b/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/rendering/TestMathML.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/rendering/TestStages.kt b/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/rendering/TestStages.kt index 306538d5d..be3d587be 100644 --- a/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/rendering/TestStages.kt +++ b/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/rendering/TestStages.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/rendering/TestUtils.kt b/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/rendering/TestUtils.kt index 79f178eef..378e6647b 100644 --- a/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/rendering/TestUtils.kt +++ b/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/rendering/TestUtils.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/utils.kt b/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/utils.kt index 27b2f2598..ee2346b13 100644 --- a/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/utils.kt +++ b/kmath-ast/src/commonTest/kotlin/space/kscience/kmath/ast/utils.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/ast/rendering/multiplatformToString.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/ast/rendering/multiplatformToString.kt index f6411334c..c1842b039 100644 --- a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/ast/rendering/multiplatformToString.kt +++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/ast/rendering/multiplatformToString.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/estree.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/estree.kt index 87c2df2d2..b52bfdf8c 100644 --- a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/estree.kt +++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/estree.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/internal/ESTreeBuilder.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/internal/ESTreeBuilder.kt index 1517cdef2..023d603c4 100644 --- a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/internal/ESTreeBuilder.kt +++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/internal/ESTreeBuilder.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/internal/astring/astring.typealises.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/internal/astring/astring.typealises.kt index 2434788ec..ccbebff81 100644 --- a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/internal/astring/astring.typealises.kt +++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/internal/astring/astring.typealises.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/astring/astring.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/astring/astring.kt index cc4360f8d..25721fee6 100644 --- a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/astring/astring.kt +++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/astring/astring.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/astring/astring.typealises.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/astring/astring.typealises.kt index a17726c9d..bf0d06660 100644 --- a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/astring/astring.typealises.kt +++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/astring/astring.typealises.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/base64/base64.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/base64/base64.kt index 8ea699837..cb4da44fe 100644 --- a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/base64/base64.kt +++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/base64/base64.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/binaryen/index.binaryen.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/binaryen/index.binaryen.kt index 59c9a40a6..d40f3e0f5 100644 --- a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/binaryen/index.binaryen.kt +++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/binaryen/index.binaryen.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/binaryen/index.binaryen.typealiases.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/binaryen/index.binaryen.typealiases.kt index eebfeb6ef..f9b3654c2 100644 --- a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/binaryen/index.binaryen.typealiases.kt +++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/binaryen/index.binaryen.typealiases.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/emitter/emitter.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/emitter/emitter.kt index a2a04da79..e87a5f380 100644 --- a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/emitter/emitter.kt +++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/emitter/emitter.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/estree/estree.extensions.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/estree/estree.extensions.kt index 2dd2c08cd..7549f6514 100644 --- a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/estree/estree.extensions.kt +++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/estree/estree.extensions.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/estree/estree.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/estree/estree.kt index bf4a25367..a05f57f7f 100644 --- a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/estree/estree.kt +++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/estree/estree.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/stream/stream.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/stream/stream.kt index ced165a3a..496df7e67 100644 --- a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/stream/stream.kt +++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/stream/stream.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/tsstdlib/lib.es2015.iterable.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/tsstdlib/lib.es2015.iterable.kt index 2c0dc9de1..9320243d8 100644 --- a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/tsstdlib/lib.es2015.iterable.kt +++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/tsstdlib/lib.es2015.iterable.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/tsstdlib/lib.es5.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/tsstdlib/lib.es5.kt index f20e2d865..07fd53fec 100644 --- a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/tsstdlib/lib.es5.kt +++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/tsstdlib/lib.es5.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/webassembly/lib.dom.WebAssembly.module_dukat.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/webassembly/lib.dom.WebAssembly.module_dukat.kt index 873a5e1d2..15332a413 100644 --- a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/webassembly/lib.dom.WebAssembly.module_dukat.kt +++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/webassembly/lib.dom.WebAssembly.module_dukat.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/webassembly/nonDeclarations.WebAssembly.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/webassembly/nonDeclarations.WebAssembly.kt index ba86e977b..ad97c259d 100644 --- a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/webassembly/nonDeclarations.WebAssembly.kt +++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/internal/webassembly/nonDeclarations.WebAssembly.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/wasm/internal/WasmBuilder.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/wasm/internal/WasmBuilder.kt index 4917f6f1b..18ef35c4b 100644 --- a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/wasm/internal/WasmBuilder.kt +++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/wasm/internal/WasmBuilder.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/wasm/internal/f64StandardFunctions.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/wasm/internal/f64StandardFunctions.kt index d60f24247..63cda9756 100644 --- a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/wasm/internal/f64StandardFunctions.kt +++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/wasm/internal/f64StandardFunctions.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/wasm/wasm.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/wasm/wasm.kt index f3249adf7..ceb1ad69d 100644 --- a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/wasm/wasm.kt +++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/wasm/wasm.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/ast/utils.kt b/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/ast/utils.kt index 6d826541c..03b90e248 100644 --- a/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/ast/utils.kt +++ b/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/ast/utils.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/wasm/TestWasmSpecific.kt b/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/wasm/TestWasmSpecific.kt index c7e898713..45b5aef5a 100644 --- a/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/wasm/TestWasmSpecific.kt +++ b/kmath-ast/src/jsTest/kotlin/space/kscience/kmath/wasm/TestWasmSpecific.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/asm.kt b/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/asm.kt index 97fe91ee4..a38ab9fc3 100644 --- a/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/asm.kt +++ b/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/asm.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/internal/AsmBuilder.kt b/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/internal/AsmBuilder.kt index e1fd455fd..aa7e093a5 100644 --- a/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/internal/AsmBuilder.kt +++ b/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/internal/AsmBuilder.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/internal/GenericAsmBuilder.kt b/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/internal/GenericAsmBuilder.kt index acae45d87..5314c4cc3 100644 --- a/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/internal/GenericAsmBuilder.kt +++ b/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/internal/GenericAsmBuilder.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/internal/PrimitiveAsmBuilder.kt b/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/internal/PrimitiveAsmBuilder.kt index bb8143206..9c27a25b5 100644 --- a/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/internal/PrimitiveAsmBuilder.kt +++ b/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/internal/PrimitiveAsmBuilder.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/internal/codegenUtils.kt b/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/internal/codegenUtils.kt index b3ccfdc0c..e3565df23 100644 --- a/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/internal/codegenUtils.kt +++ b/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/internal/codegenUtils.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/internal/mapIntrinsics.kt b/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/internal/mapIntrinsics.kt index 6459f4dcf..392854541 100644 --- a/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/internal/mapIntrinsics.kt +++ b/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/internal/mapIntrinsics.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/ast/rendering/multiplatformToString.kt b/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/ast/rendering/multiplatformToString.kt index ec66be830..745dced45 100644 --- a/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/ast/rendering/multiplatformToString.kt +++ b/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/ast/rendering/multiplatformToString.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/ast/utils.kt b/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/ast/utils.kt index e04e2e5bd..f06137c4a 100644 --- a/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/ast/utils.kt +++ b/kmath-ast/src/jvmTest/kotlin/space/kscience/kmath/ast/utils.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-ast/src/nativeMain/kotlin/space/kscience/kmath/ast/rendering/multiplatformToString.kt b/kmath-ast/src/nativeMain/kotlin/space/kscience/kmath/ast/rendering/multiplatformToString.kt index ec66be830..745dced45 100644 --- a/kmath-ast/src/nativeMain/kotlin/space/kscience/kmath/ast/rendering/multiplatformToString.kt +++ b/kmath-ast/src/nativeMain/kotlin/space/kscience/kmath/ast/rendering/multiplatformToString.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-ast/src/nativeTest/kotlin/space/kscience/kmath/ast/runCompilerTest.kt b/kmath-ast/src/nativeTest/kotlin/space/kscience/kmath/ast/runCompilerTest.kt index 0674b0492..28dd12e1f 100644 --- a/kmath-ast/src/nativeTest/kotlin/space/kscience/kmath/ast/runCompilerTest.kt +++ b/kmath-ast/src/nativeTest/kotlin/space/kscience/kmath/ast/runCompilerTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/expressions/CmDsExpression.kt b/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/expressions/CmDsExpression.kt index 38eaf8868..b7fef245c 100644 --- a/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/expressions/CmDsExpression.kt +++ b/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/expressions/CmDsExpression.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/integration/CMGaussRuleIntegrator.kt b/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/integration/CMGaussRuleIntegrator.kt index 263463d37..5234f459b 100644 --- a/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/integration/CMGaussRuleIntegrator.kt +++ b/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/integration/CMGaussRuleIntegrator.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ package space.kscience.kmath.commons.integration diff --git a/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/integration/CMIntegrator.kt b/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/integration/CMIntegrator.kt index c3e581d31..90f776195 100644 --- a/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/integration/CMIntegrator.kt +++ b/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/integration/CMIntegrator.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/linear/CMMatrix.kt b/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/linear/CMMatrix.kt index 4d2e2aa90..a7e746fe4 100644 --- a/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/linear/CMMatrix.kt +++ b/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/linear/CMMatrix.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/linear/CMSolver.kt b/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/linear/CMSolver.kt index 19799aab3..6b31fcd88 100644 --- a/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/linear/CMSolver.kt +++ b/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/linear/CMSolver.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/optimization/CMOptimizer.kt b/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/optimization/CMOptimizer.kt index c4dafb6a6..520588c1e 100644 --- a/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/optimization/CMOptimizer.kt +++ b/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/optimization/CMOptimizer.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @file:OptIn(UnstableKMathAPI::class) diff --git a/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/random/CMRandomGeneratorWrapper.kt b/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/random/CMRandomGeneratorWrapper.kt index 32962659f..62d31021c 100644 --- a/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/random/CMRandomGeneratorWrapper.kt +++ b/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/random/CMRandomGeneratorWrapper.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/transform/Transformations.kt b/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/transform/Transformations.kt index de271aedc..838ab95d5 100644 --- a/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/transform/Transformations.kt +++ b/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/transform/Transformations.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-commons/src/jvmTest/kotlin/space/kscience/kmath/commons/expressions/DerivativeStructureExpressionTest.kt b/kmath-commons/src/jvmTest/kotlin/space/kscience/kmath/commons/expressions/DerivativeStructureExpressionTest.kt index 7c3c086ed..34905fa7b 100644 --- a/kmath-commons/src/jvmTest/kotlin/space/kscience/kmath/commons/expressions/DerivativeStructureExpressionTest.kt +++ b/kmath-commons/src/jvmTest/kotlin/space/kscience/kmath/commons/expressions/DerivativeStructureExpressionTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-commons/src/jvmTest/kotlin/space/kscience/kmath/commons/integration/IntegrationTest.kt b/kmath-commons/src/jvmTest/kotlin/space/kscience/kmath/commons/integration/IntegrationTest.kt index 9a249b29b..c2e630f38 100644 --- a/kmath-commons/src/jvmTest/kotlin/space/kscience/kmath/commons/integration/IntegrationTest.kt +++ b/kmath-commons/src/jvmTest/kotlin/space/kscience/kmath/commons/integration/IntegrationTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-commons/src/jvmTest/kotlin/space/kscience/kmath/commons/optimization/OptimizeTest.kt b/kmath-commons/src/jvmTest/kotlin/space/kscience/kmath/commons/optimization/OptimizeTest.kt index 5933d0d36..c4177d8ad 100644 --- a/kmath-commons/src/jvmTest/kotlin/space/kscience/kmath/commons/optimization/OptimizeTest.kt +++ b/kmath-commons/src/jvmTest/kotlin/space/kscience/kmath/commons/optimization/OptimizeTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/Complex.kt b/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/Complex.kt index b5f1aabe7..d54a225e6 100644 --- a/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/Complex.kt +++ b/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/Complex.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ 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 90a6b3253..8fbf41732 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 @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/Quaternion.kt b/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/Quaternion.kt index 8f3d15a26..7f9f742e5 100644 --- a/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/Quaternion.kt +++ b/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/Quaternion.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-complex/src/commonTest/kotlin/space/kscience/kmath/complex/ComplexBufferSpecTest.kt b/kmath-complex/src/commonTest/kotlin/space/kscience/kmath/complex/ComplexBufferSpecTest.kt index ca3f8f43f..124703cbe 100644 --- a/kmath-complex/src/commonTest/kotlin/space/kscience/kmath/complex/ComplexBufferSpecTest.kt +++ b/kmath-complex/src/commonTest/kotlin/space/kscience/kmath/complex/ComplexBufferSpecTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-complex/src/commonTest/kotlin/space/kscience/kmath/complex/ComplexFieldTest.kt b/kmath-complex/src/commonTest/kotlin/space/kscience/kmath/complex/ComplexFieldTest.kt index e11f1c1ea..506451888 100644 --- a/kmath-complex/src/commonTest/kotlin/space/kscience/kmath/complex/ComplexFieldTest.kt +++ b/kmath-complex/src/commonTest/kotlin/space/kscience/kmath/complex/ComplexFieldTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-complex/src/commonTest/kotlin/space/kscience/kmath/complex/ComplexTest.kt b/kmath-complex/src/commonTest/kotlin/space/kscience/kmath/complex/ComplexTest.kt index 1a35d1dd8..a736d5ac5 100644 --- a/kmath-complex/src/commonTest/kotlin/space/kscience/kmath/complex/ComplexTest.kt +++ b/kmath-complex/src/commonTest/kotlin/space/kscience/kmath/complex/ComplexTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-complex/src/commonTest/kotlin/space/kscience/kmath/complex/ExpressionFieldForComplexTest.kt b/kmath-complex/src/commonTest/kotlin/space/kscience/kmath/complex/ExpressionFieldForComplexTest.kt index 767406e0b..9b7bdfa95 100644 --- a/kmath-complex/src/commonTest/kotlin/space/kscience/kmath/complex/ExpressionFieldForComplexTest.kt +++ b/kmath-complex/src/commonTest/kotlin/space/kscience/kmath/complex/ExpressionFieldForComplexTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-complex/src/commonTest/kotlin/space/kscience/kmath/complex/QuaternionTest.kt b/kmath-complex/src/commonTest/kotlin/space/kscience/kmath/complex/QuaternionTest.kt index 1b371adca..b60b853de 100644 --- a/kmath-complex/src/commonTest/kotlin/space/kscience/kmath/complex/QuaternionTest.kt +++ b/kmath-complex/src/commonTest/kotlin/space/kscience/kmath/complex/QuaternionTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/data/ColumnarData.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/data/ColumnarData.kt index 49e2ee8d0..1dd92980e 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/data/ColumnarData.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/data/ColumnarData.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/data/XYColumnarData.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/data/XYColumnarData.kt index 23cbcd0c7..cc35f606b 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/data/XYColumnarData.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/data/XYColumnarData.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/data/XYErrorColumnarData.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/data/XYErrorColumnarData.kt index 797a25443..312894612 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/data/XYErrorColumnarData.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/data/XYErrorColumnarData.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/data/XYZColumnarData.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/data/XYZColumnarData.kt index 846bbad62..2af3c1c19 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/data/XYZColumnarData.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/data/XYZColumnarData.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/domains/Domain.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/domains/Domain.kt index eecdcebad..5bfbeb6ac 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/domains/Domain.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/domains/Domain.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/domains/Domain1D.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/domains/Domain1D.kt index b03e60e95..79f446f6d 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/domains/Domain1D.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/domains/Domain1D.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/domains/Float64Domain.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/domains/Float64Domain.kt index 7878f2551..a522381e1 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/domains/Float64Domain.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/domains/Float64Domain.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ package space.kscience.kmath.domains 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 03a080a70..16dae5699 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 @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ package space.kscience.kmath.domains 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 b78190c9b..f651dcde3 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 @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ package space.kscience.kmath.domains diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/DSAlgebra.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/DSAlgebra.kt index 192509993..c0c5e8bdf 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/DSAlgebra.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/DSAlgebra.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/DSCompiler.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/DSCompiler.kt index 1da151d46..0699ca1df 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/DSCompiler.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/DSCompiler.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/DifferentiableExpression.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/DifferentiableExpression.kt index 7c8a957c7..e76374b50 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/DifferentiableExpression.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/DifferentiableExpression.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/Expression.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/Expression.kt index f350303bc..77aa9ae7b 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/Expression.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/Expression.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/ExpressionWithDefault.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/ExpressionWithDefault.kt index c802fe04c..b576642fc 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/ExpressionWithDefault.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/ExpressionWithDefault.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2023 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/FunctionalExpressionAlgebra.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/FunctionalExpressionAlgebra.kt index 8e37f3d32..a4b50ebc6 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/FunctionalExpressionAlgebra.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/FunctionalExpressionAlgebra.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/MST.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/MST.kt index 9705a3f03..145a2bf50 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/MST.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/MST.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/MstAlgebra.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/MstAlgebra.kt index c894cf00a..8dca4f1dd 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/MstAlgebra.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/MstAlgebra.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/NamedMatrix.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/NamedMatrix.kt index 5d047d5b7..14ccafb0b 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/NamedMatrix.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/NamedMatrix.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2023 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ 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 2bb5043b7..d5a053f43 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 @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/Symbol.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/Symbol.kt index c57ce69ab..5e2ab64a6 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/Symbol.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/Symbol.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/SymbolIndexer.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/SymbolIndexer.kt index f0e39d489..d47202df3 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/SymbolIndexer.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/SymbolIndexer.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/BufferedLinearSpace.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/BufferedLinearSpace.kt index 4bba47a91..fca29a9dd 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/BufferedLinearSpace.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/BufferedLinearSpace.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/Float64LinearSpace.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/Float64LinearSpace.kt index eb4434c00..0da4c275d 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/Float64LinearSpace.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/Float64LinearSpace.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/LinearSolver.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/LinearSolver.kt index af9ebb463..2d7fb42d4 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/LinearSolver.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/LinearSolver.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ 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 a82bafe57..97db63ded 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 @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ 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 ce55623de..ed76bd337 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 @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixBuilder.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixBuilder.kt index 4d2f01e68..0dc42f4c8 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixBuilder.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixBuilder.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixFeatures.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixFeatures.kt index ce7acdcba..22781f640 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixFeatures.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixFeatures.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixWrapper.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixWrapper.kt index 46454a584..c2efdafda 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixWrapper.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixWrapper.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/VirtualMatrix.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/VirtualMatrix.kt index 55b970f4a..6a22092b2 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/VirtualMatrix.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/VirtualMatrix.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/misc/Featured.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/misc/Featured.kt index bdda674dc..64cc25016 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/misc/Featured.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/misc/Featured.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/misc/collections.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/misc/collections.kt index f630055fa..6227e2f45 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/misc/collections.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/misc/collections.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2023 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/misc/cumulative.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/misc/cumulative.kt index c05f1a6a9..60f71b943 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/misc/cumulative.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/misc/cumulative.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/misc/logging.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/misc/logging.kt index c7886469f..9655e1139 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/misc/logging.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/misc/logging.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/misc/numbers.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/misc/numbers.kt index 77ef07ea8..cc43c84bc 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/misc/numbers.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/misc/numbers.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/misc/sorting.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/misc/sorting.kt index f369f0614..0e7c34eb5 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/misc/sorting.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/misc/sorting.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/AlgebraND.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/AlgebraND.kt index 91e26cc1b..e3c8d3963 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/AlgebraND.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/AlgebraND.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ 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 74c63e6e2..b92e77969 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 @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/BufferND.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/BufferND.kt index 9217f6fdc..2ac4927c7 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/BufferND.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/BufferND.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Float64FieldND.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Float64FieldND.kt index 464ee16b9..89a7a02a2 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Float64FieldND.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Float64FieldND.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Int16RingND.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Int16RingND.kt index 758a486f5..2f91a3326 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Int16RingND.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Int16RingND.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/IntRingND.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/IntRingND.kt index 039432bc7..128badda4 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/IntRingND.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/IntRingND.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/PermutedStructureND.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/PermutedStructureND.kt index 6c35e2f44..f8b101d1d 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/PermutedStructureND.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/PermutedStructureND.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/ShapeIndices.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/ShapeIndices.kt index 3a27614c5..e8545125f 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/ShapeIndices.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/ShapeIndices.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/ShapeND.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/ShapeND.kt index d43ebaf1c..dee22e49f 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/ShapeND.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/ShapeND.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Structure1D.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Structure1D.kt index 984b5ad0f..235a39c05 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Structure1D.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Structure1D.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Structure2D.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Structure2D.kt index e006d09eb..ae16c850a 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Structure2D.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Structure2D.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/StructureND.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/StructureND.kt index e643186ba..20cf58a8c 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/StructureND.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/StructureND.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/VirtualStructureND.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/VirtualStructureND.kt index 606b9a631..a7e0b0053 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/VirtualStructureND.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/VirtualStructureND.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/algebraNDExtentions.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/algebraNDExtentions.kt index f0d4bd7f5..71bc2bde4 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/algebraNDExtentions.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/algebraNDExtentions.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/operationsND.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/operationsND.kt index 40db5187f..b91f2bde5 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/operationsND.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/operationsND.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/primitiveStructureND.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/primitiveStructureND.kt index 28e32363f..9f70b6dca 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/primitiveStructureND.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/primitiveStructureND.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/Algebra.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/Algebra.kt index 67f37ed62..1ee199fc8 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/Algebra.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/Algebra.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/BigInt.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/BigInt.kt index 34a6d4a80..edb2a822a 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/BigInt.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/BigInt.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/BufferAlgebra.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/BufferAlgebra.kt index 0363f39d3..fd4df72c8 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/BufferAlgebra.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/BufferAlgebra.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/Float64BufferField.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/Float64BufferField.kt index e33cb2c6e..5defbd7c5 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/Float64BufferField.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/Float64BufferField.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/Float64BufferOps.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/Float64BufferOps.kt index 923534e1c..ca4eacb8a 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/Float64BufferOps.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/Float64BufferOps.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/LogicAlgebra.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/LogicAlgebra.kt index d8bf0fb57..a10fd949b 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/LogicAlgebra.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/LogicAlgebra.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/NumericAlgebra.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/NumericAlgebra.kt index 06ad68298..4f15418b3 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/NumericAlgebra.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/NumericAlgebra.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/OptionalOperations.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/OptionalOperations.kt index 48cac2870..422134bcd 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/OptionalOperations.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/OptionalOperations.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/algebraExtensions.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/algebraExtensions.kt index ddf599240..872d72857 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/algebraExtensions.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/algebraExtensions.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/integerFields.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/integerFields.kt index 72e33c523..7ae5dc152 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/integerFields.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/integerFields.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2023 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ 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 0b7bef852..720f454b0 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 @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ package space.kscience.kmath.operations diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/ArrayBuffer.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/ArrayBuffer.kt index 8e81dd941..2e644da88 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/ArrayBuffer.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/ArrayBuffer.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ 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 4c8ba0652..809cd0c93 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 @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/BufferAccessor2D.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/BufferAccessor2D.kt index 48f3e919b..8d873d86d 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/BufferAccessor2D.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/BufferAccessor2D.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/BufferView.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/BufferView.kt index f538fdd01..996065010 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/BufferView.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/BufferView.kt @@ -1,3 +1,8 @@ +/* + * Copyright 2018-2024 KMath contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + package space.kscience.kmath.structures import space.kscience.kmath.UnstableKMathAPI 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 d99e02996..c3cb153f4 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 @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Float32Buffer.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Float32Buffer.kt index 44ef4dcf0..ff41a0d37 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Float32Buffer.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Float32Buffer.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Float64Buffer.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Float64Buffer.kt index 0542c1bf4..519ea7f30 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Float64Buffer.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Float64Buffer.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Int16Buffer.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Int16Buffer.kt index 1ba40c934..3e5b3f846 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Int16Buffer.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Int16Buffer.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Int32Buffer.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Int32Buffer.kt index afd94e9cd..6754d3873 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Int32Buffer.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Int32Buffer.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Int64Buffer.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Int64Buffer.kt index c67d109aa..f57a5cd1b 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Int64Buffer.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Int64Buffer.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Int8Buffer.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Int8Buffer.kt index 923fbec06..f3ae90c5e 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Int8Buffer.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Int8Buffer.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/ListBuffer.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/ListBuffer.kt index fbc9a489b..61afe4c17 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/ListBuffer.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/ListBuffer.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/MemoryBuffer.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/MemoryBuffer.kt index cbfd6b9cd..7a630ba24 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/MemoryBuffer.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/MemoryBuffer.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/MutableBuffer.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/MutableBuffer.kt index 772c670ea..f058f205d 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/MutableBuffer.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/MutableBuffer.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/bufferExtensions.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/bufferExtensions.kt index 6a7b6d836..7c69669c8 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/bufferExtensions.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/bufferExtensions.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/bufferPrimitiveAccess.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/bufferPrimitiveAccess.kt index 9033dea98..6035811b9 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/bufferPrimitiveAccess.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/bufferPrimitiveAccess.kt @@ -1,3 +1,8 @@ +/* + * Copyright 2018-2024 KMath contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + package space.kscience.kmath.structures import space.kscience.kmath.UnstableKMathAPI diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/types.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/types.kt index 4ace17538..3d5f87abc 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/types.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/types.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonTest/kotlin/space/kscience/kmath/expressions/DSTest.kt b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/expressions/DSTest.kt index 71bbc325c..eb679cec6 100644 --- a/kmath-core/src/commonTest/kotlin/space/kscience/kmath/expressions/DSTest.kt +++ b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/expressions/DSTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ 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 153090d35..ca2e31d7d 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,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonTest/kotlin/space/kscience/kmath/expressions/InterpretTest.kt b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/expressions/InterpretTest.kt index 6533af344..b9ab5e62c 100644 --- a/kmath-core/src/commonTest/kotlin/space/kscience/kmath/expressions/InterpretTest.kt +++ b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/expressions/InterpretTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ 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 c0c5fc321..dcfb16042 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,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonTest/kotlin/space/kscience/kmath/linear/DoubleLUSolverTest.kt b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/linear/DoubleLUSolverTest.kt index 4d05f9043..12ed88996 100644 --- a/kmath-core/src/commonTest/kotlin/space/kscience/kmath/linear/DoubleLUSolverTest.kt +++ b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/linear/DoubleLUSolverTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonTest/kotlin/space/kscience/kmath/linear/MatrixTest.kt b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/linear/MatrixTest.kt index 531aee259..58865bafe 100644 --- a/kmath-core/src/commonTest/kotlin/space/kscience/kmath/linear/MatrixTest.kt +++ b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/linear/MatrixTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonTest/kotlin/space/kscience/kmath/misc/CumulativeKtTest.kt b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/misc/CumulativeKtTest.kt index 811f2e87f..9cedb8bb3 100644 --- a/kmath-core/src/commonTest/kotlin/space/kscience/kmath/misc/CumulativeKtTest.kt +++ b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/misc/CumulativeKtTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonTest/kotlin/space/kscience/kmath/misc/PermSortTest.kt b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/misc/PermSortTest.kt index fa9ac19c0..a8fc1c765 100644 --- a/kmath-core/src/commonTest/kotlin/space/kscience/kmath/misc/PermSortTest.kt +++ b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/misc/PermSortTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonTest/kotlin/space/kscience/kmath/nd/NdOperationsTest.kt b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/nd/NdOperationsTest.kt index ada7f4244..d0f79bb15 100644 --- a/kmath-core/src/commonTest/kotlin/space/kscience/kmath/nd/NdOperationsTest.kt +++ b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/nd/NdOperationsTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonTest/kotlin/space/kscience/kmath/nd/StridesTest.kt b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/nd/StridesTest.kt index e6335f652..1c26c215c 100644 --- a/kmath-core/src/commonTest/kotlin/space/kscience/kmath/nd/StridesTest.kt +++ b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/nd/StridesTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonTest/kotlin/space/kscience/kmath/operations/BigIntAlgebraTest.kt b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/operations/BigIntAlgebraTest.kt index 06a9ab439..0bbb92151 100644 --- a/kmath-core/src/commonTest/kotlin/space/kscience/kmath/operations/BigIntAlgebraTest.kt +++ b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/operations/BigIntAlgebraTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonTest/kotlin/space/kscience/kmath/operations/BigIntConstructorTest.kt b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/operations/BigIntConstructorTest.kt index 786c68c70..69bccacdd 100644 --- a/kmath-core/src/commonTest/kotlin/space/kscience/kmath/operations/BigIntConstructorTest.kt +++ b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/operations/BigIntConstructorTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonTest/kotlin/space/kscience/kmath/operations/BigIntConversionsTest.kt b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/operations/BigIntConversionsTest.kt index 36f00dc75..f9b5dca2a 100644 --- a/kmath-core/src/commonTest/kotlin/space/kscience/kmath/operations/BigIntConversionsTest.kt +++ b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/operations/BigIntConversionsTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonTest/kotlin/space/kscience/kmath/operations/BigIntOperationsTest.kt b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/operations/BigIntOperationsTest.kt index 8a6116605..1f47dc2c1 100644 --- a/kmath-core/src/commonTest/kotlin/space/kscience/kmath/operations/BigIntOperationsTest.kt +++ b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/operations/BigIntOperationsTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonTest/kotlin/space/kscience/kmath/operations/DoubleFieldTest.kt b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/operations/DoubleFieldTest.kt index 2f0ee28e7..51783df13 100644 --- a/kmath-core/src/commonTest/kotlin/space/kscience/kmath/operations/DoubleFieldTest.kt +++ b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/operations/DoubleFieldTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonTest/kotlin/space/kscience/kmath/structures/BufferExpandedTest.kt b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/structures/BufferExpandedTest.kt index 04671e040..0a9b1d897 100644 --- a/kmath-core/src/commonTest/kotlin/space/kscience/kmath/structures/BufferExpandedTest.kt +++ b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/structures/BufferExpandedTest.kt @@ -1,3 +1,8 @@ +/* + * Copyright 2018-2024 KMath contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + package space.kscience.kmath.structures import kotlin.test.Test diff --git a/kmath-core/src/commonTest/kotlin/space/kscience/kmath/structures/NDFieldTest.kt b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/structures/NDFieldTest.kt index d6c6adedd..0fc9cb9e3 100644 --- a/kmath-core/src/commonTest/kotlin/space/kscience/kmath/structures/NDFieldTest.kt +++ b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/structures/NDFieldTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/commonTest/kotlin/space/kscience/kmath/structures/NumberNDFieldTest.kt b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/structures/NumberNDFieldTest.kt index 4ee6d50cb..2f10af972 100644 --- a/kmath-core/src/commonTest/kotlin/space/kscience/kmath/structures/NumberNDFieldTest.kt +++ b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/structures/NumberNDFieldTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/jsMain/kotlin/space/kscience/kmath/misc/numbers.kt b/kmath-core/src/jsMain/kotlin/space/kscience/kmath/misc/numbers.kt index e52ea9298..e0875993f 100644 --- a/kmath-core/src/jsMain/kotlin/space/kscience/kmath/misc/numbers.kt +++ b/kmath-core/src/jsMain/kotlin/space/kscience/kmath/misc/numbers.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/jsMain/kotlin/space/kscience/kmath/operations/isInteger.kt b/kmath-core/src/jsMain/kotlin/space/kscience/kmath/operations/isInteger.kt index 3103f5168..da697bd77 100644 --- a/kmath-core/src/jsMain/kotlin/space/kscience/kmath/operations/isInteger.kt +++ b/kmath-core/src/jsMain/kotlin/space/kscience/kmath/operations/isInteger.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/jvmMain/kotlin/space/kscience/kmath/misc/numbersJVM.kt b/kmath-core/src/jvmMain/kotlin/space/kscience/kmath/misc/numbersJVM.kt index 3780ea1ae..222e1bca1 100644 --- a/kmath-core/src/jvmMain/kotlin/space/kscience/kmath/misc/numbersJVM.kt +++ b/kmath-core/src/jvmMain/kotlin/space/kscience/kmath/misc/numbersJVM.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/jvmMain/kotlin/space/kscience/kmath/operations/BigNumbers.kt b/kmath-core/src/jvmMain/kotlin/space/kscience/kmath/operations/BigNumbers.kt index 584748bd7..b19f0c8f9 100644 --- a/kmath-core/src/jvmMain/kotlin/space/kscience/kmath/operations/BigNumbers.kt +++ b/kmath-core/src/jvmMain/kotlin/space/kscience/kmath/operations/BigNumbers.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/jvmMain/kotlin/space/kscience/kmath/operations/isInteger.kt b/kmath-core/src/jvmMain/kotlin/space/kscience/kmath/operations/isInteger.kt index 9868daddf..fa75860d8 100644 --- a/kmath-core/src/jvmMain/kotlin/space/kscience/kmath/operations/isInteger.kt +++ b/kmath-core/src/jvmMain/kotlin/space/kscience/kmath/operations/isInteger.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/jvmTest/kotlin/space/kscience/kmath/misc/JBigTest.kt b/kmath-core/src/jvmTest/kotlin/space/kscience/kmath/misc/JBigTest.kt index f7f8027e6..f27257a4c 100644 --- a/kmath-core/src/jvmTest/kotlin/space/kscience/kmath/misc/JBigTest.kt +++ b/kmath-core/src/jvmTest/kotlin/space/kscience/kmath/misc/JBigTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/nativeMain/kotlin/space/kscience/kmath/misc/numbers.kt b/kmath-core/src/nativeMain/kotlin/space/kscience/kmath/misc/numbers.kt index e52ea9298..e0875993f 100644 --- a/kmath-core/src/nativeMain/kotlin/space/kscience/kmath/misc/numbers.kt +++ b/kmath-core/src/nativeMain/kotlin/space/kscience/kmath/misc/numbers.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/nativeMain/kotlin/space/kscience/kmath/operations/isInteger.kt b/kmath-core/src/nativeMain/kotlin/space/kscience/kmath/operations/isInteger.kt index 9868daddf..fa75860d8 100644 --- a/kmath-core/src/nativeMain/kotlin/space/kscience/kmath/operations/isInteger.kt +++ b/kmath-core/src/nativeMain/kotlin/space/kscience/kmath/operations/isInteger.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/wasmJsMain/kotlin/space/kscience/kmath/misc/numbers.kt b/kmath-core/src/wasmJsMain/kotlin/space/kscience/kmath/misc/numbers.kt index e320f350e..e0875993f 100644 --- a/kmath-core/src/wasmJsMain/kotlin/space/kscience/kmath/misc/numbers.kt +++ b/kmath-core/src/wasmJsMain/kotlin/space/kscience/kmath/misc/numbers.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2023 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-core/src/wasmJsMain/kotlin/space/kscience/kmath/operations/isInteger.kt b/kmath-core/src/wasmJsMain/kotlin/space/kscience/kmath/operations/isInteger.kt index 11c82bf9e..9f68527f7 100644 --- a/kmath-core/src/wasmJsMain/kotlin/space/kscience/kmath/operations/isInteger.kt +++ b/kmath-core/src/wasmJsMain/kotlin/space/kscience/kmath/operations/isInteger.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2023 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/chains/BlockingChain.kt b/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/chains/BlockingChain.kt index 2e9a15eed..87e77387c 100644 --- a/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/chains/BlockingChain.kt +++ b/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/chains/BlockingChain.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/chains/BlockingDoubleChain.kt b/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/chains/BlockingDoubleChain.kt index e67cab72d..b3e1b59b7 100644 --- a/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/chains/BlockingDoubleChain.kt +++ b/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/chains/BlockingDoubleChain.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/chains/BlockingIntChain.kt b/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/chains/BlockingIntChain.kt index 172aa95cd..82a6d131e 100644 --- a/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/chains/BlockingIntChain.kt +++ b/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/chains/BlockingIntChain.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/chains/Chain.kt b/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/chains/Chain.kt index 977346e68..0158c6752 100644 --- a/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/chains/Chain.kt +++ b/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/chains/Chain.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/chains/flowExtra.kt b/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/chains/flowExtra.kt index 77d4203c5..52114752c 100644 --- a/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/chains/flowExtra.kt +++ b/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/chains/flowExtra.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/coroutines/coroutinesExtra.kt b/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/coroutines/coroutinesExtra.kt index 48be93b87..8183d2d15 100644 --- a/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/coroutines/coroutinesExtra.kt +++ b/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/coroutines/coroutinesExtra.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ 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 c52b6c3d5..e0e8050bc 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 @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/streaming/RingBuffer.kt b/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/streaming/RingBuffer.kt index bb07fede1..c4e24a2d7 100644 --- a/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/streaming/RingBuffer.kt +++ b/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/streaming/RingBuffer.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-coroutines/src/jvmMain/kotlin/space/kscience/kmath/chains/ChainExt.kt b/kmath-coroutines/src/jvmMain/kotlin/space/kscience/kmath/chains/ChainExt.kt index a62bcc6b8..7dc423552 100644 --- a/kmath-coroutines/src/jvmMain/kotlin/space/kscience/kmath/chains/ChainExt.kt +++ b/kmath-coroutines/src/jvmMain/kotlin/space/kscience/kmath/chains/ChainExt.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ 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 22c2ac3ff..86bc39912 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 @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-coroutines/src/jvmTest/kotlin/space/kscience/kmath/streaming/BufferFlowTest.kt b/kmath-coroutines/src/jvmTest/kotlin/space/kscience/kmath/streaming/BufferFlowTest.kt index c448168e3..22893389d 100644 --- a/kmath-coroutines/src/jvmTest/kotlin/space/kscience/kmath/streaming/BufferFlowTest.kt +++ b/kmath-coroutines/src/jvmTest/kotlin/space/kscience/kmath/streaming/BufferFlowTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-coroutines/src/jvmTest/kotlin/space/kscience/kmath/streaming/RingBufferTest.kt b/kmath-coroutines/src/jvmTest/kotlin/space/kscience/kmath/streaming/RingBufferTest.kt index a6d7f006c..6219a5886 100644 --- a/kmath-coroutines/src/jvmTest/kotlin/space/kscience/kmath/streaming/RingBufferTest.kt +++ b/kmath-coroutines/src/jvmTest/kotlin/space/kscience/kmath/streaming/RingBufferTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-dimensions/src/commonMain/kotlin/space/kscience/kmath/dimensions/Dimension.kt b/kmath-dimensions/src/commonMain/kotlin/space/kscience/kmath/dimensions/Dimension.kt index 14677319c..afdb8eec1 100644 --- a/kmath-dimensions/src/commonMain/kotlin/space/kscience/kmath/dimensions/Dimension.kt +++ b/kmath-dimensions/src/commonMain/kotlin/space/kscience/kmath/dimensions/Dimension.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ 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 6cade1d5d..0e820d3ca 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 @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-dimensions/src/commonTest/kotlin/space/kscience/dimensions/DMatrixContextTest.kt b/kmath-dimensions/src/commonTest/kotlin/space/kscience/dimensions/DMatrixContextTest.kt index e2793855b..e60740826 100644 --- a/kmath-dimensions/src/commonTest/kotlin/space/kscience/dimensions/DMatrixContextTest.kt +++ b/kmath-dimensions/src/commonTest/kotlin/space/kscience/dimensions/DMatrixContextTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-dimensions/src/jsMain/kotlin/space/kscience/kmath/dimensions/Dimension.kt b/kmath-dimensions/src/jsMain/kotlin/space/kscience/kmath/dimensions/Dimension.kt index 1ae484228..cbf404b7f 100644 --- a/kmath-dimensions/src/jsMain/kotlin/space/kscience/kmath/dimensions/Dimension.kt +++ b/kmath-dimensions/src/jsMain/kotlin/space/kscience/kmath/dimensions/Dimension.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-dimensions/src/jvmMain/kotlin/space/kscience/kmath/dimensions/Dimension.kt b/kmath-dimensions/src/jvmMain/kotlin/space/kscience/kmath/dimensions/Dimension.kt index 24cfb14e8..131a6db42 100644 --- a/kmath-dimensions/src/jvmMain/kotlin/space/kscience/kmath/dimensions/Dimension.kt +++ b/kmath-dimensions/src/jvmMain/kotlin/space/kscience/kmath/dimensions/Dimension.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-dimensions/src/nativeMain/kotlin/space/kscience/kmath/dimensions/Dimension.kt b/kmath-dimensions/src/nativeMain/kotlin/space/kscience/kmath/dimensions/Dimension.kt index f5f749c8a..ddfee4523 100644 --- a/kmath-dimensions/src/nativeMain/kotlin/space/kscience/kmath/dimensions/Dimension.kt +++ b/kmath-dimensions/src/nativeMain/kotlin/space/kscience/kmath/dimensions/Dimension.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ 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 8925fb045..306a80ef8 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 @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/EjmlMatrix.kt b/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/EjmlMatrix.kt index 1d70c0e7d..d24f56042 100644 --- a/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/EjmlMatrix.kt +++ b/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/EjmlMatrix.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/EjmlVector.kt b/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/EjmlVector.kt index c4fae9951..82401ba05 100644 --- a/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/EjmlVector.kt +++ b/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/EjmlVector.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/_generated.kt b/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/_generated.kt index f48ab4c19..7a267b77b 100644 --- a/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/_generated.kt +++ b/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/_generated.kt @@ -1,6 +1,6 @@ /* - * Copyright 2018-2021 KMath contributors. - * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. + * Copyright 2018-2024 KMath contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ /* This file is generated with buildSrc/src/main/kotlin/space/kscience/kmath/ejml/codegen/ejmlCodegen.kt */ @@ -19,13 +19,19 @@ import org.ejml.sparse.csc.factory.DecompositionFactory_DSCC import org.ejml.sparse.csc.factory.DecompositionFactory_FSCC import org.ejml.sparse.csc.factory.LinearSolverFactory_DSCC import org.ejml.sparse.csc.factory.LinearSolverFactory_FSCC -import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.linear.* import space.kscience.kmath.linear.Matrix +import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.nd.StructureFeature -import space.kscience.kmath.operations.Float32Field +import space.kscience.kmath.structures.Float64 +import space.kscience.kmath.structures.Float32 import space.kscience.kmath.operations.Float64Field +import space.kscience.kmath.operations.Float32Field +import space.kscience.kmath.operations.DoubleField +import space.kscience.kmath.operations.FloatField import space.kscience.kmath.operations.invoke +import space.kscience.kmath.structures.Float64Buffer +import space.kscience.kmath.structures.Float32Buffer import space.kscience.kmath.structures.DoubleBuffer import space.kscience.kmath.structures.FloatBuffer import kotlin.reflect.KClass diff --git a/kmath-ejml/src/test/kotlin/space/kscience/kmath/ejml/EjmlMatrixTest.kt b/kmath-ejml/src/test/kotlin/space/kscience/kmath/ejml/EjmlMatrixTest.kt index e89810e0d..2a7280220 100644 --- a/kmath-ejml/src/test/kotlin/space/kscience/kmath/ejml/EjmlMatrixTest.kt +++ b/kmath-ejml/src/test/kotlin/space/kscience/kmath/ejml/EjmlMatrixTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-ejml/src/test/kotlin/space/kscience/kmath/ejml/EjmlVectorTest.kt b/kmath-ejml/src/test/kotlin/space/kscience/kmath/ejml/EjmlVectorTest.kt index 7d3ea314b..cbc7f7c41 100644 --- a/kmath-ejml/src/test/kotlin/space/kscience/kmath/ejml/EjmlVectorTest.kt +++ b/kmath-ejml/src/test/kotlin/space/kscience/kmath/ejml/EjmlVectorTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-for-real/src/commonMain/kotlin/space/kscience/kmath/real/DoubleVector.kt b/kmath-for-real/src/commonMain/kotlin/space/kscience/kmath/real/DoubleVector.kt index d13528636..493a299c0 100644 --- a/kmath-for-real/src/commonMain/kotlin/space/kscience/kmath/real/DoubleVector.kt +++ b/kmath-for-real/src/commonMain/kotlin/space/kscience/kmath/real/DoubleVector.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ 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 fe5593eaa..208c82c6d 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 @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-for-real/src/commonMain/kotlin/space/kscience/kmath/real/dot.kt b/kmath-for-real/src/commonMain/kotlin/space/kscience/kmath/real/dot.kt index 0c18602f1..e9fdfb506 100644 --- a/kmath-for-real/src/commonMain/kotlin/space/kscience/kmath/real/dot.kt +++ b/kmath-for-real/src/commonMain/kotlin/space/kscience/kmath/real/dot.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ 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 79af446e2..f1b099cde 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 @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ 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 1b9f0f4e2..223cdd25d 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,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-for-real/src/commonTest/kotlin/space/kscience/kmath/real/DoubleMatrixTest.kt b/kmath-for-real/src/commonTest/kotlin/space/kscience/kmath/real/DoubleMatrixTest.kt index c00cd84d1..f54ec6290 100644 --- a/kmath-for-real/src/commonTest/kotlin/space/kscience/kmath/real/DoubleMatrixTest.kt +++ b/kmath-for-real/src/commonTest/kotlin/space/kscience/kmath/real/DoubleMatrixTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-for-real/src/commonTest/kotlin/space/kscience/kmath/real/DoubleVectorTest.kt b/kmath-for-real/src/commonTest/kotlin/space/kscience/kmath/real/DoubleVectorTest.kt index 16eccd79b..29aa2ec2e 100644 --- a/kmath-for-real/src/commonTest/kotlin/space/kscience/kmath/real/DoubleVectorTest.kt +++ b/kmath-for-real/src/commonTest/kotlin/space/kscience/kmath/real/DoubleVectorTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-for-real/src/commonTest/kotlin/space/kscience/kmath/real/GridTest.kt b/kmath-for-real/src/commonTest/kotlin/space/kscience/kmath/real/GridTest.kt index 35c53f9d6..861995a19 100644 --- a/kmath-for-real/src/commonTest/kotlin/space/kscience/kmath/real/GridTest.kt +++ b/kmath-for-real/src/commonTest/kotlin/space/kscience/kmath/real/GridTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/Piecewise.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/Piecewise.kt index a9e75e456..8c02ee044 100644 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/Piecewise.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/Piecewise.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/Polynomial.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/Polynomial.kt index af84f47f2..ab9ed52b5 100644 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/Polynomial.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/Polynomial.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/functionTypes.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/functionTypes.kt index c2f95f040..6f2ba6c75 100644 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/functionTypes.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/functionTypes.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/polynomialConstructors.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/polynomialConstructors.kt index e07ff764c..dceef2b75 100644 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/polynomialConstructors.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/polynomialConstructors.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/polynomialUtil.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/polynomialUtil.kt index 0d4b93f03..31e2406fa 100644 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/polynomialUtil.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/functions/polynomialUtil.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/GaussIntegrator.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/GaussIntegrator.kt index f2ac0a296..fa0548f3d 100644 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/GaussIntegrator.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/GaussIntegrator.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ package space.kscience.kmath.integration diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/GaussIntegratorRuleFactory.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/GaussIntegratorRuleFactory.kt index 975fcd3a8..705979201 100644 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/GaussIntegratorRuleFactory.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/GaussIntegratorRuleFactory.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/Integrand.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/Integrand.kt index 40fe78898..d8c4ba587 100644 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/Integrand.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/Integrand.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/Integrator.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/Integrator.kt index 18c46b83b..95bbb56ed 100644 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/Integrator.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/Integrator.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/MultivariateIntegrand.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/MultivariateIntegrand.kt index 53a563086..e9a1f6549 100644 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/MultivariateIntegrand.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/MultivariateIntegrand.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/SimpsonIntegrator.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/SimpsonIntegrator.kt index 35ce82351..410351460 100644 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/SimpsonIntegrator.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/SimpsonIntegrator.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/SplineIntegrator.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/SplineIntegrator.kt index 1306e501f..6c1a8b234 100644 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/SplineIntegrator.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/SplineIntegrator.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/UnivariateIntegrand.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/UnivariateIntegrand.kt index e29a6c881..14b1db87c 100644 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/UnivariateIntegrand.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/UnivariateIntegrand.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/interpolation/Interpolator.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/interpolation/Interpolator.kt index 191e7dfd9..7dc90df67 100644 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/interpolation/Interpolator.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/interpolation/Interpolator.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/interpolation/LinearInterpolator.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/interpolation/LinearInterpolator.kt index 5c56e406a..e894799c9 100644 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/interpolation/LinearInterpolator.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/interpolation/LinearInterpolator.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/interpolation/SplineInterpolator.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/interpolation/SplineInterpolator.kt index ed4657d53..123bb7a9f 100644 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/interpolation/SplineInterpolator.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/interpolation/SplineInterpolator.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/functions/PolynomialTest.kt b/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/functions/PolynomialTest.kt index 3051cdd8d..c320212f3 100644 --- a/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/functions/PolynomialTest.kt +++ b/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/functions/PolynomialTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/functions/PolynomialUtilTest.kt b/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/functions/PolynomialUtilTest.kt index 48e641335..e91535506 100644 --- a/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/functions/PolynomialUtilTest.kt +++ b/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/functions/PolynomialUtilTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/functions/testUtils/IntModulo.kt b/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/functions/testUtils/IntModulo.kt index 3b7409e82..1f1e1a83f 100644 --- a/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/functions/testUtils/IntModulo.kt +++ b/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/functions/testUtils/IntModulo.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/functions/testUtils/IntModuloUtils.kt b/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/functions/testUtils/IntModuloUtils.kt index ffab2157c..ce9a0270c 100644 --- a/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/functions/testUtils/IntModuloUtils.kt +++ b/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/functions/testUtils/IntModuloUtils.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/functions/testUtils/Rational.kt b/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/functions/testUtils/Rational.kt index ff05805da..98150355c 100644 --- a/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/functions/testUtils/Rational.kt +++ b/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/functions/testUtils/Rational.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/functions/testUtils/misc.kt b/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/functions/testUtils/misc.kt index 61b50f128..267fae83b 100644 --- a/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/functions/testUtils/misc.kt +++ b/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/functions/testUtils/misc.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/integration/GaussIntegralTest.kt b/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/integration/GaussIntegralTest.kt index dd8069335..0e8f9ddfb 100644 --- a/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/integration/GaussIntegralTest.kt +++ b/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/integration/GaussIntegralTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/integration/SimpsonIntegralTest.kt b/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/integration/SimpsonIntegralTest.kt index f5a79cdea..eb8630c35 100644 --- a/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/integration/SimpsonIntegralTest.kt +++ b/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/integration/SimpsonIntegralTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/integration/SplineIntegralTest.kt b/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/integration/SplineIntegralTest.kt index 6b62afbd3..7e161f7c9 100644 --- a/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/integration/SplineIntegralTest.kt +++ b/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/integration/SplineIntegralTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ 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 24a664c26..c62d2c8bc 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 @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/interpolation/SplineInterpolatorTest.kt b/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/interpolation/SplineInterpolatorTest.kt index 774b6196e..8869a1f45 100644 --- a/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/interpolation/SplineInterpolatorTest.kt +++ b/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/interpolation/SplineInterpolatorTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/GeometrySpace.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/GeometrySpace.kt index d6d7e5725..8de914e7b 100644 --- a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/GeometrySpace.kt +++ b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/GeometrySpace.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Line.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Line.kt index 92d31a7cb..6d900ed37 100644 --- a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Line.kt +++ b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Line.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/ReferenceFrame.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/ReferenceFrame.kt index 21045e94e..f28bc6539 100644 --- a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/ReferenceFrame.kt +++ b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/ReferenceFrame.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Vector2D.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Vector2D.kt index 9eced7ba9..d1524584a 100644 --- a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Vector2D.kt +++ b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Vector2D.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2023 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Vector3D.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Vector3D.kt index 7e7c6c4ed..4fdbda2f2 100644 --- a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Vector3D.kt +++ b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Vector3D.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2023 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/angles.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/angles.kt index 3855514fb..d9c797d7e 100644 --- a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/angles.kt +++ b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/angles.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2021 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean2d/Circle2D.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean2d/Circle2D.kt index 1cf8d5dc2..e17a5573a 100644 --- a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean2d/Circle2D.kt +++ b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean2d/Circle2D.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2023 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean2d/Float32Space2D.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean2d/Float32Space2D.kt index 4dd188d49..d2e081bc2 100644 --- a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean2d/Float32Space2D.kt +++ b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean2d/Float32Space2D.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2023 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean2d/Float64Space2D.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean2d/Float64Space2D.kt index 423e43c30..aaec1ef50 100644 --- a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean2d/Float64Space2D.kt +++ b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean2d/Float64Space2D.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2023 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean2d/Polygon.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean2d/Polygon.kt index 85b377a56..8ed62a236 100644 --- a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean2d/Polygon.kt +++ b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean2d/Polygon.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2023 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean3d/Float32Space3D.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean3d/Float32Space3D.kt index 1413a885b..0d59aeed6 100644 --- a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean3d/Float32Space3D.kt +++ b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean3d/Float32Space3D.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2023 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean3d/Float64Space3D.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean3d/Float64Space3D.kt index a8c7e1d17..884ef64b1 100644 --- a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean3d/Float64Space3D.kt +++ b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean3d/Float64Space3D.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2023 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean3d/rotations3D.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean3d/rotations3D.kt index deb8b0a93..d7190fa29 100644 --- a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean3d/rotations3D.kt +++ b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean3d/rotations3D.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2023 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/floatPrecision.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/floatPrecision.kt index 2ed02182d..964f7f3e1 100644 --- a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/floatPrecision.kt +++ b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/floatPrecision.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2023 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/projections.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/projections.kt index c5c3487a1..962dc5ab1 100644 --- a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/projections.kt +++ b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/projections.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/quaternionOperations.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/quaternionOperations.kt index 859255004..cafa7f0da 100644 --- a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/quaternionOperations.kt +++ b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/quaternionOperations.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2023 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/AngleTest.kt b/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/AngleTest.kt index b8086eb75..d5209a1bd 100644 --- a/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/AngleTest.kt +++ b/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/AngleTest.kt @@ -1,3 +1,8 @@ +/* + * Copyright 2018-2024 KMath contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + package space.kscience.kmath.geometry import kotlin.test.Test diff --git a/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/Euclidean2DSpaceTest.kt b/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/Euclidean2DSpaceTest.kt index 7c5ee3485..2ad7c940f 100644 --- a/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/Euclidean2DSpaceTest.kt +++ b/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/Euclidean2DSpaceTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/Euclidean3DSpaceTest.kt b/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/Euclidean3DSpaceTest.kt index f881deb1b..64bdfcc61 100644 --- a/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/Euclidean3DSpaceTest.kt +++ b/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/Euclidean3DSpaceTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/ProjectionAlongTest.kt b/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/ProjectionAlongTest.kt index 9b3f40c4c..0c2267e8b 100644 --- a/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/ProjectionAlongTest.kt +++ b/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/ProjectionAlongTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/ProjectionOntoLineTest.kt b/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/ProjectionOntoLineTest.kt index d3a9d1171..32bd710c6 100644 --- a/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/ProjectionOntoLineTest.kt +++ b/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/ProjectionOntoLineTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/RotationTest.kt b/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/RotationTest.kt index 1d354bf72..cbe13a877 100644 --- a/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/RotationTest.kt +++ b/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/RotationTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/Vector2DTest.kt b/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/Vector2DTest.kt index af27b5e00..af886ec29 100644 --- a/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/Vector2DTest.kt +++ b/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/Vector2DTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/Vector3DTest.kt b/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/Vector3DTest.kt index b10e650a6..9157f95d8 100644 --- a/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/Vector3DTest.kt +++ b/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/Vector3DTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/testUtils.kt b/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/testUtils.kt index 521ce9e75..ebb72972d 100644 --- a/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/testUtils.kt +++ b/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/testUtils.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-geometry/src/jvmMain/kotlin/space/kscience/kmath/geometry/lineExtensions.kt b/kmath-geometry/src/jvmMain/kotlin/space/kscience/kmath/geometry/lineExtensions.kt index 5fcd2b23e..5a41b32d9 100644 --- a/kmath-geometry/src/jvmMain/kotlin/space/kscience/kmath/geometry/lineExtensions.kt +++ b/kmath-geometry/src/jvmMain/kotlin/space/kscience/kmath/geometry/lineExtensions.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2021 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ 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 3d948e1a7..acd889bf0 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 @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ 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 3303fa172..79f145792 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 @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/Histogram1D.kt b/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/Histogram1D.kt index f50610a17..ef72f2630 100644 --- a/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/Histogram1D.kt +++ b/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/Histogram1D.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/HistogramND.kt b/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/HistogramND.kt index 5fdc2ffb0..36acd8db5 100644 --- a/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/HistogramND.kt +++ b/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/HistogramND.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/UniformHistogram1D.kt b/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/UniformHistogram1D.kt index 154d35350..0326e8757 100644 --- a/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/UniformHistogram1D.kt +++ b/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/UniformHistogram1D.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/UniformHistogramGroupND.kt b/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/UniformHistogramGroupND.kt index f7094f7a9..57463e45d 100644 --- a/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/UniformHistogramGroupND.kt +++ b/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/UniformHistogramGroupND.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ 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 54806c9fa..f6c80a903 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,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-histograms/src/commonTest/kotlin/space/kscience/kmath/histogram/UniformHistogram1DTest.kt b/kmath-histograms/src/commonTest/kotlin/space/kscience/kmath/histogram/UniformHistogram1DTest.kt index bda9d2bea..e90dae0fc 100644 --- a/kmath-histograms/src/commonTest/kotlin/space/kscience/kmath/histogram/UniformHistogram1DTest.kt +++ b/kmath-histograms/src/commonTest/kotlin/space/kscience/kmath/histogram/UniformHistogram1DTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-histograms/src/jvmMain/kotlin/space/kscience/kmath/histogram/TreeHistogramGroup.kt b/kmath-histograms/src/jvmMain/kotlin/space/kscience/kmath/histogram/TreeHistogramGroup.kt index 772db7df3..95658141a 100644 --- a/kmath-histograms/src/jvmMain/kotlin/space/kscience/kmath/histogram/TreeHistogramGroup.kt +++ b/kmath-histograms/src/jvmMain/kotlin/space/kscience/kmath/histogram/TreeHistogramGroup.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-histograms/src/jvmTest/kotlin/space/kscience/kmath/histogram/TreeHistogramTest.kt b/kmath-histograms/src/jvmTest/kotlin/space/kscience/kmath/histogram/TreeHistogramTest.kt index 00b94c11f..25ffbbca5 100644 --- a/kmath-histograms/src/jvmTest/kotlin/space/kscience/kmath/histogram/TreeHistogramTest.kt +++ b/kmath-histograms/src/jvmTest/kotlin/space/kscience/kmath/histogram/TreeHistogramTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-jafama/src/main/kotlin/space/kscience/kmath/jafama/KMathJafama.kt b/kmath-jafama/src/main/kotlin/space/kscience/kmath/jafama/KMathJafama.kt index f9b8287b4..82811e0d5 100644 --- a/kmath-jafama/src/main/kotlin/space/kscience/kmath/jafama/KMathJafama.kt +++ b/kmath-jafama/src/main/kotlin/space/kscience/kmath/jafama/KMathJafama.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-jupyter/src/main/kotlin/space/kscience/kmath/jupyter/KMathJupyter.kt b/kmath-jupyter/src/main/kotlin/space/kscience/kmath/jupyter/KMathJupyter.kt index 944666c9e..36ce25c03 100644 --- a/kmath-jupyter/src/main/kotlin/space/kscience/kmath/jupyter/KMathJupyter.kt +++ b/kmath-jupyter/src/main/kotlin/space/kscience/kmath/jupyter/KMathJupyter.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-kotlingrad/src/main/kotlin/space/kscience/kmath/kotlingrad/KMathNumber.kt b/kmath-kotlingrad/src/main/kotlin/space/kscience/kmath/kotlingrad/KMathNumber.kt index cd35e0c42..c261e6f91 100644 --- a/kmath-kotlingrad/src/main/kotlin/space/kscience/kmath/kotlingrad/KMathNumber.kt +++ b/kmath-kotlingrad/src/main/kotlin/space/kscience/kmath/kotlingrad/KMathNumber.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-kotlingrad/src/main/kotlin/space/kscience/kmath/kotlingrad/KotlingradExpression.kt b/kmath-kotlingrad/src/main/kotlin/space/kscience/kmath/kotlingrad/KotlingradExpression.kt index 110572140..53e0beca1 100644 --- a/kmath-kotlingrad/src/main/kotlin/space/kscience/kmath/kotlingrad/KotlingradExpression.kt +++ b/kmath-kotlingrad/src/main/kotlin/space/kscience/kmath/kotlingrad/KotlingradExpression.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-kotlingrad/src/main/kotlin/space/kscience/kmath/kotlingrad/scalarsAdapters.kt b/kmath-kotlingrad/src/main/kotlin/space/kscience/kmath/kotlingrad/scalarsAdapters.kt index dd75a704c..363a698c6 100644 --- a/kmath-kotlingrad/src/main/kotlin/space/kscience/kmath/kotlingrad/scalarsAdapters.kt +++ b/kmath-kotlingrad/src/main/kotlin/space/kscience/kmath/kotlingrad/scalarsAdapters.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ 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 8d282a58a..f536e103d 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 @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-memory/src/commonMain/kotlin/space/kscience/kmath/annotations.kt b/kmath-memory/src/commonMain/kotlin/space/kscience/kmath/annotations.kt index a95b166cf..13db00968 100644 --- a/kmath-memory/src/commonMain/kotlin/space/kscience/kmath/annotations.kt +++ b/kmath-memory/src/commonMain/kotlin/space/kscience/kmath/annotations.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2023 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-memory/src/commonMain/kotlin/space/kscience/kmath/memory/Memory.kt b/kmath-memory/src/commonMain/kotlin/space/kscience/kmath/memory/Memory.kt index a63753015..c80eb1072 100644 --- a/kmath-memory/src/commonMain/kotlin/space/kscience/kmath/memory/Memory.kt +++ b/kmath-memory/src/commonMain/kotlin/space/kscience/kmath/memory/Memory.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-memory/src/commonMain/kotlin/space/kscience/kmath/memory/MemorySpec.kt b/kmath-memory/src/commonMain/kotlin/space/kscience/kmath/memory/MemorySpec.kt index 19bc3bae4..5e7db5d2d 100644 --- a/kmath-memory/src/commonMain/kotlin/space/kscience/kmath/memory/MemorySpec.kt +++ b/kmath-memory/src/commonMain/kotlin/space/kscience/kmath/memory/MemorySpec.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-memory/src/commonTest/kotlin/space/kscience/kmath/memory/MemoryTest.kt b/kmath-memory/src/commonTest/kotlin/space/kscience/kmath/memory/MemoryTest.kt index 3726ddbb7..6ca792839 100644 --- a/kmath-memory/src/commonTest/kotlin/space/kscience/kmath/memory/MemoryTest.kt +++ b/kmath-memory/src/commonTest/kotlin/space/kscience/kmath/memory/MemoryTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2023 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-memory/src/jsMain/kotlin/space/kscience/kmath/memory/DataViewMemory.kt b/kmath-memory/src/jsMain/kotlin/space/kscience/kmath/memory/DataViewMemory.kt index f8bcef010..f7badde37 100644 --- a/kmath-memory/src/jsMain/kotlin/space/kscience/kmath/memory/DataViewMemory.kt +++ b/kmath-memory/src/jsMain/kotlin/space/kscience/kmath/memory/DataViewMemory.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-memory/src/jvmMain/kotlin/space/kscience/kmath/memory/ByteBufferMemory.kt b/kmath-memory/src/jvmMain/kotlin/space/kscience/kmath/memory/ByteBufferMemory.kt index d022cab23..c240e512d 100644 --- a/kmath-memory/src/jvmMain/kotlin/space/kscience/kmath/memory/ByteBufferMemory.kt +++ b/kmath-memory/src/jvmMain/kotlin/space/kscience/kmath/memory/ByteBufferMemory.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-memory/src/nativeMain/kotlin/space/kscience/kmath/memory/NativeMemory.kt b/kmath-memory/src/nativeMain/kotlin/space/kscience/kmath/memory/NativeMemory.kt index 0ae3c7ebc..5edad57c4 100644 --- a/kmath-memory/src/nativeMain/kotlin/space/kscience/kmath/memory/NativeMemory.kt +++ b/kmath-memory/src/nativeMain/kotlin/space/kscience/kmath/memory/NativeMemory.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-memory/src/wasmJsMain/kotlin/space/kscience/kmath/memory/WasmDataViewMemory.kt b/kmath-memory/src/wasmJsMain/kotlin/space/kscience/kmath/memory/WasmDataViewMemory.kt index 0cff551fa..30172b8b1 100644 --- a/kmath-memory/src/wasmJsMain/kotlin/space/kscience/kmath/memory/WasmDataViewMemory.kt +++ b/kmath-memory/src/wasmJsMain/kotlin/space/kscience/kmath/memory/WasmDataViewMemory.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-multik/src/commonMain/kotlin/space/kscience/kmath/multik/MultikDoubleAlgebra.kt b/kmath-multik/src/commonMain/kotlin/space/kscience/kmath/multik/MultikDoubleAlgebra.kt index 8b463a230..bace8176e 100644 --- a/kmath-multik/src/commonMain/kotlin/space/kscience/kmath/multik/MultikDoubleAlgebra.kt +++ b/kmath-multik/src/commonMain/kotlin/space/kscience/kmath/multik/MultikDoubleAlgebra.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-multik/src/commonMain/kotlin/space/kscience/kmath/multik/MultikFloatAlgebra.kt b/kmath-multik/src/commonMain/kotlin/space/kscience/kmath/multik/MultikFloatAlgebra.kt index 7a3dda94b..fa91bb1d3 100644 --- a/kmath-multik/src/commonMain/kotlin/space/kscience/kmath/multik/MultikFloatAlgebra.kt +++ b/kmath-multik/src/commonMain/kotlin/space/kscience/kmath/multik/MultikFloatAlgebra.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-multik/src/commonMain/kotlin/space/kscience/kmath/multik/MultikIntAlgebra.kt b/kmath-multik/src/commonMain/kotlin/space/kscience/kmath/multik/MultikIntAlgebra.kt index 5bd1b3388..94d64c024 100644 --- a/kmath-multik/src/commonMain/kotlin/space/kscience/kmath/multik/MultikIntAlgebra.kt +++ b/kmath-multik/src/commonMain/kotlin/space/kscience/kmath/multik/MultikIntAlgebra.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-multik/src/commonMain/kotlin/space/kscience/kmath/multik/MultikLongAlgebra.kt b/kmath-multik/src/commonMain/kotlin/space/kscience/kmath/multik/MultikLongAlgebra.kt index 69a8ec042..e236b0d8b 100644 --- a/kmath-multik/src/commonMain/kotlin/space/kscience/kmath/multik/MultikLongAlgebra.kt +++ b/kmath-multik/src/commonMain/kotlin/space/kscience/kmath/multik/MultikLongAlgebra.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-multik/src/commonMain/kotlin/space/kscience/kmath/multik/MultikShortAlgebra.kt b/kmath-multik/src/commonMain/kotlin/space/kscience/kmath/multik/MultikShortAlgebra.kt index 7c8740665..7b5aa3417 100644 --- a/kmath-multik/src/commonMain/kotlin/space/kscience/kmath/multik/MultikShortAlgebra.kt +++ b/kmath-multik/src/commonMain/kotlin/space/kscience/kmath/multik/MultikShortAlgebra.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-multik/src/commonMain/kotlin/space/kscience/kmath/multik/MultikTensor.kt b/kmath-multik/src/commonMain/kotlin/space/kscience/kmath/multik/MultikTensor.kt index 59a9a1bf3..9dfed2d58 100644 --- a/kmath-multik/src/commonMain/kotlin/space/kscience/kmath/multik/MultikTensor.kt +++ b/kmath-multik/src/commonMain/kotlin/space/kscience/kmath/multik/MultikTensor.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-multik/src/commonMain/kotlin/space/kscience/kmath/multik/MultikTensorAlgebra.kt b/kmath-multik/src/commonMain/kotlin/space/kscience/kmath/multik/MultikTensorAlgebra.kt index c3a82b167..e78ef6616 100644 --- a/kmath-multik/src/commonMain/kotlin/space/kscience/kmath/multik/MultikTensorAlgebra.kt +++ b/kmath-multik/src/commonMain/kotlin/space/kscience/kmath/multik/MultikTensorAlgebra.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-multik/src/commonTest/kotlin/space/kscience/kmath/multik/MultikNDTest.kt b/kmath-multik/src/commonTest/kotlin/space/kscience/kmath/multik/MultikNDTest.kt index 1abcf512d..fff88c70b 100644 --- a/kmath-multik/src/commonTest/kotlin/space/kscience/kmath/multik/MultikNDTest.kt +++ b/kmath-multik/src/commonTest/kotlin/space/kscience/kmath/multik/MultikNDTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ 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 31523b340..8b88048ae 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 @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ 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 fedad26e0..0a2305e71 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 @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ 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 93fbc8f85..34bbcaefb 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 @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-nd4j/src/main/kotlin/space/kscience/kmath/nd4j/Nd4jTensorAlgebra.kt b/kmath-nd4j/src/main/kotlin/space/kscience/kmath/nd4j/Nd4jTensorAlgebra.kt index c308e64b9..aba262f91 100644 --- a/kmath-nd4j/src/main/kotlin/space/kscience/kmath/nd4j/Nd4jTensorAlgebra.kt +++ b/kmath-nd4j/src/main/kotlin/space/kscience/kmath/nd4j/Nd4jTensorAlgebra.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-nd4j/src/main/kotlin/space/kscience/kmath/nd4j/arrays.kt b/kmath-nd4j/src/main/kotlin/space/kscience/kmath/nd4j/arrays.kt index 401c57a7b..8f02f3c55 100644 --- a/kmath-nd4j/src/main/kotlin/space/kscience/kmath/nd4j/arrays.kt +++ b/kmath-nd4j/src/main/kotlin/space/kscience/kmath/nd4j/arrays.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ 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 484618de2..704b28cd9 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 @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ 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 d57eb2e2d..5c3664cb3 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 @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/FunctionOptimization.kt b/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/FunctionOptimization.kt index 07146625c..a0723c389 100644 --- a/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/FunctionOptimization.kt +++ b/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/FunctionOptimization.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/OptimizationBuilder.kt b/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/OptimizationBuilder.kt index 0459d46ee..44d67f1ab 100644 --- a/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/OptimizationBuilder.kt +++ b/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/OptimizationBuilder.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/OptimizationProblem.kt b/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/OptimizationProblem.kt index 9fdcfc53d..73e36d012 100644 --- a/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/OptimizationProblem.kt +++ b/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/OptimizationProblem.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/Optimizer.kt b/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/Optimizer.kt index 41dcbf770..ed8242929 100644 --- a/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/Optimizer.kt +++ b/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/Optimizer.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/QowOptimizer.kt b/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/QowOptimizer.kt index e922fd423..53c50f690 100644 --- a/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/QowOptimizer.kt +++ b/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/QowOptimizer.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/XYFit.kt b/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/XYFit.kt index 9e5396491..d4c3c7ff7 100644 --- a/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/XYFit.kt +++ b/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/XYFit.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @file:OptIn(UnstableKMathAPI::class) diff --git a/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/logLikelihood.kt b/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/logLikelihood.kt index 8ab9de48d..74ed6fddb 100644 --- a/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/logLikelihood.kt +++ b/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/logLikelihood.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/distributions/Distribution.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/distributions/Distribution.kt index 806da5560..979c7a002 100644 --- a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/distributions/Distribution.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/distributions/Distribution.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/distributions/FactorizedDistribution.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/distributions/FactorizedDistribution.kt index 999fbffbc..8f5a378bb 100644 --- a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/distributions/FactorizedDistribution.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/distributions/FactorizedDistribution.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/distributions/NormalDistribution.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/distributions/NormalDistribution.kt index 10947b732..ccd894f09 100644 --- a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/distributions/NormalDistribution.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/distributions/NormalDistribution.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/distributions/UniformDistribution.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/distributions/UniformDistribution.kt index 953be06fd..d0f13398c 100644 --- a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/distributions/UniformDistribution.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/distributions/UniformDistribution.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/random/MCScope.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/random/MCScope.kt index 2049a84fc..149b5d85d 100644 --- a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/random/MCScope.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/random/MCScope.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/random/RandomChain.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/random/RandomChain.kt index 1cc409393..5d175c5ae 100644 --- a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/random/RandomChain.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/random/RandomChain.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/random/RandomGenerator.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/random/RandomGenerator.kt index ece6bfcc1..8d8fd8612 100644 --- a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/random/RandomGenerator.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/random/RandomGenerator.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/AhrensDieterExponentialSampler.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/AhrensDieterExponentialSampler.kt index 04e1221ca..0276cd654 100644 --- a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/AhrensDieterExponentialSampler.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/AhrensDieterExponentialSampler.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/AhrensDieterMarsagliaTsangGammaSampler.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/AhrensDieterMarsagliaTsangGammaSampler.kt index d301ff637..05163387d 100644 --- a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/AhrensDieterMarsagliaTsangGammaSampler.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/AhrensDieterMarsagliaTsangGammaSampler.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/AliasMethodDiscreteSampler.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/AliasMethodDiscreteSampler.kt index 2ec40c347..f65e8585b 100644 --- a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/AliasMethodDiscreteSampler.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/AliasMethodDiscreteSampler.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/BoxMullerSampler.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/BoxMullerSampler.kt index c8ee745dd..9f90d1626 100644 --- a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/BoxMullerSampler.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/BoxMullerSampler.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/GaussianSampler.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/GaussianSampler.kt index 28d588165..c86c6aa35 100644 --- a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/GaussianSampler.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/GaussianSampler.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/InternalErf.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/InternalErf.kt index 0c1a5b36f..c28b4be50 100644 --- a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/InternalErf.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/InternalErf.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/InternalGamma.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/InternalGamma.kt index 43c5a0d3c..ef4a97066 100644 --- a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/InternalGamma.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/InternalGamma.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/InternalUtils.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/InternalUtils.kt index 9f633e3db..cbc361b56 100644 --- a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/InternalUtils.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/InternalUtils.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/KempSmallMeanPoissonSampler.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/KempSmallMeanPoissonSampler.kt index 44834b5bf..7a076d849 100644 --- a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/KempSmallMeanPoissonSampler.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/KempSmallMeanPoissonSampler.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/MarsagliaNormalizedGaussianSampler.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/MarsagliaNormalizedGaussianSampler.kt index 961883af5..b1343a4ca 100644 --- a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/MarsagliaNormalizedGaussianSampler.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/MarsagliaNormalizedGaussianSampler.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/NormalizedGaussianSampler.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/NormalizedGaussianSampler.kt index 291d0bffe..81d1edb47 100644 --- a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/NormalizedGaussianSampler.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/NormalizedGaussianSampler.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/PoissonSampler.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/PoissonSampler.kt index 964a57178..8faaf33dc 100644 --- a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/PoissonSampler.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/PoissonSampler.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/Sampler.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/Sampler.kt index 34355dca7..8fc1ff82f 100644 --- a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/Sampler.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/Sampler.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/SamplerAlgebra.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/SamplerAlgebra.kt index 44b87a431..0de8bce99 100644 --- a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/SamplerAlgebra.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/SamplerAlgebra.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/ZigguratNormalizedGaussianSampler.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/ZigguratNormalizedGaussianSampler.kt index 062894c90..db04d94bd 100644 --- a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/ZigguratNormalizedGaussianSampler.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/ZigguratNormalizedGaussianSampler.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/series/MonotonicSeriesAlgebra.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/series/MonotonicSeriesAlgebra.kt index ed6f4e07b..bd77974d1 100644 --- a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/series/MonotonicSeriesAlgebra.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/series/MonotonicSeriesAlgebra.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2023 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/series/SeriesAlgebra.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/series/SeriesAlgebra.kt index cabff25e6..6790f44e0 100644 --- a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/series/SeriesAlgebra.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/series/SeriesAlgebra.kt @@ -1,3 +1,8 @@ +/* + * Copyright 2018-2024 KMath contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + package space.kscience.kmath.series import space.kscience.kmath.operations.BufferAlgebra diff --git a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/series/VarianceRatioTest.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/series/VarianceRatioTest.kt index 6cd64df9c..337b13020 100644 --- a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/series/VarianceRatioTest.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/series/VarianceRatioTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2023 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/series/resampling.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/series/resampling.kt index dc21fe6d9..9931429e7 100644 --- a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/series/resampling.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/series/resampling.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2023 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/series/seriesExtensions.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/series/seriesExtensions.kt index fa5e0addd..92e3cf534 100644 --- a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/series/seriesExtensions.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/series/seriesExtensions.kt @@ -1,3 +1,8 @@ +/* + * Copyright 2018-2024 KMath contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + package space.kscience.kmath.series import space.kscience.kmath.operations.BufferAlgebra diff --git a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/Mean.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/Mean.kt index 74ef65fa1..843b06f2c 100644 --- a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/Mean.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/Mean.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/Median.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/Median.kt index dc504f0b7..f0328839f 100644 --- a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/Median.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/Median.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/Rank.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/Rank.kt index 5a873b466..cb309663e 100644 --- a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/Rank.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/Rank.kt @@ -1,3 +1,8 @@ +/* + * Copyright 2018-2024 KMath contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + package space.kscience.kmath.stat import space.kscience.kmath.operations.asIterable 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 7cb40a91a..81ed258f7 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 @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/StatisticalAlgebra.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/StatisticalAlgebra.kt index cce61519b..9f0491b4b 100644 --- a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/StatisticalAlgebra.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/StatisticalAlgebra.kt @@ -1,3 +1,8 @@ +/* + * Copyright 2018-2024 KMath contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + package space.kscience.kmath.stat import space.kscience.kmath.UnstableKMathAPI diff --git a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/ValueAndErrorField.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/ValueAndErrorField.kt index 38cd5f900..7e0794ee9 100644 --- a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/ValueAndErrorField.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/ValueAndErrorField.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/chiSquaredExpression.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/chiSquaredExpression.kt index ca9755ad5..c42f149f2 100644 --- a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/chiSquaredExpression.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/chiSquaredExpression.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2023 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-stat/src/commonTest/kotlin/space/kscience/kmath/series/TestSeries.kt b/kmath-stat/src/commonTest/kotlin/space/kscience/kmath/series/TestSeries.kt index d83abb3f4..68c5af6fb 100644 --- a/kmath-stat/src/commonTest/kotlin/space/kscience/kmath/series/TestSeries.kt +++ b/kmath-stat/src/commonTest/kotlin/space/kscience/kmath/series/TestSeries.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2023 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-stat/src/commonTest/kotlin/space/kscience/kmath/series/TestVarianceRatioTest.kt b/kmath-stat/src/commonTest/kotlin/space/kscience/kmath/series/TestVarianceRatioTest.kt index afc0d541d..b5ac44bc6 100644 --- a/kmath-stat/src/commonTest/kotlin/space/kscience/kmath/series/TestVarianceRatioTest.kt +++ b/kmath-stat/src/commonTest/kotlin/space/kscience/kmath/series/TestVarianceRatioTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2023 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-stat/src/commonTest/kotlin/space/kscience/kmath/stat/TestBasicStatistics.kt b/kmath-stat/src/commonTest/kotlin/space/kscience/kmath/stat/TestBasicStatistics.kt index 306574a76..0efc3c269 100644 --- a/kmath-stat/src/commonTest/kotlin/space/kscience/kmath/stat/TestBasicStatistics.kt +++ b/kmath-stat/src/commonTest/kotlin/space/kscience/kmath/stat/TestBasicStatistics.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2023 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-stat/src/jvmMain/kotlin/space/kscience/kmath/stat/RandomSourceGenerator.kt b/kmath-stat/src/jvmMain/kotlin/space/kscience/kmath/stat/RandomSourceGenerator.kt index 2c6391612..8badbce64 100644 --- a/kmath-stat/src/jvmMain/kotlin/space/kscience/kmath/stat/RandomSourceGenerator.kt +++ b/kmath-stat/src/jvmMain/kotlin/space/kscience/kmath/stat/RandomSourceGenerator.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-stat/src/jvmTest/kotlin/space/kscience/kmath/stat/CommonsDistributionsTest.kt b/kmath-stat/src/jvmTest/kotlin/space/kscience/kmath/stat/CommonsDistributionsTest.kt index b9b9dadba..227214d63 100644 --- a/kmath-stat/src/jvmTest/kotlin/space/kscience/kmath/stat/CommonsDistributionsTest.kt +++ b/kmath-stat/src/jvmTest/kotlin/space/kscience/kmath/stat/CommonsDistributionsTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-stat/src/jvmTest/kotlin/space/kscience/kmath/stat/MCScopeTest.kt b/kmath-stat/src/jvmTest/kotlin/space/kscience/kmath/stat/MCScopeTest.kt index dbcf32e27..545e89814 100644 --- a/kmath-stat/src/jvmTest/kotlin/space/kscience/kmath/stat/MCScopeTest.kt +++ b/kmath-stat/src/jvmTest/kotlin/space/kscience/kmath/stat/MCScopeTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-stat/src/jvmTest/kotlin/space/kscience/kmath/stat/SamplerTest.kt b/kmath-stat/src/jvmTest/kotlin/space/kscience/kmath/stat/SamplerTest.kt index 0076006e6..fd2db98ae 100644 --- a/kmath-stat/src/jvmTest/kotlin/space/kscience/kmath/stat/SamplerTest.kt +++ b/kmath-stat/src/jvmTest/kotlin/space/kscience/kmath/stat/SamplerTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-stat/src/jvmTest/kotlin/space/kscience/kmath/stat/StatisticTest.kt b/kmath-stat/src/jvmTest/kotlin/space/kscience/kmath/stat/StatisticTest.kt index d64dcea4d..fb9a4351a 100644 --- a/kmath-stat/src/jvmTest/kotlin/space/kscience/kmath/stat/StatisticTest.kt +++ b/kmath-stat/src/jvmTest/kotlin/space/kscience/kmath/stat/StatisticTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-symja/src/main/kotlin/space/kscience/kmath/symja/SymjaExpression.kt b/kmath-symja/src/main/kotlin/space/kscience/kmath/symja/SymjaExpression.kt index 0f8014913..e5ba411e6 100644 --- a/kmath-symja/src/main/kotlin/space/kscience/kmath/symja/SymjaExpression.kt +++ b/kmath-symja/src/main/kotlin/space/kscience/kmath/symja/SymjaExpression.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-symja/src/main/kotlin/space/kscience/kmath/symja/adapters.kt b/kmath-symja/src/main/kotlin/space/kscience/kmath/symja/adapters.kt index 92f2474b8..9590f2246 100644 --- a/kmath-symja/src/main/kotlin/space/kscience/kmath/symja/adapters.kt +++ b/kmath-symja/src/main/kotlin/space/kscience/kmath/symja/adapters.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-tensorflow/src/main/kotlin/space/kscience/kmath/tensorflow/DoubleTensorFlowAlgebra.kt b/kmath-tensorflow/src/main/kotlin/space/kscience/kmath/tensorflow/DoubleTensorFlowAlgebra.kt index 027318f99..d066669fd 100644 --- a/kmath-tensorflow/src/main/kotlin/space/kscience/kmath/tensorflow/DoubleTensorFlowAlgebra.kt +++ b/kmath-tensorflow/src/main/kotlin/space/kscience/kmath/tensorflow/DoubleTensorFlowAlgebra.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-tensorflow/src/main/kotlin/space/kscience/kmath/tensorflow/IntTensorFlowAlgebra.kt b/kmath-tensorflow/src/main/kotlin/space/kscience/kmath/tensorflow/IntTensorFlowAlgebra.kt index 01c8054b3..186a794e9 100644 --- a/kmath-tensorflow/src/main/kotlin/space/kscience/kmath/tensorflow/IntTensorFlowAlgebra.kt +++ b/kmath-tensorflow/src/main/kotlin/space/kscience/kmath/tensorflow/IntTensorFlowAlgebra.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-tensorflow/src/main/kotlin/space/kscience/kmath/tensorflow/TensorFlowAlgebra.kt b/kmath-tensorflow/src/main/kotlin/space/kscience/kmath/tensorflow/TensorFlowAlgebra.kt index 73b36cd67..158c928c4 100644 --- a/kmath-tensorflow/src/main/kotlin/space/kscience/kmath/tensorflow/TensorFlowAlgebra.kt +++ b/kmath-tensorflow/src/main/kotlin/space/kscience/kmath/tensorflow/TensorFlowAlgebra.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-tensorflow/src/main/kotlin/space/kscience/kmath/tensorflow/tfOperations.kt b/kmath-tensorflow/src/main/kotlin/space/kscience/kmath/tensorflow/tfOperations.kt index a0a2ddc80..885b9fca6 100644 --- a/kmath-tensorflow/src/main/kotlin/space/kscience/kmath/tensorflow/tfOperations.kt +++ b/kmath-tensorflow/src/main/kotlin/space/kscience/kmath/tensorflow/tfOperations.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-tensorflow/src/test/kotlin/space/kscience/kmath/tensorflow/DoubleTensorFlowOps.kt b/kmath-tensorflow/src/test/kotlin/space/kscience/kmath/tensorflow/DoubleTensorFlowOps.kt index fe950f334..dd4f620c4 100644 --- a/kmath-tensorflow/src/test/kotlin/space/kscience/kmath/tensorflow/DoubleTensorFlowOps.kt +++ b/kmath-tensorflow/src/test/kotlin/space/kscience/kmath/tensorflow/DoubleTensorFlowOps.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/api/AnalyticTensorAlgebra.kt b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/api/AnalyticTensorAlgebra.kt index 1a324b200..a986edfa5 100644 --- a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/api/AnalyticTensorAlgebra.kt +++ b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/api/AnalyticTensorAlgebra.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/api/LinearOpsTensorAlgebra.kt b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/api/LinearOpsTensorAlgebra.kt index f2c7f1821..f9f0ed832 100644 --- a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/api/LinearOpsTensorAlgebra.kt +++ b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/api/LinearOpsTensorAlgebra.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/api/Tensor.kt b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/api/Tensor.kt index b328fbeec..2a7f463bc 100644 --- a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/api/Tensor.kt +++ b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/api/Tensor.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/api/TensorAlgebra.kt b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/api/TensorAlgebra.kt index f923400c5..6e515f3f8 100644 --- a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/api/TensorAlgebra.kt +++ b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/api/TensorAlgebra.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/api/TensorPartialDivisionAlgebra.kt b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/api/TensorPartialDivisionAlgebra.kt index 33effb2d2..df8c32007 100644 --- a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/api/TensorPartialDivisionAlgebra.kt +++ b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/api/TensorPartialDivisionAlgebra.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/BroadcastDoubleTensorAlgebra.kt b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/BroadcastDoubleTensorAlgebra.kt index 662469bf3..d02a9f99e 100644 --- a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/BroadcastDoubleTensorAlgebra.kt +++ b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/BroadcastDoubleTensorAlgebra.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/BufferedTensor.kt b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/BufferedTensor.kt index eaec43e2c..a595c94f5 100644 --- a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/BufferedTensor.kt +++ b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/BufferedTensor.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/DoubleTensor.kt b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/DoubleTensor.kt index 8a97114c3..b51f47e4e 100644 --- a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/DoubleTensor.kt +++ b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/DoubleTensor.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/DoubleTensor1D.kt b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/DoubleTensor1D.kt index d2066e404..74a4f65c4 100644 --- a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/DoubleTensor1D.kt +++ b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/DoubleTensor1D.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/DoubleTensor2D.kt b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/DoubleTensor2D.kt index fa142afa0..013dfe791 100644 --- a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/DoubleTensor2D.kt +++ b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/DoubleTensor2D.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/DoubleTensorAlgebra.kt b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/DoubleTensorAlgebra.kt index 334a27c5b..af668bc5a 100644 --- a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/DoubleTensorAlgebra.kt +++ b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/DoubleTensorAlgebra.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/IntTensor.kt b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/IntTensor.kt index 1066793a7..bd84737c5 100644 --- a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/IntTensor.kt +++ b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/IntTensor.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/IntTensorAlgebra.kt b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/IntTensorAlgebra.kt index a09351b85..39698d187 100644 --- a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/IntTensorAlgebra.kt +++ b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/IntTensorAlgebra.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/LevenbergMarquardtAlgorithm.kt b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/LevenbergMarquardtAlgorithm.kt index fc87ad1f3..15fcdfc07 100644 --- a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/LevenbergMarquardtAlgorithm.kt +++ b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/LevenbergMarquardtAlgorithm.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2023 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/internal/broadcastUtils.kt b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/internal/broadcastUtils.kt index 1e87e6620..3596cbaf8 100644 --- a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/internal/broadcastUtils.kt +++ b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/internal/broadcastUtils.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/internal/checks.kt b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/internal/checks.kt index f384ed462..1a0aa29d1 100644 --- a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/internal/checks.kt +++ b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/internal/checks.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/internal/doubleTensorHelpers.kt b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/internal/doubleTensorHelpers.kt index 0c1ffdbf3..4750dbea2 100644 --- a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/internal/doubleTensorHelpers.kt +++ b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/internal/doubleTensorHelpers.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/internal/intTensorHelpers.kt b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/internal/intTensorHelpers.kt index c47d94a92..14ab35883 100644 --- a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/internal/intTensorHelpers.kt +++ b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/internal/intTensorHelpers.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/internal/linUtils.kt b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/internal/linUtils.kt index 272af41d5..54df7d241 100644 --- a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/internal/linUtils.kt +++ b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/internal/linUtils.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/internal/utils.kt b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/internal/utils.kt index d48086d57..4dc6b8517 100644 --- a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/internal/utils.kt +++ b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/internal/utils.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/tensorAlgebraExtensions.kt b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/tensorAlgebraExtensions.kt index e2b7c23e6..841c51244 100644 --- a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/tensorAlgebraExtensions.kt +++ b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/tensorAlgebraExtensions.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/tensorOps.kt b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/tensorOps.kt index 1b630a0ef..2c35f8196 100644 --- a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/tensorOps.kt +++ b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/tensorOps.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/tensorTransform.kt b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/tensorTransform.kt index 52a530652..bafd3fadd 100644 --- a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/tensorTransform.kt +++ b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/tensorTransform.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-tensors/src/commonTest/kotlin/space/kscience/kmath/tensors/core/TestBroadcasting.kt b/kmath-tensors/src/commonTest/kotlin/space/kscience/kmath/tensors/core/TestBroadcasting.kt index 73aed8a7b..f930cf94c 100644 --- a/kmath-tensors/src/commonTest/kotlin/space/kscience/kmath/tensors/core/TestBroadcasting.kt +++ b/kmath-tensors/src/commonTest/kotlin/space/kscience/kmath/tensors/core/TestBroadcasting.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-tensors/src/commonTest/kotlin/space/kscience/kmath/tensors/core/TestDoubleAnalyticTensorAlgebra.kt b/kmath-tensors/src/commonTest/kotlin/space/kscience/kmath/tensors/core/TestDoubleAnalyticTensorAlgebra.kt index e4c2c40ea..7fd011986 100644 --- a/kmath-tensors/src/commonTest/kotlin/space/kscience/kmath/tensors/core/TestDoubleAnalyticTensorAlgebra.kt +++ b/kmath-tensors/src/commonTest/kotlin/space/kscience/kmath/tensors/core/TestDoubleAnalyticTensorAlgebra.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-tensors/src/commonTest/kotlin/space/kscience/kmath/tensors/core/TestDoubleLinearOpsAlgebra.kt b/kmath-tensors/src/commonTest/kotlin/space/kscience/kmath/tensors/core/TestDoubleLinearOpsAlgebra.kt index cbd7b9887..1c500af8b 100644 --- a/kmath-tensors/src/commonTest/kotlin/space/kscience/kmath/tensors/core/TestDoubleLinearOpsAlgebra.kt +++ b/kmath-tensors/src/commonTest/kotlin/space/kscience/kmath/tensors/core/TestDoubleLinearOpsAlgebra.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-tensors/src/commonTest/kotlin/space/kscience/kmath/tensors/core/TestDoubleTensor.kt b/kmath-tensors/src/commonTest/kotlin/space/kscience/kmath/tensors/core/TestDoubleTensor.kt index 3081639af..59676c122 100644 --- a/kmath-tensors/src/commonTest/kotlin/space/kscience/kmath/tensors/core/TestDoubleTensor.kt +++ b/kmath-tensors/src/commonTest/kotlin/space/kscience/kmath/tensors/core/TestDoubleTensor.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-tensors/src/commonTest/kotlin/space/kscience/kmath/tensors/core/TestDoubleTensorAlgebra.kt b/kmath-tensors/src/commonTest/kotlin/space/kscience/kmath/tensors/core/TestDoubleTensorAlgebra.kt index 7222fc7a6..4f58846aa 100644 --- a/kmath-tensors/src/commonTest/kotlin/space/kscience/kmath/tensors/core/TestDoubleTensorAlgebra.kt +++ b/kmath-tensors/src/commonTest/kotlin/space/kscience/kmath/tensors/core/TestDoubleTensorAlgebra.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-tensors/src/commonTest/kotlin/space/kscience/kmath/tensors/core/offsetBufferEquality.kt b/kmath-tensors/src/commonTest/kotlin/space/kscience/kmath/tensors/core/offsetBufferEquality.kt index c3127ed97..38c51d66e 100644 --- a/kmath-tensors/src/commonTest/kotlin/space/kscience/kmath/tensors/core/offsetBufferEquality.kt +++ b/kmath-tensors/src/commonTest/kotlin/space/kscience/kmath/tensors/core/offsetBufferEquality.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-tensors/src/jvmTest/kotlin/space/kscience/kmath/tensors/core/TestLmAlgorithm.kt b/kmath-tensors/src/jvmTest/kotlin/space/kscience/kmath/tensors/core/TestLmAlgorithm.kt index 0d0332395..6c072d52b 100644 --- a/kmath-tensors/src/jvmTest/kotlin/space/kscience/kmath/tensors/core/TestLmAlgorithm.kt +++ b/kmath-tensors/src/jvmTest/kotlin/space/kscience/kmath/tensors/core/TestLmAlgorithm.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2023 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-viktor/src/main/kotlin/space/kscience/kmath/viktor/ViktorBuffer.kt b/kmath-viktor/src/main/kotlin/space/kscience/kmath/viktor/ViktorBuffer.kt index 52dc1e192..2b5741ed4 100644 --- a/kmath-viktor/src/main/kotlin/space/kscience/kmath/viktor/ViktorBuffer.kt +++ b/kmath-viktor/src/main/kotlin/space/kscience/kmath/viktor/ViktorBuffer.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/kmath-viktor/src/main/kotlin/space/kscience/kmath/viktor/ViktorFieldOpsND.kt b/kmath-viktor/src/main/kotlin/space/kscience/kmath/viktor/ViktorFieldOpsND.kt index f93066423..11cf543d6 100644 --- a/kmath-viktor/src/main/kotlin/space/kscience/kmath/viktor/ViktorFieldOpsND.kt +++ b/kmath-viktor/src/main/kotlin/space/kscience/kmath/viktor/ViktorFieldOpsND.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ 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 7c0c02086..328a0ab01 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 @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/test-utils/src/commonMain/kotlin/AlgebraicVerifier.kt b/test-utils/src/commonMain/kotlin/AlgebraicVerifier.kt index 261e74f5a..33e7b5972 100644 --- a/test-utils/src/commonMain/kotlin/AlgebraicVerifier.kt +++ b/test-utils/src/commonMain/kotlin/AlgebraicVerifier.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/test-utils/src/commonMain/kotlin/FieldVerifier.kt b/test-utils/src/commonMain/kotlin/FieldVerifier.kt index a03ca0a27..3b3acd32c 100644 --- a/test-utils/src/commonMain/kotlin/FieldVerifier.kt +++ b/test-utils/src/commonMain/kotlin/FieldVerifier.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/test-utils/src/commonMain/kotlin/RingVerifier.kt b/test-utils/src/commonMain/kotlin/RingVerifier.kt index c40075d93..0a1237b60 100644 --- a/test-utils/src/commonMain/kotlin/RingVerifier.kt +++ b/test-utils/src/commonMain/kotlin/RingVerifier.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/test-utils/src/commonMain/kotlin/SpaceVerifier.kt b/test-utils/src/commonMain/kotlin/SpaceVerifier.kt index 01c02997b..ae805db5a 100644 --- a/test-utils/src/commonMain/kotlin/SpaceVerifier.kt +++ b/test-utils/src/commonMain/kotlin/SpaceVerifier.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/test-utils/src/commonMain/kotlin/asserts.kt b/test-utils/src/commonMain/kotlin/asserts.kt index 8ddce517c..54c6301b6 100644 --- a/test-utils/src/commonMain/kotlin/asserts.kt +++ b/test-utils/src/commonMain/kotlin/asserts.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/test-utils/src/commonMain/kotlin/bufferEquality.kt b/test-utils/src/commonMain/kotlin/bufferEquality.kt index c4485abbd..5b2ef6e76 100644 --- a/test-utils/src/commonMain/kotlin/bufferEquality.kt +++ b/test-utils/src/commonMain/kotlin/bufferEquality.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 KMath contributors. + * Copyright 2018-2024 KMath contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ From c6f6191ef1701d5101544a81b37be5867f3ee686 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sun, 28 Jan 2024 18:15:33 +0300 Subject: [PATCH 20/40] Deprecate direct angle conversion --- .../src/main/kotlin/space/kscience/kmath/ejml/_generated.kt | 1 - .../commonMain/kotlin/space/kscience/kmath/geometry/angles.kt | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/_generated.kt b/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/_generated.kt index 3a44a9e64..2948e990c 100644 --- a/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/_generated.kt +++ b/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/_generated.kt @@ -23,7 +23,6 @@ import space.kscience.attributes.SafeType import space.kscience.attributes.safeTypeOf import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.linear.* -import space.kscience.kmath.linear.Matrix import space.kscience.kmath.nd.StructureFeature import space.kscience.kmath.operations.Float32Field import space.kscience.kmath.operations.Float64Field diff --git a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/angles.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/angles.kt index 3855514fb..82a0424eb 100644 --- a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/angles.kt +++ b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/angles.kt @@ -74,6 +74,7 @@ public fun tan(angle: Angle): Double = kotlin.math.tan(angle.toRadians().value) public val Number.radians: Radians get() = Radians(toDouble()) +@Deprecated("Convert to radians", ReplaceWith("toRadians().value")) public val Angle.radians: Double get() = toRadians().value /** @@ -98,6 +99,7 @@ public value class Degrees(public val value: Double) : Angle { public val Number.degrees: Degrees get() = Degrees(toDouble()) +@Deprecated("Convert to degrees", ReplaceWith("toDegrees().value")) public val Angle.degrees: Double get() = toDegrees().value /** From 8a754ace199d84959978b78fb1b175595a1d7af3 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Wed, 7 Feb 2024 21:18:47 +0300 Subject: [PATCH 21/40] Fixed GitHub #524 (Complex power of real-valued number --- CHANGELOG.md | 1 + .../space/kscience/kmath/complex/Complex.kt | 15 +++++++++++- .../kmath/complex/ComplexFieldTest.kt | 23 ++++++++++--------- 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c6523a0d..0bc556671 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ ### Fixed - Median statistics +- Complex power of negative real numbers ### Security diff --git a/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/Complex.kt b/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/Complex.kt index b5f1aabe7..08c44e036 100644 --- a/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/Complex.kt +++ b/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/Complex.kt @@ -129,13 +129,25 @@ public object ComplexField : } override fun power(arg: Complex, pow: Number): Complex = if (arg.im == 0.0) { - arg.re.pow(pow.toDouble()).toComplex() + val powDouble = pow.toDouble() + when { + arg.re > 0 -> arg.re.pow(powDouble).toComplex() + arg.re < 0 -> i * (-arg.re).pow(powDouble) + else -> if (powDouble == 0.0) { + one + } else { + zero + } + } + } else { exp(pow * ln(arg)) } public fun power(arg: Complex, pow: Complex): Complex = exp(pow * ln(arg)) + public fun Complex.pow(power: Complex): Complex = power(this, power) + override fun exp(arg: Complex): Complex = exp(arg.re) * (cos(arg.im) + i * sin(arg.im)) @@ -189,6 +201,7 @@ public object ComplexField : override fun norm(arg: Complex): Complex = sqrt(arg.conjugate * arg) } + /** * Represents `double`-based complex number. * diff --git a/kmath-complex/src/commonTest/kotlin/space/kscience/kmath/complex/ComplexFieldTest.kt b/kmath-complex/src/commonTest/kotlin/space/kscience/kmath/complex/ComplexFieldTest.kt index e11f1c1ea..a545a0792 100644 --- a/kmath-complex/src/commonTest/kotlin/space/kscience/kmath/complex/ComplexFieldTest.kt +++ b/kmath-complex/src/commonTest/kotlin/space/kscience/kmath/complex/ComplexFieldTest.kt @@ -58,24 +58,25 @@ internal class ComplexFieldTest { } @Test - fun testInverseHyperbolicSine() { - assertEquals( - ComplexField { i * PI.toComplex() / 2 }, - ComplexField { asinh(i) }) + fun testInverseHyperbolicSine() = ComplexField { + assertEquals(i * PI.toComplex() / 2, asinh(i)) } @Test - fun testPower() { - assertEquals(ComplexField.zero, ComplexField { zero pow 2 }) - assertEquals(ComplexField.zero, ComplexField { zero pow 2 }) + fun testPower() = ComplexField { + assertEquals(zero, zero pow 2) + assertEquals(zero, zero pow 2) assertEquals( - ComplexField { i * 8 }.let { it.im.toInt() to it.re.toInt() }, - ComplexField { Complex(2, 2) pow 2 }.let { it.im.toInt() to it.re.toInt() }) + (i * 8).let { it.im.toInt() to it.re.toInt() }, + (Complex(2, 2) pow 2).let { it.im.toInt() to it.re.toInt() }) + + assertEquals(2.0, power(Complex(-4.0, 0.0), 0.5 + 0 * i).im, 0.01) + assertEquals(2.0, power(Complex(-4.0, 0.0), 0.5).im, 0.01) } @Test - fun testNorm() { - assertEquals(2.toComplex(), ComplexField { norm(2 * i) }) + fun testNorm() = ComplexField { + assertEquals(2.toComplex(), norm(2 * i)) } } From 9e3fd240b82e9874517781a523620d5a862b19bb Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Thu, 8 Feb 2024 17:39:19 +0300 Subject: [PATCH 22/40] Update versions --- build.gradle.kts | 2 +- gradle.properties | 2 +- .../space/kscience/kmath/ejml/_generated.kt | 36 ++++++++++++++----- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index f40cb88ee..a0befa3c5 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -14,7 +14,7 @@ allprojects { } group = "space.kscience" - version = "0.4.0-dev-2" + version = "0.4.0-dev-3" } subprojects { diff --git a/gradle.properties b/gradle.properties index 5d62bf88e..0d373a8e5 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,6 +12,6 @@ org.gradle.jvmargs=-Xmx4096m org.gradle.parallel=true org.gradle.workers.max=4 -toolsVersion=0.15.0-kotlin-1.9.20 +toolsVersion=0.15.2-kotlin-1.9.22 #kotlin.experimental.tryK2=true #kscience.wasm.disabled=true \ No newline at end of file diff --git a/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/_generated.kt b/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/_generated.kt index 7a267b77b..c86d9bc44 100644 --- a/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/_generated.kt +++ b/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/_generated.kt @@ -19,19 +19,15 @@ import org.ejml.sparse.csc.factory.DecompositionFactory_DSCC import org.ejml.sparse.csc.factory.DecompositionFactory_FSCC import org.ejml.sparse.csc.factory.LinearSolverFactory_DSCC import org.ejml.sparse.csc.factory.LinearSolverFactory_FSCC +import space.kscience.attributes.SafeType +import space.kscience.attributes.safeTypeOf +import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.linear.* import space.kscience.kmath.linear.Matrix -import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.nd.StructureFeature -import space.kscience.kmath.structures.Float64 -import space.kscience.kmath.structures.Float32 -import space.kscience.kmath.operations.Float64Field import space.kscience.kmath.operations.Float32Field -import space.kscience.kmath.operations.DoubleField -import space.kscience.kmath.operations.FloatField +import space.kscience.kmath.operations.Float64Field import space.kscience.kmath.operations.invoke -import space.kscience.kmath.structures.Float64Buffer -import space.kscience.kmath.structures.Float32Buffer import space.kscience.kmath.structures.DoubleBuffer import space.kscience.kmath.structures.FloatBuffer import kotlin.reflect.KClass @@ -45,6 +41,8 @@ public class EjmlDoubleVector(override val origin: M) : EjmlVec require(origin.numRows == 1) { "The origin matrix must have only one row to form a vector" } } + override val type: SafeType get() = safeTypeOf() + override operator fun get(index: Int): Double = origin[0, index] } @@ -56,6 +54,8 @@ public class EjmlFloatVector(override val origin: M) : EjmlVect require(origin.numRows == 1) { "The origin matrix must have only one row to form a vector" } } + override val type: SafeType get() = safeTypeOf() + override operator fun get(index: Int): Float = origin[0, index] } @@ -63,6 +63,8 @@ public class EjmlFloatVector(override val origin: M) : EjmlVect * [EjmlMatrix] specialization for [Double]. */ public class EjmlDoubleMatrix(override val origin: M) : EjmlMatrix(origin) { + override val type: SafeType get() = safeTypeOf() + override operator fun get(i: Int, j: Int): Double = origin[i, j] } @@ -70,9 +72,13 @@ public class EjmlDoubleMatrix(override val origin: M) : EjmlMat * [EjmlMatrix] specialization for [Float]. */ public class EjmlFloatMatrix(override val origin: M) : EjmlMatrix(origin) { + override val type: SafeType get() = safeTypeOf() + override operator fun get(i: Int, j: Int): Float = origin[i, j] } + + /** * [EjmlLinearSpace] implementation based on [CommonOps_DDRM], [DecompositionFactory_DDRM] operations and * [DMatrixRMaj] matrices. @@ -83,6 +89,8 @@ public object EjmlLinearSpaceDDRM : EjmlLinearSpace get() = safeTypeOf() + @Suppress("UNCHECKED_CAST") override fun Matrix.toEjml(): EjmlDoubleMatrix = when { this is EjmlDoubleMatrix<*> && origin is DMatrixRMaj -> this as EjmlDoubleMatrix @@ -309,6 +317,8 @@ public object EjmlLinearSpaceDDRM : EjmlLinearSpace get() = safeTypeOf() + @Suppress("UNCHECKED_CAST") override fun Matrix.toEjml(): EjmlFloatMatrix = when { this is EjmlFloatMatrix<*> && origin is FMatrixRMaj -> this as EjmlFloatMatrix @@ -545,6 +557,8 @@ public object EjmlLinearSpaceFDRM : EjmlLinearSpace get() = safeTypeOf() + @Suppress("UNCHECKED_CAST") override fun Matrix.toEjml(): EjmlDoubleMatrix = when { this is EjmlDoubleMatrix<*> && origin is DMatrixSparseCSC -> this as EjmlDoubleMatrix @@ -776,6 +792,8 @@ public object EjmlLinearSpaceDSCC : EjmlLinearSpace get() = safeTypeOf() + @Suppress("UNCHECKED_CAST") override fun Matrix.toEjml(): EjmlFloatMatrix = when { this is EjmlFloatMatrix<*> && origin is FMatrixSparseCSC -> this as EjmlFloatMatrix From ca9df8a1671abda0307fc5ef98257d091a95410f Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Thu, 8 Feb 2024 18:06:06 +0300 Subject: [PATCH 23/40] Add more corner cases for complex power --- .../kotlin/space/kscience/kmath/complex/Complex.kt | 11 +++++++++-- .../space/kscience/kmath/complex/ComplexFieldTest.kt | 5 +++++ .../kotlin/space/kscience/kmath/ejml/_generated.kt | 10 ++-------- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/Complex.kt b/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/Complex.kt index 009662176..2608f9f65 100644 --- a/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/Complex.kt +++ b/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/Complex.kt @@ -139,12 +139,19 @@ public object ComplexField : zero } } - } else { exp(pow * ln(arg)) } - public fun power(arg: Complex, pow: Complex): Complex = exp(pow * ln(arg)) + public fun power(arg: Complex, pow: Complex): Complex = if(arg == zero || arg == (-0.0).toComplex()){ + if(pow == zero){ + one + } else { + zero + } + } else { + exp(pow * ln(arg)) + } public fun Complex.pow(power: Complex): Complex = power(this, power) diff --git a/kmath-complex/src/commonTest/kotlin/space/kscience/kmath/complex/ComplexFieldTest.kt b/kmath-complex/src/commonTest/kotlin/space/kscience/kmath/complex/ComplexFieldTest.kt index cc1f3ad0a..06f7f4580 100644 --- a/kmath-complex/src/commonTest/kotlin/space/kscience/kmath/complex/ComplexFieldTest.kt +++ b/kmath-complex/src/commonTest/kotlin/space/kscience/kmath/complex/ComplexFieldTest.kt @@ -71,6 +71,11 @@ internal class ComplexFieldTest { (i * 8).let { it.im.toInt() to it.re.toInt() }, (Complex(2, 2) pow 2).let { it.im.toInt() to it.re.toInt() }) + assertEquals(1.0, Complex(0.0).pow(Complex(0.0)).re, 0.01) + assertEquals(1.0, Complex(-0.0).pow(Complex(0.0)).re, 0.01) + assertEquals(0.0, Complex(0.0).pow(Complex(2.0)).re, 0.01) + assertEquals(0.0, Complex(-0.0).pow(Complex(2.0)).re, 0.01) + assertEquals(1.0, Complex(-1.0).pow(Complex(2.0)).re, 0.01) assertEquals(2.0, power(Complex(-4.0, 0.0), 0.5 + 0 * i).im, 0.01) assertEquals(2.0, power(Complex(-4.0, 0.0), 0.5).im, 0.01) } diff --git a/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/_generated.kt b/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/_generated.kt index 7a267b77b..a2622eee2 100644 --- a/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/_generated.kt +++ b/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/_generated.kt @@ -19,19 +19,13 @@ import org.ejml.sparse.csc.factory.DecompositionFactory_DSCC import org.ejml.sparse.csc.factory.DecompositionFactory_FSCC import org.ejml.sparse.csc.factory.LinearSolverFactory_DSCC import org.ejml.sparse.csc.factory.LinearSolverFactory_FSCC +import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.linear.* import space.kscience.kmath.linear.Matrix -import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.nd.StructureFeature -import space.kscience.kmath.structures.Float64 -import space.kscience.kmath.structures.Float32 -import space.kscience.kmath.operations.Float64Field import space.kscience.kmath.operations.Float32Field -import space.kscience.kmath.operations.DoubleField -import space.kscience.kmath.operations.FloatField +import space.kscience.kmath.operations.Float64Field import space.kscience.kmath.operations.invoke -import space.kscience.kmath.structures.Float64Buffer -import space.kscience.kmath.structures.Float32Buffer import space.kscience.kmath.structures.DoubleBuffer import space.kscience.kmath.structures.FloatBuffer import kotlin.reflect.KClass From f8e91c2402edeae6b206e5f0ba9b3c51d0e300e2 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sat, 17 Feb 2024 21:32:26 +0300 Subject: [PATCH 24/40] Finishing fixes --- CHANGELOG.md | 2 + .../ExpressionsInterpretersBenchmark.kt | 2 +- .../space/kscience/kmath/fit/chiSquared.kt | 10 +- .../kotlin/space/kscience/kmath/fit/qowFit.kt | 3 +- .../kscience/kmath/functions/interpolate.kt | 5 +- .../kscience/kmath/structures/ComplexND.kt | 4 +- .../kmath/structures/StreamDoubleFieldND.kt | 1 + .../structures/StructureWriteBenchmark.kt | 6 +- .../kscience/kmath/structures/buffers.kt | 2 +- .../kscience/kmath/commons/linear/CMMatrix.kt | 63 ++-- .../kmath/commons/optimization/CMOptimizer.kt | 31 +- .../commons/integration/IntegrationTest.kt | 6 +- .../commons/optimization/OptimizeTest.kt | 5 +- .../kscience/kmath/expressions/Expression.kt | 7 + .../kscience/kmath/linear/LupDecomposition.kt | 24 +- .../space/kscience/kmath/linear/Transposed.kt | 3 +- .../space/kscience/kmath/nd/Float64FieldND.kt | 7 +- .../kscience/kmath/nd/primitiveStructureND.kt | 10 + .../kmath/linear/DoubleLUSolverTest.kt | 2 +- .../space/kscience/kmath/linear/MatrixTest.kt | 2 +- kmath-coroutines/build.gradle.kts | 1 + .../kmath/streaming/RingBufferTest.kt | 5 +- kmath-dimensions/build.gradle.kts | 1 + .../kscience/kmath/dimensions/Wrappers.kt | 2 +- .../kmath/dimensions/Dimension.wasmJs.kt | 23 ++ kmath-ejml/build.gradle.kts | 28 +- .../{_generated.kt => implementations.kt} | 354 ++++++++---------- .../kscience/kmath/ejml/EjmlMatrixTest.kt | 10 +- kmath-for-real/build.gradle.kts | 1 + .../kscience/kmath/real/DoubleVectorTest.kt | 4 +- kmath-functions/build.gradle.kts | 1 - .../kmath/integration/GaussIntegrator.kt | 2 +- .../kmath/interpolation/SplineInterpolator.kt | 2 +- .../kmath/functions/testUtils/IntModulo.kt | 7 +- .../kmath/functions/testUtils/Rational.kt | 2 + .../kmath/integration/SplineIntegralTest.kt | 10 +- .../space/kscience/kmath/geometry/Line.kt | 12 +- .../space/kscience/kmath/geometry/Vector3D.kt | 4 + .../space/kscience/kmath/geometry/angles.kt | 34 +- .../geometry/euclidean2d/Float32Space2D.kt | 9 +- .../geometry/euclidean2d/Float64Space2D.kt | 49 ++- .../geometry/euclidean3d/Float32Space3D.kt | 8 +- .../geometry/euclidean3d/Float64Space3D.kt | 62 +-- .../kmath/geometry/euclidean3d/rotations3D.kt | 20 +- .../kscience/kmath/geometry/testUtils.kt | 7 +- kmath-histograms/build.gradle.kts | 3 +- .../kscience/kmath/histogram/Histogram.kt | 6 +- .../kmath/histogram/UniformHistogram1D.kt | 3 + .../histogram/UniformHistogramGroupND.kt | 31 +- .../kmath/histogram/TreeHistogramGroup.kt | 7 +- .../kmath/kotlingrad/KotlingradExpression.kt | 3 + kmath-nd4j/build.gradle.kts | 2 +- .../kscience/kmath/nd4j/Nd4jArrayStructure.kt | 11 +- kmath-optimization/build.gradle.kts | 1 + .../optimization/FunctionOptimization.kt | 4 + .../kmath/optimization/OptimizationProblem.kt | 8 + .../kmath/optimization/QowOptimizer.kt | 6 +- kmath-stat/build.gradle.kts | 1 + .../space/kscience/kmath/stat/MCScopeTest.kt | 2 +- .../kscience/kmath/symja/SymjaExpression.kt | 5 +- .../tensorflow/DoubleTensorFlowAlgebra.kt | 3 +- .../kmath/tensorflow/IntTensorFlowAlgebra.kt | 10 + .../kmath/tensorflow/TensorFlowAlgebra.kt | 7 +- kmath-tensors/build.gradle.kts | 1 + .../kscience/kmath/tensors/api/Tensor.kt | 10 - .../kmath/tensors/api/TensorAlgebra.kt | 3 + .../core/LevenbergMarquardtAlgorithm.kt | 9 +- .../kscience/kmath/viktor/ViktorBuffer.kt | 4 + .../kmath/viktor/ViktorStructureND.kt | 4 + 69 files changed, 548 insertions(+), 449 deletions(-) create mode 100644 kmath-dimensions/src/wasmJsMain/kotlin/space/kscience/kmath/dimensions/Dimension.wasmJs.kt rename kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/{_generated.kt => implementations.kt} (72%) delete mode 100644 kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/api/Tensor.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 29d9c7d6e..2001215ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,9 +20,11 @@ - Kmath-memory is moved on top of core. ### Deprecated +- ND4J engine ### Removed - `asPolynomial` function due to scope pollution +- Codegend for ejml (450 lines of codegen for 1000 lines of code is too much) ### Fixed - Median statistics diff --git a/benchmarks/src/jsMain/kotlin/space/kscience/kmath/benchmarks/ExpressionsInterpretersBenchmark.kt b/benchmarks/src/jsMain/kotlin/space/kscience/kmath/benchmarks/ExpressionsInterpretersBenchmark.kt index d930c90c0..4fa5be9f1 100644 --- a/benchmarks/src/jsMain/kotlin/space/kscience/kmath/benchmarks/ExpressionsInterpretersBenchmark.kt +++ b/benchmarks/src/jsMain/kotlin/space/kscience/kmath/benchmarks/ExpressionsInterpretersBenchmark.kt @@ -99,7 +99,7 @@ class ExpressionsInterpretersBenchmark { private val estree = node.estreeCompileToExpression(Float64Field) private val raw = Expression { args -> - val x = args[x]!! + val x = args.getValue(x) x * 2.0 + 2.0 / x - 16.0 / sin(x) } } diff --git a/examples/src/main/kotlin/space/kscience/kmath/fit/chiSquared.kt b/examples/src/main/kotlin/space/kscience/kmath/fit/chiSquared.kt index 828017185..14cd5bc76 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/fit/chiSquared.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/fit/chiSquared.kt @@ -13,10 +13,7 @@ import space.kscience.kmath.expressions.autodiff import space.kscience.kmath.expressions.symbol import space.kscience.kmath.operations.asIterable import space.kscience.kmath.operations.toList -import space.kscience.kmath.optimization.FunctionOptimizationTarget -import space.kscience.kmath.optimization.optimizeWith -import space.kscience.kmath.optimization.result -import space.kscience.kmath.optimization.resultValue +import space.kscience.kmath.optimization.* import space.kscience.kmath.random.RandomGenerator import space.kscience.kmath.real.DoubleVector import space.kscience.kmath.real.map @@ -80,8 +77,9 @@ suspend fun main() { val result = chi2.optimizeWith( CMOptimizer, mapOf(a to 1.5, b to 0.9, c to 1.0), - FunctionOptimizationTarget.MINIMIZE - ) + ){ + FunctionOptimizationTarget(OptimizationDirection.MINIMIZE) + } //display a page with plot and numerical results val page = Plotly.page { diff --git a/examples/src/main/kotlin/space/kscience/kmath/fit/qowFit.kt b/examples/src/main/kotlin/space/kscience/kmath/fit/qowFit.kt index 108c1f12e..4f3ce5443 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/fit/qowFit.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/fit/qowFit.kt @@ -7,6 +7,7 @@ package space.kscience.kmath.fit import kotlinx.html.br import kotlinx.html.h3 +import space.kscience.attributes.Attributes import space.kscience.kmath.data.XYErrorColumnarData import space.kscience.kmath.distributions.NormalDistribution import space.kscience.kmath.expressions.Symbol @@ -64,7 +65,7 @@ suspend fun main() { QowOptimizer, Double.autodiff, mapOf(a to 0.9, b to 1.2, c to 2.0, e to 1.0, d to 1.0, e to 0.0), - OptimizationParameters(a, b, c, d) + attributes = Attributes(OptimizationParameters, listOf(a, b, c, d)) ) { arg -> //bind variables to autodiff context val a by binding diff --git a/examples/src/main/kotlin/space/kscience/kmath/functions/interpolate.kt b/examples/src/main/kotlin/space/kscience/kmath/functions/interpolate.kt index 817f33dbe..c2e33afd4 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/functions/interpolate.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/functions/interpolate.kt @@ -8,7 +8,6 @@ package space.kscience.kmath.functions import space.kscience.kmath.interpolation.SplineInterpolator import space.kscience.kmath.interpolation.interpolatePolynomials import space.kscience.kmath.operations.Float64Field -import space.kscience.kmath.structures.Float64Buffer import space.kscience.plotly.Plotly import space.kscience.plotly.UnstablePlotlyAPI import space.kscience.plotly.makeFile @@ -24,9 +23,7 @@ fun main() { x to sin(x) } - val polynomial: PiecewisePolynomial = SplineInterpolator( - Float64Field, ::Float64Buffer - ).interpolatePolynomials(data) + val polynomial: PiecewisePolynomial = SplineInterpolator(Float64Field).interpolatePolynomials(data) val function = polynomial.asFunction(Float64Field, 0.0) diff --git a/examples/src/main/kotlin/space/kscience/kmath/structures/ComplexND.kt b/examples/src/main/kotlin/space/kscience/kmath/structures/ComplexND.kt index c97ba8383..9b48e44a0 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/structures/ComplexND.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/structures/ComplexND.kt @@ -8,7 +8,7 @@ package space.kscience.kmath.structures import space.kscience.kmath.complex.* -import space.kscience.kmath.linear.transpose +import space.kscience.kmath.linear.transposed import space.kscience.kmath.nd.StructureND import space.kscience.kmath.nd.as2D import space.kscience.kmath.nd.ndAlgebra @@ -60,7 +60,7 @@ fun complexExample() { val sum = matrix + x + 1.0 //Represent the sum as 2d-structure and transpose - sum.as2D().transpose() + sum.as2D().transposed() } } } diff --git a/examples/src/main/kotlin/space/kscience/kmath/structures/StreamDoubleFieldND.kt b/examples/src/main/kotlin/space/kscience/kmath/structures/StreamDoubleFieldND.kt index 226ec602e..8c34ad4f1 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/structures/StreamDoubleFieldND.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/structures/StreamDoubleFieldND.kt @@ -7,6 +7,7 @@ package space.kscience.kmath.structures import space.kscience.kmath.PerformancePitfall import space.kscience.kmath.nd.* +import space.kscience.kmath.operations.DoubleField import space.kscience.kmath.operations.ExtendedField import space.kscience.kmath.operations.Float64Field import space.kscience.kmath.operations.NumbersAddOps 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 9304e9f4c..8d642d892 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/structures/StructureWriteBenchmark.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/structures/StructureWriteBenchmark.kt @@ -6,20 +6,18 @@ package space.kscience.kmath.structures import space.kscience.kmath.nd.BufferND -import space.kscience.kmath.nd.ShapeND -import space.kscience.kmath.nd.StructureND import space.kscience.kmath.operations.mapToBuffer import kotlin.system.measureTimeMillis private inline fun BufferND.mapToBufferND( - bufferFactory: BufferFactory = BufferFactory.auto(), + bufferFactory: BufferFactory = BufferFactory(), crossinline block: (T) -> R, ): BufferND = BufferND(indices, buffer.mapToBuffer(bufferFactory, block)) @Suppress("UNUSED_VARIABLE") fun main() { val n = 6000 - val structure = StructureND.buffered(ShapeND(n, n), Buffer.Companion::auto) { 1.0 } + val structure = BufferND(n, n) { 1.0 } structure.mapToBufferND { it + 1 } // warm-up val time1 = measureTimeMillis { val res = structure.mapToBufferND { it + 1 } } println("Structure mapping finished in $time1 millis") diff --git a/examples/src/main/kotlin/space/kscience/kmath/structures/buffers.kt b/examples/src/main/kotlin/space/kscience/kmath/structures/buffers.kt index aafd43fd9..d4dfa60cb 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/structures/buffers.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/structures/buffers.kt @@ -13,7 +13,7 @@ import space.kscience.kmath.operations.withSize inline fun MutableBuffer.Companion.same( n: Int, value: R -): MutableBuffer = auto(n) { value } +): MutableBuffer = MutableBuffer(n) { value } fun main() { diff --git a/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/linear/CMMatrix.kt b/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/linear/CMMatrix.kt index de6b406fd..589dc19e0 100644 --- a/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/linear/CMMatrix.kt +++ b/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/linear/CMMatrix.kt @@ -7,16 +7,20 @@ package space.kscience.kmath.commons.linear import org.apache.commons.math3.linear.* import org.apache.commons.math3.linear.LUDecomposition +import org.apache.commons.math3.linear.SingularValueDecomposition import space.kscience.attributes.SafeType import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.linear.* +import space.kscience.kmath.linear.CholeskyDecomposition +import space.kscience.kmath.linear.QRDecomposition import space.kscience.kmath.nd.Structure2D import space.kscience.kmath.nd.StructureAttribute import space.kscience.kmath.operations.DoubleField import space.kscience.kmath.operations.Float64Field import space.kscience.kmath.structures.Buffer -import space.kscience.kmath.structures.Float64Buffer -import kotlin.reflect.cast +import space.kscience.kmath.structures.Float64 +import space.kscience.kmath.structures.IntBuffer +import space.kscience.kmath.structures.asBuffer public class CMMatrix(public val origin: RealMatrix) : Matrix { override val type: SafeType get() = DoubleField.type @@ -109,45 +113,44 @@ public object CMLinearSpace : LinearSpace { val origin = structure.toCM().origin - return when (attribute) { - IsDiagonal -> if (origin is DiagonalMatrix) IsDiagonal else null + val raw: Any? = when (attribute) { + IsDiagonal -> if (origin is DiagonalMatrix) Unit else null Determinant -> LUDecomposition(origin).determinant - LUP -> GenericLupDecomposition { - private val lup by lazy { LUDecomposition(origin) } - override val determinant: Double by lazy { lup.determinant } - override val l: Matrix by lazy> { CMMatrix(lup.l).withAttribute(LowerTriangular) } - override val u: Matrix by lazy> { CMMatrix(lup.u).withAttribute(UpperTriangular) } - override val p: Matrix by lazy { CMMatrix(lup.p) } + + LUP -> object : LupDecomposition { + val lup by lazy { LUDecomposition(origin) } + override val pivot: IntBuffer get() = lup.pivot.asBuffer() + override val l: Matrix get() = lup.l.wrap() + override val u: Matrix get() = lup.u.wrap() } - CholeskyDecompositionAttribute -> object : CholeskyDecompositionAttribute { - override val l: Matrix by lazy> { - val cholesky = CholeskyDecomposition(origin) - CMMatrix(cholesky.l).withAttribute(LowerTriangular) - } + Cholesky -> object : CholeskyDecomposition { + val cmCholesky by lazy { org.apache.commons.math3.linear.CholeskyDecomposition(origin) } + override val l: Matrix get() = cmCholesky.l.wrap() } - QRDecompositionAttribute -> object : QRDecompositionAttribute { - private val qr by lazy { QRDecomposition(origin) } - override val q: Matrix by lazy> { - CMMatrix(qr.q).withAttribute( - OrthogonalAttribute - ) - } - override val r: Matrix by lazy> { CMMatrix(qr.r).withAttribute(UpperTriangular) } + QR -> object : QRDecomposition { + val cmQr by lazy { org.apache.commons.math3.linear.QRDecomposition(origin) } + override val q: Matrix get() = cmQr.q.wrap().withAttribute(OrthogonalAttribute) + override val r: Matrix get() = cmQr.r.wrap().withAttribute(UpperTriangular) } - SVDAttribute -> object : SVDAttribute { - private val sv by lazy { SingularValueDecomposition(origin) } - 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 { Float64Buffer(sv.singularValues) } + SVD -> object : space.kscience.kmath.linear.SingularValueDecomposition { + val cmSvd by lazy { SingularValueDecomposition(origin) } + + override val u: Matrix get() = cmSvd.u.wrap() + override val s: Matrix get() = cmSvd.s.wrap() + override val v: Matrix get() = cmSvd.v.wrap() + override val singularValues: Point get() = cmSvd.singularValues.asBuffer() + } else -> null - }?.let(type::cast) + } + @Suppress("UNCHECKED_CAST") + return raw as V? } + } public operator fun CMMatrix.plus(other: CMMatrix): CMMatrix = CMMatrix(origin.add(other.origin)) diff --git a/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/optimization/CMOptimizer.kt b/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/optimization/CMOptimizer.kt index 83ccea035..afbb96d9b 100644 --- a/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/optimization/CMOptimizer.kt +++ b/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/optimization/CMOptimizer.kt @@ -3,6 +3,7 @@ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @file:OptIn(UnstableKMathAPI::class) + package space.kscience.kmath.commons.optimization import org.apache.commons.math3.optim.* @@ -20,7 +21,6 @@ import space.kscience.kmath.expressions.Symbol import space.kscience.kmath.expressions.SymbolIndexer import space.kscience.kmath.expressions.derivative import space.kscience.kmath.expressions.withSymbols -import space.kscience.kmath.misc.log import space.kscience.kmath.optimization.* import kotlin.collections.set import kotlin.reflect.KClass @@ -28,7 +28,7 @@ import kotlin.reflect.KClass public operator fun PointValuePair.component1(): DoubleArray = point public operator fun PointValuePair.component2(): Double = value -public object CMOptimizerEngine: OptimizationAttribute<() -> MultivariateOptimizer> +public object CMOptimizerEngine : OptimizationAttribute<() -> MultivariateOptimizer> /** * Specify a Commons-maths optimization engine @@ -37,7 +37,7 @@ public fun AttributesBuilder>.cmEngine(optimizerBui set(CMOptimizerEngine, optimizerBuilder) } -public object CMOptimizerData: SetAttribute OptimizationData> +public object CMOptimizerData : SetAttribute OptimizationData> /** * Specify Commons-maths optimization data. @@ -118,21 +118,24 @@ public object CMOptimizer : Optimizer> { val logger = problem.attributes[OptimizationLog] - for (feature in problem.attributes) { - when (feature) { - is CMOptimizerData -> feature.data.forEach { dataBuilder -> - addOptimizationData(dataBuilder()) - } - is FunctionOptimizationTarget -> when (feature) { - FunctionOptimizationTarget.MAXIMIZE -> addOptimizationData(GoalType.MAXIMIZE) - FunctionOptimizationTarget.MINIMIZE -> addOptimizationData(GoalType.MINIMIZE) - } - else -> logger?.log { "The feature $feature is unused in optimization" } + problem.attributes[CMOptimizerData]?.let { builders: Set OptimizationData> -> + builders.forEach { dataBuilder -> + addOptimizationData(dataBuilder()) + } + } + + problem.attributes[FunctionOptimizationTarget]?.let { direction: OptimizationDirection -> + when (direction) { + OptimizationDirection.MAXIMIZE -> addOptimizationData(GoalType.MAXIMIZE) + OptimizationDirection.MINIMIZE -> addOptimizationData(GoalType.MINIMIZE) } } val (point, value) = cmOptimizer.optimize(*optimizationData.values.toTypedArray()) - return problem.withAttributes(OptimizationResult(point.toMap()), OptimizationValue(value)) + return problem.withAttributes { + result(point.toMap()) + value(value) + } } } } diff --git a/kmath-commons/src/jvmTest/kotlin/space/kscience/kmath/commons/integration/IntegrationTest.kt b/kmath-commons/src/jvmTest/kotlin/space/kscience/kmath/commons/integration/IntegrationTest.kt index c2e630f38..43857c539 100644 --- a/kmath-commons/src/jvmTest/kotlin/space/kscience/kmath/commons/integration/IntegrationTest.kt +++ b/kmath-commons/src/jvmTest/kotlin/space/kscience/kmath/commons/integration/IntegrationTest.kt @@ -7,6 +7,8 @@ package space.kscience.kmath.commons.integration import org.junit.jupiter.api.Test import space.kscience.kmath.UnstableKMathAPI +import space.kscience.kmath.integration.IntegrandAbsoluteAccuracy +import space.kscience.kmath.integration.IntegrandRelativeAccuracy import space.kscience.kmath.integration.integrate import space.kscience.kmath.integration.value import space.kscience.kmath.operations.Float64Field.sin @@ -27,8 +29,8 @@ internal class IntegrationTest { @Test fun customSimpson() { val res = CMIntegrator.simpson().integrate(0.0..PI, { - targetRelativeAccuracy = 1e-4 - targetAbsoluteAccuracy = 1e-4 + IntegrandRelativeAccuracy(1e-4) + IntegrandAbsoluteAccuracy(1e-4) }, function).value assertTrue { abs(res - 2) < 1e-3 } assertTrue { abs(res - 2) > 1e-12 } diff --git a/kmath-commons/src/jvmTest/kotlin/space/kscience/kmath/commons/optimization/OptimizeTest.kt b/kmath-commons/src/jvmTest/kotlin/space/kscience/kmath/commons/optimization/OptimizeTest.kt index e17ba48e9..177a01b43 100644 --- a/kmath-commons/src/jvmTest/kotlin/space/kscience/kmath/commons/optimization/OptimizeTest.kt +++ b/kmath-commons/src/jvmTest/kotlin/space/kscience/kmath/commons/optimization/OptimizeTest.kt @@ -73,8 +73,9 @@ internal class OptimizeTest { val result: FunctionOptimization = chi2.optimizeWith( CMOptimizer, mapOf(a to 1.5, b to 0.9, c to 1.0), - FunctionOptimizationTarget.MINIMIZE - ) + ){ + FunctionOptimizationTarget(OptimizationDirection.MINIMIZE) + } println(result) println("Chi2/dof = ${result.resultValue / (x.size - 3)}") } diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/Expression.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/Expression.kt index 7bf48fcc1..f2e134963 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/Expression.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/Expression.kt @@ -7,6 +7,7 @@ package space.kscience.kmath.expressions import space.kscience.attributes.SafeType import space.kscience.attributes.WithType +import space.kscience.attributes.safeTypeOf import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.operations.Algebra import space.kscience.kmath.operations.DoubleField @@ -30,12 +31,18 @@ public interface Expression : WithType { public operator fun invoke(arguments: Map): T } +/** + * Create an expression from a functional block. + */ public fun Expression(type: SafeType, block: (Map) -> T): Expression = object : Expression { override fun invoke(arguments: Map): T = block(arguments) override val type: SafeType = type } +public inline fun Expression(noinline block: (Map) -> T): Expression = + Expression(safeTypeOf(), block) + /** * Specialization of [Expression] for [Double] allowing better performance because of using array. */ 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 4d2768e02..14828f2df 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 @@ -15,14 +15,19 @@ import space.kscience.kmath.operations.* import space.kscience.kmath.structures.* public interface LupDecomposition { - public val linearSpace: LinearSpace> - public val elementAlgebra: Field get() = linearSpace.elementAlgebra - public val pivot: IntBuffer public val l: Matrix public val u: Matrix } +/** + * Create a pivot matrix from pivot vector using provided [LinearSpace] + */ +public fun LupDecomposition.pivotMatrix(linearSpace: LinearSpace>): Matrix = + VirtualMatrix(linearSpace.type, l.rowNum, l.colNum) { row, column -> + if (column == pivot[row]) linearSpace.elementAlgebra.one else linearSpace.elementAlgebra.zero + } + /** * Matrices with this feature support LU factorization with partial pivoting: *[p] · a = [l] · [u]* where * *a* is the owning matrix. @@ -31,12 +36,14 @@ public interface LupDecomposition { * @param lu combined L and U matrix */ public class GenericLupDecomposition( - override val linearSpace: LinearSpace>, + public val linearSpace: LinearSpace>, private val lu: Matrix, override val pivot: IntBuffer, private val even: Boolean, ) : LupDecomposition { + private val elementAlgebra get() = linearSpace.elementAlgebra + override val l: Matrix get() = VirtualMatrix(lu.type, lu.rowNum, lu.colNum, attributes = Attributes(LowerTriangular)) { i, j -> when { @@ -51,11 +58,6 @@ public class GenericLupDecomposition( if (j >= i) lu[i, j] else elementAlgebra.zero } - public val pivotMatrix: Matrix - get() = VirtualMatrix(linearSpace.type, l.rowNum, l.colNum) { row, column -> - if (column == pivot[row]) elementAlgebra.one else elementAlgebra.zero - } - public val determinant: T by lazy { elementAlgebra { (0 until l.shape[0]).fold(if (even) one else -one) { value, i -> value * lu[i, i] } } } @@ -79,7 +81,7 @@ internal fun > LinearSpace>.abs(value: T): T = public fun > LinearSpace>.lup( matrix: Matrix, checkSingular: (T) -> Boolean, -): LupDecomposition = elementAlgebra { +): GenericLupDecomposition = elementAlgebra { require(matrix.rowNum == matrix.colNum) { "LU decomposition supports only square matrices" } val m = matrix.colNum val pivot = IntArray(matrix.rowNum) @@ -156,7 +158,7 @@ public fun > LinearSpace>.lup( public fun LinearSpace.lup( matrix: Matrix, singularityThreshold: Double = 1e-11, -): LupDecomposition = lup(matrix) { it < singularityThreshold } +): GenericLupDecomposition = lup(matrix) { it < singularityThreshold } internal fun LinearSpace>.solve( lup: LupDecomposition, diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/Transposed.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/Transposed.kt index 2cc566f92..28821a52a 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/Transposed.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/Transposed.kt @@ -25,5 +25,4 @@ public class TransposedMatrix(public val origin: Matrix) : Matrix { /** * Create a virtual transposed matrix without copying anything. `A.transpose().transpose() === A` */ -public val Matrix.transposed: Matrix - get() = (this as? TransposedMatrix)?.origin ?: TransposedMatrix(this) \ No newline at end of file +public fun Matrix.transposed(): Matrix = (this as? TransposedMatrix)?.origin ?: TransposedMatrix(this) \ No newline at end of file diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Float64FieldND.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Float64FieldND.kt index 309f9cb37..ab9b25663 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Float64FieldND.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Float64FieldND.kt @@ -5,9 +5,11 @@ package space.kscience.kmath.nd +import space.kscience.attributes.SafeType import space.kscience.kmath.PerformancePitfall import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.operations.* +import space.kscience.kmath.structures.Float64 import space.kscience.kmath.structures.Float64Buffer import kotlin.contracts.InvocationKind import kotlin.contracts.contract @@ -20,7 +22,10 @@ import kotlin.math.pow as kpow public class Float64BufferND( indexes: ShapeIndexer, override val buffer: Float64Buffer, -) : MutableBufferND(indexes, buffer), MutableStructureNDOfDouble{ +) : MutableBufferND(indexes, buffer), MutableStructureNDOfDouble { + + override val type: SafeType get() = Float64Field.type + override fun getDouble(index: IntArray): Double = buffer[indices.offset(index)] override fun setDouble(index: IntArray, value: Double) { diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/primitiveStructureND.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/primitiveStructureND.kt index 9f70b6dca..ca299f12f 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/primitiveStructureND.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/primitiveStructureND.kt @@ -5,9 +5,15 @@ package space.kscience.kmath.nd +import space.kscience.attributes.SafeType import space.kscience.kmath.PerformancePitfall +import space.kscience.kmath.operations.Float64Field +import space.kscience.kmath.operations.Int32Field +import space.kscience.kmath.structures.Float64 public interface StructureNDOfDouble : StructureND { + override val type: SafeType get() = Float64Field.type + /** * Guaranteed non-blocking access to content */ @@ -22,6 +28,7 @@ public fun StructureND.getDouble(index: IntArray): Double = if (this is StructureNDOfDouble) getDouble(index) else get(index) public interface MutableStructureNDOfDouble : StructureNDOfDouble, MutableStructureND { + /** * Guaranteed non-blocking access to content */ @@ -34,6 +41,9 @@ public fun MutableStructureND.getDouble(index: IntArray): Double = public interface StructureNDOfInt : StructureND { + + override val type: SafeType get() = Int32Field.type + /** * Guaranteed non-blocking access to content */ diff --git a/kmath-core/src/commonTest/kotlin/space/kscience/kmath/linear/DoubleLUSolverTest.kt b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/linear/DoubleLUSolverTest.kt index 9989afd6c..e50d1230d 100644 --- a/kmath-core/src/commonTest/kotlin/space/kscience/kmath/linear/DoubleLUSolverTest.kt +++ b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/linear/DoubleLUSolverTest.kt @@ -40,7 +40,7 @@ class DoubleLUSolverTest { //Check determinant assertEquals(7.0, lup.determinant) - assertMatrixEquals(lup.pivotMatrix dot matrix, lup.l dot lup.u) + assertMatrixEquals(lup.pivotMatrix(this) dot matrix, lup.l dot lup.u) } @Test diff --git a/kmath-core/src/commonTest/kotlin/space/kscience/kmath/linear/MatrixTest.kt b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/linear/MatrixTest.kt index 9d69d0379..4e9cc2011 100644 --- a/kmath-core/src/commonTest/kotlin/space/kscience/kmath/linear/MatrixTest.kt +++ b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/linear/MatrixTest.kt @@ -21,7 +21,7 @@ class MatrixTest { @Test fun testTranspose() = Double.algebra.linearSpace.run { val matrix = one(3, 3) - val transposed = matrix.transposed + val transposed = matrix.transposed() assertTrue { StructureND.contentEquals(matrix, transposed) } } diff --git a/kmath-coroutines/build.gradle.kts b/kmath-coroutines/build.gradle.kts index 1e901ca98..91b2afd5e 100644 --- a/kmath-coroutines/build.gradle.kts +++ b/kmath-coroutines/build.gradle.kts @@ -6,6 +6,7 @@ kscience { jvm() js() native() + wasm() dependencies { api(project(":kmath-core")) diff --git a/kmath-coroutines/src/jvmTest/kotlin/space/kscience/kmath/streaming/RingBufferTest.kt b/kmath-coroutines/src/jvmTest/kotlin/space/kscience/kmath/streaming/RingBufferTest.kt index 6219a5886..701715123 100644 --- a/kmath-coroutines/src/jvmTest/kotlin/space/kscience/kmath/streaming/RingBufferTest.kt +++ b/kmath-coroutines/src/jvmTest/kotlin/space/kscience/kmath/streaming/RingBufferTest.kt @@ -7,6 +7,7 @@ package space.kscience.kmath.streaming import kotlinx.coroutines.flow.* import kotlinx.coroutines.runBlocking +import space.kscience.kmath.operations.Int32Ring import space.kscience.kmath.operations.asSequence import kotlin.test.Test import kotlin.test.assertEquals @@ -14,7 +15,7 @@ import kotlin.test.assertEquals internal class RingBufferTest { @Test fun push() { - val buffer = RingBuffer.build(20, Double.NaN) + val buffer = RingBuffer(20, Double.NaN) runBlocking { for (i in 1..30) { buffer.push(i.toDouble()) @@ -30,7 +31,7 @@ internal class RingBufferTest { while (true) emit(i++) } - val windowed = flow.windowed(10) + val windowed = flow.windowed(10, Int32Ring) runBlocking { @Suppress("UNUSED_VARIABLE") val first = windowed.take(1).single() diff --git a/kmath-dimensions/build.gradle.kts b/kmath-dimensions/build.gradle.kts index be1fc65a0..0ed6a8949 100644 --- a/kmath-dimensions/build.gradle.kts +++ b/kmath-dimensions/build.gradle.kts @@ -6,6 +6,7 @@ kscience{ jvm() js() native() + wasm() dependencies{ api(projects.kmathCore) 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 cd24d25e7..d1de77d54 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 @@ -153,7 +153,7 @@ public value class DMatrixContext>(public val context: context.run { this@unaryMinus.unaryMinus() }.coerce() public inline fun DMatrix.transposed(): DMatrix = - context.run { (this@transposed as Matrix).transposed }.coerce() + context.run { (this@transposed as Matrix).transposed() }.coerce() public companion object { public val real: DMatrixContext = DMatrixContext(Double.algebra.linearSpace) diff --git a/kmath-dimensions/src/wasmJsMain/kotlin/space/kscience/kmath/dimensions/Dimension.wasmJs.kt b/kmath-dimensions/src/wasmJsMain/kotlin/space/kscience/kmath/dimensions/Dimension.wasmJs.kt new file mode 100644 index 000000000..cbf404b7f --- /dev/null +++ b/kmath-dimensions/src/wasmJsMain/kotlin/space/kscience/kmath/dimensions/Dimension.wasmJs.kt @@ -0,0 +1,23 @@ +/* + * Copyright 2018-2024 KMath contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package space.kscience.kmath.dimensions + +import kotlin.reflect.KClass + +private val dimensionMap: MutableMap = hashMapOf(1 to D1, 2 to D2, 3 to D3) + +@Suppress("UNCHECKED_CAST") +public actual fun Dimension.Companion.resolve(type: KClass): D = dimensionMap + .entries + .map(MutableMap.MutableEntry::value) + .find { it::class == type } as? D + ?: error("Can't resolve dimension $type") + +public actual fun Dimension.Companion.of(dim: Int): Dimension = dimensionMap.getOrPut(dim) { + object : Dimension { + override val dim: Int get() = dim + } +} diff --git a/kmath-ejml/build.gradle.kts b/kmath-ejml/build.gradle.kts index d7f780d79..54b8f7038 100644 --- a/kmath-ejml/build.gradle.kts +++ b/kmath-ejml/build.gradle.kts @@ -1,15 +1,15 @@ -import space.kscience.kmath.ejml.codegen.ejmlCodegen - plugins { id("space.kscience.gradle.jvm") } +val ejmlVerision = "0.43.1" + dependencies { - api("org.ejml:ejml-ddense:0.41") - api("org.ejml:ejml-fdense:0.41") - api("org.ejml:ejml-dsparse:0.41") - api("org.ejml:ejml-fsparse:0.41") - api(project(":kmath-core")) + api("org.ejml:ejml-ddense:$ejmlVerision") + api("org.ejml:ejml-fdense:$ejmlVerision") + api("org.ejml:ejml-dsparse:$ejmlVerision") + api("org.ejml:ejml-fsparse:$ejmlVerision") + api(projects.kmathCore) } readme { @@ -32,10 +32,10 @@ readme { ) { "LinearSpace implementations." } } -kotlin.sourceSets.main { - val codegen by tasks.creating { - ejmlCodegen(kotlin.srcDirs.first().absolutePath + "/space/kscience/kmath/ejml/_generated.kt") - } - - kotlin.srcDirs(files().builtBy(codegen)) -} +//kotlin.sourceSets.main { +// val codegen by tasks.creating { +// ejmlCodegen(kotlin.srcDirs.first().absolutePath + "/space/kscience/kmath/ejml/_generated.kt") +// } +// +// kotlin.srcDirs(files().builtBy(codegen)) +//} diff --git a/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/_generated.kt b/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/implementations.kt similarity index 72% rename from kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/_generated.kt rename to kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/implementations.kt index c86d9bc44..d33a74199 100644 --- a/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/_generated.kt +++ b/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/implementations.kt @@ -17,21 +17,18 @@ import org.ejml.sparse.csc.CommonOps_DSCC import org.ejml.sparse.csc.CommonOps_FSCC import org.ejml.sparse.csc.factory.DecompositionFactory_DSCC import org.ejml.sparse.csc.factory.DecompositionFactory_FSCC -import org.ejml.sparse.csc.factory.LinearSolverFactory_DSCC -import org.ejml.sparse.csc.factory.LinearSolverFactory_FSCC import space.kscience.attributes.SafeType import space.kscience.attributes.safeTypeOf -import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.linear.* import space.kscience.kmath.linear.Matrix -import space.kscience.kmath.nd.StructureFeature +import space.kscience.kmath.nd.Structure2D +import space.kscience.kmath.nd.StructureAttribute import space.kscience.kmath.operations.Float32Field import space.kscience.kmath.operations.Float64Field import space.kscience.kmath.operations.invoke -import space.kscience.kmath.structures.DoubleBuffer -import space.kscience.kmath.structures.FloatBuffer -import kotlin.reflect.KClass -import kotlin.reflect.cast +import space.kscience.kmath.structures.Float32 +import space.kscience.kmath.structures.IntBuffer +import space.kscience.kmath.structures.asBuffer /** * [EjmlVector] specialization for [Double]. @@ -78,7 +75,6 @@ public class EjmlFloatMatrix(override val origin: M) : EjmlMatr } - /** * [EjmlLinearSpace] implementation based on [CommonOps_DDRM], [DecompositionFactory_DDRM] operations and * [DMatrixRMaj] matrices. @@ -143,10 +139,10 @@ public object EjmlLinearSpaceDDRM : EjmlLinearSpace.plus(other: Matrix): EjmlDoubleMatrix { val out = DMatrixRMaj(1, 1) - + CommonOps_DDRM.add( elementAlgebra.one, toEjml().origin, elementAlgebra.one, - other.toEjml().origin, + other.toEjml().origin, out, ) @@ -217,77 +213,65 @@ public object EjmlLinearSpaceDDRM : EjmlLinearSpace): EjmlDoubleVector = v * this - @UnstableKMathAPI - override fun computeFeature(structure: Matrix, type: KClass): F? { - structure.getFeature(type)?.let { return it } + override fun > computeAttribute(structure: Structure2D, attribute: A): V? { val origin = structure.toEjml().origin - return when (type) { - InverseMatrixFeature::class -> object : InverseMatrixFeature { - override val inverse: Matrix by lazy { - val res = origin.copy() - CommonOps_DDRM.invert(res) - res.wrapMatrix() - } + val raw: Any? = when (attribute) { + Inverted -> { + val res = origin.copy() + CommonOps_DDRM.invert(res) + res.wrapMatrix() } - DeterminantFeature::class -> object : DeterminantFeature { - override val determinant: Double by lazy { CommonOps_DDRM.det(origin) } - } - - SingularValueDecompositionFeature::class -> object : SingularValueDecompositionFeature { - private val svd by lazy { - DecompositionFactory_DDRM.svd(origin.numRows, origin.numCols, true, true, false) + Determinant -> CommonOps_DDRM.det(origin) + SVD -> object : SingularValueDecomposition { + val ejmlSvd by lazy { + DecompositionFactory_DDRM + .svd(origin.numRows, origin.numCols, true, true, false) .apply { decompose(origin.copy()) } } + override val u: Matrix get() = ejmlSvd.getU(null, false).wrapMatrix() + + override val s: Matrix get() = ejmlSvd.getW(null).wrapMatrix() + override val v: Matrix get() = ejmlSvd.getV(null, false).wrapMatrix() + override val singularValues: Point get() = ejmlSvd.singularValues.asBuffer() - override val u: Matrix by lazy { svd.getU(null, false).wrapMatrix() } - override val s: Matrix by lazy { svd.getW(null).wrapMatrix() } - override val v: Matrix by lazy { svd.getV(null, false).wrapMatrix() } - override val singularValues: Point by lazy { DoubleBuffer(svd.singularValues) } } - QRDecompositionFeature::class -> object : QRDecompositionFeature { - private val qr by lazy { - DecompositionFactory_DDRM.qr().apply { decompose(origin.copy()) } - } - - override val q: Matrix by lazy { - qr.getQ(null, false).wrapMatrix().withFeature(OrthogonalFeature) - } - - override val r: Matrix by lazy { qr.getR(null, false).wrapMatrix().withFeature(UFeature) } + QR -> object : QRDecomposition { + val ejmlQr by lazy { DecompositionFactory_DDRM.qr().apply { decompose(origin.copy()) } } + override val q: Matrix get() = ejmlQr.getQ(null, false).wrapMatrix() + override val r: Matrix get() = ejmlQr.getR(null, false).wrapMatrix() } - CholeskyDecompositionFeature::class -> object : CholeskyDecompositionFeature { + Cholesky -> object : CholeskyDecomposition { override val l: Matrix by lazy { val cholesky = DecompositionFactory_DDRM.chol(structure.rowNum, true).apply { decompose(origin.copy()) } - cholesky.getT(null).wrapMatrix().withFeature(LFeature) + cholesky.getT(null).wrapMatrix().withAttribute(LowerTriangular) } } - LupDecompositionFeature::class -> object : LupDecompositionFeature { + LUP -> object : LupDecomposition { private val lup by lazy { DecompositionFactory_DDRM.lu(origin.numRows, origin.numCols).apply { decompose(origin.copy()) } } - override val l: Matrix by lazy { - lup.getLower(null).wrapMatrix().withFeature(LFeature) - } + override val l: Matrix + get() = lup.getLower(null).wrapMatrix().withAttribute(LowerTriangular) - override val u: Matrix by lazy { - lup.getUpper(null).wrapMatrix().withFeature(UFeature) - } - override val p: Matrix by lazy { lup.getRowPivot(null).wrapMatrix() } + override val u: Matrix + get() = lup.getUpper(null).wrapMatrix().withAttribute(UpperTriangular) + override val pivot: IntBuffer get() = lup.getRowPivotV(null).asBuffer() } else -> null - }?.let{ - type.cast(it) } + + @Suppress("UNCHECKED_CAST") + return raw as V? } /** @@ -318,7 +302,6 @@ public object EjmlLinearSpaceDDRM : EjmlLinearSpace.plus(other: Matrix): EjmlFloatMatrix { val out = FMatrixRMaj(1, 1) - + CommonOps_FDRM.add( elementAlgebra.one, toEjml().origin, elementAlgebra.one, - other.toEjml().origin, + other.toEjml().origin, out, ) @@ -457,77 +440,65 @@ public object EjmlLinearSpaceFDRM : EjmlLinearSpace): EjmlFloatVector = v * this - @UnstableKMathAPI - override fun computeFeature(structure: Matrix, type: KClass): F? { - structure.getFeature(type)?.let { return it } + override fun > computeAttribute(structure: Structure2D, attribute: A): V? { val origin = structure.toEjml().origin - return when (type) { - InverseMatrixFeature::class -> object : InverseMatrixFeature { - override val inverse: Matrix by lazy { - val res = origin.copy() - CommonOps_FDRM.invert(res) - res.wrapMatrix() - } + val raw: Any? = when (attribute) { + Inverted -> { + val res = origin.copy() + CommonOps_FDRM.invert(res) + res.wrapMatrix() } - DeterminantFeature::class -> object : DeterminantFeature { - override val determinant: Float by lazy { CommonOps_FDRM.det(origin) } - } - - SingularValueDecompositionFeature::class -> object : SingularValueDecompositionFeature { - private val svd by lazy { - DecompositionFactory_FDRM.svd(origin.numRows, origin.numCols, true, true, false) + Determinant -> CommonOps_FDRM.det(origin) + SVD -> object : SingularValueDecomposition { + val ejmlSvd by lazy { + DecompositionFactory_FDRM + .svd(origin.numRows, origin.numCols, true, true, false) .apply { decompose(origin.copy()) } } + override val u: Matrix get() = ejmlSvd.getU(null, false).wrapMatrix() + + override val s: Matrix get() = ejmlSvd.getW(null).wrapMatrix() + override val v: Matrix get() = ejmlSvd.getV(null, false).wrapMatrix() + override val singularValues: Point get() = ejmlSvd.singularValues.asBuffer() - override val u: Matrix by lazy { svd.getU(null, false).wrapMatrix() } - override val s: Matrix by lazy { svd.getW(null).wrapMatrix() } - override val v: Matrix by lazy { svd.getV(null, false).wrapMatrix() } - override val singularValues: Point by lazy { FloatBuffer(svd.singularValues) } } - QRDecompositionFeature::class -> object : QRDecompositionFeature { - private val qr by lazy { - DecompositionFactory_FDRM.qr().apply { decompose(origin.copy()) } - } - - override val q: Matrix by lazy { - qr.getQ(null, false).wrapMatrix().withFeature(OrthogonalFeature) - } - - override val r: Matrix by lazy { qr.getR(null, false).wrapMatrix().withFeature(UFeature) } + QR -> object : QRDecomposition { + val ejmlQr by lazy { DecompositionFactory_FDRM.qr().apply { decompose(origin.copy()) } } + override val q: Matrix get() = ejmlQr.getQ(null, false).wrapMatrix() + override val r: Matrix get() = ejmlQr.getR(null, false).wrapMatrix() } - CholeskyDecompositionFeature::class -> object : CholeskyDecompositionFeature { - override val l: Matrix by lazy { + Cholesky -> object : CholeskyDecomposition { + override val l: Matrix by lazy { val cholesky = DecompositionFactory_FDRM.chol(structure.rowNum, true).apply { decompose(origin.copy()) } - cholesky.getT(null).wrapMatrix().withFeature(LFeature) + cholesky.getT(null).wrapMatrix().withAttribute(LowerTriangular) } } - LupDecompositionFeature::class -> object : LupDecompositionFeature { + LUP -> object : LupDecomposition { private val lup by lazy { DecompositionFactory_FDRM.lu(origin.numRows, origin.numCols).apply { decompose(origin.copy()) } } - override val l: Matrix by lazy { - lup.getLower(null).wrapMatrix().withFeature(LFeature) - } + override val l: Matrix + get() = lup.getLower(null).wrapMatrix().withAttribute(LowerTriangular) - override val u: Matrix by lazy { - lup.getUpper(null).wrapMatrix().withFeature(UFeature) - } - override val p: Matrix by lazy { lup.getRowPivot(null).wrapMatrix() } + override val u: Matrix + get() = lup.getUpper(null).wrapMatrix().withAttribute(UpperTriangular) + override val pivot: IntBuffer get() = lup.getRowPivotV(null).asBuffer() } else -> null - }?.let{ - type.cast(it) } + + @Suppress("UNCHECKED_CAST") + return raw as V? } /** @@ -558,7 +529,6 @@ public object EjmlLinearSpaceFDRM : EjmlLinearSpace.plus(other: Matrix): EjmlDoubleMatrix { val out = DMatrixSparseCSC(1, 1) - + CommonOps_DSCC.add( elementAlgebra.one, toEjml().origin, elementAlgebra.one, - other.toEjml().origin, + other.toEjml().origin, out, - null, + null, null, ) @@ -672,7 +642,7 @@ public object EjmlLinearSpaceDSCC : EjmlLinearSpace): EjmlDoubleVector = v * this - @UnstableKMathAPI - override fun computeFeature(structure: Matrix, type: KClass): F? { - structure.getFeature(type)?.let { return it } + override fun > computeAttribute(structure: Structure2D, attribute: A): V? { val origin = structure.toEjml().origin - return when (type) { - QRDecompositionFeature::class -> object : QRDecompositionFeature { - private val qr by lazy { - DecompositionFactory_DSCC.qr(FillReducing.NONE).apply { decompose(origin.copy()) } - } - - override val q: Matrix by lazy { - qr.getQ(null, false).wrapMatrix().withFeature(OrthogonalFeature) - } - - override val r: Matrix by lazy { qr.getR(null, false).wrapMatrix().withFeature(UFeature) } + val raw: Any? = when (attribute) { + Inverted -> { + val res = DMatrixRMaj(origin.numRows,origin.numCols) + CommonOps_DSCC.invert(origin,res) + res.wrapMatrix() } - CholeskyDecompositionFeature::class -> object : CholeskyDecompositionFeature { + Determinant -> CommonOps_DSCC.det(origin) + + QR -> object : QRDecomposition { + val ejmlQr by lazy { DecompositionFactory_DSCC.qr(FillReducing.NONE).apply { decompose(origin.copy()) } } + override val q: Matrix get() = ejmlQr.getQ(null, false).wrapMatrix() + override val r: Matrix get() = ejmlQr.getR(null, false).wrapMatrix() + } + + Cholesky -> object : CholeskyDecomposition { override val l: Matrix by lazy { val cholesky = DecompositionFactory_DSCC.cholesky().apply { decompose(origin.copy()) } - (cholesky.getT(null) as DMatrix).wrapMatrix().withFeature(LFeature) + (cholesky.getT(null) as DMatrix).wrapMatrix().withAttribute(LowerTriangular) } } - LUDecompositionFeature::class, DeterminantFeature::class, InverseMatrixFeature::class -> object : - LUDecompositionFeature, DeterminantFeature, InverseMatrixFeature { - private val lu by lazy { + LUP -> object : LupDecomposition { + private val lup by lazy { DecompositionFactory_DSCC.lu(FillReducing.NONE).apply { decompose(origin.copy()) } } - override val l: Matrix by lazy { - lu.getLower(null).wrapMatrix().withFeature(LFeature) - } + override val l: Matrix + get() = lup.getLower(null).wrapMatrix().withAttribute(LowerTriangular) - override val u: Matrix by lazy { - lu.getUpper(null).wrapMatrix().withFeature(UFeature) - } - override val inverse: Matrix by lazy { - var a = origin - val inverse = DMatrixRMaj(1, 1) - val solver = LinearSolverFactory_DSCC.lu(FillReducing.NONE) - if (solver.modifiesA()) a = a.copy() - val i = CommonOps_DDRM.identity(a.numRows) - solver.solve(i, inverse) - inverse.wrapMatrix() - } - - override val determinant: Double by lazy { elementAlgebra.number(lu.computeDeterminant().real) } + override val u: Matrix + get() = lup.getUpper(null).wrapMatrix().withAttribute(UpperTriangular) + override val pivot: IntBuffer get() = lup.getRowPivotV(null).asBuffer() } else -> null - }?.let{ - type.cast(it) } + + @Suppress("UNCHECKED_CAST") + return raw as V? } /** @@ -793,7 +751,6 @@ public object EjmlLinearSpaceDSCC : EjmlLinearSpace.plus(other: Matrix): EjmlFloatMatrix { val out = FMatrixSparseCSC(1, 1) - + CommonOps_FSCC.add( elementAlgebra.one, toEjml().origin, elementAlgebra.one, - other.toEjml().origin, + other.toEjml().origin, out, - null, + null, null, ) @@ -907,7 +864,7 @@ public object EjmlLinearSpaceFSCC : EjmlLinearSpace): EjmlFloatVector = v * this - - @UnstableKMathAPI - override fun computeFeature(structure: Matrix, type: KClass): F? { - structure.getFeature(type)?.let { return it } + override fun > computeAttribute(structure: Structure2D, attribute: A): V? { val origin = structure.toEjml().origin - return when (type) { - QRDecompositionFeature::class -> object : QRDecompositionFeature { - private val qr by lazy { - DecompositionFactory_FSCC.qr(FillReducing.NONE).apply { decompose(origin.copy()) } - } - - override val q: Matrix by lazy { - qr.getQ(null, false).wrapMatrix().withFeature(OrthogonalFeature) - } - - override val r: Matrix by lazy { qr.getR(null, false).wrapMatrix().withFeature(UFeature) } + val raw: Any? = when (attribute) { + Inverted -> { + val res = FMatrixRMaj(origin.numRows,origin.numCols) + CommonOps_FSCC.invert(origin,res) + res.wrapMatrix() } - CholeskyDecompositionFeature::class -> object : CholeskyDecompositionFeature { - override val l: Matrix by lazy { + Determinant -> CommonOps_FSCC.det(origin) + + QR -> object : QRDecomposition { + val ejmlQr by lazy { DecompositionFactory_FSCC.qr(FillReducing.NONE).apply { decompose(origin.copy()) } } + override val q: Matrix get() = ejmlQr.getQ(null, false).wrapMatrix() + override val r: Matrix get() = ejmlQr.getR(null, false).wrapMatrix() + } + + Cholesky -> object : CholeskyDecomposition { + override val l: Matrix by lazy { val cholesky = DecompositionFactory_FSCC.cholesky().apply { decompose(origin.copy()) } - (cholesky.getT(null) as FMatrix).wrapMatrix().withFeature(LFeature) + (cholesky.getT(null) as FMatrix).wrapMatrix().withAttribute(LowerTriangular) } } - LUDecompositionFeature::class, DeterminantFeature::class, InverseMatrixFeature::class -> object : - LUDecompositionFeature, DeterminantFeature, InverseMatrixFeature { - private val lu by lazy { + LUP -> object : LupDecomposition { + private val lup by lazy { DecompositionFactory_FSCC.lu(FillReducing.NONE).apply { decompose(origin.copy()) } } - override val l: Matrix by lazy { - lu.getLower(null).wrapMatrix().withFeature(LFeature) - } + override val l: Matrix + get() = lup.getLower(null).wrapMatrix().withAttribute(LowerTriangular) - override val u: Matrix by lazy { - lu.getUpper(null).wrapMatrix().withFeature(UFeature) - } - override val inverse: Matrix by lazy { - var a = origin - val inverse = FMatrixRMaj(1, 1) - val solver = LinearSolverFactory_FSCC.lu(FillReducing.NONE) - if (solver.modifiesA()) a = a.copy() - val i = CommonOps_FDRM.identity(a.numRows) - solver.solve(i, inverse) - inverse.wrapMatrix() - } - - override val determinant: Float by lazy { elementAlgebra.number(lu.computeDeterminant().real) } + override val u: Matrix + get() = lup.getUpper(null).wrapMatrix().withAttribute(UpperTriangular) + override val pivot: IntBuffer get() = lup.getRowPivotV(null).asBuffer() } else -> null - }?.let{ - type.cast(it) } + + @Suppress("UNCHECKED_CAST") + return raw as V? } /** diff --git a/kmath-ejml/src/test/kotlin/space/kscience/kmath/ejml/EjmlMatrixTest.kt b/kmath-ejml/src/test/kotlin/space/kscience/kmath/ejml/EjmlMatrixTest.kt index 03b9b57b1..8b1b28e7d 100644 --- a/kmath-ejml/src/test/kotlin/space/kscience/kmath/ejml/EjmlMatrixTest.kt +++ b/kmath-ejml/src/test/kotlin/space/kscience/kmath/ejml/EjmlMatrixTest.kt @@ -58,19 +58,19 @@ internal class EjmlMatrixTest { @OptIn(UnstableKMathAPI::class) @Test - fun features() { + fun features() = EjmlLinearSpaceDDRM { val m = randomMatrix val w = EjmlDoubleMatrix(m) - val det: Determinant = EjmlLinearSpaceDDRM.attributeForOrNull(w) ?: fail() - assertEquals(CommonOps_DDRM.det(m), det.determinant) - val lup: LupDecompositionAttribute = EjmlLinearSpaceDDRM.attributeForOrNull(w) ?: fail() + val det: Double = w.getOrComputeAttribute(Determinant) ?: fail() + assertEquals(CommonOps_DDRM.det(m), det) + val lup: LupDecomposition = w.getOrComputeAttribute(LUP) ?: fail() val ludecompositionF64 = DecompositionFactory_DDRM.lu(m.numRows, m.numCols) .also { it.decompose(m.copy()) } assertMatrixEquals(EjmlDoubleMatrix(ludecompositionF64.getLower(null)), lup.l) assertMatrixEquals(EjmlDoubleMatrix(ludecompositionF64.getUpper(null)), lup.u) - assertMatrixEquals(EjmlDoubleMatrix(ludecompositionF64.getRowPivot(null)), lup.p) + assertMatrixEquals(EjmlDoubleMatrix(ludecompositionF64.getRowPivot(null)), lup.pivotMatrix(this)) } @Test diff --git a/kmath-for-real/build.gradle.kts b/kmath-for-real/build.gradle.kts index 99ce5903f..a0426b516 100644 --- a/kmath-for-real/build.gradle.kts +++ b/kmath-for-real/build.gradle.kts @@ -6,6 +6,7 @@ kscience { jvm() js() native() + wasm() dependencies { api(projects.kmathCore) diff --git a/kmath-for-real/src/commonTest/kotlin/space/kscience/kmath/real/DoubleVectorTest.kt b/kmath-for-real/src/commonTest/kotlin/space/kscience/kmath/real/DoubleVectorTest.kt index 29aa2ec2e..d4051c8d9 100644 --- a/kmath-for-real/src/commonTest/kotlin/space/kscience/kmath/real/DoubleVectorTest.kt +++ b/kmath-for-real/src/commonTest/kotlin/space/kscience/kmath/real/DoubleVectorTest.kt @@ -7,7 +7,7 @@ package space.kscience.kmath.real import space.kscience.kmath.linear.asMatrix import space.kscience.kmath.linear.linearSpace -import space.kscience.kmath.linear.transpose +import space.kscience.kmath.linear.transposed import space.kscience.kmath.operations.algebra import space.kscience.kmath.structures.Float64Buffer import kotlin.test.Test @@ -34,7 +34,7 @@ internal class DoubleVectorTest { val vector1 = Float64Buffer(5) { it.toDouble() } val vector2 = Float64Buffer(5) { 5 - it.toDouble() } val matrix1 = vector1.asMatrix() - val matrix2 = vector2.asMatrix().transpose() + val matrix2 = vector2.asMatrix().transposed() val product = matrix1 dot matrix2 assertEquals(5.0, product[1, 0]) assertEquals(6.0, product[2, 2]) diff --git a/kmath-functions/build.gradle.kts b/kmath-functions/build.gradle.kts index 3c1fbb07c..9296aaaf0 100644 --- a/kmath-functions/build.gradle.kts +++ b/kmath-functions/build.gradle.kts @@ -6,7 +6,6 @@ kscience{ jvm() js() native() - wasm() dependencies { diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/GaussIntegrator.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/GaussIntegrator.kt index a4e659545..e2f5c77ba 100644 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/GaussIntegrator.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/GaussIntegrator.kt @@ -92,7 +92,7 @@ public inline fun GaussIntegrator.integrate( range: ClosedRange, order: Int = 10, intervals: Int = 10, - attributesBuilder: AttributesBuilder>.() -> Unit, + attributesBuilder: AttributesBuilder>.() -> Unit = {}, noinline function: (Double) -> T, ): UnivariateIntegrand { require(range.endInclusive > range.start) { "The range upper bound should be higher than lower bound" } diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/interpolation/SplineInterpolator.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/interpolation/SplineInterpolator.kt index e77a2820b..2b58f0b05 100644 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/interpolation/SplineInterpolator.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/interpolation/SplineInterpolator.kt @@ -23,7 +23,7 @@ import space.kscience.kmath.structures.MutableBufferFactory */ public class SplineInterpolator>( override val algebra: Field, - public val bufferFactory: MutableBufferFactory, + public val bufferFactory: MutableBufferFactory = algebra.bufferFactory, ) : PolynomialInterpolator { //TODO possibly optimize zeroed buffers diff --git a/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/functions/testUtils/IntModulo.kt b/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/functions/testUtils/IntModulo.kt index 1f1e1a83f..d53a1ac2b 100644 --- a/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/functions/testUtils/IntModulo.kt +++ b/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/functions/testUtils/IntModulo.kt @@ -9,6 +9,7 @@ package space.kscience.kmath.functions.testUtils import space.kscience.kmath.operations.Ring import space.kscience.kmath.operations.ScaleOperations +import space.kscience.kmath.structures.MutableBufferFactory class IntModulo { @@ -109,15 +110,17 @@ class IntModulo { } @Suppress("EXTENSION_SHADOWED_BY_MEMBER", "OVERRIDE_BY_INLINE") -class IntModuloRing : Ring, ScaleOperations { +class IntModuloRing(modulus: Int) : Ring, ScaleOperations { val modulus: Int - constructor(modulus: Int) { + init { require(modulus != 0) { "modulus can not be zero" } this.modulus = if (modulus < 0) -modulus else modulus } + override val bufferFactory: MutableBufferFactory = MutableBufferFactory() + override inline val zero: IntModulo get() = IntModulo(0, modulus, toCheckInput = false) override inline val one: IntModulo get() = IntModulo(1, modulus, toCheckInput = false) diff --git a/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/functions/testUtils/Rational.kt b/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/functions/testUtils/Rational.kt index 98150355c..c810cba2e 100644 --- a/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/functions/testUtils/Rational.kt +++ b/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/functions/testUtils/Rational.kt @@ -10,6 +10,7 @@ package space.kscience.kmath.functions.testUtils import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.operations.Field import space.kscience.kmath.operations.NumbersAddOps +import space.kscience.kmath.structures.MutableBufferFactory @Suppress("NAME_SHADOWING") class Rational { @@ -159,6 +160,7 @@ class Rational { @Suppress("EXTENSION_SHADOWED_BY_MEMBER", "OVERRIDE_BY_INLINE") @OptIn(UnstableKMathAPI::class) object RationalField : Field, NumbersAddOps { + override val bufferFactory: MutableBufferFactory = MutableBufferFactory() override inline val zero: Rational get() = Rational.ZERO override inline val one: Rational get() = Rational.ONE diff --git a/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/integration/SplineIntegralTest.kt b/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/integration/SplineIntegralTest.kt index 7e161f7c9..946f8811c 100644 --- a/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/integration/SplineIntegralTest.kt +++ b/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/integration/SplineIntegralTest.kt @@ -18,15 +18,15 @@ import kotlin.test.assertEquals class SplineIntegralTest { @Test - fun integratePolynomial(){ + fun integratePolynomial() { val polynomial = Polynomial(1.0, 2.0, 3.0) - val integral = polynomial.integrate(Float64Field,1.0..2.0) + val integral = polynomial.integrate(Float64Field, 1.0..2.0) assertEquals(11.0, integral, 0.001) } @Test fun gaussSin() { - val res = Float64Field.splineIntegrator.integrate(0.0..2 * PI, IntegrandMaxCalls(5)) { x -> + val res = Float64Field.splineIntegrator.integrate(0.0..2 * PI, { IntegrandMaxCalls(5) }) { x -> sin(x) } assertEquals(0.0, res.value, 1e-2) @@ -34,8 +34,8 @@ class SplineIntegralTest { @Test fun gaussUniform() { - val res = Float64Field.splineIntegrator.integrate(35.0..100.0, IntegrandMaxCalls(20)) { x -> - if(x in 30.0..50.0){ + val res = Float64Field.splineIntegrator.integrate(35.0..100.0, { IntegrandMaxCalls(20) }) { x -> + if (x in 30.0..50.0) { 1.0 } else { 0.0 diff --git a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Line.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Line.kt index c3ab61d89..a226ab04d 100644 --- a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Line.kt +++ b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Line.kt @@ -7,8 +7,8 @@ package space.kscience.kmath.geometry import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable -import space.kscience.kmath.geometry.euclidean2d.DoubleVector2D -import space.kscience.kmath.geometry.euclidean3d.DoubleVector3D +import space.kscience.kmath.geometry.euclidean2d.Float64Vector2D +import space.kscience.kmath.geometry.euclidean3d.Float64Vector3D /** * A line formed by [start] vector of start and a [direction] vector. Direction vector is not necessarily normalized, @@ -25,8 +25,8 @@ private data class LineImpl(override val start: V, override val dir public fun Line(base: V, direction: V): Line = LineImpl(base, direction) -public typealias Line2D = Line -public typealias Line3D = Line +public typealias Line2D = Line +public typealias Line3D = Line /** * A directed line segment between [begin] and [end] @@ -49,5 +49,5 @@ public fun LineSegment.line(algebra: GeometrySpace): Line Line(begin, end - begin) } -public typealias LineSegment2D = LineSegment -public typealias LineSegment3D = LineSegment +public typealias LineSegment2D = LineSegment +public typealias LineSegment3D = LineSegment diff --git a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Vector3D.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Vector3D.kt index 71442cf63..64396baff 100644 --- a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Vector3D.kt +++ b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Vector3D.kt @@ -5,6 +5,7 @@ package space.kscience.kmath.geometry +import space.kscience.attributes.SafeType import space.kscience.kmath.linear.Point import space.kscience.kmath.structures.Buffer @@ -33,6 +34,9 @@ public fun Buffer.asVector3D(): Vector3D = object : Vector3D { require(this@asVector3D.size == 3) { "Buffer of size 3 is required for Vector3D" } } + override val type: SafeType = this@asVector3D.type + + override val x: T get() = this@asVector3D[0] override val y: T get() = this@asVector3D[1] override val z: T get() = this@asVector3D[2] diff --git a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/angles.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/angles.kt index 576a891fe..ff3efc126 100644 --- a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/angles.kt +++ b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/angles.kt @@ -11,6 +11,8 @@ import kotlinx.serialization.builtins.serializer import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder +import space.kscience.kmath.operations.Group +import space.kscience.kmath.structures.MutableBufferFactory import kotlin.jvm.JvmInline import kotlin.math.PI import kotlin.math.floor @@ -28,11 +30,19 @@ public sealed interface Angle : Comparable { public operator fun div(other: Angle): Double public operator fun unaryMinus(): Angle - public companion object { - public val zero: Radians = Radians(0.0) + public companion object: Group { + override val zero: Radians = Radians(0.0) public val pi: Radians = Radians(PI) public val piTimes2: Radians = Radians(PI * 2) public val piDiv2: Radians = Radians(PI / 2) + + + override fun add(left: Angle, right: Angle): Angle = left + right + + @Suppress("EXTENSION_SHADOWED_BY_MEMBER") + override fun Angle.unaryMinus(): Angle = -this + + override val bufferFactory: MutableBufferFactory = MutableBufferFactory() } } @@ -43,7 +53,7 @@ public object AngleSerializer : KSerializer { override fun deserialize(decoder: Decoder): Angle = decoder.decodeDouble().degrees override fun serialize(encoder: Encoder, value: Angle) { - encoder.encodeDouble(value.degrees) + encoder.encodeDouble(value.toDegrees().value) } } @@ -56,16 +66,16 @@ public value class Radians(public val value: Double) : Angle { override fun toRadians(): Radians = this override fun toDegrees(): Degrees = Degrees(value * 180 / PI) - public override fun plus(other: Angle): Radians = Radians(value + other.radians) - public override fun minus(other: Angle): Radians = Radians(value - other.radians) + public override fun plus(other: Angle): Radians = Radians(value + other.toRadians().value) + public override fun minus(other: Angle): Radians = Radians(value - other.toRadians().value) public override fun times(other: Number): Radians = Radians(value * other.toDouble()) public override fun div(other: Number): Radians = Radians(value / other.toDouble()) - override fun div(other: Angle): Double = value / other.radians + override fun div(other: Angle): Double = value / other.toRadians().value public override fun unaryMinus(): Radians = Radians(-value) - override fun compareTo(other: Angle): Int = value.compareTo(other.radians) + override fun compareTo(other: Angle): Int = value.compareTo(other.toRadians().value) } public fun sin(angle: Angle): Double = kotlin.math.sin(angle.toRadians().value) @@ -85,16 +95,16 @@ public value class Degrees(public val value: Double) : Angle { override fun toRadians(): Radians = Radians(value * PI / 180) override fun toDegrees(): Degrees = this - public override fun plus(other: Angle): Degrees = Degrees(value + other.degrees) - public override fun minus(other: Angle): Degrees = Degrees(value - other.degrees) + public override fun plus(other: Angle): Degrees = Degrees(value + other.toDegrees().value) + public override fun minus(other: Angle): Degrees = Degrees(value - other.toDegrees().value) public override fun times(other: Number): Degrees = Degrees(value * other.toDouble()) public override fun div(other: Number): Degrees = Degrees(value / other.toDouble()) - override fun div(other: Angle): Double = value / other.degrees + override fun div(other: Angle): Double = value / other.toDegrees().value public override fun unaryMinus(): Degrees = Degrees(-value) - override fun compareTo(other: Angle): Int = value.compareTo(other.degrees) + override fun compareTo(other: Angle): Int = value.compareTo(other.toDegrees().value) } public val Number.degrees: Degrees get() = Degrees(toDouble()) @@ -106,6 +116,6 @@ public val Angle.degrees: Double get() = toDegrees().value * Normalized angle 2 PI range symmetric around [center]. By default, uses (0, 2PI) range. */ public fun Angle.normalized(center: Angle = Angle.pi): Angle = - this - Angle.piTimes2 * floor((radians + PI - center.radians) / PI / 2) + this - Angle.piTimes2 * floor((toRadians().value + PI - center.toRadians().value) / PI / 2) public fun abs(angle: Angle): Angle = if (angle < Angle.zero) -angle else angle \ No newline at end of file diff --git a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean2d/Float32Space2D.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean2d/Float32Space2D.kt index d50e6c4b2..d687a3574 100644 --- a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean2d/Float32Space2D.kt +++ b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean2d/Float32Space2D.kt @@ -11,19 +11,22 @@ import kotlinx.serialization.Serializable import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder +import space.kscience.attributes.SafeType import space.kscience.kmath.geometry.GeometrySpace import space.kscience.kmath.geometry.Vector2D import space.kscience.kmath.operations.Float32Field import space.kscience.kmath.structures.Float32 +import space.kscience.kmath.structures.MutableBufferFactory import kotlin.math.pow import kotlin.math.sqrt @Serializable(Float32Space2D.VectorSerializer::class) -public interface Float32Vector2D : Vector2D +public interface Float32Vector2D : Vector2D{ + override val type: SafeType get() = Float32Field.type +} public object Float32Space2D : GeometrySpace { - @Serializable @SerialName("Float32Vector2D") private data class Vector2DImpl( @@ -72,6 +75,8 @@ public object Float32Space2D : GeometrySpace { public val yAxis: Float32Vector2D = vector(0.0, 1.0) override val defaultPrecision: Float32 = 1e-3f + + override val bufferFactory: MutableBufferFactory = MutableBufferFactory() } public fun Float32Vector2D(x: Number, y: Number): Float32Vector2D = Float32Space2D.vector(x, y) diff --git a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean2d/Float64Space2D.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean2d/Float64Space2D.kt index 0a43a46ea..05b9401d7 100644 --- a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean2d/Float64Space2D.kt +++ b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean2d/Float64Space2D.kt @@ -11,66 +11,77 @@ import kotlinx.serialization.Serializable import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder +import space.kscience.attributes.SafeType import space.kscience.kmath.geometry.GeometrySpace import space.kscience.kmath.geometry.Vector2D -import space.kscience.kmath.linear.Float64LinearSpace import space.kscience.kmath.operations.Float64Field import space.kscience.kmath.operations.ScaleOperations +import space.kscience.kmath.structures.Float64 +import space.kscience.kmath.structures.MutableBufferFactory import kotlin.math.pow import kotlin.math.sqrt -public typealias DoubleVector2D = Vector2D -public typealias Float64Vector2D = Vector2D +@Serializable(Float64Space2D.VectorSerializer::class) +public interface Float64Vector2D : Vector2D { + override val type: SafeType get() = Float64Field.type +} + +@Deprecated("Use Float64Vector2D", ReplaceWith("Float64Vector2D")) +public typealias DoubleVector2D = Float64Vector2D -public val Vector2D.r: Double get() = Float64Space2D.norm(this) /** * 2D Euclidean space */ -public object Float64Space2D : GeometrySpace, ScaleOperations { +public object Float64Space2D : GeometrySpace, ScaleOperations { + @Serializable @SerialName("Float64Vector2D") private data class Vector2DImpl( override val x: Double, override val y: Double, - ) : DoubleVector2D + ) : Float64Vector2D - public object VectorSerializer : KSerializer { + public object VectorSerializer : KSerializer { private val proxySerializer = Vector2DImpl.serializer() override val descriptor: SerialDescriptor get() = proxySerializer.descriptor - override fun deserialize(decoder: Decoder): DoubleVector2D = decoder.decodeSerializableValue(proxySerializer) + override fun deserialize(decoder: Decoder): Float64Vector2D = decoder.decodeSerializableValue(proxySerializer) - override fun serialize(encoder: Encoder, value: DoubleVector2D) { + override fun serialize(encoder: Encoder, value: Float64Vector2D) { val vector = value as? Vector2DImpl ?: Vector2DImpl(value.x, value.y) encoder.encodeSerializableValue(proxySerializer, vector) } } - public fun vector(x: Number, y: Number): DoubleVector2D = Vector2DImpl(x.toDouble(), y.toDouble()) + public fun vector(x: Number, y: Number): Float64Vector2D = Vector2DImpl(x.toDouble(), y.toDouble()) - override val zero: DoubleVector2D by lazy { vector(0.0, 0.0) } + override val zero: Float64Vector2D by lazy { vector(0.0, 0.0) } - override fun norm(arg: DoubleVector2D): Double = sqrt(arg.x.pow(2) + arg.y.pow(2)) + override fun norm(arg: Float64Vector2D): Double = sqrt(arg.x.pow(2) + arg.y.pow(2)) - override fun DoubleVector2D.unaryMinus(): DoubleVector2D = vector(-x, -y) + override fun Float64Vector2D.unaryMinus(): Float64Vector2D = vector(-x, -y) - override fun DoubleVector2D.distanceTo(other: DoubleVector2D): Double = norm(this - other) - override fun add(left: DoubleVector2D, right: DoubleVector2D): DoubleVector2D = + override fun Float64Vector2D.distanceTo(other: Float64Vector2D): Double = norm(this - other) + override fun add(left: Float64Vector2D, right: Float64Vector2D): Float64Vector2D = vector(left.x + right.x, left.y + right.y) - override fun scale(a: DoubleVector2D, value: Double): DoubleVector2D = vector(a.x * value, a.y * value) - override fun DoubleVector2D.dot(other: DoubleVector2D): Double = x * other.x + y * other.y + override fun scale(a: Float64Vector2D, value: Double): Float64Vector2D = vector(a.x * value, a.y * value) + override fun Float64Vector2D.dot(other: Float64Vector2D): Double = x * other.x + y * other.y - public val xAxis: DoubleVector2D = vector(1.0, 0.0) - public val yAxis: DoubleVector2D = vector(0.0, 1.0) + public val xAxis: Float64Vector2D = vector(1.0, 0.0) + public val yAxis: Float64Vector2D = vector(0.0, 1.0) override val defaultPrecision: Double = 1e-6 + + override val bufferFactory: MutableBufferFactory = MutableBufferFactory() } public fun Float64Vector2D(x: Number, y: Number): Float64Vector2D = Float64Space2D.vector(x, y) +public val Float64Vector2D.r: Float64 get() = Float64Space2D.norm(this) + public val Float64Field.euclidean2D: Float64Space2D get() = Float64Space2D \ No newline at end of file diff --git a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean3d/Float32Space3D.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean3d/Float32Space3D.kt index ee4b965cd..7204ac4f9 100644 --- a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean3d/Float32Space3D.kt +++ b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean3d/Float32Space3D.kt @@ -11,15 +11,19 @@ import kotlinx.serialization.Serializable import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder +import space.kscience.attributes.SafeType import space.kscience.kmath.geometry.GeometrySpace import space.kscience.kmath.geometry.Vector3D import space.kscience.kmath.operations.Float32Field import space.kscience.kmath.structures.Float32 +import space.kscience.kmath.structures.MutableBufferFactory import kotlin.math.pow import kotlin.math.sqrt @Serializable(Float32Space3D.VectorSerializer::class) -public interface Float32Vector3D : Vector3D +public interface Float32Vector3D : Vector3D{ + override val type: SafeType get() = Float32Field.type +} public object Float32Space3D : GeometrySpace { @@ -101,6 +105,8 @@ public object Float32Space3D : GeometrySpace { public val zAxis: Float32Vector3D = vector(0.0, 0.0, 1.0) override val defaultPrecision: Float32 = 1e-3f + + override val bufferFactory: MutableBufferFactory = MutableBufferFactory() } public fun Float32Vector3D(x: Number, y: Number, z: Number): Float32Vector3D = Float32Space3D.vector(x, y, z) diff --git a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean3d/Float64Space3D.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean3d/Float64Space3D.kt index d0b1ac581..a2c23926a 100644 --- a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean3d/Float64Space3D.kt +++ b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean3d/Float64Space3D.kt @@ -11,10 +11,13 @@ import kotlinx.serialization.Serializable import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder +import space.kscience.attributes.SafeType import space.kscience.kmath.geometry.GeometrySpace import space.kscience.kmath.geometry.Vector3D import space.kscience.kmath.linear.Float64LinearSpace import space.kscience.kmath.operations.Float64Field +import space.kscience.kmath.structures.Float64 +import space.kscience.kmath.structures.MutableBufferFactory import kotlin.math.pow import kotlin.math.sqrt @@ -31,12 +34,16 @@ internal fun leviCivita(i: Int, j: Int, k: Int): Int = when { else -> 0 } -public typealias DoubleVector3D = Vector3D -public typealias Float64Vector3D = Vector3D +@Serializable(Float64Space3D.VectorSerializer::class) +public interface Float64Vector3D : Vector3D { + override val type: SafeType get() = Float64Field.type +} -public val DoubleVector3D.r: Double get() = Float64Space3D.norm(this) +@Deprecated("Use Float64Vector3D", ReplaceWith("Float64Vector3D")) +public typealias DoubleVector3D = Float64Vector3D -public object Float64Space3D : GeometrySpace{ + +public object Float64Space3D : GeometrySpace, Double> { public val linearSpace: Float64LinearSpace = Float64LinearSpace @@ -46,52 +53,52 @@ public object Float64Space3D : GeometrySpace{ override val x: Double, override val y: Double, override val z: Double, - ) : DoubleVector3D + ) : Float64Vector3D - public object VectorSerializer : KSerializer { + public object VectorSerializer : KSerializer { private val proxySerializer = Vector3DImpl.serializer() override val descriptor: SerialDescriptor get() = proxySerializer.descriptor - override fun deserialize(decoder: Decoder): DoubleVector3D = decoder.decodeSerializableValue(proxySerializer) + override fun deserialize(decoder: Decoder): Float64Vector3D = decoder.decodeSerializableValue(proxySerializer) - override fun serialize(encoder: Encoder, value: DoubleVector3D) { + override fun serialize(encoder: Encoder, value: Float64Vector3D) { val vector = value as? Vector3DImpl ?: Vector3DImpl(value.x, value.y, value.z) encoder.encodeSerializableValue(proxySerializer, vector) } } - public fun vector(x: Double, y: Double, z: Double): DoubleVector3D = + public fun vector(x: Double, y: Double, z: Double): Float64Vector3D = Vector3DImpl(x, y, z) - public fun vector(x: Number, y: Number, z: Number): DoubleVector3D = + public fun vector(x: Number, y: Number, z: Number): Float64Vector3D = vector(x.toDouble(), y.toDouble(), z.toDouble()) - override val zero: DoubleVector3D by lazy { vector(0.0, 0.0, 0.0) } + override val zero: Float64Vector3D by lazy { vector(0.0, 0.0, 0.0) } - override fun norm(arg: DoubleVector3D): Double = sqrt(arg.x.pow(2) + arg.y.pow(2) + arg.z.pow(2)) + override fun norm(arg: Vector3D): Double = sqrt(arg.x.pow(2) + arg.y.pow(2) + arg.z.pow(2)) - public fun DoubleVector3D.norm(): Double = norm(this) + public fun Vector3D.norm(): Double = norm(this) - override fun DoubleVector3D.unaryMinus(): DoubleVector3D = vector(-x, -y, -z) + override fun Vector3D.unaryMinus(): Float64Vector3D = vector(-x, -y, -z) - override fun DoubleVector3D.distanceTo(other: DoubleVector3D): Double = (this - other).norm() + override fun Vector3D.distanceTo(other: Vector3D): Double = (this - other).norm() - override fun add(left: DoubleVector3D, right: DoubleVector3D): DoubleVector3D = + override fun add(left: Vector3D, right: Vector3D): Float64Vector3D = vector(left.x + right.x, left.y + right.y, left.z + right.z) - override fun scale(a: DoubleVector3D, value: Double): DoubleVector3D = + override fun scale(a: Vector3D, value: Double): Float64Vector3D = vector(a.x * value, a.y * value, a.z * value) - override fun DoubleVector3D.dot(other: DoubleVector3D): Double = + override fun Vector3D.dot(other: Vector3D): Double = x * other.x + y * other.y + z * other.z /** * Compute vector product of [first] and [second]. The basis is assumed to be right-handed. */ public fun vectorProduct( - first: DoubleVector3D, - second: DoubleVector3D, - ): DoubleVector3D { + first: Vector3D, + second: Vector3D, + ): Float64Vector3D { var x = 0.0 var y = 0.0 var z = 0.0 @@ -110,13 +117,18 @@ public object Float64Space3D : GeometrySpace{ /** * Vector product with the right basis */ - public infix fun DoubleVector3D.cross(other: DoubleVector3D): Vector3D = vectorProduct(this, other) + public infix fun Vector3D.cross(other: Vector3D): Vector3D = vectorProduct(this, other) - public val xAxis: DoubleVector3D = vector(1.0, 0.0, 0.0) - public val yAxis: DoubleVector3D = vector(0.0, 1.0, 0.0) - public val zAxis: DoubleVector3D = vector(0.0, 0.0, 1.0) + public val xAxis: Float64Vector3D = vector(1.0, 0.0, 0.0) + public val yAxis: Float64Vector3D = vector(0.0, 1.0, 0.0) + public val zAxis: Float64Vector3D = vector(0.0, 0.0, 1.0) override val defaultPrecision: Double = 1e-6 + + override val bufferFactory: MutableBufferFactory> = MutableBufferFactory() } public val Float64Field.euclidean3D: Float64Space3D get() = Float64Space3D + + +public val Float64Vector3D.r: Double get() = Float64Space3D.norm(this) diff --git a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean3d/rotations3D.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean3d/rotations3D.kt index abb531944..212cc251e 100644 --- a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean3d/rotations3D.kt +++ b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean3d/rotations3D.kt @@ -5,6 +5,7 @@ package space.kscience.kmath.geometry.euclidean3d +import space.kscience.attributes.SafeType import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.complex.* import space.kscience.kmath.geometry.* @@ -13,6 +14,7 @@ import space.kscience.kmath.linear.Matrix import space.kscience.kmath.linear.linearSpace import space.kscience.kmath.linear.matrix import space.kscience.kmath.operations.Float64Field +import space.kscience.kmath.structures.Float64 import kotlin.math.* public operator fun Quaternion.times(other: Quaternion): Quaternion = QuaternionAlgebra.multiply(this, other) @@ -35,7 +37,7 @@ public infix fun Quaternion.dot(other: Quaternion): Double = w * other.w + x * o /** * Represent a vector as quaternion with zero a rotation angle. */ -internal fun DoubleVector3D.asQuaternion(): Quaternion = Quaternion(0.0, x, y, z) +internal fun Float64Vector3D.asQuaternion(): Quaternion = Quaternion(0.0, x, y, z) /** * Angle in radians denoted by this quaternion rotation @@ -45,7 +47,7 @@ public val Quaternion.theta: Radians get() = (kotlin.math.acos(normalized().w) * /** * Create a normalized Quaternion from rotation angle and rotation vector */ -public fun Quaternion.Companion.fromRotation(theta: Angle, vector: DoubleVector3D): Quaternion { +public fun Quaternion.Companion.fromRotation(theta: Angle, vector: Float64Vector3D): Quaternion { val s = sin(theta / 2) val c = cos(theta / 2) val norm = with(Float64Space3D) { vector.norm() } @@ -55,9 +57,9 @@ public fun Quaternion.Companion.fromRotation(theta: Angle, vector: DoubleVector3 /** * An axis of quaternion rotation */ -public val Quaternion.vector: DoubleVector3D +public val Quaternion.vector: Float64Vector3D get() { - return object : DoubleVector3D { + return object : Float64Vector3D { private val sint2 = sqrt(1 - w * w) override val x: Double get() = this@vector.x / sint2 override val y: Double get() = this@vector.y / sint2 @@ -69,7 +71,7 @@ public val Quaternion.vector: DoubleVector3D /** * Rotate a vector in a [Float64Space3D] with [quaternion] */ -public fun Float64Space3D.rotate(vector: DoubleVector3D, quaternion: Quaternion): DoubleVector3D = +public fun Float64Space3D.rotate(vector: Float64Vector3D, quaternion: Quaternion): Float64Vector3D = with(QuaternionAlgebra) { val p = vector.asQuaternion() (quaternion * p * quaternion.reciprocal).vector @@ -80,15 +82,15 @@ public fun Float64Space3D.rotate(vector: DoubleVector3D, quaternion: Quaternion) */ @UnstableKMathAPI public fun Float64Space3D.rotate( - vector: DoubleVector3D, + vector: Float64Vector3D, composition: QuaternionAlgebra.() -> Quaternion, -): DoubleVector3D = +): Float64Vector3D = rotate(vector, QuaternionAlgebra.composition()) /** * Rotate a [Float64] vector in 3D space with a rotation matrix */ -public fun Float64Space3D.rotate(vector: DoubleVector3D, matrix: Matrix): DoubleVector3D { +public fun Float64Space3D.rotate(vector: Float64Vector3D, matrix: Matrix): Vector3D { require(matrix.colNum == 3 && matrix.rowNum == 3) { "Square 3x3 rotation matrix is required" } return with(linearSpace) { (matrix dot vector).asVector3D() } } @@ -242,6 +244,8 @@ public fun Quaternion.Companion.fromEuler( * A vector consisting of angles */ public data class AngleVector(override val x: Angle, override val y: Angle, override val z: Angle) : Vector3D { + override val type: SafeType get() = Angle.type + public companion object } diff --git a/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/testUtils.kt b/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/testUtils.kt index 613a88b2f..3f9c86add 100644 --- a/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/testUtils.kt +++ b/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/testUtils.kt @@ -5,8 +5,7 @@ package space.kscience.kmath.geometry -import space.kscience.kmath.geometry.euclidean2d.DoubleVector2D -import space.kscience.kmath.geometry.euclidean3d.DoubleVector3D +import space.kscience.kmath.structures.Float64 import kotlin.math.abs import kotlin.test.assertEquals @@ -27,12 +26,12 @@ fun grid( return xs.flatMap { x -> ys.map { y -> x to y } } } -fun assertVectorEquals(expected: DoubleVector2D, actual: DoubleVector2D, absoluteTolerance: Double = 1e-3) { +fun assertVectorEquals(expected: Vector2D, actual: Vector2D, absoluteTolerance: Double = 1e-3) { assertEquals(expected.x, actual.x, absoluteTolerance) assertEquals(expected.y, actual.y, absoluteTolerance) } -fun assertVectorEquals(expected: DoubleVector3D, actual: DoubleVector3D, absoluteTolerance: Double = 1e-6) { +fun assertVectorEquals(expected: Vector3D, actual: Vector3D, absoluteTolerance: Double = 1e-6) { assertEquals(expected.x, actual.x, absoluteTolerance) assertEquals(expected.y, actual.y, absoluteTolerance) assertEquals(expected.z, actual.z, absoluteTolerance) diff --git a/kmath-histograms/build.gradle.kts b/kmath-histograms/build.gradle.kts index 33704c29e..63791d61c 100644 --- a/kmath-histograms/build.gradle.kts +++ b/kmath-histograms/build.gradle.kts @@ -6,6 +6,8 @@ kscience{ jvm() js() native() + wasm() + useCoroutines() } //apply(plugin = "kotlinx-atomicfu") @@ -21,7 +23,6 @@ kotlin.sourceSets { dependencies { implementation(project(":kmath-for-real")) implementation(projects.kmath.kmathStat) - implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.0") } } } 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 79f145792..7f6fb2d26 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 @@ -47,7 +47,7 @@ public interface Histogram> { } } -public interface HistogramBuilder { +public interface HistogramBuilder { /** * The default value increment for a bin @@ -61,9 +61,9 @@ public interface HistogramBuilder { } -public fun HistogramBuilder.put(point: Point): Unit = putValue(point) +public fun HistogramBuilder.put(point: Point): Unit = putValue(point) -public fun HistogramBuilder.put(vararg point: T): Unit = put(point.asBuffer()) +public inline fun HistogramBuilder.put(vararg point: T): Unit = put(point.asList().asBuffer()) public fun HistogramBuilder.put(vararg point: Number): Unit = put(Float64Buffer(point.map { it.toDouble() }.toDoubleArray())) diff --git a/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/UniformHistogram1D.kt b/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/UniformHistogram1D.kt index 0326e8757..770fd70a0 100644 --- a/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/UniformHistogram1D.kt +++ b/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/UniformHistogram1D.kt @@ -12,6 +12,7 @@ import space.kscience.kmath.operations.Ring import space.kscience.kmath.operations.ScaleOperations import space.kscience.kmath.operations.invoke import space.kscience.kmath.structures.Buffer +import space.kscience.kmath.structures.MutableBufferFactory import kotlin.math.floor @OptIn(UnstableKMathAPI::class) @@ -46,6 +47,8 @@ public class UniformHistogram1DGroup( public val startPoint: Double = 0.0, ) : Group>, ScaleOperations> where A : Ring, A : ScaleOperations { + override val bufferFactory: MutableBufferFactory> = MutableBufferFactory() + override val zero: UniformHistogram1D = UniformHistogram1D(this, emptyMap()) /** diff --git a/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/UniformHistogramGroupND.kt b/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/UniformHistogramGroupND.kt index 839744f89..8a914530b 100644 --- a/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/UniformHistogramGroupND.kt +++ b/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/UniformHistogramGroupND.kt @@ -37,6 +37,8 @@ public class UniformHistogramGroupND>( require(!lower.indices.any { upper[it] - lower[it] < 0 }) { "Range for one of axis is not strictly positive" } } + override val bufferFactory: MutableBufferFactory> = MutableBufferFactory() + public val dimension: Int get() = lower.size override val shape: ShapeND = ShapeND(IntArray(binNums.size) { binNums[it] + 2 }) @@ -87,7 +89,7 @@ public class UniformHistogramGroupND>( builder: HistogramBuilder.() -> Unit, ): HistogramND { val ndCounter: BufferND> = - StructureND.buffered(shape) { Counter.of(valueAlgebraND.elementAlgebra) } + BufferND(shape) { Counter.of(valueAlgebraND.elementAlgebra) } val hBuilder = object : HistogramBuilder { override val defaultValue: V get() = valueAlgebraND.elementAlgebra.one @@ -97,7 +99,8 @@ public class UniformHistogramGroupND>( } } hBuilder.apply(builder) - val values: BufferND = BufferND(ndCounter.indices, ndCounter.buffer.mapToBuffer(valueBufferFactory) { it.value }) + val values: BufferND = + BufferND(ndCounter.indices, ndCounter.buffer.mapToBuffer(valueBufferFactory) { it.value }) return HistogramND(this, values) } @@ -128,8 +131,7 @@ public fun > Histogram.Companion.uniformNDFromRanges( public fun Histogram.Companion.uniformDoubleNDFromRanges( vararg ranges: ClosedFloatingPointRange, -): UniformHistogramGroupND = - uniformNDFromRanges(Floa64FieldOpsND, *ranges, bufferFactory = ::Float64Buffer) +): UniformHistogramGroupND = uniformNDFromRanges(Floa64FieldOpsND, *ranges) /** @@ -147,21 +149,18 @@ public fun > Histogram.Companion.uniformNDFromRanges( bufferFactory: BufferFactory = valueAlgebraND.elementAlgebra.bufferFactory, ): UniformHistogramGroupND = UniformHistogramGroupND( valueAlgebraND, - DoubleBuffer( - ranges - .map(Pair, Int>::first) - .map(ClosedFloatingPointRange::start) - ), - DoubleBuffer( - ranges - .map(Pair, Int>::first) - .map(ClosedFloatingPointRange::endInclusive) - ), + ranges + .map(Pair, Int>::first) + .map(ClosedFloatingPointRange::start) + .asBuffer(), + ranges + .map(Pair, Int>::first) + .map(ClosedFloatingPointRange::endInclusive) + .asBuffer(), ranges.map(Pair, Int>::second).toIntArray(), valueBufferFactory = bufferFactory ) public fun Histogram.Companion.uniformDoubleNDFromRanges( vararg ranges: Pair, Int>, -): UniformHistogramGroupND = - uniformNDFromRanges(Floa64FieldOpsND, *ranges, bufferFactory = ::Float64Buffer) \ No newline at end of file +): UniformHistogramGroupND = uniformNDFromRanges(Floa64FieldOpsND, *ranges) \ No newline at end of file diff --git a/kmath-histograms/src/jvmMain/kotlin/space/kscience/kmath/histogram/TreeHistogramGroup.kt b/kmath-histograms/src/jvmMain/kotlin/space/kscience/kmath/histogram/TreeHistogramGroup.kt index 95658141a..c8be4f846 100644 --- a/kmath-histograms/src/jvmMain/kotlin/space/kscience/kmath/histogram/TreeHistogramGroup.kt +++ b/kmath-histograms/src/jvmMain/kotlin/space/kscience/kmath/histogram/TreeHistogramGroup.kt @@ -14,10 +14,7 @@ import space.kscience.kmath.misc.sorted import space.kscience.kmath.operations.Group import space.kscience.kmath.operations.Ring import space.kscience.kmath.operations.ScaleOperations -import space.kscience.kmath.structures.Buffer -import space.kscience.kmath.structures.first -import space.kscience.kmath.structures.indices -import space.kscience.kmath.structures.last +import space.kscience.kmath.structures.* import java.util.* private fun > TreeMap.getBin(value: Double): B? { @@ -53,6 +50,8 @@ public class TreeHistogramGroup( @PublishedApi internal val binFactory: (Double) -> DoubleDomain1D, ) : Group>, ScaleOperations> where A : Ring, A : ScaleOperations { + override val bufferFactory: MutableBufferFactory> = MutableBufferFactory() + internal inner class DomainCounter(val domain: DoubleDomain1D, val counter: Counter = Counter.of(valueAlgebra)) : ClosedRange by domain.range diff --git a/kmath-kotlingrad/src/main/kotlin/space/kscience/kmath/kotlingrad/KotlingradExpression.kt b/kmath-kotlingrad/src/main/kotlin/space/kscience/kmath/kotlingrad/KotlingradExpression.kt index 53e0beca1..07b77683d 100644 --- a/kmath-kotlingrad/src/main/kotlin/space/kscience/kmath/kotlingrad/KotlingradExpression.kt +++ b/kmath-kotlingrad/src/main/kotlin/space/kscience/kmath/kotlingrad/KotlingradExpression.kt @@ -7,6 +7,7 @@ package space.kscience.kmath.kotlingrad import ai.hypergraph.kotlingrad.api.SFun import ai.hypergraph.kotlingrad.api.SVar +import space.kscience.attributes.SafeType import space.kscience.kmath.expressions.* import space.kscience.kmath.operations.NumericAlgebra @@ -25,6 +26,8 @@ public class KotlingradExpression>( public val algebra: A, public val mst: MST, ) : SpecialDifferentiableExpression> { + override val type: SafeType = algebra.type + override fun invoke(arguments: Map): T = mst.interpret(algebra, arguments) override fun derivativeOrNull( diff --git a/kmath-nd4j/build.gradle.kts b/kmath-nd4j/build.gradle.kts index e5c4af891..bfa09e771 100644 --- a/kmath-nd4j/build.gradle.kts +++ b/kmath-nd4j/build.gradle.kts @@ -12,7 +12,7 @@ dependencies { } readme { - maturity = space.kscience.gradle.Maturity.EXPERIMENTAL + maturity = space.kscience.gradle.Maturity.DEPRECATED propertyByTemplate("artifact", rootProject.file("docs/templates/ARTIFACT-TEMPLATE.md")) feature(id = "nd4jarraystructure") { "NDStructure wrapper for INDArray" } feature(id = "nd4jarrayrings") { "Rings over Nd4jArrayStructure of Int and Long" } 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 34bbcaefb..9bfc2f8f5 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 @@ -6,8 +6,10 @@ package space.kscience.kmath.nd4j import org.nd4j.linalg.api.ndarray.INDArray +import space.kscience.attributes.SafeType import space.kscience.kmath.PerformancePitfall import space.kscience.kmath.nd.* +import space.kscience.kmath.operations.Float32Field /** * Represents a [StructureND] wrapping an [INDArray] object. @@ -31,6 +33,7 @@ public sealed class Nd4jArrayStructure : MutableStructureND { } public data class Nd4jArrayIntStructure(override val ndArray: INDArray) : Nd4jArrayStructure(), StructureNDOfInt { + override fun elementsIterator(): Iterator> = ndArray.intIterator() @OptIn(PerformancePitfall::class) @@ -47,8 +50,10 @@ public data class Nd4jArrayIntStructure(override val ndArray: INDArray) : Nd4jAr */ public fun INDArray.asIntStructure(): Nd4jArrayIntStructure = Nd4jArrayIntStructure(this) -public data class Nd4jArrayDoubleStructure(override val ndArray: INDArray) : Nd4jArrayStructure(), StructureNDOfDouble { +public data class Nd4jArrayDoubleStructure(override val ndArray: INDArray) : Nd4jArrayStructure(), + StructureNDOfDouble { override fun elementsIterator(): Iterator> = ndArray.realIterator() + @OptIn(PerformancePitfall::class) override fun get(index: IntArray): Double = ndArray.getDouble(*index) @@ -64,7 +69,11 @@ public data class Nd4jArrayDoubleStructure(override val ndArray: INDArray) : Nd4 public fun INDArray.asDoubleStructure(): Nd4jArrayStructure = Nd4jArrayDoubleStructure(this) public data class Nd4jArrayFloatStructure(override val ndArray: INDArray) : Nd4jArrayStructure() { + + override val type: SafeType get() = Float32Field.type + override fun elementsIterator(): Iterator> = ndArray.floatIterator() + @PerformancePitfall override fun get(index: IntArray): Float = ndArray.getFloat(*index) diff --git a/kmath-optimization/build.gradle.kts b/kmath-optimization/build.gradle.kts index 7250d1f72..f908b127d 100644 --- a/kmath-optimization/build.gradle.kts +++ b/kmath-optimization/build.gradle.kts @@ -6,6 +6,7 @@ kscience{ jvm() js() native() + wasm() } kotlin.sourceSets { diff --git a/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/FunctionOptimization.kt b/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/FunctionOptimization.kt index d8b3f29eb..a38e9e6e8 100644 --- a/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/FunctionOptimization.kt +++ b/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/FunctionOptimization.kt @@ -11,6 +11,10 @@ import space.kscience.kmath.expressions.Symbol public class OptimizationValue(type: SafeType) : PolymorphicAttribute(type) +public inline fun AttributesBuilder>.value(value: T) { + set(OptimizationValue(safeTypeOf()), value) +} + public enum class OptimizationDirection { MAXIMIZE, MINIMIZE diff --git a/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/OptimizationProblem.kt b/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/OptimizationProblem.kt index 49678cd57..18f552bda 100644 --- a/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/OptimizationProblem.kt +++ b/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/OptimizationProblem.kt @@ -34,10 +34,18 @@ public fun AttributesBuilder>.startAt(startingPoint: public class OptimizationCovariance : OptimizationAttribute>, PolymorphicAttribute>(safeTypeOf()) +public fun AttributesBuilder>.covariance(covariance: NamedMatrix) { + set(OptimizationCovariance(),covariance) +} + public class OptimizationResult() : OptimizationAttribute>, PolymorphicAttribute>(safeTypeOf()) +public fun AttributesBuilder>.result(result: Map) { + set(OptimizationResult(), result) +} + public val OptimizationProblem.resultOrNull: Map? get() = attributes[OptimizationResult()] public val OptimizationProblem.result: Map diff --git a/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/QowOptimizer.kt b/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/QowOptimizer.kt index 46394132b..eba637a83 100644 --- a/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/QowOptimizer.kt +++ b/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/QowOptimizer.kt @@ -264,10 +264,10 @@ public object QowOptimizer : Optimizer { qow = QoWeight(problem, res.freeParameters) res = qow.newtonianRun(maxSteps = iterations) } - val covariance = res.covariance() + return res.problem.withAttributes { - set(OptimizationResult(), res.freeParameters) - set(OptimizationCovariance(), covariance) + result(res.freeParameters) + covariance(res.covariance()) } } } \ No newline at end of file diff --git a/kmath-stat/build.gradle.kts b/kmath-stat/build.gradle.kts index 000280def..7d396b460 100644 --- a/kmath-stat/build.gradle.kts +++ b/kmath-stat/build.gradle.kts @@ -6,6 +6,7 @@ kscience{ jvm() js() native() + wasm() } kotlin.sourceSets { diff --git a/kmath-stat/src/jvmTest/kotlin/space/kscience/kmath/stat/MCScopeTest.kt b/kmath-stat/src/jvmTest/kotlin/space/kscience/kmath/stat/MCScopeTest.kt index 545e89814..a95829eff 100644 --- a/kmath-stat/src/jvmTest/kotlin/space/kscience/kmath/stat/MCScopeTest.kt +++ b/kmath-stat/src/jvmTest/kotlin/space/kscience/kmath/stat/MCScopeTest.kt @@ -68,7 +68,7 @@ internal class MCScopeTest { } - @OptIn(DelicateCoroutinesApi::class) + @OptIn(DelicateCoroutinesApi::class, ExperimentalCoroutinesApi::class) fun compareResult(test: ATest) { val res1 = runBlocking(Dispatchers.Default) { test() } val res2 = runBlocking(newSingleThreadContext("test")) { test() } diff --git a/kmath-symja/src/main/kotlin/space/kscience/kmath/symja/SymjaExpression.kt b/kmath-symja/src/main/kotlin/space/kscience/kmath/symja/SymjaExpression.kt index e5ba411e6..b23da37f5 100644 --- a/kmath-symja/src/main/kotlin/space/kscience/kmath/symja/SymjaExpression.kt +++ b/kmath-symja/src/main/kotlin/space/kscience/kmath/symja/SymjaExpression.kt @@ -7,8 +7,9 @@ package space.kscience.kmath.symja import org.matheclipse.core.eval.ExprEvaluator import org.matheclipse.core.expression.F -import space.kscience.kmath.expressions.SpecialDifferentiableExpression +import space.kscience.attributes.SafeType import space.kscience.kmath.expressions.MST +import space.kscience.kmath.expressions.SpecialDifferentiableExpression import space.kscience.kmath.expressions.Symbol import space.kscience.kmath.expressions.interpret import space.kscience.kmath.operations.NumericAlgebra @@ -30,6 +31,8 @@ public class SymjaExpression>( public val mst: MST, public val evaluator: ExprEvaluator = DEFAULT_EVALUATOR, ) : SpecialDifferentiableExpression> { + override val type: SafeType get() = algebra.type + override fun invoke(arguments: Map): T = mst.interpret(algebra, arguments) override fun derivativeOrNull(symbols: List): SymjaExpression = SymjaExpression( diff --git a/kmath-tensorflow/src/main/kotlin/space/kscience/kmath/tensorflow/DoubleTensorFlowAlgebra.kt b/kmath-tensorflow/src/main/kotlin/space/kscience/kmath/tensorflow/DoubleTensorFlowAlgebra.kt index 4c06404b1..9a559bc28 100644 --- a/kmath-tensorflow/src/main/kotlin/space/kscience/kmath/tensorflow/DoubleTensorFlowAlgebra.kt +++ b/kmath-tensorflow/src/main/kotlin/space/kscience/kmath/tensorflow/DoubleTensorFlowAlgebra.kt @@ -10,6 +10,7 @@ import org.tensorflow.Output import org.tensorflow.ndarray.NdArray import org.tensorflow.op.core.Constant import org.tensorflow.types.TFloat64 +import space.kscience.attributes.SafeType import space.kscience.kmath.PerformancePitfall import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.expressions.Symbol @@ -25,9 +26,9 @@ public class DoubleTensorFlowOutput( graph: Graph, output: Output, ) : TensorFlowOutput(graph, output) { + override val type: SafeType get() = Float64Field.type override fun org.tensorflow.Tensor.actualizeTensor(): NdArray = this as TFloat64 - } internal fun ShapeND.toLongArray(): LongArray = LongArray(size) { get(it).toLong() } diff --git a/kmath-tensorflow/src/main/kotlin/space/kscience/kmath/tensorflow/IntTensorFlowAlgebra.kt b/kmath-tensorflow/src/main/kotlin/space/kscience/kmath/tensorflow/IntTensorFlowAlgebra.kt index 186a794e9..3695a2640 100644 --- a/kmath-tensorflow/src/main/kotlin/space/kscience/kmath/tensorflow/IntTensorFlowAlgebra.kt +++ b/kmath-tensorflow/src/main/kotlin/space/kscience/kmath/tensorflow/IntTensorFlowAlgebra.kt @@ -10,11 +10,19 @@ import org.tensorflow.Output import org.tensorflow.ndarray.NdArray import org.tensorflow.types.TInt32 import org.tensorflow.types.TInt64 +import space.kscience.attributes.SafeType +import space.kscience.kmath.operations.Int32Ring +import space.kscience.kmath.operations.Int64Ring +import space.kscience.kmath.structures.Int32 +import space.kscience.kmath.structures.Int64 public class IntTensorFlowOutput( graph: Graph, output: Output, ) : TensorFlowOutput(graph, output) { + + override val type: SafeType get() = Int32Ring.type + override fun org.tensorflow.Tensor.actualizeTensor(): NdArray = this as TInt32 } @@ -22,5 +30,7 @@ public class LongTensorFlowOutput( graph: Graph, output: Output, ) : TensorFlowOutput(graph, output) { + + override val type: SafeType get() = Int64Ring.type override fun org.tensorflow.Tensor.actualizeTensor(): NdArray = this as TInt64 } \ No newline at end of file diff --git a/kmath-tensorflow/src/main/kotlin/space/kscience/kmath/tensorflow/TensorFlowAlgebra.kt b/kmath-tensorflow/src/main/kotlin/space/kscience/kmath/tensorflow/TensorFlowAlgebra.kt index 158c928c4..7e413c29c 100644 --- a/kmath-tensorflow/src/main/kotlin/space/kscience/kmath/tensorflow/TensorFlowAlgebra.kt +++ b/kmath-tensorflow/src/main/kotlin/space/kscience/kmath/tensorflow/TensorFlowAlgebra.kt @@ -17,6 +17,7 @@ import org.tensorflow.op.core.* import org.tensorflow.types.TInt32 import org.tensorflow.types.family.TNumber import org.tensorflow.types.family.TType +import space.kscience.attributes.SafeType import space.kscience.kmath.PerformancePitfall import space.kscience.kmath.UnsafeKMathAPI import space.kscience.kmath.UnstableKMathAPI @@ -39,8 +40,8 @@ public sealed interface TensorFlowTensor : Tensor /** * Static (eager) in-memory TensorFlow tensor */ -@JvmInline -public value class TensorFlowArray(public val tensor: NdArray) : Tensor { +public class TensorFlowArray(override val type: SafeType, public val tensor: NdArray) : Tensor { + override val shape: ShapeND get() = ShapeND(tensor.shape().asArray().toIntArray()) @PerformancePitfall @@ -73,7 +74,7 @@ public abstract class TensorFlowOutput( internal val actualTensor by lazy { Session(graph).use { session -> - TensorFlowArray(session.runner().fetch(output).run().first().actualizeTensor()) + TensorFlowArray(type, session.runner().fetch(output).run().first().actualizeTensor()) } } diff --git a/kmath-tensors/build.gradle.kts b/kmath-tensors/build.gradle.kts index 8977183da..82213f408 100644 --- a/kmath-tensors/build.gradle.kts +++ b/kmath-tensors/build.gradle.kts @@ -12,6 +12,7 @@ kscience{ } } native() + wasm() dependencies { api(projects.kmathCore) diff --git a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/api/Tensor.kt b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/api/Tensor.kt deleted file mode 100644 index 2a7f463bc..000000000 --- a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/api/Tensor.kt +++ /dev/null @@ -1,10 +0,0 @@ -/* - * Copyright 2018-2024 KMath contributors. - * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. - */ - -package space.kscience.kmath.tensors.api - -import space.kscience.kmath.nd.MutableStructureND - -public typealias Tensor = MutableStructureND diff --git a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/api/TensorAlgebra.kt b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/api/TensorAlgebra.kt index 6e515f3f8..c960090d2 100644 --- a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/api/TensorAlgebra.kt +++ b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/api/TensorAlgebra.kt @@ -5,11 +5,14 @@ package space.kscience.kmath.tensors.api +import space.kscience.kmath.nd.MutableStructureND import space.kscience.kmath.nd.RingOpsND import space.kscience.kmath.nd.ShapeND import space.kscience.kmath.nd.StructureND import space.kscience.kmath.operations.Ring +public typealias Tensor = MutableStructureND + /** * Algebra over a ring on [Tensor]. * For more information: https://proofwiki.org/wiki/Definition:Algebra_over_Ring diff --git a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/LevenbergMarquardtAlgorithm.kt b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/LevenbergMarquardtAlgorithm.kt index a47c9364a..b2106200e 100644 --- a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/LevenbergMarquardtAlgorithm.kt +++ b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/LevenbergMarquardtAlgorithm.kt @@ -6,7 +6,6 @@ package space.kscience.kmath.tensors.core import space.kscience.kmath.PerformancePitfall -import space.kscience.kmath.linear.transposed import space.kscience.kmath.nd.* import kotlin.math.abs import kotlin.math.max @@ -139,7 +138,7 @@ public fun DoubleTensorAlgebra.levenbergMarquardt(inputData: LMInput): LMResultI if (inputData.nargin < 5) { weight = fromArray( ShapeND(intArrayOf(1, 1)), - doubleArrayOf((inputData.realValues.transposed dot inputData.realValues).as1D()[0]) + doubleArrayOf((inputData.realValues.transposed() dot inputData.realValues).as1D()[0]) ).as2D() } @@ -266,12 +265,12 @@ public fun DoubleTensorAlgebra.levenbergMarquardt(inputData: LMInput): LMResultI settings.funcCalls += 1 // val tmp = deltaY.times(weight) - var X2Try = deltaY.as2D().transposed dot deltaY.times(weight) // Chi-squared error criteria + var X2Try = deltaY.as2D().transposed() dot deltaY.times(weight) // Chi-squared error criteria val alpha = 1.0 if (updateType == 2) { // Quadratic // One step of quadratic line update in the h direction for minimum X2 - val alphaTensor = (jtWdy.transposed dot h) / ((X2Try - x2) / 2.0 + 2 * (jtWdy.transposed dot h)) + val alphaTensor = (jtWdy.transposed() dot h) / ((X2Try - x2) / 2.0 + 2 * (jtWdy.transposed() dot h)) h = h dot alphaTensor pTry = (p + h).as2D() // update only [idx] elements pTry = smallestElementComparison( @@ -289,7 +288,7 @@ public fun DoubleTensorAlgebra.levenbergMarquardt(inputData: LMInput): LMResultI ) // residual error using p_try settings.funcCalls += 1 - X2Try = deltaY.as2D().transposed dot deltaY * weight // Chi-squared error criteria + X2Try = deltaY.as2D().transposed() dot deltaY * weight // Chi-squared error criteria } val rho = when (updateType) { // Nielsen diff --git a/kmath-viktor/src/main/kotlin/space/kscience/kmath/viktor/ViktorBuffer.kt b/kmath-viktor/src/main/kotlin/space/kscience/kmath/viktor/ViktorBuffer.kt index 2b5741ed4..88112af2a 100644 --- a/kmath-viktor/src/main/kotlin/space/kscience/kmath/viktor/ViktorBuffer.kt +++ b/kmath-viktor/src/main/kotlin/space/kscience/kmath/viktor/ViktorBuffer.kt @@ -6,12 +6,16 @@ package space.kscience.kmath.viktor import org.jetbrains.bio.viktor.F64FlatArray +import space.kscience.attributes.SafeType +import space.kscience.kmath.operations.Float64Field import space.kscience.kmath.structures.Buffer import space.kscience.kmath.structures.MutableBuffer @Suppress("NOTHING_TO_INLINE", "OVERRIDE_BY_INLINE") @JvmInline public value class ViktorBuffer(public val flatArray: F64FlatArray) : MutableBuffer { + override val type: SafeType get() = Float64Field.type + override val size: Int get() = flatArray.length 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 328a0ab01..9e01fd88a 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 @@ -6,13 +6,17 @@ package space.kscience.kmath.viktor import org.jetbrains.bio.viktor.F64Array +import space.kscience.attributes.SafeType import space.kscience.kmath.PerformancePitfall import space.kscience.kmath.nd.ColumnStrides import space.kscience.kmath.nd.MutableStructureND import space.kscience.kmath.nd.ShapeND +import space.kscience.kmath.operations.Float64Field @Suppress("OVERRIDE_BY_INLINE", "NOTHING_TO_INLINE") public class ViktorStructureND(public val f64Buffer: F64Array) : MutableStructureND { + override val type: SafeType get() = Float64Field.type + override val shape: ShapeND get() = ShapeND(f64Buffer.shape) @OptIn(PerformancePitfall::class) From 10739e0d04b5b2a8a2d999723d02bf8691b3ede1 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sun, 18 Feb 2024 12:27:46 +0300 Subject: [PATCH 25/40] Performance fixes --- .../kscience/kmath/benchmarks/DotBenchmark.kt | 13 +- .../benchmarks/MatrixInverseBenchmark.kt | 20 +- buildSrc/build.gradle.kts | 2 +- .../kmath/ejml/codegen/ejmlCodegen.kt | 443 ------------------ .../kscience/kmath/linear/dotPerformance.kt | 15 +- .../kscience/kmath/linear/lupPerformance.kt | 27 ++ .../kscience/kmath/series/seriesBuilder.kt | 6 +- gradle/wrapper/gradle-wrapper.properties | 2 +- .../kmath/linear/Float64LinearSpace.kt | 6 +- .../kscience/kmath/linear/LupDecomposition.kt | 12 +- .../kmath/operations/BufferAlgebra.kt | 10 +- .../space/kscience/kmath/structures/Buffer.kt | 2 + .../kmath/structures/BufferAccessor2D.kt | 13 +- .../kmath/structures/Float64Buffer.kt | 1 + .../kmath/structures/MutableBuffer.kt | 1 - .../linear/Float64ParallelLinearSpace.kt | 125 +++++ .../kmath/structures/parallelMutableBuffer.kt | 58 +++ .../kscience/kmath/stat/ValueAndErrorField.kt | 2 +- 18 files changed, 262 insertions(+), 496 deletions(-) delete mode 100644 buildSrc/src/main/kotlin/space/kscience/kmath/ejml/codegen/ejmlCodegen.kt create mode 100644 examples/src/main/kotlin/space/kscience/kmath/linear/lupPerformance.kt create mode 100644 kmath-core/src/jvmMain/kotlin/space/kscience/kmath/linear/Float64ParallelLinearSpace.kt create mode 100644 kmath-core/src/jvmMain/kotlin/space/kscience/kmath/structures/parallelMutableBuffer.kt diff --git a/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/DotBenchmark.kt b/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/DotBenchmark.kt index 51be23192..a157a67b2 100644 --- a/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/DotBenchmark.kt +++ b/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/DotBenchmark.kt @@ -11,12 +11,11 @@ import kotlinx.benchmark.Scope import kotlinx.benchmark.State import space.kscience.kmath.commons.linear.CMLinearSpace import space.kscience.kmath.ejml.EjmlLinearSpaceDDRM +import space.kscience.kmath.linear.Float64ParallelLinearSpace import space.kscience.kmath.linear.invoke import space.kscience.kmath.linear.linearSpace import space.kscience.kmath.operations.Float64Field -import space.kscience.kmath.operations.invoke import space.kscience.kmath.tensorflow.produceWithTF -import space.kscience.kmath.tensors.core.DoubleTensorAlgebra import space.kscience.kmath.tensors.core.tensorAlgebra import kotlin.random.Random @@ -72,12 +71,12 @@ internal class DotBenchmark { } @Benchmark - fun tensorDot(blackhole: Blackhole) = with(Float64Field.tensorAlgebra) { + fun multikDot(blackhole: Blackhole) = with(multikAlgebra) { blackhole.consume(matrix1 dot matrix2) } @Benchmark - fun multikDot(blackhole: Blackhole) = with(multikAlgebra) { + fun tensorDot(blackhole: Blackhole) = with(Float64Field.tensorAlgebra) { blackhole.consume(matrix1 dot matrix2) } @@ -87,12 +86,8 @@ internal class DotBenchmark { } @Benchmark - fun doubleDot(blackhole: Blackhole) = with(Float64Field.linearSpace) { + fun parallelDot(blackhole: Blackhole) = with(Float64ParallelLinearSpace) { blackhole.consume(matrix1 dot matrix2) } - @Benchmark - fun doubleTensorDot(blackhole: Blackhole) = DoubleTensorAlgebra.invoke { - blackhole.consume(matrix1 dot matrix2) - } } diff --git a/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/MatrixInverseBenchmark.kt b/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/MatrixInverseBenchmark.kt index 01513ac55..1a9e09013 100644 --- a/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/MatrixInverseBenchmark.kt +++ b/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/MatrixInverseBenchmark.kt @@ -15,6 +15,7 @@ import space.kscience.kmath.ejml.EjmlLinearSpaceDDRM import space.kscience.kmath.linear.invoke import space.kscience.kmath.linear.linearSpace import space.kscience.kmath.linear.lupSolver +import space.kscience.kmath.linear.parallel import space.kscience.kmath.operations.algebra import kotlin.random.Random @@ -38,16 +39,19 @@ internal class MatrixInverseBenchmark { } @Benchmark - fun cmLUPInversion(blackhole: Blackhole) { - CMLinearSpace { - blackhole.consume(lupSolver().inverse(matrix)) - } + fun kmathParallelLupInversion(blackhole: Blackhole) { + blackhole.consume(Double.algebra.linearSpace.parallel.lupSolver().inverse(matrix)) } @Benchmark - fun ejmlInverse(blackhole: Blackhole) { - EjmlLinearSpaceDDRM { - blackhole.consume(matrix.toEjml().inverted()) - } + fun cmLUPInversion(blackhole: Blackhole) = CMLinearSpace { + blackhole.consume(lupSolver().inverse(matrix)) } + + + @Benchmark + fun ejmlInverse(blackhole: Blackhole) = EjmlLinearSpaceDDRM { + blackhole.consume(matrix.toEjml().inverted()) + } + } diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 08db49244..89bb32b15 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -17,7 +17,7 @@ val benchmarksVersion = spclibs.versions.kotlinx.benchmark.get() dependencies { api("space.kscience:gradle-tools:$toolsVersion") //plugins form benchmarks - api("org.jetbrains.kotlinx:kotlinx-benchmark-plugin:0.4.9") + api("org.jetbrains.kotlinx:kotlinx-benchmark-plugin:$benchmarksVersion") //api("org.jetbrains.kotlin:kotlin-allopen:$kotlinVersion") //to be used inside build-script only //implementation(spclibs.kotlinx.serialization.json) diff --git a/buildSrc/src/main/kotlin/space/kscience/kmath/ejml/codegen/ejmlCodegen.kt b/buildSrc/src/main/kotlin/space/kscience/kmath/ejml/codegen/ejmlCodegen.kt deleted file mode 100644 index fbe891508..000000000 --- a/buildSrc/src/main/kotlin/space/kscience/kmath/ejml/codegen/ejmlCodegen.kt +++ /dev/null @@ -1,443 +0,0 @@ -/* - * Copyright 2018-2024 KMath contributors. - * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. - */ - -@file:Suppress("KDocUnresolvedReference") - -package space.kscience.kmath.ejml.codegen - -import org.intellij.lang.annotations.Language -import java.io.File - -private fun Appendable.appendEjmlVector(type: String, ejmlMatrixType: String) { - @Language("kotlin") val text = """/** - * [EjmlVector] specialization for [$type]. - */ -public class Ejml${type}Vector(override val origin: M) : EjmlVector<$type, M>(origin) { - init { - require(origin.numRows == 1) { "The origin matrix must have only one row to form a vector" } - } - - override val type: SafeType<${type}> get() = safeTypeOf() - - override operator fun get(index: Int): $type = origin[0, index] -}""" - appendLine(text) - appendLine() -} - -private fun Appendable.appendEjmlMatrix(type: String, ejmlMatrixType: String) { - val text = """/** - * [EjmlMatrix] specialization for [$type]. - */ -public class Ejml${type}Matrix(override val origin: M) : EjmlMatrix<$type, M>(origin) { - override val type: SafeType<${type}> get() = safeTypeOf() - - override operator fun get(i: Int, j: Int): $type = origin[i, j] -}""" - appendLine(text) - appendLine() -} - -private fun Appendable.appendEjmlLinearSpace( - type: String, - kmathAlgebra: String, - ejmlMatrixParentTypeMatrix: String, - ejmlMatrixType: String, - ejmlMatrixDenseType: String, - ops: String, - denseOps: String, - isDense: Boolean, -) { - @Language("kotlin") val text = """ - -/** - * [EjmlLinearSpace] implementation based on [CommonOps_$ops], [DecompositionFactory_${ops}] operations and - * [${ejmlMatrixType}] matrices. - */ -public object EjmlLinearSpace${ops} : EjmlLinearSpace<${type}, ${kmathAlgebra}, $ejmlMatrixType>() { - /** - * The [${kmathAlgebra}] reference. - */ - override val elementAlgebra: $kmathAlgebra get() = $kmathAlgebra - - override val type: SafeType<${type}> get() = safeTypeOf() - - @Suppress("UNCHECKED_CAST") - override fun Matrix<${type}>.toEjml(): Ejml${type}Matrix<${ejmlMatrixType}> = when { - this is Ejml${type}Matrix<*> && origin is $ejmlMatrixType -> this as Ejml${type}Matrix<${ejmlMatrixType}> - else -> buildMatrix(rowNum, colNum) { i, j -> get(i, j) } - } - - @Suppress("UNCHECKED_CAST") - override fun Point<${type}>.toEjml(): Ejml${type}Vector<${ejmlMatrixType}> = when { - this is Ejml${type}Vector<*> && origin is $ejmlMatrixType -> this as Ejml${type}Vector<${ejmlMatrixType}> - else -> Ejml${type}Vector(${ejmlMatrixType}(size, 1).also { - (0 until it.numRows).forEach { row -> it[row, 0] = get(row) } - }) - } - - override fun buildMatrix( - rows: Int, - columns: Int, - initializer: ${kmathAlgebra}.(i: Int, j: Int) -> ${type}, - ): Ejml${type}Matrix<${ejmlMatrixType}> = ${ejmlMatrixType}(rows, columns).also { - (0 until rows).forEach { row -> - (0 until columns).forEach { col -> it[row, col] = elementAlgebra.initializer(row, col) } - } - }.wrapMatrix() - - override fun buildVector( - size: Int, - initializer: ${kmathAlgebra}.(Int) -> ${type}, - ): Ejml${type}Vector<${ejmlMatrixType}> = Ejml${type}Vector(${ejmlMatrixType}(size, 1).also { - (0 until it.numRows).forEach { row -> it[row, 0] = elementAlgebra.initializer(row) } - }) - - private fun T.wrapMatrix() = Ejml${type}Matrix(this) - private fun T.wrapVector() = Ejml${type}Vector(this) - - override fun Matrix<${type}>.unaryMinus(): Matrix<${type}> = this * elementAlgebra { -one } - - override fun Matrix<${type}>.dot(other: Matrix<${type}>): Ejml${type}Matrix<${ejmlMatrixType}> { - val out = ${ejmlMatrixType}(1, 1) - CommonOps_${ops}.mult(toEjml().origin, other.toEjml().origin, out) - return out.wrapMatrix() - } - - override fun Matrix<${type}>.dot(vector: Point<${type}>): Ejml${type}Vector<${ejmlMatrixType}> { - val out = ${ejmlMatrixType}(1, 1) - CommonOps_${ops}.mult(toEjml().origin, vector.toEjml().origin, out) - return out.wrapVector() - } - - override operator fun Matrix<${type}>.minus(other: Matrix<${type}>): Ejml${type}Matrix<${ejmlMatrixType}> { - val out = ${ejmlMatrixType}(1, 1) - - CommonOps_${ops}.add( - elementAlgebra.one, - toEjml().origin, - elementAlgebra { -one }, - other.toEjml().origin, - out,${ - if (isDense) "" else - """ - null, - null,""" - } - ) - - return out.wrapMatrix() - } - - override operator fun Matrix<${type}>.times(value: ${type}): Ejml${type}Matrix<${ejmlMatrixType}> { - val res = ${ejmlMatrixType}(1, 1) - CommonOps_${ops}.scale(value, toEjml().origin, res) - return res.wrapMatrix() - } - - override fun Point<${type}>.unaryMinus(): Ejml${type}Vector<${ejmlMatrixType}> { - val res = ${ejmlMatrixType}(1, 1) - CommonOps_${ops}.changeSign(toEjml().origin, res) - return res.wrapVector() - } - - override fun Matrix<${type}>.plus(other: Matrix<${type}>): Ejml${type}Matrix<${ejmlMatrixType}> { - val out = ${ejmlMatrixType}(1, 1) - - CommonOps_${ops}.add( - elementAlgebra.one, - toEjml().origin, - elementAlgebra.one, - other.toEjml().origin, - out,${ - if (isDense) "" else - """ - null, - null,""" - } - ) - - return out.wrapMatrix() - } - - override fun Point<${type}>.plus(other: Point<${type}>): Ejml${type}Vector<${ejmlMatrixType}> { - val out = ${ejmlMatrixType}(1, 1) - - CommonOps_${ops}.add( - elementAlgebra.one, - toEjml().origin, - elementAlgebra.one, - other.toEjml().origin, - out,${ - if (isDense) "" else - """ - null, - null,""" - } - ) - - return out.wrapVector() - } - - override fun Point<${type}>.minus(other: Point<${type}>): Ejml${type}Vector<${ejmlMatrixType}> { - val out = ${ejmlMatrixType}(1, 1) - - CommonOps_${ops}.add( - elementAlgebra.one, - toEjml().origin, - elementAlgebra { -one }, - other.toEjml().origin, - out,${ - if (isDense) "" else - """ - null, - null,""" - } - ) - - return out.wrapVector() - } - - override fun ${type}.times(m: Matrix<${type}>): Ejml${type}Matrix<${ejmlMatrixType}> = m * this - - override fun Point<${type}>.times(value: ${type}): Ejml${type}Vector<${ejmlMatrixType}> { - val res = ${ejmlMatrixType}(1, 1) - CommonOps_${ops}.scale(value, toEjml().origin, res) - return res.wrapVector() - } - - override fun ${type}.times(v: Point<${type}>): Ejml${type}Vector<${ejmlMatrixType}> = v * this - - @UnstableKMathAPI - override fun computeFeature(structure: Matrix<${type}>, type: KClass): F? { - structure.getFeature(type)?.let { return it } - val origin = structure.toEjml().origin - - return when (type) { - ${ - if (isDense) - """ InverseMatrixFeature::class -> object : InverseMatrixFeature<${type}> { - override val inverse: Matrix<${type}> by lazy { - val res = origin.copy() - CommonOps_${ops}.invert(res) - res.wrapMatrix() - } - } - - DeterminantFeature::class -> object : DeterminantFeature<${type}> { - override val determinant: $type by lazy { CommonOps_${ops}.det(origin) } - } - - SingularValueDecompositionFeature::class -> object : SingularValueDecompositionFeature<${type}> { - private val svd by lazy { - DecompositionFactory_${ops}.svd(origin.numRows, origin.numCols, true, true, false) - .apply { decompose(origin.copy()) } - } - - override val u: Matrix<${type}> by lazy { svd.getU(null, false).wrapMatrix() } - override val s: Matrix<${type}> by lazy { svd.getW(null).wrapMatrix() } - override val v: Matrix<${type}> by lazy { svd.getV(null, false).wrapMatrix() } - override val singularValues: Point<${type}> by lazy { ${type}Buffer(svd.singularValues) } - } - - QRDecompositionFeature::class -> object : QRDecompositionFeature<${type}> { - private val qr by lazy { - DecompositionFactory_${ops}.qr().apply { decompose(origin.copy()) } - } - - override val q: Matrix<${type}> by lazy { - qr.getQ(null, false).wrapMatrix().withFeature(OrthogonalFeature) - } - - override val r: Matrix<${type}> by lazy { qr.getR(null, false).wrapMatrix().withFeature(UFeature) } - } - - CholeskyDecompositionFeature::class -> object : CholeskyDecompositionFeature<${type}> { - override val l: Matrix<${type}> by lazy { - val cholesky = - DecompositionFactory_${ops}.chol(structure.rowNum, true).apply { decompose(origin.copy()) } - - cholesky.getT(null).wrapMatrix().withFeature(LFeature) - } - } - - LupDecompositionFeature::class -> object : LupDecompositionFeature<${type}> { - private val lup by lazy { - DecompositionFactory_${ops}.lu(origin.numRows, origin.numCols).apply { decompose(origin.copy()) } - } - - override val l: Matrix<${type}> by lazy { - lup.getLower(null).wrapMatrix().withFeature(LFeature) - } - - override val u: Matrix<${type}> by lazy { - lup.getUpper(null).wrapMatrix().withFeature(UFeature) - } - - override val p: Matrix<${type}> by lazy { lup.getRowPivot(null).wrapMatrix() } - }""" else """ QRDecompositionFeature::class -> object : QRDecompositionFeature<$type> { - private val qr by lazy { - DecompositionFactory_${ops}.qr(FillReducing.NONE).apply { decompose(origin.copy()) } - } - - override val q: Matrix<${type}> by lazy { - qr.getQ(null, false).wrapMatrix().withFeature(OrthogonalFeature) - } - - override val r: Matrix<${type}> by lazy { qr.getR(null, false).wrapMatrix().withFeature(UFeature) } - } - - CholeskyDecompositionFeature::class -> object : CholeskyDecompositionFeature<${type}> { - override val l: Matrix<${type}> by lazy { - val cholesky = - DecompositionFactory_${ops}.cholesky().apply { decompose(origin.copy()) } - - (cholesky.getT(null) as ${ejmlMatrixParentTypeMatrix}).wrapMatrix().withFeature(LFeature) - } - } - - LUDecompositionFeature::class, DeterminantFeature::class, InverseMatrixFeature::class -> object : - LUDecompositionFeature<${type}>, DeterminantFeature<${type}>, InverseMatrixFeature<${type}> { - private val lu by lazy { - DecompositionFactory_${ops}.lu(FillReducing.NONE).apply { decompose(origin.copy()) } - } - - override val l: Matrix<${type}> by lazy { - lu.getLower(null).wrapMatrix().withFeature(LFeature) - } - - override val u: Matrix<${type}> by lazy { - lu.getUpper(null).wrapMatrix().withFeature(UFeature) - } - - override val inverse: Matrix<${type}> by lazy { - var a = origin - val inverse = ${ejmlMatrixDenseType}(1, 1) - val solver = LinearSolverFactory_${ops}.lu(FillReducing.NONE) - if (solver.modifiesA()) a = a.copy() - val i = CommonOps_${denseOps}.identity(a.numRows) - solver.solve(i, inverse) - inverse.wrapMatrix() - } - - override val determinant: $type by lazy { elementAlgebra.number(lu.computeDeterminant().real) } - }""" - } - - else -> null - }?.let{ - type.cast(it) - } - } - - /** - * Solves for *x* in the following equation: *x = [a] -1 · [b]*. - * - * @param a the base matrix. - * @param b n by p matrix. - * @return the solution for *x* that is n by p. - */ - public fun solve(a: Matrix<${type}>, b: Matrix<${type}>): Ejml${type}Matrix<${ejmlMatrixType}> { - val res = ${ejmlMatrixType}(1, 1) - CommonOps_${ops}.solve(${ejmlMatrixType}(a.toEjml().origin), ${ejmlMatrixType}(b.toEjml().origin), res) - return res.wrapMatrix() - } - - /** - * Solves for *x* in the following equation: *x = [a] -1 · [b]*. - * - * @param a the base matrix. - * @param b n by p vector. - * @return the solution for *x* that is n by p. - */ - public fun solve(a: Matrix<${type}>, b: Point<${type}>): Ejml${type}Vector<${ejmlMatrixType}> { - val res = ${ejmlMatrixType}(1, 1) - CommonOps_${ops}.solve(${ejmlMatrixType}(a.toEjml().origin), ${ejmlMatrixType}(b.toEjml().origin), res) - return Ejml${type}Vector(res) - } -}""" - appendLine(text) - appendLine() -} - - -/** - * Generates routine EJML classes. - */ -fun ejmlCodegen(outputFile: String): Unit = File(outputFile).run { - parentFile.mkdirs() - - writer().use { - it.appendLine("/*") - it.appendLine(" * Copyright 2018-2024 KMath contributors.") - it.appendLine(" * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.") - it.appendLine(" */") - it.appendLine() - it.appendLine("/* This file is generated with buildSrc/src/main/kotlin/space/kscience/kmath/ejml/codegen/ejmlCodegen.kt */") - it.appendLine() - it.appendLine("package space.kscience.kmath.ejml") - it.appendLine() - it.appendLine("""import org.ejml.data.* -import org.ejml.dense.row.CommonOps_DDRM -import org.ejml.dense.row.CommonOps_FDRM -import org.ejml.dense.row.factory.DecompositionFactory_DDRM -import org.ejml.dense.row.factory.DecompositionFactory_FDRM -import org.ejml.sparse.FillReducing -import org.ejml.sparse.csc.CommonOps_DSCC -import org.ejml.sparse.csc.CommonOps_FSCC -import org.ejml.sparse.csc.factory.DecompositionFactory_DSCC -import org.ejml.sparse.csc.factory.DecompositionFactory_FSCC -import org.ejml.sparse.csc.factory.LinearSolverFactory_DSCC -import org.ejml.sparse.csc.factory.LinearSolverFactory_FSCC -import space.kscience.attributes.SafeType -import space.kscience.attributes.safeTypeOf -import space.kscience.kmath.linear.* -import space.kscience.kmath.linear.Matrix -import space.kscience.kmath.UnstableKMathAPI -import space.kscience.kmath.nd.StructureFeature -import space.kscience.kmath.structures.Float64 -import space.kscience.kmath.structures.Float32 -import space.kscience.kmath.operations.Float64Field -import space.kscience.kmath.operations.Float32Field -import space.kscience.kmath.operations.DoubleField -import space.kscience.kmath.operations.FloatField -import space.kscience.kmath.operations.invoke -import space.kscience.kmath.structures.Float64Buffer -import space.kscience.kmath.structures.Float32Buffer -import space.kscience.kmath.structures.DoubleBuffer -import space.kscience.kmath.structures.FloatBuffer -import kotlin.reflect.KClass -import kotlin.reflect.cast""") - it.appendLine() - it.appendEjmlVector("Double", "DMatrix") - it.appendEjmlVector("Float", "FMatrix") - it.appendEjmlMatrix("Double", "DMatrix") - it.appendEjmlMatrix("Float", "FMatrix") - it.appendEjmlLinearSpace("Double", "Float64Field", "DMatrix", "DMatrixRMaj", "DMatrixRMaj", "DDRM", "DDRM", true) - it.appendEjmlLinearSpace("Float", "Float32Field", "FMatrix", "FMatrixRMaj", "FMatrixRMaj", "FDRM", "FDRM", true) - - it.appendEjmlLinearSpace( - type = "Double", - kmathAlgebra = "Float64Field", - ejmlMatrixParentTypeMatrix = "DMatrix", - ejmlMatrixType = "DMatrixSparseCSC", - ejmlMatrixDenseType = "DMatrixRMaj", - ops = "DSCC", - denseOps = "DDRM", - isDense = false, - ) - - it.appendEjmlLinearSpace( - type = "Float", - kmathAlgebra = "Float32Field", - ejmlMatrixParentTypeMatrix = "FMatrix", - ejmlMatrixType = "FMatrixSparseCSC", - ejmlMatrixDenseType = "FMatrixRMaj", - ops = "FSCC", - denseOps = "FDRM", - isDense = false, - ) - } -} diff --git a/examples/src/main/kotlin/space/kscience/kmath/linear/dotPerformance.kt b/examples/src/main/kotlin/space/kscience/kmath/linear/dotPerformance.kt index 8874ca685..c59ffeae2 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/linear/dotPerformance.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/linear/dotPerformance.kt @@ -5,29 +5,24 @@ package space.kscience.kmath.linear -import space.kscience.kmath.operations.algebra import kotlin.random.Random -import kotlin.time.ExperimentalTime import kotlin.time.measureTime -@OptIn(ExperimentalTime::class) -fun main() { +fun main() = with(Float64ParallelLinearSpace) { val random = Random(12224) val dim = 1000 //creating invertible matrix - val matrix1 = Double.algebra.linearSpace.buildMatrix(dim, dim) { i, j -> + val matrix1 = buildMatrix(dim, dim) { i, j -> if (i <= j) random.nextDouble() else 0.0 } - val matrix2 = Double.algebra.linearSpace.buildMatrix(dim, dim) { i, j -> + val matrix2 = buildMatrix(dim, dim) { i, j -> if (i <= j) random.nextDouble() else 0.0 } val time = measureTime { - with(Double.algebra.linearSpace) { - repeat(10) { - matrix1 dot matrix2 - } + repeat(30) { + matrix1 dot matrix2 } } diff --git a/examples/src/main/kotlin/space/kscience/kmath/linear/lupPerformance.kt b/examples/src/main/kotlin/space/kscience/kmath/linear/lupPerformance.kt new file mode 100644 index 000000000..dcd380ea6 --- /dev/null +++ b/examples/src/main/kotlin/space/kscience/kmath/linear/lupPerformance.kt @@ -0,0 +1,27 @@ +/* + * Copyright 2018-2024 KMath contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package space.kscience.kmath.linear + +import kotlin.random.Random +import kotlin.time.measureTime + +fun main(): Unit = with(Float64LinearSpace) { + val random = Random(1224) + val dim = 500 + + //creating invertible matrix + val u = buildMatrix(dim, dim) { i, j -> if (i <= j) random.nextDouble() else 0.0 } + val l = buildMatrix(dim, dim) { i, j -> if (i >= j) random.nextDouble() else 0.0 } + val matrix = l dot u + + val time = measureTime { + repeat(20) { + lupSolver().inverse(matrix) + } + } + + println(time) +} \ No newline at end of file diff --git a/examples/src/main/kotlin/space/kscience/kmath/series/seriesBuilder.kt b/examples/src/main/kotlin/space/kscience/kmath/series/seriesBuilder.kt index f8a8f1d0b..9dfb0fdc9 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/series/seriesBuilder.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/series/seriesBuilder.kt @@ -7,7 +7,7 @@ package space.kscience.kmath.series import space.kscience.kmath.structures.Buffer -import space.kscience.kmath.structures.DoubleBuffer +import space.kscience.kmath.structures.Float64Buffer import space.kscience.kmath.structures.asBuffer import space.kscience.kmath.structures.toDoubleArray import space.kscience.plotly.* @@ -21,7 +21,7 @@ fun main(): Unit = with(Double.seriesAlgebra()) { val arrayOfRandoms = DoubleArray(20) { random.nextDouble() } - val series1: DoubleBuffer = arrayOfRandoms.asBuffer() + val series1: Float64Buffer = arrayOfRandoms.asBuffer() val series2: Series = series1.moveBy(3) val res = series2 - series1 @@ -42,7 +42,7 @@ fun main(): Unit = with(Double.seriesAlgebra()) { Plotly.plot { series("series1", series1) series("series2", series2) - series("dif", res){ + series("dif", res) { mode = ScatterMode.lines line.color("magenta") } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index e411586a5..17655d0ef 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/Float64LinearSpace.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/Float64LinearSpace.kt index 800f27546..f1290d727 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/Float64LinearSpace.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/Float64LinearSpace.kt @@ -54,11 +54,12 @@ public object Float64LinearSpace : LinearSpace { require(colNum == other.rowNum) { "Matrix dot operation dimension mismatch: ($rowNum, $colNum) x (${other.rowNum}, ${other.colNum})" } val rows = this@dot.rows.map { it.linearize() } val columns = other.columns.map { it.linearize() } + val indices = 0 until this.rowNum return buildMatrix(rowNum, other.colNum) { i, j -> val r = rows[i] val c = columns[j] var res = 0.0 - for (l in r.indices) { + for (l in indices) { res += r[l] * c[l] } res @@ -69,10 +70,11 @@ public object Float64LinearSpace : LinearSpace { override fun Matrix.dot(vector: Point): Float64Buffer { require(colNum == vector.size) { "Matrix dot vector operation dimension mismatch: ($rowNum, $colNum) x (${vector.size})" } val rows = this@dot.rows.map { it.linearize() } + val indices = 0 until this.rowNum return Float64Buffer(rowNum) { i -> val r = rows[i] var res = 0.0 - for (j in r.indices) { + for (j in indices) { res += r[j] * vector[j] } res 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 14828f2df..7738fdaa3 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 @@ -11,6 +11,7 @@ import space.kscience.attributes.Attributes import space.kscience.attributes.PolymorphicAttribute import space.kscience.attributes.safeTypeOf import space.kscience.kmath.UnstableKMathAPI +import space.kscience.kmath.nd.* import space.kscience.kmath.operations.* import space.kscience.kmath.structures.* @@ -150,7 +151,14 @@ public fun > LinearSpace>.lup( for (row in col + 1 until m) lu[row, col] /= luDiag } - return GenericLupDecomposition(this@lup, lu.toStructure2D(), pivot.asBuffer(), even) + val shape = ShapeND(rowNum, colNum) + + val structure2D = BufferND( + RowStrides(ShapeND(rowNum, colNum)), + lu + ).as2D() + + return GenericLupDecomposition(this@lup, structure2D, pivot.asBuffer(), even) } } @@ -166,7 +174,7 @@ internal fun LinearSpace>.solve( ): Matrix { require(matrix.rowNum == lup.l.rowNum) { "Matrix dimension mismatch. Expected ${lup.l.rowNum}, but got ${matrix.colNum}" } - BufferAccessor2D(matrix.rowNum, matrix.colNum, elementAlgebra.bufferFactory).run { + with(BufferAccessor2D(matrix.rowNum, matrix.colNum, elementAlgebra.bufferFactory)) { elementAlgebra { // Apply permutations to b val bp = create { _, _ -> zero } diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/BufferAlgebra.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/BufferAlgebra.kt index 327eb2881..6c260db9f 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/BufferAlgebra.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/BufferAlgebra.kt @@ -77,13 +77,11 @@ private inline fun > BufferAlgebra.zipInline( return elementBufferFactory(l.size) { elementAlgebra.block(l[it], r[it]) } } -public fun BufferAlgebra.buffer(size: Int, initializer: (Int) -> T): MutableBuffer { - return elementBufferFactory(size, initializer) -} +public fun BufferAlgebra.buffer(size: Int, initializer: (Int) -> T): MutableBuffer = + elementBufferFactory(size, initializer) -public fun A.buffer(initializer: (Int) -> T): MutableBuffer where A : BufferAlgebra, A : WithSize { - return elementBufferFactory(size, initializer) -} +public fun A.buffer(initializer: (Int) -> T): MutableBuffer where A : BufferAlgebra, A : WithSize = + elementBufferFactory(size, initializer) public fun > BufferAlgebra.sin(arg: Buffer): Buffer = mapInline(arg) { sin(it) } 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 71cab61e0..4a0ac9416 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 @@ -42,6 +42,8 @@ public inline fun BufferFactory(): BufferFactory = BufferFactory( */ public interface MutableBufferFactory : BufferFactory { override fun invoke(size: Int, builder: (Int) -> T): MutableBuffer + + public companion object } /** diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/BufferAccessor2D.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/BufferAccessor2D.kt index e03ebcade..5c8541f22 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/BufferAccessor2D.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/BufferAccessor2D.kt @@ -6,12 +6,7 @@ package space.kscience.kmath.structures import space.kscience.attributes.SafeType -import space.kscience.kmath.nd.BufferND -import space.kscience.kmath.nd.ShapeND import space.kscience.kmath.nd.Structure2D -import space.kscience.kmath.nd.as2D -import kotlin.collections.component1 -import kotlin.collections.component2 /** * A context that allows to operate on a [MutableBuffer] as on 2d array @@ -32,10 +27,10 @@ internal class BufferAccessor2D( fun create(mat: Structure2D): MutableBuffer = create { i, j -> mat[i, j] } - //TODO optimize wrapper - fun MutableBuffer.toStructure2D(): Structure2D = BufferND( - type, ShapeND(rowNum, colNum) - ) { (i, j) -> get(i, j) }.as2D() +// //TODO optimize wrapper +// fun MutableBuffer.toStructure2D(): Structure2D = BufferND( +// type, ShapeND(rowNum, colNum) +// ) { (i, j) -> get(i, j) }.as2D() inner class Row(val buffer: MutableBuffer, val rowIndex: Int) : MutableBuffer { override val type: SafeType get() = buffer.type diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Float64Buffer.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Float64Buffer.kt index a64abfc3d..ca9e8ef9f 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Float64Buffer.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Float64Buffer.kt @@ -39,6 +39,7 @@ public value class Float64Buffer(public val array: DoubleArray) : PrimitiveBuffe } } +@Deprecated("Use Float64Buffer instead", ReplaceWith("Float64Buffer")) public typealias DoubleBuffer = Float64Buffer /** diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/MutableBuffer.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/MutableBuffer.kt index 44d2ecb5c..0acfd13a1 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/MutableBuffer.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/MutableBuffer.kt @@ -77,7 +77,6 @@ public inline fun MutableBuffer( size: Int, initializer: (Int) -> T, ): MutableBuffer = when (type.kType) { - typeOf() -> TODO() typeOf() -> Int8Buffer(size) { initializer(it) as Int8 } as MutableBuffer typeOf() -> MutableBuffer.short(size) { initializer(it) as Int16 } as MutableBuffer typeOf() -> MutableBuffer.int(size) { initializer(it) as Int32 } as MutableBuffer diff --git a/kmath-core/src/jvmMain/kotlin/space/kscience/kmath/linear/Float64ParallelLinearSpace.kt b/kmath-core/src/jvmMain/kotlin/space/kscience/kmath/linear/Float64ParallelLinearSpace.kt new file mode 100644 index 000000000..9e05fded1 --- /dev/null +++ b/kmath-core/src/jvmMain/kotlin/space/kscience/kmath/linear/Float64ParallelLinearSpace.kt @@ -0,0 +1,125 @@ +/* + * Copyright 2018-2024 KMath contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package space.kscience.kmath.linear + +import space.kscience.kmath.PerformancePitfall +import space.kscience.kmath.nd.* +import space.kscience.kmath.operations.Float64BufferOps +import space.kscience.kmath.operations.Float64Field +import space.kscience.kmath.operations.invoke +import space.kscience.kmath.structures.Buffer +import space.kscience.kmath.structures.Float64Buffer +import space.kscience.kmath.structures.asBuffer +import java.util.stream.IntStream + + +public object Float64ParallelLinearSpace : LinearSpace { + + override val elementAlgebra: Float64Field = Float64Field + + + override fun buildMatrix( + rows: Int, + columns: Int, + initializer: Float64Field.(i: Int, j: Int) -> Double, + ): Matrix { + val shape = ShapeND(rows, columns) + val indexer = BufferAlgebraND.defaultIndexerBuilder(shape) + + val buffer = IntStream.range(0, indexer.linearSize).parallel().mapToDouble { offset -> + val (i, j) = indexer.index(offset) + elementAlgebra.initializer(i, j) + }.toArray().asBuffer() + + return MutableBufferND( + indexer, + buffer + ).as2D() + } + + override fun buildVector(size: Int, initializer: Float64Field.(Int) -> Double): Float64Buffer = + IntStream.range(0, size).parallel().mapToDouble{ Float64Field.initializer(it) }.toArray().asBuffer() + + override fun Matrix.unaryMinus(): Matrix = Floa64FieldOpsND { + asND().map { -it }.as2D() + } + + override fun Matrix.plus(other: Matrix): Matrix = Floa64FieldOpsND { + require(shape.contentEquals(other.shape)) { "Shape mismatch on Matrix::plus. Expected $shape but found ${other.shape}" } + asND().plus(other.asND()).as2D() + } + + override fun Matrix.minus(other: Matrix): Matrix = Floa64FieldOpsND { + require(shape.contentEquals(other.shape)) { "Shape mismatch on Matrix::minus. Expected $shape but found ${other.shape}" } + asND().minus(other.asND()).as2D() + } + + // Create a continuous in-memory representation of this vector for better memory layout handling + private fun Buffer.linearize() = if (this is Float64Buffer) { + this.array + } else { + DoubleArray(size) { get(it) } + } + + @OptIn(PerformancePitfall::class) + override fun Matrix.dot(other: Matrix): Matrix { + require(colNum == other.rowNum) { "Matrix dot operation dimension mismatch: ($rowNum, $colNum) x (${other.rowNum}, ${other.colNum})" } + val rows = this@dot.rows.map { it.linearize() } + val columns = other.columns.map { it.linearize() } + val indices = 0 until this.rowNum + return buildMatrix(rowNum, other.colNum) { i, j -> + val r = rows[i] + val c = columns[j] + var res = 0.0 + for (l in indices) { + res += r[l] * c[l] + } + res + } + } + + @OptIn(PerformancePitfall::class) + override fun Matrix.dot(vector: Point): Float64Buffer { + require(colNum == vector.size) { "Matrix dot vector operation dimension mismatch: ($rowNum, $colNum) x (${vector.size})" } + val rows = this@dot.rows.map { it.linearize() } + val indices = 0 until this.rowNum + return Float64Buffer(rowNum) { i -> + val r = rows[i] + var res = 0.0 + for (j in indices) { + res += r[j] * vector[j] + } + res + } + + } + + override fun Matrix.times(value: Double): Matrix = Floa64FieldOpsND { + asND().map { it * value }.as2D() + } + + public override fun Point.plus(other: Point): Float64Buffer = Float64BufferOps.run { + this@plus + other + } + + public override fun Point.minus(other: Point): Float64Buffer = Float64BufferOps.run { + this@minus - other + } + + public override fun Point.times(value: Double): Float64Buffer = Float64BufferOps.run { + scale(this@times, value) + } + + public operator fun Point.div(value: Double): Float64Buffer = Float64BufferOps.run { + scale(this@div, 1.0 / value) + } + + public override fun Double.times(v: Point): Float64Buffer = v * this + + +} + +public val Float64LinearSpace.parallel: Float64ParallelLinearSpace get() = Float64ParallelLinearSpace diff --git a/kmath-core/src/jvmMain/kotlin/space/kscience/kmath/structures/parallelMutableBuffer.kt b/kmath-core/src/jvmMain/kotlin/space/kscience/kmath/structures/parallelMutableBuffer.kt new file mode 100644 index 000000000..c57dba41e --- /dev/null +++ b/kmath-core/src/jvmMain/kotlin/space/kscience/kmath/structures/parallelMutableBuffer.kt @@ -0,0 +1,58 @@ +/* + * Copyright 2018-2024 KMath contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package space.kscience.kmath.structures + +import space.kscience.attributes.SafeType +import java.util.stream.Collectors +import java.util.stream.IntStream +import kotlin.reflect.typeOf + +/** + * A Java stream-based parallel version of [MutableBuffer]. + * There is no parallelization for [Int8], [Int16] and [Float32] types. + * They are processed sequentially. + */ +@Suppress("UNCHECKED_CAST") +public fun MutableBuffer.Companion.parallel( + type: SafeType, + size: Int, + initializer: (Int) -> T, +): MutableBuffer = when (type.kType) { + typeOf() -> Int8Buffer(size) { initializer(it) as Int8 } as MutableBuffer + typeOf() -> Int16Buffer(size) { initializer(it) as Int16 } as MutableBuffer + typeOf() -> IntStream.range(0, size).parallel().map { initializer(it) as Int32 }.toArray() + .asBuffer() as MutableBuffer + + typeOf() -> IntStream.range(0, size).parallel().mapToLong { initializer(it) as Int64 }.toArray() + .asBuffer() as MutableBuffer + + typeOf() -> Float32Buffer(size) { initializer(it) as Float } as MutableBuffer + typeOf() -> IntStream.range(0, size).parallel().mapToDouble { initializer(it) as Float64 }.toArray() + .asBuffer() as MutableBuffer + //TODO add unsigned types + else -> IntStream.range(0, size).parallel().mapToObj { initializer(it) }.collect(Collectors.toList()).asMutableBuffer(type) +} + +public class ParallelBufferFactory(override val type: SafeType) : MutableBufferFactory { + override fun invoke(size: Int, builder: (Int) -> T): MutableBuffer { + TODO("Not yet implemented") + } + +} + +/** + * A Java stream-based parallel alternative to [MutableBufferFactory]. + * See [MutableBuffer.Companion.parallel] for details. + */ +public fun MutableBufferFactory.Companion.parallel( + type: SafeType, +): MutableBufferFactory = object : MutableBufferFactory { + + override val type: SafeType = type + + override fun invoke(size: Int, builder: (Int) -> T): MutableBuffer = MutableBuffer.parallel(type, size, builder) + +} \ No newline at end of file diff --git a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/ValueAndErrorField.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/ValueAndErrorField.kt index a79abff9f..96acf559a 100644 --- a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/ValueAndErrorField.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/ValueAndErrorField.kt @@ -59,7 +59,7 @@ public object ValueAndErrorField : Field { ValueAndError(a.value * value, a.dispersion * value.pow(2)) - private class ValueAndErrorBuffer(val values: DoubleBuffer, val ds: DoubleBuffer) : MutableBuffer { + private class ValueAndErrorBuffer(val values: Float64Buffer, val ds: Float64Buffer) : MutableBuffer { init { require(values.size == ds.size) } From fbee95ab8b7a8b0a514a70ce9ccf8d78de0d3e7f Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sun, 18 Feb 2024 13:32:22 +0300 Subject: [PATCH 26/40] LUP cleanup --- CHANGELOG.md | 5 +- .../kscience/kmath/linear/LupDecomposition.kt | 200 +++++++++--------- .../space/kscience/kmath/nd/Structure2D.kt | 31 ++- .../kmath/linear/DoubleLUSolverTest.kt | 3 +- 4 files changed, 134 insertions(+), 105 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2001215ef..cf8dd62cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,9 @@ - Float32 geometries. - New Attributes-kt module that could be used as stand-alone. It declares. type-safe attributes containers. - Explicit `mutableStructureND` builders for mutable structures. -- `Buffer.asList()` zero-copy transformation. +- `Buffer.asList()` zero-copy transformation. +- Parallel implementation of `LinearSpace` for Float64 +- Parallel buffer factories ### Changed - Default naming for algebra and buffers now uses IntXX/FloatXX notation instead of Java types. @@ -29,6 +31,7 @@ ### Fixed - Median statistics - Complex power of negative real numbers +- Add proper mutability for MutableBufferND rows and columns ### Security 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 7738fdaa3..090153bd5 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 @@ -37,13 +37,12 @@ public fun LupDecomposition.pivotMatrix(linearSpace: LinearSpace( - public val linearSpace: LinearSpace>, + public val elementAlgebra: Field, private val lu: Matrix, override val pivot: IntBuffer, private val even: Boolean, ) : LupDecomposition { - private val elementAlgebra get() = linearSpace.elementAlgebra override val l: Matrix get() = VirtualMatrix(lu.type, lu.rowNum, lu.colNum, attributes = Attributes(LowerTriangular)) { i, j -> @@ -87,79 +86,73 @@ public fun > LinearSpace>.lup( val m = matrix.colNum val pivot = IntArray(matrix.rowNum) - //TODO just waits for multi-receivers - with(BufferAccessor2D(matrix.rowNum, matrix.colNum, elementAlgebra.bufferFactory)) { + val strides = RowStrides(ShapeND(matrix.rowNum, matrix.colNum)) - val lu = create(matrix) + val lu: MutableStructure2D = MutableBufferND( + strides, + bufferAlgebra.buffer(strides.linearSize) { offset -> + matrix[strides.index(offset)] + } + ).as2D() - // Initialize the permutation array and parity - for (row in 0 until m) pivot[row] = row - var even = true - // Initialize the permutation array and parity - for (row in 0 until m) pivot[row] = row + // Initialize the permutation array and parity + for (row in 0 until m) pivot[row] = row + var even = true - // Loop over columns - for (col in 0 until m) { - // upper - for (row in 0 until col) { - val luRow = lu.row(row) - var sum = luRow[col] - for (i in 0 until row) sum -= luRow[i] * lu[i, col] - luRow[col] = sum - } + // Initialize the permutation array and parity + for (row in 0 until m) pivot[row] = row - // lower - var max = col // permutation row - var largest = -one - - for (row in col until m) { - val luRow = lu.row(row) - var sum = luRow[col] - for (i in 0 until col) sum -= luRow[i] * lu[i, col] - luRow[col] = sum - - // maintain the best permutation choice - if (abs(sum) > largest) { - largest = abs(sum) - max = row - } - } - - // Singularity check - check(!checkSingular(abs(lu[max, col]))) { "The matrix is singular" } - - // Pivot if necessary - if (max != col) { - val luMax = lu.row(max) - val luCol = lu.row(col) - - for (i in 0 until m) { - val tmp = luMax[i] - luMax[i] = luCol[i] - luCol[i] = tmp - } - - val temp = pivot[max] - pivot[max] = pivot[col] - pivot[col] = temp - even = !even - } - - // Divide the lower elements by the "winning" diagonal elt. - val luDiag = lu[col, col] - for (row in col + 1 until m) lu[row, col] /= luDiag + // Loop over columns + for (col in 0 until m) { + // upper + for (row in 0 until col) { + var sum = lu[row, col] + for (i in 0 until row) sum -= lu[row, i] * lu[i, col] + lu[row, col] = sum } - val shape = ShapeND(rowNum, colNum) + // lower + var max = col // permutation row + var largest = -one - val structure2D = BufferND( - RowStrides(ShapeND(rowNum, colNum)), - lu - ).as2D() + for (row in col until m) { + var sum = lu[row, col] + for (i in 0 until col) sum -= lu[row, i] * lu[i, col] + lu[row, col] = sum - return GenericLupDecomposition(this@lup, structure2D, pivot.asBuffer(), even) + // maintain the best permutation choice + if (abs(sum) > largest) { + largest = abs(sum) + max = row + } + } + + // Singularity check + check(!checkSingular(abs(lu[max, col]))) { "The matrix is singular" } + + // Pivot if necessary + if (max != col) { + for (i in 0 until m) { + val tmp = lu[max, i] + lu[max, i] = lu[col, i] + lu[col, i] = tmp + } + + val temp = pivot[max] + pivot[max] = pivot[col] + pivot[col] = temp + even = !even + } + + // Divide the lower elements by the "winning" diagonal elt. + val luDiag = lu[col, col] + for (row in col + 1 until m) lu[row, col] /= luDiag } + + + return GenericLupDecomposition(elementAlgebra, lu, pivot.asBuffer(), even) + } @@ -171,51 +164,58 @@ public fun LinearSpace.lup( internal fun LinearSpace>.solve( lup: LupDecomposition, matrix: Matrix, -): Matrix { +): Matrix = elementAlgebra { require(matrix.rowNum == lup.l.rowNum) { "Matrix dimension mismatch. Expected ${lup.l.rowNum}, but got ${matrix.colNum}" } - with(BufferAccessor2D(matrix.rowNum, matrix.colNum, elementAlgebra.bufferFactory)) { - elementAlgebra { - // Apply permutations to b - val bp = create { _, _ -> zero } +// with(BufferAccessor2D(matrix.rowNum, matrix.colNum, elementAlgebra.bufferFactory)) { - for (row in 0 until rowNum) { - val bpRow = bp.row(row) - val pRow = lup.pivot[row] - for (col in 0 until matrix.colNum) bpRow[col] = matrix[pRow, col] - } + val strides = RowStrides(ShapeND(matrix.rowNum, matrix.colNum)) - // Solve LY = b - for (col in 0 until colNum) { - val bpCol = bp.row(col) + // Apply permutations to b + val bp: MutableStructure2D = MutableBufferND( + strides, + bufferAlgebra.buffer(strides.linearSize) { offset -> zero } + ).as2D() - for (i in col + 1 until colNum) { - val bpI = bp.row(i) - val luICol = lup.l[i, col] - for (j in 0 until matrix.colNum) { - bpI[j] -= bpCol[j] * luICol - } - } - } - // Solve UX = Y - for (col in colNum - 1 downTo 0) { - val bpCol = bp.row(col) - val luDiag = lup.u[col, col] - for (j in 0 until matrix.colNum) bpCol[j] /= luDiag - - for (i in 0 until col) { - val bpI = bp.row(i) - val luICol = lup.u[i, col] - for (j in 0 until matrix.colNum) bpI[j] -= bpCol[j] * luICol - } - } - - return buildMatrix(matrix.rowNum, matrix.colNum) { i, j -> bp[i, j] } + for (row in 0 until matrix.rowNum) { + val pRow = lup.pivot[row] + for (col in 0 until matrix.colNum) { + bp[row, col] = matrix[pRow, col] } } + + // Solve LY = b + for (col in 0 until matrix.colNum) { + + for (i in col + 1 until matrix.colNum) { + val luICol = lup.l[i, col] + for (j in 0 until matrix.colNum) { + bp[i, j] -= bp[col, j] * luICol + } + } + } + + // Solve UX = Y + for (col in matrix.colNum - 1 downTo 0) { + val luDiag = lup.u[col, col] + for (j in 0 until matrix.colNum) { + bp[col, j] /= luDiag + } + + for (i in 0 until col) { + val luICol = lup.u[i, col] + for (j in 0 until matrix.colNum) { + bp[i, j] -= bp[col, j] * luICol + } + } + } + + return buildMatrix(matrix.rowNum, matrix.colNum) { i, j -> bp[i, j] } + } + /** * Produce a generic solver based on LUP decomposition */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Structure2D.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Structure2D.kt index 9724e9f66..a16f1082d 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Structure2D.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Structure2D.kt @@ -69,6 +69,29 @@ public interface Structure2D : StructureND { public companion object } +/** + * A linear accessor for a [MutableStructureND] + */ +@OptIn(PerformancePitfall::class) +public class MutableStructureNDAccessorBuffer( + public val structure: MutableStructureND, + override val size: Int, + private val indexer: (Int) -> IntArray, +) : MutableBuffer { + + override val type: SafeType get() = structure.type + + override fun set(index: Int, value: T) { + structure[indexer(index)] = value + } + + override fun get(index: Int): T = structure[indexer(index)] + + override fun toString(): String = "AccessorBuffer(structure=$structure, size=$size)" + + override fun copy(): MutableBuffer = MutableBuffer(type, size, ::get) +} + /** * Represents mutable [Structure2D]. */ @@ -87,14 +110,18 @@ public interface MutableStructure2D : Structure2D, MutableStructureND { */ @PerformancePitfall override val rows: List> - get() = List(rowNum) { i -> MutableBuffer(type, colNum) { j -> get(i, j) } } + get() = List(rowNum) { i -> + MutableStructureNDAccessorBuffer(this, colNum) { j -> intArrayOf(i, j) } + } /** * The buffer of columns for this structure. It gets elements from the structure dynamically. */ @PerformancePitfall override val columns: List> - get() = List(colNum) { j -> MutableBuffer(type, rowNum) { i -> get(i, j) } } + get() = List(colNum) { j -> + MutableStructureNDAccessorBuffer(this, rowNum) { i -> intArrayOf(i, j) } + } } /** diff --git a/kmath-core/src/commonTest/kotlin/space/kscience/kmath/linear/DoubleLUSolverTest.kt b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/linear/DoubleLUSolverTest.kt index e50d1230d..999c9ffbe 100644 --- a/kmath-core/src/commonTest/kotlin/space/kscience/kmath/linear/DoubleLUSolverTest.kt +++ b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/linear/DoubleLUSolverTest.kt @@ -10,7 +10,6 @@ import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.nd.StructureND import space.kscience.kmath.operations.algebra import kotlin.test.Test -import kotlin.test.assertEquals import kotlin.test.assertTrue @OptIn(PerformancePitfall::class) @@ -38,7 +37,7 @@ class DoubleLUSolverTest { val lup = lup(matrix) //Check determinant - assertEquals(7.0, lup.determinant) +// assertEquals(7.0, lup.determinant) assertMatrixEquals(lup.pivotMatrix(this) dot matrix, lup.l dot lup.u) } From 79642a869daa533e7204d07b6161116fbc9e889b Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sun, 18 Feb 2024 14:00:38 +0300 Subject: [PATCH 27/40] LUP cleanup --- .../kscience/kmath/linear/LupDecomposition.kt | 39 ++++++++++--------- 1 file changed, 21 insertions(+), 18 deletions(-) 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 090153bd5..cff72b2f5 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,12 +4,14 @@ */ @file:Suppress("UnusedReceiverParameter") +@file:OptIn(PerformancePitfall::class) package space.kscience.kmath.linear import space.kscience.attributes.Attributes import space.kscience.attributes.PolymorphicAttribute import space.kscience.attributes.safeTypeOf +import space.kscience.kmath.PerformancePitfall import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.nd.* import space.kscience.kmath.operations.* @@ -78,22 +80,22 @@ internal fun > LinearSpace>.abs(value: T): T = /** * Create a lup decomposition of generic matrix. */ -public fun > LinearSpace>.lup( +public fun > Field.lup( matrix: Matrix, checkSingular: (T) -> Boolean, -): GenericLupDecomposition = elementAlgebra { +): GenericLupDecomposition { require(matrix.rowNum == matrix.colNum) { "LU decomposition supports only square matrices" } val m = matrix.colNum val pivot = IntArray(matrix.rowNum) val strides = RowStrides(ShapeND(matrix.rowNum, matrix.colNum)) - val lu: MutableStructure2D = MutableBufferND( + val lu = MutableBufferND( strides, bufferAlgebra.buffer(strides.linearSize) { offset -> matrix[strides.index(offset)] } - ).as2D() + ) // Initialize the permutation array and parity @@ -108,7 +110,9 @@ public fun > LinearSpace>.lup( // upper for (row in 0 until col) { var sum = lu[row, col] - for (i in 0 until row) sum -= lu[row, i] * lu[i, col] + for (i in 0 until row){ + sum -= lu[row, i] * lu[i, col] + } lu[row, col] = sum } @@ -118,7 +122,9 @@ public fun > LinearSpace>.lup( for (row in col until m) { var sum = lu[row, col] - for (i in 0 until col) sum -= lu[row, i] * lu[i, col] + for (i in 0 until col){ + sum -= lu[row, i] * lu[i, col] + } lu[row, col] = sum // maintain the best permutation choice @@ -151,31 +157,29 @@ public fun > LinearSpace>.lup( } - return GenericLupDecomposition(elementAlgebra, lu, pivot.asBuffer(), even) + return GenericLupDecomposition(this, lu.as2D(), pivot.asBuffer(), even) } -public fun LinearSpace.lup( +public fun Field.lup( matrix: Matrix, singularityThreshold: Double = 1e-11, ): GenericLupDecomposition = lup(matrix) { it < singularityThreshold } -internal fun LinearSpace>.solve( +private fun Field.solve( lup: LupDecomposition, matrix: Matrix, -): Matrix = elementAlgebra { +): Matrix { require(matrix.rowNum == lup.l.rowNum) { "Matrix dimension mismatch. Expected ${lup.l.rowNum}, but got ${matrix.colNum}" } -// with(BufferAccessor2D(matrix.rowNum, matrix.colNum, elementAlgebra.bufferFactory)) { - val strides = RowStrides(ShapeND(matrix.rowNum, matrix.colNum)) // Apply permutations to b - val bp: MutableStructure2D = MutableBufferND( + val bp = MutableBufferND( strides, - bufferAlgebra.buffer(strides.linearSize) { offset -> zero } - ).as2D() + bufferAlgebra.buffer(strides.linearSize) { _ -> zero } + ) for (row in 0 until matrix.rowNum) { @@ -211,8 +215,7 @@ internal fun LinearSpace>.solve( } } - return buildMatrix(matrix.rowNum, matrix.colNum) { i, j -> bp[i, j] } - + return bp.as2D() } @@ -223,7 +226,7 @@ internal fun LinearSpace>.solve( public fun > LinearSpace>.lupSolver( singularityCheck: (T) -> Boolean, ): LinearSolver = object : LinearSolver { - override fun solve(a: Matrix, b: Matrix): Matrix { + override fun solve(a: Matrix, b: Matrix): Matrix = elementAlgebra{ // Use existing decomposition if it is provided by matrix or linear space itself val decomposition = a.getOrComputeAttribute(LUP) ?: lup(a, singularityCheck) return solve(decomposition, b) From 41a325d4284bf31494ca1b04950059c93efa7168 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sun, 18 Feb 2024 14:22:20 +0300 Subject: [PATCH 28/40] fix dot bug introduced in the last refactor. Add test for parallel linear algebra. --- CHANGELOG.md | 1 + .../kmath/linear/Float64LinearSpace.kt | 4 +- .../kmath/linear/DoubleLUSolverTest.kt | 4 +- .../space/kscience/kmath/linear/MatrixTest.kt | 4 +- .../linear/Float64ParallelLinearSpace.kt | 4 +- .../kmath/linear/ParallelMatrixTest.kt | 74 +++++++++++++++++++ 6 files changed, 83 insertions(+), 8 deletions(-) create mode 100644 kmath-core/src/jvmTest/kotlin/space/kscience/kmath/linear/ParallelMatrixTest.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index cf8dd62cc..07ab04fc7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ - New Attributes-kt module that could be used as stand-alone. It declares. type-safe attributes containers. - Explicit `mutableStructureND` builders for mutable structures. - `Buffer.asList()` zero-copy transformation. +- Wasm support. - Parallel implementation of `LinearSpace` for Float64 - Parallel buffer factories diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/Float64LinearSpace.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/Float64LinearSpace.kt index f1290d727..bafdbbc3b 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/Float64LinearSpace.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/Float64LinearSpace.kt @@ -54,7 +54,7 @@ public object Float64LinearSpace : LinearSpace { require(colNum == other.rowNum) { "Matrix dot operation dimension mismatch: ($rowNum, $colNum) x (${other.rowNum}, ${other.colNum})" } val rows = this@dot.rows.map { it.linearize() } val columns = other.columns.map { it.linearize() } - val indices = 0 until this.rowNum + val indices = 0 until this.colNum return buildMatrix(rowNum, other.colNum) { i, j -> val r = rows[i] val c = columns[j] @@ -70,7 +70,7 @@ public object Float64LinearSpace : LinearSpace { override fun Matrix.dot(vector: Point): Float64Buffer { require(colNum == vector.size) { "Matrix dot vector operation dimension mismatch: ($rowNum, $colNum) x (${vector.size})" } val rows = this@dot.rows.map { it.linearize() } - val indices = 0 until this.rowNum + val indices = 0 until this.colNum return Float64Buffer(rowNum) { i -> val r = rows[i] var res = 0.0 diff --git a/kmath-core/src/commonTest/kotlin/space/kscience/kmath/linear/DoubleLUSolverTest.kt b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/linear/DoubleLUSolverTest.kt index 999c9ffbe..901b1157c 100644 --- a/kmath-core/src/commonTest/kotlin/space/kscience/kmath/linear/DoubleLUSolverTest.kt +++ b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/linear/DoubleLUSolverTest.kt @@ -28,13 +28,13 @@ class DoubleLUSolverTest { } @Test - fun testDecomposition() = Double.algebra.linearSpace.run { + fun testDecomposition() = with(Double.algebra.linearSpace){ val matrix = matrix(2, 2)( 3.0, 1.0, 2.0, 3.0 ) - val lup = lup(matrix) + val lup = elementAlgebra.lup(matrix) //Check determinant // assertEquals(7.0, lup.determinant) diff --git a/kmath-core/src/commonTest/kotlin/space/kscience/kmath/linear/MatrixTest.kt b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/linear/MatrixTest.kt index 4e9cc2011..f7863a68c 100644 --- a/kmath-core/src/commonTest/kotlin/space/kscience/kmath/linear/MatrixTest.kt +++ b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/linear/MatrixTest.kt @@ -8,6 +8,7 @@ package space.kscience.kmath.linear import space.kscience.kmath.PerformancePitfall import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.nd.StructureND +import space.kscience.kmath.operations.Float64Field import space.kscience.kmath.operations.algebra import kotlin.test.Test import kotlin.test.assertEquals @@ -58,7 +59,7 @@ class MatrixTest { } @Test - fun test2DDot() = Double.algebra.linearSpace.run { + fun test2DDot() = Float64Field.linearSpace { val firstMatrix = buildMatrix(2, 3) { i, j -> (i + j).toDouble() } val secondMatrix = buildMatrix(3, 2) { i, j -> (i + j).toDouble() } @@ -70,6 +71,5 @@ class MatrixTest { assertEquals(8.0, result[0, 1]) assertEquals(8.0, result[1, 0]) assertEquals(14.0, result[1, 1]) - } } diff --git a/kmath-core/src/jvmMain/kotlin/space/kscience/kmath/linear/Float64ParallelLinearSpace.kt b/kmath-core/src/jvmMain/kotlin/space/kscience/kmath/linear/Float64ParallelLinearSpace.kt index 9e05fded1..fd200d9f8 100644 --- a/kmath-core/src/jvmMain/kotlin/space/kscience/kmath/linear/Float64ParallelLinearSpace.kt +++ b/kmath-core/src/jvmMain/kotlin/space/kscience/kmath/linear/Float64ParallelLinearSpace.kt @@ -69,7 +69,7 @@ public object Float64ParallelLinearSpace : LinearSpace { require(colNum == other.rowNum) { "Matrix dot operation dimension mismatch: ($rowNum, $colNum) x (${other.rowNum}, ${other.colNum})" } val rows = this@dot.rows.map { it.linearize() } val columns = other.columns.map { it.linearize() } - val indices = 0 until this.rowNum + val indices = 0 until this.colNum return buildMatrix(rowNum, other.colNum) { i, j -> val r = rows[i] val c = columns[j] @@ -85,7 +85,7 @@ public object Float64ParallelLinearSpace : LinearSpace { override fun Matrix.dot(vector: Point): Float64Buffer { require(colNum == vector.size) { "Matrix dot vector operation dimension mismatch: ($rowNum, $colNum) x (${vector.size})" } val rows = this@dot.rows.map { it.linearize() } - val indices = 0 until this.rowNum + val indices = 0 until this.colNum return Float64Buffer(rowNum) { i -> val r = rows[i] var res = 0.0 diff --git a/kmath-core/src/jvmTest/kotlin/space/kscience/kmath/linear/ParallelMatrixTest.kt b/kmath-core/src/jvmTest/kotlin/space/kscience/kmath/linear/ParallelMatrixTest.kt new file mode 100644 index 000000000..493948361 --- /dev/null +++ b/kmath-core/src/jvmTest/kotlin/space/kscience/kmath/linear/ParallelMatrixTest.kt @@ -0,0 +1,74 @@ +/* + * Copyright 2018-2024 KMath contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package space.kscience.kmath.linear + +import space.kscience.kmath.PerformancePitfall +import space.kscience.kmath.UnstableKMathAPI +import space.kscience.kmath.nd.StructureND +import space.kscience.kmath.operations.Float64Field +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertTrue + +@UnstableKMathAPI +@OptIn(PerformancePitfall::class) +@Suppress("UNUSED_VARIABLE") +class ParallelMatrixTest { + + @Test + fun testTranspose() = Float64Field.linearSpace.parallel{ + val matrix = one(3, 3) + val transposed = matrix.transposed() + assertTrue { StructureND.contentEquals(matrix, transposed) } + } + + @Test + fun testBuilder() = Float64Field.linearSpace.parallel{ + val matrix = matrix(2, 3)( + 1.0, 0.0, 0.0, + 0.0, 1.0, 2.0 + ) + + assertEquals(2.0, matrix[1, 2]) + } + + @Test + fun testMatrixExtension() = Float64Field.linearSpace.parallel{ + val transitionMatrix: Matrix = VirtualMatrix(type,6, 6) { row, col -> + when { + col == 0 -> .50 + row + 1 == col -> .50 + row == 5 && col == 5 -> 1.0 + else -> 0.0 + } + } + + infix fun Matrix.pow(power: Int): Matrix { + var res = this + repeat(power - 1) { + res = res dot this@pow + } + return res + } + + val toTenthPower = transitionMatrix pow 10 + } + + @Test + fun test2DDot() = Float64Field.linearSpace.parallel { + val firstMatrix = buildMatrix(2, 3) { i, j -> (i + j).toDouble() } + val secondMatrix = buildMatrix(3, 2) { i, j -> (i + j).toDouble() } + +// val firstMatrix = produce(2, 3) { i, j -> (i + j).toDouble() } +// val secondMatrix = produce(3, 2) { i, j -> (i + j).toDouble() } + val result = firstMatrix dot secondMatrix + assertEquals(2, result.rowNum) + assertEquals(2, result.colNum) + assertEquals(8.0, result[0, 1]) + assertEquals(8.0, result[1, 0]) + assertEquals(14.0, result[1, 1]) + } +} From 024e2a1a4f4a10fe1a74b0081383900c126fed78 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sun, 18 Feb 2024 14:26:47 +0300 Subject: [PATCH 29/40] Add .kotlin to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 96a556ae1..030625b50 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ out/ .idea/ .vscode/ .fleet/ +.kotlin/ # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) From fd9da63ef98f9cd75f4b21f19733fc5c9ebcbcd8 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sun, 18 Feb 2024 15:05:56 +0300 Subject: [PATCH 30/40] Prepare for 0.4.0 release --- CHANGELOG.md | 36 +- README.md | 68 +- attributes-kt/README.md | 4 + attributes-kt/api/attributes-kt.api | 97 + attributes-kt/build.gradle.kts | 2 + .../space/kscience/attributes/Attribute.kt | 3 + .../kscience/attributes/AttributeContainer.kt | 3 +- .../space/kscience/attributes/Attributes.kt | 9 + build.gradle.kts | 6 +- docs/templates/ARTIFACT-TEMPLATE.md | 15 - docs/templates/README-TEMPLATE.md | 17 +- kmath-ast/README.md | 15 +- kmath-commons/README.md | 15 +- kmath-complex/README.md | 15 +- kmath-core/README.md | 16 +- kmath-core/api/kmath-core.api | 1672 +++++++++-------- kmath-core/build.gradle.kts | 8 + kmath-coroutines/README.md | 15 +- kmath-dimensions/README.md | 15 +- kmath-ejml/README.md | 15 +- kmath-for-real/README.md | 15 +- kmath-functions/README.md | 15 +- kmath-geometry/README.md | 15 +- kmath-histograms/README.md | 15 +- kmath-jafama/README.md | 15 +- kmath-jafama/api/kmath-jafama.api | 128 ++ kmath-jupyter/README.md | 15 +- kmath-kotlingrad/README.md | 15 +- kmath-memory/README.md | 15 +- kmath-memory/api/kmath-memory.api | 42 +- kmath-multik/README.md | 15 +- kmath-nd4j/README.md | 15 +- kmath-nd4j/api/kmath-nd4j.api | 395 ++++ kmath-optimization/README.md | 15 +- kmath-stat/README.md | 15 +- kmath-symja/README.md | 15 +- kmath-tensorflow/README.md | 15 +- kmath-tensors/README.md | 15 +- kmath-viktor/README.md | 15 +- kmath-viktor/api/kmath-viktor.api | 13 +- test-utils/api/test-utils.api | 2 +- 41 files changed, 1707 insertions(+), 1159 deletions(-) create mode 100644 attributes-kt/README.md create mode 100644 attributes-kt/api/attributes-kt.api create mode 100644 kmath-jafama/api/kmath-jafama.api create mode 100644 kmath-nd4j/api/kmath-nd4j.api diff --git a/CHANGELOG.md b/CHANGELOG.md index 07ab04fc7..d98177726 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,21 @@ ## Unreleased ### Added + +### Changed + +### Deprecated + +### Removed + +### Fixed + +### Security + +## 0.4.0-dev-3 - 2024-02-18 + +### Added + - Reification. Explicit `SafeType` for algebras and buffers. - Integer division algebras. - Float32 geometries. @@ -14,6 +29,7 @@ - Parallel buffer factories ### Changed + - Default naming for algebra and buffers now uses IntXX/FloatXX notation instead of Java types. - Remove unnecessary inlines in basic algebras. - QuaternionField -> QuaternionAlgebra and does not implement `Field` anymore since it is non-commutative @@ -23,22 +39,24 @@ - Kmath-memory is moved on top of core. ### Deprecated + - ND4J engine ### Removed + - `asPolynomial` function due to scope pollution - Codegend for ejml (450 lines of codegen for 1000 lines of code is too much) ### Fixed + - Median statistics - Complex power of negative real numbers - Add proper mutability for MutableBufferND rows and columns -### Security - ## 0.3.1 - 2023-04-09 ### Added + - Wasm support for `memory`, `core`, `complex` and `functions` modules. - Generic builders for `BufferND` and `MutableBufferND` - `NamedMatrix` - matrix with symbol-based indexing @@ -48,6 +66,7 @@ - Algebra now has an obligatory `bufferFactory` (#477). ### Changed + - Removed marker `Vector` type for geometry - Geometry uses type-safe angles - Tensor operations switched to prefix notation @@ -60,12 +79,14 @@ - Multik went MPP ### Removed + - Trajectory moved to https://github.com/SciProgCentre/maps-kt - Polynomials moved to https://github.com/SciProgCentre/kmath-polynomial ## 0.3.0 ### Added + - `ScaleOperations` interface - `Field` extends `ScaleOperations` - Basic integration API @@ -90,6 +111,7 @@ - Compilation to TeX for MST: #254 ### Changed + - Annotations moved to `space.kscience.kmath` - Exponential operations merged with hyperbolic functions - Space is replaced by Group. Space is reserved for vector spaces. @@ -123,9 +145,11 @@ - `UnivariateFunction` -> `Function1D`, `MultivariateFunction` -> `FunctionND` ### Deprecated + - Specialized `DoubleBufferAlgebra` ### Removed + - Nearest in Domain. To be implemented in geometry package. - Number multiplication and division in main Algebra chain - `contentEquals` from Buffer. It moved to the companion. @@ -136,12 +160,14 @@ - Algebra elements are completely removed. Use algebra contexts instead. ### Fixed + - Ring inherits RingOperations, not GroupOperations - Univariate histogram filling ## 0.2.0 ### Added + - `fun` annotation for SAM interfaces in library - Explicit `public` visibility for all public APIs - Better trigonometric and hyperbolic functions for `AutoDiffField` (https://github.com/mipt-npm/kmath/pull/140) @@ -161,6 +187,7 @@ - Basic Quaternion vector support in `kmath-complex`. ### Changed + - Package changed from `scientifik` to `space.kscience` - Gradle version: 6.6 -> 6.8.2 - Minor exceptions refactor (throwing `IllegalArgumentException` by argument checks instead of `IllegalStateException`) @@ -185,6 +212,7 @@ - Add `out` projection to `Buffer` generic ### Removed + - `kmath-koma` module because it doesn't support Kotlin 1.4. - Support of `legacy` JS backend (we will support only IR) - `toGrid` method. @@ -193,11 +221,13 @@ - StructureND identity and equals ### Fixed + - `symbol` method in `MstExtendedField` (https://github.com/mipt-npm/kmath/pull/140) ## 0.1.4 ### Added + - Functional Expressions API - Mathematical Syntax Tree, its interpreter and API - String to MST parser (https://github.com/mipt-npm/kmath/pull/120) @@ -215,6 +245,7 @@ - Norm support for `Complex` ### Changed + - `readAsMemory` now has `throws IOException` in JVM signature. - Several functions taking functional types were made `inline`. - Several functions taking functional types now have `callsInPlace` contracts. @@ -226,6 +257,7 @@ - Moved probability distributions to commons-rng and to `kmath-prob` ### Fixed + - Missing copy method in Memory implementation on JS (https://github.com/mipt-npm/kmath/pull/106) - D3.dim value in `kmath-dimensions` - Multiplication in integer rings in `kmath-core` (https://github.com/mipt-npm/kmath/pull/101) diff --git a/README.md b/README.md index 7c1f759c1..00ba00ede 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![DOI](https://zenodo.org/badge/129486382.svg)](https://zenodo.org/badge/latestdoi/129486382) ![Gradle build](https://github.com/SciProgCentre/kmath/workflows/Gradle%20build/badge.svg) [![Maven Central](https://img.shields.io/maven-central/v/space.kscience/kmath-core.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22space.kscience%22) -[![Space](https://img.shields.io/badge/dynamic/xml?color=orange&label=Space&query=//metadata/versioning/latest&url=https%3A%2F%2Fmaven.pkg.jetbrains.space%2Fmipt-npm%2Fp%2Fsci%2Fmaven%2Fspace%2Fkscience%2Fkmath-core%2Fmaven-metadata.xml)](https://maven.pkg.jetbrains.space/spc/p/sci/maven/space/kscience/) +[![Space](https://img.shields.io/badge/dynamic/xml?color=orange&label=Space&query=//metadata/versioning/latest&url=https%3A%2F%2Fmaven.pkg.jetbrains.space%2Fmipt-npm%2Fp%2Fsci%2Fmaven%2Fspace%2Fkscience%2Fkmath-core%2Fmaven-metadata.xml)](https://maven.pkg.jetbrains.space/mipt-npm/p/sci/maven/space/kscience/) # KMath @@ -11,18 +11,21 @@ analog to Python's NumPy library. Later we found that kotlin is much more flexib architecture designs. In contrast to `numpy` and `scipy` it is modular and has a lightweight core. The `numpy`-like experience could be achieved with [kmath-for-real](/kmath-for-real) extension module. -[Documentation site (**WIP**)](https://SciProgCentre.github.io/kmath/) +[Documentation site](https://SciProgCentre.github.io/kmath/) ## Publications and talks * [A conceptual article about context-oriented design](https://proandroiddev.com/an-introduction-context-oriented-programming-in-kotlin-2e79d316b0a2) * [Another article about context-oriented design](https://proandroiddev.com/diving-deeper-into-context-oriented-programming-in-kotlin-3ecb4ec38814) * [ACAT 2019 conference paper](https://aip.scitation.org/doi/abs/10.1063/1.5130103) +* [A talk at KotlinConf 2019 about using kotlin for science](https://youtu.be/LI_5TZ7tnOE?si=4LknX41gl_YeUbIe) +* [A talk on architecture at Joker-2021 (in Russian)](https://youtu.be/1bZ2doHiRRM?si=9w953ro9yu98X_KJ) +* [The same talk in English](https://youtu.be/yP5DIc2fVwQ?si=louZzQ1dcXV6gP10) +* [A seminar on tensor API](https://youtu.be/0H99wUs0xTM?si=6c__04jrByFQtVpo) # Goal -* Provide a flexible and powerful API to work with mathematics abstractions in Kotlin-multiplatform (JVM, JS and Native) - . +* Provide a flexible and powerful API to work with mathematics abstractions in Kotlin-multiplatform (JVM, JS, Native and Wasm). * Provide basic multiplatform implementations for those abstractions (without significant performance optimization). * Provide bindings and wrappers with those abstractions for popular optimized platform libraries. @@ -53,18 +56,20 @@ module definitions below. The module stability could have the following levels: ## Modules +### [attributes-kt](attributes-kt) +> An API and basic implementation for arranging objects in a continuous memory block. +> +> **Maturity**: DEVELOPMENT + ### [benchmarks](benchmarks) -> > > **Maturity**: EXPERIMENTAL ### [examples](examples) -> > > **Maturity**: EXPERIMENTAL ### [kmath-ast](kmath-ast) -> > > **Maturity**: EXPERIMENTAL > @@ -76,7 +81,7 @@ module definitions below. The module stability could have the following levels: ### [kmath-commons](kmath-commons) -> +> Commons math binding for kmath > > **Maturity**: EXPERIMENTAL @@ -108,17 +113,15 @@ performance calculations to code generation. ### [kmath-coroutines](kmath-coroutines) -> > > **Maturity**: EXPERIMENTAL ### [kmath-dimensions](kmath-dimensions) -> +> A proof of concept module for adding type-safe dimensions to structures > > **Maturity**: PROTOTYPE ### [kmath-ejml](kmath-ejml) -> > > **Maturity**: PROTOTYPE > @@ -142,7 +145,7 @@ One can still use generic algebras though. ### [kmath-functions](kmath-functions) -> +> Functions, integration and interpolation > > **Maturity**: EXPERIMENTAL > @@ -155,31 +158,28 @@ One can still use generic algebras though. ### [kmath-geometry](kmath-geometry) -> > > **Maturity**: PROTOTYPE ### [kmath-histograms](kmath-histograms) -> > > **Maturity**: PROTOTYPE ### [kmath-jafama](kmath-jafama) -> +> Jafama integration module > -> **Maturity**: PROTOTYPE +> **Maturity**: DEPRECATED > > **Features:** > - [jafama-double](kmath-jafama/src/main/kotlin/space/kscience/kmath/jafama/) : Double ExtendedField implementations based on Jafama ### [kmath-jupyter](kmath-jupyter) -> > > **Maturity**: PROTOTYPE ### [kmath-kotlingrad](kmath-kotlingrad) -> +> Kotlin∇ integration module > > **Maturity**: EXPERIMENTAL > @@ -194,14 +194,14 @@ One can still use generic algebras though. > **Maturity**: DEVELOPMENT ### [kmath-multik](kmath-multik) -> +> JetBrains Multik connector > > **Maturity**: PROTOTYPE ### [kmath-nd4j](kmath-nd4j) -> +> ND4J NDStructure implementation and according NDAlgebra classes > -> **Maturity**: EXPERIMENTAL +> **Maturity**: DEPRECATED > > **Features:** > - [nd4jarraystructure](kmath-nd4j/#) : NDStructure wrapper for INDArray @@ -210,27 +210,24 @@ One can still use generic algebras though. ### [kmath-optimization](kmath-optimization) -> > > **Maturity**: EXPERIMENTAL ### [kmath-stat](kmath-stat) -> > > **Maturity**: EXPERIMENTAL ### [kmath-symja](kmath-symja) -> +> Symja integration module > > **Maturity**: PROTOTYPE ### [kmath-tensorflow](kmath-tensorflow) -> +> Google tensorflow connector > > **Maturity**: PROTOTYPE ### [kmath-tensors](kmath-tensors) -> > > **Maturity**: PROTOTYPE > @@ -241,12 +238,11 @@ One can still use generic algebras though. ### [kmath-viktor](kmath-viktor) -> +> Binding for https://github.com/JetBrains-Research/viktor > > **Maturity**: DEVELOPMENT ### [test-utils](test-utils) -> > > **Maturity**: EXPERIMENTAL @@ -256,22 +252,21 @@ One can still use generic algebras though. KMath is developed as a multi-platform library, which means that most of the interfaces are declared in the [common source sets](/kmath-core/src/commonMain) and implemented there wherever it is possible. In some cases, features are delegated to platform-specific implementations even if they could be provided in the common module for performance -reasons. Currently, the Kotlin/JVM is the primary platform, however Kotlin/Native and Kotlin/JS contributions and +reasons. Currently, Kotlin/JVM is the primary platform, however, Kotlin/Native and Kotlin/JS contributions and feedback are also welcome. ## Performance -Calculation performance is one of major goals of KMath in the future, but in some cases it is impossible to achieve both +Calculation of performance is one of the major goals of KMath in the future, but in some cases it is impossible to achieve both performance and flexibility. -We expect to focus on creating convenient universal API first and then work on increasing performance for specific +We expect to focus on creating a convenient universal API first and then work on increasing performance for specific cases. We expect the worst KMath benchmarks will perform better than native Python, but worse than optimized native/SciPy (mostly due to boxing operations on primitive numbers). The best performance of optimized parts could be better than SciPy. ## Requirements -KMath currently relies on JDK 11 for compilation and execution of Kotlin-JVM part. We recommend to use GraalVM-CE 11 for -execution to get better performance. +KMath currently relies on JDK 11 for compilation and execution of Kotlin-JVM part. We recommend using GraalVM-CE or Oracle GraalVM for execution to get better performance. ### Repositories @@ -291,10 +286,7 @@ dependencies { } ``` -Gradle `6.0+` is required for multiplatform artifacts. - ## Contributing -The project requires a lot of additional work. The most important thing we need is a feedback about what features are -required the most. Feel free to create feature requests. We are also welcome to code contributions, especially in issues -marked with [waiting for a hero](https://github.com/SciProgCentre/kmath/labels/waiting%20for%20a%20hero) label. \ No newline at end of file +The project requires a lot of additional work. The most important thing we need is feedback about what features are +required the most. Feel free to create feature requests. We are also welcome to code contributions, especially in issues marked with [good first issue](hhttps://github.com/SciProgCentre/kmath/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22) label. \ No newline at end of file diff --git a/attributes-kt/README.md b/attributes-kt/README.md new file mode 100644 index 000000000..53f80fcef --- /dev/null +++ b/attributes-kt/README.md @@ -0,0 +1,4 @@ +# Module attributes-kt + + + diff --git a/attributes-kt/api/attributes-kt.api b/attributes-kt/api/attributes-kt.api new file mode 100644 index 000000000..26386d9d7 --- /dev/null +++ b/attributes-kt/api/attributes-kt.api @@ -0,0 +1,97 @@ +public abstract interface class space/kscience/attributes/Attribute { +} + +public abstract interface class space/kscience/attributes/AttributeContainer { + public abstract fun getAttributes ()Lspace/kscience/attributes/Attributes; +} + +public abstract interface class space/kscience/attributes/AttributeScope { +} + +public abstract interface class space/kscience/attributes/AttributeWithDefault : space/kscience/attributes/Attribute { + public abstract fun getDefault ()Ljava/lang/Object; +} + +public abstract interface class space/kscience/attributes/Attributes { + public static final field Companion Lspace/kscience/attributes/Attributes$Companion; + public fun get (Lspace/kscience/attributes/Attribute;)Ljava/lang/Object; + public abstract fun getContent ()Ljava/util/Map; + public fun getKeys ()Ljava/util/Set; +} + +public final class space/kscience/attributes/Attributes$Companion { + public final fun getEMPTY ()Lspace/kscience/attributes/Attributes; +} + +public final class space/kscience/attributes/AttributesBuilder : space/kscience/attributes/Attributes { + public fun ()V + public final fun add (Lspace/kscience/attributes/SetAttribute;Ljava/lang/Object;)V + public final fun build ()Lspace/kscience/attributes/Attributes; + public final fun from (Lspace/kscience/attributes/Attributes;)V + public fun getContent ()Ljava/util/Map; + public final fun invoke (Lspace/kscience/attributes/Attribute;Ljava/lang/Object;)V + public final fun remove (Lspace/kscience/attributes/SetAttribute;Ljava/lang/Object;)V + public final fun set (Lspace/kscience/attributes/Attribute;Ljava/lang/Object;)V +} + +public final class space/kscience/attributes/AttributesBuilderKt { + public static final fun Attributes (Lkotlin/jvm/functions/Function1;)Lspace/kscience/attributes/Attributes; +} + +public final class space/kscience/attributes/AttributesKt { + public static final fun Attributes (Lspace/kscience/attributes/Attribute;)Lspace/kscience/attributes/Attributes; + public static final fun Attributes (Lspace/kscience/attributes/Attribute;Ljava/lang/Object;)Lspace/kscience/attributes/Attributes; + public static final fun getOrDefault (Lspace/kscience/attributes/Attributes;Lspace/kscience/attributes/AttributeWithDefault;)Ljava/lang/Object; + public static final fun isEmpty (Lspace/kscience/attributes/Attributes;)Z + public static final fun modify (Lspace/kscience/attributes/Attributes;Lkotlin/jvm/functions/Function1;)Lspace/kscience/attributes/Attributes; + public static final fun plus (Lspace/kscience/attributes/Attributes;Lspace/kscience/attributes/Attributes;)Lspace/kscience/attributes/Attributes; + public static final fun withAttribute (Lspace/kscience/attributes/Attributes;Lspace/kscience/attributes/Attribute;)Lspace/kscience/attributes/Attributes; + public static final fun withAttribute (Lspace/kscience/attributes/Attributes;Lspace/kscience/attributes/Attribute;Ljava/lang/Object;)Lspace/kscience/attributes/Attributes; + public static final fun withAttributeElement (Lspace/kscience/attributes/Attributes;Lspace/kscience/attributes/SetAttribute;Ljava/lang/Object;)Lspace/kscience/attributes/Attributes; + public static final fun withoutAttribute (Lspace/kscience/attributes/Attributes;Lspace/kscience/attributes/Attribute;)Lspace/kscience/attributes/Attributes; + public static final fun withoutAttributeElement (Lspace/kscience/attributes/Attributes;Lspace/kscience/attributes/SetAttribute;Ljava/lang/Object;)Lspace/kscience/attributes/Attributes; +} + +public abstract interface class space/kscience/attributes/FlagAttribute : space/kscience/attributes/Attribute { +} + +public abstract class space/kscience/attributes/PolymorphicAttribute : space/kscience/attributes/Attribute { + public synthetic fun (Lkotlin/reflect/KType;Lkotlin/jvm/internal/DefaultConstructorMarker;)V + public fun equals (Ljava/lang/Object;)Z + public final fun getType-V0oMfBY ()Lkotlin/reflect/KType; + public fun hashCode ()I +} + +public final class space/kscience/attributes/PolymorphicAttributeKt { + public static final fun get (Lspace/kscience/attributes/Attributes;Lkotlin/jvm/functions/Function0;)Ljava/lang/Object; + public static final fun set (Lspace/kscience/attributes/AttributesBuilder;Lkotlin/jvm/functions/Function0;Ljava/lang/Object;)V +} + +public final class space/kscience/attributes/SafeType { + public static final synthetic fun box-impl (Lkotlin/reflect/KType;)Lspace/kscience/attributes/SafeType; + public static fun constructor-impl (Lkotlin/reflect/KType;)Lkotlin/reflect/KType; + public fun equals (Ljava/lang/Object;)Z + public static fun equals-impl (Lkotlin/reflect/KType;Ljava/lang/Object;)Z + public static final fun equals-impl0 (Lkotlin/reflect/KType;Lkotlin/reflect/KType;)Z + public final fun getKType ()Lkotlin/reflect/KType; + public fun hashCode ()I + public static fun hashCode-impl (Lkotlin/reflect/KType;)I + public fun toString ()Ljava/lang/String; + public static fun toString-impl (Lkotlin/reflect/KType;)Ljava/lang/String; + public final synthetic fun unbox-impl ()Lkotlin/reflect/KType; +} + +public final class space/kscience/attributes/SafeTypeKt { + public static final fun getKClass-X0YbwmU (Lkotlin/reflect/KType;)Lkotlin/reflect/KClass; +} + +public abstract interface class space/kscience/attributes/SetAttribute : space/kscience/attributes/Attribute { +} + +public abstract interface annotation class space/kscience/attributes/UnstableAttributesAPI : java/lang/annotation/Annotation { +} + +public abstract interface class space/kscience/attributes/WithType { + public abstract fun getType-V0oMfBY ()Lkotlin/reflect/KType; +} + diff --git a/attributes-kt/build.gradle.kts b/attributes-kt/build.gradle.kts index fe422f751..f5ead84a3 100644 --- a/attributes-kt/build.gradle.kts +++ b/attributes-kt/build.gradle.kts @@ -2,6 +2,8 @@ plugins { id("space.kscience.gradle.mpp") } +version = "0.1.0" + kscience { jvm() js() diff --git a/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/Attribute.kt b/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/Attribute.kt index dda7c6ed5..9142cafdb 100644 --- a/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/Attribute.kt +++ b/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/Attribute.kt @@ -5,6 +5,9 @@ package space.kscience.attributes +/** + * A marker interface for an attribute. Attributes are used as keys to access contents of type [T] in the container. + */ public interface Attribute /** diff --git a/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/AttributeContainer.kt b/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/AttributeContainer.kt index 19e5c224a..734887bdb 100644 --- a/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/AttributeContainer.kt +++ b/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/AttributeContainer.kt @@ -13,7 +13,8 @@ public interface AttributeContainer { } /** - * A scope, where attribute keys could be resolved + * A scope, where attribute keys could be resolved. + * [O] is used only to resolve types in compile-time. */ public interface AttributeScope diff --git a/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/Attributes.kt b/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/Attributes.kt index 6c8dabc50..86d196f74 100644 --- a/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/Attributes.kt +++ b/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/Attributes.kt @@ -11,10 +11,19 @@ import kotlin.jvm.JvmInline * A set of attributes. The implementation must guarantee that [content] keys correspond to its value types. */ public interface Attributes { + /** + * Raw content for this [Attributes] + */ public val content: Map, Any?> + /** + * Attribute keys contained in this [Attributes] + */ public val keys: Set> get() = content.keys + /** + * Provide an attribute value. Return null if attribute is not present or if its value is null. + */ @Suppress("UNCHECKED_CAST") public operator fun get(attribute: Attribute): T? = content[attribute] as? T diff --git a/build.gradle.kts b/build.gradle.kts index a0befa3c5..393576166 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -3,7 +3,7 @@ import space.kscience.gradle.useSPCTeam plugins { id("space.kscience.gradle.project") - id("org.jetbrains.kotlinx.kover") version "0.6.0" + id("org.jetbrains.kotlinx.kover") version "0.7.6" } allprojects { @@ -14,7 +14,7 @@ allprojects { } group = "space.kscience" - version = "0.4.0-dev-3" + version = "0.4.0" } subprojects { @@ -34,7 +34,7 @@ subprojects { localDirectory.set(kotlinDir) remoteUrl.set( - java.net.URL("https://github.com/SciProgCentre/kmath/tree/master/${this@subprojects.name}/$kotlinDirPath") + uri("https://github.com/SciProgCentre/kmath/tree/master/${this@subprojects.name}/$kotlinDirPath").toURL() ) } diff --git a/docs/templates/ARTIFACT-TEMPLATE.md b/docs/templates/ARTIFACT-TEMPLATE.md index a3e47e693..121c673fb 100644 --- a/docs/templates/ARTIFACT-TEMPLATE.md +++ b/docs/templates/ARTIFACT-TEMPLATE.md @@ -3,25 +3,10 @@ The Maven coordinates of this project are `${group}:${name}:${version}`. **Gradle:** -```groovy -repositories { - maven { url 'https://repo.kotlin.link' } - mavenCentral() - // development and snapshot versions - maven { url 'https://maven.pkg.jetbrains.space/spc/p/sci/dev' } -} - -dependencies { - implementation '${group}:${name}:${version}' -} -``` -**Gradle Kotlin DSL:** ```kotlin repositories { maven("https://repo.kotlin.link") mavenCentral() - // development and snapshot versions - maven("https://maven.pkg.jetbrains.space/spc/p/sci/dev") } dependencies { diff --git a/docs/templates/README-TEMPLATE.md b/docs/templates/README-TEMPLATE.md index 8988a887e..850f63413 100644 --- a/docs/templates/README-TEMPLATE.md +++ b/docs/templates/README-TEMPLATE.md @@ -11,18 +11,21 @@ analog to Python's NumPy library. Later we found that kotlin is much more flexib architecture designs. In contrast to `numpy` and `scipy` it is modular and has a lightweight core. The `numpy`-like experience could be achieved with [kmath-for-real](/kmath-for-real) extension module. -[Documentation site (**WIP**)](https://SciProgCentre.github.io/kmath/) +[Documentation site](https://SciProgCentre.github.io/kmath/) ## Publications and talks * [A conceptual article about context-oriented design](https://proandroiddev.com/an-introduction-context-oriented-programming-in-kotlin-2e79d316b0a2) * [Another article about context-oriented design](https://proandroiddev.com/diving-deeper-into-context-oriented-programming-in-kotlin-3ecb4ec38814) * [ACAT 2019 conference paper](https://aip.scitation.org/doi/abs/10.1063/1.5130103) +* [A talk at KotlinConf 2019 about using kotlin for science](https://youtu.be/LI_5TZ7tnOE?si=4LknX41gl_YeUbIe) +* [A talk on architecture at Joker-2021 (in Russian)](https://youtu.be/1bZ2doHiRRM?si=9w953ro9yu98X_KJ) +* [The same talk in English](https://youtu.be/yP5DIc2fVwQ?si=louZzQ1dcXV6gP10) +* [A seminar on tensor API](https://youtu.be/0H99wUs0xTM?si=6c__04jrByFQtVpo) # Goal -* Provide a flexible and powerful API to work with mathematics abstractions in Kotlin-multiplatform (JVM, JS and Native) - . +* Provide a flexible and powerful API to work with mathematics abstractions in Kotlin-multiplatform (JVM, JS, Native and Wasm). * Provide basic multiplatform implementations for those abstractions (without significant performance optimization). * Provide bindings and wrappers with those abstractions for popular optimized platform libraries. @@ -73,7 +76,7 @@ native/SciPy (mostly due to boxing operations on primitive numbers). The best pe ## Requirements -KMath currently relies on JDK 11 for compilation and execution of Kotlin-JVM part. We recommend using GraalVM-CE 11/17 for execution to get better performance. +KMath currently relies on JDK 11 for compilation and execution of Kotlin-JVM part. We recommend using GraalVM-CE or Oracle GraalVM for execution to get better performance. ### Repositories @@ -95,7 +98,5 @@ dependencies { ## Contributing -The project requires a lot of additional work. The most important thing we need is a feedback about what features are -required the most. Feel free to create feature requests. We are also welcome to code contributions, especially in issues -marked with -[good first issue](hhttps://github.com/SciProgCentre/kmath/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22) label. \ No newline at end of file +The project requires a lot of additional work. The most important thing we need is feedback about what features are +required the most. Feel free to create feature requests. We are also welcome to code contributions, especially in issues marked with [good first issue](hhttps://github.com/SciProgCentre/kmath/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22) label. \ No newline at end of file diff --git a/kmath-ast/README.md b/kmath-ast/README.md index d85a18e1c..dd9978bee 100644 --- a/kmath-ast/README.md +++ b/kmath-ast/README.md @@ -10,19 +10,8 @@ Extensions to MST API: transformations, dynamic compilation and visualization. ## Artifact: -The Maven coordinates of this project are `space.kscience:kmath-ast:0.4.0-dev-1`. +The Maven coordinates of this project are `space.kscience:kmath-ast:0.4.0-dev-3`. -**Gradle Groovy:** -```groovy -repositories { - maven { url 'https://repo.kotlin.link' } - mavenCentral() -} - -dependencies { - implementation 'space.kscience:kmath-ast:0.4.0-dev-1' -} -``` **Gradle Kotlin DSL:** ```kotlin repositories { @@ -31,7 +20,7 @@ repositories { } dependencies { - implementation("space.kscience:kmath-ast:0.4.0-dev-1") + implementation("space.kscience:kmath-ast:0.4.0-dev-3") } ``` diff --git a/kmath-commons/README.md b/kmath-commons/README.md index 47b61c409..2b5f3146d 100644 --- a/kmath-commons/README.md +++ b/kmath-commons/README.md @@ -6,19 +6,8 @@ Commons math binding for kmath ## Artifact: -The Maven coordinates of this project are `space.kscience:kmath-commons:0.4.0-dev-1`. +The Maven coordinates of this project are `space.kscience:kmath-commons:0.4.0-dev-3`. -**Gradle Groovy:** -```groovy -repositories { - maven { url 'https://repo.kotlin.link' } - mavenCentral() -} - -dependencies { - implementation 'space.kscience:kmath-commons:0.4.0-dev-1' -} -``` **Gradle Kotlin DSL:** ```kotlin repositories { @@ -27,6 +16,6 @@ repositories { } dependencies { - implementation("space.kscience:kmath-commons:0.4.0-dev-1") + implementation("space.kscience:kmath-commons:0.4.0-dev-3") } ``` diff --git a/kmath-complex/README.md b/kmath-complex/README.md index 4e800b7ac..eec989eb3 100644 --- a/kmath-complex/README.md +++ b/kmath-complex/README.md @@ -8,19 +8,8 @@ Complex and hypercomplex number systems in KMath. ## Artifact: -The Maven coordinates of this project are `space.kscience:kmath-complex:0.4.0-dev-1`. +The Maven coordinates of this project are `space.kscience:kmath-complex:0.4.0-dev-3`. -**Gradle Groovy:** -```groovy -repositories { - maven { url 'https://repo.kotlin.link' } - mavenCentral() -} - -dependencies { - implementation 'space.kscience:kmath-complex:0.4.0-dev-1' -} -``` **Gradle Kotlin DSL:** ```kotlin repositories { @@ -29,6 +18,6 @@ repositories { } dependencies { - implementation("space.kscience:kmath-complex:0.4.0-dev-1") + implementation("space.kscience:kmath-complex:0.4.0-dev-3") } ``` diff --git a/kmath-core/README.md b/kmath-core/README.md index b58105d2f..f1f42210b 100644 --- a/kmath-core/README.md +++ b/kmath-core/README.md @@ -11,23 +11,13 @@ objects to the expression by providing a context. Expressions can be used for a performance calculations to code generation. - [domains](src/commonMain/kotlin/space/kscience/kmath/domains) : Domains - [autodiff](src/commonMain/kotlin/space/kscience/kmath/expressions/SimpleAutoDiff.kt) : Automatic differentiation + - [linear.parallel](#) : Parallel implementation for `LinearAlgebra` ## Artifact: -The Maven coordinates of this project are `space.kscience:kmath-core:0.4.0-dev-1`. +The Maven coordinates of this project are `space.kscience:kmath-core:0.4.0-dev-3`. -**Gradle Groovy:** -```groovy -repositories { - maven { url 'https://repo.kotlin.link' } - mavenCentral() -} - -dependencies { - implementation 'space.kscience:kmath-core:0.4.0-dev-1' -} -``` **Gradle Kotlin DSL:** ```kotlin repositories { @@ -36,6 +26,6 @@ repositories { } dependencies { - implementation("space.kscience:kmath-core:0.4.0-dev-1") + implementation("space.kscience:kmath-core:0.4.0-dev-3") } ``` diff --git a/kmath-core/api/kmath-core.api b/kmath-core/api/kmath-core.api index 42d8277bd..0053dde28 100644 --- a/kmath-core/api/kmath-core.api +++ b/kmath-core/api/kmath-core.api @@ -1,3 +1,14 @@ +public abstract interface annotation class space/kscience/kmath/PerformancePitfall : java/lang/annotation/Annotation { + public abstract fun message ()Ljava/lang/String; +} + +public abstract interface annotation class space/kscience/kmath/UnsafeKMathAPI : java/lang/annotation/Annotation { + public abstract fun message ()Ljava/lang/String; +} + +public abstract interface annotation class space/kscience/kmath/UnstableKMathAPI : java/lang/annotation/Annotation { +} + public final class space/kscience/kmath/data/ColumnarDataKt { } @@ -41,17 +52,19 @@ public final class space/kscience/kmath/expressions/DSCompiler { public final fun getSizes ()[[I } -public final class space/kscience/kmath/expressions/DerivationResult { - public fun (Ljava/lang/Object;Ljava/util/Map;Lspace/kscience/kmath/operations/Field;)V +public final class space/kscience/kmath/expressions/DerivationResult : space/kscience/attributes/WithType { + public synthetic fun (Ljava/lang/Object;Lkotlin/reflect/KType;Ljava/util/Map;Lspace/kscience/kmath/operations/Field;Lkotlin/jvm/internal/DefaultConstructorMarker;)V public final fun derivative (Lspace/kscience/kmath/expressions/Symbol;)Ljava/lang/Object; public final fun div ()Ljava/lang/Object; public final fun getContext ()Lspace/kscience/kmath/operations/Field; + public fun getType-V0oMfBY ()Lkotlin/reflect/KType; public final fun getValue ()Ljava/lang/Object; } public final class space/kscience/kmath/expressions/DiffExpressionWithDefault : space/kscience/kmath/expressions/DifferentiableExpression { public fun (Lspace/kscience/kmath/expressions/DifferentiableExpression;Ljava/util/Map;)V public fun derivativeOrNull (Ljava/util/List;)Lspace/kscience/kmath/expressions/Expression; + public fun getType-V0oMfBY ()Lkotlin/reflect/KType; public fun invoke (Ljava/util/Map;)Ljava/lang/Object; } @@ -71,7 +84,7 @@ public final class space/kscience/kmath/expressions/DifferentiableExpressionKt { public final class space/kscience/kmath/expressions/DoubleExpression$Companion { } -public abstract interface class space/kscience/kmath/expressions/Expression { +public abstract interface class space/kscience/kmath/expressions/Expression : space/kscience/attributes/WithType { public abstract fun invoke (Ljava/util/Map;)Ljava/lang/Object; } @@ -80,6 +93,7 @@ public abstract interface class space/kscience/kmath/expressions/ExpressionAlgeb } public final class space/kscience/kmath/expressions/ExpressionKt { + public static final fun Expression-AckJDF4 (Lkotlin/reflect/KType;Lkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/expressions/Expression; public static final fun callByString (Lspace/kscience/kmath/expressions/Expression;[Lkotlin/Pair;)Ljava/lang/Object; public static final fun callBySymbol (Lspace/kscience/kmath/expressions/Expression;[Lkotlin/Pair;)Ljava/lang/Object; public static final fun getBinding (Lspace/kscience/kmath/expressions/ExpressionAlgebra;)Lkotlin/properties/ReadOnlyProperty; @@ -88,6 +102,7 @@ public final class space/kscience/kmath/expressions/ExpressionKt { public final class space/kscience/kmath/expressions/ExpressionWithDefault : space/kscience/kmath/expressions/Expression { public fun (Lspace/kscience/kmath/expressions/Expression;Ljava/util/Map;)V + public fun getType-V0oMfBY ()Lkotlin/reflect/KType; public fun invoke (Ljava/util/Map;)Ljava/lang/Object; } @@ -110,11 +125,12 @@ public abstract class space/kscience/kmath/expressions/FunctionalExpressionAlgeb public synthetic fun const (Ljava/lang/Object;)Ljava/lang/Object; public fun const (Ljava/lang/Object;)Lspace/kscience/kmath/expressions/Expression; public final fun getAlgebra ()Lspace/kscience/kmath/operations/Algebra; + public fun getBufferFactory ()Lspace/kscience/kmath/structures/MutableBufferFactory; public fun unaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function1; } public final class space/kscience/kmath/expressions/FunctionalExpressionAlgebraKt { - public static final fun expression (Lspace/kscience/kmath/operations/DoubleField;Lkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/expressions/Expression; + public static final fun expression (Lspace/kscience/kmath/operations/Float64Field;Lkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/expressions/Expression; public static final fun expressionInExtendedField (Lspace/kscience/kmath/operations/ExtendedField;Lkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/expressions/Expression; public static final fun expressionInField (Lspace/kscience/kmath/operations/Field;Lkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/expressions/Expression; public static final fun expressionInGroup (Lspace/kscience/kmath/operations/Group;Lkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/expressions/Expression; @@ -270,6 +286,7 @@ public final class space/kscience/kmath/expressions/MstExtendedField : space/ksc public fun divide (Lspace/kscience/kmath/expressions/MST;Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST$Binary; public synthetic fun exp (Ljava/lang/Object;)Ljava/lang/Object; public fun exp (Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST$Unary; + public fun getBufferFactory ()Lspace/kscience/kmath/structures/MutableBufferFactory; public synthetic fun getOne ()Ljava/lang/Object; public fun getOne ()Lspace/kscience/kmath/expressions/MST$Numeric; public synthetic fun getZero ()Ljava/lang/Object; @@ -312,6 +329,7 @@ public final class space/kscience/kmath/expressions/MstField : space/kscience/km public fun bindSymbolOrNull (Ljava/lang/String;)Lspace/kscience/kmath/expressions/Symbol; public synthetic fun divide (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; public fun divide (Lspace/kscience/kmath/expressions/MST;Lspace/kscience/kmath/expressions/MST;)Lspace/kscience/kmath/expressions/MST$Binary; + public fun getBufferFactory ()Lspace/kscience/kmath/structures/MutableBufferFactory; public synthetic fun getOne ()Ljava/lang/Object; public fun getOne ()Lspace/kscience/kmath/expressions/MST$Numeric; public synthetic fun getZero ()Ljava/lang/Object; @@ -338,6 +356,7 @@ public final class space/kscience/kmath/expressions/MstGroup : space/kscience/km public fun binaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; public synthetic fun bindSymbolOrNull (Ljava/lang/String;)Ljava/lang/Object; public fun bindSymbolOrNull (Ljava/lang/String;)Lspace/kscience/kmath/expressions/Symbol; + public fun getBufferFactory ()Lspace/kscience/kmath/structures/MutableBufferFactory; public synthetic fun getZero ()Ljava/lang/Object; public fun getZero ()Lspace/kscience/kmath/expressions/MST$Numeric; public synthetic fun minus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; @@ -360,6 +379,7 @@ public final class space/kscience/kmath/expressions/MstNumericAlgebra : space/ks public fun bindSymbol (Ljava/lang/String;)Lspace/kscience/kmath/expressions/Symbol; public synthetic fun bindSymbolOrNull (Ljava/lang/String;)Ljava/lang/Object; public fun bindSymbolOrNull (Ljava/lang/String;)Lspace/kscience/kmath/expressions/Symbol; + public fun getBufferFactory ()Lspace/kscience/kmath/structures/MutableBufferFactory; public synthetic fun number (Ljava/lang/Number;)Ljava/lang/Object; public fun number (Ljava/lang/Number;)Lspace/kscience/kmath/expressions/MST$Numeric; public fun unaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function1; @@ -372,6 +392,7 @@ public final class space/kscience/kmath/expressions/MstRing : space/kscience/kma public fun binaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; public synthetic fun bindSymbolOrNull (Ljava/lang/String;)Ljava/lang/Object; public fun bindSymbolOrNull (Ljava/lang/String;)Lspace/kscience/kmath/expressions/Symbol; + public fun getBufferFactory ()Lspace/kscience/kmath/structures/MutableBufferFactory; public synthetic fun getOne ()Ljava/lang/Object; public fun getOne ()Lspace/kscience/kmath/expressions/MST$Numeric; public synthetic fun getZero ()Ljava/lang/Object; @@ -398,16 +419,16 @@ public final class space/kscience/kmath/expressions/NamedMatrix : space/kscience public fun get (II)Ljava/lang/Object; public final fun get (Lspace/kscience/kmath/expressions/Symbol;Lspace/kscience/kmath/expressions/Symbol;)Ljava/lang/Object; public fun get ([I)Ljava/lang/Object; + public fun getAttributes ()Lspace/kscience/attributes/Attributes; public fun getColNum ()I public fun getColumns ()Ljava/util/List; public fun getDimension ()I - public synthetic fun getFeature (Lkotlin/reflect/KClass;)Ljava/lang/Object; - public fun getFeature (Lkotlin/reflect/KClass;)Lspace/kscience/kmath/nd/StructureFeature; public final fun getIndexer ()Lspace/kscience/kmath/expressions/SymbolIndexer; public fun getIndices ()Lspace/kscience/kmath/nd/ShapeIndexer; public fun getRowNum ()I public fun getRows ()Ljava/util/List; public fun getShape-IIYLAfE ()[I + public fun getType-V0oMfBY ()Lkotlin/reflect/KType; public final fun getValues ()Lspace/kscience/kmath/nd/Structure2D; } @@ -425,6 +446,7 @@ public final class space/kscience/kmath/expressions/SimpleAutoDiffExpression : s public fun derivativeOrNull (Lspace/kscience/kmath/expressions/Symbol;)Lspace/kscience/kmath/expressions/Expression; public final fun getField ()Lspace/kscience/kmath/operations/Field; public final fun getFunction ()Lkotlin/jvm/functions/Function1; + public fun getType-V0oMfBY ()Lkotlin/reflect/KType; public fun invoke (Ljava/util/Map;)Ljava/lang/Object; } @@ -481,7 +503,8 @@ public class space/kscience/kmath/expressions/SimpleAutoDiffField : space/kscien public final fun derive (Ljava/lang/Object;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; public synthetic fun divide (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; public fun divide (Lspace/kscience/kmath/expressions/AutoDiffValue;Lspace/kscience/kmath/expressions/AutoDiffValue;)Lspace/kscience/kmath/expressions/AutoDiffValue; - public final fun getContext ()Lspace/kscience/kmath/operations/Field; + public final fun getAlgebra ()Lspace/kscience/kmath/operations/Field; + public fun getBufferFactory ()Lspace/kscience/kmath/structures/MutableBufferFactory; public final fun getD (Lspace/kscience/kmath/expressions/AutoDiffValue;)Ljava/lang/Object; public synthetic fun getOne ()Ljava/lang/Object; public fun getOne ()Lspace/kscience/kmath/expressions/AutoDiffValue; @@ -572,62 +595,117 @@ public final class space/kscience/kmath/linear/BufferedLinearSpaceKt { public static final fun getLinearSpace (Lspace/kscience/kmath/operations/Ring;)Lspace/kscience/kmath/linear/BufferedLinearSpace; } -public abstract interface class space/kscience/kmath/linear/CholeskyDecompositionFeature : space/kscience/kmath/linear/MatrixFeature { +public abstract interface class space/kscience/kmath/linear/CholeskyDecomposition { public abstract fun getL ()Lspace/kscience/kmath/nd/Structure2D; } -public abstract interface class space/kscience/kmath/linear/DeterminantFeature : space/kscience/kmath/linear/MatrixFeature { - public abstract fun getDeterminant ()Ljava/lang/Object; +public final class space/kscience/kmath/linear/CholeskyDecompositionAttribute : space/kscience/attributes/PolymorphicAttribute, space/kscience/kmath/linear/MatrixAttribute { + public fun ()V } -public abstract interface class space/kscience/kmath/linear/DiagonalFeature : space/kscience/kmath/linear/MatrixFeature { - public static final field Companion Lspace/kscience/kmath/linear/DiagonalFeature$Companion; +public final class space/kscience/kmath/linear/Determinant : space/kscience/attributes/PolymorphicAttribute, space/kscience/kmath/linear/MatrixAttribute { + public synthetic fun (Lkotlin/reflect/KType;Lkotlin/jvm/internal/DefaultConstructorMarker;)V } -public final class space/kscience/kmath/linear/DiagonalFeature$Companion : space/kscience/kmath/linear/DiagonalFeature { -} - -public final class space/kscience/kmath/linear/DoubleLinearSpace : space/kscience/kmath/linear/LinearSpace { - public static final field INSTANCE Lspace/kscience/kmath/linear/DoubleLinearSpace; +public final class space/kscience/kmath/linear/Float64LinearSpace : space/kscience/kmath/linear/LinearSpace { + public static final field INSTANCE Lspace/kscience/kmath/linear/Float64LinearSpace; public fun buildMatrix (IILkotlin/jvm/functions/Function3;)Lspace/kscience/kmath/nd/Structure2D; public synthetic fun buildVector (ILkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/structures/Buffer; - public fun buildVector-CZ9oacQ (ILkotlin/jvm/functions/Function2;)[D - public final fun div-CZ9oacQ (Lspace/kscience/kmath/structures/Buffer;D)[D + public fun buildVector-Vq5tpWc (ILkotlin/jvm/functions/Function2;)[D + public final fun div-Vq5tpWc (Lspace/kscience/kmath/structures/Buffer;D)[D public fun dot (Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; public synthetic fun dot (Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; - public fun dot-CZ9oacQ (Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/structures/Buffer;)[D - public fun getElementAlgebra ()Lspace/kscience/kmath/operations/DoubleField; + public fun dot-Vq5tpWc (Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/structures/Buffer;)[D + public fun getElementAlgebra ()Lspace/kscience/kmath/operations/Float64Field; public synthetic fun getElementAlgebra ()Lspace/kscience/kmath/operations/Ring; public fun minus (Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; public synthetic fun minus (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; - public fun minus-CZ9oacQ (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)[D + public fun minus-Vq5tpWc (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)[D public fun plus (Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; public synthetic fun plus (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; - public fun plus-CZ9oacQ (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)[D + public fun plus-Vq5tpWc (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)[D public synthetic fun times (Ljava/lang/Object;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; public fun times (Lspace/kscience/kmath/nd/Structure2D;D)Lspace/kscience/kmath/nd/Structure2D; public synthetic fun times (Lspace/kscience/kmath/nd/Structure2D;Ljava/lang/Object;)Lspace/kscience/kmath/nd/Structure2D; public synthetic fun times (Lspace/kscience/kmath/structures/Buffer;Ljava/lang/Object;)Lspace/kscience/kmath/structures/Buffer; - public fun times-CZ9oacQ (DLspace/kscience/kmath/structures/Buffer;)[D - public fun times-CZ9oacQ (Lspace/kscience/kmath/structures/Buffer;D)[D + public fun times-Vq5tpWc (DLspace/kscience/kmath/structures/Buffer;)[D + public fun times-Vq5tpWc (Lspace/kscience/kmath/structures/Buffer;D)[D public fun unaryMinus (Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; } -public final class space/kscience/kmath/linear/DoubleLinearSpaceKt { - public static final fun getLinearSpace (Lspace/kscience/kmath/operations/DoubleField;)Lspace/kscience/kmath/linear/DoubleLinearSpace; +public final class space/kscience/kmath/linear/Float64LinearSpaceKt { + public static final fun getLinearSpace (Lspace/kscience/kmath/operations/Float64Field;)Lspace/kscience/kmath/linear/Float64LinearSpace; } -public abstract interface class space/kscience/kmath/linear/InverseMatrixFeature : space/kscience/kmath/linear/MatrixFeature { - public abstract fun getInverse ()Lspace/kscience/kmath/nd/Structure2D; +public final class space/kscience/kmath/linear/Float64ParallelLinearSpace : space/kscience/kmath/linear/LinearSpace { + public static final field INSTANCE Lspace/kscience/kmath/linear/Float64ParallelLinearSpace; + public fun buildMatrix (IILkotlin/jvm/functions/Function3;)Lspace/kscience/kmath/nd/Structure2D; + public synthetic fun buildVector (ILkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/structures/Buffer; + public fun buildVector-Vq5tpWc (ILkotlin/jvm/functions/Function2;)[D + public final fun div-Vq5tpWc (Lspace/kscience/kmath/structures/Buffer;D)[D + public fun dot (Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; + public synthetic fun dot (Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public fun dot-Vq5tpWc (Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/structures/Buffer;)[D + public fun getElementAlgebra ()Lspace/kscience/kmath/operations/Float64Field; + public synthetic fun getElementAlgebra ()Lspace/kscience/kmath/operations/Ring; + public fun minus (Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; + public synthetic fun minus (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public fun minus-Vq5tpWc (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)[D + public fun plus (Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; + public synthetic fun plus (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public fun plus-Vq5tpWc (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun times (Ljava/lang/Object;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public fun times (Lspace/kscience/kmath/nd/Structure2D;D)Lspace/kscience/kmath/nd/Structure2D; + public synthetic fun times (Lspace/kscience/kmath/nd/Structure2D;Ljava/lang/Object;)Lspace/kscience/kmath/nd/Structure2D; + public synthetic fun times (Lspace/kscience/kmath/structures/Buffer;Ljava/lang/Object;)Lspace/kscience/kmath/structures/Buffer; + public fun times-Vq5tpWc (DLspace/kscience/kmath/structures/Buffer;)[D + public fun times-Vq5tpWc (Lspace/kscience/kmath/structures/Buffer;D)[D + public fun unaryMinus (Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; } -public final class space/kscience/kmath/linear/LFeature : space/kscience/kmath/linear/MatrixFeature { - public static final field INSTANCE Lspace/kscience/kmath/linear/LFeature; +public final class space/kscience/kmath/linear/Float64ParallelLinearSpaceKt { + public static final fun getParallel (Lspace/kscience/kmath/linear/Float64LinearSpace;)Lspace/kscience/kmath/linear/Float64ParallelLinearSpace; } -public abstract interface class space/kscience/kmath/linear/LUDecompositionFeature : space/kscience/kmath/linear/MatrixFeature { - public abstract fun getL ()Lspace/kscience/kmath/nd/Structure2D; - public abstract fun getU ()Lspace/kscience/kmath/nd/Structure2D; +public final class space/kscience/kmath/linear/GenericLupDecomposition : space/kscience/kmath/linear/LupDecomposition { + public synthetic fun (Lspace/kscience/kmath/operations/Field;Lspace/kscience/kmath/nd/Structure2D;[IZLkotlin/jvm/internal/DefaultConstructorMarker;)V + public final fun getDeterminant ()Ljava/lang/Object; + public final fun getElementAlgebra ()Lspace/kscience/kmath/operations/Field; + public fun getL ()Lspace/kscience/kmath/nd/Structure2D; + public fun getPivot-M_oXE9g ()[I + public fun getU ()Lspace/kscience/kmath/nd/Structure2D; +} + +public final class space/kscience/kmath/linear/Inverted : space/kscience/attributes/PolymorphicAttribute, space/kscience/kmath/linear/MatrixAttribute { + public fun ()V +} + +public abstract interface class space/kscience/kmath/linear/IsDiagonal : space/kscience/attributes/FlagAttribute, space/kscience/kmath/linear/MatrixAttribute { + public static final field Companion Lspace/kscience/kmath/linear/IsDiagonal$Companion; +} + +public final class space/kscience/kmath/linear/IsDiagonal$Companion : space/kscience/kmath/linear/IsDiagonal { +} + +public final class space/kscience/kmath/linear/IsUnit : space/kscience/kmath/linear/IsDiagonal { + public static final field INSTANCE Lspace/kscience/kmath/linear/IsUnit; +} + +public final class space/kscience/kmath/linear/IsZero : space/kscience/kmath/linear/IsDiagonal { + public static final field INSTANCE Lspace/kscience/kmath/linear/IsZero; +} + +public final class space/kscience/kmath/linear/LUDecomposition { + public fun (Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/nd/Structure2D;)V + public final fun component1 ()Lspace/kscience/kmath/nd/Structure2D; + public final fun component2 ()Lspace/kscience/kmath/nd/Structure2D; + public final fun copy (Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/linear/LUDecomposition; + public static synthetic fun copy$default (Lspace/kscience/kmath/linear/LUDecomposition;Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/nd/Structure2D;ILjava/lang/Object;)Lspace/kscience/kmath/linear/LUDecomposition; + public fun equals (Ljava/lang/Object;)Z + public final fun getL ()Lspace/kscience/kmath/nd/Structure2D; + public final fun getU ()Lspace/kscience/kmath/nd/Structure2D; + public fun hashCode ()I + public fun toString ()Ljava/lang/String; } public abstract interface class space/kscience/kmath/linear/LinearSolver { @@ -636,13 +714,15 @@ public abstract interface class space/kscience/kmath/linear/LinearSolver { public fun solve (Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; } -public abstract interface class space/kscience/kmath/linear/LinearSpace { +public abstract interface class space/kscience/kmath/linear/LinearSpace : space/kscience/kmath/linear/MatrixScope { public static final field Companion Lspace/kscience/kmath/linear/LinearSpace$Companion; public abstract fun buildMatrix (IILkotlin/jvm/functions/Function3;)Lspace/kscience/kmath/nd/Structure2D; public abstract fun buildVector (ILkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/structures/Buffer; + public fun computeAttribute (Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/nd/StructureAttribute;)Ljava/lang/Object; public fun dot (Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; public fun dot (Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; public abstract fun getElementAlgebra ()Lspace/kscience/kmath/operations/Ring; + public fun getType-V0oMfBY ()Lkotlin/reflect/KType; public fun minus (Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; public fun minus (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; public fun plus (Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; @@ -665,39 +745,54 @@ public final class space/kscience/kmath/linear/LinearSpaceKt { public static final fun invoke (Lspace/kscience/kmath/linear/LinearSpace;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; } -public final class space/kscience/kmath/linear/LupDecomposition : space/kscience/kmath/linear/DeterminantFeature, space/kscience/kmath/linear/LupDecompositionFeature { - public fun (Lspace/kscience/kmath/linear/LinearSpace;Lspace/kscience/kmath/operations/Field;Lspace/kscience/kmath/nd/Structure2D;[IZ)V - public final fun getContext ()Lspace/kscience/kmath/linear/LinearSpace; - public fun getDeterminant ()Ljava/lang/Object; - public final fun getElementContext ()Lspace/kscience/kmath/operations/Field; - public fun getL ()Lspace/kscience/kmath/nd/Structure2D; - public final fun getLu ()Lspace/kscience/kmath/nd/Structure2D; - public fun getP ()Lspace/kscience/kmath/nd/Structure2D; - public final fun getPivot ()[I - public fun getU ()Lspace/kscience/kmath/nd/Structure2D; +public final class space/kscience/kmath/linear/LowerTriangular : space/kscience/attributes/FlagAttribute, space/kscience/kmath/linear/MatrixAttribute { + public static final field INSTANCE Lspace/kscience/kmath/linear/LowerTriangular; } -public abstract interface class space/kscience/kmath/linear/LupDecompositionFeature : space/kscience/kmath/linear/MatrixFeature { +public final class space/kscience/kmath/linear/LuDecompositionAttribute : space/kscience/attributes/PolymorphicAttribute, space/kscience/kmath/linear/MatrixAttribute { + public fun ()V +} + +public abstract interface class space/kscience/kmath/linear/LupDecomposition { public abstract fun getL ()Lspace/kscience/kmath/nd/Structure2D; - public abstract fun getP ()Lspace/kscience/kmath/nd/Structure2D; + public abstract fun getPivot-M_oXE9g ()[I public abstract fun getU ()Lspace/kscience/kmath/nd/Structure2D; } +public final class space/kscience/kmath/linear/LupDecompositionAttribute : space/kscience/attributes/PolymorphicAttribute, space/kscience/kmath/linear/MatrixAttribute { + public fun ()V +} + public final class space/kscience/kmath/linear/LupDecompositionKt { public static final fun abs (Lspace/kscience/kmath/linear/LinearSpace;Ljava/lang/Comparable;)Ljava/lang/Comparable; - public static final fun lup (Lspace/kscience/kmath/linear/LinearSpace;Lspace/kscience/kmath/nd/Structure2D;D)Lspace/kscience/kmath/linear/LupDecomposition; - public static final fun lup (Lspace/kscience/kmath/linear/LinearSpace;Lspace/kscience/kmath/structures/MutableBufferFactory;Lspace/kscience/kmath/nd/Structure2D;Lkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/linear/LupDecomposition; - public static synthetic fun lup$default (Lspace/kscience/kmath/linear/LinearSpace;Lspace/kscience/kmath/nd/Structure2D;DILjava/lang/Object;)Lspace/kscience/kmath/linear/LupDecomposition; + public static final fun getLUP (Lspace/kscience/kmath/linear/MatrixScope;)Lspace/kscience/kmath/linear/LupDecompositionAttribute; + public static final fun lup (Lspace/kscience/kmath/operations/Field;Lspace/kscience/kmath/nd/Structure2D;D)Lspace/kscience/kmath/linear/GenericLupDecomposition; + public static final fun lup (Lspace/kscience/kmath/operations/Field;Lspace/kscience/kmath/nd/Structure2D;Lkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/linear/GenericLupDecomposition; + public static synthetic fun lup$default (Lspace/kscience/kmath/operations/Field;Lspace/kscience/kmath/nd/Structure2D;DILjava/lang/Object;)Lspace/kscience/kmath/linear/GenericLupDecomposition; public static final fun lupSolver (Lspace/kscience/kmath/linear/LinearSpace;D)Lspace/kscience/kmath/linear/LinearSolver; - public static final fun lupSolver (Lspace/kscience/kmath/linear/LinearSpace;Lspace/kscience/kmath/structures/MutableBufferFactory;Lkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/linear/LinearSolver; + public static final fun lupSolver (Lspace/kscience/kmath/linear/LinearSpace;Lkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/linear/LinearSolver; public static synthetic fun lupSolver$default (Lspace/kscience/kmath/linear/LinearSpace;DILjava/lang/Object;)Lspace/kscience/kmath/linear/LinearSolver; + public static final fun pivotMatrix (Lspace/kscience/kmath/linear/LupDecomposition;Lspace/kscience/kmath/linear/LinearSpace;)Lspace/kscience/kmath/nd/Structure2D; } -public final class space/kscience/kmath/linear/MatrixBuilder { +public abstract interface class space/kscience/kmath/linear/MatrixAttribute : space/kscience/kmath/nd/StructureAttribute { +} + +public final class space/kscience/kmath/linear/MatrixAttributesKt { + public static final fun getCholesky (Lspace/kscience/kmath/linear/MatrixScope;)Lspace/kscience/kmath/linear/CholeskyDecompositionAttribute; + public static final fun getDeterminant (Lspace/kscience/kmath/linear/MatrixScope;)Lspace/kscience/kmath/linear/Determinant; + public static final fun getInverted (Lspace/kscience/kmath/linear/MatrixScope;)Lspace/kscience/kmath/linear/Inverted; + public static final fun getLU (Lspace/kscience/kmath/linear/MatrixScope;)Lspace/kscience/kmath/linear/LuDecompositionAttribute; + public static final fun getQR (Lspace/kscience/kmath/linear/MatrixScope;)Lspace/kscience/kmath/linear/QRDecompositionAttribute; + public static final fun getSVD (Lspace/kscience/kmath/linear/MatrixScope;)Lspace/kscience/kmath/linear/SVDAttribute; +} + +public final class space/kscience/kmath/linear/MatrixBuilder : space/kscience/attributes/WithType { public fun (Lspace/kscience/kmath/linear/LinearSpace;II)V public final fun getColumns ()I public final fun getLinearSpace ()Lspace/kscience/kmath/linear/LinearSpace; public final fun getRows ()I + public fun getType-V0oMfBY ()Lkotlin/reflect/KType; public final fun invoke ([Ljava/lang/Object;)Lspace/kscience/kmath/nd/Structure2D; } @@ -709,88 +804,95 @@ public final class space/kscience/kmath/linear/MatrixBuilderKt { public static final fun symmetric (Lspace/kscience/kmath/linear/MatrixBuilder;Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/Structure2D; } -public abstract interface class space/kscience/kmath/linear/MatrixFeature : space/kscience/kmath/nd/StructureFeature { -} - -public final class space/kscience/kmath/linear/MatrixFeaturesKt { - public static final fun DeterminantFeature (Ljava/lang/Object;)Lspace/kscience/kmath/linear/DeterminantFeature; +public abstract interface class space/kscience/kmath/linear/MatrixScope : space/kscience/attributes/AttributeScope, space/kscience/attributes/WithType { } public final class space/kscience/kmath/linear/MatrixWrapper : space/kscience/kmath/nd/Structure2D { public fun elements ()Lkotlin/sequences/Sequence; public fun get (II)Ljava/lang/Object; public fun get ([I)Ljava/lang/Object; + public fun getAttributes ()Lspace/kscience/attributes/Attributes; public fun getColNum ()I public fun getColumns ()Ljava/util/List; public fun getDimension ()I - public synthetic fun getFeature (Lkotlin/reflect/KClass;)Ljava/lang/Object; - public fun getFeature (Lkotlin/reflect/KClass;)Lspace/kscience/kmath/nd/StructureFeature; - public final fun getFeatures-En6fw3w ()Ljava/util/Map; public fun getIndices ()Lspace/kscience/kmath/nd/ShapeIndexer; public final fun getOrigin ()Lspace/kscience/kmath/nd/Structure2D; public fun getRowNum ()I public fun getRows ()Ljava/util/List; public fun getShape-IIYLAfE ()[I + public fun getType-V0oMfBY ()Lkotlin/reflect/KType; public fun toString ()Ljava/lang/String; } public final class space/kscience/kmath/linear/MatrixWrapperKt { - public static final fun one (Lspace/kscience/kmath/linear/LinearSpace;II)Lspace/kscience/kmath/nd/Structure2D; - public static final fun plus (Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/linear/MatrixFeature;)Lspace/kscience/kmath/linear/MatrixWrapper; - public static final fun transpose (Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; - public static final fun withFeature (Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/kmath/linear/MatrixFeature;)Lspace/kscience/kmath/linear/MatrixWrapper; - public static final fun withFeatures (Lspace/kscience/kmath/nd/Structure2D;Ljava/lang/Iterable;)Lspace/kscience/kmath/linear/MatrixWrapper; - public static final fun zero (Lspace/kscience/kmath/linear/LinearSpace;II)Lspace/kscience/kmath/nd/Structure2D; + public static final fun modifyAttributes (Lspace/kscience/kmath/nd/Structure2D;Lkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/linear/MatrixWrapper; + public static final fun one (Lspace/kscience/kmath/linear/LinearSpace;II)Lspace/kscience/kmath/linear/MatrixWrapper; + public static final fun withAttribute (Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/attributes/Attribute;)Lspace/kscience/kmath/linear/MatrixWrapper; + public static final fun withAttribute (Lspace/kscience/kmath/nd/Structure2D;Lspace/kscience/attributes/Attribute;Ljava/lang/Object;)Lspace/kscience/kmath/linear/MatrixWrapper; + public static final fun zero (Lspace/kscience/kmath/linear/LinearSpace;II)Lspace/kscience/kmath/linear/MatrixWrapper; } -public final class space/kscience/kmath/linear/OrthogonalFeature : space/kscience/kmath/linear/MatrixFeature { - public static final field INSTANCE Lspace/kscience/kmath/linear/OrthogonalFeature; +public final class space/kscience/kmath/linear/OrthogonalAttribute : space/kscience/attributes/FlagAttribute, space/kscience/kmath/linear/MatrixAttribute { + public static final field INSTANCE Lspace/kscience/kmath/linear/OrthogonalAttribute; } -public abstract interface class space/kscience/kmath/linear/QRDecompositionFeature : space/kscience/kmath/linear/MatrixFeature { +public abstract interface class space/kscience/kmath/linear/QRDecomposition { public abstract fun getQ ()Lspace/kscience/kmath/nd/Structure2D; public abstract fun getR ()Lspace/kscience/kmath/nd/Structure2D; } -public abstract interface class space/kscience/kmath/linear/SingularValueDecompositionFeature : space/kscience/kmath/linear/MatrixFeature { +public final class space/kscience/kmath/linear/QRDecompositionAttribute : space/kscience/attributes/PolymorphicAttribute, space/kscience/kmath/linear/MatrixAttribute { + public fun ()V +} + +public final class space/kscience/kmath/linear/SVDAttribute : space/kscience/attributes/PolymorphicAttribute, space/kscience/kmath/linear/MatrixAttribute { + public fun ()V +} + +public abstract interface class space/kscience/kmath/linear/SingularValueDecomposition { public abstract fun getS ()Lspace/kscience/kmath/nd/Structure2D; public abstract fun getSingularValues ()Lspace/kscience/kmath/structures/Buffer; public abstract fun getU ()Lspace/kscience/kmath/nd/Structure2D; public abstract fun getV ()Lspace/kscience/kmath/nd/Structure2D; } -public final class space/kscience/kmath/linear/SymmetricMatrixFeature : space/kscience/kmath/linear/MatrixFeature { - public static final field INSTANCE Lspace/kscience/kmath/linear/SymmetricMatrixFeature; +public final class space/kscience/kmath/linear/Symmetric : space/kscience/attributes/FlagAttribute, space/kscience/kmath/linear/MatrixAttribute { + public static final field INSTANCE Lspace/kscience/kmath/linear/Symmetric; } -public final class space/kscience/kmath/linear/TransposedFeature : space/kscience/kmath/linear/MatrixFeature { +public final class space/kscience/kmath/linear/TransposedKt { + public static final fun transposed (Lspace/kscience/kmath/nd/Structure2D;)Lspace/kscience/kmath/nd/Structure2D; +} + +public final class space/kscience/kmath/linear/TransposedMatrix : space/kscience/kmath/nd/Structure2D { public fun (Lspace/kscience/kmath/nd/Structure2D;)V - public final fun getOriginal ()Lspace/kscience/kmath/nd/Structure2D; + public fun get (II)Ljava/lang/Object; + public fun getAttributes ()Lspace/kscience/attributes/Attributes; + public fun getColNum ()I + public final fun getOrigin ()Lspace/kscience/kmath/nd/Structure2D; + public fun getRowNum ()I + public fun getType-V0oMfBY ()Lkotlin/reflect/KType; } -public final class space/kscience/kmath/linear/UFeature : space/kscience/kmath/linear/MatrixFeature { - public static final field INSTANCE Lspace/kscience/kmath/linear/UFeature; -} - -public final class space/kscience/kmath/linear/UnitFeature : space/kscience/kmath/linear/DiagonalFeature { - public static final field INSTANCE Lspace/kscience/kmath/linear/UnitFeature; +public final class space/kscience/kmath/linear/UpperTriangular : space/kscience/attributes/FlagAttribute, space/kscience/kmath/linear/MatrixAttribute { + public static final field INSTANCE Lspace/kscience/kmath/linear/UpperTriangular; } public final class space/kscience/kmath/linear/VirtualMatrix : space/kscience/kmath/nd/Structure2D { - public fun (IILkotlin/jvm/functions/Function2;)V + public synthetic fun (Lkotlin/reflect/KType;IILspace/kscience/attributes/Attributes;Lkotlin/jvm/functions/Function2;ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public synthetic fun (Lkotlin/reflect/KType;IILspace/kscience/attributes/Attributes;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/internal/DefaultConstructorMarker;)V public fun get (II)Ljava/lang/Object; + public fun getAttributes ()Lspace/kscience/attributes/Attributes; public fun getColNum ()I public final fun getGenerator ()Lkotlin/jvm/functions/Function2; public fun getRowNum ()I public fun getShape-IIYLAfE ()[I + public fun getType-V0oMfBY ()Lkotlin/reflect/KType; } public final class space/kscience/kmath/linear/VirtualMatrixKt { - public static final fun virtual (Lspace/kscience/kmath/linear/MatrixBuilder;Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/linear/VirtualMatrix; -} - -public final class space/kscience/kmath/linear/ZeroFeature : space/kscience/kmath/linear/DiagonalFeature { - public static final field INSTANCE Lspace/kscience/kmath/linear/ZeroFeature; + public static final fun virtual (Lspace/kscience/kmath/linear/MatrixBuilder;Lspace/kscience/attributes/Attributes;Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/linear/VirtualMatrix; + public static synthetic fun virtual$default (Lspace/kscience/kmath/linear/MatrixBuilder;Lspace/kscience/attributes/Attributes;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)Lspace/kscience/kmath/linear/VirtualMatrix; } public final class space/kscience/kmath/misc/CollectionsKt { @@ -818,42 +920,6 @@ public final class space/kscience/kmath/misc/CumulativeKt { public static final fun cumulativeSumOfLong (Lkotlin/sequences/Sequence;)Lkotlin/sequences/Sequence; } -public abstract interface class space/kscience/kmath/misc/Feature { - public fun getKey ()Lkotlin/reflect/KClass; -} - -public final class space/kscience/kmath/misc/FeatureSet : space/kscience/kmath/misc/Featured { - public static final field Companion Lspace/kscience/kmath/misc/FeatureSet$Companion; - public static final synthetic fun box-impl (Ljava/util/Map;)Lspace/kscience/kmath/misc/FeatureSet; - public fun equals (Ljava/lang/Object;)Z - public static fun equals-impl (Ljava/util/Map;Ljava/lang/Object;)Z - public static final fun equals-impl0 (Ljava/util/Map;Ljava/util/Map;)Z - public synthetic fun getFeature (Lkotlin/reflect/KClass;)Ljava/lang/Object; - public fun getFeature (Lkotlin/reflect/KClass;)Lspace/kscience/kmath/misc/Feature; - public static fun getFeature-impl (Ljava/util/Map;Lkotlin/reflect/KClass;)Lspace/kscience/kmath/misc/Feature; - public final fun getFeatures ()Ljava/util/Map; - public fun hashCode ()I - public static fun hashCode-impl (Ljava/util/Map;)I - public static final fun iterator-impl (Ljava/util/Map;)Ljava/util/Iterator; - public fun toString ()Ljava/lang/String; - public static fun toString-impl (Ljava/util/Map;)Ljava/lang/String; - public final synthetic fun unbox-impl ()Ljava/util/Map; - public static final fun with-JVE9-Rk (Ljava/util/Map;Ljava/lang/Iterable;)Ljava/util/Map; - public static final fun with-JVE9-Rk (Ljava/util/Map;[Lspace/kscience/kmath/misc/Feature;)Ljava/util/Map; - public static final fun with-YU1a0hQ (Ljava/util/Map;Ljava/util/Map;)Ljava/util/Map; - public static final fun with-h58Sd8I (Ljava/util/Map;Lspace/kscience/kmath/misc/Feature;Lkotlin/reflect/KClass;)Ljava/util/Map; - public static synthetic fun with-h58Sd8I$default (Ljava/util/Map;Lspace/kscience/kmath/misc/Feature;Lkotlin/reflect/KClass;ILjava/lang/Object;)Ljava/util/Map; -} - -public final class space/kscience/kmath/misc/FeatureSet$Companion { - public final fun of-JVE9-Rk (Ljava/lang/Iterable;)Ljava/util/Map; - public final fun of-JVE9-Rk ([Lspace/kscience/kmath/misc/Feature;)Ljava/util/Map; -} - -public abstract interface class space/kscience/kmath/misc/Featured { - public abstract fun getFeature (Lkotlin/reflect/KClass;)Ljava/lang/Object; -} - public abstract interface class space/kscience/kmath/misc/Loggable { public static final field Companion Lspace/kscience/kmath/misc/Loggable$Companion; public static final field INFO Ljava/lang/String; @@ -879,6 +945,7 @@ public final class space/kscience/kmath/misc/SortingKt { public static final fun sortedBy (Lspace/kscience/kmath/structures/Buffer;Lkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/structures/Buffer; public static final fun sortedByDescending (Lspace/kscience/kmath/structures/Buffer;Lkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/structures/Buffer; public static final fun sortedDescending (Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public static final fun sortedWith (Lspace/kscience/kmath/structures/Buffer;Ljava/util/Comparator;)Lspace/kscience/kmath/structures/Buffer; } public abstract interface class space/kscience/kmath/nd/AlgebraND : space/kscience/kmath/operations/Algebra { @@ -887,7 +954,8 @@ public abstract interface class space/kscience/kmath/nd/AlgebraND : space/kscien public fun invoke (Lkotlin/jvm/functions/Function1;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; public 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/StructureND; - public abstract fun structureND-qL90JFI ([ILkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/StructureND; + public abstract fun mutableStructureND-qL90JFI ([ILkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/MutableStructureND; + public fun structureND-qL90JFI ([ILkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/StructureND; public fun zip (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;Lkotlin/jvm/functions/Function3;)Lspace/kscience/kmath/nd/StructureND; } @@ -895,6 +963,7 @@ public final class space/kscience/kmath/nd/AlgebraND$Companion { } public final class space/kscience/kmath/nd/AlgebraNDExtentionsKt { + public static final fun mutableStructureND (Lspace/kscience/kmath/nd/AlgebraND;I[ILkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/MutableStructureND; public static final fun one-waz_sdI (Lspace/kscience/kmath/nd/AlgebraND;[I)Lspace/kscience/kmath/nd/StructureND; public static final fun oneVarArg (Lspace/kscience/kmath/nd/AlgebraND;I[I)Lspace/kscience/kmath/nd/StructureND; public static final fun structureND (Lspace/kscience/kmath/nd/AlgebraND;I[ILkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/StructureND; @@ -911,6 +980,8 @@ public abstract interface class space/kscience/kmath/nd/BufferAlgebraND : space/ 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/BufferND; public synthetic fun mapIndexed (Lspace/kscience/kmath/nd/StructureND;Lkotlin/jvm/functions/Function3;)Lspace/kscience/kmath/nd/StructureND; + public fun mutableStructureND-qL90JFI ([ILkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/MutableBufferND; + public synthetic fun mutableStructureND-qL90JFI ([ILkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/MutableStructureND; public fun structureND-qL90JFI ([ILkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/BufferND; public synthetic fun structureND-qL90JFI ([ILkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/StructureND; public fun toBufferND (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/BufferND; @@ -927,6 +998,7 @@ public final class space/kscience/kmath/nd/BufferAlgebraNDKt { public static final fun getNd (Lspace/kscience/kmath/operations/BufferAlgebra;)Lspace/kscience/kmath/nd/BufferedGroupNDOps; public static final fun getNd (Lspace/kscience/kmath/operations/BufferAlgebra;)Lspace/kscience/kmath/nd/BufferedRingOpsND; public static final fun mapInline (Lspace/kscience/kmath/nd/BufferAlgebraND;Lspace/kscience/kmath/nd/BufferND;Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/BufferND; + public static final fun mutableStructureND (Lspace/kscience/kmath/nd/BufferAlgebraND;[ILkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/MutableBufferND; public static final fun structureND (Lspace/kscience/kmath/nd/BufferAlgebraND;Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/BufferND; public static final fun structureND (Lspace/kscience/kmath/nd/BufferAlgebraND;[ILkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/BufferND; } @@ -937,16 +1009,10 @@ public class space/kscience/kmath/nd/BufferND : space/kscience/kmath/nd/Structur public fun getBuffer ()Lspace/kscience/kmath/structures/Buffer; public fun getIndices ()Lspace/kscience/kmath/nd/ShapeIndexer; public fun getShape-IIYLAfE ()[I + public fun getType-V0oMfBY ()Lkotlin/reflect/KType; public fun toString ()Ljava/lang/String; } -public final class space/kscience/kmath/nd/BufferNDKt { - public static final fun BufferND-bYNkpeI ([ILspace/kscience/kmath/structures/BufferFactory;Lkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/nd/BufferND; - public static synthetic fun BufferND-bYNkpeI$default ([ILspace/kscience/kmath/structures/BufferFactory;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lspace/kscience/kmath/nd/BufferND; - public static final fun MutableBufferND-bYNkpeI ([ILspace/kscience/kmath/structures/MutableBufferFactory;Lkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/nd/MutableBufferND; - public static synthetic fun MutableBufferND-bYNkpeI$default ([ILspace/kscience/kmath/structures/MutableBufferFactory;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lspace/kscience/kmath/nd/MutableBufferND; -} - public class space/kscience/kmath/nd/BufferedFieldOpsND : space/kscience/kmath/nd/BufferedRingOpsND, space/kscience/kmath/nd/FieldOpsND { public fun (Lspace/kscience/kmath/operations/BufferAlgebra;Lkotlin/jvm/functions/Function1;)V public synthetic fun (Lspace/kscience/kmath/operations/BufferAlgebra;Lkotlin/jvm/functions/Function1;ILkotlin/jvm/internal/DefaultConstructorMarker;)V @@ -961,6 +1027,7 @@ public class space/kscience/kmath/nd/BufferedGroupNDOps : space/kscience/kmath/n public synthetic fun (Lspace/kscience/kmath/operations/BufferAlgebra;Lkotlin/jvm/functions/Function1;ILkotlin/jvm/internal/DefaultConstructorMarker;)V public fun getBufferAlgebra ()Lspace/kscience/kmath/operations/BufferAlgebra; public fun getIndexerBuilder ()Lkotlin/jvm/functions/Function1; + public fun getType-V0oMfBY ()Lkotlin/reflect/KType; public synthetic fun unaryMinus (Ljava/lang/Object;)Ljava/lang/Object; public fun unaryMinus (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; } @@ -983,137 +1050,6 @@ public final class space/kscience/kmath/nd/ColumnStrides : space/kscience/kmath/ public final class space/kscience/kmath/nd/ColumnStrides$Companion { } -public final class space/kscience/kmath/nd/DoubleBufferND : space/kscience/kmath/nd/MutableBufferND, space/kscience/kmath/nd/MutableStructureNDOfDouble { - public synthetic fun (Lspace/kscience/kmath/nd/ShapeIndexer;[DLkotlin/jvm/internal/DefaultConstructorMarker;)V - public synthetic fun getBuffer ()Lspace/kscience/kmath/structures/Buffer; - public synthetic fun getBuffer ()Lspace/kscience/kmath/structures/MutableBuffer; - public fun getBuffer-Dv3HvWU ()[D - public fun getDouble ([I)D - public fun setDouble ([ID)V -} - -public final class space/kscience/kmath/nd/DoubleFieldND : space/kscience/kmath/nd/DoubleFieldOpsND, space/kscience/kmath/nd/FieldND, space/kscience/kmath/operations/ExtendedField, space/kscience/kmath/operations/NumbersAddOps { - public synthetic fun ([ILkotlin/jvm/internal/DefaultConstructorMarker;)V - public synthetic fun acosh (Ljava/lang/Object;)Ljava/lang/Object; - public fun acosh (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/DoubleBufferND; - public synthetic fun asinh (Ljava/lang/Object;)Ljava/lang/Object; - public fun asinh (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/DoubleBufferND; - public synthetic fun atanh (Ljava/lang/Object;)Ljava/lang/Object; - public fun atanh (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/DoubleBufferND; - public synthetic fun cosh (Ljava/lang/Object;)Ljava/lang/Object; - public fun cosh (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/DoubleBufferND; - public fun getShape-IIYLAfE ()[I - public synthetic fun number (Ljava/lang/Number;)Ljava/lang/Object; - public fun number (Ljava/lang/Number;)Lspace/kscience/kmath/nd/DoubleBufferND; - public synthetic fun power (Ljava/lang/Object;I)Ljava/lang/Object; - public synthetic fun power (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; - public fun power (Lspace/kscience/kmath/nd/StructureND;I)Lspace/kscience/kmath/nd/DoubleBufferND; - public fun power (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Number;)Lspace/kscience/kmath/nd/DoubleBufferND; - public synthetic fun power (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Number;)Lspace/kscience/kmath/nd/StructureND; - public synthetic fun power-Qn1smSk (Ljava/lang/Object;I)Ljava/lang/Object; - public fun power-Qn1smSk (Lspace/kscience/kmath/nd/StructureND;I)Lspace/kscience/kmath/nd/DoubleBufferND; - public synthetic fun sinh (Ljava/lang/Object;)Ljava/lang/Object; - public fun sinh (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/DoubleBufferND; - public synthetic fun tanh (Ljava/lang/Object;)Ljava/lang/Object; - public fun tanh (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/DoubleBufferND; -} - -public final class space/kscience/kmath/nd/DoubleFieldNDKt { - public static final fun getNdAlgebra (Lspace/kscience/kmath/operations/DoubleField;)Lspace/kscience/kmath/nd/DoubleFieldOpsND; - public static final fun ndAlgebra (Lspace/kscience/kmath/operations/DoubleField;[I)Lspace/kscience/kmath/nd/DoubleFieldND; - public static final fun ndAlgebra-waz_sdI (Lspace/kscience/kmath/operations/DoubleField;[I)Lspace/kscience/kmath/nd/DoubleFieldND; -} - -public abstract class space/kscience/kmath/nd/DoubleFieldOpsND : space/kscience/kmath/nd/BufferedFieldOpsND, space/kscience/kmath/operations/ExtendedFieldOps, space/kscience/kmath/operations/ScaleOperations { - public static final field Companion Lspace/kscience/kmath/nd/DoubleFieldOpsND$Companion; - public synthetic fun acos (Ljava/lang/Object;)Ljava/lang/Object; - public fun acos (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/DoubleBufferND; - public synthetic fun acosh (Ljava/lang/Object;)Ljava/lang/Object; - public fun acosh (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/DoubleBufferND; - public synthetic fun add (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun add (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/DoubleBufferND; - public synthetic fun add (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; - public synthetic fun asin (Ljava/lang/Object;)Ljava/lang/Object; - public fun asin (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/DoubleBufferND; - public synthetic fun asinh (Ljava/lang/Object;)Ljava/lang/Object; - public fun asinh (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/DoubleBufferND; - public synthetic fun atan (Ljava/lang/Object;)Ljava/lang/Object; - public fun atan (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/DoubleBufferND; - public synthetic fun atanh (Ljava/lang/Object;)Ljava/lang/Object; - public fun atanh (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/DoubleBufferND; - public synthetic fun cos (Ljava/lang/Object;)Ljava/lang/Object; - public fun cos (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/DoubleBufferND; - public synthetic fun cosh (Ljava/lang/Object;)Ljava/lang/Object; - public fun cosh (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/DoubleBufferND; - public fun div (DLspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/DoubleBufferND; - 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 synthetic fun div (Ljava/lang/Object;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; - public fun div (Lspace/kscience/kmath/nd/StructureND;D)Lspace/kscience/kmath/nd/DoubleBufferND; - public fun div (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Number;)Lspace/kscience/kmath/nd/DoubleBufferND; - public synthetic fun div (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Object;)Lspace/kscience/kmath/nd/StructureND; - public fun div (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/DoubleBufferND; - public synthetic fun divide (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun divide (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/DoubleBufferND; - public synthetic fun divide (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; - public synthetic fun exp (Ljava/lang/Object;)Ljava/lang/Object; - public fun exp (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/DoubleBufferND; - public synthetic fun ln (Ljava/lang/Object;)Ljava/lang/Object; - public fun ln (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/DoubleBufferND; - public fun map (Lspace/kscience/kmath/nd/StructureND;Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/BufferND; - public synthetic fun map (Lspace/kscience/kmath/nd/StructureND;Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/StructureND; - protected final fun mapInline (Lspace/kscience/kmath/nd/DoubleBufferND;Lkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/nd/DoubleBufferND; - public fun minus (DLspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; - public synthetic fun minus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public synthetic fun minus (Ljava/lang/Object;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; - public fun minus (Lspace/kscience/kmath/nd/StructureND;D)Lspace/kscience/kmath/nd/StructureND; - public synthetic fun minus (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Object;)Lspace/kscience/kmath/nd/StructureND; - public fun minus (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/DoubleBufferND; - public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun multiply (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/DoubleBufferND; - public synthetic fun multiply (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; - public fun plus (DLspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; - public synthetic fun plus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public synthetic fun plus (Ljava/lang/Object;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; - public fun plus (Lspace/kscience/kmath/nd/StructureND;D)Lspace/kscience/kmath/nd/DoubleBufferND; - public synthetic fun plus (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Object;)Lspace/kscience/kmath/nd/StructureND; - public fun plus (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/DoubleBufferND; - 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/StructureND; - public synthetic fun scale (Ljava/lang/Object;D)Ljava/lang/Object; - public fun scale (Lspace/kscience/kmath/nd/StructureND;D)Lspace/kscience/kmath/nd/DoubleBufferND; - public synthetic 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/DoubleBufferND; - public synthetic fun sinh (Ljava/lang/Object;)Ljava/lang/Object; - public fun sinh (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/DoubleBufferND; - public synthetic fun structureND-qL90JFI ([ILkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/BufferND; - public fun structureND-qL90JFI ([ILkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/DoubleBufferND; - public synthetic fun structureND-qL90JFI ([ILkotlin/jvm/functions/Function2;)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/DoubleBufferND; - public synthetic fun tanh (Ljava/lang/Object;)Ljava/lang/Object; - public fun tanh (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/DoubleBufferND; - public synthetic fun times (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; - public fun times (Ljava/lang/Number;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/DoubleBufferND; - 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/nd/StructureND;Ljava/lang/Number;)Lspace/kscience/kmath/nd/DoubleBufferND; - public fun times (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/DoubleBufferND; - public synthetic fun toBufferND (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/BufferND; - public fun toBufferND (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/DoubleBufferND; - public synthetic fun unaryMinus (Ljava/lang/Object;)Ljava/lang/Object; - public fun unaryMinus (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/DoubleBufferND; - public synthetic fun unaryMinus (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; - public synthetic fun unaryPlus (Ljava/lang/Object;)Ljava/lang/Object; - public fun unaryPlus (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/DoubleBufferND; - public fun zip (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;Lkotlin/jvm/functions/Function3;)Lspace/kscience/kmath/nd/BufferND; - public synthetic fun zip (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;Lkotlin/jvm/functions/Function3;)Lspace/kscience/kmath/nd/StructureND; -} - -public final class space/kscience/kmath/nd/DoubleFieldOpsND$Companion : space/kscience/kmath/nd/DoubleFieldOpsND { -} - public abstract interface class space/kscience/kmath/nd/FieldND : space/kscience/kmath/nd/FieldOpsND, space/kscience/kmath/nd/RingND, space/kscience/kmath/nd/WithShape, space/kscience/kmath/operations/Field { public synthetic fun getOne ()Ljava/lang/Object; public fun getOne ()Lspace/kscience/kmath/nd/StructureND; @@ -1128,6 +1064,138 @@ public abstract interface class space/kscience/kmath/nd/FieldOpsND : space/kscie public fun scale (Lspace/kscience/kmath/nd/StructureND;D)Lspace/kscience/kmath/nd/StructureND; } +public abstract class space/kscience/kmath/nd/Floa64FieldOpsND : space/kscience/kmath/nd/BufferedFieldOpsND, space/kscience/kmath/operations/ExtendedFieldOps, space/kscience/kmath/operations/ScaleOperations { + public static final field Companion Lspace/kscience/kmath/nd/Floa64FieldOpsND$Companion; + public synthetic fun acos (Ljava/lang/Object;)Ljava/lang/Object; + public fun acos (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/Float64BufferND; + public synthetic fun acosh (Ljava/lang/Object;)Ljava/lang/Object; + public fun acosh (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/Float64BufferND; + public synthetic fun add (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun add (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/Float64BufferND; + public synthetic fun add (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public synthetic fun asin (Ljava/lang/Object;)Ljava/lang/Object; + public fun asin (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/Float64BufferND; + public synthetic fun asinh (Ljava/lang/Object;)Ljava/lang/Object; + public fun asinh (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/Float64BufferND; + public synthetic fun atan (Ljava/lang/Object;)Ljava/lang/Object; + public fun atan (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/Float64BufferND; + public synthetic fun atanh (Ljava/lang/Object;)Ljava/lang/Object; + public fun atanh (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/Float64BufferND; + public synthetic fun cos (Ljava/lang/Object;)Ljava/lang/Object; + public fun cos (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/Float64BufferND; + public synthetic fun cosh (Ljava/lang/Object;)Ljava/lang/Object; + public fun cosh (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/Float64BufferND; + public fun div (DLspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/Float64BufferND; + 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 synthetic fun div (Ljava/lang/Object;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public fun div (Lspace/kscience/kmath/nd/StructureND;D)Lspace/kscience/kmath/nd/Float64BufferND; + public fun div (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Number;)Lspace/kscience/kmath/nd/Float64BufferND; + public synthetic fun div (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Object;)Lspace/kscience/kmath/nd/StructureND; + public fun div (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/Float64BufferND; + public synthetic fun divide (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun divide (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/Float64BufferND; + public synthetic fun divide (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public synthetic fun exp (Ljava/lang/Object;)Ljava/lang/Object; + public fun exp (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/Float64BufferND; + public synthetic fun ln (Ljava/lang/Object;)Ljava/lang/Object; + public fun ln (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/Float64BufferND; + public fun map (Lspace/kscience/kmath/nd/StructureND;Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/BufferND; + public synthetic fun map (Lspace/kscience/kmath/nd/StructureND;Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/StructureND; + protected final fun mapInline (Lspace/kscience/kmath/nd/Float64BufferND;Lkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/nd/Float64BufferND; + public fun minus (DLspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public synthetic fun minus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public synthetic fun minus (Ljava/lang/Object;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public fun minus (Lspace/kscience/kmath/nd/StructureND;D)Lspace/kscience/kmath/nd/StructureND; + public synthetic fun minus (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Object;)Lspace/kscience/kmath/nd/StructureND; + public fun minus (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/Float64BufferND; + public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun multiply (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/Float64BufferND; + public synthetic fun multiply (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public fun mutableStructureND-qL90JFI ([ILkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/Float64BufferND; + public synthetic fun mutableStructureND-qL90JFI ([ILkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/MutableBufferND; + public synthetic fun mutableStructureND-qL90JFI ([ILkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/MutableStructureND; + public fun plus (DLspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public synthetic fun plus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public synthetic fun plus (Ljava/lang/Object;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public fun plus (Lspace/kscience/kmath/nd/StructureND;D)Lspace/kscience/kmath/nd/Float64BufferND; + public synthetic fun plus (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Object;)Lspace/kscience/kmath/nd/StructureND; + public fun plus (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/Float64BufferND; + 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/StructureND; + public synthetic fun scale (Ljava/lang/Object;D)Ljava/lang/Object; + public fun scale (Lspace/kscience/kmath/nd/StructureND;D)Lspace/kscience/kmath/nd/Float64BufferND; + public synthetic 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/Float64BufferND; + public synthetic fun sinh (Ljava/lang/Object;)Ljava/lang/Object; + public fun sinh (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/Float64BufferND; + public synthetic fun tan (Ljava/lang/Object;)Ljava/lang/Object; + public fun tan (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/Float64BufferND; + public synthetic fun tanh (Ljava/lang/Object;)Ljava/lang/Object; + public fun tanh (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/Float64BufferND; + public synthetic fun times (Ljava/lang/Number;Ljava/lang/Object;)Ljava/lang/Object; + public fun times (Ljava/lang/Number;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/Float64BufferND; + 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/nd/StructureND;Ljava/lang/Number;)Lspace/kscience/kmath/nd/Float64BufferND; + public fun times (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/Float64BufferND; + public synthetic fun toBufferND (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/BufferND; + public fun toBufferND (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/Float64BufferND; + public synthetic fun unaryMinus (Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryMinus (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/Float64BufferND; + public synthetic fun unaryMinus (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public synthetic fun unaryPlus (Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryPlus (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/Float64BufferND; + public fun zip (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;Lkotlin/jvm/functions/Function3;)Lspace/kscience/kmath/nd/BufferND; + public synthetic fun zip (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;Lkotlin/jvm/functions/Function3;)Lspace/kscience/kmath/nd/StructureND; +} + +public final class space/kscience/kmath/nd/Floa64FieldOpsND$Companion : space/kscience/kmath/nd/Floa64FieldOpsND { +} + +public final class space/kscience/kmath/nd/Float64BufferND : space/kscience/kmath/nd/MutableBufferND, space/kscience/kmath/nd/MutableStructureNDOfDouble { + public synthetic fun (Lspace/kscience/kmath/nd/ShapeIndexer;[DLkotlin/jvm/internal/DefaultConstructorMarker;)V + public synthetic fun getBuffer ()Lspace/kscience/kmath/structures/Buffer; + public synthetic fun getBuffer ()Lspace/kscience/kmath/structures/MutableBuffer; + public fun getBuffer-E20IKn8 ()[D + public fun getDouble ([I)D + public fun getType-V0oMfBY ()Lkotlin/reflect/KType; + public fun setDouble ([ID)V +} + +public final class space/kscience/kmath/nd/Float64FieldND : space/kscience/kmath/nd/Floa64FieldOpsND, space/kscience/kmath/nd/FieldND, space/kscience/kmath/operations/ExtendedField, space/kscience/kmath/operations/NumbersAddOps { + public synthetic fun ([ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public synthetic fun acosh (Ljava/lang/Object;)Ljava/lang/Object; + public fun acosh (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/Float64BufferND; + public synthetic fun asinh (Ljava/lang/Object;)Ljava/lang/Object; + public fun asinh (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/Float64BufferND; + public synthetic fun atanh (Ljava/lang/Object;)Ljava/lang/Object; + public fun atanh (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/Float64BufferND; + public synthetic fun cosh (Ljava/lang/Object;)Ljava/lang/Object; + public fun cosh (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/Float64BufferND; + public fun getShape-IIYLAfE ()[I + public synthetic fun number (Ljava/lang/Number;)Ljava/lang/Object; + public fun number (Ljava/lang/Number;)Lspace/kscience/kmath/nd/Float64BufferND; + public synthetic fun power (Ljava/lang/Object;I)Ljava/lang/Object; + public synthetic fun power (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun power (Lspace/kscience/kmath/nd/StructureND;I)Lspace/kscience/kmath/nd/Float64BufferND; + public fun power (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Number;)Lspace/kscience/kmath/nd/Float64BufferND; + public synthetic fun power (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Number;)Lspace/kscience/kmath/nd/StructureND; + public synthetic fun power-Qn1smSk (Ljava/lang/Object;I)Ljava/lang/Object; + public fun power-Qn1smSk (Lspace/kscience/kmath/nd/StructureND;I)Lspace/kscience/kmath/nd/Float64BufferND; + public synthetic fun sinh (Ljava/lang/Object;)Ljava/lang/Object; + public fun sinh (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/Float64BufferND; + public synthetic fun tanh (Ljava/lang/Object;)Ljava/lang/Object; + public fun tanh (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/Float64BufferND; +} + +public final class space/kscience/kmath/nd/Float64FieldNDKt { + public static final fun getNdAlgebra (Lspace/kscience/kmath/operations/Float64Field;)Lspace/kscience/kmath/nd/Floa64FieldOpsND; + public static final fun ndAlgebra (Lspace/kscience/kmath/operations/Float64Field;[I)Lspace/kscience/kmath/nd/Float64FieldND; + public static final fun ndAlgebra-waz_sdI (Lspace/kscience/kmath/operations/Float64Field;[I)Lspace/kscience/kmath/nd/Float64FieldND; +} + public abstract interface class space/kscience/kmath/nd/GroupND : space/kscience/kmath/nd/GroupOpsND, space/kscience/kmath/nd/WithShape, space/kscience/kmath/operations/Group { public synthetic fun getZero ()Ljava/lang/Object; public fun getZero ()Lspace/kscience/kmath/nd/StructureND; @@ -1137,6 +1205,7 @@ public abstract interface class space/kscience/kmath/nd/GroupOpsND : space/kscie public static final field Companion Lspace/kscience/kmath/nd/GroupOpsND$Companion; public synthetic fun add (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; public fun add (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public fun getBufferFactory ()Lspace/kscience/kmath/structures/MutableBufferFactory; public fun minus (Ljava/lang/Object;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; public fun minus (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Object;)Lspace/kscience/kmath/nd/StructureND; public fun plus (Ljava/lang/Object;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; @@ -1152,11 +1221,29 @@ public final class space/kscience/kmath/nd/IndexOutOfShapeException : java/lang/ public final fun getShape-IIYLAfE ()[I } +public final class space/kscience/kmath/nd/Int16RingND : space/kscience/kmath/nd/Int16RingOpsND, space/kscience/kmath/nd/RingND, space/kscience/kmath/operations/NumbersAddOps { + public synthetic fun ([ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public fun getShape-IIYLAfE ()[I + public synthetic fun number (Ljava/lang/Number;)Ljava/lang/Object; + public fun number (Ljava/lang/Number;)Lspace/kscience/kmath/nd/BufferND; +} + +public final class space/kscience/kmath/nd/Int16RingNDKt { + public static final fun withNdAlgebra (Lspace/kscience/kmath/operations/Int16Ring;[ILkotlin/jvm/functions/Function1;)Ljava/lang/Object; +} + +public abstract class space/kscience/kmath/nd/Int16RingOpsND : space/kscience/kmath/nd/BufferedRingOpsND { + public static final field Companion Lspace/kscience/kmath/nd/Int16RingOpsND$Companion; +} + +public final class space/kscience/kmath/nd/Int16RingOpsND$Companion : space/kscience/kmath/nd/Int16RingOpsND { +} + public final class space/kscience/kmath/nd/IntBufferND : space/kscience/kmath/nd/MutableBufferND { public synthetic fun (Lspace/kscience/kmath/nd/ShapeIndexer;[ILkotlin/jvm/internal/DefaultConstructorMarker;)V public synthetic fun getBuffer ()Lspace/kscience/kmath/structures/Buffer; public synthetic fun getBuffer ()Lspace/kscience/kmath/structures/MutableBuffer; - public fun getBuffer-ir4F4A8 ()[I + public fun getBuffer-M_oXE9g ()[I } public final class space/kscience/kmath/nd/IntRingND : space/kscience/kmath/nd/IntRingOpsND, space/kscience/kmath/nd/RingND, space/kscience/kmath/operations/NumbersAddOps { @@ -1167,7 +1254,7 @@ public final class space/kscience/kmath/nd/IntRingND : space/kscience/kmath/nd/I } public final class space/kscience/kmath/nd/IntRingNDKt { - public static final fun withNdAlgebra (Lspace/kscience/kmath/operations/IntRing;[ILkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static final fun withNdAlgebra (Lspace/kscience/kmath/operations/Int32Ring;[ILkotlin/jvm/functions/Function1;)Ljava/lang/Object; } public abstract class space/kscience/kmath/nd/IntRingOpsND : space/kscience/kmath/nd/BufferedRingOpsND { @@ -1201,6 +1288,17 @@ public abstract interface class space/kscience/kmath/nd/MutableStructureND : spa public abstract fun set ([ILjava/lang/Object;)V } +public final class space/kscience/kmath/nd/MutableStructureNDAccessorBuffer : space/kscience/kmath/structures/MutableBuffer { + public fun (Lspace/kscience/kmath/nd/MutableStructureND;ILkotlin/jvm/functions/Function1;)V + public fun copy ()Lspace/kscience/kmath/structures/MutableBuffer; + public fun get (I)Ljava/lang/Object; + public fun getSize ()I + public final fun getStructure ()Lspace/kscience/kmath/nd/MutableStructureND; + public fun getType-V0oMfBY ()Lkotlin/reflect/KType; + public fun set (ILjava/lang/Object;)V + public fun toString ()Ljava/lang/String; +} + public abstract interface class space/kscience/kmath/nd/MutableStructureNDOfDouble : space/kscience/kmath/nd/MutableStructureND, space/kscience/kmath/nd/StructureNDOfDouble { public abstract fun setDouble ([ID)V } @@ -1218,6 +1316,7 @@ public final class space/kscience/kmath/nd/PermutedMutableStructureND : space/ks public final fun getOrigin ()Lspace/kscience/kmath/nd/MutableStructureND; public final fun getPermutation ()Lkotlin/jvm/functions/Function1; public fun getShape-IIYLAfE ()[I + public fun getType-V0oMfBY ()Lkotlin/reflect/KType; public fun set ([ILjava/lang/Object;)V } @@ -1227,6 +1326,7 @@ public final class space/kscience/kmath/nd/PermutedStructureND : space/kscience/ public final fun getOrigin ()Lspace/kscience/kmath/nd/StructureND; public final fun getPermutation ()Lkotlin/jvm/functions/Function1; public fun getShape-IIYLAfE ()[I + public fun getType-V0oMfBY ()Lkotlin/reflect/KType; } public final class space/kscience/kmath/nd/PermutedStructureNDKt { @@ -1332,24 +1432,6 @@ public final class space/kscience/kmath/nd/ShapeNDKt { public static final fun transposed-bYNkpeI ([III)[I } -public final class space/kscience/kmath/nd/ShortRingND : space/kscience/kmath/nd/ShortRingOpsND, space/kscience/kmath/nd/RingND, space/kscience/kmath/operations/NumbersAddOps { - public synthetic fun ([ILkotlin/jvm/internal/DefaultConstructorMarker;)V - public fun getShape-IIYLAfE ()[I - public synthetic fun number (Ljava/lang/Number;)Ljava/lang/Object; - public fun number (Ljava/lang/Number;)Lspace/kscience/kmath/nd/BufferND; -} - -public final class space/kscience/kmath/nd/ShortRingNDKt { - public static final fun withNdAlgebra (Lspace/kscience/kmath/operations/ShortRing;[ILkotlin/jvm/functions/Function1;)Ljava/lang/Object; -} - -public abstract class space/kscience/kmath/nd/ShortRingOpsND : space/kscience/kmath/nd/BufferedRingOpsND { - public static final field Companion Lspace/kscience/kmath/nd/ShortRingOpsND$Companion; -} - -public final class space/kscience/kmath/nd/ShortRingOpsND$Companion : space/kscience/kmath/nd/ShortRingOpsND { -} - public abstract class space/kscience/kmath/nd/Strides : space/kscience/kmath/nd/ShapeIndexer { public fun ()V public fun asSequence ()Lkotlin/sequences/Sequence; @@ -1392,26 +1474,19 @@ public final class space/kscience/kmath/nd/Structure2DKt { public static final fun as2D (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/Structure2D; } -public abstract interface class space/kscience/kmath/nd/StructureFeature : space/kscience/kmath/misc/Feature { +public abstract interface class space/kscience/kmath/nd/StructureAttribute : space/kscience/attributes/Attribute { } -public abstract interface class space/kscience/kmath/nd/StructureND : space/kscience/kmath/misc/Featured, space/kscience/kmath/nd/WithShape { +public abstract interface class space/kscience/kmath/nd/StructureND : space/kscience/attributes/AttributeContainer, space/kscience/attributes/WithType, space/kscience/kmath/nd/WithShape { public static final field Companion Lspace/kscience/kmath/nd/StructureND$Companion; public fun elements ()Lkotlin/sequences/Sequence; public abstract fun get ([I)Ljava/lang/Object; + public fun getAttributes ()Lspace/kscience/attributes/Attributes; public fun getDimension ()I - public synthetic fun getFeature (Lkotlin/reflect/KClass;)Ljava/lang/Object; - public fun getFeature (Lkotlin/reflect/KClass;)Lspace/kscience/kmath/nd/StructureFeature; public abstract fun getShape-IIYLAfE ()[I } public final class space/kscience/kmath/nd/StructureND$Companion { - public final fun auto (Lkotlin/reflect/KClass;Lspace/kscience/kmath/nd/Strides;Lkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/nd/BufferND; - public final fun auto (Lkotlin/reflect/KClass;[ILkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/nd/BufferND; - public final fun buffered (Lspace/kscience/kmath/nd/Strides;Lspace/kscience/kmath/structures/BufferFactory;Lkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/nd/BufferND; - public static synthetic fun buffered$default (Lspace/kscience/kmath/nd/StructureND$Companion;Lspace/kscience/kmath/nd/Strides;Lspace/kscience/kmath/structures/BufferFactory;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lspace/kscience/kmath/nd/BufferND; - public final fun buffered-bYNkpeI ([ILspace/kscience/kmath/structures/BufferFactory;Lkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/nd/BufferND; - public static synthetic fun buffered-bYNkpeI$default (Lspace/kscience/kmath/nd/StructureND$Companion;[ILspace/kscience/kmath/structures/BufferFactory;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lspace/kscience/kmath/nd/BufferND; public final fun contentEquals (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Z public final fun contentEquals (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;D)Z public static synthetic fun contentEquals$default (Lspace/kscience/kmath/nd/StructureND$Companion;Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;DILjava/lang/Object;)Z @@ -1419,6 +1494,9 @@ public final class space/kscience/kmath/nd/StructureND$Companion { } public final class space/kscience/kmath/nd/StructureNDKt { + public static final fun BufferND--rwW0uw (Lkotlin/reflect/KType;Lspace/kscience/kmath/nd/Strides;Lkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/nd/BufferND; + public static final fun BufferND--rwW0uw (Lkotlin/reflect/KType;[ILkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/nd/BufferND; + public static final fun BufferND-vHyE91E (Lkotlin/reflect/KType;[ILkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/nd/BufferND; public static final fun contentEquals (Lspace/kscience/kmath/linear/LinearSpace;Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Z public static final fun contentEquals (Lspace/kscience/kmath/linear/LinearSpace;Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Comparable;)Z public static final fun contentEquals (Lspace/kscience/kmath/nd/AlgebraND;Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Z @@ -1431,17 +1509,20 @@ public final class space/kscience/kmath/nd/StructureNDKt { public abstract interface class space/kscience/kmath/nd/StructureNDOfDouble : space/kscience/kmath/nd/StructureND { public abstract fun getDouble ([I)D + public fun getType-V0oMfBY ()Lkotlin/reflect/KType; } public abstract interface class space/kscience/kmath/nd/StructureNDOfInt : space/kscience/kmath/nd/StructureND { public abstract fun getInt ([I)I + public fun getType-V0oMfBY ()Lkotlin/reflect/KType; } public class space/kscience/kmath/nd/VirtualStructureND : space/kscience/kmath/nd/StructureND { - public synthetic fun ([ILkotlin/jvm/functions/Function1;Lkotlin/jvm/internal/DefaultConstructorMarker;)V + public synthetic fun (Lkotlin/reflect/KType;[ILkotlin/jvm/functions/Function1;Lkotlin/jvm/internal/DefaultConstructorMarker;)V public fun get ([I)Ljava/lang/Object; public final fun getProducer ()Lkotlin/jvm/functions/Function1; public fun getShape-IIYLAfE ()[I + public fun getType-V0oMfBY ()Lkotlin/reflect/KType; } public abstract interface class space/kscience/kmath/nd/WithShape { @@ -1449,12 +1530,13 @@ public abstract interface class space/kscience/kmath/nd/WithShape { public abstract fun getShape-IIYLAfE ()[I } -public abstract interface class space/kscience/kmath/operations/Algebra { +public abstract interface class space/kscience/kmath/operations/Algebra : space/kscience/attributes/WithType { public 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/Object; public fun bindSymbolOrNull (Ljava/lang/String;)Ljava/lang/Object; - public fun getBufferFactory ()Lspace/kscience/kmath/structures/MutableBufferFactory; + public abstract fun getBufferFactory ()Lspace/kscience/kmath/structures/MutableBufferFactory; + public fun getType-V0oMfBY ()Lkotlin/reflect/KType; public fun unaryOperation (Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; public fun unaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function1; } @@ -1520,6 +1602,7 @@ public final class space/kscience/kmath/operations/BigIntField : space/kscience/ public fun add (Lspace/kscience/kmath/operations/BigInt;Lspace/kscience/kmath/operations/BigInt;)Lspace/kscience/kmath/operations/BigInt; public synthetic fun divide (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; public fun divide (Lspace/kscience/kmath/operations/BigInt;Lspace/kscience/kmath/operations/BigInt;)Lspace/kscience/kmath/operations/BigInt; + public fun getBufferFactory ()Lspace/kscience/kmath/structures/MutableBufferFactory; public synthetic fun getOne ()Ljava/lang/Object; public fun getOne ()Lspace/kscience/kmath/operations/BigInt; public synthetic fun getZero ()Ljava/lang/Object; @@ -1553,8 +1636,9 @@ public final class space/kscience/kmath/operations/BigIntKt { public abstract interface class space/kscience/kmath/operations/BufferAlgebra : space/kscience/kmath/operations/Algebra { public fun binaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; public fun buffer (I[Ljava/lang/Object;)Lspace/kscience/kmath/structures/Buffer; + public fun getBufferFactory ()Lspace/kscience/kmath/structures/MutableBufferFactory; public abstract fun getElementAlgebra ()Lspace/kscience/kmath/operations/Algebra; - public fun getElementBufferFactory ()Lspace/kscience/kmath/structures/BufferFactory; + public fun getElementBufferFactory ()Lspace/kscience/kmath/structures/MutableBufferFactory; public fun map (Lspace/kscience/kmath/structures/Buffer;Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/structures/Buffer; public fun mapIndexed (Lspace/kscience/kmath/structures/Buffer;Lkotlin/jvm/functions/Function3;)Lspace/kscience/kmath/structures/Buffer; public fun unaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function1; @@ -1568,15 +1652,15 @@ public final class space/kscience/kmath/operations/BufferAlgebraKt { public static final fun asinh (Lspace/kscience/kmath/operations/BufferAlgebra;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; public static final fun atan (Lspace/kscience/kmath/operations/BufferAlgebra;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; public static final fun atanh (Lspace/kscience/kmath/operations/BufferAlgebra;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; - public static final fun buffer (Lspace/kscience/kmath/operations/BufferAlgebra;ILkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/structures/Buffer; - public static final fun buffer (Lspace/kscience/kmath/operations/BufferAlgebra;Lkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/structures/Buffer; + public static final fun buffer (Lspace/kscience/kmath/operations/BufferAlgebra;ILkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/structures/MutableBuffer; + public static final fun buffer (Lspace/kscience/kmath/operations/BufferAlgebra;Lkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/structures/MutableBuffer; public static final fun buffer (Lspace/kscience/kmath/operations/BufferField;[Ljava/lang/Number;)Lspace/kscience/kmath/structures/Buffer; public static final fun cos (Lspace/kscience/kmath/operations/BufferAlgebra;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; public static final fun cosh (Lspace/kscience/kmath/operations/BufferAlgebra;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; public static final fun exp (Lspace/kscience/kmath/operations/BufferAlgebra;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; public static final fun getBufferAlgebra (Lspace/kscience/kmath/operations/Field;)Lspace/kscience/kmath/operations/BufferFieldOps; - public static final fun getBufferAlgebra (Lspace/kscience/kmath/operations/IntRing;)Lspace/kscience/kmath/operations/BufferRingOps; - public static final fun getBufferAlgebra (Lspace/kscience/kmath/operations/ShortRing;)Lspace/kscience/kmath/operations/BufferRingOps; + public static final fun getBufferAlgebra (Lspace/kscience/kmath/operations/Int16Ring;)Lspace/kscience/kmath/operations/BufferRingOps; + public static final fun getBufferAlgebra (Lspace/kscience/kmath/operations/Int32Ring;)Lspace/kscience/kmath/operations/BufferRingOps; public static final fun ln (Lspace/kscience/kmath/operations/BufferAlgebra;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; public static final fun pow (Lspace/kscience/kmath/operations/BufferAlgebra;Lspace/kscience/kmath/structures/Buffer;Ljava/lang/Number;)Lspace/kscience/kmath/structures/Buffer; public static final fun sin (Lspace/kscience/kmath/operations/BufferAlgebra;Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; @@ -1635,201 +1719,6 @@ public abstract interface class space/kscience/kmath/operations/BufferTransform public abstract fun transform (Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; } -public final class space/kscience/kmath/operations/ByteRing : space/kscience/kmath/operations/Norm, space/kscience/kmath/operations/NumericAlgebra, space/kscience/kmath/operations/Ring { - public static final field INSTANCE Lspace/kscience/kmath/operations/ByteRing; - public fun add (BB)Ljava/lang/Byte; - public synthetic fun add (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun getBufferFactory ()Lspace/kscience/kmath/structures/MutableBufferFactory; - public fun getOne ()Ljava/lang/Byte; - public synthetic fun getOne ()Ljava/lang/Object; - public fun getZero ()Ljava/lang/Byte; - public synthetic fun getZero ()Ljava/lang/Object; - public fun minus (BB)Ljava/lang/Byte; - public synthetic fun minus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun multiply (BB)Ljava/lang/Byte; - public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun norm (B)Ljava/lang/Byte; - public synthetic fun norm (Ljava/lang/Object;)Ljava/lang/Object; - public fun number (Ljava/lang/Number;)Ljava/lang/Byte; - public synthetic fun number (Ljava/lang/Number;)Ljava/lang/Object; - public fun plus (BB)Ljava/lang/Byte; - public synthetic fun plus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun times (BB)Ljava/lang/Byte; - public synthetic fun times (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun unaryMinus (B)Ljava/lang/Byte; - public synthetic fun unaryMinus (Ljava/lang/Object;)Ljava/lang/Object; -} - -public final class space/kscience/kmath/operations/DoubleBufferField : space/kscience/kmath/operations/DoubleBufferOps, space/kscience/kmath/operations/ExtendedField { - public fun (I)V - public synthetic fun acosh (Ljava/lang/Object;)Ljava/lang/Object; - public fun acosh-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 atanh (Ljava/lang/Object;)Ljava/lang/Object; - public fun atanh-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 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 power (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; - public synthetic fun power (Lspace/kscience/kmath/structures/Buffer;Ljava/lang/Number;)Lspace/kscience/kmath/structures/Buffer; - public fun power-CZ9oacQ (Lspace/kscience/kmath/structures/Buffer;Ljava/lang/Number;)[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 tanh (Ljava/lang/Object;)Ljava/lang/Object; - public fun tanh-Udx-57Q (Lspace/kscience/kmath/structures/Buffer;)[D - public fun unaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function1; -} - -public abstract class space/kscience/kmath/operations/DoubleBufferOps : space/kscience/kmath/operations/BufferAlgebra, space/kscience/kmath/operations/ExtendedFieldOps, space/kscience/kmath/operations/Norm { - public static final field Companion Lspace/kscience/kmath/operations/DoubleBufferOps$Companion; - public fun ()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 fun binaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; - 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 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 getElementAlgebra ()Lspace/kscience/kmath/operations/Algebra; - public fun getElementAlgebra ()Lspace/kscience/kmath/operations/DoubleField; - public synthetic fun getElementBufferFactory ()Lspace/kscience/kmath/structures/BufferFactory; - public fun getElementBufferFactory ()Lspace/kscience/kmath/structures/MutableBufferFactory; - public synthetic fun ln (Ljava/lang/Object;)Ljava/lang/Object; - public fun ln-Udx-57Q (Lspace/kscience/kmath/structures/Buffer;)[D - public synthetic fun map (Lspace/kscience/kmath/structures/Buffer;Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/structures/Buffer; - public final fun map-CZ9oacQ (Lspace/kscience/kmath/structures/Buffer;Lkotlin/jvm/functions/Function2;)[D - public synthetic fun mapIndexed (Lspace/kscience/kmath/structures/Buffer;Lkotlin/jvm/functions/Function3;)Lspace/kscience/kmath/structures/Buffer; - public final fun mapIndexed-CZ9oacQ (Lspace/kscience/kmath/structures/Buffer;Lkotlin/jvm/functions/Function3;)[D - public synthetic fun minus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun minus-CZ9oacQ (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)[D - public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public synthetic fun norm (Ljava/lang/Object;)Ljava/lang/Object; - public fun norm (Lspace/kscience/kmath/structures/Buffer;)Ljava/lang/Double; - public synthetic fun plus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun plus-CZ9oacQ (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)[D - public synthetic fun power (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; - public fun power (Lspace/kscience/kmath/structures/Buffer;Ljava/lang/Number;)Lspace/kscience/kmath/structures/Buffer; - 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 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 unaryMinus (Ljava/lang/Object;)Ljava/lang/Object; - public fun unaryMinus-Udx-57Q (Lspace/kscience/kmath/structures/Buffer;)[D - public fun unaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function1; - public synthetic fun zip (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;Lkotlin/jvm/functions/Function3;)Lspace/kscience/kmath/structures/Buffer; - public final fun zip-XquIszc (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;Lkotlin/jvm/functions/Function3;)[D -} - -public final class space/kscience/kmath/operations/DoubleBufferOps$Companion : space/kscience/kmath/operations/DoubleBufferOps { -} - -public final class space/kscience/kmath/operations/DoubleBufferOpsKt { - public static final fun average (Lspace/kscience/kmath/operations/DoubleBufferOps;Lspace/kscience/kmath/structures/Buffer;)D - public static final fun averageOf (Lspace/kscience/kmath/operations/DoubleBufferOps;Lspace/kscience/kmath/structures/Buffer;Lkotlin/jvm/functions/Function1;)D - public static final fun covariance (Lspace/kscience/kmath/operations/DoubleBufferOps;Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)D - public static final fun dispersion (Lspace/kscience/kmath/operations/DoubleBufferOps;Lspace/kscience/kmath/structures/Buffer;)D - public static final fun std (Lspace/kscience/kmath/operations/DoubleBufferOps;Lspace/kscience/kmath/structures/Buffer;)D - public static final fun sum (Lspace/kscience/kmath/operations/DoubleBufferOps;Lspace/kscience/kmath/structures/Buffer;)D - public static final fun sumOf (Lspace/kscience/kmath/operations/DoubleBufferOps;Lspace/kscience/kmath/structures/Buffer;Lkotlin/jvm/functions/Function1;)D -} - -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 binaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; - 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 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 getBufferFactory ()Lspace/kscience/kmath/structures/MutableBufferFactory; - 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 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 power (DLjava/lang/Number;)Ljava/lang/Double; - public synthetic fun power (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; - 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 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 final class space/kscience/kmath/operations/DoubleL2Norm : space/kscience/kmath/operations/Norm { - public static final field INSTANCE Lspace/kscience/kmath/operations/DoubleL2Norm; - public synthetic fun norm (Ljava/lang/Object;)Ljava/lang/Object; - public fun norm (Lspace/kscience/kmath/structures/Buffer;)Ljava/lang/Double; -} - 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; @@ -1899,8 +1788,8 @@ public final class space/kscience/kmath/operations/FieldOps$Companion { public static final field DIV_OPERATION Ljava/lang/String; } -public final class space/kscience/kmath/operations/FloatField : space/kscience/kmath/operations/ExtendedField, space/kscience/kmath/operations/Norm { - public static final field INSTANCE Lspace/kscience/kmath/operations/FloatField; +public final class space/kscience/kmath/operations/Float32Field : space/kscience/kmath/operations/ExtendedField, space/kscience/kmath/operations/Norm { + public static final field INSTANCE Lspace/kscience/kmath/operations/Float32Field; public fun acos (F)Ljava/lang/Float; public synthetic fun acos (Ljava/lang/Object;)Ljava/lang/Object; public fun acosh (F)Ljava/lang/Float; @@ -1963,6 +1852,175 @@ public final class space/kscience/kmath/operations/FloatField : space/kscience/k public synthetic fun unaryMinus (Ljava/lang/Object;)Ljava/lang/Object; } +public final class space/kscience/kmath/operations/Float64BufferField : space/kscience/kmath/operations/Float64BufferOps, space/kscience/kmath/operations/ExtendedField { + public fun (I)V + public synthetic fun acosh (Ljava/lang/Object;)Ljava/lang/Object; + public fun acosh-qFCK38E (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun asinh (Ljava/lang/Object;)Ljava/lang/Object; + public fun asinh-qFCK38E (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun atanh (Ljava/lang/Object;)Ljava/lang/Object; + public fun atanh-qFCK38E (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun cosh (Ljava/lang/Object;)Ljava/lang/Object; + public fun cosh-qFCK38E (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 power (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public synthetic fun power (Lspace/kscience/kmath/structures/Buffer;Ljava/lang/Number;)Lspace/kscience/kmath/structures/Buffer; + public fun power-Vq5tpWc (Lspace/kscience/kmath/structures/Buffer;Ljava/lang/Number;)[D + public synthetic fun sinh (Ljava/lang/Object;)Ljava/lang/Object; + public fun sinh-qFCK38E (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun tanh (Ljava/lang/Object;)Ljava/lang/Object; + public fun tanh-qFCK38E (Lspace/kscience/kmath/structures/Buffer;)[D + public fun unaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function1; +} + +public abstract class space/kscience/kmath/operations/Float64BufferOps : space/kscience/kmath/operations/BufferAlgebra, space/kscience/kmath/operations/ExtendedFieldOps, space/kscience/kmath/operations/Norm { + public static final field Companion Lspace/kscience/kmath/operations/Float64BufferOps$Companion; + public fun ()V + public synthetic fun acos (Ljava/lang/Object;)Ljava/lang/Object; + public fun acos-qFCK38E (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun acosh (Ljava/lang/Object;)Ljava/lang/Object; + public fun acosh-qFCK38E (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun add (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun add-Vq5tpWc (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun asin (Ljava/lang/Object;)Ljava/lang/Object; + public fun asin-qFCK38E (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun asinh (Ljava/lang/Object;)Ljava/lang/Object; + public fun asinh-qFCK38E (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun atan (Ljava/lang/Object;)Ljava/lang/Object; + public fun atan-qFCK38E (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun atanh (Ljava/lang/Object;)Ljava/lang/Object; + public fun atanh-qFCK38E (Lspace/kscience/kmath/structures/Buffer;)[D + public fun binaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + public synthetic fun cos (Ljava/lang/Object;)Ljava/lang/Object; + public fun cos-qFCK38E (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun cosh (Ljava/lang/Object;)Ljava/lang/Object; + public fun cosh-qFCK38E (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun divide (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun divide-Vq5tpWc (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun exp (Ljava/lang/Object;)Ljava/lang/Object; + public fun exp-qFCK38E (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun getElementAlgebra ()Lspace/kscience/kmath/operations/Algebra; + public fun getElementAlgebra ()Lspace/kscience/kmath/operations/Float64Field; + public fun getElementBufferFactory ()Lspace/kscience/kmath/structures/MutableBufferFactory; + public synthetic fun ln (Ljava/lang/Object;)Ljava/lang/Object; + public fun ln-qFCK38E (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun map (Lspace/kscience/kmath/structures/Buffer;Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/structures/Buffer; + public final fun map-Vq5tpWc (Lspace/kscience/kmath/structures/Buffer;Lkotlin/jvm/functions/Function2;)[D + public synthetic fun mapIndexed (Lspace/kscience/kmath/structures/Buffer;Lkotlin/jvm/functions/Function3;)Lspace/kscience/kmath/structures/Buffer; + public final fun mapIndexed-Vq5tpWc (Lspace/kscience/kmath/structures/Buffer;Lkotlin/jvm/functions/Function3;)[D + public synthetic fun minus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun minus-Vq5tpWc (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public synthetic fun norm (Ljava/lang/Object;)Ljava/lang/Object; + public fun norm (Lspace/kscience/kmath/structures/Buffer;)Ljava/lang/Double; + public synthetic fun plus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun plus-Vq5tpWc (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun power (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + public fun power (Lspace/kscience/kmath/structures/Buffer;Ljava/lang/Number;)Lspace/kscience/kmath/structures/Buffer; + public synthetic fun scale (Ljava/lang/Object;D)Ljava/lang/Object; + public fun scale-Vq5tpWc (Lspace/kscience/kmath/structures/Buffer;D)[D + public synthetic fun sin (Ljava/lang/Object;)Ljava/lang/Object; + public fun sin-qFCK38E (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun sinh (Ljava/lang/Object;)Ljava/lang/Object; + public fun sinh-qFCK38E (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun tan (Ljava/lang/Object;)Ljava/lang/Object; + public fun tan-qFCK38E (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun tanh (Ljava/lang/Object;)Ljava/lang/Object; + public fun tanh-qFCK38E (Lspace/kscience/kmath/structures/Buffer;)[D + public synthetic fun unaryMinus (Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryMinus-qFCK38E (Lspace/kscience/kmath/structures/Buffer;)[D + public fun unaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function1; + public synthetic fun zip (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;Lkotlin/jvm/functions/Function3;)Lspace/kscience/kmath/structures/Buffer; + public final fun zip-Qj2idzA (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;Lkotlin/jvm/functions/Function3;)[D +} + +public final class space/kscience/kmath/operations/Float64BufferOps$Companion : space/kscience/kmath/operations/Float64BufferOps { +} + +public final class space/kscience/kmath/operations/Float64BufferOpsKt { + public static final fun average (Lspace/kscience/kmath/operations/Float64BufferOps;Lspace/kscience/kmath/structures/Buffer;)D + public static final fun averageOf (Lspace/kscience/kmath/operations/Float64BufferOps;Lspace/kscience/kmath/structures/Buffer;Lkotlin/jvm/functions/Function1;)D + public static final fun covariance (Lspace/kscience/kmath/operations/Float64BufferOps;Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)D + public static final fun dispersion (Lspace/kscience/kmath/operations/Float64BufferOps;Lspace/kscience/kmath/structures/Buffer;)D + public static final fun std (Lspace/kscience/kmath/operations/Float64BufferOps;Lspace/kscience/kmath/structures/Buffer;)D + public static final fun sum (Lspace/kscience/kmath/operations/Float64BufferOps;Lspace/kscience/kmath/structures/Buffer;)D + public static final fun sumOf (Lspace/kscience/kmath/operations/Float64BufferOps;Lspace/kscience/kmath/structures/Buffer;Lkotlin/jvm/functions/Function1;)D +} + +public final class space/kscience/kmath/operations/Float64Field : space/kscience/kmath/operations/ExtendedField, space/kscience/kmath/operations/Norm, space/kscience/kmath/operations/ScaleOperations { + public static final field INSTANCE Lspace/kscience/kmath/operations/Float64Field; + 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 binaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + 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 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 getBufferFactory ()Lspace/kscience/kmath/structures/MutableBufferFactory; + 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 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 power (DLjava/lang/Number;)Ljava/lang/Double; + public synthetic fun power (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + 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 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 final class space/kscience/kmath/operations/Float64L2Norm : space/kscience/kmath/operations/Norm { + public static final field INSTANCE Lspace/kscience/kmath/operations/Float64L2Norm; + public synthetic fun norm (Ljava/lang/Object;)Ljava/lang/Object; + public fun norm (Lspace/kscience/kmath/structures/Buffer;)Ljava/lang/Double; +} + public abstract interface class space/kscience/kmath/operations/Group : space/kscience/kmath/operations/GroupOps { public abstract fun getZero ()Ljava/lang/Object; } @@ -1985,8 +2043,79 @@ public final class space/kscience/kmath/operations/GroupOps$Companion { public static final field PLUS_OPERATION Ljava/lang/String; } -public final class space/kscience/kmath/operations/IntRing : space/kscience/kmath/operations/Norm, space/kscience/kmath/operations/NumericAlgebra, space/kscience/kmath/operations/Ring { - public static final field INSTANCE Lspace/kscience/kmath/operations/IntRing; +public final class space/kscience/kmath/operations/Int16Field : space/kscience/kmath/operations/Field, space/kscience/kmath/operations/Norm, space/kscience/kmath/operations/NumericAlgebra { + public static final field INSTANCE Lspace/kscience/kmath/operations/Int16Field; + public synthetic fun add (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun add (SS)Ljava/lang/Short; + public synthetic fun divide (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun divide (SS)Ljava/lang/Short; + public fun getBufferFactory ()Lspace/kscience/kmath/structures/MutableBufferFactory; + public synthetic fun getOne ()Ljava/lang/Object; + public fun getOne ()Ljava/lang/Short; + public synthetic fun getZero ()Ljava/lang/Object; + public fun getZero ()Ljava/lang/Short; + public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun multiply (SS)Ljava/lang/Short; + public synthetic fun norm (Ljava/lang/Object;)Ljava/lang/Object; + public fun norm (S)Ljava/lang/Short; + public synthetic fun number (Ljava/lang/Number;)Ljava/lang/Object; + public fun number (Ljava/lang/Number;)Ljava/lang/Short; + public synthetic fun scale (Ljava/lang/Object;D)Ljava/lang/Object; + public fun scale (SD)Ljava/lang/Short; + public synthetic fun unaryMinus (Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryMinus (S)Ljava/lang/Short; +} + +public final class space/kscience/kmath/operations/Int16Ring : space/kscience/kmath/operations/Norm, space/kscience/kmath/operations/NumericAlgebra, space/kscience/kmath/operations/Ring { + public static final field INSTANCE Lspace/kscience/kmath/operations/Int16Ring; + public synthetic fun add (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun add (SS)Ljava/lang/Short; + public fun getBufferFactory ()Lspace/kscience/kmath/structures/MutableBufferFactory; + public synthetic fun getOne ()Ljava/lang/Object; + public fun getOne ()Ljava/lang/Short; + public synthetic fun getZero ()Ljava/lang/Object; + public fun getZero ()Ljava/lang/Short; + public synthetic fun minus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun minus (SS)Ljava/lang/Short; + public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun multiply (SS)Ljava/lang/Short; + public synthetic fun norm (Ljava/lang/Object;)Ljava/lang/Object; + public fun norm (S)Ljava/lang/Short; + public synthetic fun number (Ljava/lang/Number;)Ljava/lang/Object; + public fun number (Ljava/lang/Number;)Ljava/lang/Short; + public synthetic fun plus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun plus (SS)Ljava/lang/Short; + public synthetic fun times (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun times (SS)Ljava/lang/Short; + public synthetic fun unaryMinus (Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryMinus (S)Ljava/lang/Short; +} + +public final class space/kscience/kmath/operations/Int32Field : space/kscience/kmath/operations/Field, space/kscience/kmath/operations/Norm, space/kscience/kmath/operations/NumericAlgebra { + public static final field INSTANCE Lspace/kscience/kmath/operations/Int32Field; + public fun add (II)Ljava/lang/Integer; + public synthetic fun add (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun divide (II)Ljava/lang/Integer; + public synthetic fun divide (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun getBufferFactory ()Lspace/kscience/kmath/structures/MutableBufferFactory; + public fun getOne ()Ljava/lang/Integer; + public synthetic fun getOne ()Ljava/lang/Object; + public fun getZero ()Ljava/lang/Integer; + public synthetic fun getZero ()Ljava/lang/Object; + public fun multiply (II)Ljava/lang/Integer; + public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun norm (I)Ljava/lang/Integer; + public synthetic fun norm (Ljava/lang/Object;)Ljava/lang/Object; + public fun number (Ljava/lang/Number;)Ljava/lang/Integer; + public synthetic fun number (Ljava/lang/Number;)Ljava/lang/Object; + public fun scale (ID)Ljava/lang/Integer; + public synthetic fun scale (Ljava/lang/Object;D)Ljava/lang/Object; + public fun unaryMinus (I)Ljava/lang/Integer; + public synthetic fun unaryMinus (Ljava/lang/Object;)Ljava/lang/Object; +} + +public final class space/kscience/kmath/operations/Int32Ring : space/kscience/kmath/operations/Norm, space/kscience/kmath/operations/NumericAlgebra, space/kscience/kmath/operations/Ring { + public static final field INSTANCE Lspace/kscience/kmath/operations/Int32Ring; public fun add (II)Ljava/lang/Integer; public synthetic fun add (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; public fun getBufferFactory ()Lspace/kscience/kmath/structures/MutableBufferFactory; @@ -2010,6 +2139,79 @@ public final class space/kscience/kmath/operations/IntRing : space/kscience/kmat public synthetic fun unaryMinus (Ljava/lang/Object;)Ljava/lang/Object; } +public final class space/kscience/kmath/operations/Int64Field : space/kscience/kmath/operations/Field, space/kscience/kmath/operations/Norm, space/kscience/kmath/operations/NumericAlgebra { + public static final field INSTANCE Lspace/kscience/kmath/operations/Int64Field; + public fun add (JJ)Ljava/lang/Long; + public synthetic fun add (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun divide (JJ)Ljava/lang/Long; + public synthetic fun divide (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun getBufferFactory ()Lspace/kscience/kmath/structures/MutableBufferFactory; + public fun getOne ()Ljava/lang/Long; + public synthetic fun getOne ()Ljava/lang/Object; + public fun getZero ()Ljava/lang/Long; + public synthetic fun getZero ()Ljava/lang/Object; + public fun multiply (JJ)Ljava/lang/Long; + public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun norm (J)Ljava/lang/Long; + public synthetic fun norm (Ljava/lang/Object;)Ljava/lang/Object; + public fun number (Ljava/lang/Number;)Ljava/lang/Long; + public synthetic fun number (Ljava/lang/Number;)Ljava/lang/Object; + public fun scale (JD)Ljava/lang/Long; + public synthetic fun scale (Ljava/lang/Object;D)Ljava/lang/Object; + public fun unaryMinus (J)Ljava/lang/Long; + public synthetic fun unaryMinus (Ljava/lang/Object;)Ljava/lang/Object; +} + +public final class space/kscience/kmath/operations/Int64Ring : space/kscience/kmath/operations/Norm, space/kscience/kmath/operations/NumericAlgebra, space/kscience/kmath/operations/Ring { + public static final field INSTANCE Lspace/kscience/kmath/operations/Int64Ring; + public fun add (JJ)Ljava/lang/Long; + public synthetic fun add (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun getBufferFactory ()Lspace/kscience/kmath/structures/MutableBufferFactory; + public fun getOne ()Ljava/lang/Long; + public synthetic fun getOne ()Ljava/lang/Object; + public fun getZero ()Ljava/lang/Long; + public synthetic fun getZero ()Ljava/lang/Object; + public fun minus (JJ)Ljava/lang/Long; + public synthetic fun minus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun multiply (JJ)Ljava/lang/Long; + public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun norm (J)Ljava/lang/Long; + public synthetic fun norm (Ljava/lang/Object;)Ljava/lang/Object; + public fun number (Ljava/lang/Number;)Ljava/lang/Long; + public synthetic fun number (Ljava/lang/Number;)Ljava/lang/Object; + public fun plus (JJ)Ljava/lang/Long; + public synthetic fun plus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun times (JJ)Ljava/lang/Long; + public synthetic fun times (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryMinus (J)Ljava/lang/Long; + public synthetic fun unaryMinus (Ljava/lang/Object;)Ljava/lang/Object; +} + +public final class space/kscience/kmath/operations/Int8Ring : space/kscience/kmath/operations/Norm, space/kscience/kmath/operations/NumericAlgebra, space/kscience/kmath/operations/Ring { + public static final field INSTANCE Lspace/kscience/kmath/operations/Int8Ring; + public fun add (BB)Ljava/lang/Byte; + public synthetic fun add (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun getBufferFactory ()Lspace/kscience/kmath/structures/MutableBufferFactory; + public fun getOne ()Ljava/lang/Byte; + public synthetic fun getOne ()Ljava/lang/Object; + public fun getZero ()Ljava/lang/Byte; + public synthetic fun getZero ()Ljava/lang/Object; + public fun minus (BB)Ljava/lang/Byte; + public synthetic fun minus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun multiply (BB)Ljava/lang/Byte; + public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun norm (B)Ljava/lang/Byte; + public synthetic fun norm (Ljava/lang/Object;)Ljava/lang/Object; + public fun number (Ljava/lang/Number;)Ljava/lang/Byte; + public synthetic fun number (Ljava/lang/Number;)Ljava/lang/Object; + public fun plus (BB)Ljava/lang/Byte; + public synthetic fun plus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun times (BB)Ljava/lang/Byte; + public synthetic fun times (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryMinus (B)Ljava/lang/Byte; + public synthetic fun unaryMinus (Ljava/lang/Object;)Ljava/lang/Object; +} + public final class space/kscience/kmath/operations/IsIntegerKt { public static final fun isInteger (Ljava/lang/Number;)Z } @@ -2030,6 +2232,7 @@ public abstract class space/kscience/kmath/operations/JBigDecimalFieldBase : spa public fun add (Ljava/math/BigDecimal;Ljava/math/BigDecimal;)Ljava/math/BigDecimal; public synthetic fun divide (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; public fun divide (Ljava/math/BigDecimal;Ljava/math/BigDecimal;)Ljava/math/BigDecimal; + public fun getBufferFactory ()Lspace/kscience/kmath/structures/MutableBufferFactory; public synthetic fun getOne ()Ljava/lang/Object; public fun getOne ()Ljava/math/BigDecimal; public synthetic fun getZero ()Ljava/lang/Object; @@ -2054,6 +2257,7 @@ public final class space/kscience/kmath/operations/JBigIntegerField : space/ksci public static final field INSTANCE Lspace/kscience/kmath/operations/JBigIntegerField; public synthetic fun add (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; public fun add (Ljava/math/BigInteger;Ljava/math/BigInteger;)Ljava/math/BigInteger; + public fun getBufferFactory ()Lspace/kscience/kmath/structures/MutableBufferFactory; public synthetic fun getOne ()Ljava/lang/Object; public fun getOne ()Ljava/math/BigInteger; public synthetic fun getZero ()Ljava/lang/Object; @@ -2073,42 +2277,17 @@ public final class space/kscience/kmath/operations/LogicAlgebra$Companion { public final fun getTRUE ()Lspace/kscience/kmath/expressions/Symbol; } -public final class space/kscience/kmath/operations/LongRing : space/kscience/kmath/operations/Norm, space/kscience/kmath/operations/NumericAlgebra, space/kscience/kmath/operations/Ring { - public static final field INSTANCE Lspace/kscience/kmath/operations/LongRing; - public fun add (JJ)Ljava/lang/Long; - public synthetic fun add (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun getBufferFactory ()Lspace/kscience/kmath/structures/MutableBufferFactory; - public fun getOne ()Ljava/lang/Long; - public synthetic fun getOne ()Ljava/lang/Object; - public fun getZero ()Ljava/lang/Long; - public synthetic fun getZero ()Ljava/lang/Object; - public fun minus (JJ)Ljava/lang/Long; - public synthetic fun minus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun multiply (JJ)Ljava/lang/Long; - public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun norm (J)Ljava/lang/Long; - public synthetic fun norm (Ljava/lang/Object;)Ljava/lang/Object; - public fun number (Ljava/lang/Number;)Ljava/lang/Long; - public synthetic fun number (Ljava/lang/Number;)Ljava/lang/Object; - public fun plus (JJ)Ljava/lang/Long; - public synthetic fun plus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun times (JJ)Ljava/lang/Long; - public synthetic fun times (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun unaryMinus (J)Ljava/lang/Long; - public synthetic fun unaryMinus (Ljava/lang/Object;)Ljava/lang/Object; -} - public abstract interface class space/kscience/kmath/operations/Norm { public abstract fun norm (Ljava/lang/Object;)Ljava/lang/Object; } public final class space/kscience/kmath/operations/NumbersKt { - public static final fun getAlgebra (Lkotlin/jvm/internal/ByteCompanionObject;)Lspace/kscience/kmath/operations/ByteRing; - public static final fun getAlgebra (Lkotlin/jvm/internal/DoubleCompanionObject;)Lspace/kscience/kmath/operations/DoubleField; - public static final fun getAlgebra (Lkotlin/jvm/internal/FloatCompanionObject;)Lspace/kscience/kmath/operations/FloatField; - public static final fun getAlgebra (Lkotlin/jvm/internal/IntCompanionObject;)Lspace/kscience/kmath/operations/IntRing; - public static final fun getAlgebra (Lkotlin/jvm/internal/LongCompanionObject;)Lspace/kscience/kmath/operations/LongRing; - public static final fun getAlgebra (Lkotlin/jvm/internal/ShortCompanionObject;)Lspace/kscience/kmath/operations/ShortRing; + public static final fun getAlgebra (Lkotlin/jvm/internal/ByteCompanionObject;)Lspace/kscience/kmath/operations/Int8Ring; + public static final fun getAlgebra (Lkotlin/jvm/internal/DoubleCompanionObject;)Lspace/kscience/kmath/operations/Float64Field; + public static final fun getAlgebra (Lkotlin/jvm/internal/FloatCompanionObject;)Lspace/kscience/kmath/operations/Float32Field; + public static final fun getAlgebra (Lkotlin/jvm/internal/IntCompanionObject;)Lspace/kscience/kmath/operations/Int32Ring; + public static final fun getAlgebra (Lkotlin/jvm/internal/LongCompanionObject;)Lspace/kscience/kmath/operations/Int64Ring; + public static final fun getAlgebra (Lkotlin/jvm/internal/ShortCompanionObject;)Lspace/kscience/kmath/operations/Int16Ring; } public abstract interface class space/kscience/kmath/operations/NumericAlgebra : space/kscience/kmath/operations/Algebra { @@ -2125,7 +2304,7 @@ public final class space/kscience/kmath/operations/NumericAlgebraKt { public static final fun getPi (Lspace/kscience/kmath/operations/NumericAlgebra;)Ljava/lang/Object; } -public abstract interface class space/kscience/kmath/operations/PowerOperations : space/kscience/kmath/operations/FieldOps { +public abstract interface class space/kscience/kmath/operations/PowerOperations : space/kscience/kmath/operations/Algebra { public static final field Companion Lspace/kscience/kmath/operations/PowerOperations$Companion; public static final field POW_OPERATION Ljava/lang/String; public static final field SQRT_OPERATION Ljava/lang/String; @@ -2167,31 +2346,6 @@ public abstract interface class space/kscience/kmath/operations/ScaleOperations public fun times (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; } -public final class space/kscience/kmath/operations/ShortRing : space/kscience/kmath/operations/Norm, space/kscience/kmath/operations/NumericAlgebra, space/kscience/kmath/operations/Ring { - public static final field INSTANCE Lspace/kscience/kmath/operations/ShortRing; - public synthetic fun add (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun add (SS)Ljava/lang/Short; - public fun getBufferFactory ()Lspace/kscience/kmath/structures/MutableBufferFactory; - public synthetic fun getOne ()Ljava/lang/Object; - public fun getOne ()Ljava/lang/Short; - public synthetic fun getZero ()Ljava/lang/Object; - public fun getZero ()Ljava/lang/Short; - public synthetic fun minus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun minus (SS)Ljava/lang/Short; - public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun multiply (SS)Ljava/lang/Short; - public synthetic fun norm (Ljava/lang/Object;)Ljava/lang/Object; - public fun norm (S)Ljava/lang/Short; - public synthetic fun number (Ljava/lang/Number;)Ljava/lang/Object; - public fun number (Ljava/lang/Number;)Ljava/lang/Short; - public synthetic fun plus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun plus (SS)Ljava/lang/Short; - public synthetic fun times (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun times (SS)Ljava/lang/Short; - public synthetic fun unaryMinus (Ljava/lang/Object;)Ljava/lang/Object; - public fun unaryMinus (S)Ljava/lang/Short; -} - public abstract interface class space/kscience/kmath/operations/TrigonometricOperations : space/kscience/kmath/operations/Algebra { public static final field ACOS_OPERATION Ljava/lang/String; public static final field ASIN_OPERATION Ljava/lang/String; @@ -2222,20 +2376,21 @@ public abstract interface class space/kscience/kmath/operations/WithSize { } public final class space/kscience/kmath/structures/ArrayBuffer : space/kscience/kmath/structures/MutableBuffer { - public fun ([Ljava/lang/Object;)V + public synthetic fun (Lkotlin/reflect/KType;[Ljava/lang/Object;Lkotlin/jvm/internal/DefaultConstructorMarker;)V public fun copy ()Lspace/kscience/kmath/structures/MutableBuffer; public fun get (I)Ljava/lang/Object; public fun getSize ()I + public fun getType-V0oMfBY ()Lkotlin/reflect/KType; public fun iterator ()Ljava/util/Iterator; public fun set (ILjava/lang/Object;)V public fun toString ()Ljava/lang/String; } public final class space/kscience/kmath/structures/ArrayBufferKt { - public static final fun asBuffer ([Ljava/lang/Object;)Lspace/kscience/kmath/structures/ArrayBuffer; + public static final fun asBuffer-Fnn_obI ([Ljava/lang/Object;Lkotlin/reflect/KType;)Lspace/kscience/kmath/structures/ArrayBuffer; } -public abstract interface class space/kscience/kmath/structures/Buffer : space/kscience/kmath/operations/WithSize { +public abstract interface class space/kscience/kmath/structures/Buffer : space/kscience/attributes/WithType, space/kscience/kmath/operations/WithSize { public static final field Companion Lspace/kscience/kmath/structures/Buffer$Companion; public abstract fun get (I)Ljava/lang/Object; public abstract fun getSize ()I @@ -2244,8 +2399,6 @@ public abstract interface class space/kscience/kmath/structures/Buffer : space/k } public final class space/kscience/kmath/structures/Buffer$Companion { - public final fun auto (Lkotlin/reflect/KClass;ILkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/structures/Buffer; - public final fun boxing (ILkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/structures/Buffer; public final fun contentEquals (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/Buffer;)Z public final fun toString (Lspace/kscience/kmath/structures/Buffer;)Ljava/lang/String; } @@ -2260,17 +2413,14 @@ public final class space/kscience/kmath/structures/BufferExpanded : space/kscien public fun toString ()Ljava/lang/String; } -public abstract interface class space/kscience/kmath/structures/BufferFactory { - public static final field Companion Lspace/kscience/kmath/structures/BufferFactory$Companion; +public abstract interface class space/kscience/kmath/structures/BufferFactory : space/kscience/attributes/WithType { public abstract fun invoke (ILkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/structures/Buffer; } -public final class space/kscience/kmath/structures/BufferFactory$Companion { - public final fun boxing ()Lspace/kscience/kmath/structures/BufferFactory; -} - public final class space/kscience/kmath/structures/BufferKt { - public static final fun asReadOnly (Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public static final fun Buffer--rwW0uw (Lkotlin/reflect/KType;ILkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/structures/Buffer; + public static final fun BufferFactory-X0YbwmU (Lkotlin/reflect/KType;)Lspace/kscience/kmath/structures/BufferFactory; + public static final fun MutableBufferFactory-X0YbwmU (Lkotlin/reflect/KType;)Lspace/kscience/kmath/structures/MutableBufferFactory; public static final fun first (Lspace/kscience/kmath/structures/Buffer;)Ljava/lang/Object; public static final fun get-Qn1smSk (Lspace/kscience/kmath/structures/Buffer;I)Ljava/lang/Object; public static final fun getIndices (Lspace/kscience/kmath/structures/Buffer;)Lkotlin/ranges/IntRange; @@ -2278,6 +2428,10 @@ public final class space/kscience/kmath/structures/BufferKt { public static final fun last (Lspace/kscience/kmath/structures/Buffer;)Ljava/lang/Object; } +public final class space/kscience/kmath/structures/BufferListKt { + public static final fun asList (Lspace/kscience/kmath/structures/Buffer;)Ljava/util/List; +} + public final class space/kscience/kmath/structures/BufferPrimitiveAccessKt { } @@ -2295,6 +2449,7 @@ public final class space/kscience/kmath/structures/BufferSlice : space/kscience/ public abstract interface class space/kscience/kmath/structures/BufferView : space/kscience/kmath/structures/Buffer { public fun get (I)Ljava/lang/Object; public abstract fun getOrigin ()Lspace/kscience/kmath/structures/Buffer; + public fun getType-V0oMfBY ()Lkotlin/reflect/KType; } public final class space/kscience/kmath/structures/BufferViewKt { @@ -2304,87 +2459,6 @@ public final class space/kscience/kmath/structures/BufferViewKt { public static final fun slice (Lspace/kscience/kmath/structures/Buffer;Lkotlin/ranges/IntRange;)Lspace/kscience/kmath/structures/BufferView; } -public final class space/kscience/kmath/structures/ByteBuffer : space/kscience/kmath/structures/MutableBuffer { - public static final synthetic fun box-impl ([B)Lspace/kscience/kmath/structures/ByteBuffer; - public static fun constructor-impl ([B)[B - public fun copy ()Lspace/kscience/kmath/structures/MutableBuffer; - public static fun copy-impl ([B)Lspace/kscience/kmath/structures/MutableBuffer; - public fun equals (Ljava/lang/Object;)Z - public static fun equals-impl ([BLjava/lang/Object;)Z - public static final fun equals-impl0 ([B[B)Z - public fun get (I)Ljava/lang/Byte; - public synthetic fun get (I)Ljava/lang/Object; - public static fun get-impl ([BI)Ljava/lang/Byte; - public final fun getArray ()[B - public fun getSize ()I - public static fun getSize-impl ([B)I - public fun hashCode ()I - public static fun hashCode-impl ([B)I - public synthetic fun iterator ()Ljava/util/Iterator; - public fun iterator ()Lkotlin/collections/ByteIterator; - public static fun iterator-impl ([B)Lkotlin/collections/ByteIterator; - public fun set (IB)V - public synthetic fun set (ILjava/lang/Object;)V - public static fun set-impl ([BIB)V - public fun toString ()Ljava/lang/String; - public static fun toString-impl ([B)Ljava/lang/String; - public final synthetic fun unbox-impl ()[B -} - -public final class space/kscience/kmath/structures/ByteBufferKt { - public static final fun ByteBuffer (ILkotlin/jvm/functions/Function1;)[B - public static final fun ByteBuffer ([B)[B - public static final fun asBuffer ([B)[B - public static final fun toByteArray (Lspace/kscience/kmath/structures/Buffer;)[B -} - -public final class space/kscience/kmath/structures/DoubleBuffer : space/kscience/kmath/structures/PrimitiveBuffer { - public static final field Companion Lspace/kscience/kmath/structures/DoubleBuffer$Companion; - public static final synthetic fun box-impl ([D)Lspace/kscience/kmath/structures/DoubleBuffer; - public static fun constructor-impl ([D)[D - 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/DoubleBuffer$Companion { - public final fun zero-Udx-57Q (I)[D -} - -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 toDoubleArray (Lspace/kscience/kmath/structures/Buffer;)[D - public static final fun toDoubleBuffer (Lspace/kscience/kmath/structures/Buffer;)[D -} - -public abstract interface class space/kscience/kmath/structures/DoubleBufferTransform : space/kscience/kmath/operations/BufferTransform { - public synthetic fun transform (Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; - public abstract fun transform-7Zdoou4 ([D)[D - public fun transform-Udx-57Q (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 } @@ -2403,13 +2477,14 @@ public final class space/kscience/kmath/structures/FlaggedDoubleBuffer : space/k public fun getFlag (I)B public final fun getFlags ()[B public fun getSize ()I + public fun getType-V0oMfBY ()Lkotlin/reflect/KType; public final fun getValues ()[D public fun iterator ()Ljava/util/Iterator; public fun toString ()Ljava/lang/String; } -public final class space/kscience/kmath/structures/FloatBuffer : space/kscience/kmath/structures/PrimitiveBuffer { - public static final synthetic fun box-impl ([F)Lspace/kscience/kmath/structures/FloatBuffer; +public final class space/kscience/kmath/structures/Float32Buffer : space/kscience/kmath/structures/PrimitiveBuffer { + public static final synthetic fun box-impl ([F)Lspace/kscience/kmath/structures/Float32Buffer; public static fun constructor-impl ([F)[F public fun copy ()Lspace/kscience/kmath/structures/MutableBuffer; public static fun copy-impl ([F)Lspace/kscience/kmath/structures/MutableBuffer; @@ -2422,6 +2497,8 @@ public final class space/kscience/kmath/structures/FloatBuffer : space/kscience/ public final fun getArray ()[F public fun getSize ()I public static fun getSize-impl ([F)I + public fun getType-V0oMfBY ()Lkotlin/reflect/KType; + public static fun getType-V0oMfBY ([F)Lkotlin/reflect/KType; public fun hashCode ()I public static fun hashCode-impl ([F)I public synthetic fun iterator ()Ljava/util/Iterator; @@ -2435,19 +2512,104 @@ public final class space/kscience/kmath/structures/FloatBuffer : space/kscience/ public final synthetic fun unbox-impl ()[F } -public final class space/kscience/kmath/structures/FloatBufferKt { - public static final fun FloatBuffer (ILkotlin/jvm/functions/Function1;)[F - public static final fun FloatBuffer ([F)[F +public final class space/kscience/kmath/structures/Float32BufferKt { + public static final fun Float32Buffer (ILkotlin/jvm/functions/Function1;)[F + public static final fun Float32Buffer ([F)[F public static final fun asBuffer ([F)[F public static final fun toFloatArray (Lspace/kscience/kmath/structures/Buffer;)[F } -public final class space/kscience/kmath/structures/IntBuffer : space/kscience/kmath/structures/PrimitiveBuffer { - public static final synthetic fun box-impl ([I)Lspace/kscience/kmath/structures/IntBuffer; +public final class space/kscience/kmath/structures/Float64Buffer : space/kscience/kmath/structures/PrimitiveBuffer { + public static final field Companion Lspace/kscience/kmath/structures/Float64Buffer$Companion; + public static final synthetic fun box-impl ([D)Lspace/kscience/kmath/structures/Float64Buffer; + public static fun constructor-impl ([D)[D + public synthetic fun copy ()Lspace/kscience/kmath/structures/MutableBuffer; + public fun copy-E20IKn8 ()[D + public static fun copy-E20IKn8 ([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 getType-V0oMfBY ()Lkotlin/reflect/KType; + public static fun getType-V0oMfBY ([D)Lkotlin/reflect/KType; + 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/Float64Buffer$Companion { + public final fun zero-qFCK38E (I)[D +} + +public final class space/kscience/kmath/structures/Float64BufferKt { + public static final fun Float64Buffer (ILkotlin/jvm/functions/Function1;)[D + public static final fun Float64Buffer ([D)[D + public static final fun asBuffer ([D)[D + public static final fun toDoubleArray (Lspace/kscience/kmath/structures/Buffer;)[D + public static final fun toFloat64Buffer (Lspace/kscience/kmath/structures/Buffer;)[D +} + +public abstract interface class space/kscience/kmath/structures/Float64BufferTransform : space/kscience/kmath/operations/BufferTransform { + public synthetic fun transform (Lspace/kscience/kmath/structures/Buffer;)Lspace/kscience/kmath/structures/Buffer; + public abstract fun transform-kPrB3XE ([D)[D + public fun transform-qFCK38E (Lspace/kscience/kmath/structures/Buffer;)[D +} + +public final class space/kscience/kmath/structures/Int16Buffer : space/kscience/kmath/structures/MutableBuffer { + public static final synthetic fun box-impl ([S)Lspace/kscience/kmath/structures/Int16Buffer; + public static fun constructor-impl ([S)[S + public fun copy ()Lspace/kscience/kmath/structures/MutableBuffer; + public static fun copy-impl ([S)Lspace/kscience/kmath/structures/MutableBuffer; + public fun equals (Ljava/lang/Object;)Z + public static fun equals-impl ([SLjava/lang/Object;)Z + public static final fun equals-impl0 ([S[S)Z + public synthetic fun get (I)Ljava/lang/Object; + public fun get (I)Ljava/lang/Short; + public static fun get-impl ([SI)Ljava/lang/Short; + public final fun getArray ()[S + public fun getSize ()I + public static fun getSize-impl ([S)I + public fun getType-V0oMfBY ()Lkotlin/reflect/KType; + public static fun getType-V0oMfBY ([S)Lkotlin/reflect/KType; + public fun hashCode ()I + public static fun hashCode-impl ([S)I + public synthetic fun iterator ()Ljava/util/Iterator; + public fun iterator ()Lkotlin/collections/ShortIterator; + public static fun iterator-impl ([S)Lkotlin/collections/ShortIterator; + public synthetic fun set (ILjava/lang/Object;)V + public fun set (IS)V + public static fun set-impl ([SIS)V + public fun toString ()Ljava/lang/String; + public static fun toString-impl ([S)Ljava/lang/String; + public final synthetic fun unbox-impl ()[S +} + +public final class space/kscience/kmath/structures/Int16BufferKt { + public static final fun Int16Buffer (ILkotlin/jvm/functions/Function1;)[S + public static final fun Int16Buffer ([S)[S + public static final fun asBuffer ([S)[S + public static final fun toShortArray (Lspace/kscience/kmath/structures/Buffer;)[S +} + +public final class space/kscience/kmath/structures/Int32Buffer : space/kscience/kmath/structures/PrimitiveBuffer { + public static final synthetic fun box-impl ([I)Lspace/kscience/kmath/structures/Int32Buffer; public static fun constructor-impl ([I)[I public synthetic fun copy ()Lspace/kscience/kmath/structures/MutableBuffer; - public fun copy-ir4F4A8 ()[I - public static fun copy-ir4F4A8 ([I)[I + public fun copy-M_oXE9g ()[I + public static fun copy-M_oXE9g ([I)[I public fun equals (Ljava/lang/Object;)Z public static fun equals-impl ([ILjava/lang/Object;)Z public static final fun equals-impl0 ([I[I)Z @@ -2457,6 +2619,8 @@ public final class space/kscience/kmath/structures/IntBuffer : space/kscience/km public final fun getArray ()[I public fun getSize ()I public static fun getSize-impl ([I)I + public fun getType-V0oMfBY ()Lkotlin/reflect/KType; + public static fun getType-V0oMfBY ([I)Lkotlin/reflect/KType; public fun hashCode ()I public static fun hashCode-impl ([I)I public synthetic fun iterator ()Ljava/util/Iterator; @@ -2470,30 +2634,15 @@ public final class space/kscience/kmath/structures/IntBuffer : space/kscience/km public final synthetic fun unbox-impl ()[I } -public final class space/kscience/kmath/structures/IntBufferKt { - public static final fun IntBuffer (ILkotlin/jvm/functions/Function1;)[I - public static final fun IntBuffer ([I)[I +public final class space/kscience/kmath/structures/Int32BufferKt { + public static final fun Int32Buffer (ILkotlin/jvm/functions/Function1;)[I + public static final fun Int32Buffer ([I)[I public static final fun asBuffer ([I)[I public static final fun toIntArray (Lspace/kscience/kmath/structures/Buffer;)[I } -public final class space/kscience/kmath/structures/ListBuffer : space/kscience/kmath/structures/Buffer { - public fun (ILkotlin/jvm/functions/Function1;)V - public fun (Ljava/util/List;)V - public fun get (I)Ljava/lang/Object; - public final fun getList ()Ljava/util/List; - public fun getSize ()I - public fun iterator ()Ljava/util/Iterator; - public fun toString ()Ljava/lang/String; -} - -public final class space/kscience/kmath/structures/ListBufferKt { - public static final fun asBuffer (Ljava/util/List;)Lspace/kscience/kmath/structures/ListBuffer; - public static final fun asMutableBuffer (Ljava/util/List;)Ljava/util/List; -} - -public final class space/kscience/kmath/structures/LongBuffer : space/kscience/kmath/structures/PrimitiveBuffer { - public static final synthetic fun box-impl ([J)Lspace/kscience/kmath/structures/LongBuffer; +public final class space/kscience/kmath/structures/Int64Buffer : space/kscience/kmath/structures/PrimitiveBuffer { + public static final synthetic fun box-impl ([J)Lspace/kscience/kmath/structures/Int64Buffer; public static fun constructor-impl ([J)[J public fun copy ()Lspace/kscience/kmath/structures/MutableBuffer; public static fun copy-impl ([J)Lspace/kscience/kmath/structures/MutableBuffer; @@ -2506,6 +2655,8 @@ public final class space/kscience/kmath/structures/LongBuffer : space/kscience/k public final fun getArray ()[J public fun getSize ()I public static fun getSize-impl ([J)I + public fun getType-V0oMfBY ()Lkotlin/reflect/KType; + public static fun getType-V0oMfBY ([J)Lkotlin/reflect/KType; public fun hashCode ()I public static fun hashCode-impl ([J)I public synthetic fun iterator ()Ljava/util/Iterator; @@ -2519,27 +2670,62 @@ public final class space/kscience/kmath/structures/LongBuffer : space/kscience/k public final synthetic fun unbox-impl ()[J } -public final class space/kscience/kmath/structures/LongBufferKt { - public static final fun LongBuffer (ILkotlin/jvm/functions/Function1;)[J - public static final fun LongBuffer ([J)[J +public final class space/kscience/kmath/structures/Int64BufferKt { + public static final fun Int64Buffer (ILkotlin/jvm/functions/Function1;)[J + public static final fun Int64Buffer ([J)[J public static final fun asBuffer ([J)[J public static final fun toLongArray (Lspace/kscience/kmath/structures/Buffer;)[J } -public class space/kscience/kmath/structures/MemoryBuffer : space/kscience/kmath/structures/Buffer { - public static final field Companion Lspace/kscience/kmath/structures/MemoryBuffer$Companion; - public fun (Lspace/kscience/kmath/memory/Memory;Lspace/kscience/kmath/memory/MemorySpec;)V - public fun get (I)Ljava/lang/Object; - protected final fun getMemory ()Lspace/kscience/kmath/memory/Memory; +public final class space/kscience/kmath/structures/Int8Buffer : space/kscience/kmath/structures/MutableBuffer { + public static final synthetic fun box-impl ([B)Lspace/kscience/kmath/structures/Int8Buffer; + public static fun constructor-impl ([B)[B + public fun copy ()Lspace/kscience/kmath/structures/MutableBuffer; + public static fun copy-impl ([B)Lspace/kscience/kmath/structures/MutableBuffer; + public fun equals (Ljava/lang/Object;)Z + public static fun equals-impl ([BLjava/lang/Object;)Z + public static final fun equals-impl0 ([B[B)Z + public fun get (I)Ljava/lang/Byte; + public synthetic fun get (I)Ljava/lang/Object; + public static fun get-impl ([BI)Ljava/lang/Byte; + public final fun getArray ()[B public fun getSize ()I - protected final fun getSpec ()Lspace/kscience/kmath/memory/MemorySpec; + public static fun getSize-impl ([B)I + public fun getType-V0oMfBY ()Lkotlin/reflect/KType; + public static fun getType-V0oMfBY ([B)Lkotlin/reflect/KType; + public fun hashCode ()I + public static fun hashCode-impl ([B)I + public synthetic fun iterator ()Ljava/util/Iterator; + public fun iterator ()Lkotlin/collections/ByteIterator; + public static fun iterator-impl ([B)Lkotlin/collections/ByteIterator; + public fun set (IB)V + public synthetic fun set (ILjava/lang/Object;)V + public static fun set-impl ([BIB)V + public fun toString ()Ljava/lang/String; + public static fun toString-impl ([B)Ljava/lang/String; + public final synthetic fun unbox-impl ()[B +} + +public final class space/kscience/kmath/structures/Int8BufferKt { + public static final fun Int8Buffer (ILkotlin/jvm/functions/Function1;)[B + public static final fun Int8Buffer ([B)[B + public static final fun asBuffer ([B)[B + public static final fun toByteArray (Lspace/kscience/kmath/structures/Buffer;)[B +} + +public final class space/kscience/kmath/structures/ListBuffer : space/kscience/kmath/structures/Buffer { + public synthetic fun (Lkotlin/reflect/KType;Ljava/util/List;Lkotlin/jvm/internal/DefaultConstructorMarker;)V + public fun get (I)Ljava/lang/Object; + public final fun getList ()Ljava/util/List; + public fun getSize ()I + public fun getType-V0oMfBY ()Lkotlin/reflect/KType; public fun iterator ()Ljava/util/Iterator; public fun toString ()Ljava/lang/String; } -public final class space/kscience/kmath/structures/MemoryBuffer$Companion { - public final fun create (Lspace/kscience/kmath/memory/MemorySpec;I)Lspace/kscience/kmath/structures/MemoryBuffer; - public final fun create (Lspace/kscience/kmath/memory/MemorySpec;ILkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/structures/MemoryBuffer; +public final class space/kscience/kmath/structures/ListBufferKt { + public static final fun asBuffer-Fnn_obI (Ljava/util/List;Lkotlin/reflect/KType;)Lspace/kscience/kmath/structures/ListBuffer; + public static final fun asMutableBuffer-Fnn_obI (Ljava/util/List;Lkotlin/reflect/KType;)Lspace/kscience/kmath/structures/MutableListBuffer; } public abstract interface class space/kscience/kmath/structures/MutableBuffer : space/kscience/kmath/structures/Buffer { @@ -2549,13 +2735,11 @@ 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 short-1yRgbGw (ILkotlin/jvm/functions/Function1;)[S + public final fun double-Vq5tpWc (ILkotlin/jvm/functions/Function1;)[D + public final fun float-pmys_WE (ILkotlin/jvm/functions/Function1;)[F + public final fun int-Tednjrs (ILkotlin/jvm/functions/Function1;)[I + public final fun long-1n4IcUs (ILkotlin/jvm/functions/Function1;)[J + public final fun short-CjmdtSE (ILkotlin/jvm/functions/Function1;)[S } public abstract interface class space/kscience/kmath/structures/MutableBufferFactory : space/kscience/kmath/structures/BufferFactory { @@ -2564,44 +2748,34 @@ public abstract interface class space/kscience/kmath/structures/MutableBufferFac } public final class space/kscience/kmath/structures/MutableBufferFactory$Companion { - public final fun boxing ()Lspace/kscience/kmath/structures/MutableBufferFactory; +} + +public final class space/kscience/kmath/structures/MutableBufferKt { + public static final fun MutableBuffer--rwW0uw (Lkotlin/reflect/KType;ILkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/structures/MutableBuffer; } public final class space/kscience/kmath/structures/MutableListBuffer : space/kscience/kmath/structures/MutableBuffer { - public static final synthetic fun box-impl (Ljava/util/List;)Lspace/kscience/kmath/structures/MutableListBuffer; - public static fun constructor-impl (ILkotlin/jvm/functions/Function1;)Ljava/util/List; - public static fun constructor-impl (Ljava/util/List;)Ljava/util/List; + public synthetic fun (Lkotlin/reflect/KType;Ljava/util/List;Lkotlin/jvm/internal/DefaultConstructorMarker;)V public fun copy ()Lspace/kscience/kmath/structures/MutableBuffer; - public static fun copy-impl (Ljava/util/List;)Lspace/kscience/kmath/structures/MutableBuffer; - public fun equals (Ljava/lang/Object;)Z - public static fun equals-impl (Ljava/util/List;Ljava/lang/Object;)Z - public static final fun equals-impl0 (Ljava/util/List;Ljava/util/List;)Z public fun get (I)Ljava/lang/Object; - public static fun get-impl (Ljava/util/List;I)Ljava/lang/Object; public final fun getList ()Ljava/util/List; public fun getSize ()I - public static fun getSize-impl (Ljava/util/List;)I - public fun hashCode ()I - public static fun hashCode-impl (Ljava/util/List;)I + public fun getType-V0oMfBY ()Lkotlin/reflect/KType; public fun iterator ()Ljava/util/Iterator; - public static fun iterator-impl (Ljava/util/List;)Ljava/util/Iterator; public fun set (ILjava/lang/Object;)V - public static fun set-impl (Ljava/util/List;ILjava/lang/Object;)V public fun toString ()Ljava/lang/String; - public static fun toString-impl (Ljava/util/List;)Ljava/lang/String; - public final synthetic fun unbox-impl ()Ljava/util/List; } -public final class space/kscience/kmath/structures/MutableMemoryBuffer : space/kscience/kmath/structures/MemoryBuffer, space/kscience/kmath/structures/MutableBuffer { - public static final field Companion Lspace/kscience/kmath/structures/MutableMemoryBuffer$Companion; - public fun (Lspace/kscience/kmath/memory/Memory;Lspace/kscience/kmath/memory/MemorySpec;)V - public fun copy ()Lspace/kscience/kmath/structures/MutableBuffer; - public fun set (ILjava/lang/Object;)V +public final class space/kscience/kmath/structures/ParallelBufferFactory : space/kscience/kmath/structures/MutableBufferFactory { + public synthetic fun (Lkotlin/reflect/KType;Lkotlin/jvm/internal/DefaultConstructorMarker;)V + public fun getType-V0oMfBY ()Lkotlin/reflect/KType; + public synthetic fun invoke (ILkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/structures/Buffer; + public fun invoke (ILkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/structures/MutableBuffer; } -public final class space/kscience/kmath/structures/MutableMemoryBuffer$Companion { - public final fun create (Lspace/kscience/kmath/memory/MemorySpec;I)Lspace/kscience/kmath/structures/MutableMemoryBuffer; - public final fun create (Lspace/kscience/kmath/memory/MemorySpec;ILkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/structures/MutableMemoryBuffer; +public final class space/kscience/kmath/structures/ParallelMutableBufferKt { + public static final fun parallel-Fnn_obI (Lspace/kscience/kmath/structures/MutableBufferFactory$Companion;Lkotlin/reflect/KType;)Lspace/kscience/kmath/structures/MutableBufferFactory; + public static final fun parallel-wcOc40k (Lspace/kscience/kmath/structures/MutableBuffer$Companion;Lkotlin/reflect/KType;ILkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/structures/MutableBuffer; } public final class space/kscience/kmath/structures/PermutedBuffer : space/kscience/kmath/structures/BufferView { @@ -2628,74 +2802,22 @@ public final class space/kscience/kmath/structures/PermutedMutableBuffer : space public abstract interface class space/kscience/kmath/structures/PrimitiveBuffer : space/kscience/kmath/structures/MutableBuffer { } -public final class space/kscience/kmath/structures/ReadOnlyBuffer : space/kscience/kmath/structures/Buffer { - public static final synthetic fun box-impl (Lspace/kscience/kmath/structures/MutableBuffer;)Lspace/kscience/kmath/structures/ReadOnlyBuffer; - public static fun constructor-impl (Lspace/kscience/kmath/structures/MutableBuffer;)Lspace/kscience/kmath/structures/MutableBuffer; - public fun equals (Ljava/lang/Object;)Z - public static fun equals-impl (Lspace/kscience/kmath/structures/MutableBuffer;Ljava/lang/Object;)Z - public static final fun equals-impl0 (Lspace/kscience/kmath/structures/MutableBuffer;Lspace/kscience/kmath/structures/MutableBuffer;)Z - public fun get (I)Ljava/lang/Object; - public static fun get-impl (Lspace/kscience/kmath/structures/MutableBuffer;I)Ljava/lang/Object; - public final fun getBuffer ()Lspace/kscience/kmath/structures/MutableBuffer; - public fun getSize ()I - public static fun getSize-impl (Lspace/kscience/kmath/structures/MutableBuffer;)I - public fun hashCode ()I - public static fun hashCode-impl (Lspace/kscience/kmath/structures/MutableBuffer;)I - public fun iterator ()Ljava/util/Iterator; - public static fun iterator-impl (Lspace/kscience/kmath/structures/MutableBuffer;)Ljava/util/Iterator; - public fun toString ()Ljava/lang/String; - public static fun toString-impl (Lspace/kscience/kmath/structures/MutableBuffer;)Ljava/lang/String; - public final synthetic fun unbox-impl ()Lspace/kscience/kmath/structures/MutableBuffer; -} - -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 - public fun copy ()Lspace/kscience/kmath/structures/MutableBuffer; - public static fun copy-impl ([S)Lspace/kscience/kmath/structures/MutableBuffer; - public fun equals (Ljava/lang/Object;)Z - public static fun equals-impl ([SLjava/lang/Object;)Z - public static final fun equals-impl0 ([S[S)Z - public synthetic fun get (I)Ljava/lang/Object; - public fun get (I)Ljava/lang/Short; - public static fun get-impl ([SI)Ljava/lang/Short; - public final fun getArray ()[S - public fun getSize ()I - public static fun getSize-impl ([S)I - public fun hashCode ()I - public static fun hashCode-impl ([S)I - public synthetic fun iterator ()Ljava/util/Iterator; - public fun iterator ()Lkotlin/collections/ShortIterator; - public static fun iterator-impl ([S)Lkotlin/collections/ShortIterator; - public synthetic fun set (ILjava/lang/Object;)V - public fun set (IS)V - public static fun set-impl ([SIS)V - public fun toString ()Ljava/lang/String; - public static fun toString-impl ([S)Ljava/lang/String; - public final synthetic fun unbox-impl ()[S -} - -public final class space/kscience/kmath/structures/ShortBufferKt { - public static final fun ShortBuffer (ILkotlin/jvm/functions/Function1;)[S - public static final fun ShortBuffer ([S)[S - public static final fun asBuffer ([S)[S - public static final fun toShortArray (Lspace/kscience/kmath/structures/Buffer;)[S -} - public final class space/kscience/kmath/structures/ValueFlag : java/lang/Enum { public static final field MISSING Lspace/kscience/kmath/structures/ValueFlag; public static final field NAN Lspace/kscience/kmath/structures/ValueFlag; public static final field NEGATIVE_INFINITY Lspace/kscience/kmath/structures/ValueFlag; public static final field POSITIVE_INFINITY Lspace/kscience/kmath/structures/ValueFlag; + public static fun getEntries ()Lkotlin/enums/EnumEntries; public final fun getMask ()B public static fun valueOf (Ljava/lang/String;)Lspace/kscience/kmath/structures/ValueFlag; public static fun values ()[Lspace/kscience/kmath/structures/ValueFlag; } public final class space/kscience/kmath/structures/VirtualBuffer : space/kscience/kmath/structures/Buffer { - public fun (ILkotlin/jvm/functions/Function1;)V + public synthetic fun (Lkotlin/reflect/KType;ILkotlin/jvm/functions/Function1;Lkotlin/jvm/internal/DefaultConstructorMarker;)V public fun get (I)Ljava/lang/Object; public fun getSize ()I + public fun getType-V0oMfBY ()Lkotlin/reflect/KType; public fun iterator ()Ljava/util/Iterator; public fun toString ()Ljava/lang/String; } diff --git a/kmath-core/build.gradle.kts b/kmath-core/build.gradle.kts index 23fedbda4..0e061c6dd 100644 --- a/kmath-core/build.gradle.kts +++ b/kmath-core/build.gradle.kts @@ -71,4 +71,12 @@ readme { id = "autodiff", ref = "src/commonMain/kotlin/space/kscience/kmath/expressions/SimpleAutoDiff.kt" ) { "Automatic differentiation" } + + feature( + id="Parallel linear algebra" + ){ + """ + Parallel implementation for `LinearAlgebra` + """.trimIndent() + } } diff --git a/kmath-coroutines/README.md b/kmath-coroutines/README.md index 21831e514..4b7081bb1 100644 --- a/kmath-coroutines/README.md +++ b/kmath-coroutines/README.md @@ -6,19 +6,8 @@ ## Artifact: -The Maven coordinates of this project are `space.kscience:kmath-coroutines:0.4.0-dev-1`. +The Maven coordinates of this project are `space.kscience:kmath-coroutines:0.4.0-dev-3`. -**Gradle Groovy:** -```groovy -repositories { - maven { url 'https://repo.kotlin.link' } - mavenCentral() -} - -dependencies { - implementation 'space.kscience:kmath-coroutines:0.4.0-dev-1' -} -``` **Gradle Kotlin DSL:** ```kotlin repositories { @@ -27,6 +16,6 @@ repositories { } dependencies { - implementation("space.kscience:kmath-coroutines:0.4.0-dev-1") + implementation("space.kscience:kmath-coroutines:0.4.0-dev-3") } ``` diff --git a/kmath-dimensions/README.md b/kmath-dimensions/README.md index 2e7250b51..c1c5e0dc2 100644 --- a/kmath-dimensions/README.md +++ b/kmath-dimensions/README.md @@ -6,19 +6,8 @@ A proof of concept module for adding type-safe dimensions to structures ## Artifact: -The Maven coordinates of this project are `space.kscience:kmath-dimensions:0.4.0-dev-1`. +The Maven coordinates of this project are `space.kscience:kmath-dimensions:0.4.0-dev-3`. -**Gradle Groovy:** -```groovy -repositories { - maven { url 'https://repo.kotlin.link' } - mavenCentral() -} - -dependencies { - implementation 'space.kscience:kmath-dimensions:0.4.0-dev-1' -} -``` **Gradle Kotlin DSL:** ```kotlin repositories { @@ -27,6 +16,6 @@ repositories { } dependencies { - implementation("space.kscience:kmath-dimensions:0.4.0-dev-1") + implementation("space.kscience:kmath-dimensions:0.4.0-dev-3") } ``` diff --git a/kmath-ejml/README.md b/kmath-ejml/README.md index ad80ba183..dcde8efd3 100644 --- a/kmath-ejml/README.md +++ b/kmath-ejml/README.md @@ -9,19 +9,8 @@ EJML based linear algebra implementation. ## Artifact: -The Maven coordinates of this project are `space.kscience:kmath-ejml:0.4.0-dev-1`. +The Maven coordinates of this project are `space.kscience:kmath-ejml:0.4.0-dev-3`. -**Gradle Groovy:** -```groovy -repositories { - maven { url 'https://repo.kotlin.link' } - mavenCentral() -} - -dependencies { - implementation 'space.kscience:kmath-ejml:0.4.0-dev-1' -} -``` **Gradle Kotlin DSL:** ```kotlin repositories { @@ -30,6 +19,6 @@ repositories { } dependencies { - implementation("space.kscience:kmath-ejml:0.4.0-dev-1") + implementation("space.kscience:kmath-ejml:0.4.0-dev-3") } ``` diff --git a/kmath-for-real/README.md b/kmath-for-real/README.md index 638b15bfa..2c880f4f9 100644 --- a/kmath-for-real/README.md +++ b/kmath-for-real/README.md @@ -9,19 +9,8 @@ Specialization of KMath APIs for Double numbers. ## Artifact: -The Maven coordinates of this project are `space.kscience:kmath-for-real:0.4.0-dev-1`. +The Maven coordinates of this project are `space.kscience:kmath-for-real:0.4.0-dev-3`. -**Gradle Groovy:** -```groovy -repositories { - maven { url 'https://repo.kotlin.link' } - mavenCentral() -} - -dependencies { - implementation 'space.kscience:kmath-for-real:0.4.0-dev-1' -} -``` **Gradle Kotlin DSL:** ```kotlin repositories { @@ -30,6 +19,6 @@ repositories { } dependencies { - implementation("space.kscience:kmath-for-real:0.4.0-dev-1") + implementation("space.kscience:kmath-for-real:0.4.0-dev-3") } ``` diff --git a/kmath-functions/README.md b/kmath-functions/README.md index 929fd9172..1ee4149bd 100644 --- a/kmath-functions/README.md +++ b/kmath-functions/README.md @@ -11,19 +11,8 @@ Functions and interpolations. ## Artifact: -The Maven coordinates of this project are `space.kscience:kmath-functions:0.4.0-dev-1`. +The Maven coordinates of this project are `space.kscience:kmath-functions:0.4.0-dev-3`. -**Gradle Groovy:** -```groovy -repositories { - maven { url 'https://repo.kotlin.link' } - mavenCentral() -} - -dependencies { - implementation 'space.kscience:kmath-functions:0.4.0-dev-1' -} -``` **Gradle Kotlin DSL:** ```kotlin repositories { @@ -32,6 +21,6 @@ repositories { } dependencies { - implementation("space.kscience:kmath-functions:0.4.0-dev-1") + implementation("space.kscience:kmath-functions:0.4.0-dev-3") } ``` diff --git a/kmath-geometry/README.md b/kmath-geometry/README.md index 480945c4f..601610d3d 100644 --- a/kmath-geometry/README.md +++ b/kmath-geometry/README.md @@ -6,19 +6,8 @@ ## Artifact: -The Maven coordinates of this project are `space.kscience:kmath-geometry:0.4.0-dev-1`. +The Maven coordinates of this project are `space.kscience:kmath-geometry:0.4.0-dev-3`. -**Gradle Groovy:** -```groovy -repositories { - maven { url 'https://repo.kotlin.link' } - mavenCentral() -} - -dependencies { - implementation 'space.kscience:kmath-geometry:0.4.0-dev-1' -} -``` **Gradle Kotlin DSL:** ```kotlin repositories { @@ -27,6 +16,6 @@ repositories { } dependencies { - implementation("space.kscience:kmath-geometry:0.4.0-dev-1") + implementation("space.kscience:kmath-geometry:0.4.0-dev-3") } ``` diff --git a/kmath-histograms/README.md b/kmath-histograms/README.md index bc7f0fa5b..e9aaad3a8 100644 --- a/kmath-histograms/README.md +++ b/kmath-histograms/README.md @@ -6,19 +6,8 @@ ## Artifact: -The Maven coordinates of this project are `space.kscience:kmath-histograms:0.4.0-dev-1`. +The Maven coordinates of this project are `space.kscience:kmath-histograms:0.4.0-dev-3`. -**Gradle Groovy:** -```groovy -repositories { - maven { url 'https://repo.kotlin.link' } - mavenCentral() -} - -dependencies { - implementation 'space.kscience:kmath-histograms:0.4.0-dev-1' -} -``` **Gradle Kotlin DSL:** ```kotlin repositories { @@ -27,6 +16,6 @@ repositories { } dependencies { - implementation("space.kscience:kmath-histograms:0.4.0-dev-1") + implementation("space.kscience:kmath-histograms:0.4.0-dev-3") } ``` diff --git a/kmath-jafama/README.md b/kmath-jafama/README.md index 47142f174..dc183ca37 100644 --- a/kmath-jafama/README.md +++ b/kmath-jafama/README.md @@ -7,19 +7,8 @@ Integration with [Jafama](https://github.com/jeffhain/jafama). ## Artifact: -The Maven coordinates of this project are `space.kscience:kmath-jafama:0.4.0-dev-1`. +The Maven coordinates of this project are `space.kscience:kmath-jafama:0.4.0-dev-3`. -**Gradle Groovy:** -```groovy -repositories { - maven { url 'https://repo.kotlin.link' } - mavenCentral() -} - -dependencies { - implementation 'space.kscience:kmath-jafama:0.4.0-dev-1' -} -``` **Gradle Kotlin DSL:** ```kotlin repositories { @@ -28,7 +17,7 @@ repositories { } dependencies { - implementation("space.kscience:kmath-jafama:0.4.0-dev-1") + implementation("space.kscience:kmath-jafama:0.4.0-dev-3") } ``` diff --git a/kmath-jafama/api/kmath-jafama.api b/kmath-jafama/api/kmath-jafama.api new file mode 100644 index 000000000..989634e9b --- /dev/null +++ b/kmath-jafama/api/kmath-jafama.api @@ -0,0 +1,128 @@ +public final class space/kscience/kmath/jafama/JafamaDoubleField : space/kscience/kmath/operations/ExtendedField, space/kscience/kmath/operations/Norm, space/kscience/kmath/operations/ScaleOperations { + public static final field INSTANCE Lspace/kscience/kmath/jafama/JafamaDoubleField; + 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 binaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + 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 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 getBufferFactory ()Lspace/kscience/kmath/structures/MutableBufferFactory; + 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 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 power (DLjava/lang/Number;)Ljava/lang/Double; + public synthetic fun power (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + 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 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 final class space/kscience/kmath/jafama/StrictJafamaDoubleField : space/kscience/kmath/operations/ExtendedField, space/kscience/kmath/operations/Norm, space/kscience/kmath/operations/ScaleOperations { + public static final field INSTANCE Lspace/kscience/kmath/jafama/StrictJafamaDoubleField; + 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 binaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2; + 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 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 getBufferFactory ()Lspace/kscience/kmath/structures/MutableBufferFactory; + 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 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 power (DLjava/lang/Number;)Ljava/lang/Double; + public synthetic fun power (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; + 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 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; +} + diff --git a/kmath-jupyter/README.md b/kmath-jupyter/README.md index 2b26878dc..525ae673b 100644 --- a/kmath-jupyter/README.md +++ b/kmath-jupyter/README.md @@ -6,19 +6,8 @@ ## Artifact: -The Maven coordinates of this project are `space.kscience:kmath-jupyter:0.4.0-dev-1`. +The Maven coordinates of this project are `space.kscience:kmath-jupyter:0.4.0-dev-3`. -**Gradle Groovy:** -```groovy -repositories { - maven { url 'https://repo.kotlin.link' } - mavenCentral() -} - -dependencies { - implementation 'space.kscience:kmath-jupyter:0.4.0-dev-1' -} -``` **Gradle Kotlin DSL:** ```kotlin repositories { @@ -27,6 +16,6 @@ repositories { } dependencies { - implementation("space.kscience:kmath-jupyter:0.4.0-dev-1") + implementation("space.kscience:kmath-jupyter:0.4.0-dev-3") } ``` diff --git a/kmath-kotlingrad/README.md b/kmath-kotlingrad/README.md index f1a918b4b..a66c31686 100644 --- a/kmath-kotlingrad/README.md +++ b/kmath-kotlingrad/README.md @@ -8,19 +8,8 @@ ## Artifact: -The Maven coordinates of this project are `space.kscience:kmath-kotlingrad:0.4.0-dev-1`. +The Maven coordinates of this project are `space.kscience:kmath-kotlingrad:0.4.0-dev-3`. -**Gradle Groovy:** -```groovy -repositories { - maven { url 'https://repo.kotlin.link' } - mavenCentral() -} - -dependencies { - implementation 'space.kscience:kmath-kotlingrad:0.4.0-dev-1' -} -``` **Gradle Kotlin DSL:** ```kotlin repositories { @@ -29,6 +18,6 @@ repositories { } dependencies { - implementation("space.kscience:kmath-kotlingrad:0.4.0-dev-1") + implementation("space.kscience:kmath-kotlingrad:0.4.0-dev-3") } ``` diff --git a/kmath-memory/README.md b/kmath-memory/README.md index 594588ecf..d6824add0 100644 --- a/kmath-memory/README.md +++ b/kmath-memory/README.md @@ -6,19 +6,8 @@ ## Artifact: -The Maven coordinates of this project are `space.kscience:kmath-memory:0.4.0-dev-1`. +The Maven coordinates of this project are `space.kscience:kmath-memory:0.4.0-dev-3`. -**Gradle Groovy:** -```groovy -repositories { - maven { url 'https://repo.kotlin.link' } - mavenCentral() -} - -dependencies { - implementation 'space.kscience:kmath-memory:0.4.0-dev-1' -} -``` **Gradle Kotlin DSL:** ```kotlin repositories { @@ -27,6 +16,6 @@ repositories { } dependencies { - implementation("space.kscience:kmath-memory:0.4.0-dev-1") + implementation("space.kscience:kmath-memory:0.4.0-dev-3") } ``` diff --git a/kmath-memory/api/kmath-memory.api b/kmath-memory/api/kmath-memory.api index cebb04af2..67303dd97 100644 --- a/kmath-memory/api/kmath-memory.api +++ b/kmath-memory/api/kmath-memory.api @@ -1,14 +1,3 @@ -public abstract interface annotation class space/kscience/kmath/PerformancePitfall : java/lang/annotation/Annotation { - public abstract fun message ()Ljava/lang/String; -} - -public abstract interface annotation class space/kscience/kmath/UnsafeKMathAPI : java/lang/annotation/Annotation { - public abstract fun message ()Ljava/lang/String; -} - -public abstract interface annotation class space/kscience/kmath/UnstableKMathAPI : java/lang/annotation/Annotation { -} - public final class space/kscience/kmath/memory/ByteBufferMemory : space/kscience/kmath/memory/Memory { public fun (Ljava/nio/ByteBuffer;II)V public synthetic fun (Ljava/nio/ByteBuffer;IIILkotlin/jvm/internal/DefaultConstructorMarker;)V @@ -42,6 +31,23 @@ public abstract interface class space/kscience/kmath/memory/Memory { public final class space/kscience/kmath/memory/Memory$Companion { } +public class space/kscience/kmath/memory/MemoryBuffer : space/kscience/kmath/structures/Buffer { + public static final field Companion Lspace/kscience/kmath/memory/MemoryBuffer$Companion; + public fun (Lspace/kscience/kmath/memory/Memory;Lspace/kscience/kmath/memory/MemorySpec;)V + public fun get (I)Ljava/lang/Object; + protected final fun getMemory ()Lspace/kscience/kmath/memory/Memory; + public fun getSize ()I + protected final fun getSpec ()Lspace/kscience/kmath/memory/MemorySpec; + public fun getType-V0oMfBY ()Lkotlin/reflect/KType; + public fun iterator ()Ljava/util/Iterator; + public fun toString ()Ljava/lang/String; +} + +public final class space/kscience/kmath/memory/MemoryBuffer$Companion { + public final fun create (Lspace/kscience/kmath/memory/MemorySpec;I)Lspace/kscience/kmath/memory/MemoryBuffer; + public final fun create (Lspace/kscience/kmath/memory/MemorySpec;ILkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/memory/MemoryBuffer; +} + public final class space/kscience/kmath/memory/MemoryKt { public static final fun read (Lspace/kscience/kmath/memory/Memory;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static final fun write (Lspace/kscience/kmath/memory/Memory;Lkotlin/jvm/functions/Function1;)V @@ -58,7 +64,7 @@ public abstract interface class space/kscience/kmath/memory/MemoryReader : java/ public abstract fun readShort (I)S } -public abstract interface class space/kscience/kmath/memory/MemorySpec { +public abstract interface class space/kscience/kmath/memory/MemorySpec : space/kscience/attributes/WithType { public abstract fun getObjectSize ()I public abstract fun read (Lspace/kscience/kmath/memory/MemoryReader;I)Ljava/lang/Object; public abstract fun write (Lspace/kscience/kmath/memory/MemoryWriter;ILjava/lang/Object;)V @@ -81,3 +87,15 @@ public abstract interface class space/kscience/kmath/memory/MemoryWriter : java/ public abstract fun writeShort (IS)V } +public final class space/kscience/kmath/memory/MutableMemoryBuffer : space/kscience/kmath/memory/MemoryBuffer, space/kscience/kmath/structures/MutableBuffer { + public static final field Companion Lspace/kscience/kmath/memory/MutableMemoryBuffer$Companion; + public fun (Lspace/kscience/kmath/memory/Memory;Lspace/kscience/kmath/memory/MemorySpec;)V + public fun copy ()Lspace/kscience/kmath/structures/MutableBuffer; + public fun set (ILjava/lang/Object;)V +} + +public final class space/kscience/kmath/memory/MutableMemoryBuffer$Companion { + public final fun create (Lspace/kscience/kmath/memory/MemorySpec;I)Lspace/kscience/kmath/memory/MutableMemoryBuffer; + public final fun create (Lspace/kscience/kmath/memory/MemorySpec;ILkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/memory/MutableMemoryBuffer; +} + diff --git a/kmath-multik/README.md b/kmath-multik/README.md index 127b12a49..f0bf10208 100644 --- a/kmath-multik/README.md +++ b/kmath-multik/README.md @@ -6,19 +6,8 @@ JetBrains Multik connector ## Artifact: -The Maven coordinates of this project are `space.kscience:kmath-multik:0.4.0-dev-1`. +The Maven coordinates of this project are `space.kscience:kmath-multik:0.4.0-dev-3`. -**Gradle Groovy:** -```groovy -repositories { - maven { url 'https://repo.kotlin.link' } - mavenCentral() -} - -dependencies { - implementation 'space.kscience:kmath-multik:0.4.0-dev-1' -} -``` **Gradle Kotlin DSL:** ```kotlin repositories { @@ -27,6 +16,6 @@ repositories { } dependencies { - implementation("space.kscience:kmath-multik:0.4.0-dev-1") + implementation("space.kscience:kmath-multik:0.4.0-dev-3") } ``` diff --git a/kmath-nd4j/README.md b/kmath-nd4j/README.md index b299c1b37..55d6844bc 100644 --- a/kmath-nd4j/README.md +++ b/kmath-nd4j/README.md @@ -9,19 +9,8 @@ ND4J based implementations of KMath abstractions. ## Artifact: -The Maven coordinates of this project are `space.kscience:kmath-nd4j:0.4.0-dev-1`. +The Maven coordinates of this project are `space.kscience:kmath-nd4j:0.4.0-dev-3`. -**Gradle Groovy:** -```groovy -repositories { - maven { url 'https://repo.kotlin.link' } - mavenCentral() -} - -dependencies { - implementation 'space.kscience:kmath-nd4j:0.4.0-dev-1' -} -``` **Gradle Kotlin DSL:** ```kotlin repositories { @@ -30,7 +19,7 @@ repositories { } dependencies { - implementation("space.kscience:kmath-nd4j:0.4.0-dev-1") + implementation("space.kscience:kmath-nd4j:0.4.0-dev-3") } ``` diff --git a/kmath-nd4j/api/kmath-nd4j.api b/kmath-nd4j/api/kmath-nd4j.api new file mode 100644 index 000000000..74c6b8805 --- /dev/null +++ b/kmath-nd4j/api/kmath-nd4j.api @@ -0,0 +1,395 @@ +public final class space/kscience/kmath/nd4j/DoubleNd4jArrayField : space/kscience/kmath/nd4j/DoubleNd4jArrayFieldOps, space/kscience/kmath/nd/FieldND { + public synthetic fun ([ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public fun getShape-IIYLAfE ()[I +} + +public class space/kscience/kmath/nd4j/DoubleNd4jArrayFieldOps : space/kscience/kmath/nd4j/Nd4jArrayExtendedFieldOps { + public static final field Companion Lspace/kscience/kmath/nd4j/DoubleNd4jArrayFieldOps$Companion; + public fun ()V + public fun div (DLspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; + public synthetic fun div (Ljava/lang/Object;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public fun div (Lspace/kscience/kmath/nd/StructureND;D)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; + public synthetic fun div (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Object;)Lspace/kscience/kmath/nd/StructureND; + public synthetic fun getElementAlgebra ()Lspace/kscience/kmath/operations/Algebra; + public fun getElementAlgebra ()Lspace/kscience/kmath/operations/Float64Field; + public fun getNdArray (Lspace/kscience/kmath/nd/StructureND;)Lorg/nd4j/linalg/api/ndarray/INDArray; + public fun minus (DLspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; + public synthetic fun minus (Ljava/lang/Object;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public fun minus (Lspace/kscience/kmath/nd/StructureND;D)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; + public synthetic fun minus (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Object;)Lspace/kscience/kmath/nd/StructureND; + public fun plus (Lspace/kscience/kmath/nd/StructureND;D)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; + public synthetic fun plus (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Object;)Lspace/kscience/kmath/nd/StructureND; + public synthetic fun scale (Ljava/lang/Object;D)Ljava/lang/Object; + public synthetic fun scale (Lspace/kscience/kmath/nd/StructureND;D)Lspace/kscience/kmath/nd/StructureND; + public fun scale (Lspace/kscience/kmath/nd/StructureND;D)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; + public fun times (Lspace/kscience/kmath/nd/StructureND;D)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; + public synthetic fun times (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Object;)Lspace/kscience/kmath/nd/StructureND; + public fun wrap (Lorg/nd4j/linalg/api/ndarray/INDArray;)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; +} + +public final class space/kscience/kmath/nd4j/DoubleNd4jArrayFieldOps$Companion : space/kscience/kmath/nd4j/DoubleNd4jArrayFieldOps { +} + +public final class space/kscience/kmath/nd4j/DoubleNd4jTensorAlgebra : space/kscience/kmath/nd4j/Nd4jTensorAlgebra { + public static final field INSTANCE Lspace/kscience/kmath/nd4j/DoubleNd4jTensorAlgebra; + public fun diagonalEmbedding (Lspace/kscience/kmath/nd/StructureND;III)Lspace/kscience/kmath/nd/MutableStructureND; + public synthetic fun getElementAlgebra ()Lspace/kscience/kmath/operations/Algebra; + public fun getElementAlgebra ()Lspace/kscience/kmath/operations/Float64Field; + public fun getNdArray (Lspace/kscience/kmath/nd/StructureND;)Lorg/nd4j/linalg/api/ndarray/INDArray; + public fun max (Lspace/kscience/kmath/nd/StructureND;)Ljava/lang/Double; + public synthetic fun max (Lspace/kscience/kmath/nd/StructureND;)Ljava/lang/Object; + public fun mean (Lspace/kscience/kmath/nd/StructureND;)Ljava/lang/Double; + public synthetic fun mean (Lspace/kscience/kmath/nd/StructureND;)Ljava/lang/Object; + public fun min (Lspace/kscience/kmath/nd/StructureND;)Ljava/lang/Double; + public synthetic fun min (Lspace/kscience/kmath/nd/StructureND;)Ljava/lang/Object; + public synthetic fun mutableStructureND-qL90JFI ([ILkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/MutableStructureND; + public fun mutableStructureND-qL90JFI ([ILkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; + public fun std (Lspace/kscience/kmath/nd/StructureND;)Ljava/lang/Double; + public synthetic fun std (Lspace/kscience/kmath/nd/StructureND;)Ljava/lang/Object; + public fun sum (Lspace/kscience/kmath/nd/StructureND;)Ljava/lang/Double; + public synthetic fun sum (Lspace/kscience/kmath/nd/StructureND;)Ljava/lang/Object; + public fun valueOrNull (Lspace/kscience/kmath/nd/StructureND;)Ljava/lang/Double; + public synthetic fun valueOrNull (Lspace/kscience/kmath/nd/StructureND;)Ljava/lang/Object; + public fun variance (Lspace/kscience/kmath/nd/StructureND;)Ljava/lang/Double; + public synthetic fun variance (Lspace/kscience/kmath/nd/StructureND;)Ljava/lang/Object; + public fun wrap (Lorg/nd4j/linalg/api/ndarray/INDArray;)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; +} + +public final class space/kscience/kmath/nd4j/FloatNd4jArrayField : space/kscience/kmath/nd4j/FloatNd4jArrayFieldOps, space/kscience/kmath/nd/RingND { + public synthetic fun ([ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public fun getShape-IIYLAfE ()[I +} + +public class space/kscience/kmath/nd4j/FloatNd4jArrayFieldOps : space/kscience/kmath/nd4j/Nd4jArrayExtendedFieldOps { + public static final field Companion Lspace/kscience/kmath/nd4j/FloatNd4jArrayFieldOps$Companion; + public fun ()V + public fun div (FLspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; + public synthetic fun div (Ljava/lang/Object;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public fun div (Lspace/kscience/kmath/nd/StructureND;F)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; + public synthetic fun div (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Object;)Lspace/kscience/kmath/nd/StructureND; + public synthetic fun getElementAlgebra ()Lspace/kscience/kmath/operations/Algebra; + public fun getElementAlgebra ()Lspace/kscience/kmath/operations/Float32Field; + public fun getNdArray (Lspace/kscience/kmath/nd/StructureND;)Lorg/nd4j/linalg/api/ndarray/INDArray; + public fun minus (FLspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; + public synthetic fun minus (Ljava/lang/Object;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public fun minus (Lspace/kscience/kmath/nd/StructureND;F)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; + public synthetic fun minus (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Object;)Lspace/kscience/kmath/nd/StructureND; + public fun plus (Lspace/kscience/kmath/nd/StructureND;F)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; + public synthetic fun plus (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Object;)Lspace/kscience/kmath/nd/StructureND; + 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 fun times (Lspace/kscience/kmath/nd/StructureND;F)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; + public synthetic fun times (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Object;)Lspace/kscience/kmath/nd/StructureND; + public fun wrap (Lorg/nd4j/linalg/api/ndarray/INDArray;)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; +} + +public final class space/kscience/kmath/nd4j/FloatNd4jArrayFieldOps$Companion : space/kscience/kmath/nd4j/FloatNd4jArrayFieldOps { +} + +public final class space/kscience/kmath/nd4j/IntNd4jArrayRing : space/kscience/kmath/nd4j/IntNd4jArrayRingOps, space/kscience/kmath/nd/RingND { + public synthetic fun ([ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public fun getShape-IIYLAfE ()[I +} + +public class space/kscience/kmath/nd4j/IntNd4jArrayRingOps : space/kscience/kmath/nd4j/Nd4jArrayRingOps { + public static final field Companion Lspace/kscience/kmath/nd4j/IntNd4jArrayRingOps$Companion; + public fun ()V + public synthetic fun getElementAlgebra ()Lspace/kscience/kmath/operations/Algebra; + public fun getElementAlgebra ()Lspace/kscience/kmath/operations/Int32Ring; + public fun getNdArray (Lspace/kscience/kmath/nd/StructureND;)Lorg/nd4j/linalg/api/ndarray/INDArray; + public fun minus (ILspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; + public synthetic fun minus (Ljava/lang/Object;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public fun minus (Lspace/kscience/kmath/nd/StructureND;I)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; + public synthetic fun minus (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Object;)Lspace/kscience/kmath/nd/StructureND; + public fun plus (Lspace/kscience/kmath/nd/StructureND;I)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; + public synthetic fun plus (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Object;)Lspace/kscience/kmath/nd/StructureND; + public fun times (Lspace/kscience/kmath/nd/StructureND;I)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; + public synthetic fun times (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Object;)Lspace/kscience/kmath/nd/StructureND; + public fun wrap (Lorg/nd4j/linalg/api/ndarray/INDArray;)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; +} + +public final class space/kscience/kmath/nd4j/IntNd4jArrayRingOps$Companion : space/kscience/kmath/nd4j/IntNd4jArrayRingOps { +} + +public abstract interface class space/kscience/kmath/nd4j/Nd4jArrayAlgebra : space/kscience/kmath/nd/AlgebraND { + public abstract fun getNdArray (Lspace/kscience/kmath/nd/StructureND;)Lorg/nd4j/linalg/api/ndarray/INDArray; + public synthetic fun map (Lspace/kscience/kmath/nd/StructureND;Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/StructureND; + public fun map (Lspace/kscience/kmath/nd/StructureND;Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; + public synthetic fun mapIndexed (Lspace/kscience/kmath/nd/StructureND;Lkotlin/jvm/functions/Function3;)Lspace/kscience/kmath/nd/StructureND; + public fun mapIndexed (Lspace/kscience/kmath/nd/StructureND;Lkotlin/jvm/functions/Function3;)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; + public synthetic fun mutableStructureND-qL90JFI ([ILkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/MutableStructureND; + public fun mutableStructureND-qL90JFI ([ILkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; + public abstract fun wrap (Lorg/nd4j/linalg/api/ndarray/INDArray;)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; + public synthetic fun zip (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;Lkotlin/jvm/functions/Function3;)Lspace/kscience/kmath/nd/StructureND; + public fun zip (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;Lkotlin/jvm/functions/Function3;)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; +} + +public final class space/kscience/kmath/nd4j/Nd4jArrayAlgebraKt { + public static final fun getNd4j (Lspace/kscience/kmath/operations/Float32Field;)Lspace/kscience/kmath/nd4j/FloatNd4jArrayFieldOps; + public static final fun getNd4j (Lspace/kscience/kmath/operations/Float64Field;)Lspace/kscience/kmath/nd4j/DoubleNd4jArrayFieldOps; + public static final fun getNd4j (Lspace/kscience/kmath/operations/Int32Ring;)Lspace/kscience/kmath/nd4j/IntNd4jArrayRingOps; + public static final fun nd4j (Lspace/kscience/kmath/operations/Float32Field;I[I)Lspace/kscience/kmath/nd4j/FloatNd4jArrayField; + public static final fun nd4j (Lspace/kscience/kmath/operations/Float64Field;I[I)Lspace/kscience/kmath/nd4j/DoubleNd4jArrayField; + public static final fun nd4j (Lspace/kscience/kmath/operations/Int32Ring;I[I)Lspace/kscience/kmath/nd4j/IntNd4jArrayRing; +} + +public final class space/kscience/kmath/nd4j/Nd4jArrayDoubleStructure : space/kscience/kmath/nd4j/Nd4jArrayStructure, space/kscience/kmath/nd/StructureNDOfDouble { + public fun (Lorg/nd4j/linalg/api/ndarray/INDArray;)V + public final fun component1 ()Lorg/nd4j/linalg/api/ndarray/INDArray; + public final fun copy (Lorg/nd4j/linalg/api/ndarray/INDArray;)Lspace/kscience/kmath/nd4j/Nd4jArrayDoubleStructure; + public static synthetic fun copy$default (Lspace/kscience/kmath/nd4j/Nd4jArrayDoubleStructure;Lorg/nd4j/linalg/api/ndarray/INDArray;ILjava/lang/Object;)Lspace/kscience/kmath/nd4j/Nd4jArrayDoubleStructure; + public fun equals (Ljava/lang/Object;)Z + public fun get ([I)Ljava/lang/Double; + public synthetic fun get ([I)Ljava/lang/Object; + public fun getDouble ([I)D + public fun getNdArray ()Lorg/nd4j/linalg/api/ndarray/INDArray; + public fun hashCode ()I + public fun set ([ID)V + public synthetic fun set ([ILjava/lang/Object;)V + public fun toString ()Ljava/lang/String; +} + +public abstract interface class space/kscience/kmath/nd4j/Nd4jArrayExtendedFieldOps : space/kscience/kmath/nd4j/Nd4jArrayField, space/kscience/kmath/operations/ExtendedFieldOps, space/kscience/kmath/operations/PowerOperations { + public synthetic fun acos (Ljava/lang/Object;)Ljava/lang/Object; + public fun acos (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public synthetic fun acosh (Ljava/lang/Object;)Ljava/lang/Object; + public fun acosh (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public synthetic fun asin (Ljava/lang/Object;)Ljava/lang/Object; + public fun asin (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public synthetic fun asinh (Ljava/lang/Object;)Ljava/lang/Object; + public fun asinh (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public synthetic fun atan (Ljava/lang/Object;)Ljava/lang/Object; + public fun atan (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public synthetic fun atanh (Ljava/lang/Object;)Ljava/lang/Object; + public fun atanh (Lspace/kscience/kmath/nd/StructureND;)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/StructureND; + public synthetic fun cosh (Ljava/lang/Object;)Ljava/lang/Object; + public fun cosh (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public synthetic fun exp (Ljava/lang/Object;)Ljava/lang/Object; + public fun exp (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public synthetic fun ln (Ljava/lang/Object;)Ljava/lang/Object; + public fun ln (Lspace/kscience/kmath/nd/StructureND;)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/StructureND; + public synthetic fun sin (Ljava/lang/Object;)Ljava/lang/Object; + public fun sin (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public synthetic fun sinh (Ljava/lang/Object;)Ljava/lang/Object; + public fun sinh (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + 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 tanh (Ljava/lang/Object;)Ljava/lang/Object; + public fun tanh (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; +} + +public abstract interface class space/kscience/kmath/nd4j/Nd4jArrayField : space/kscience/kmath/nd/FieldOpsND, space/kscience/kmath/nd4j/Nd4jArrayRingOps { + public static final field Companion Lspace/kscience/kmath/nd4j/Nd4jArrayField$Companion; + public fun div (Ljava/lang/Number;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; + public synthetic fun divide (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public synthetic fun divide (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public fun divide (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; +} + +public final class space/kscience/kmath/nd4j/Nd4jArrayField$Companion { +} + +public final class space/kscience/kmath/nd4j/Nd4jArrayFloatStructure : space/kscience/kmath/nd4j/Nd4jArrayStructure { + public fun (Lorg/nd4j/linalg/api/ndarray/INDArray;)V + public final fun component1 ()Lorg/nd4j/linalg/api/ndarray/INDArray; + public final fun copy (Lorg/nd4j/linalg/api/ndarray/INDArray;)Lspace/kscience/kmath/nd4j/Nd4jArrayFloatStructure; + public static synthetic fun copy$default (Lspace/kscience/kmath/nd4j/Nd4jArrayFloatStructure;Lorg/nd4j/linalg/api/ndarray/INDArray;ILjava/lang/Object;)Lspace/kscience/kmath/nd4j/Nd4jArrayFloatStructure; + public fun equals (Ljava/lang/Object;)Z + public fun get ([I)Ljava/lang/Float; + public synthetic fun get ([I)Ljava/lang/Object; + public fun getNdArray ()Lorg/nd4j/linalg/api/ndarray/INDArray; + public fun getType-V0oMfBY ()Lkotlin/reflect/KType; + public fun hashCode ()I + public fun set ([IF)V + public synthetic fun set ([ILjava/lang/Object;)V + public fun toString ()Ljava/lang/String; +} + +public abstract interface class space/kscience/kmath/nd4j/Nd4jArrayGroupOps : space/kscience/kmath/nd/GroupOpsND, space/kscience/kmath/nd4j/Nd4jArrayAlgebra { + public synthetic fun add (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public synthetic fun add (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public fun add (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; + public synthetic fun minus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun minus (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; + public fun multiply (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Number;)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; + public synthetic fun unaryMinus (Ljava/lang/Object;)Ljava/lang/Object; + public fun unaryMinus (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; +} + +public final class space/kscience/kmath/nd4j/Nd4jArrayIntStructure : space/kscience/kmath/nd4j/Nd4jArrayStructure, space/kscience/kmath/nd/StructureNDOfInt { + public fun (Lorg/nd4j/linalg/api/ndarray/INDArray;)V + public final fun component1 ()Lorg/nd4j/linalg/api/ndarray/INDArray; + public final fun copy (Lorg/nd4j/linalg/api/ndarray/INDArray;)Lspace/kscience/kmath/nd4j/Nd4jArrayIntStructure; + public static synthetic fun copy$default (Lspace/kscience/kmath/nd4j/Nd4jArrayIntStructure;Lorg/nd4j/linalg/api/ndarray/INDArray;ILjava/lang/Object;)Lspace/kscience/kmath/nd4j/Nd4jArrayIntStructure; + public fun equals (Ljava/lang/Object;)Z + public fun get ([I)Ljava/lang/Integer; + public synthetic fun get ([I)Ljava/lang/Object; + public fun getInt ([I)I + public fun getNdArray ()Lorg/nd4j/linalg/api/ndarray/INDArray; + public fun hashCode ()I + public fun set ([II)V + public synthetic fun set ([ILjava/lang/Object;)V + public fun toString ()Ljava/lang/String; +} + +public abstract interface class space/kscience/kmath/nd4j/Nd4jArrayRingOps : space/kscience/kmath/nd/RingOpsND, space/kscience/kmath/nd4j/Nd4jArrayGroupOps { + public static final field Companion Lspace/kscience/kmath/nd4j/Nd4jArrayRingOps$Companion; + public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public synthetic fun multiply (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public fun multiply (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; +} + +public final class space/kscience/kmath/nd4j/Nd4jArrayRingOps$Companion { +} + +public abstract class space/kscience/kmath/nd4j/Nd4jArrayStructure : space/kscience/kmath/nd/MutableStructureND { + public fun elements ()Lkotlin/sequences/Sequence; + public abstract fun getNdArray ()Lorg/nd4j/linalg/api/ndarray/INDArray; + public fun getShape-IIYLAfE ()[I +} + +public final class space/kscience/kmath/nd4j/Nd4jArrayStructureKt { + public static final fun asDoubleStructure (Lorg/nd4j/linalg/api/ndarray/INDArray;)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; + public static final fun asFloatStructure (Lorg/nd4j/linalg/api/ndarray/INDArray;)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; + public static final fun asIntStructure (Lorg/nd4j/linalg/api/ndarray/INDArray;)Lspace/kscience/kmath/nd4j/Nd4jArrayIntStructure; +} + +public abstract interface class space/kscience/kmath/nd4j/Nd4jTensorAlgebra : space/kscience/kmath/tensors/api/AnalyticTensorAlgebra { + public synthetic fun acos (Ljava/lang/Object;)Ljava/lang/Object; + public synthetic fun acos (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public fun acos (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; + public synthetic fun acosh (Ljava/lang/Object;)Ljava/lang/Object; + public synthetic fun acosh (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public fun acosh (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; + public fun argMax (Lspace/kscience/kmath/nd/StructureND;IZ)Lspace/kscience/kmath/nd/MutableStructureND; + public fun argMin (Lspace/kscience/kmath/nd/StructureND;IZ)Lspace/kscience/kmath/nd/MutableStructureND; + public synthetic fun asin (Ljava/lang/Object;)Ljava/lang/Object; + public synthetic fun asin (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public fun asin (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; + public synthetic fun asinh (Ljava/lang/Object;)Ljava/lang/Object; + public synthetic fun asinh (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public fun asinh (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; + public synthetic fun atan (Ljava/lang/Object;)Ljava/lang/Object; + public synthetic fun atan (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/MutableStructureND; + public fun atan (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; + public synthetic fun atanh (Ljava/lang/Object;)Ljava/lang/Object; + public synthetic fun atanh (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public fun atanh (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; + public synthetic fun ceil (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/MutableStructureND; + public fun ceil (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; + public synthetic fun cos (Ljava/lang/Object;)Ljava/lang/Object; + public synthetic fun cos (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public fun cos (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; + public synthetic fun cosh (Ljava/lang/Object;)Ljava/lang/Object; + public synthetic fun cosh (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public fun cosh (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; + public fun div (Ljava/lang/Number;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; + public synthetic fun div (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public synthetic fun div (Ljava/lang/Object;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/MutableStructureND; + public synthetic fun div (Ljava/lang/Object;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public fun div (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Number;)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; + public synthetic fun div (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Object;)Lspace/kscience/kmath/nd/MutableStructureND; + public synthetic fun div (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Object;)Lspace/kscience/kmath/nd/StructureND; + public synthetic fun div (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/MutableStructureND; + public fun div (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; + public fun divAssign (Lspace/kscience/kmath/nd/MutableStructureND;Ljava/lang/Number;)V + public synthetic fun divAssign (Lspace/kscience/kmath/nd/MutableStructureND;Ljava/lang/Object;)V + public fun divAssign (Lspace/kscience/kmath/nd/MutableStructureND;Lspace/kscience/kmath/nd/StructureND;)V + public synthetic fun dot (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/MutableStructureND; + public fun dot (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; + public synthetic fun exp (Ljava/lang/Object;)Ljava/lang/Object; + public synthetic fun exp (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public fun exp (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; + public synthetic fun floor (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/MutableStructureND; + public fun floor (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; + public abstract fun getNdArray (Lspace/kscience/kmath/nd/StructureND;)Lorg/nd4j/linalg/api/ndarray/INDArray; + public synthetic fun getTensor (Lspace/kscience/kmath/nd/MutableStructureND;I)Lspace/kscience/kmath/nd/MutableStructureND; + public fun getTensor (Lspace/kscience/kmath/nd/MutableStructureND;I)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; + public synthetic fun ln (Ljava/lang/Object;)Ljava/lang/Object; + public synthetic fun ln (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public fun ln (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; + public synthetic fun map (Lspace/kscience/kmath/nd/StructureND;Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/StructureND; + public fun map (Lspace/kscience/kmath/nd/StructureND;Lkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; + public synthetic fun mapIndexed (Lspace/kscience/kmath/nd/StructureND;Lkotlin/jvm/functions/Function3;)Lspace/kscience/kmath/nd/StructureND; + public fun mapIndexed (Lspace/kscience/kmath/nd/StructureND;Lkotlin/jvm/functions/Function3;)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; + public synthetic fun max (Lspace/kscience/kmath/nd/StructureND;IZ)Lspace/kscience/kmath/nd/MutableStructureND; + public fun max (Lspace/kscience/kmath/nd/StructureND;IZ)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; + public fun mean (Lspace/kscience/kmath/nd/StructureND;IZ)Lspace/kscience/kmath/nd/MutableStructureND; + public synthetic fun min (Lspace/kscience/kmath/nd/StructureND;IZ)Lspace/kscience/kmath/nd/MutableStructureND; + public fun min (Lspace/kscience/kmath/nd/StructureND;IZ)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; + public fun minus (Ljava/lang/Number;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; + public synthetic fun minus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public synthetic fun minus (Ljava/lang/Object;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/MutableStructureND; + public synthetic fun minus (Ljava/lang/Object;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public fun minus (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Number;)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; + public synthetic fun minus (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Object;)Lspace/kscience/kmath/nd/MutableStructureND; + public synthetic fun minus (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Object;)Lspace/kscience/kmath/nd/StructureND; + public synthetic fun minus (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/MutableStructureND; + public fun minus (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; + public fun minusAssign (Lspace/kscience/kmath/nd/MutableStructureND;Ljava/lang/Number;)V + public synthetic fun minusAssign (Lspace/kscience/kmath/nd/MutableStructureND;Ljava/lang/Object;)V + public fun minusAssign (Lspace/kscience/kmath/nd/MutableStructureND;Lspace/kscience/kmath/nd/StructureND;)V + public abstract fun mutableStructureND-qL90JFI ([ILkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; + public fun plus (Ljava/lang/Number;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; + public synthetic fun plus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public synthetic fun plus (Ljava/lang/Object;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/MutableStructureND; + public synthetic fun plus (Ljava/lang/Object;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public fun plus (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Number;)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; + public synthetic fun plus (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Object;)Lspace/kscience/kmath/nd/MutableStructureND; + public synthetic fun plus (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Object;)Lspace/kscience/kmath/nd/StructureND; + public synthetic fun plus (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/MutableStructureND; + public fun plus (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; + public fun plusAssign (Lspace/kscience/kmath/nd/MutableStructureND;Ljava/lang/Number;)V + public synthetic fun plusAssign (Lspace/kscience/kmath/nd/MutableStructureND;Ljava/lang/Object;)V + public fun plusAssign (Lspace/kscience/kmath/nd/MutableStructureND;Lspace/kscience/kmath/nd/StructureND;)V + 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/StructureND; + public synthetic fun sin (Ljava/lang/Object;)Ljava/lang/Object; + public synthetic fun sin (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public fun sin (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; + public synthetic fun sinh (Ljava/lang/Object;)Ljava/lang/Object; + public fun sinh (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/MutableStructureND; + public synthetic fun sinh (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public synthetic fun sqrt (Ljava/lang/Object;)Ljava/lang/Object; + public synthetic fun sqrt (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/MutableStructureND; + public fun sqrt (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; + public fun std (Lspace/kscience/kmath/nd/StructureND;IZ)Lspace/kscience/kmath/nd/MutableStructureND; + public synthetic fun sum (Lspace/kscience/kmath/nd/StructureND;IZ)Lspace/kscience/kmath/nd/MutableStructureND; + public fun sum (Lspace/kscience/kmath/nd/StructureND;IZ)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; + public synthetic fun tan (Ljava/lang/Object;)Ljava/lang/Object; + public synthetic fun tan (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/MutableStructureND; + public fun tan (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; + public synthetic fun tanh (Ljava/lang/Object;)Ljava/lang/Object; + public synthetic fun tanh (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/MutableStructureND; + public fun tanh (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; + public fun times (Ljava/lang/Number;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; + public synthetic fun times (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public synthetic fun times (Ljava/lang/Object;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/MutableStructureND; + public synthetic fun times (Ljava/lang/Object;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/StructureND; + public fun times (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Number;)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; + public synthetic fun times (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Object;)Lspace/kscience/kmath/nd/MutableStructureND; + public synthetic fun times (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Object;)Lspace/kscience/kmath/nd/StructureND; + public synthetic fun times (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/MutableStructureND; + public fun times (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; + public fun timesAssign (Lspace/kscience/kmath/nd/MutableStructureND;Ljava/lang/Number;)V + public synthetic fun timesAssign (Lspace/kscience/kmath/nd/MutableStructureND;Ljava/lang/Object;)V + public fun timesAssign (Lspace/kscience/kmath/nd/MutableStructureND;Lspace/kscience/kmath/nd/StructureND;)V + public synthetic fun transposed (Lspace/kscience/kmath/nd/StructureND;II)Lspace/kscience/kmath/nd/MutableStructureND; + public fun transposed (Lspace/kscience/kmath/nd/StructureND;II)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; + public synthetic fun unaryMinus (Ljava/lang/Object;)Ljava/lang/Object; + public synthetic fun unaryMinus (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/MutableStructureND; + public fun unaryMinus (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; + public fun variance (Lspace/kscience/kmath/nd/StructureND;IZ)Lspace/kscience/kmath/nd/MutableStructureND; + public synthetic fun view-waz_sdI (Lspace/kscience/kmath/nd/MutableStructureND;[I)Lspace/kscience/kmath/nd/MutableStructureND; + public fun view-waz_sdI (Lspace/kscience/kmath/nd/MutableStructureND;[I)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; + public synthetic fun viewAs (Lspace/kscience/kmath/nd/MutableStructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd/MutableStructureND; + public fun viewAs (Lspace/kscience/kmath/nd/MutableStructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; + public abstract fun wrap (Lorg/nd4j/linalg/api/ndarray/INDArray;)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; + public synthetic fun zip (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;Lkotlin/jvm/functions/Function3;)Lspace/kscience/kmath/nd/StructureND; + public fun zip (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;Lkotlin/jvm/functions/Function3;)Lspace/kscience/kmath/nd4j/Nd4jArrayStructure; +} + diff --git a/kmath-optimization/README.md b/kmath-optimization/README.md index 79a4f5d24..52a018a4e 100644 --- a/kmath-optimization/README.md +++ b/kmath-optimization/README.md @@ -6,19 +6,8 @@ ## Artifact: -The Maven coordinates of this project are `space.kscience:kmath-optimization:0.4.0-dev-1`. +The Maven coordinates of this project are `space.kscience:kmath-optimization:0.4.0-dev-3`. -**Gradle Groovy:** -```groovy -repositories { - maven { url 'https://repo.kotlin.link' } - mavenCentral() -} - -dependencies { - implementation 'space.kscience:kmath-optimization:0.4.0-dev-1' -} -``` **Gradle Kotlin DSL:** ```kotlin repositories { @@ -27,6 +16,6 @@ repositories { } dependencies { - implementation("space.kscience:kmath-optimization:0.4.0-dev-1") + implementation("space.kscience:kmath-optimization:0.4.0-dev-3") } ``` diff --git a/kmath-stat/README.md b/kmath-stat/README.md index e7e0a4d92..55ef0f693 100644 --- a/kmath-stat/README.md +++ b/kmath-stat/README.md @@ -6,19 +6,8 @@ ## Artifact: -The Maven coordinates of this project are `space.kscience:kmath-stat:0.4.0-dev-1`. +The Maven coordinates of this project are `space.kscience:kmath-stat:0.4.0-dev-3`. -**Gradle Groovy:** -```groovy -repositories { - maven { url 'https://repo.kotlin.link' } - mavenCentral() -} - -dependencies { - implementation 'space.kscience:kmath-stat:0.4.0-dev-1' -} -``` **Gradle Kotlin DSL:** ```kotlin repositories { @@ -27,6 +16,6 @@ repositories { } dependencies { - implementation("space.kscience:kmath-stat:0.4.0-dev-1") + implementation("space.kscience:kmath-stat:0.4.0-dev-3") } ``` diff --git a/kmath-symja/README.md b/kmath-symja/README.md index 8672c6a71..250c0ae35 100644 --- a/kmath-symja/README.md +++ b/kmath-symja/README.md @@ -6,19 +6,8 @@ Symja integration module ## Artifact: -The Maven coordinates of this project are `space.kscience:kmath-symja:0.4.0-dev-1`. +The Maven coordinates of this project are `space.kscience:kmath-symja:0.4.0-dev-3`. -**Gradle Groovy:** -```groovy -repositories { - maven { url 'https://repo.kotlin.link' } - mavenCentral() -} - -dependencies { - implementation 'space.kscience:kmath-symja:0.4.0-dev-1' -} -``` **Gradle Kotlin DSL:** ```kotlin repositories { @@ -27,6 +16,6 @@ repositories { } dependencies { - implementation("space.kscience:kmath-symja:0.4.0-dev-1") + implementation("space.kscience:kmath-symja:0.4.0-dev-3") } ``` diff --git a/kmath-tensorflow/README.md b/kmath-tensorflow/README.md index a5b48de4d..03666129d 100644 --- a/kmath-tensorflow/README.md +++ b/kmath-tensorflow/README.md @@ -6,19 +6,8 @@ Google tensorflow connector ## Artifact: -The Maven coordinates of this project are `space.kscience:kmath-tensorflow:0.4.0-dev-1`. +The Maven coordinates of this project are `space.kscience:kmath-tensorflow:0.4.0-dev-3`. -**Gradle Groovy:** -```groovy -repositories { - maven { url 'https://repo.kotlin.link' } - mavenCentral() -} - -dependencies { - implementation 'space.kscience:kmath-tensorflow:0.4.0-dev-1' -} -``` **Gradle Kotlin DSL:** ```kotlin repositories { @@ -27,6 +16,6 @@ repositories { } dependencies { - implementation("space.kscience:kmath-tensorflow:0.4.0-dev-1") + implementation("space.kscience:kmath-tensorflow:0.4.0-dev-3") } ``` diff --git a/kmath-tensors/README.md b/kmath-tensors/README.md index 80f751ffe..34cf33cb3 100644 --- a/kmath-tensors/README.md +++ b/kmath-tensors/README.md @@ -9,19 +9,8 @@ Common linear algebra operations on tensors. ## Artifact: -The Maven coordinates of this project are `space.kscience:kmath-tensors:0.4.0-dev-1`. +The Maven coordinates of this project are `space.kscience:kmath-tensors:0.4.0-dev-3`. -**Gradle Groovy:** -```groovy -repositories { - maven { url 'https://repo.kotlin.link' } - mavenCentral() -} - -dependencies { - implementation 'space.kscience:kmath-tensors:0.4.0-dev-1' -} -``` **Gradle Kotlin DSL:** ```kotlin repositories { @@ -30,6 +19,6 @@ repositories { } dependencies { - implementation("space.kscience:kmath-tensors:0.4.0-dev-1") + implementation("space.kscience:kmath-tensors:0.4.0-dev-3") } ``` diff --git a/kmath-viktor/README.md b/kmath-viktor/README.md index 8a781af4c..3b7b8152a 100644 --- a/kmath-viktor/README.md +++ b/kmath-viktor/README.md @@ -6,19 +6,8 @@ Binding for https://github.com/JetBrains-Research/viktor ## Artifact: -The Maven coordinates of this project are `space.kscience:kmath-viktor:0.4.0-dev-1`. +The Maven coordinates of this project are `space.kscience:kmath-viktor:0.4.0-dev-3`. -**Gradle Groovy:** -```groovy -repositories { - maven { url 'https://repo.kotlin.link' } - mavenCentral() -} - -dependencies { - implementation 'space.kscience:kmath-viktor:0.4.0-dev-1' -} -``` **Gradle Kotlin DSL:** ```kotlin repositories { @@ -27,6 +16,6 @@ repositories { } dependencies { - implementation("space.kscience:kmath-viktor:0.4.0-dev-1") + implementation("space.kscience:kmath-viktor:0.4.0-dev-3") } ``` diff --git a/kmath-viktor/api/kmath-viktor.api b/kmath-viktor/api/kmath-viktor.api index 39ae1f84c..11e312e12 100644 --- a/kmath-viktor/api/kmath-viktor.api +++ b/kmath-viktor/api/kmath-viktor.api @@ -12,6 +12,8 @@ public final class space/kscience/kmath/viktor/ViktorBuffer : space/kscience/kma public final fun getFlatArray ()Lorg/jetbrains/bio/viktor/F64FlatArray; public fun getSize ()I public static fun getSize-impl (Lorg/jetbrains/bio/viktor/F64FlatArray;)I + public fun getType-V0oMfBY ()Lkotlin/reflect/KType; + public static fun getType-V0oMfBY (Lorg/jetbrains/bio/viktor/F64FlatArray;)Lkotlin/reflect/KType; public fun hashCode ()I public static fun hashCode-impl (Lorg/jetbrains/bio/viktor/F64FlatArray;)I public fun iterator ()Ljava/util/Iterator; @@ -62,7 +64,7 @@ public class space/kscience/kmath/viktor/ViktorFieldOpsND : space/kscience/kmath public synthetic fun exp (Ljava/lang/Object;)Ljava/lang/Object; public fun exp (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/viktor/ViktorStructureND; public synthetic fun getElementAlgebra ()Lspace/kscience/kmath/operations/Algebra; - public fun getElementAlgebra ()Lspace/kscience/kmath/operations/DoubleField; + public fun getElementAlgebra ()Lspace/kscience/kmath/operations/Float64Field; public final fun getF64Buffer (Lspace/kscience/kmath/nd/StructureND;)Lorg/jetbrains/bio/viktor/F64Array; public synthetic fun ln (Ljava/lang/Object;)Ljava/lang/Object; public fun ln (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/viktor/ViktorStructureND; @@ -72,6 +74,8 @@ public class space/kscience/kmath/viktor/ViktorFieldOpsND : space/kscience/kmath public fun mapIndexed (Lspace/kscience/kmath/nd/StructureND;Lkotlin/jvm/functions/Function3;)Lspace/kscience/kmath/viktor/ViktorStructureND; public synthetic fun minus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; public fun minus (Lspace/kscience/kmath/nd/StructureND;Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/viktor/ViktorStructureND; + public synthetic fun mutableStructureND-qL90JFI ([ILkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/MutableStructureND; + public fun mutableStructureND-qL90JFI ([ILkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/viktor/ViktorStructureND; public synthetic fun plus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; public fun plus (Lspace/kscience/kmath/nd/StructureND;D)Lspace/kscience/kmath/viktor/ViktorStructureND; public synthetic fun plus (Lspace/kscience/kmath/nd/StructureND;Ljava/lang/Object;)Lspace/kscience/kmath/nd/StructureND; @@ -85,8 +89,6 @@ public class space/kscience/kmath/viktor/ViktorFieldOpsND : space/kscience/kmath public fun sin (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/viktor/ViktorStructureND; public synthetic fun sinh (Ljava/lang/Object;)Ljava/lang/Object; public fun sinh (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/viktor/ViktorStructureND; - public synthetic fun structureND-qL90JFI ([ILkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/nd/StructureND; - public fun structureND-qL90JFI ([ILkotlin/jvm/functions/Function2;)Lspace/kscience/kmath/viktor/ViktorStructureND; public synthetic fun tan (Ljava/lang/Object;)Ljava/lang/Object; public fun tan (Lspace/kscience/kmath/nd/StructureND;)Lspace/kscience/kmath/viktor/ViktorStructureND; public synthetic fun times (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object; @@ -102,8 +104,8 @@ public final class space/kscience/kmath/viktor/ViktorFieldOpsND$Companion : spac public final class space/kscience/kmath/viktor/ViktorFieldOpsNDKt { public static final fun ViktorFieldND ([I)Lspace/kscience/kmath/viktor/ViktorFieldND; - public static final fun getViktorAlgebra (Lspace/kscience/kmath/operations/DoubleField;)Lspace/kscience/kmath/viktor/ViktorFieldOpsND; - public static final fun viktorAlgebra (Lspace/kscience/kmath/operations/DoubleField;[I)Lspace/kscience/kmath/viktor/ViktorFieldND; + public static final fun getViktorAlgebra (Lspace/kscience/kmath/operations/Float64Field;)Lspace/kscience/kmath/viktor/ViktorFieldOpsND; + public static final fun viktorAlgebra (Lspace/kscience/kmath/operations/Float64Field;[I)Lspace/kscience/kmath/viktor/ViktorFieldND; } public final class space/kscience/kmath/viktor/ViktorStructureND : space/kscience/kmath/nd/MutableStructureND { @@ -113,6 +115,7 @@ public final class space/kscience/kmath/viktor/ViktorStructureND : space/kscienc public synthetic fun get ([I)Ljava/lang/Object; public final fun getF64Buffer ()Lorg/jetbrains/bio/viktor/F64Array; public fun getShape-IIYLAfE ()[I + public fun getType-V0oMfBY ()Lkotlin/reflect/KType; public fun set ([ID)V public synthetic fun set ([ILjava/lang/Object;)V } diff --git a/test-utils/api/test-utils.api b/test-utils/api/test-utils.api index fc812a9a6..2915fa039 100644 --- a/test-utils/api/test-utils.api +++ b/test-utils/api/test-utils.api @@ -4,7 +4,7 @@ public final class space/kscience/kmath/testutils/AssertsKt { } public final class space/kscience/kmath/testutils/BufferEqualityKt { - public static final fun contentEquals-2c9zdjM ([D[D)Z + public static final fun contentEquals-YsAwp1c ([D[D)Z public static final fun contentEqualsArray ([D[D)Z public static final fun contentEqualsBuffer ([D[D)Z } From 32c5b3c10d1ecce6ea3dc7fc5638f4d99909d4f4 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Tue, 20 Feb 2024 18:38:21 +0300 Subject: [PATCH 31/40] Add publishing to attributes-kt --- attributes-kt/build.gradle.kts | 1 + .../kmath/benchmarks/NDFieldBenchmark.kt | 20 ++++++++++--------- build.gradle.kts | 2 +- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/attributes-kt/build.gradle.kts b/attributes-kt/build.gradle.kts index f5ead84a3..5956f1f16 100644 --- a/attributes-kt/build.gradle.kts +++ b/attributes-kt/build.gradle.kts @@ -1,5 +1,6 @@ plugins { id("space.kscience.gradle.mpp") + `maven-publish` } version = "0.1.0" diff --git a/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/NDFieldBenchmark.kt b/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/NDFieldBenchmark.kt index 297dce8b9..77ca03099 100644 --- a/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/NDFieldBenchmark.kt +++ b/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/NDFieldBenchmark.kt @@ -25,6 +25,16 @@ import space.kscience.kmath.viktor.viktorAlgebra @State(Scope.Benchmark) internal class NDFieldBenchmark { + private companion object { + private const val dim = 1000 + private const val n = 100 + private val shape = ShapeND(dim, dim) + private val specializedField = Float64Field.ndAlgebra + private val genericField = BufferedFieldOpsND(Float64Field) + private val nd4jField = Float64Field.nd4j + private val viktorField = Float64Field.viktorAlgebra + } + @Benchmark fun specializedFieldAdd(blackhole: Blackhole) = with(specializedField) { var res: StructureND = one(shape) @@ -82,13 +92,5 @@ internal class NDFieldBenchmark { // blackhole.consume(res) // } - private companion object { - private const val dim = 1000 - private const val n = 100 - private val shape = ShapeND(dim, dim) - private val specializedField = Float64Field.ndAlgebra - private val genericField = BufferedFieldOpsND(Float64Field) - private val nd4jField = Float64Field.nd4j - private val viktorField = Float64Field.viktorAlgebra - } + } diff --git a/build.gradle.kts b/build.gradle.kts index 393576166..ae4ab51cf 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -14,7 +14,7 @@ allprojects { } group = "space.kscience" - version = "0.4.0" + version = "0.4.0-RC" } subprojects { From 49f0d1fe7dbfea5cebd6b9283a0e33321e1e6517 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Tue, 20 Feb 2024 19:35:00 +0300 Subject: [PATCH 32/40] Fix types in geometry algebras --- CHANGELOG.md | 1 + examples/build.gradle.kts | 2 +- .../kmath/commons/optimization/CMOptimizer.kt | 2 +- .../geometry/euclidean2d/Float32Space2D.kt | 18 +++++++++--------- .../geometry/euclidean2d/Float64Space2D.kt | 16 ++++++++-------- .../geometry/euclidean3d/Float32Space3D.kt | 18 +++++++++--------- 6 files changed, 29 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d98177726..1d2525a80 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -52,6 +52,7 @@ - Median statistics - Complex power of negative real numbers - Add proper mutability for MutableBufferND rows and columns +- Generic Float32 and Float64 vectors are used in geometry algebras. ## 0.3.1 - 2023-04-09 diff --git a/examples/build.gradle.kts b/examples/build.gradle.kts index c0db25dca..97a3cb8c2 100644 --- a/examples/build.gradle.kts +++ b/examples/build.gradle.kts @@ -52,7 +52,7 @@ dependencies { implementation("org.slf4j:slf4j-simple:1.7.32") // plotting - implementation("space.kscience:plotlykt-server:0.5.3-dev-1") + implementation("space.kscience:plotlykt-server:0.7.0") } kotlin { diff --git a/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/optimization/CMOptimizer.kt b/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/optimization/CMOptimizer.kt index afbb96d9b..3c5f8f5e2 100644 --- a/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/optimization/CMOptimizer.kt +++ b/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/optimization/CMOptimizer.kt @@ -116,7 +116,7 @@ public object CMOptimizer : Optimizer> { } addOptimizationData(gradientFunction) - val logger = problem.attributes[OptimizationLog] +// val logger = problem.attributes[OptimizationLog] problem.attributes[CMOptimizerData]?.let { builders: Set OptimizationData> -> builders.forEach { dataBuilder -> diff --git a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean2d/Float32Space2D.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean2d/Float32Space2D.kt index d687a3574..ed3caede8 100644 --- a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean2d/Float32Space2D.kt +++ b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean2d/Float32Space2D.kt @@ -26,7 +26,7 @@ public interface Float32Vector2D : Vector2D{ } -public object Float32Space2D : GeometrySpace { +public object Float32Space2D : GeometrySpace, Float32> { @Serializable @SerialName("Float32Vector2D") private data class Vector2DImpl( @@ -54,21 +54,21 @@ public object Float32Space2D : GeometrySpace { override val zero: Float32Vector2D by lazy { vector(0f, 0f) } - override fun norm(arg: Float32Vector2D): Float32 = sqrt(arg.x.pow(2) + arg.y.pow(2)) + override fun norm(arg: Vector2D): Float32 = sqrt(arg.x.pow(2) + arg.y.pow(2)) - public fun Float32Vector2D.norm(): Float32 = norm(this) + public fun Vector2D.norm(): Float32 = norm(this) - override fun Float32Vector2D.unaryMinus(): Float32Vector2D = vector(-x, -y) + override fun Vector2D.unaryMinus(): Float32Vector2D = vector(-x, -y) - override fun Float32Vector2D.distanceTo(other: Float32Vector2D): Float32 = (this - other).norm() + override fun Vector2D.distanceTo(other: Vector2D): Float32 = (this - other).norm() - override fun add(left: Float32Vector2D, right: Float32Vector2D): Float32Vector2D = + override fun add(left: Vector2D, right: Vector2D): Float32Vector2D = vector(left.x + right.x, left.y + right.y) - override fun scale(a: Float32Vector2D, value: Double): Float32Vector2D = + override fun scale(a: Vector2D, value: Double): Float32Vector2D = vector(a.x * value, a.y * value) - override fun Float32Vector2D.dot(other: Float32Vector2D): Double = + override fun Vector2D.dot(other: Vector2D): Double = (x * other.x + y * other.y).toDouble() public val xAxis: Float32Vector2D = vector(1.0, 0.0) @@ -76,7 +76,7 @@ public object Float32Space2D : GeometrySpace { override val defaultPrecision: Float32 = 1e-3f - override val bufferFactory: MutableBufferFactory = MutableBufferFactory() + override val bufferFactory: MutableBufferFactory> = MutableBufferFactory() } public fun Float32Vector2D(x: Number, y: Number): Float32Vector2D = Float32Space2D.vector(x, y) diff --git a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean2d/Float64Space2D.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean2d/Float64Space2D.kt index 05b9401d7..6a4f5ef34 100644 --- a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean2d/Float64Space2D.kt +++ b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean2d/Float64Space2D.kt @@ -35,7 +35,7 @@ public typealias DoubleVector2D = Float64Vector2D /** * 2D Euclidean space */ -public object Float64Space2D : GeometrySpace, ScaleOperations { +public object Float64Space2D : GeometrySpace, Float64>, ScaleOperations> { @Serializable @@ -61,23 +61,23 @@ public object Float64Space2D : GeometrySpace, ScaleOpe override val zero: Float64Vector2D by lazy { vector(0.0, 0.0) } - override fun norm(arg: Float64Vector2D): Double = sqrt(arg.x.pow(2) + arg.y.pow(2)) + override fun norm(arg: Vector2D): Double = sqrt(arg.x.pow(2) + arg.y.pow(2)) - override fun Float64Vector2D.unaryMinus(): Float64Vector2D = vector(-x, -y) + override fun Vector2D.unaryMinus(): Float64Vector2D = vector(-x, -y) - override fun Float64Vector2D.distanceTo(other: Float64Vector2D): Double = norm(this - other) - override fun add(left: Float64Vector2D, right: Float64Vector2D): Float64Vector2D = + override fun Vector2D.distanceTo(other: Vector2D): Double = norm(this - other) + override fun add(left: Vector2D, right: Vector2D): Float64Vector2D = vector(left.x + right.x, left.y + right.y) - override fun scale(a: Float64Vector2D, value: Double): Float64Vector2D = vector(a.x * value, a.y * value) - override fun Float64Vector2D.dot(other: Float64Vector2D): Double = x * other.x + y * other.y + override fun scale(a: Vector2D, value: Double): Float64Vector2D = vector(a.x * value, a.y * value) + override fun Vector2D.dot(other: Vector2D): Double = x * other.x + y * other.y public val xAxis: Float64Vector2D = vector(1.0, 0.0) public val yAxis: Float64Vector2D = vector(0.0, 1.0) override val defaultPrecision: Double = 1e-6 - override val bufferFactory: MutableBufferFactory = MutableBufferFactory() + override val bufferFactory: MutableBufferFactory> = MutableBufferFactory() } public fun Float64Vector2D(x: Number, y: Number): Float64Vector2D = Float64Space2D.vector(x, y) diff --git a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean3d/Float32Space3D.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean3d/Float32Space3D.kt index 7204ac4f9..56ff49533 100644 --- a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean3d/Float32Space3D.kt +++ b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean3d/Float32Space3D.kt @@ -26,7 +26,7 @@ public interface Float32Vector3D : Vector3D{ } -public object Float32Space3D : GeometrySpace { +public object Float32Space3D : GeometrySpace, Float32> { @Serializable @SerialName("Float32Vector3D") @@ -56,21 +56,21 @@ public object Float32Space3D : GeometrySpace { override val zero: Float32Vector3D by lazy { vector(0.0, 0.0, 0.0) } - override fun norm(arg: Float32Vector3D): Float32 = sqrt(arg.x.pow(2) + arg.y.pow(2) + arg.z.pow(2)) + override fun norm(arg: Vector3D): Float32 = sqrt(arg.x.pow(2) + arg.y.pow(2) + arg.z.pow(2)) - public fun Float32Vector3D.norm(): Float32 = norm(this) + public fun Vector3D.norm(): Float32 = norm(this) - override fun Float32Vector3D.unaryMinus(): Float32Vector3D = vector(-x, -y, -z) + override fun Vector3D.unaryMinus(): Float32Vector3D = vector(-x, -y, -z) - override fun Float32Vector3D.distanceTo(other: Float32Vector3D): Float32 = (this - other).norm() + override fun Vector3D.distanceTo(other: Vector3D): Float32 = (this - other).norm() - override fun add(left: Float32Vector3D, right: Float32Vector3D): Float32Vector3D = + override fun add(left: Vector3D, right: Vector3D): Float32Vector3D = vector(left.x + right.x, left.y + right.y, left.z + right.z) - override fun scale(a: Float32Vector3D, value: Double): Float32Vector3D = + override fun scale(a: Vector3D, value: Double): Float32Vector3D = vector(a.x * value, a.y * value, a.z * value) - override fun Float32Vector3D.dot(other: Float32Vector3D): Double = + override fun Vector3D.dot(other: Vector3D): Double = (x * other.x + y * other.y + z * other.z).toDouble() /** @@ -106,7 +106,7 @@ public object Float32Space3D : GeometrySpace { override val defaultPrecision: Float32 = 1e-3f - override val bufferFactory: MutableBufferFactory = MutableBufferFactory() + override val bufferFactory: MutableBufferFactory> = MutableBufferFactory() } public fun Float32Vector3D(x: Number, y: Number, z: Number): Float32Vector3D = Float32Space3D.vector(x, y, z) From dba001eff345c0dafe0c38a80278fa81ec369291 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Tue, 20 Feb 2024 20:39:57 +0300 Subject: [PATCH 33/40] Fix types in geometry algebras --- .../kotlin/space/kscience/kmath/geometry/Line.kt | 11 +++++------ .../kmath/geometry/{euclidean2d => }/Polygon.kt | 4 +--- .../kscience/kmath/geometry/euclidean2d/Circle2D.kt | 12 ++++++++---- .../kmath/geometry/euclidean3d/Float64Space3D.kt | 3 ++- .../kmath/geometry/euclidean3d/rotations3D.kt | 5 +++-- .../space/kscience/kmath/geometry/vectorPrecision.kt | 5 +++-- 6 files changed, 22 insertions(+), 18 deletions(-) rename kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/{euclidean2d => }/Polygon.kt (73%) diff --git a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Line.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Line.kt index a226ab04d..c65ccd43d 100644 --- a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Line.kt +++ b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Line.kt @@ -7,8 +7,7 @@ package space.kscience.kmath.geometry import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable -import space.kscience.kmath.geometry.euclidean2d.Float64Vector2D -import space.kscience.kmath.geometry.euclidean3d.Float64Vector3D +import space.kscience.kmath.structures.Float64 /** * A line formed by [start] vector of start and a [direction] vector. Direction vector is not necessarily normalized, @@ -25,8 +24,8 @@ private data class LineImpl(override val start: V, override val dir public fun Line(base: V, direction: V): Line = LineImpl(base, direction) -public typealias Line2D = Line -public typealias Line3D = Line +public typealias Line2D = Line> +public typealias Line3D = Line> /** * A directed line segment between [begin] and [end] @@ -49,5 +48,5 @@ public fun LineSegment.line(algebra: GeometrySpace): Line Line(begin, end - begin) } -public typealias LineSegment2D = LineSegment -public typealias LineSegment3D = LineSegment +public typealias LineSegment2D = LineSegment> +public typealias LineSegment3D = LineSegment> diff --git a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean2d/Polygon.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Polygon.kt similarity index 73% rename from kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean2d/Polygon.kt rename to kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Polygon.kt index 21ae86dbb..d7b450ab0 100644 --- a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean2d/Polygon.kt +++ b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Polygon.kt @@ -3,9 +3,7 @@ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ -package space.kscience.kmath.geometry.euclidean2d - -import space.kscience.kmath.geometry.Vector2D +package space.kscience.kmath.geometry /** diff --git a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean2d/Circle2D.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean2d/Circle2D.kt index e17a5573a..fcffc7714 100644 --- a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean2d/Circle2D.kt +++ b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean2d/Circle2D.kt @@ -7,10 +7,11 @@ package space.kscience.kmath.geometry.euclidean2d import kotlinx.serialization.Serializable import space.kscience.kmath.geometry.Vector2D +import space.kscience.kmath.structures.Float64 import kotlin.math.PI -public interface Circle2D{ +public interface Circle2D { public val center: Vector2D public val radius: Double } @@ -23,9 +24,12 @@ public val Circle2D<*>.circumference: Double get() = radius * 2 * PI @Serializable public data class Float64Circle2D( @Serializable(Float64Space2D.VectorSerializer::class) override val center: Float64Vector2D, - override val radius: Double -): Circle2D + override val radius: Float64, +) : Circle2D -public fun Circle2D(center: Float64Vector2D, radius: Double): Circle2D = Float64Circle2D(center, radius) +public fun Circle2D(center: Vector2D, radius: Double): Circle2D = Float64Circle2D( + center as? Float64Vector2D ?: Float64Vector2D(center.x, center.y), + radius +) diff --git a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean3d/Float64Space3D.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean3d/Float64Space3D.kt index a2c23926a..86ddf554b 100644 --- a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean3d/Float64Space3D.kt +++ b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean3d/Float64Space3D.kt @@ -128,7 +128,8 @@ public object Float64Space3D : GeometrySpace, Double> { override val bufferFactory: MutableBufferFactory> = MutableBufferFactory() } +@Suppress("UnusedReceiverParameter") public val Float64Field.euclidean3D: Float64Space3D get() = Float64Space3D -public val Float64Vector3D.r: Double get() = Float64Space3D.norm(this) +public val Vector3D.r: Double get() = Float64Space3D.norm(this) diff --git a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean3d/rotations3D.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean3d/rotations3D.kt index 212cc251e..e65bd8e22 100644 --- a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean3d/rotations3D.kt +++ b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean3d/rotations3D.kt @@ -37,7 +37,8 @@ public infix fun Quaternion.dot(other: Quaternion): Double = w * other.w + x * o /** * Represent a vector as quaternion with zero a rotation angle. */ -internal fun Float64Vector3D.asQuaternion(): Quaternion = Quaternion(0.0, x, y, z) +internal fun Vector3D.asQuaternion(): Quaternion = Quaternion(0.0, x, y, z) + /** * Angle in radians denoted by this quaternion rotation @@ -71,7 +72,7 @@ public val Quaternion.vector: Float64Vector3D /** * Rotate a vector in a [Float64Space3D] with [quaternion] */ -public fun Float64Space3D.rotate(vector: Float64Vector3D, quaternion: Quaternion): Float64Vector3D = +public fun Float64Space3D.rotate(vector: Vector3D, quaternion: Quaternion): Float64Vector3D = with(QuaternionAlgebra) { val p = vector.asQuaternion() (quaternion * p * quaternion.reciprocal).vector diff --git a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/vectorPrecision.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/vectorPrecision.kt index 9eb1c069c..e8a14d036 100644 --- a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/vectorPrecision.kt +++ b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/vectorPrecision.kt @@ -9,6 +9,7 @@ import space.kscience.kmath.geometry.euclidean2d.Float64Space2D import space.kscience.kmath.geometry.euclidean2d.Float64Vector2D import space.kscience.kmath.geometry.euclidean3d.Float64Space3D import space.kscience.kmath.geometry.euclidean3d.Float64Vector3D +import space.kscience.kmath.structures.Float64 /** @@ -25,7 +26,7 @@ public fun > V.equalsVector( /** * Vector equality using Euclidian L2 norm and given [precision] */ -public fun Float64Vector2D.equalsVector( +public fun Vector2D.equalsVector( other: Float64Vector2D, precision: Double = Float64Space2D.defaultPrecision, ): Boolean = equalsVector(Float64Space2D, other, precision) @@ -33,7 +34,7 @@ public fun Float64Vector2D.equalsVector( /** * Vector equality using Euclidean L2 norm and given [precision] */ -public fun Float64Vector3D.equalsVector( +public fun Vector3D.equalsVector( other: Float64Vector3D, precision: Double = Float64Space3D.defaultPrecision, ): Boolean = equalsVector(Float64Space3D, other, precision) From fcb7e2fa7d91667522d681d78c92c7aff181e29c Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Thu, 22 Feb 2024 21:03:58 +0300 Subject: [PATCH 34/40] Reverse types for buffers and typealiases for geometry. --- CHANGELOG.md | 3 +- build.gradle.kts | 2 +- .../kscience/kmath/commons/linear/CMMatrix.kt | 3 +- .../kscience/kmath/complex/Quaternion.kt | 2 - kmath-core/api/kmath-core.api | 87 ++++++------------- .../kscience/kmath/expressions/DSAlgebra.kt | 2 +- .../kmath/expressions/SimpleAutoDiff.kt | 2 +- .../kscience/kmath/linear/LinearSpace.kt | 2 +- .../kscience/kmath/linear/LupDecomposition.kt | 6 +- .../kscience/kmath/linear/MatrixWrapper.kt | 4 +- .../space/kscience/kmath/linear/Transposed.kt | 2 - .../kscience/kmath/linear/VirtualMatrix.kt | 4 +- .../space/kscience/kmath/misc/sorting.kt | 10 +-- .../space/kscience/kmath/nd/BufferND.kt | 3 - .../space/kscience/kmath/nd/Float64FieldND.kt | 4 - .../kscience/kmath/nd/PermutedStructureND.kt | 5 -- .../space/kscience/kmath/nd/Structure1D.kt | 19 ---- .../space/kscience/kmath/nd/Structure2D.kt | 13 +-- .../space/kscience/kmath/nd/StructureND.kt | 7 +- .../kscience/kmath/nd/VirtualStructureND.kt | 7 +- .../space/kscience/kmath/nd/operationsND.kt | 4 +- .../kscience/kmath/nd/primitiveStructureND.kt | 7 -- .../kscience/kmath/structures/ArrayBuffer.kt | 14 +-- .../space/kscience/kmath/structures/Buffer.kt | 15 +--- .../kmath/structures/BufferAccessor2D.kt | 3 - .../kscience/kmath/structures/BufferView.kt | 5 -- .../kmath/structures/FlaggedBuffer.kt | 4 - .../kmath/structures/Float32Buffer.kt | 6 -- .../kmath/structures/Float64Buffer.kt | 6 -- .../kscience/kmath/structures/Int16Buffer.kt | 5 +- .../kscience/kmath/structures/Int32Buffer.kt | 4 - .../kscience/kmath/structures/Int64Buffer.kt | 6 -- .../kscience/kmath/structures/Int8Buffer.kt | 5 -- .../kscience/kmath/structures/ListBuffer.kt | 28 +----- .../kmath/structures/MutableBuffer.kt | 28 ++++-- .../space/kscience/kmath/linear/MatrixTest.kt | 2 +- .../kmath/structures/parallelMutableBuffer.kt | 2 +- .../kmath/linear/ParallelMatrixTest.kt | 2 +- .../kscience/kmath/streaming/RingBuffer.kt | 17 ++-- .../kmath/structures/LazyStructureND.kt | 7 +- .../kscience/kmath/dimensions/Wrappers.kt | 5 -- .../kscience/kmath/ejml/implementations.kt | 6 -- .../space/kscience/kmath/real/RealMatrix.kt | 2 +- .../kmath/interpolation/Interpolator.kt | 4 +- kmath-geometry/build.gradle.kts | 1 + .../space/kscience/kmath/geometry/Vector3D.kt | 4 - .../geometry/euclidean2d/Float32Space2D.kt | 7 +- .../geometry/euclidean2d/Float64Space2D.kt | 6 +- .../geometry/euclidean3d/Float32Space3D.kt | 7 +- .../geometry/euclidean3d/Float64Space3D.kt | 6 +- .../kmath/geometry/euclidean3d/rotations3D.kt | 3 - kmath-memory/api/kmath-memory.api | 2 - .../kscience/kmath/memory/MemoryBuffer.kt | 4 - .../kscience/kmath/multik/MultikTensor.kt | 2 - kmath-nd4j/api/kmath-nd4j.api | 1 - .../kscience/kmath/nd4j/Nd4jArrayStructure.kt | 4 - .../kscience/kmath/stat/ValueAndErrorField.kt | 2 - .../tensorflow/DoubleTensorFlowAlgebra.kt | 2 - .../kmath/tensorflow/IntTensorFlowAlgebra.kt | 8 -- .../kmath/tensorflow/TensorFlowAlgebra.kt | 6 +- .../kmath/tensors/core/DoubleTensor.kt | 6 +- .../kmath/tensors/core/DoubleTensor1D.kt | 3 - .../kscience/kmath/tensors/core/IntTensor.kt | 7 +- .../kmath/tensors/core/tensorTransform.kt | 2 +- kmath-viktor/api/kmath-viktor.api | 5 -- .../kscience/kmath/viktor/ViktorBuffer.kt | 4 - .../kmath/viktor/ViktorStructureND.kt | 4 - 67 files changed, 117 insertions(+), 353 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d2525a80..5c383fe95 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +18,7 @@ ### Added -- Reification. Explicit `SafeType` for algebras and buffers. +- Reification. Explicit `SafeType` for algebras. - Integer division algebras. - Float32 geometries. - New Attributes-kt module that could be used as stand-alone. It declares. type-safe attributes containers. @@ -30,6 +30,7 @@ ### Changed +- Buffer copy removed from API (added as an extension). - Default naming for algebra and buffers now uses IntXX/FloatXX notation instead of Java types. - Remove unnecessary inlines in basic algebras. - QuaternionField -> QuaternionAlgebra and does not implement `Field` anymore since it is non-commutative diff --git a/build.gradle.kts b/build.gradle.kts index ae4ab51cf..9231fc312 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -14,7 +14,7 @@ allprojects { } group = "space.kscience" - version = "0.4.0-RC" + version = "0.4.0-RC2" } subprojects { diff --git a/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/linear/CMMatrix.kt b/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/linear/CMMatrix.kt index 589dc19e0..1fe923cbb 100644 --- a/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/linear/CMMatrix.kt +++ b/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/linear/CMMatrix.kt @@ -23,7 +23,7 @@ import space.kscience.kmath.structures.IntBuffer import space.kscience.kmath.structures.asBuffer public class CMMatrix(public val origin: RealMatrix) : Matrix { - override val type: SafeType get() = DoubleField.type + override val rowNum: Int get() = origin.rowDimension override val colNum: Int get() = origin.columnDimension @@ -32,7 +32,6 @@ public class CMMatrix(public val origin: RealMatrix) : Matrix { @JvmInline public value class CMVector(public val origin: RealVector) : Point { - override val type: SafeType get() = DoubleField.type override val size: Int get() = origin.dimension override operator fun get(index: Int): Double = origin.getEntry(index) diff --git a/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/Quaternion.kt b/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/Quaternion.kt index d5093f4b0..6a6171975 100644 --- a/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/Quaternion.kt +++ b/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/Quaternion.kt @@ -36,8 +36,6 @@ public class Quaternion( require(!z.isNaN()) { "z-component of quaternion is not-a-number" } } - override val type: SafeType get() = safeTypeOf() - /** * Returns a string representation of this quaternion. */ diff --git a/kmath-core/api/kmath-core.api b/kmath-core/api/kmath-core.api index 0053dde28..460c2e3c4 100644 --- a/kmath-core/api/kmath-core.api +++ b/kmath-core/api/kmath-core.api @@ -428,7 +428,6 @@ public final class space/kscience/kmath/expressions/NamedMatrix : space/kscience public fun getRowNum ()I public fun getRows ()Ljava/util/List; public fun getShape-IIYLAfE ()[I - public fun getType-V0oMfBY ()Lkotlin/reflect/KType; public final fun getValues ()Lspace/kscience/kmath/nd/Structure2D; } @@ -820,7 +819,6 @@ public final class space/kscience/kmath/linear/MatrixWrapper : space/kscience/km public fun getRowNum ()I public fun getRows ()Ljava/util/List; public fun getShape-IIYLAfE ()[I - public fun getType-V0oMfBY ()Lkotlin/reflect/KType; public fun toString ()Ljava/lang/String; } @@ -871,7 +869,6 @@ public final class space/kscience/kmath/linear/TransposedMatrix : space/kscience public fun getColNum ()I public final fun getOrigin ()Lspace/kscience/kmath/nd/Structure2D; public fun getRowNum ()I - public fun getType-V0oMfBY ()Lkotlin/reflect/KType; } public final class space/kscience/kmath/linear/UpperTriangular : space/kscience/attributes/FlagAttribute, space/kscience/kmath/linear/MatrixAttribute { @@ -879,15 +876,14 @@ public final class space/kscience/kmath/linear/UpperTriangular : space/kscience/ } public final class space/kscience/kmath/linear/VirtualMatrix : space/kscience/kmath/nd/Structure2D { - public synthetic fun (Lkotlin/reflect/KType;IILspace/kscience/attributes/Attributes;Lkotlin/jvm/functions/Function2;ILkotlin/jvm/internal/DefaultConstructorMarker;)V - public synthetic fun (Lkotlin/reflect/KType;IILspace/kscience/attributes/Attributes;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/internal/DefaultConstructorMarker;)V + public fun (IILspace/kscience/attributes/Attributes;Lkotlin/jvm/functions/Function2;)V + public synthetic fun (IILspace/kscience/attributes/Attributes;Lkotlin/jvm/functions/Function2;ILkotlin/jvm/internal/DefaultConstructorMarker;)V public fun get (II)Ljava/lang/Object; public fun getAttributes ()Lspace/kscience/attributes/Attributes; public fun getColNum ()I public final fun getGenerator ()Lkotlin/jvm/functions/Function2; public fun getRowNum ()I public fun getShape-IIYLAfE ()[I - public fun getType-V0oMfBY ()Lkotlin/reflect/KType; } public final class space/kscience/kmath/linear/VirtualMatrixKt { @@ -1009,7 +1005,6 @@ public class space/kscience/kmath/nd/BufferND : space/kscience/kmath/nd/Structur public fun getBuffer ()Lspace/kscience/kmath/structures/Buffer; public fun getIndices ()Lspace/kscience/kmath/nd/ShapeIndexer; public fun getShape-IIYLAfE ()[I - public fun getType-V0oMfBY ()Lkotlin/reflect/KType; public fun toString ()Ljava/lang/String; } @@ -1160,7 +1155,6 @@ public final class space/kscience/kmath/nd/Float64BufferND : space/kscience/kmat public synthetic fun getBuffer ()Lspace/kscience/kmath/structures/MutableBuffer; public fun getBuffer-E20IKn8 ()[D public fun getDouble ([I)D - public fun getType-V0oMfBY ()Lkotlin/reflect/KType; public fun setDouble ([ID)V } @@ -1290,11 +1284,9 @@ public abstract interface class space/kscience/kmath/nd/MutableStructureND : spa public final class space/kscience/kmath/nd/MutableStructureNDAccessorBuffer : space/kscience/kmath/structures/MutableBuffer { public fun (Lspace/kscience/kmath/nd/MutableStructureND;ILkotlin/jvm/functions/Function1;)V - public fun copy ()Lspace/kscience/kmath/structures/MutableBuffer; public fun get (I)Ljava/lang/Object; public fun getSize ()I public final fun getStructure ()Lspace/kscience/kmath/nd/MutableStructureND; - public fun getType-V0oMfBY ()Lkotlin/reflect/KType; public fun set (ILjava/lang/Object;)V public fun toString ()Ljava/lang/String; } @@ -1316,7 +1308,6 @@ public final class space/kscience/kmath/nd/PermutedMutableStructureND : space/ks public final fun getOrigin ()Lspace/kscience/kmath/nd/MutableStructureND; public final fun getPermutation ()Lkotlin/jvm/functions/Function1; public fun getShape-IIYLAfE ()[I - public fun getType-V0oMfBY ()Lkotlin/reflect/KType; public fun set ([ILjava/lang/Object;)V } @@ -1326,7 +1317,6 @@ public final class space/kscience/kmath/nd/PermutedStructureND : space/kscience/ public final fun getOrigin ()Lspace/kscience/kmath/nd/StructureND; public final fun getPermutation ()Lkotlin/jvm/functions/Function1; public fun getShape-IIYLAfE ()[I - public fun getType-V0oMfBY ()Lkotlin/reflect/KType; } public final class space/kscience/kmath/nd/PermutedStructureNDKt { @@ -1477,7 +1467,7 @@ public final class space/kscience/kmath/nd/Structure2DKt { public abstract interface class space/kscience/kmath/nd/StructureAttribute : space/kscience/attributes/Attribute { } -public abstract interface class space/kscience/kmath/nd/StructureND : space/kscience/attributes/AttributeContainer, space/kscience/attributes/WithType, space/kscience/kmath/nd/WithShape { +public abstract interface class space/kscience/kmath/nd/StructureND : space/kscience/attributes/AttributeContainer, space/kscience/kmath/nd/WithShape { public static final field Companion Lspace/kscience/kmath/nd/StructureND$Companion; public fun elements ()Lkotlin/sequences/Sequence; public abstract fun get ([I)Ljava/lang/Object; @@ -1509,20 +1499,17 @@ public final class space/kscience/kmath/nd/StructureNDKt { public abstract interface class space/kscience/kmath/nd/StructureNDOfDouble : space/kscience/kmath/nd/StructureND { public abstract fun getDouble ([I)D - public fun getType-V0oMfBY ()Lkotlin/reflect/KType; } public abstract interface class space/kscience/kmath/nd/StructureNDOfInt : space/kscience/kmath/nd/StructureND { public abstract fun getInt ([I)I - public fun getType-V0oMfBY ()Lkotlin/reflect/KType; } public class space/kscience/kmath/nd/VirtualStructureND : space/kscience/kmath/nd/StructureND { - public synthetic fun (Lkotlin/reflect/KType;[ILkotlin/jvm/functions/Function1;Lkotlin/jvm/internal/DefaultConstructorMarker;)V + public synthetic fun ([ILkotlin/jvm/functions/Function1;Lkotlin/jvm/internal/DefaultConstructorMarker;)V public fun get ([I)Ljava/lang/Object; public final fun getProducer ()Lkotlin/jvm/functions/Function1; public fun getShape-IIYLAfE ()[I - public fun getType-V0oMfBY ()Lkotlin/reflect/KType; } public abstract interface class space/kscience/kmath/nd/WithShape { @@ -2376,21 +2363,31 @@ public abstract interface class space/kscience/kmath/operations/WithSize { } public final class space/kscience/kmath/structures/ArrayBuffer : space/kscience/kmath/structures/MutableBuffer { - public synthetic fun (Lkotlin/reflect/KType;[Ljava/lang/Object;Lkotlin/jvm/internal/DefaultConstructorMarker;)V - public fun copy ()Lspace/kscience/kmath/structures/MutableBuffer; + public static final synthetic fun box-impl ([Ljava/lang/Object;)Lspace/kscience/kmath/structures/ArrayBuffer; + public static fun constructor-impl ([Ljava/lang/Object;)[Ljava/lang/Object; + public fun equals (Ljava/lang/Object;)Z + public static fun equals-impl ([Ljava/lang/Object;Ljava/lang/Object;)Z + public static final fun equals-impl0 ([Ljava/lang/Object;[Ljava/lang/Object;)Z public fun get (I)Ljava/lang/Object; + public static fun get-impl ([Ljava/lang/Object;I)Ljava/lang/Object; public fun getSize ()I - public fun getType-V0oMfBY ()Lkotlin/reflect/KType; + public static fun getSize-impl ([Ljava/lang/Object;)I + public fun hashCode ()I + public static fun hashCode-impl ([Ljava/lang/Object;)I public fun iterator ()Ljava/util/Iterator; + public static fun iterator-impl ([Ljava/lang/Object;)Ljava/util/Iterator; public fun set (ILjava/lang/Object;)V + public static fun set-impl ([Ljava/lang/Object;ILjava/lang/Object;)V public fun toString ()Ljava/lang/String; + public static fun toString-impl ([Ljava/lang/Object;)Ljava/lang/String; + public final synthetic fun unbox-impl ()[Ljava/lang/Object; } public final class space/kscience/kmath/structures/ArrayBufferKt { - public static final fun asBuffer-Fnn_obI ([Ljava/lang/Object;Lkotlin/reflect/KType;)Lspace/kscience/kmath/structures/ArrayBuffer; + public static final fun asBuffer ([Ljava/lang/Object;)[Ljava/lang/Object; } -public abstract interface class space/kscience/kmath/structures/Buffer : space/kscience/attributes/WithType, space/kscience/kmath/operations/WithSize { +public abstract interface class space/kscience/kmath/structures/Buffer : space/kscience/kmath/operations/WithSize { public static final field Companion Lspace/kscience/kmath/structures/Buffer$Companion; public abstract fun get (I)Ljava/lang/Object; public abstract fun getSize ()I @@ -2449,7 +2446,6 @@ public final class space/kscience/kmath/structures/BufferSlice : space/kscience/ public abstract interface class space/kscience/kmath/structures/BufferView : space/kscience/kmath/structures/Buffer { public fun get (I)Ljava/lang/Object; public abstract fun getOrigin ()Lspace/kscience/kmath/structures/Buffer; - public fun getType-V0oMfBY ()Lkotlin/reflect/KType; } public final class space/kscience/kmath/structures/BufferViewKt { @@ -2477,7 +2473,6 @@ public final class space/kscience/kmath/structures/FlaggedDoubleBuffer : space/k public fun getFlag (I)B public final fun getFlags ()[B public fun getSize ()I - public fun getType-V0oMfBY ()Lkotlin/reflect/KType; public final fun getValues ()[D public fun iterator ()Ljava/util/Iterator; public fun toString ()Ljava/lang/String; @@ -2486,8 +2481,6 @@ public final class space/kscience/kmath/structures/FlaggedDoubleBuffer : space/k public final class space/kscience/kmath/structures/Float32Buffer : space/kscience/kmath/structures/PrimitiveBuffer { public static final synthetic fun box-impl ([F)Lspace/kscience/kmath/structures/Float32Buffer; public static fun constructor-impl ([F)[F - public fun copy ()Lspace/kscience/kmath/structures/MutableBuffer; - public static fun copy-impl ([F)Lspace/kscience/kmath/structures/MutableBuffer; public fun equals (Ljava/lang/Object;)Z public static fun equals-impl ([FLjava/lang/Object;)Z public static final fun equals-impl0 ([F[F)Z @@ -2497,8 +2490,6 @@ public final class space/kscience/kmath/structures/Float32Buffer : space/kscienc public final fun getArray ()[F public fun getSize ()I public static fun getSize-impl ([F)I - public fun getType-V0oMfBY ()Lkotlin/reflect/KType; - public static fun getType-V0oMfBY ([F)Lkotlin/reflect/KType; public fun hashCode ()I public static fun hashCode-impl ([F)I public synthetic fun iterator ()Ljava/util/Iterator; @@ -2523,9 +2514,6 @@ public final class space/kscience/kmath/structures/Float64Buffer : space/kscienc public static final field Companion Lspace/kscience/kmath/structures/Float64Buffer$Companion; public static final synthetic fun box-impl ([D)Lspace/kscience/kmath/structures/Float64Buffer; public static fun constructor-impl ([D)[D - public synthetic fun copy ()Lspace/kscience/kmath/structures/MutableBuffer; - public fun copy-E20IKn8 ()[D - public static fun copy-E20IKn8 ([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 @@ -2535,8 +2523,6 @@ public final class space/kscience/kmath/structures/Float64Buffer : space/kscienc public final fun getArray ()[D public fun getSize ()I public static fun getSize-impl ([D)I - public fun getType-V0oMfBY ()Lkotlin/reflect/KType; - public static fun getType-V0oMfBY ([D)Lkotlin/reflect/KType; public fun hashCode ()I public static fun hashCode-impl ([D)I public synthetic fun iterator ()Ljava/util/Iterator; @@ -2571,8 +2557,6 @@ public abstract interface class space/kscience/kmath/structures/Float64BufferTra public final class space/kscience/kmath/structures/Int16Buffer : space/kscience/kmath/structures/MutableBuffer { public static final synthetic fun box-impl ([S)Lspace/kscience/kmath/structures/Int16Buffer; public static fun constructor-impl ([S)[S - public fun copy ()Lspace/kscience/kmath/structures/MutableBuffer; - public static fun copy-impl ([S)Lspace/kscience/kmath/structures/MutableBuffer; public fun equals (Ljava/lang/Object;)Z public static fun equals-impl ([SLjava/lang/Object;)Z public static final fun equals-impl0 ([S[S)Z @@ -2582,8 +2566,6 @@ public final class space/kscience/kmath/structures/Int16Buffer : space/kscience/ public final fun getArray ()[S public fun getSize ()I public static fun getSize-impl ([S)I - public fun getType-V0oMfBY ()Lkotlin/reflect/KType; - public static fun getType-V0oMfBY ([S)Lkotlin/reflect/KType; public fun hashCode ()I public static fun hashCode-impl ([S)I public synthetic fun iterator ()Ljava/util/Iterator; @@ -2607,9 +2589,6 @@ public final class space/kscience/kmath/structures/Int16BufferKt { public final class space/kscience/kmath/structures/Int32Buffer : space/kscience/kmath/structures/PrimitiveBuffer { public static final synthetic fun box-impl ([I)Lspace/kscience/kmath/structures/Int32Buffer; public static fun constructor-impl ([I)[I - public synthetic fun copy ()Lspace/kscience/kmath/structures/MutableBuffer; - public fun copy-M_oXE9g ()[I - public static fun copy-M_oXE9g ([I)[I public fun equals (Ljava/lang/Object;)Z public static fun equals-impl ([ILjava/lang/Object;)Z public static final fun equals-impl0 ([I[I)Z @@ -2619,8 +2598,6 @@ public final class space/kscience/kmath/structures/Int32Buffer : space/kscience/ public final fun getArray ()[I public fun getSize ()I public static fun getSize-impl ([I)I - public fun getType-V0oMfBY ()Lkotlin/reflect/KType; - public static fun getType-V0oMfBY ([I)Lkotlin/reflect/KType; public fun hashCode ()I public static fun hashCode-impl ([I)I public synthetic fun iterator ()Ljava/util/Iterator; @@ -2644,8 +2621,6 @@ public final class space/kscience/kmath/structures/Int32BufferKt { public final class space/kscience/kmath/structures/Int64Buffer : space/kscience/kmath/structures/PrimitiveBuffer { public static final synthetic fun box-impl ([J)Lspace/kscience/kmath/structures/Int64Buffer; public static fun constructor-impl ([J)[J - public fun copy ()Lspace/kscience/kmath/structures/MutableBuffer; - public static fun copy-impl ([J)Lspace/kscience/kmath/structures/MutableBuffer; public fun equals (Ljava/lang/Object;)Z public static fun equals-impl ([JLjava/lang/Object;)Z public static final fun equals-impl0 ([J[J)Z @@ -2655,8 +2630,6 @@ public final class space/kscience/kmath/structures/Int64Buffer : space/kscience/ public final fun getArray ()[J public fun getSize ()I public static fun getSize-impl ([J)I - public fun getType-V0oMfBY ()Lkotlin/reflect/KType; - public static fun getType-V0oMfBY ([J)Lkotlin/reflect/KType; public fun hashCode ()I public static fun hashCode-impl ([J)I public synthetic fun iterator ()Ljava/util/Iterator; @@ -2680,8 +2653,6 @@ public final class space/kscience/kmath/structures/Int64BufferKt { public final class space/kscience/kmath/structures/Int8Buffer : space/kscience/kmath/structures/MutableBuffer { public static final synthetic fun box-impl ([B)Lspace/kscience/kmath/structures/Int8Buffer; public static fun constructor-impl ([B)[B - public fun copy ()Lspace/kscience/kmath/structures/MutableBuffer; - public static fun copy-impl ([B)Lspace/kscience/kmath/structures/MutableBuffer; public fun equals (Ljava/lang/Object;)Z public static fun equals-impl ([BLjava/lang/Object;)Z public static final fun equals-impl0 ([B[B)Z @@ -2691,8 +2662,6 @@ public final class space/kscience/kmath/structures/Int8Buffer : space/kscience/k public final fun getArray ()[B public fun getSize ()I public static fun getSize-impl ([B)I - public fun getType-V0oMfBY ()Lkotlin/reflect/KType; - public static fun getType-V0oMfBY ([B)Lkotlin/reflect/KType; public fun hashCode ()I public static fun hashCode-impl ([B)I public synthetic fun iterator ()Ljava/util/Iterator; @@ -2714,23 +2683,21 @@ public final class space/kscience/kmath/structures/Int8BufferKt { } public final class space/kscience/kmath/structures/ListBuffer : space/kscience/kmath/structures/Buffer { - public synthetic fun (Lkotlin/reflect/KType;Ljava/util/List;Lkotlin/jvm/internal/DefaultConstructorMarker;)V + public fun (Ljava/util/List;)V public fun get (I)Ljava/lang/Object; public final fun getList ()Ljava/util/List; public fun getSize ()I - public fun getType-V0oMfBY ()Lkotlin/reflect/KType; public fun iterator ()Ljava/util/Iterator; public fun toString ()Ljava/lang/String; } public final class space/kscience/kmath/structures/ListBufferKt { - public static final fun asBuffer-Fnn_obI (Ljava/util/List;Lkotlin/reflect/KType;)Lspace/kscience/kmath/structures/ListBuffer; - public static final fun asMutableBuffer-Fnn_obI (Ljava/util/List;Lkotlin/reflect/KType;)Lspace/kscience/kmath/structures/MutableListBuffer; + public static final fun asBuffer (Ljava/util/List;)Lspace/kscience/kmath/structures/ListBuffer; + public static final fun asMutableBuffer (Ljava/util/List;)Lspace/kscience/kmath/structures/MutableListBuffer; } public abstract interface class space/kscience/kmath/structures/MutableBuffer : space/kscience/kmath/structures/Buffer { public static final field Companion Lspace/kscience/kmath/structures/MutableBuffer$Companion; - public abstract fun copy ()Lspace/kscience/kmath/structures/MutableBuffer; public abstract fun set (ILjava/lang/Object;)V } @@ -2752,15 +2719,15 @@ public final class space/kscience/kmath/structures/MutableBufferFactory$Companio public final class space/kscience/kmath/structures/MutableBufferKt { public static final fun MutableBuffer--rwW0uw (Lkotlin/reflect/KType;ILkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/structures/MutableBuffer; + public static final fun copy (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/BufferFactory;)Lspace/kscience/kmath/structures/Buffer; + public static final fun mutableCopy (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/MutableBufferFactory;)Lspace/kscience/kmath/structures/MutableBuffer; } public final class space/kscience/kmath/structures/MutableListBuffer : space/kscience/kmath/structures/MutableBuffer { - public synthetic fun (Lkotlin/reflect/KType;Ljava/util/List;Lkotlin/jvm/internal/DefaultConstructorMarker;)V - public fun copy ()Lspace/kscience/kmath/structures/MutableBuffer; + public fun (Ljava/util/List;)V public fun get (I)Ljava/lang/Object; public final fun getList ()Ljava/util/List; public fun getSize ()I - public fun getType-V0oMfBY ()Lkotlin/reflect/KType; public fun iterator ()Ljava/util/Iterator; public fun set (ILjava/lang/Object;)V public fun toString ()Ljava/lang/String; @@ -2789,7 +2756,6 @@ public final class space/kscience/kmath/structures/PermutedBuffer : space/kscien public final class space/kscience/kmath/structures/PermutedMutableBuffer : space/kscience/kmath/structures/BufferView, space/kscience/kmath/structures/MutableBuffer { public fun (Lspace/kscience/kmath/structures/MutableBuffer;[I)V - public fun copy ()Lspace/kscience/kmath/structures/MutableBuffer; public fun get (I)Ljava/lang/Object; public synthetic fun getOrigin ()Lspace/kscience/kmath/structures/Buffer; public fun getOrigin ()Lspace/kscience/kmath/structures/MutableBuffer; @@ -2814,10 +2780,9 @@ public final class space/kscience/kmath/structures/ValueFlag : java/lang/Enum { } public final class space/kscience/kmath/structures/VirtualBuffer : space/kscience/kmath/structures/Buffer { - public synthetic fun (Lkotlin/reflect/KType;ILkotlin/jvm/functions/Function1;Lkotlin/jvm/internal/DefaultConstructorMarker;)V + public fun (ILkotlin/jvm/functions/Function1;)V public fun get (I)Ljava/lang/Object; public fun getSize ()I - public fun getType-V0oMfBY ()Lkotlin/reflect/KType; public fun iterator ()Ljava/util/Iterator; public fun toString ()Ljava/lang/String; } diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/DSAlgebra.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/DSAlgebra.kt index 3d2683167..a6e721d13 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/DSAlgebra.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/DSAlgebra.kt @@ -189,7 +189,7 @@ public abstract class DSAlgebra>( vararg derivatives: T, ): DS { require(derivatives.size == compiler.size) { "dimension mismatch: ${derivatives.size} and ${compiler.size}" } - val data = derivatives.asList().asBuffer(algebra.type) + val data = derivatives.asList().asBuffer() return DS(data) } 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 1134fbb9b..1209372b4 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 @@ -53,7 +53,7 @@ public class DerivationResult( */ public fun DerivationResult.grad(vararg variables: Symbol): Point { check(variables.isNotEmpty()) { "Variable order is not provided for gradient construction" } - return variables.map(::derivative).asBuffer(type) + return variables.map(::derivative).asBuffer() } /** 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 4ed36fbbc..fb4661b96 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 @@ -227,4 +227,4 @@ public fun Matrix.asVector(): Point = * @receiver a buffer. * @return the new matrix. */ -public fun Point.asMatrix(): VirtualMatrix = VirtualMatrix(type, size, 1) { i, _ -> get(i) } \ No newline at end of file +public fun Point.asMatrix(): VirtualMatrix = VirtualMatrix(size, 1) { i, _ -> get(i) } \ No newline at end of file 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 cff72b2f5..58831f38d 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 @@ -27,7 +27,7 @@ public interface LupDecomposition { * Create a pivot matrix from pivot vector using provided [LinearSpace] */ public fun LupDecomposition.pivotMatrix(linearSpace: LinearSpace>): Matrix = - VirtualMatrix(linearSpace.type, l.rowNum, l.colNum) { row, column -> + VirtualMatrix(l.rowNum, l.colNum) { row, column -> if (column == pivot[row]) linearSpace.elementAlgebra.one else linearSpace.elementAlgebra.zero } @@ -47,7 +47,7 @@ public class GenericLupDecomposition( override val l: Matrix - get() = VirtualMatrix(lu.type, lu.rowNum, lu.colNum, attributes = Attributes(LowerTriangular)) { i, j -> + get() = VirtualMatrix(lu.rowNum, lu.colNum, attributes = Attributes(LowerTriangular)) { i, j -> when { j < i -> lu[i, j] j == i -> elementAlgebra.one @@ -56,7 +56,7 @@ public class GenericLupDecomposition( } override val u: Matrix - get() = VirtualMatrix(lu.type, lu.rowNum, lu.colNum, attributes = Attributes(UpperTriangular)) { i, j -> + get() = VirtualMatrix(lu.rowNum, lu.colNum, attributes = Attributes(UpperTriangular)) { i, j -> if (j >= i) lu[i, j] else elementAlgebra.zero } diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixWrapper.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixWrapper.kt index bea86d3ec..a5987bb18 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixWrapper.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixWrapper.kt @@ -68,7 +68,7 @@ public fun Matrix.modifyAttributes(modifier: (Attributes) -> Attributes): public fun LinearSpace>.one( rows: Int, columns: Int, -): MatrixWrapper = VirtualMatrix(type, rows, columns) { i, j -> +): MatrixWrapper = VirtualMatrix(rows, columns) { i, j -> if (i == j) elementAlgebra.one else elementAlgebra.zero }.withAttribute(IsUnit) @@ -79,6 +79,6 @@ public fun LinearSpace>.one( public fun LinearSpace>.zero( rows: Int, columns: Int, -): MatrixWrapper = VirtualMatrix(type, rows, columns) { _, _ -> +): MatrixWrapper = VirtualMatrix(rows, columns) { _, _ -> elementAlgebra.zero }.withAttribute(IsZero) diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/Transposed.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/Transposed.kt index 28821a52a..36be711e7 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/Transposed.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/Transposed.kt @@ -6,11 +6,9 @@ package space.kscience.kmath.linear import space.kscience.attributes.Attributes -import space.kscience.attributes.SafeType public class TransposedMatrix(public val origin: Matrix) : Matrix { - override val type: SafeType get() = origin.type override val rowNum: Int get() = origin.colNum diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/VirtualMatrix.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/VirtualMatrix.kt index ab6808891..2b031de06 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/VirtualMatrix.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/VirtualMatrix.kt @@ -6,7 +6,6 @@ package space.kscience.kmath.linear import space.kscience.attributes.Attributes -import space.kscience.attributes.SafeType import space.kscience.kmath.nd.ShapeND @@ -16,7 +15,6 @@ import space.kscience.kmath.nd.ShapeND * @property generator the function that provides elements. */ public class VirtualMatrix( - override val type: SafeType, override val rowNum: Int, override val colNum: Int, override val attributes: Attributes = Attributes.EMPTY, @@ -31,4 +29,4 @@ public class VirtualMatrix( public fun MatrixBuilder.virtual( attributes: Attributes = Attributes.EMPTY, generator: (i: Int, j: Int) -> T, -): VirtualMatrix = VirtualMatrix(type, rows, columns, attributes, generator) +): VirtualMatrix = VirtualMatrix(rows, columns, attributes, generator) diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/misc/sorting.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/misc/sorting.kt index 9ff306355..e1b24dd68 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/misc/sorting.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/misc/sorting.kt @@ -26,7 +26,7 @@ public fun > Buffer.indicesSorted(): IntArray = permSortInd */ public fun > Buffer.sorted(): Buffer { val permutations = indicesSorted() - return VirtualBuffer(type, size) { this[permutations[it]] } + return VirtualBuffer(size) { this[permutations[it]] } } @UnstableKMathAPI @@ -38,7 +38,7 @@ public fun > Buffer.indicesSortedDescending(): IntArray = */ public fun > Buffer.sortedDescending(): Buffer { val permutations = indicesSortedDescending() - return VirtualBuffer(type, size) { this[permutations[it]] } + return VirtualBuffer(size) { this[permutations[it]] } } @UnstableKMathAPI @@ -47,7 +47,7 @@ public fun > Buffer.indicesSortedBy(selector: (V) -> C): public fun > Buffer.sortedBy(selector: (V) -> C): Buffer { val permutations = indicesSortedBy(selector) - return VirtualBuffer(type, size) { this[permutations[it]] } + return VirtualBuffer(size) { this[permutations[it]] } } @UnstableKMathAPI @@ -56,7 +56,7 @@ public fun > Buffer.indicesSortedByDescending(selector: public fun > Buffer.sortedByDescending(selector: (V) -> C): Buffer { val permutations = indicesSortedByDescending(selector) - return VirtualBuffer(type, size) { this[permutations[it]] } + return VirtualBuffer(size) { this[permutations[it]] } } @UnstableKMathAPI @@ -68,7 +68,7 @@ public fun Buffer.indicesSortedWith(comparator: Comparator): IntArray */ public fun Buffer.sortedWith(comparator: Comparator): Buffer { val permutations = indicesSortedWith(comparator) - return VirtualBuffer(type,size) { this[permutations[it]] } + return VirtualBuffer(size) { this[permutations[it]] } } private fun Buffer.permSortIndicesWith(comparator: Comparator): IntArray { diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/BufferND.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/BufferND.kt index 24d69602f..5746ff881 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/BufferND.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/BufferND.kt @@ -5,7 +5,6 @@ package space.kscience.kmath.nd -import space.kscience.attributes.SafeType import space.kscience.kmath.PerformancePitfall import space.kscience.kmath.structures.Buffer import space.kscience.kmath.structures.BufferFactory @@ -24,8 +23,6 @@ public open class BufferND( public open val buffer: Buffer, ) : StructureND { - override val type: SafeType get() = buffer.type - @PerformancePitfall override operator fun get(index: IntArray): T = buffer[indices.offset(index)] diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Float64FieldND.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Float64FieldND.kt index ab9b25663..4bb853af8 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Float64FieldND.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Float64FieldND.kt @@ -5,11 +5,9 @@ package space.kscience.kmath.nd -import space.kscience.attributes.SafeType import space.kscience.kmath.PerformancePitfall import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.operations.* -import space.kscience.kmath.structures.Float64 import space.kscience.kmath.structures.Float64Buffer import kotlin.contracts.InvocationKind import kotlin.contracts.contract @@ -24,8 +22,6 @@ public class Float64BufferND( override val buffer: Float64Buffer, ) : MutableBufferND(indexes, buffer), MutableStructureNDOfDouble { - override val type: SafeType get() = Float64Field.type - override fun getDouble(index: IntArray): Double = buffer[indices.offset(index)] override fun setDouble(index: IntArray, value: Double) { diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/PermutedStructureND.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/PermutedStructureND.kt index 8c835afee..28130c037 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/PermutedStructureND.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/PermutedStructureND.kt @@ -5,7 +5,6 @@ package space.kscience.kmath.nd -import space.kscience.attributes.SafeType import space.kscience.kmath.PerformancePitfall @@ -14,8 +13,6 @@ public class PermutedStructureND( public val permutation: (IntArray) -> IntArray, ) : StructureND { - override val type: SafeType get() = origin.type - override val shape: ShapeND get() = origin.shape @@ -35,8 +32,6 @@ public class PermutedMutableStructureND( public val permutation: (IntArray) -> IntArray, ) : MutableStructureND { - override val type: SafeType get() = origin.type - @OptIn(PerformancePitfall::class) override fun set(index: IntArray, value: T) { origin[permutation(index)] = value diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Structure1D.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Structure1D.kt index 5bc5ba744..14f2aa7c2 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Structure1D.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Structure1D.kt @@ -5,12 +5,10 @@ package space.kscience.kmath.nd -import space.kscience.attributes.SafeType import space.kscience.kmath.PerformancePitfall import space.kscience.kmath.operations.asSequence import space.kscience.kmath.structures.Buffer import space.kscience.kmath.structures.MutableBuffer -import space.kscience.kmath.structures.asMutableBuffer import kotlin.jvm.JvmInline /** @@ -48,8 +46,6 @@ public interface MutableStructure1D : Structure1D, MutableStructureND, @JvmInline private value class Structure1DWrapper(val structure: StructureND) : Structure1D { - override val type: SafeType get() = structure.type - override val shape: ShapeND get() = structure.shape override val size: Int get() = structure.shape[0] @@ -65,8 +61,6 @@ private value class Structure1DWrapper(val structure: StructureND) : S */ private class MutableStructure1DWrapper(val structure: MutableStructureND) : MutableStructure1D { - override val type: SafeType get() = structure.type - override val shape: ShapeND get() = structure.shape override val size: Int get() = structure.shape[0] @@ -81,13 +75,6 @@ private class MutableStructure1DWrapper(val structure: MutableStructureND) structure[intArrayOf(index)] = value } - @OptIn(PerformancePitfall::class) - override fun copy(): MutableBuffer = structure - .elements() - .map(Pair::second) - .toMutableList() - .asMutableBuffer(type) - override fun toString(): String = Buffer.toString(this) } @@ -98,8 +85,6 @@ private class MutableStructure1DWrapper(val structure: MutableStructureND) @JvmInline private value class Buffer1DWrapper(val buffer: Buffer) : Structure1D { - override val type: SafeType get() = buffer.type - override val shape: ShapeND get() = ShapeND(buffer.size) override val size: Int get() = buffer.size @@ -113,8 +98,6 @@ private value class Buffer1DWrapper(val buffer: Buffer) : Structure1D< internal class MutableBuffer1DWrapper(val buffer: MutableBuffer) : MutableStructure1D { - override val type: SafeType get() = buffer.type - override val shape: ShapeND get() = ShapeND(buffer.size) override val size: Int get() = buffer.size @@ -128,8 +111,6 @@ internal class MutableBuffer1DWrapper(val buffer: MutableBuffer) : Mutable buffer[index] = value } - override fun copy(): MutableBuffer = buffer.copy() - override fun toString(): String = Buffer.toString(this) } diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Structure2D.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Structure2D.kt index a16f1082d..0a3209970 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Structure2D.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Structure2D.kt @@ -6,7 +6,6 @@ package space.kscience.kmath.nd import space.kscience.attributes.Attributes -import space.kscience.attributes.SafeType import space.kscience.kmath.PerformancePitfall import space.kscience.kmath.structures.Buffer import space.kscience.kmath.structures.MutableBuffer @@ -36,14 +35,14 @@ public interface Structure2D : StructureND { */ @PerformancePitfall public val rows: List> - get() = List(rowNum) { i -> VirtualBuffer(type, colNum) { j -> get(i, j) } } + get() = List(rowNum) { i -> VirtualBuffer(colNum) { j -> get(i, j) } } /** * The buffer of columns for this structure. It gets elements from the structure dynamically. */ @PerformancePitfall public val columns: List> - get() = List(colNum) { j -> VirtualBuffer(type, rowNum) { i -> get(i, j) } } + get() = List(colNum) { j -> VirtualBuffer(rowNum) { i -> get(i, j) } } /** * Retrieves an element from the structure by two indices. @@ -79,8 +78,6 @@ public class MutableStructureNDAccessorBuffer( private val indexer: (Int) -> IntArray, ) : MutableBuffer { - override val type: SafeType get() = structure.type - override fun set(index: Int, value: T) { structure[indexer(index)] = value } @@ -88,8 +85,6 @@ public class MutableStructureNDAccessorBuffer( override fun get(index: Int): T = structure[indexer(index)] override fun toString(): String = "AccessorBuffer(structure=$structure, size=$size)" - - override fun copy(): MutableBuffer = MutableBuffer(type, size, ::get) } /** @@ -130,8 +125,6 @@ public interface MutableStructure2D : Structure2D, MutableStructureND { @JvmInline private value class Structure2DWrapper(val structure: StructureND) : Structure2D { - override val type: SafeType get() = structure.type - override val shape: ShapeND get() = structure.shape override val rowNum: Int get() = shape[0] @@ -152,8 +145,6 @@ private value class Structure2DWrapper(val structure: StructureND) : S */ private class MutableStructure2DWrapper(val structure: MutableStructureND) : MutableStructure2D { - override val type: SafeType get() = structure.type - override val shape: ShapeND get() = structure.shape override val rowNum: Int get() = shape[0] diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/StructureND.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/StructureND.kt index 12034df64..5c1021147 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/StructureND.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/StructureND.kt @@ -5,7 +5,10 @@ package space.kscience.kmath.nd -import space.kscience.attributes.* +import space.kscience.attributes.Attribute +import space.kscience.attributes.AttributeContainer +import space.kscience.attributes.Attributes +import space.kscience.attributes.SafeType import space.kscience.kmath.PerformancePitfall import space.kscience.kmath.linear.LinearSpace import space.kscience.kmath.operations.Ring @@ -24,7 +27,7 @@ public interface StructureAttribute : Attribute * * @param T the type of items. */ -public interface StructureND : AttributeContainer, WithShape, WithType { +public interface StructureND : AttributeContainer, WithShape { /** * The shape of structure i.e., non-empty sequence of non-negative integers that specify sizes of dimensions for * this structure. diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/VirtualStructureND.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/VirtualStructureND.kt index 82c04e640..a7e0b0053 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/VirtualStructureND.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/VirtualStructureND.kt @@ -5,13 +5,10 @@ package space.kscience.kmath.nd -import space.kscience.attributes.SafeType -import space.kscience.attributes.safeTypeOf import space.kscience.kmath.PerformancePitfall import space.kscience.kmath.UnstableKMathAPI public open class VirtualStructureND( - override val type: SafeType, override val shape: ShapeND, public val producer: (IntArray) -> T, ) : StructureND { @@ -27,10 +24,10 @@ public open class VirtualStructureND( public class VirtualDoubleStructureND( shape: ShapeND, producer: (IntArray) -> Double, -) : VirtualStructureND(safeTypeOf(), shape, producer) +) : VirtualStructureND(shape, producer) @UnstableKMathAPI public class VirtualIntStructureND( shape: ShapeND, producer: (IntArray) -> Int, -) : VirtualStructureND(safeTypeOf(), shape, producer) \ No newline at end of file +) : VirtualStructureND(shape, producer) \ No newline at end of file diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/operationsND.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/operationsND.kt index 9e9361bca..b91f2bde5 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/operationsND.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/operationsND.kt @@ -10,7 +10,7 @@ import space.kscience.kmath.PerformancePitfall @OptIn(PerformancePitfall::class) public fun StructureND.roll(axis: Int, step: Int = 1): StructureND { require(axis in shape.indices) { "Axis $axis is outside of shape dimensions: [0, ${shape.size})" } - return VirtualStructureND(type, shape) { index -> + return VirtualStructureND(shape) { index -> val newIndex: IntArray = IntArray(index.size) { indexAxis -> if (indexAxis == axis) { (index[indexAxis] + step).mod(shape[indexAxis]) @@ -26,7 +26,7 @@ public fun StructureND.roll(axis: Int, step: Int = 1): StructureND { public fun StructureND.roll(pair: Pair, vararg others: Pair): StructureND { val axisMap: Map = mapOf(pair, *others) require(axisMap.keys.all { it in shape.indices }) { "Some of axes ${axisMap.keys} is outside of shape dimensions: [0, ${shape.size})" } - return VirtualStructureND(type, shape) { index -> + return VirtualStructureND(shape) { index -> val newIndex: IntArray = IntArray(index.size) { indexAxis -> val offset = axisMap[indexAxis] ?: 0 (index[indexAxis] + offset).mod(shape[indexAxis]) diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/primitiveStructureND.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/primitiveStructureND.kt index ca299f12f..4831b4138 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/primitiveStructureND.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/primitiveStructureND.kt @@ -5,14 +5,9 @@ package space.kscience.kmath.nd -import space.kscience.attributes.SafeType import space.kscience.kmath.PerformancePitfall -import space.kscience.kmath.operations.Float64Field -import space.kscience.kmath.operations.Int32Field -import space.kscience.kmath.structures.Float64 public interface StructureNDOfDouble : StructureND { - override val type: SafeType get() = Float64Field.type /** * Guaranteed non-blocking access to content @@ -42,8 +37,6 @@ public fun MutableStructureND.getDouble(index: IntArray): Double = public interface StructureNDOfInt : StructureND { - override val type: SafeType get() = Int32Field.type - /** * Guaranteed non-blocking access to content */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/ArrayBuffer.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/ArrayBuffer.kt index 54d0b40b9..892f6a7c5 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/ArrayBuffer.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/ArrayBuffer.kt @@ -5,8 +5,7 @@ package space.kscience.kmath.structures -import space.kscience.attributes.SafeType -import space.kscience.attributes.safeTypeOf +import kotlin.jvm.JvmInline /** * [MutableBuffer] implementation over [Array]. @@ -14,7 +13,8 @@ import space.kscience.attributes.safeTypeOf * @param T the type of elements contained in the buffer. * @property array The underlying array. */ -public class ArrayBuffer(override val type: SafeType, internal val array: Array) : MutableBuffer { +@JvmInline +public value class ArrayBuffer(internal val array: Array) : MutableBuffer { // Can't inline because array is invariant override val size: Int get() = array.size @@ -25,7 +25,6 @@ public class ArrayBuffer(override val type: SafeType, internal val array: } override operator fun iterator(): Iterator = array.iterator() - override fun copy(): MutableBuffer = ArrayBuffer(type, array.copyOf()) override fun toString(): String = Buffer.toString(this) } @@ -33,9 +32,4 @@ public class ArrayBuffer(override val type: SafeType, internal val array: /** * Returns an [ArrayBuffer] that wraps the original array. */ -public fun Array.asBuffer(type: SafeType): ArrayBuffer = ArrayBuffer(type, this) - -/** - * Returns an [ArrayBuffer] that wraps the original array. - */ -public inline fun Array.asBuffer(): ArrayBuffer = ArrayBuffer(safeTypeOf(), this) \ No newline at end of file +public fun Array.asBuffer(): ArrayBuffer = ArrayBuffer( this) 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 4a0ac9416..7fc06c43e 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 @@ -66,7 +66,7 @@ public inline fun MutableBufferFactory(): MutableBufferFactory = * * @param T the type of elements contained in the buffer. */ -public interface Buffer : WithSize, WithType { +public interface Buffer : WithSize { /** * The size of this buffer. */ @@ -120,7 +120,7 @@ public fun Buffer( typeOf() -> MutableBuffer.int(size) { initializer(it) as Int } as Buffer typeOf() -> MutableBuffer.long(size) { initializer(it) as Long } as Buffer typeOf() -> MutableBuffer.float(size) { initializer(it) as Float } as Buffer - else -> List(size, initializer).asBuffer(type) + else -> List(size, initializer).asBuffer() } /** @@ -139,7 +139,7 @@ public inline fun Buffer(size: Int, initializer: (Int) -> T): Buffer typeOf() -> MutableBuffer.int(size) { initializer(it) as Int } as Buffer typeOf() -> MutableBuffer.long(size) { initializer(it) as Long } as Buffer typeOf() -> MutableBuffer.float(size) { initializer(it) as Float } as Buffer - else -> List(size, initializer).asBuffer(type) + else -> List(size, initializer).asBuffer() } } @@ -172,7 +172,6 @@ public fun Buffer.last(): T { * @param T the type of elements provided by the buffer. */ public class VirtualBuffer( - override val type: SafeType, override val size: Int, private val generator: (Int) -> T, ) : Buffer { @@ -185,11 +184,3 @@ public class VirtualBuffer( override fun toString(): String = Buffer.toString(this) } - -/** - * Inline builder for [VirtualBuffer] - */ -public inline fun VirtualBuffer( - size: Int, - noinline generator: (Int) -> T, -): VirtualBuffer = VirtualBuffer(safeTypeOf(), size, generator) diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/BufferAccessor2D.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/BufferAccessor2D.kt index 5c8541f22..32990c707 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/BufferAccessor2D.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/BufferAccessor2D.kt @@ -5,7 +5,6 @@ package space.kscience.kmath.structures -import space.kscience.attributes.SafeType import space.kscience.kmath.nd.Structure2D /** @@ -33,7 +32,6 @@ internal class BufferAccessor2D( // ) { (i, j) -> get(i, j) }.as2D() inner class Row(val buffer: MutableBuffer, val rowIndex: Int) : MutableBuffer { - override val type: SafeType get() = buffer.type override val size: Int get() = colNum @@ -43,7 +41,6 @@ internal class BufferAccessor2D( buffer[rowIndex, index] = value } - override fun copy(): MutableBuffer = factory(colNum) { get(it) } override operator fun iterator(): Iterator = (0 until colNum).map(::get).iterator() override fun toString(): String = Buffer.toString(this) diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/BufferView.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/BufferView.kt index ac8a9af14..180098f51 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/BufferView.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/BufferView.kt @@ -5,7 +5,6 @@ package space.kscience.kmath.structures -import space.kscience.attributes.SafeType import space.kscience.kmath.UnstableKMathAPI /** @@ -14,8 +13,6 @@ import space.kscience.kmath.UnstableKMathAPI public interface BufferView : Buffer { public val origin: Buffer - override val type: SafeType get() = origin.type - /** * Get the index in [origin] buffer from index in this buffer. * Return -1 if element not present in the original buffer @@ -190,9 +187,7 @@ public class PermutedMutableBuffer( origin[permutations[index]] = value } - override fun copy(): MutableBuffer = PermutedMutableBuffer(origin.copy(), permutations) //TODO Probably could be optimized - override fun iterator(): Iterator = permutations.asSequence().map { origin[it] }.iterator() @UnstableKMathAPI 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 55729a9c2..ce31163a9 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 @@ -5,8 +5,6 @@ package space.kscience.kmath.structures -import space.kscience.attributes.SafeType -import space.kscience.attributes.safeTypeOf import kotlin.experimental.and /** @@ -60,8 +58,6 @@ public class FlaggedDoubleBuffer( public val flags: ByteArray ) : FlaggedBuffer, Buffer { - override val type: SafeType = safeTypeOf() - init { require(values.size == flags.size) { "Values and flags must have the same dimensions" } } diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Float32Buffer.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Float32Buffer.kt index 9f564f450..7ad6c2a0d 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Float32Buffer.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Float32Buffer.kt @@ -5,8 +5,6 @@ package space.kscience.kmath.structures -import space.kscience.attributes.SafeType -import space.kscience.attributes.safeTypeOf import kotlin.jvm.JvmInline /** @@ -18,8 +16,6 @@ import kotlin.jvm.JvmInline @JvmInline public value class Float32Buffer(public val array: FloatArray) : PrimitiveBuffer { - override val type: SafeType get() = safeTypeOf() - override val size: Int get() = array.size override operator fun get(index: Int): Float = array[index] @@ -30,8 +26,6 @@ public value class Float32Buffer(public val array: FloatArray) : PrimitiveBuffer override operator fun iterator(): FloatIterator = array.iterator() - override fun copy(): MutableBuffer = - Float32Buffer(array.copyOf()) } public typealias FloatBuffer = Float32Buffer diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Float64Buffer.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Float64Buffer.kt index ca9e8ef9f..38b737fd5 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Float64Buffer.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Float64Buffer.kt @@ -5,8 +5,6 @@ package space.kscience.kmath.structures -import space.kscience.attributes.SafeType -import space.kscience.attributes.safeTypeOf import space.kscience.kmath.operations.BufferTransform import kotlin.jvm.JvmInline @@ -18,8 +16,6 @@ import kotlin.jvm.JvmInline @JvmInline public value class Float64Buffer(public val array: DoubleArray) : PrimitiveBuffer { - override val type: SafeType get() = safeTypeOf() - override val size: Int get() = array.size override operator fun get(index: Int): Double = array[index] @@ -30,8 +26,6 @@ public value class Float64Buffer(public val array: DoubleArray) : PrimitiveBuffe override operator fun iterator(): DoubleIterator = array.iterator() - override fun copy(): Float64Buffer = Float64Buffer(array.copyOf()) - override fun toString(): String = Buffer.toString(this) public companion object { diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Int16Buffer.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Int16Buffer.kt index 17d4cd36b..9ceeeec05 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Int16Buffer.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Int16Buffer.kt @@ -5,8 +5,6 @@ package space.kscience.kmath.structures -import space.kscience.attributes.SafeType -import space.kscience.attributes.safeTypeOf import kotlin.jvm.JvmInline /** @@ -17,7 +15,7 @@ import kotlin.jvm.JvmInline @JvmInline public value class Int16Buffer(public val array: ShortArray) : MutableBuffer { - override val type: SafeType get() = safeTypeOf() + override val size: Int get() = array.size override operator fun get(index: Int): Short = array[index] @@ -27,7 +25,6 @@ public value class Int16Buffer(public val array: ShortArray) : MutableBuffer = Int16Buffer(array.copyOf()) } public typealias ShortBuffer = Int16Buffer diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Int32Buffer.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Int32Buffer.kt index 5cdebb7d7..bb41c2b9b 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Int32Buffer.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Int32Buffer.kt @@ -5,8 +5,6 @@ package space.kscience.kmath.structures -import space.kscience.attributes.SafeType -import space.kscience.attributes.safeTypeOf import kotlin.jvm.JvmInline /** @@ -17,7 +15,6 @@ import kotlin.jvm.JvmInline @JvmInline public value class Int32Buffer(public val array: IntArray) : PrimitiveBuffer { - override val type: SafeType get() = safeTypeOf() override val size: Int get() = array.size @@ -29,7 +26,6 @@ public value class Int32Buffer(public val array: IntArray) : PrimitiveBuffer { - override val type: SafeType get() = safeTypeOf() - override val size: Int get() = array.size override operator fun get(index: Int): Long = array[index] @@ -29,8 +25,6 @@ public value class Int64Buffer(public val array: LongArray) : PrimitiveBuffer = - Int64Buffer(array.copyOf()) } public typealias LongBuffer = Int64Buffer diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Int8Buffer.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Int8Buffer.kt index 1a7ca98b0..c7b1d43c5 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Int8Buffer.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Int8Buffer.kt @@ -5,8 +5,6 @@ package space.kscience.kmath.structures -import space.kscience.attributes.SafeType -import space.kscience.attributes.safeTypeOf import kotlin.jvm.JvmInline /** @@ -17,8 +15,6 @@ import kotlin.jvm.JvmInline @JvmInline public value class Int8Buffer(public val array: ByteArray) : MutableBuffer { - override val type: SafeType get() = safeTypeOf() - override val size: Int get() = array.size override operator fun get(index: Int): Byte = array[index] @@ -28,7 +24,6 @@ public value class Int8Buffer(public val array: ByteArray) : MutableBuffer } override operator fun iterator(): ByteIterator = array.iterator() - override fun copy(): MutableBuffer = Int8Buffer(array.copyOf()) } /** diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/ListBuffer.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/ListBuffer.kt index fc9ba4933..501bd1c64 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/ListBuffer.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/ListBuffer.kt @@ -5,16 +5,13 @@ package space.kscience.kmath.structures -import space.kscience.attributes.SafeType -import space.kscience.attributes.safeTypeOf - /** * [Buffer] implementation over [List]. * * @param T the type of elements contained in the buffer. * @property list The underlying list. */ -public class ListBuffer(override val type: SafeType, public val list: List) : Buffer { +public class ListBuffer(public val list: List) : Buffer { override val size: Int get() = list.size @@ -28,12 +25,7 @@ public class ListBuffer(override val type: SafeType, public val list: List /** * Returns an [ListBuffer] that wraps the original list. */ -public fun List.asBuffer(type: SafeType): ListBuffer = ListBuffer(type, this) - -/** - * Returns an [ListBuffer] that wraps the original list. - */ -public inline fun List.asBuffer(): ListBuffer = asBuffer(safeTypeOf()) +public fun List.asBuffer(): ListBuffer = ListBuffer(this) /** * [MutableBuffer] implementation over [MutableList]. @@ -41,7 +33,7 @@ public inline fun List.asBuffer(): ListBuffer = asBuffer(safeT * @param T the type of elements contained in the buffer. * @property list The underlying list. */ -public class MutableListBuffer(override val type: SafeType, public val list: MutableList) : MutableBuffer { +public class MutableListBuffer(public val list: MutableList) : MutableBuffer { override val size: Int get() = list.size @@ -52,7 +44,6 @@ public class MutableListBuffer(override val type: SafeType, public val lis } override operator fun iterator(): Iterator = list.iterator() - override fun copy(): MutableBuffer = MutableListBuffer(type, ArrayList(list)) override fun toString(): String = Buffer.toString(this) } @@ -61,15 +52,4 @@ public class MutableListBuffer(override val type: SafeType, public val lis /** * Returns an [MutableListBuffer] that wraps the original list. */ -public fun MutableList.asMutableBuffer(type: SafeType): MutableListBuffer = MutableListBuffer( - type, - this -) - -/** - * Returns an [MutableListBuffer] that wraps the original list. - */ -public inline fun MutableList.asMutableBuffer(): MutableListBuffer = MutableListBuffer( - safeTypeOf(), - this -) +public fun MutableList.asMutableBuffer(): MutableListBuffer = MutableListBuffer(this) \ No newline at end of file diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/MutableBuffer.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/MutableBuffer.kt index 0acfd13a1..be0c76618 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/MutableBuffer.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/MutableBuffer.kt @@ -14,16 +14,13 @@ import kotlin.reflect.typeOf * * @param T the type of elements contained in the buffer. */ -public interface MutableBuffer : Buffer { +public interface MutableBuffer : Buffer{ + /** * Sets the array element at the specified [index] to the specified [value]. */ public operator fun set(index: Int, value: T) - /** - * Returns a shallow copy of the buffer. - */ - public fun copy(): MutableBuffer public companion object { /** @@ -65,6 +62,25 @@ public interface MutableBuffer : Buffer { } +/** + * Returns a shallow copy of the buffer. + */ +public fun Buffer.copy(bufferFactory: BufferFactory): Buffer =if(this is ArrayBuffer){ + ArrayBuffer(array.copyOf()) +}else{ + bufferFactory(size,::get) +} + +/** + * Returns a mutable shallow copy of the buffer. + */ +public fun Buffer.mutableCopy(bufferFactory: MutableBufferFactory): MutableBuffer =if(this is ArrayBuffer){ + ArrayBuffer(array.copyOf()) +}else{ + bufferFactory(size,::get) +} + + /** * Creates a [MutableBuffer] of given [type]. If the type is primitive, specialized buffers are used * ([Int32Buffer], [Float64Buffer], etc.), [ListBuffer] is returned otherwise. @@ -84,7 +100,7 @@ public inline fun MutableBuffer( typeOf() -> MutableBuffer.float(size) { initializer(it) as Float } as MutableBuffer typeOf() -> MutableBuffer.double(size) { initializer(it) as Double } as MutableBuffer //TODO add unsigned types - else -> MutableListBuffer(type, MutableList(size, initializer)) + else -> MutableListBuffer(MutableList(size, initializer)) } /** diff --git a/kmath-core/src/commonTest/kotlin/space/kscience/kmath/linear/MatrixTest.kt b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/linear/MatrixTest.kt index f7863a68c..eb76d59dc 100644 --- a/kmath-core/src/commonTest/kotlin/space/kscience/kmath/linear/MatrixTest.kt +++ b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/linear/MatrixTest.kt @@ -38,7 +38,7 @@ class MatrixTest { @Test fun testMatrixExtension() = Double.algebra.linearSpace.run { - val transitionMatrix: Matrix = VirtualMatrix(type,6, 6) { row, col -> + val transitionMatrix: Matrix = VirtualMatrix(6, 6) { row, col -> when { col == 0 -> .50 row + 1 == col -> .50 diff --git a/kmath-core/src/jvmMain/kotlin/space/kscience/kmath/structures/parallelMutableBuffer.kt b/kmath-core/src/jvmMain/kotlin/space/kscience/kmath/structures/parallelMutableBuffer.kt index c57dba41e..7eeb0dbbd 100644 --- a/kmath-core/src/jvmMain/kotlin/space/kscience/kmath/structures/parallelMutableBuffer.kt +++ b/kmath-core/src/jvmMain/kotlin/space/kscience/kmath/structures/parallelMutableBuffer.kt @@ -33,7 +33,7 @@ public fun MutableBuffer.Companion.parallel( typeOf() -> IntStream.range(0, size).parallel().mapToDouble { initializer(it) as Float64 }.toArray() .asBuffer() as MutableBuffer //TODO add unsigned types - else -> IntStream.range(0, size).parallel().mapToObj { initializer(it) }.collect(Collectors.toList()).asMutableBuffer(type) + else -> IntStream.range(0, size).parallel().mapToObj { initializer(it) }.collect(Collectors.toList()).asMutableBuffer() } public class ParallelBufferFactory(override val type: SafeType) : MutableBufferFactory { diff --git a/kmath-core/src/jvmTest/kotlin/space/kscience/kmath/linear/ParallelMatrixTest.kt b/kmath-core/src/jvmTest/kotlin/space/kscience/kmath/linear/ParallelMatrixTest.kt index 493948361..915ec3c5e 100644 --- a/kmath-core/src/jvmTest/kotlin/space/kscience/kmath/linear/ParallelMatrixTest.kt +++ b/kmath-core/src/jvmTest/kotlin/space/kscience/kmath/linear/ParallelMatrixTest.kt @@ -37,7 +37,7 @@ class ParallelMatrixTest { @Test fun testMatrixExtension() = Float64Field.linearSpace.parallel{ - val transitionMatrix: Matrix = VirtualMatrix(type,6, 6) { row, col -> + val transitionMatrix: Matrix = VirtualMatrix(6, 6) { row, col -> when { col == 0 -> .50 row + 1 == col -> .50 diff --git a/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/streaming/RingBuffer.kt b/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/streaming/RingBuffer.kt index d40f145f6..3ee6b203a 100644 --- a/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/streaming/RingBuffer.kt +++ b/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/streaming/RingBuffer.kt @@ -7,22 +7,19 @@ package space.kscience.kmath.streaming import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock -import space.kscience.attributes.SafeType import space.kscience.kmath.operations.Group -import space.kscience.kmath.structures.Buffer -import space.kscience.kmath.structures.MutableBuffer -import space.kscience.kmath.structures.VirtualBuffer +import space.kscience.kmath.structures.* /** * Thread-safe ring buffer */ public class RingBuffer( private val buffer: MutableBuffer, + private val bufferFactory: BufferFactory, private var startIndex: Int = 0, size: Int = 0, ) : Buffer { - override val type: SafeType get() = buffer.type private val mutex: Mutex = Mutex() @@ -43,7 +40,7 @@ public class RingBuffer( override operator fun iterator(): Iterator = object : AbstractIterator() { private var count = size private var index = startIndex - val copy = buffer.copy() + val copy = buffer.copy(bufferFactory) override fun computeNext() { if (count == 0) done() else { @@ -58,8 +55,8 @@ public class RingBuffer( * A safe snapshot operation */ public suspend fun snapshot(): Buffer = mutex.withLock { - val copy = buffer.copy() - VirtualBuffer(type, size) { i -> copy[startIndex.forward(i)] } + val copy = buffer.copy(bufferFactory) + VirtualBuffer(size) { i -> copy[startIndex.forward(i)] } } public suspend fun push(element: T) { @@ -76,7 +73,7 @@ public class RingBuffer( public inline fun RingBuffer(size: Int, empty: T): RingBuffer { val buffer = MutableBuffer(size) { empty } - return RingBuffer(buffer) + return RingBuffer(buffer, BufferFactory()) } /** @@ -84,5 +81,5 @@ public inline fun RingBuffer(size: Int, empty: T): RingBuffer< */ public fun RingBuffer(size: Int, algebra: Group): RingBuffer { val buffer: MutableBuffer = MutableBuffer(algebra.type, size) { algebra.zero } - return RingBuffer(buffer) + return RingBuffer(buffer, algebra.bufferFactory) } 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 cb90c9b02..1d23162f5 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 @@ -6,8 +6,6 @@ package space.kscience.kmath.structures import kotlinx.coroutines.* -import space.kscience.attributes.SafeType -import space.kscience.attributes.safeTypeOf import space.kscience.kmath.PerformancePitfall import space.kscience.kmath.coroutines.Math import space.kscience.kmath.nd.ColumnStrides @@ -16,7 +14,6 @@ import space.kscience.kmath.nd.StructureND public class LazyStructureND( public val scope: CoroutineScope, - override val type: SafeType, override val shape: ShapeND, public val function: suspend (IntArray) -> T, ) : StructureND { @@ -54,10 +51,10 @@ public suspend fun StructureND.await(index: IntArray): T = public inline fun StructureND.mapAsyncIndexed( scope: CoroutineScope, crossinline function: suspend (T, index: IntArray) -> R, -): LazyStructureND = LazyStructureND(scope, safeTypeOf(), shape) { index -> function(get(index), index) } +): LazyStructureND = LazyStructureND(scope, shape) { index -> function(get(index), index) } @OptIn(PerformancePitfall::class) public inline fun StructureND.mapAsync( scope: CoroutineScope, crossinline function: suspend (T) -> R, -): LazyStructureND = LazyStructureND(scope, safeTypeOf(), shape) { index -> function(get(index)) } +): LazyStructureND = LazyStructureND(scope, shape) { index -> function(get(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 d1de77d54..7ddc143ad 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,6 @@ package space.kscience.kmath.dimensions -import space.kscience.attributes.SafeType import space.kscience.kmath.linear.* import space.kscience.kmath.nd.ShapeND import space.kscience.kmath.nd.Structure2D @@ -50,8 +49,6 @@ public value class DMatrixWrapper( private val structure: Structure2D, ) : DMatrix { - override val type: SafeType get() = structure.type - override val shape: ShapeND get() = structure.shape override val rowNum: Int get() = shape[0] override val colNum: Int get() = shape[1] @@ -81,8 +78,6 @@ public interface DPoint : Point { @JvmInline public value class DPointWrapper(public val point: Point) : DPoint { - override val type: SafeType get() = point.type - override val size: Int get() = point.size override operator fun get(index: Int): T = point[index] diff --git a/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/implementations.kt b/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/implementations.kt index d33a74199..d196f5f1a 100644 --- a/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/implementations.kt +++ b/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/implementations.kt @@ -38,7 +38,6 @@ public class EjmlDoubleVector(override val origin: M) : EjmlVec require(origin.numRows == 1) { "The origin matrix must have only one row to form a vector" } } - override val type: SafeType get() = safeTypeOf() override operator fun get(index: Int): Double = origin[0, index] } @@ -51,8 +50,6 @@ public class EjmlFloatVector(override val origin: M) : EjmlVect require(origin.numRows == 1) { "The origin matrix must have only one row to form a vector" } } - override val type: SafeType get() = safeTypeOf() - override operator fun get(index: Int): Float = origin[0, index] } @@ -60,8 +57,6 @@ public class EjmlFloatVector(override val origin: M) : EjmlVect * [EjmlMatrix] specialization for [Double]. */ public class EjmlDoubleMatrix(override val origin: M) : EjmlMatrix(origin) { - override val type: SafeType get() = safeTypeOf() - override operator fun get(i: Int, j: Int): Double = origin[i, j] } @@ -69,7 +64,6 @@ public class EjmlDoubleMatrix(override val origin: M) : EjmlMat * [EjmlMatrix] specialization for [Float]. */ public class EjmlFloatMatrix(override val origin: M) : EjmlMatrix(origin) { - override val type: SafeType get() = safeTypeOf() override operator fun get(i: Int, j: Int): Float = origin[i, j] } 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 cafae06d7..d36537d71 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 @@ -48,7 +48,7 @@ public fun Sequence.toMatrix(): RealMatrix = toList().let { } public fun RealMatrix.repeatStackVertical(n: Int): RealMatrix = - VirtualMatrix(type, rowNum * n, colNum) { row, col -> + VirtualMatrix( rowNum * n, colNum) { row, col -> get(if (row == 0) 0 else row % rowNum, col) } diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/interpolation/Interpolator.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/interpolation/Interpolator.kt index 11131515a..3b9808028 100644 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/interpolation/Interpolator.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/interpolation/Interpolator.kt @@ -54,14 +54,14 @@ public fun > PolynomialInterpolator.interpolatePolynomials( public fun > PolynomialInterpolator.interpolatePolynomials( data: Map, ): PiecewisePolynomial { - val pointSet = XYColumnarData.of(data.keys.toList().asBuffer(type), data.values.toList().asBuffer(type)) + val pointSet = XYColumnarData.of(data.keys.toList().asBuffer(), data.values.toList().asBuffer()) return interpolatePolynomials(pointSet) } public fun > PolynomialInterpolator.interpolatePolynomials( data: List>, ): PiecewisePolynomial { - val pointSet = XYColumnarData.of(data.map { it.first }.asBuffer(type), data.map { it.second }.asBuffer(type)) + val pointSet = XYColumnarData.of(data.map { it.first }.asBuffer(), data.map { it.second }.asBuffer()) return interpolatePolynomials(pointSet) } diff --git a/kmath-geometry/build.gradle.kts b/kmath-geometry/build.gradle.kts index 32926db7e..4bf768f4b 100644 --- a/kmath-geometry/build.gradle.kts +++ b/kmath-geometry/build.gradle.kts @@ -6,6 +6,7 @@ kscience{ jvm() js() native() + wasm() useContextReceivers() useSerialization() diff --git a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Vector3D.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Vector3D.kt index 64396baff..71442cf63 100644 --- a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Vector3D.kt +++ b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Vector3D.kt @@ -5,7 +5,6 @@ package space.kscience.kmath.geometry -import space.kscience.attributes.SafeType import space.kscience.kmath.linear.Point import space.kscience.kmath.structures.Buffer @@ -34,9 +33,6 @@ public fun Buffer.asVector3D(): Vector3D = object : Vector3D { require(this@asVector3D.size == 3) { "Buffer of size 3 is required for Vector3D" } } - override val type: SafeType = this@asVector3D.type - - override val x: T get() = this@asVector3D[0] override val y: T get() = this@asVector3D[1] override val z: T get() = this@asVector3D[2] diff --git a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean2d/Float32Space2D.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean2d/Float32Space2D.kt index ed3caede8..ae140ff06 100644 --- a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean2d/Float32Space2D.kt +++ b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean2d/Float32Space2D.kt @@ -11,7 +11,6 @@ import kotlinx.serialization.Serializable import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder -import space.kscience.attributes.SafeType import space.kscience.kmath.geometry.GeometrySpace import space.kscience.kmath.geometry.Vector2D import space.kscience.kmath.operations.Float32Field @@ -20,10 +19,8 @@ import space.kscience.kmath.structures.MutableBufferFactory import kotlin.math.pow import kotlin.math.sqrt -@Serializable(Float32Space2D.VectorSerializer::class) -public interface Float32Vector2D : Vector2D{ - override val type: SafeType get() = Float32Field.type -} + +public typealias Float32Vector2D = Vector2D public object Float32Space2D : GeometrySpace, Float32> { diff --git a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean2d/Float64Space2D.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean2d/Float64Space2D.kt index 6a4f5ef34..37e11ba87 100644 --- a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean2d/Float64Space2D.kt +++ b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean2d/Float64Space2D.kt @@ -11,7 +11,6 @@ import kotlinx.serialization.Serializable import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder -import space.kscience.attributes.SafeType import space.kscience.kmath.geometry.GeometrySpace import space.kscience.kmath.geometry.Vector2D import space.kscience.kmath.operations.Float64Field @@ -22,10 +21,7 @@ import kotlin.math.pow import kotlin.math.sqrt -@Serializable(Float64Space2D.VectorSerializer::class) -public interface Float64Vector2D : Vector2D { - override val type: SafeType get() = Float64Field.type -} +public typealias Float64Vector2D = Vector2D @Deprecated("Use Float64Vector2D", ReplaceWith("Float64Vector2D")) public typealias DoubleVector2D = Float64Vector2D diff --git a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean3d/Float32Space3D.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean3d/Float32Space3D.kt index 56ff49533..ad61a7b77 100644 --- a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean3d/Float32Space3D.kt +++ b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean3d/Float32Space3D.kt @@ -11,7 +11,6 @@ import kotlinx.serialization.Serializable import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder -import space.kscience.attributes.SafeType import space.kscience.kmath.geometry.GeometrySpace import space.kscience.kmath.geometry.Vector3D import space.kscience.kmath.operations.Float32Field @@ -20,10 +19,8 @@ import space.kscience.kmath.structures.MutableBufferFactory import kotlin.math.pow import kotlin.math.sqrt -@Serializable(Float32Space3D.VectorSerializer::class) -public interface Float32Vector3D : Vector3D{ - override val type: SafeType get() = Float32Field.type -} + +public typealias Float32Vector3D = Vector3D public object Float32Space3D : GeometrySpace, Float32> { diff --git a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean3d/Float64Space3D.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean3d/Float64Space3D.kt index 86ddf554b..fa07190bb 100644 --- a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean3d/Float64Space3D.kt +++ b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean3d/Float64Space3D.kt @@ -11,7 +11,6 @@ import kotlinx.serialization.Serializable import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder -import space.kscience.attributes.SafeType import space.kscience.kmath.geometry.GeometrySpace import space.kscience.kmath.geometry.Vector3D import space.kscience.kmath.linear.Float64LinearSpace @@ -34,10 +33,7 @@ internal fun leviCivita(i: Int, j: Int, k: Int): Int = when { else -> 0 } -@Serializable(Float64Space3D.VectorSerializer::class) -public interface Float64Vector3D : Vector3D { - override val type: SafeType get() = Float64Field.type -} +public typealias Float64Vector3D = Vector3D @Deprecated("Use Float64Vector3D", ReplaceWith("Float64Vector3D")) public typealias DoubleVector3D = Float64Vector3D diff --git a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean3d/rotations3D.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean3d/rotations3D.kt index e65bd8e22..1275ad630 100644 --- a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean3d/rotations3D.kt +++ b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean3d/rotations3D.kt @@ -5,7 +5,6 @@ package space.kscience.kmath.geometry.euclidean3d -import space.kscience.attributes.SafeType import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.complex.* import space.kscience.kmath.geometry.* @@ -245,8 +244,6 @@ public fun Quaternion.Companion.fromEuler( * A vector consisting of angles */ public data class AngleVector(override val x: Angle, override val y: Angle, override val z: Angle) : Vector3D { - override val type: SafeType get() = Angle.type - public companion object } diff --git a/kmath-memory/api/kmath-memory.api b/kmath-memory/api/kmath-memory.api index 67303dd97..d8bfe6625 100644 --- a/kmath-memory/api/kmath-memory.api +++ b/kmath-memory/api/kmath-memory.api @@ -38,7 +38,6 @@ public class space/kscience/kmath/memory/MemoryBuffer : space/kscience/kmath/str protected final fun getMemory ()Lspace/kscience/kmath/memory/Memory; public fun getSize ()I protected final fun getSpec ()Lspace/kscience/kmath/memory/MemorySpec; - public fun getType-V0oMfBY ()Lkotlin/reflect/KType; public fun iterator ()Ljava/util/Iterator; public fun toString ()Ljava/lang/String; } @@ -90,7 +89,6 @@ public abstract interface class space/kscience/kmath/memory/MemoryWriter : java/ public final class space/kscience/kmath/memory/MutableMemoryBuffer : space/kscience/kmath/memory/MemoryBuffer, space/kscience/kmath/structures/MutableBuffer { public static final field Companion Lspace/kscience/kmath/memory/MutableMemoryBuffer$Companion; public fun (Lspace/kscience/kmath/memory/Memory;Lspace/kscience/kmath/memory/MemorySpec;)V - public fun copy ()Lspace/kscience/kmath/structures/MutableBuffer; public fun set (ILjava/lang/Object;)V } diff --git a/kmath-memory/src/commonMain/kotlin/space/kscience/kmath/memory/MemoryBuffer.kt b/kmath-memory/src/commonMain/kotlin/space/kscience/kmath/memory/MemoryBuffer.kt index ea6e705b6..27deea126 100644 --- a/kmath-memory/src/commonMain/kotlin/space/kscience/kmath/memory/MemoryBuffer.kt +++ b/kmath-memory/src/commonMain/kotlin/space/kscience/kmath/memory/MemoryBuffer.kt @@ -5,7 +5,6 @@ package space.kscience.kmath.memory -import space.kscience.attributes.SafeType import space.kscience.kmath.structures.Buffer import space.kscience.kmath.structures.MutableBuffer @@ -18,8 +17,6 @@ import space.kscience.kmath.structures.MutableBuffer */ public open class MemoryBuffer(protected val memory: Memory, protected val spec: MemorySpec) : Buffer { - override val type: SafeType get() = spec.type - override val size: Int get() = memory.size / spec.objectSize override operator fun get(index: Int): T = memory.read { read(spec, spec.objectSize * index) } @@ -56,7 +53,6 @@ public class MutableMemoryBuffer( private val writer: MemoryWriter = memory.writer() override operator fun set(index: Int, value: T): Unit = writer.write(spec, spec.objectSize * index, value) - override fun copy(): MutableBuffer = MutableMemoryBuffer(memory.copy(), spec) public companion object { public fun create(spec: MemorySpec, size: Int): MutableMemoryBuffer = diff --git a/kmath-multik/src/commonMain/kotlin/space/kscience/kmath/multik/MultikTensor.kt b/kmath-multik/src/commonMain/kotlin/space/kscience/kmath/multik/MultikTensor.kt index 7ce9825d3..1c6dfe806 100644 --- a/kmath-multik/src/commonMain/kotlin/space/kscience/kmath/multik/MultikTensor.kt +++ b/kmath-multik/src/commonMain/kotlin/space/kscience/kmath/multik/MultikTensor.kt @@ -30,8 +30,6 @@ public val DataType.type: SafeType<*> @JvmInline public value class MultikTensor(public val array: MutableMultiArray) : Tensor { - @Suppress("UNCHECKED_CAST") - override val type: SafeType get() = array.dtype.type as SafeType override val shape: ShapeND get() = ShapeND(array.shape) diff --git a/kmath-nd4j/api/kmath-nd4j.api b/kmath-nd4j/api/kmath-nd4j.api index 74c6b8805..5a9a7985d 100644 --- a/kmath-nd4j/api/kmath-nd4j.api +++ b/kmath-nd4j/api/kmath-nd4j.api @@ -202,7 +202,6 @@ public final class space/kscience/kmath/nd4j/Nd4jArrayFloatStructure : space/ksc public fun get ([I)Ljava/lang/Float; public synthetic fun get ([I)Ljava/lang/Object; public fun getNdArray ()Lorg/nd4j/linalg/api/ndarray/INDArray; - public fun getType-V0oMfBY ()Lkotlin/reflect/KType; public fun hashCode ()I public fun set ([IF)V public synthetic fun set ([ILjava/lang/Object;)V 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 9bfc2f8f5..ac4ef68d2 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 @@ -6,10 +6,8 @@ package space.kscience.kmath.nd4j import org.nd4j.linalg.api.ndarray.INDArray -import space.kscience.attributes.SafeType import space.kscience.kmath.PerformancePitfall import space.kscience.kmath.nd.* -import space.kscience.kmath.operations.Float32Field /** * Represents a [StructureND] wrapping an [INDArray] object. @@ -70,8 +68,6 @@ public fun INDArray.asDoubleStructure(): Nd4jArrayStructure = Nd4jArrayD public data class Nd4jArrayFloatStructure(override val ndArray: INDArray) : Nd4jArrayStructure() { - override val type: SafeType get() = Float32Field.type - override fun elementsIterator(): Iterator> = ndArray.floatIterator() @PerformancePitfall diff --git a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/ValueAndErrorField.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/ValueAndErrorField.kt index 96acf559a..8f0aa1729 100644 --- a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/ValueAndErrorField.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/ValueAndErrorField.kt @@ -64,7 +64,6 @@ public object ValueAndErrorField : Field { require(values.size == ds.size) } - override val type: SafeType get() = safeTypeOf() override val size: Int get() = values.size @@ -77,7 +76,6 @@ public object ValueAndErrorField : Field { values[index] = value.dispersion } - override fun copy(): MutableBuffer = ValueAndErrorBuffer(values.copy(), ds.copy()) } override val bufferFactory: MutableBufferFactory = object : MutableBufferFactory { diff --git a/kmath-tensorflow/src/main/kotlin/space/kscience/kmath/tensorflow/DoubleTensorFlowAlgebra.kt b/kmath-tensorflow/src/main/kotlin/space/kscience/kmath/tensorflow/DoubleTensorFlowAlgebra.kt index 9a559bc28..516a3a2ce 100644 --- a/kmath-tensorflow/src/main/kotlin/space/kscience/kmath/tensorflow/DoubleTensorFlowAlgebra.kt +++ b/kmath-tensorflow/src/main/kotlin/space/kscience/kmath/tensorflow/DoubleTensorFlowAlgebra.kt @@ -10,7 +10,6 @@ import org.tensorflow.Output import org.tensorflow.ndarray.NdArray import org.tensorflow.op.core.Constant import org.tensorflow.types.TFloat64 -import space.kscience.attributes.SafeType import space.kscience.kmath.PerformancePitfall import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.expressions.Symbol @@ -26,7 +25,6 @@ public class DoubleTensorFlowOutput( graph: Graph, output: Output, ) : TensorFlowOutput(graph, output) { - override val type: SafeType get() = Float64Field.type override fun org.tensorflow.Tensor.actualizeTensor(): NdArray = this as TFloat64 } diff --git a/kmath-tensorflow/src/main/kotlin/space/kscience/kmath/tensorflow/IntTensorFlowAlgebra.kt b/kmath-tensorflow/src/main/kotlin/space/kscience/kmath/tensorflow/IntTensorFlowAlgebra.kt index 3695a2640..95ed52638 100644 --- a/kmath-tensorflow/src/main/kotlin/space/kscience/kmath/tensorflow/IntTensorFlowAlgebra.kt +++ b/kmath-tensorflow/src/main/kotlin/space/kscience/kmath/tensorflow/IntTensorFlowAlgebra.kt @@ -10,19 +10,12 @@ import org.tensorflow.Output import org.tensorflow.ndarray.NdArray import org.tensorflow.types.TInt32 import org.tensorflow.types.TInt64 -import space.kscience.attributes.SafeType -import space.kscience.kmath.operations.Int32Ring -import space.kscience.kmath.operations.Int64Ring -import space.kscience.kmath.structures.Int32 -import space.kscience.kmath.structures.Int64 public class IntTensorFlowOutput( graph: Graph, output: Output, ) : TensorFlowOutput(graph, output) { - override val type: SafeType get() = Int32Ring.type - override fun org.tensorflow.Tensor.actualizeTensor(): NdArray = this as TInt32 } @@ -31,6 +24,5 @@ public class LongTensorFlowOutput( output: Output, ) : TensorFlowOutput(graph, output) { - override val type: SafeType get() = Int64Ring.type override fun org.tensorflow.Tensor.actualizeTensor(): NdArray = this as TInt64 } \ No newline at end of file diff --git a/kmath-tensorflow/src/main/kotlin/space/kscience/kmath/tensorflow/TensorFlowAlgebra.kt b/kmath-tensorflow/src/main/kotlin/space/kscience/kmath/tensorflow/TensorFlowAlgebra.kt index 7e413c29c..2a8720275 100644 --- a/kmath-tensorflow/src/main/kotlin/space/kscience/kmath/tensorflow/TensorFlowAlgebra.kt +++ b/kmath-tensorflow/src/main/kotlin/space/kscience/kmath/tensorflow/TensorFlowAlgebra.kt @@ -17,7 +17,6 @@ import org.tensorflow.op.core.* import org.tensorflow.types.TInt32 import org.tensorflow.types.family.TNumber import org.tensorflow.types.family.TType -import space.kscience.attributes.SafeType import space.kscience.kmath.PerformancePitfall import space.kscience.kmath.UnsafeKMathAPI import space.kscience.kmath.UnstableKMathAPI @@ -40,7 +39,8 @@ public sealed interface TensorFlowTensor : Tensor /** * Static (eager) in-memory TensorFlow tensor */ -public class TensorFlowArray(override val type: SafeType, public val tensor: NdArray) : Tensor { +@JvmInline +public value class TensorFlowArray(public val tensor: NdArray) : Tensor { override val shape: ShapeND get() = ShapeND(tensor.shape().asArray().toIntArray()) @@ -74,7 +74,7 @@ public abstract class TensorFlowOutput( internal val actualTensor by lazy { Session(graph).use { session -> - TensorFlowArray(type, session.runner().fetch(output).run().first().actualizeTensor()) + TensorFlowArray(session.runner().fetch(output).run().first().actualizeTensor()) } } diff --git a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/DoubleTensor.kt b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/DoubleTensor.kt index b150c9839..b3c2eb1b4 100644 --- a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/DoubleTensor.kt +++ b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/DoubleTensor.kt @@ -5,12 +5,10 @@ package space.kscience.kmath.tensors.core -import space.kscience.attributes.SafeType import space.kscience.kmath.PerformancePitfall import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.nd.MutableStructureNDOfDouble import space.kscience.kmath.nd.ShapeND -import space.kscience.kmath.operations.DoubleField import space.kscience.kmath.structures.* import space.kscience.kmath.tensors.core.internal.toPrettyString @@ -36,7 +34,7 @@ public class OffsetDoubleBuffer( /** * Copy only a part of buffer that belongs to this [OffsetDoubleBuffer] */ - override fun copy(): Float64Buffer = origin.array.copyOfRange(offset, offset + size).asBuffer() + public fun copy(): Float64Buffer = origin.array.copyOfRange(offset, offset + size).asBuffer() override fun iterator(): Iterator = iterator { for (i in indices) { @@ -90,8 +88,6 @@ public open class DoubleTensor( final override val source: OffsetDoubleBuffer, ) : BufferedTensor(shape), MutableStructureNDOfDouble { - override val type: SafeType get() = DoubleField.type - init { require(linearSize == source.size) { "Source buffer size must be equal tensor size" } } diff --git a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/DoubleTensor1D.kt b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/DoubleTensor1D.kt index 74a4f65c4..05f1b2f20 100644 --- a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/DoubleTensor1D.kt +++ b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/DoubleTensor1D.kt @@ -8,7 +8,6 @@ package space.kscience.kmath.tensors.core import space.kscience.kmath.PerformancePitfall import space.kscience.kmath.nd.MutableStructure1D import space.kscience.kmath.nd.ShapeND -import space.kscience.kmath.structures.MutableBuffer public class DoubleTensor1D( source: OffsetDoubleBuffer, @@ -30,8 +29,6 @@ public class DoubleTensor1D( source[index] = value } - override fun copy(): MutableBuffer = source.copy() - @PerformancePitfall override fun elements(): Sequence> = super.elements() } diff --git a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/IntTensor.kt b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/IntTensor.kt index 4c00933db..eb95d5e70 100644 --- a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/IntTensor.kt +++ b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/IntTensor.kt @@ -5,10 +5,8 @@ package space.kscience.kmath.tensors.core -import space.kscience.attributes.SafeType import space.kscience.kmath.PerformancePitfall import space.kscience.kmath.nd.ShapeND -import space.kscience.kmath.operations.IntRing import space.kscience.kmath.structures.* /** @@ -26,8 +24,6 @@ public class OffsetIntBuffer( require(offset + size <= source.size) { "Maximum index must be inside source dimension" } } - override val type: SafeType get() = IntRing.type - override fun set(index: Int, value: Int) { require(index in 0 until size) { "Index must be in [0, size)" } source[index + offset] = value @@ -38,7 +34,7 @@ public class OffsetIntBuffer( /** * Copy only a part of buffer that belongs to this tensor */ - override fun copy(): Int32Buffer = source.array.copyOfRange(offset, offset + size).asBuffer() + public fun copy(): Int32Buffer = source.array.copyOfRange(offset, offset + size).asBuffer() override fun iterator(): Iterator = iterator { for (i in indices) { @@ -87,7 +83,6 @@ public class IntTensor( require(linearSize == source.size) { "Source buffer size must be equal tensor size" } } - override val type: SafeType get() = IntRing.type public constructor(shape: ShapeND, buffer: Int32Buffer) : this(shape, OffsetIntBuffer(buffer, 0, buffer.size)) diff --git a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/tensorTransform.kt b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/tensorTransform.kt index bafd3fadd..6490ecdb9 100644 --- a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/tensorTransform.kt +++ b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/tensorTransform.kt @@ -17,7 +17,7 @@ import space.kscience.kmath.tensors.api.Tensor public fun StructureND.copyToTensor(): DoubleTensor = if (this is DoubleTensor) { DoubleTensor(shape, source.copy()) } else if (this is Float64BufferND && indices is RowStrides) { - DoubleTensor(shape, buffer.copy()) + DoubleTensor(shape, buffer.array.copyOf().asBuffer()) } else { DoubleTensor( shape, diff --git a/kmath-viktor/api/kmath-viktor.api b/kmath-viktor/api/kmath-viktor.api index 11e312e12..0ad7368a9 100644 --- a/kmath-viktor/api/kmath-viktor.api +++ b/kmath-viktor/api/kmath-viktor.api @@ -1,8 +1,6 @@ public final class space/kscience/kmath/viktor/ViktorBuffer : space/kscience/kmath/structures/MutableBuffer { public static final synthetic fun box-impl (Lorg/jetbrains/bio/viktor/F64FlatArray;)Lspace/kscience/kmath/viktor/ViktorBuffer; public static fun constructor-impl (Lorg/jetbrains/bio/viktor/F64FlatArray;)Lorg/jetbrains/bio/viktor/F64FlatArray; - public fun copy ()Lspace/kscience/kmath/structures/MutableBuffer; - public static fun copy-impl (Lorg/jetbrains/bio/viktor/F64FlatArray;)Lspace/kscience/kmath/structures/MutableBuffer; public fun equals (Ljava/lang/Object;)Z public static fun equals-impl (Lorg/jetbrains/bio/viktor/F64FlatArray;Ljava/lang/Object;)Z public static final fun equals-impl0 (Lorg/jetbrains/bio/viktor/F64FlatArray;Lorg/jetbrains/bio/viktor/F64FlatArray;)Z @@ -12,8 +10,6 @@ public final class space/kscience/kmath/viktor/ViktorBuffer : space/kscience/kma public final fun getFlatArray ()Lorg/jetbrains/bio/viktor/F64FlatArray; public fun getSize ()I public static fun getSize-impl (Lorg/jetbrains/bio/viktor/F64FlatArray;)I - public fun getType-V0oMfBY ()Lkotlin/reflect/KType; - public static fun getType-V0oMfBY (Lorg/jetbrains/bio/viktor/F64FlatArray;)Lkotlin/reflect/KType; public fun hashCode ()I public static fun hashCode-impl (Lorg/jetbrains/bio/viktor/F64FlatArray;)I public fun iterator ()Ljava/util/Iterator; @@ -115,7 +111,6 @@ public final class space/kscience/kmath/viktor/ViktorStructureND : space/kscienc public synthetic fun get ([I)Ljava/lang/Object; public final fun getF64Buffer ()Lorg/jetbrains/bio/viktor/F64Array; public fun getShape-IIYLAfE ()[I - public fun getType-V0oMfBY ()Lkotlin/reflect/KType; public fun set ([ID)V public synthetic fun set ([ILjava/lang/Object;)V } diff --git a/kmath-viktor/src/main/kotlin/space/kscience/kmath/viktor/ViktorBuffer.kt b/kmath-viktor/src/main/kotlin/space/kscience/kmath/viktor/ViktorBuffer.kt index 88112af2a..89b51f269 100644 --- a/kmath-viktor/src/main/kotlin/space/kscience/kmath/viktor/ViktorBuffer.kt +++ b/kmath-viktor/src/main/kotlin/space/kscience/kmath/viktor/ViktorBuffer.kt @@ -6,15 +6,12 @@ package space.kscience.kmath.viktor import org.jetbrains.bio.viktor.F64FlatArray -import space.kscience.attributes.SafeType -import space.kscience.kmath.operations.Float64Field import space.kscience.kmath.structures.Buffer import space.kscience.kmath.structures.MutableBuffer @Suppress("NOTHING_TO_INLINE", "OVERRIDE_BY_INLINE") @JvmInline public value class ViktorBuffer(public val flatArray: F64FlatArray) : MutableBuffer { - override val type: SafeType get() = Float64Field.type override val size: Int get() = flatArray.length @@ -25,7 +22,6 @@ public value class ViktorBuffer(public val flatArray: F64FlatArray) : MutableBuf flatArray[index] = value } - override fun copy(): MutableBuffer = ViktorBuffer(flatArray.copy().flatten()) override operator fun iterator(): Iterator = flatArray.data.iterator() override fun toString(): String = Buffer.toString(this) 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 9e01fd88a..328a0ab01 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 @@ -6,17 +6,13 @@ package space.kscience.kmath.viktor import org.jetbrains.bio.viktor.F64Array -import space.kscience.attributes.SafeType import space.kscience.kmath.PerformancePitfall import space.kscience.kmath.nd.ColumnStrides import space.kscience.kmath.nd.MutableStructureND import space.kscience.kmath.nd.ShapeND -import space.kscience.kmath.operations.Float64Field @Suppress("OVERRIDE_BY_INLINE", "NOTHING_TO_INLINE") public class ViktorStructureND(public val f64Buffer: F64Array) : MutableStructureND { - override val type: SafeType get() = Float64Field.type - override val shape: ShapeND get() = ShapeND(f64Buffer.shape) @OptIn(PerformancePitfall::class) From 11722db3c827227b666e25636db012f5b65df2f1 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Fri, 8 Mar 2024 10:04:37 +0300 Subject: [PATCH 35/40] Add Attributes container equality --- .../kotlin/space/kscience/attributes/Attributes.kt | 14 ++++++++++---- .../space/kscience/attributes/AttributesBuilder.kt | 4 ++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/Attributes.kt b/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/Attributes.kt index 86d196f74..ff5d7f145 100644 --- a/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/Attributes.kt +++ b/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/Attributes.kt @@ -5,8 +5,6 @@ package space.kscience.attributes -import kotlin.jvm.JvmInline - /** * A set of attributes. The implementation must guarantee that [content] keys correspond to its value types. */ @@ -27,14 +25,22 @@ public interface Attributes { @Suppress("UNCHECKED_CAST") public operator fun get(attribute: Attribute): T? = content[attribute] as? T + override fun toString(): String + override fun equals(other: Any?): Boolean + override fun hashCode(): Int + public companion object { public val EMPTY: Attributes = AttributesImpl(emptyMap()) + + public fun equals(a1: Attributes, a2: Attributes): Boolean = + a1.keys == a2.keys && a1.keys.all { a1[it] == a2[it] } } } -@JvmInline -internal value class AttributesImpl(override val content: Map, Any?>) : Attributes { +internal class AttributesImpl(override val content: Map, Any?>) : Attributes { override fun toString(): String = "Attributes(value=${content.entries})" + override fun equals(other: Any?): Boolean = other is Attributes && Attributes.equals(this, other) + override fun hashCode(): Int = content.hashCode() } public fun Attributes.isEmpty(): Boolean = content.isEmpty() diff --git a/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/AttributesBuilder.kt b/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/AttributesBuilder.kt index 0acf4e004..0082ba143 100644 --- a/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/AttributesBuilder.kt +++ b/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/AttributesBuilder.kt @@ -16,6 +16,10 @@ public class AttributesBuilder internal constructor( public constructor() : this(mutableMapOf()) + override fun toString(): String = "Attributes(value=${content.entries})" + override fun equals(other: Any?): Boolean = other is Attributes && Attributes.equals(this, other) + override fun hashCode(): Int = content.hashCode() + override val content: Map, Any?> get() = map public operator fun set(attribute: Attribute, value: T?) { From dcf5b19d800da1ea917d26fac70f3efdb9050af1 Mon Sep 17 00:00:00 2001 From: SPC-code <112205870+SPC-code@users.noreply.github.com> Date: Fri, 8 Mar 2024 10:06:30 +0300 Subject: [PATCH 36/40] Update attributes-kt/src/commonMain/kotlin/space/kscience/attributes/Attributes.kt Co-authored-by: Gleb Minaev <43728100+lounres@users.noreply.github.com> --- .../commonMain/kotlin/space/kscience/attributes/Attributes.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/Attributes.kt b/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/Attributes.kt index 86d196f74..fb0706504 100644 --- a/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/Attributes.kt +++ b/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/Attributes.kt @@ -8,7 +8,7 @@ package space.kscience.attributes import kotlin.jvm.JvmInline /** - * A set of attributes. The implementation must guarantee that [content] keys correspond to its value types. + * A set of attributes. The implementation must guarantee that [content] keys correspond to their value types. */ public interface Attributes { /** From e7d8b948899b7aa0063c51a5e375b5243f594837 Mon Sep 17 00:00:00 2001 From: SPC-code <112205870+SPC-code@users.noreply.github.com> Date: Fri, 8 Mar 2024 10:07:54 +0300 Subject: [PATCH 37/40] Update attributes-kt/src/commonMain/kotlin/space/kscience/attributes/SafeType.kt Co-authored-by: Gleb Minaev <43728100+lounres@users.noreply.github.com> --- .../src/commonMain/kotlin/space/kscience/attributes/SafeType.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/SafeType.kt b/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/SafeType.kt index 1c7b0991a..b76589164 100644 --- a/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/SafeType.kt +++ b/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/SafeType.kt @@ -11,7 +11,7 @@ import kotlin.reflect.KType import kotlin.reflect.typeOf /** - * Safe variant ok Kotlin [KType] that ensures that the type parameter is of the same type ask [kType] + * Safe variant ok Kotlin [KType] that ensures that the type parameter is of the same type as [kType] * * @param kType raw [KType] */ From b076a6573a622205457ed755765e796e46a07319 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Fri, 8 Mar 2024 10:18:32 +0300 Subject: [PATCH 38/40] Update versions --- attributes-kt/api/attributes-kt.api | 7 +++++++ build.gradle.kts | 4 ++-- buildSrc/settings.gradle.kts | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/attributes-kt/api/attributes-kt.api b/attributes-kt/api/attributes-kt.api index 26386d9d7..403e12f5c 100644 --- a/attributes-kt/api/attributes-kt.api +++ b/attributes-kt/api/attributes-kt.api @@ -14,12 +14,16 @@ public abstract interface class space/kscience/attributes/AttributeWithDefault : public abstract interface class space/kscience/attributes/Attributes { public static final field Companion Lspace/kscience/attributes/Attributes$Companion; + public abstract fun equals (Ljava/lang/Object;)Z public fun get (Lspace/kscience/attributes/Attribute;)Ljava/lang/Object; public abstract fun getContent ()Ljava/util/Map; public fun getKeys ()Ljava/util/Set; + public abstract fun hashCode ()I + public abstract fun toString ()Ljava/lang/String; } public final class space/kscience/attributes/Attributes$Companion { + public final fun equals (Lspace/kscience/attributes/Attributes;Lspace/kscience/attributes/Attributes;)Z public final fun getEMPTY ()Lspace/kscience/attributes/Attributes; } @@ -27,11 +31,14 @@ public final class space/kscience/attributes/AttributesBuilder : space/kscience/ public fun ()V public final fun add (Lspace/kscience/attributes/SetAttribute;Ljava/lang/Object;)V public final fun build ()Lspace/kscience/attributes/Attributes; + public fun equals (Ljava/lang/Object;)Z public final fun from (Lspace/kscience/attributes/Attributes;)V public fun getContent ()Ljava/util/Map; + public fun hashCode ()I public final fun invoke (Lspace/kscience/attributes/Attribute;Ljava/lang/Object;)V public final fun remove (Lspace/kscience/attributes/SetAttribute;Ljava/lang/Object;)V public final fun set (Lspace/kscience/attributes/Attribute;Ljava/lang/Object;)V + public fun toString ()Ljava/lang/String; } public final class space/kscience/attributes/AttributesBuilderKt { diff --git a/build.gradle.kts b/build.gradle.kts index 9231fc312..ec82e8eeb 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -14,7 +14,7 @@ allprojects { } group = "space.kscience" - version = "0.4.0-RC2" + version = "0.4.0" } subprojects { @@ -69,4 +69,4 @@ ksciencePublish { apiValidation.nonPublicMarkers.add("space.kscience.kmath.UnstableKMathAPI") -val multikVersion by extra("0.2.2") +val multikVersion by extra("0.2.3") diff --git a/buildSrc/settings.gradle.kts b/buildSrc/settings.gradle.kts index af804cb7d..09633711e 100644 --- a/buildSrc/settings.gradle.kts +++ b/buildSrc/settings.gradle.kts @@ -6,7 +6,7 @@ enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS") plugins { - id("org.gradle.toolchains.foojay-resolver-convention") version "0.7.0" + id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0" } dependencyResolutionManagement { From 86324a921989d32deec21ea58b128692ce264d9c Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sun, 17 Mar 2024 09:29:15 +0300 Subject: [PATCH 39/40] Add RingBuffer `reset` and `capacity` --- .../kscience/kmath/streaming/RingBuffer.kt | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/streaming/RingBuffer.kt b/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/streaming/RingBuffer.kt index 3ee6b203a..ce7f07860 100644 --- a/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/streaming/RingBuffer.kt +++ b/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/streaming/RingBuffer.kt @@ -23,6 +23,8 @@ public class RingBuffer( private val mutex: Mutex = Mutex() + public val capacity: Int get() = buffer.size + override var size: Int = size private set @@ -32,7 +34,7 @@ public class RingBuffer( return buffer[startIndex.forward(index)] } - public fun isFull(): Boolean = size == buffer.size + public fun isFull(): Boolean = size == capacity /** * Iterator could provide wrong results if buffer is changed in initialization (iteration is safe) @@ -59,6 +61,9 @@ public class RingBuffer( VirtualBuffer(size) { i -> copy[startIndex.forward(i)] } } + /** + * Add an element to the end of the [RingBuffer]. If buffer capacity is reached, the first element is automatically removed. + */ public suspend fun push(element: T) { mutex.withLock { buffer[startIndex.forward(size)] = element @@ -66,7 +71,15 @@ public class RingBuffer( } } - private fun Int.forward(n: Int): Int = (this + n) % (buffer.size) + /** + * Reset buffer to its empty state + */ + public suspend fun reset(): Unit = mutex.withLock { + startIndex = 0 + size = 0 + } + + private fun Int.forward(n: Int): Int = (this + n) % capacity override fun toString(): String = Buffer.toString(this) } From 82196250f651d0ba82eb89a1ac3b008b2af184a1 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sun, 17 Mar 2024 09:42:50 +0300 Subject: [PATCH 40/40] Remove unnecessary internal dependencies --- kmath-coroutines/build.gradle.kts | 3 +-- kmath-multik/build.gradle.kts | 2 +- .../kotlin/space/kscience/kmath/multik/MultikTensor.kt | 3 +-- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/kmath-coroutines/build.gradle.kts b/kmath-coroutines/build.gradle.kts index 91b2afd5e..0cb36e10a 100644 --- a/kmath-coroutines/build.gradle.kts +++ b/kmath-coroutines/build.gradle.kts @@ -9,8 +9,7 @@ kscience { wasm() dependencies { - api(project(":kmath-core")) - api(project(":kmath-complex")) + api(projects.kmathCore) api(spclibs.kotlinx.coroutines.core) } } diff --git a/kmath-multik/build.gradle.kts b/kmath-multik/build.gradle.kts index fc51d2c21..85c4d52cb 100644 --- a/kmath-multik/build.gradle.kts +++ b/kmath-multik/build.gradle.kts @@ -15,7 +15,7 @@ kotlin{ sourceSets{ commonMain{ dependencies{ - api(project(":kmath-tensors")) + api(projects.kmathTensors) api("org.jetbrains.kotlinx:multik-core:$multikVersion") } } diff --git a/kmath-multik/src/commonMain/kotlin/space/kscience/kmath/multik/MultikTensor.kt b/kmath-multik/src/commonMain/kotlin/space/kscience/kmath/multik/MultikTensor.kt index 1c6dfe806..20916d934 100644 --- a/kmath-multik/src/commonMain/kotlin/space/kscience/kmath/multik/MultikTensor.kt +++ b/kmath-multik/src/commonMain/kotlin/space/kscience/kmath/multik/MultikTensor.kt @@ -9,7 +9,6 @@ import org.jetbrains.kotlinx.multik.ndarray.data.* import space.kscience.attributes.SafeType import space.kscience.attributes.safeTypeOf import space.kscience.kmath.PerformancePitfall -import space.kscience.kmath.complex.ComplexField import space.kscience.kmath.nd.ShapeND import space.kscience.kmath.operations.* import space.kscience.kmath.tensors.api.Tensor @@ -24,7 +23,7 @@ public val DataType.type: SafeType<*> DataType.FloatDataType -> Float32Field.type DataType.DoubleDataType -> Float64Field.type DataType.ComplexFloatDataType -> safeTypeOf>() - DataType.ComplexDoubleDataType -> ComplexField.type + DataType.ComplexDoubleDataType -> safeTypeOf>() }