srowen commented on a change in pull request #31394:
URL: https://github.com/apache/spark/pull/31394#discussion_r567869732



##########
File path: mllib/src/main/scala/org/apache/spark/ml/feature/MinHashLSH.scala
##########
@@ -109,9 +109,16 @@ class MinHashLSHModel private[ml](
   override protected[ml] def hashDistance(x: Seq[Vector], y: Seq[Vector]): 
Double = {
     // Since it's generated by hashing, it will be a pair of dense vectors.
     // TODO: This hashDistance function requires more discussion in SPARK-18454
-    x.iterator.zip(y.iterator).map(vectorPair =>
-      vectorPair._1.toArray.zip(vectorPair._2.toArray).count(pair => pair._1 
!= pair._2)
-    ).min
+    // Currently each hash vector (generated by hashFunction) only has one 
element, this equals to:
+    // x.iterator.zip(y.iterator).map(vectorPair =>
+    //   vectorPair._1.toArray.zip(vectorPair._2.toArray).count(pair => 
pair._1 != pair._2)
+    // ).min
+    val iter = x.iterator.zip(y.iterator)
+    while (iter.hasNext) {
+      val (vx, vy) = iter.next
+      if (vx(0) == vy(0)) return 0.0
+    }
+    1.0

Review comment:
       Remind me why this must be the min if no elements match?

##########
File path: 
mllib/src/main/scala/org/apache/spark/ml/feature/BucketedRandomProjectionLSH.scala
##########
@@ -97,7 +97,19 @@ class BucketedRandomProjectionLSHModel private[ml](
   @Since("2.1.0")
   override protected[ml] def hashDistance(x: Seq[Vector], y: Seq[Vector]): 
Double = {
     // Since it's generated by hashing, it will be a pair of dense vectors.
-    x.zip(y).map(vectorPair => Vectors.sqdist(vectorPair._1, 
vectorPair._2)).min
+    // Currently each hash vector (generated by hashFunction) only has one 
element, this equals to:

Review comment:
       Is this true? can't you have multiple hash functions? but the 
optimization would be OK even if not, I believe.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to