spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From srowen <...@git.apache.org>
Subject [GitHub] spark pull request: [SPARK-5186] [MLLIB] Vector.equals and Vector....
Date Sun, 18 Jan 2015 19:22:11 GMT
Github user srowen commented on a diff in the pull request:

    https://github.com/apache/spark/pull/3997#discussion_r23136064
  
    --- Diff: mllib/src/main/scala/org/apache/spark/mllib/linalg/Vectors.scala ---
    @@ -51,13 +51,35 @@ sealed trait Vector extends Serializable {
     
       override def equals(other: Any): Boolean = {
         other match {
    -      case v: Vector =>
    -        util.Arrays.equals(this.toArray, v.toArray)
    +      case v2: Vector => {
    +        if (this.size != v2.size) return false
    +        (this, v2) match {
    +          case (s1: SparseVector, s2: SparseVector) =>
    +            Vectors.getEquality(s1.indices, s1.values, s2.indices, s2.values)
    +          case (s1: SparseVector, d1: DenseVector) =>
    +            Vectors.getEquality(s1.indices, s1.values, 0 until d1.size, d1.values)
    +          case (d1: DenseVector, s1: SparseVector) =>
    +            Vectors.getEquality(0 until d1.size, d1.values, s1.indices, s1.values)
    +          case (_, _) => util.Arrays.equals(this.toArray, v2.toArray)
    --- End diff --
    
    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.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Mime
View raw message