You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by gglanzani <gi...@git.apache.org> on 2017/05/12 20:19:59 UTC

[GitHub] spark pull request #17968: [SPARK-9792] Make DenseMatrix equality semantical

GitHub user gglanzani opened a pull request:

    https://github.com/apache/spark/pull/17968

    [SPARK-9792] Make DenseMatrix equality semantical

    Before, you could have this code
    
    ```
    A = SparseMatrix(2, 2, [0, 2, 3], [0], [2])
    B = DenseMatrix(2, 2, [2, 0, 0, 0])
    
    B == A  # False
    A == B  # True
    ```
    
    The second would be `True` as `SparseMatrix` already checks for semantic
    equality. This commit changes `DenseMatrix` so that equality is
    semantical as well.
    
    ## What changes were proposed in this pull request?
    
    Better semantic equality for DenseMatrix
    
    ## How was this patch tested?
    
    Unit tests were added, plus manual testing. Note that the code falls back to the old behavior when `other` is not a SparseMatrix.

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/gglanzani/spark SPARK-9792

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/spark/pull/17968.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #17968
    
----
commit 4c4d1c15eb4224444f9df703851c417881f9a464
Author: Giovanni Lanzani <gi...@lanzani.nl>
Date:   2017-05-12T20:15:04Z

    [SPARK-9792] Make DenseMatrix equality semantical
    
    Before, you could have this code
    
    ```
    A = SparseMatrix(2, 2, [0, 2, 3], [0], [2])
    B = DenseMatrix(2, 2, [2, 0, 0, 0])
    
    B == A  # False
    A == B  # True
    ```
    
    The second would be `True` as `SparseMatrix` already checks for semantic
    equality. This commit changes `DenseMatrix` so that equality is
    semantical as well.

----


---
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


[GitHub] spark issue #17968: [SPARK-9792] Make DenseMatrix equality semantical

Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on the issue:

    https://github.com/apache/spark/pull/17968
  
    ok to test


---

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


[GitHub] spark issue #17968: [SPARK-9792] Make DenseMatrix equality semantical

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/17968
  
    Can one of the admins verify this patch?


---

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


[GitHub] spark issue #17968: [SPARK-9792] Make DenseMatrix equality semantical

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/17968
  
    **[Test build #85738 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/85738/testReport)** for PR 17968 at commit [`311c94a`](https://github.com/apache/spark/commit/311c94a3d608b0b86f3ce39415639ec260e5af37).
     * This patch passes all tests.
     * This patch merges cleanly.
     * This patch adds no public classes.


---

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


[GitHub] spark issue #17968: [SPARK-9792] Make DenseMatrix equality semantical

Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on the issue:

    https://github.com/apache/spark/pull/17968
  
    cc @WeichenXu123 @yanboliang 


---

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


[GitHub] spark pull request #17968: [SPARK-9792] Make DenseMatrix equality semantical

Posted by WeichenXu123 <gi...@git.apache.org>.
Github user WeichenXu123 commented on a diff in the pull request:

    https://github.com/apache/spark/pull/17968#discussion_r143656820
  
    --- Diff: python/pyspark/mllib/linalg/__init__.py ---
    @@ -1131,14 +1131,20 @@ def __getitem__(self, indices):
                 return self.values[i + j * self.numRows]
     
         def __eq__(self, other):
    +        def _eq(self, other):
    --- End diff --
    
    Ditto.


---

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


[GitHub] spark issue #17968: [SPARK-9792] Make DenseMatrix equality semantical

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/17968
  
    Can one of the admins verify this patch?


---

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


[GitHub] spark pull request #17968: [SPARK-9792] Make DenseMatrix equality semantical

Posted by WeichenXu123 <gi...@git.apache.org>.
Github user WeichenXu123 commented on a diff in the pull request:

    https://github.com/apache/spark/pull/17968#discussion_r143656736
  
    --- Diff: python/pyspark/ml/linalg/__init__.py ---
    @@ -976,14 +976,20 @@ def __getitem__(self, indices):
                 return self.values[i + j * self.numRows]
     
         def __eq__(self, other):
    +        def _eq(self, other):
    --- End diff --
    
    Now `_eq` won't be called in multiple places, we can remove the `_eq` definition, make code simpler.


---

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


[GitHub] spark pull request #17968: [SPARK-9792] Make DenseMatrix equality semantical

Posted by WeichenXu123 <gi...@git.apache.org>.
Github user WeichenXu123 commented on a diff in the pull request:

    https://github.com/apache/spark/pull/17968#discussion_r143702830
  
    --- Diff: python/pyspark/ml/linalg/__init__.py ---
    @@ -976,14 +976,18 @@ def __getitem__(self, indices):
                 return self.values[i + j * self.numRows]
     
         def __eq__(self, other):
    +
    +        if isinstance(other, SparseMatrix):
    +            return np.all(self.toArray() == other.toArray())
             if (not isinstance(other, DenseMatrix) or
    --- End diff --
    
    The condition not `isinstance(other, DenseMatrix)` is useless. remove it.


---

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


[GitHub] spark issue #17968: [SPARK-9792] Make DenseMatrix equality semantical

Posted by WeichenXu123 <gi...@git.apache.org>.
Github user WeichenXu123 commented on the issue:

    https://github.com/apache/spark/pull/17968
  
    ping @gglanzani This bug need fixed ASAP. Can you update code when you're free ? Thanks.


---

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


[GitHub] spark issue #17968: [SPARK-9792] Make DenseMatrix equality semantical

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/17968
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/85738/
    Test PASSed.


---

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


[GitHub] spark pull request #17968: [SPARK-9792] Make DenseMatrix equality semantical

Posted by WeichenXu123 <gi...@git.apache.org>.
Github user WeichenXu123 commented on a diff in the pull request:

    https://github.com/apache/spark/pull/17968#discussion_r143465176
  
    --- Diff: python/pyspark/mllib/linalg/__init__.py ---
    @@ -1131,14 +1131,21 @@ def __getitem__(self, indices):
                 return self.values[i + j * self.numRows]
     
         def __eq__(self, other):
    +        def _eq(self, other):
    +            self_values = np.ravel(self.toArray(), order='F')
    +            other_values = np.ravel(other.toArray(), order='F')
    +
    +            return np.all(self_values == other_values)
    +
    +        if isinstance(other, SparseMatrix):
    +            return _eq(self, other)
    --- End diff --
    
    This implementation is incorrect here I think.
    You flatten 2D-arrays for both side, and then compare the two flattened array. it will result in `M*N` matrix equals `N*M` matrix when their values are the same.
    
    So you need move the judgement of
    ```
    if  (self.numRows != other.numRows or		                  
          self.numCols != other.numCols):
         return False
    ```
    into front.
    Thanks!


---

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


[GitHub] spark issue #17968: [SPARK-9792] Make DenseMatrix equality semantical

Posted by gglanzani <gi...@git.apache.org>.
Github user gglanzani commented on the issue:

    https://github.com/apache/spark/pull/17968
  
    @WeichenXu123 Done again!


---

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


[GitHub] spark issue #17968: [SPARK-9792] Make DenseMatrix equality semantical

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/17968
  
    Merged build finished. Test PASSed.


---

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


[GitHub] spark issue #17968: [SPARK-9792] Make DenseMatrix equality semantical

Posted by WeichenXu123 <gi...@git.apache.org>.
Github user WeichenXu123 commented on the issue:

    https://github.com/apache/spark/pull/17968
  
    @gglanzani And you the `ml.linalg.DenseMatrix` looks have the same bug. Can you also update it ?


---

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


[GitHub] spark issue #17968: [SPARK-9792] Make DenseMatrix equality semantical

Posted by WeichenXu123 <gi...@git.apache.org>.
Github user WeichenXu123 commented on the issue:

    https://github.com/apache/spark/pull/17968
  
    @gatorsmile Add this to white list!


---

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


[GitHub] spark issue #17968: [SPARK-9792] Make DenseMatrix equality semantical

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/17968
  
    Can one of the admins verify this patch?


---

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


[GitHub] spark pull request #17968: [SPARK-9792] Make DenseMatrix equality semantical

Posted by WeichenXu123 <gi...@git.apache.org>.
Github user WeichenXu123 commented on a diff in the pull request:

    https://github.com/apache/spark/pull/17968#discussion_r143702719
  
    --- Diff: python/pyspark/mllib/linalg/__init__.py ---
    @@ -1131,14 +1131,17 @@ def __getitem__(self, indices):
                 return self.values[i + j * self.numRows]
     
         def __eq__(self, other):
    +        if isinstance(other, SparseMatrix):
    +            return np.all(self.toArray() == other.toArray())
             if (not isinstance(other, DenseMatrix) or
    --- End diff --
    
    ditto.


---

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


[GitHub] spark issue #17968: [SPARK-9792] Make DenseMatrix equality semantical

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/17968
  
    Can one of the admins verify this patch?


---
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


[GitHub] spark issue #17968: [SPARK-9792] Make DenseMatrix equality semantical

Posted by gglanzani <gi...@git.apache.org>.
Github user gglanzani commented on the issue:

    https://github.com/apache/spark/pull/17968
  
    @WeichenXu123 Done. Let me know.


---

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


[GitHub] spark issue #17968: [SPARK-9792] Make DenseMatrix equality semantical

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/17968
  
    **[Test build #85738 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/85738/testReport)** for PR 17968 at commit [`311c94a`](https://github.com/apache/spark/commit/311c94a3d608b0b86f3ce39415639ec260e5af37).


---

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