spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From srowen <>
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:
    --- 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 or file a JIRA ticket
with INFRA.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message