From 49f0d1fe7dbfea5cebd6b9283a0e33321e1e6517 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Tue, 20 Feb 2024 19:35:00 +0300 Subject: [PATCH] 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)