scalanlp / breeze

Breeze is/was a numerical processing library for Scala.
https://www.scalanlp.org
Apache License 2.0
3.45k stars 692 forks source link

DenseVector slice seems not conform with new DenseVector with offset and stride #723

Closed yiyezhiqiu233 closed 3 years ago

yiyezhiqiu233 commented 6 years ago

The behaviors of DenseVector.slice and new DenseVector seems different: slice an array (0,15) into 4 slices

val array=Array.range(0,16)
val dv = new DenseVector[Int](array)

1.slice using new DenseVector

   for (i <- 0 until 4) {
      System.out.println(new DenseVector[Int](array, i, 4, 4))
    }

and got

DenseVector(0, 4, 8, 12)
DenseVector(1, 5, 9, 13)
DenseVector(2, 6, 10, 14)
DenseVector(3, 7, 11, 15)

2.slice using DenseVector.slice

   for (i <- 0 until 4) {
      System.out.println(dv.slice(i, dv.length, 4))
    }

but got

DenseVector(0, 4, 8, 12)
DenseVector(1, 5, 9)
DenseVector(2, 6, 10)
DenseVector(3, 7, 11)