Skip to content

Commit

Permalink
Added a comment about breeze lazy slicing
Browse files Browse the repository at this point in the history
  • Loading branch information
tomerk committed Nov 25, 2015
1 parent d9b013d commit 74ab533
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/main/scala/utils/MatrixUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ object MatrixUtils extends Serializable {
*/
def matrixToRowArray[T : ClassTag](mat: DenseMatrix[T]): Array[DenseVector[T]] = {
val matT = mat.t
// The explicit copy of the vector is necessary because otherwise Breeze slices
// lazily, leading to inflated serialization size (A serious issue w/ spark)
(0 until mat.rows).toArray.map(x => DenseVector(matT(::, x).toArray))
}

Expand All @@ -29,6 +31,8 @@ object MatrixUtils extends Serializable {
* @return Array of columns.
*/
def matrixToColArray[T : ClassTag](mat: DenseMatrix[T]): Array[DenseVector[T]] = {
// The explicit copy of the vector is necessary because otherwise Breeze slices
// lazily, leading to inflated serialization size (A serious issue w/ spark)
(0 until mat.cols).toArray.map(x => DenseVector(mat(::, x).toArray))
}

Expand Down

0 comments on commit 74ab533

Please sign in to comment.