diff --git a/kmath-ejml/src/jvmMain/kotlin/space/kscience/kmath/ejml/EjmlVector.kt b/kmath-ejml/src/jvmMain/kotlin/space/kscience/kmath/ejml/EjmlVector.kt index 82401ba05..4056d419b 100644 --- a/kmath-ejml/src/jvmMain/kotlin/space/kscience/kmath/ejml/EjmlVector.kt +++ b/kmath-ejml/src/jvmMain/kotlin/space/kscience/kmath/ejml/EjmlVector.kt @@ -18,7 +18,7 @@ import space.kscience.kmath.linear.Point */ public abstract class EjmlVector(public open val origin: M) : Point { override val size: Int - get() = origin.numCols + get() = origin.numRows override operator fun iterator(): Iterator = object : Iterator { private var cursor: Int = 0 diff --git a/kmath-ejml/src/jvmMain/kotlin/space/kscience/kmath/ejml/implementations.kt b/kmath-ejml/src/jvmMain/kotlin/space/kscience/kmath/ejml/implementations.kt index f831f495f..fa6db7817 100644 --- a/kmath-ejml/src/jvmMain/kotlin/space/kscience/kmath/ejml/implementations.kt +++ b/kmath-ejml/src/jvmMain/kotlin/space/kscience/kmath/ejml/implementations.kt @@ -45,11 +45,11 @@ public fun Complex_F64.toKMathComplex(): Complex = Complex(real, imaginary) */ 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" } + require(origin.numCols == 1) { "The origin matrix must have only one column to form a vector" } } - override operator fun get(index: Int): Double = origin[0, index] + override operator fun get(index: Int): Double = origin[index, 0] } /** @@ -57,10 +57,10 @@ public class EjmlDoubleVector(override val origin: M) : EjmlVec */ 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" } + require(origin.numCols == 1) { "The origin matrix must have only one column to form a vector" } } - override operator fun get(index: Int): Float = origin[0, index] + override operator fun get(index: Int): Float = origin[index, 0] } /** diff --git a/kmath-ejml/src/jvmTest/kotlin/space/kscience/kmath/ejml/EjmlVectorTest.kt b/kmath-ejml/src/jvmTest/kotlin/space/kscience/kmath/ejml/EjmlVectorTest.kt index cbc7f7c41..a19a3acc1 100644 --- a/kmath-ejml/src/jvmTest/kotlin/space/kscience/kmath/ejml/EjmlVectorTest.kt +++ b/kmath-ejml/src/jvmTest/kotlin/space/kscience/kmath/ejml/EjmlVectorTest.kt @@ -7,6 +7,9 @@ package space.kscience.kmath.ejml import org.ejml.data.DMatrixRMaj import org.ejml.dense.row.RandomMatrices_DDRM +import space.kscience.kmath.linear.invoke +import space.kscience.kmath.structures.asBuffer +import space.kscience.kmath.testutils.assertBufferEquals import kotlin.random.Random import kotlin.random.asJavaRandom import kotlin.test.Test @@ -54,4 +57,10 @@ internal class EjmlVectorTest { val w = EjmlDoubleVector(m) assertSame(m, w.origin) } + + @Test + fun unaryMinus() = EjmlLinearSpaceDDRM { + val mu = doubleArrayOf(1.0, 2.0, 3.0).asBuffer() + assertBufferEquals(mu, -(-mu)) + } }