kyonifer / koma

A scientific computing library for Kotlin. https://kyonifer.github.io/koma
Other
270 stars 23 forks source link

Inconsistent bounds checking errors on slice assignment #65

Open drmoose opened 5 years ago

drmoose commented 5 years ago

Say I have a 4x4 matrix called x:

val x = zeros(4, 4)

If I try to populate a column with a vector oriented the wrong way, I expect an IndexOutOfBoundsException but I get an IllegalArgumentException :

>>> x[0..end, 1] = mat[1, 2, 3, 4]
java.lang.IllegalArgumentException: Specified element is out of bounds: 1 0
    at org.ejml.data.DMatrixRMaj.get(DMatrixRMaj.java:262)
    at org.ejml.simple.SimpleBase.get(SimpleBase.java:654)
    at koma.matrix.ejml.EJMLMatrix.getDouble(EJMLMatrix.kt:43)
    at koma.extensions.MatrixExtensions__Extensions_matrix_DoubleKt.get(extensions_matrix_Double.kt:152)
    at koma.extensions.MatrixExtensions.get(Unknown Source)
    at koma.extensions.MatrixExtensions__Extensions_matrix_DoubleKt.setRangesDouble(extensions_matrix_Double.kt:224)
    at koma.extensions.MatrixExtensions.setRangesDouble(Unknown Source)
    at koma.extensions.MatrixExtensions__Extensions_matrix_DoubleKt.setRowRangeDouble(extensions_matrix_Double.kt:269)
    at koma.extensions.MatrixExtensions.setRowRangeDouble(Unknown Source)

Even worse, if I provide more data than is needed to fill the space in the correct direction, there is no error, allowing me to write this off-by-one code by accident:

>>> x[0 until end, 1] = mat[1,2,3,4].T
>>> x
mat[ 0.00,  1.00,  0.00,  0.00 end
     0.00,  2.00,  0.00,  0.00 end
     0.00,  3.00,  0.00,  0.00 end
     0.00,  0.00,  0.00,  0.00 ]