Drop koma module, implement kmath-ejml module copying it, but for EJML SimpleMatrix #136

Merged
CommanderTvis merged 24 commits from ejml into dev 2020-10-01 21:30:40 +03:00
3 changed files with 14 additions and 7 deletions
Showing only changes of commit 2c21f56695 - Show all commits

View File

@ -12,6 +12,7 @@ import kscience.kmath.structures.NDStructure
* Represents featured matrix over EJML [SimpleMatrix]. * Represents featured matrix over EJML [SimpleMatrix].
* *
* @property origin the underlying [SimpleMatrix]. * @property origin the underlying [SimpleMatrix].
* @author Iaroslav Postovalov
*/ */
public class EjmlMatrix(public val origin: SimpleMatrix, features: Set<MatrixFeature>? = null) : FeaturedMatrix<Double> { public class EjmlMatrix(public val origin: SimpleMatrix, features: Set<MatrixFeature>? = null) : FeaturedMatrix<Double> {
public override val rowNum: Int public override val rowNum: Int

View File

@ -9,6 +9,8 @@ import kscience.kmath.structures.Matrix
/** /**
* Represents context of basic operations operating with [EjmlMatrix]. * Represents context of basic operations operating with [EjmlMatrix].
*
* @author Iaroslav Postovalov
*/ */
public class EjmlMatrixContext(private val space: Space<Double>) : MatrixContext<Double> { public class EjmlMatrixContext(private val space: Space<Double>) : MatrixContext<Double> {
/** /**
@ -32,22 +34,22 @@ public class EjmlMatrixContext(private val space: Space<Double>) : MatrixContext
} }
}) })
override fun Matrix<Double>.dot(other: Matrix<Double>): EjmlMatrix = public override fun Matrix<Double>.dot(other: Matrix<Double>): EjmlMatrix =
EjmlMatrix(toEjml().origin.mult(other.toEjml().origin)) EjmlMatrix(toEjml().origin.mult(other.toEjml().origin))
override fun Matrix<Double>.dot(vector: Point<Double>): EjmlVector = public override fun Matrix<Double>.dot(vector: Point<Double>): EjmlVector =
EjmlVector(toEjml().origin.mult(vector.toEjml().origin)) EjmlVector(toEjml().origin.mult(vector.toEjml().origin))
override fun add(a: Matrix<Double>, b: Matrix<Double>): EjmlMatrix = public override fun add(a: Matrix<Double>, b: Matrix<Double>): EjmlMatrix =
EjmlMatrix(a.toEjml().origin + b.toEjml().origin) EjmlMatrix(a.toEjml().origin + b.toEjml().origin)
override operator fun Matrix<Double>.minus(b: Matrix<Double>): EjmlMatrix = public override operator fun Matrix<Double>.minus(b: Matrix<Double>): EjmlMatrix =
EjmlMatrix(toEjml().origin - b.toEjml().origin) EjmlMatrix(toEjml().origin - b.toEjml().origin)
override fun multiply(a: Matrix<Double>, k: Number): EjmlMatrix = public override fun multiply(a: Matrix<Double>, k: Number): EjmlMatrix =
produce(a.rowNum, a.colNum) { i, j -> space { a[i, j] * k } } produce(a.rowNum, a.colNum) { i, j -> space { a[i, j] * k } }
override operator fun Matrix<Double>.times(value: Double): EjmlMatrix = EjmlMatrix(toEjml().origin.scale(value)) public override operator fun Matrix<Double>.times(value: Double): EjmlMatrix = EjmlMatrix(toEjml().origin.scale(value))
public companion object public companion object
} }
@ -58,6 +60,7 @@ public class EjmlMatrixContext(private val space: Space<Double>) : MatrixContext
* @param a the base matrix. * @param a the base matrix.
* @param b n by p matrix. * @param b n by p matrix.
* @return the solution for 'x' that is n by p. * @return the solution for 'x' that is n by p.
* @author Iaroslav Postovalov
*/ */
public fun EjmlMatrixContext.solve(a: Matrix<Double>, b: Matrix<Double>): EjmlMatrix = public fun EjmlMatrixContext.solve(a: Matrix<Double>, b: Matrix<Double>): EjmlMatrix =
EjmlMatrix(a.toEjml().origin.solve(b.toEjml().origin)) EjmlMatrix(a.toEjml().origin.solve(b.toEjml().origin))
@ -68,6 +71,7 @@ public fun EjmlMatrixContext.solve(a: Matrix<Double>, b: Matrix<Double>): EjmlMa
* @param a the base matrix. * @param a the base matrix.
* @param b n by p vector. * @param b n by p vector.
* @return the solution for 'x' that is n by p. * @return the solution for 'x' that is n by p.
* @author Iaroslav Postovalov
*/ */
public fun EjmlMatrixContext.solve(a: Matrix<Double>, b: Point<Double>): EjmlVector = public fun EjmlMatrixContext.solve(a: Matrix<Double>, b: Point<Double>): EjmlVector =
EjmlVector(a.toEjml().origin.solve(b.toEjml().origin)) EjmlVector(a.toEjml().origin.solve(b.toEjml().origin))
@ -77,5 +81,6 @@ public fun EjmlMatrixContext.solve(a: Matrix<Double>, b: Point<Double>): EjmlVec
* *
* @param a the matrix. * @param a the matrix.
* @return the inverse of this matrix. * @return the inverse of this matrix.
* @author Iaroslav Postovalov
*/ */
public fun EjmlMatrixContext.inverse(a: Matrix<Double>): EjmlMatrix = EjmlMatrix(a.toEjml().origin.invert()) public fun EjmlMatrixContext.inverse(a: Matrix<Double>): EjmlMatrix = EjmlMatrix(a.toEjml().origin.invert())

View File

@ -8,8 +8,9 @@ import kscience.kmath.structures.Buffer
* Represents point over EJML [SimpleMatrix]. * Represents point over EJML [SimpleMatrix].
* *
* @property origin the underlying [SimpleMatrix]. * @property origin the underlying [SimpleMatrix].
* @author Iaroslav Postavalov
*/ */
class EjmlVector internal constructor(val origin: SimpleMatrix) : Point<Double> { public class EjmlVector internal constructor(public val origin: SimpleMatrix) : Point<Double> {
override val size: Int get() = origin.numRows() override val size: Int get() = origin.numRows()
init { init {