kyonifer / koma

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

.setCol unexpected behavior #46

Open RatsRatsRats opened 6 years ago

RatsRatsRats commented 6 years ago

You can set columns (and I'd guess rows, I haven't checked) with an arbitrary Matrix that has fewer than the expected number of elements in the dimension to be set, and the fill data is taken from the rows of the matrix passed in up to the number of cols available:

val m = zeros(3, 2)
val fillVal = ones(2, 1000).fill{r, c -> c + 1.0} // 2 x 2 works also
m.setCol(0, fillVal) 
// The transpose still fails on size check
// m.setCol(0, fillVal.T) 

// Now m.getCol(0) returns
mat[ 1.00 end
     2.00 end
     0.00 ]
kyonifer commented 6 years ago

Thanks for the report. I agree this is awkward behavior.

So this is actually the result of behavior of the delegating backends in some cases, for example jblas's implementation calls into blas and does the same raw memory copy without access check.

The options here then are:

  1. Don't use the backend functions and instead use our base class implementation
  2. Add extra dimension checks to every call right before we call the backend function

Realistically I don't think calling to the backend is going to significantly improve performance for this op.