Drop koma module, implement kmath-ejml module copying it, but for EJML SimpleMatrix #136
@ -1,5 +1,5 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id("scientifik.jvm")
|
id("ru.mipt.npm.jvm")
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
@ -1,29 +1,29 @@
|
|||||||
package scientifik.kmath.ejml
|
package kscience.kmath.ejml
|
||||||
|
|
||||||
import org.ejml.dense.row.factory.DecompositionFactory_DDRM
|
import org.ejml.dense.row.factory.DecompositionFactory_DDRM
|
||||||
import org.ejml.simple.SimpleMatrix
|
import org.ejml.simple.SimpleMatrix
|
||||||
import scientifik.kmath.linear.DeterminantFeature
|
import kscience.kmath.linear.DeterminantFeature
|
||||||
import scientifik.kmath.linear.FeaturedMatrix
|
import kscience.kmath.linear.FeaturedMatrix
|
||||||
import scientifik.kmath.linear.LUPDecompositionFeature
|
import kscience.kmath.linear.LUPDecompositionFeature
|
||||||
import scientifik.kmath.linear.MatrixFeature
|
import kscience.kmath.linear.MatrixFeature
|
||||||
import scientifik.kmath.structures.NDStructure
|
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].
|
||||||
*/
|
*/
|
||||||
class EjmlMatrix(val origin: SimpleMatrix, features: Set<MatrixFeature>? = null) : FeaturedMatrix<Double> {
|
public class EjmlMatrix(public val origin: SimpleMatrix, features: Set<MatrixFeature>? = null) : FeaturedMatrix<Double> {
|
||||||
override val rowNum: Int
|
public override val rowNum: Int
|
||||||
get() = origin.numRows()
|
get() = origin.numRows()
|
||||||
|
|
||||||
override val colNum: Int
|
public override val colNum: Int
|
||||||
get() = origin.numCols()
|
get() = origin.numCols()
|
||||||
|
|
||||||
override val shape: IntArray
|
public override val shape: IntArray
|
||||||
get() = intArrayOf(origin.numRows(), origin.numCols())
|
get() = intArrayOf(origin.numRows(), origin.numCols())
|
||||||
|
|
||||||
override val features: Set<MatrixFeature> = setOf(
|
public override val features: Set<MatrixFeature> = setOf(
|
||||||
object : LUPDecompositionFeature<Double>, DeterminantFeature<Double> {
|
object : LUPDecompositionFeature<Double>, DeterminantFeature<Double> {
|
||||||
override val determinant: Double
|
override val determinant: Double
|
||||||
get() = origin.determinant()
|
get() = origin.determinant()
|
||||||
@ -50,21 +50,21 @@ class EjmlMatrix(val origin: SimpleMatrix, features: Set<MatrixFeature>? = null)
|
|||||||
}
|
}
|
||||||
) union features.orEmpty()
|
) union features.orEmpty()
|
||||||
|
|
||||||
override fun suggestFeature(vararg features: MatrixFeature): FeaturedMatrix<Double> =
|
public override fun suggestFeature(vararg features: MatrixFeature): FeaturedMatrix<Double> =
|
||||||
EjmlMatrix(origin, this.features + features)
|
EjmlMatrix(origin, this.features + features)
|
||||||
|
|
||||||
override operator fun get(i: Int, j: Int): Double = origin[i, j]
|
public override operator fun get(i: Int, j: Int): Double = origin[i, j]
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
public override fun equals(other: Any?): Boolean {
|
||||||
if (other is EjmlMatrix) return origin.isIdentical(other.origin, 0.0)
|
if (other is EjmlMatrix) return origin.isIdentical(other.origin, 0.0)
|
||||||
return NDStructure.equals(this, other as? NDStructure<*> ?: return false)
|
return NDStructure.equals(this, other as? NDStructure<*> ?: return false)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
public override fun hashCode(): Int {
|
||||||
var result = origin.hashCode()
|
var result = origin.hashCode()
|
||||||
result = 31 * result + features.hashCode()
|
result = 31 * result + features.hashCode()
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun toString(): String = "EjmlMatrix(origin=$origin, features=$features)"
|
public override fun toString(): String = "EjmlMatrix(origin=$origin, features=$features)"
|
||||||
}
|
}
|
@ -1,26 +1,26 @@
|
|||||||
package scientifik.kmath.ejml
|
package kscience.kmath.ejml
|
||||||
|
|
||||||
import org.ejml.simple.SimpleMatrix
|
import org.ejml.simple.SimpleMatrix
|
||||||
import scientifik.kmath.linear.MatrixContext
|
import kscience.kmath.linear.MatrixContext
|
||||||
import scientifik.kmath.linear.Point
|
import kscience.kmath.linear.Point
|
||||||
import scientifik.kmath.operations.Space
|
import kscience.kmath.operations.Space
|
||||||
import scientifik.kmath.operations.invoke
|
import kscience.kmath.operations.invoke
|
||||||
import scientifik.kmath.structures.Matrix
|
import kscience.kmath.structures.Matrix
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents context of basic operations operating with [EjmlMatrix].
|
* Represents context of basic operations operating with [EjmlMatrix].
|
||||||
*/
|
*/
|
||||||
class EjmlMatrixContext(private val space: Space<Double>) : MatrixContext<Double> {
|
public class EjmlMatrixContext(private val space: Space<Double>) : MatrixContext<Double> {
|
||||||
/**
|
/**
|
||||||
* Converts this matrix to EJML one.
|
* Converts this matrix to EJML one.
|
||||||
*/
|
*/
|
||||||
fun Matrix<Double>.toEjml(): EjmlMatrix =
|
public fun Matrix<Double>.toEjml(): EjmlMatrix =
|
||||||
if (this is EjmlMatrix) this else produce(rowNum, colNum) { i, j -> get(i, j) }
|
if (this is EjmlMatrix) this else produce(rowNum, colNum) { i, j -> get(i, j) }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts this vector to EJML one.
|
* Converts this vector to EJML one.
|
||||||
*/
|
*/
|
||||||
fun Point<Double>.toEjml(): EjmlVector =
|
public fun Point<Double>.toEjml(): EjmlVector =
|
||||||
if (this is EjmlVector) this else EjmlVector(SimpleMatrix(size, 1).also {
|
if (this is EjmlVector) this else EjmlVector(SimpleMatrix(size, 1).also {
|
||||||
(0 until it.numRows()).forEach { row -> it[row, 0] = get(row) }
|
(0 until it.numRows()).forEach { row -> it[row, 0] = get(row) }
|
||||||
})
|
})
|
||||||
@ -49,7 +49,7 @@ class EjmlMatrixContext(private val space: Space<Double>) : MatrixContext<Double
|
|||||||
|
|
||||||
override operator fun Matrix<Double>.times(value: Double): EjmlMatrix = EjmlMatrix(toEjml().origin.scale(value))
|
override operator fun Matrix<Double>.times(value: Double): EjmlMatrix = EjmlMatrix(toEjml().origin.scale(value))
|
||||||
|
|
||||||
companion object
|
public companion object
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -59,7 +59,7 @@ class EjmlMatrixContext(private val space: Space<Double>) : MatrixContext<Double
|
|||||||
* @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.
|
||||||
*/
|
*/
|
||||||
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))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -69,7 +69,7 @@ fun EjmlMatrixContext.solve(a: Matrix<Double>, b: Matrix<Double>): EjmlMatrix =
|
|||||||
* @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.
|
||||||
*/
|
*/
|
||||||
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))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -78,4 +78,4 @@ fun EjmlMatrixContext.solve(a: Matrix<Double>, b: Point<Double>): EjmlVector =
|
|||||||
* @param a the matrix.
|
* @param a the matrix.
|
||||||
* @return the inverse of this matrix.
|
* @return the inverse of this matrix.
|
||||||
*/
|
*/
|
||||||
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())
|
@ -1,8 +1,8 @@
|
|||||||
package scientifik.kmath.ejml
|
package kscience.kmath.ejml
|
||||||
|
|
||||||
import org.ejml.simple.SimpleMatrix
|
import org.ejml.simple.SimpleMatrix
|
||||||
import scientifik.kmath.linear.Point
|
import kscience.kmath.linear.Point
|
||||||
import scientifik.kmath.structures.Buffer
|
import kscience.kmath.structures.Buffer
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents point over EJML [SimpleMatrix].
|
* Represents point over EJML [SimpleMatrix].
|
Loading…
Reference in New Issue
Block a user