Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fix of sparse vector conversion #661

Closed
wants to merge 5 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ object Vectors {
new DenseVector(v.toArray) // Can't use underlying array directly, so make a new one
}
case v: BSV[Double] =>
new SparseVector(v.length, v.index, v.data)
new SparseVector(v.length, v.index.slice(0, v.used), v.data.slice(0, v.used))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

slice allocates a new array even when v.used == v.index.length. Could you check v.used == v.index.length first?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense. And I just found that it failed the test "Should not copy data". SparseVector from VectorBuilder has this problem of size inconsistency. It uses a dynamic growing approach to resize the index/data array and fills the unused slot zeros. So I think there is no way to completely avoid new allocation.

case v: BV[_] =>
sys.error("Unsupported Breeze vector type: " + v.getClass.getName)
}
Expand Down