Search code examples
scalascala-breeze

Linear operations with slices in breeze


Is it somehow possible to slice updates on Matrices in breeze? I could not find implicit value for parameter op. Breeze 0.11.2.

val idxs = Seq(0,1)
val x = DenseMatrix.rand(3,3)
val y = DenseMatrix.rand(3,3)
x(idxs,idxs)+= y(idxs, idxs) // cant find implicit conversion for += here.

Analog code with DenseVectors works properly.

val xv = DenseVector.rand(3)
val yv = DenseVector.rand(3)
x(idxs) += y(idxs)

There is ugly work-around updating rows in iterative manner.

val idxs = IndexedSeq(0, 1)
val x:DenseMatrix[Double] = DenseMatrix.zeros(3, 3)
val y = DenseMatrix.rand(3, 3)
for(r<-idxs) {
  val slx = x(::, r)
  val sly = y(::, r)
  slx(idxs) += sly(idxs)
}

Solution

  • It's an oversight. Please open an issue on github.