From 8179be2f6284a01fa5ebfb020ee2051c83265655 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sun, 14 Mar 2021 09:55:24 +0300 Subject: [PATCH] cleanup --- .../linear/{LinearSpaceOverNd.kt => BufferLinearSpace.kt} | 6 ++---- .../kotlin/space/kscience/kmath/linear/LinearSpace.kt | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) rename kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/{LinearSpaceOverNd.kt => BufferLinearSpace.kt} (94%) diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/LinearSpaceOverNd.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/BufferLinearSpace.kt similarity index 94% rename from kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/LinearSpaceOverNd.kt rename to kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/BufferLinearSpace.kt index 6a82f37ec..1ea138063 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/LinearSpaceOverNd.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/BufferLinearSpace.kt @@ -9,7 +9,7 @@ import space.kscience.kmath.structures.VirtualBuffer import space.kscience.kmath.structures.indices -public class LinearSpaceOverNd>( +public class BufferLinearSpace>( override val elementAlgebra: A, private val bufferFactory: BufferFactory, ) : LinearSpace { @@ -35,7 +35,7 @@ public class LinearSpaceOverNd>( } override fun Matrix.minus(other: Matrix): Matrix = ndRing(rowNum, colNum).run { - require(shape.contentEquals(other.shape)) { "Shape mismatch on Matrix::plus. Expected $shape but found ${other.shape}" } + require(shape.contentEquals(other.shape)) { "Shape mismatch on Matrix::minus. Expected $shape but found ${other.shape}" } unwrap().minus(other.unwrap()).as2D() } @@ -50,7 +50,6 @@ public class LinearSpaceOverNd>( return elementAlgebra { val rows = this@dot.rows.map{it.linearize()} val columns = other.columns.map { it.linearize() } - //TODO optimize buffers buildMatrix(rowNum, other.colNum) { i, j -> val r = rows[i] val c = columns[j] @@ -67,7 +66,6 @@ public class LinearSpaceOverNd>( require(colNum == vector.size) { "Matrix dot vector operation dimension mismatch: ($rowNum, $colNum) x (${vector.size})" } return elementAlgebra { val rows = this@dot.rows - //TODO optimize buffers buildVector(rowNum) { i -> val r = rows[i] var res = zero 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 b0331bdea..4fd4d28d1 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 @@ -171,7 +171,7 @@ public interface LinearSpace> { public fun > buffered( algebra: A, bufferFactory: BufferFactory = Buffer.Companion::boxing, - ): LinearSpace = LinearSpaceOverNd(algebra,bufferFactory) + ): LinearSpace = BufferLinearSpace(algebra,bufferFactory) public val real: LinearSpace = buffered(RealField, Buffer.Companion::real)