Skip to content

Commit 64e7198

Browse files
committed
Copy data only when necessary
1 parent b85806c commit 64e7198

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

mllib/src/main/scala/org/apache/spark/mllib/linalg/Vectors.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,12 @@ object Vectors {
136136
new DenseVector(v.toArray) // Can't use underlying array directly, so make a new one
137137
}
138138
case v: BSV[Double] =>
139-
new SparseVector(v.length, v.index.slice(0, v.used), v.data.slice(0, v.used))
139+
if (v.index.length == v.used) {
140+
new SparseVector(v.length, v.index, v.data)
141+
}
142+
else {
143+
new SparseVector(v.length, v.index.slice(0, v.used), v.data.slice(0, v.used))
144+
}
140145
case v: BV[_] =>
141146
sys.error("Unsupported Breeze vector type: " + v.getClass.getName)
142147
}

0 commit comments

Comments
 (0)