-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-5186] [MLLIB] Vector.equals and Vector.hashCode are very inefficient #3997
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
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5741144
Specialized equals for SparseVector
f41b135
iterative equals for sparse vector
hhbyyh 50abef3
fix ut for sparse vector with explicit 0
hhbyyh a6952c3
fix scala style for comments
hhbyyh bdf8789
improve equals and rewrite hashCode for Vector
hhbyyh 985e160
improve locality for equals
hhbyyh 93f0d46
unify sparse vs dense vectors
hhbyyh 0d9d130
function name change and ut update
hhbyyh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -89,6 +89,24 @@ class VectorsSuite extends FunSuite { | |
| } | ||
| } | ||
|
|
||
| test("vectors equals with explicit 0") { | ||
| val dv1 = Vectors.dense(Array(0, 0.9, 0, 0.8, 0)) | ||
| val sv1 = Vectors.sparse(5, Array(1, 3), Array(0.9, 0.8)) | ||
| val sv2 = Vectors.sparse(5, Array(0, 1, 2, 3, 4), Array(0, 0.9, 0, 0.8, 0)) | ||
|
|
||
| val vectors = Seq(dv1, sv1, sv2) | ||
| for (v <- vectors; u <- vectors) { | ||
| assert(v === u) | ||
| assert(v.## === u.##) | ||
| } | ||
|
|
||
| val another = Vectors.sparse(5, Array(0, 1, 3), Array(0, 0.9, 0.2)) | ||
| for (v <- vectors) { | ||
| assert(v != another) | ||
| assert(v.## != another.##) | ||
| } | ||
| } | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This still needs tests involving dense vectors right?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure. I'll add some. |
||
| test("indexing dense vectors") { | ||
| val vec = Vectors.dense(1.0, 2.0, 3.0, 4.0) | ||
| assert(vec(0) === 1.0) | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah looking good. I have only minor things to say, which don't necessarily need to change. For example the utility method could be called
Vectors.equals. Should there even be a catch-all case? I wonder if failing fast is good, if no other implementations are expected now.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for review, @srowen
Yes, I can change the name. Just like the name in
util.Arrays.equals.And for the catch-all case, I was thinking
util.Arrays.equalsis also fail-fast and it can cover the dense vs dense case well, and with some extensiblity. Maybe I don't catch your point. Let me know if still we should change this. Thanks