Skip to content

Comparing matrix with object #20175

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

Merged
merged 8 commits into from
Oct 24, 2020
Merged

Comparing matrix with object #20175

merged 8 commits into from
Oct 24, 2020

Conversation

sidhu1012
Copy link
Contributor

References to other Issues or PRs

Fixes #19361

Brief description of what is fixed or changed

Corrected eq() of Matrix

Other comments

Release Notes

  • matrices
    - Changed behaviour of eq() of class DenseMatrix

@sympy-bot
Copy link

sympy-bot commented Oct 1, 2020

Hi, I am the SymPy bot (v161). I'm here to help you write a release notes entry. Please read the guide on how to write release notes.

Your release notes are in good order.

Here is what the release notes will look like:

  • matrices

This will be added to https://github.com/sympy/sympy/wiki/Release-Notes-for-1.8.

Click here to see the pull request description that was parsed.
<!-- Your title above should be a short description of what
was changed. Do not include the issue number in the title. -->

#### References to other Issues or PRs
<!-- If this pull request fixes an issue, write "Fixes #NNNN" in that exact
format, e.g. "Fixes #1234" (see
https://tinyurl.com/auto-closing for more information). Also, please
write a comment on that issue linking back to this pull request once it is
open. -->
Fixes #19361

#### Brief description of what is fixed or changed
Corrected __eq__() of Matrix

#### Other comments


#### Release Notes

<!-- Write the release notes for this release below. See
https://github.com/sympy/sympy/wiki/Writing-Release-Notes for more information
on how to write release notes. The bot will check your release notes
automatically to see if they are formatted correctly. -->

<!-- BEGIN RELEASE NOTES -->
- matrices
       -  Changed behaviour of __eq__() of class DenseMatrix
<!-- END RELEASE NOTES -->

Update

The release notes on the wiki have been updated.

@sidhu1012
Copy link
Contributor Author

@oscarbenjamin Does it seems right?

@codecov
Copy link

codecov bot commented Oct 1, 2020

Codecov Report

Merging #20175 into master will decrease coverage by 0.080%.
The diff coverage is 80.000%.

@@              Coverage Diff              @@
##            master    #20175       +/-   ##
=============================================
- Coverage   75.855%   75.775%   -0.081%     
=============================================
  Files          671       674        +3     
  Lines       173793    174226      +433     
  Branches     41047     41117       +70     
=============================================
+ Hits        131832    132020      +188     
- Misses       36206     36485      +279     
+ Partials      5755      5721       -34     

@friyaz friyaz added the matrices label Oct 1, 2020
@friyaz
Copy link
Member

friyaz commented Oct 1, 2020

Always add test cases that will fail without the changes you make. This ensures that the problem does not occur in the future.

@oscarbenjamin
Copy link
Collaborator

There is a decorator sympify_return for sympifying arguments or returning NotImplemented. It is used in sympy/core/expr.py.

@sidhu1012
Copy link
Contributor Author

Always add test cases that will fail without the changes you make. This ensures that the problem does not occur in the future.

Done

@sidhu1012
Copy link
Contributor Author

There is a decorator sympify_return for sympifying arguments or returning NotImplemented. It is used in sympy/core/expr.py.

Used it , decorator really easied it.

@sidhu1012
Copy link
Contributor Author

@oscarbenjamin pls review

@sidhu1012
Copy link
Contributor Author

@friyaz Removed comments. Does everything else seems fine?

@friyaz
Copy link
Member

friyaz commented Oct 2, 2020

Looks good to me.

@sidhu1012
Copy link
Contributor Author

There is a decorator sympify_return for sympifying arguments or returning NotImplemented. It is used in sympy/core/expr.py.

@oscarbenjamin @friyaz dont think using decorator is a good way because it is making other test fail

@sidhu1012
Copy link
Contributor Author

sidhu1012 commented Oct 2, 2020

@oscarbenjamin @friyaz I dont think using decorator is a good way because it is making other test fail.
Is something missing in this PR or PR's first commit(ad3fa07) is a better solve for this.

@sidhu1012
Copy link
Contributor Author

sidhu1012 commented Oct 3, 2020

@oscarbenjamin @friyaz So shall I drop the decorator and use the method of 1st commit?

@sidhu1012
Copy link
Contributor Author

This way is better as it doesn't break anything. Decorator breaks the code

@sidhu1012
Copy link
Contributor Author

@oscarbenjamin Does it seems right now??

@oscarbenjamin
Copy link
Collaborator

Why didn't the decorator work?

@sidhu1012
Copy link
Contributor Author

Why didn't the decorator work?

Decorator broke the code , and gave way too many failures

@oscarbenjamin
Copy link
Collaborator

Can you give an example of something that didn't work?

@sidhu1012
Copy link
Contributor Author

Can you give an example of something that didn't work?

https://travis-ci.org/github/sympy/sympy/builds/732235398

See the build at travis , all 4 test failed, test files and doc tests.

@sidhu1012
Copy link
Contributor Author

@oscarbenjamin Is it good without decorator?

@oscarbenjamin
Copy link
Collaborator

Yes, it should be fine but we should check why it didn't work with the decorator. Maybe the decorator can be improved or maybe it's just not suitable for this. Without investigating the failures we won't know.

@sidhu1012
Copy link
Contributor Author

Yes, it should be fine but we should check why it didn't work with the decorator. Maybe the decorator can be improved or maybe it's just not suitable for this. Without investigating the failures we won't know.

Okay , i'll look into it as much as I can

@sidhu1012
Copy link
Contributor Author

or maybe it's just not suitable for this.

The number of test failures suggest decorator isn't suitable for this. Because the number of failures are really high and are in almost every module

@sidhu1012
Copy link
Contributor Author

@oscarbenjamin What do you say? Is is good to go?

@oscarbenjamin
Copy link
Collaborator

Why doesn't the decorator work?

The error from the test logs is

    if not isinstance(other, expectedcls):
TypeError: isinstance() arg 2 must be a type or tuple of types

That suggests that the decorator wasn't used correctly.

@sidhu1012
Copy link
Contributor Author

I'll give it another try

@sidhu1012
Copy link
Contributor Author

@oscarbenjamin Is it good to go now??

def __eq__(self, other):
other = sympify(other)
self_shape = getattr(self, 'shape', None)
other_shape = getattr(other, 'shape', None)
if None in (self_shape, other_shape):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The conditions below suggest that sometimes other is not a DenseMatrix. Is that not ever the case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works for all cases .

@sidhu1012
Copy link
Contributor Author

@oscarbenjamin I have checked and updates test file with other Matrix types also. It works as expected.

@sidhu1012
Copy link
Contributor Author

sidhu1012 commented Oct 10, 2020

@oscarbenjamin Please review.

@sidhu1012
Copy link
Contributor Author

sidhu1012 commented Oct 11, 2020

Since @oscarbenjamin is busy with 1.7 update. Can someone else review please.I think it is good to go.

@sidhu1012
Copy link
Contributor Author

Can someone please review

@friyaz friyaz requested a review from sylee957 October 11, 2020 18:56
@sidhu1012
Copy link
Contributor Author

@sylee957 Please review.

@sidhu1012
Copy link
Contributor Author

Since no one is reviewing, @oscarbenjamin please review it when free

@sidhu1012
Copy link
Contributor Author

Can someone please review this PR.

class DenseMatrix(MatrixBase):

is_MatrixExpr = False # type: bool

_op_priority = 10.01
_class_priority = 4

@sympify_return([('other', 'DenseMatrix')], NotImplemented)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we add this to SparseMatrix such that it can be symmetric change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay , would do that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The decorator can be used when sympifying code, since the SparseMatrix isn't sympifying , it shouldn't be added in SparseMatrix

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather change that SparseMatrix to sympify the arguments before calls
It is problematic if operations supported in DenseMatrix is not supported by SparseMatrix only because of sympify
For example,

from sympy import *
import mpmath

m = mpmath.matrix([[1, 2], [3, 4]])
Matrix([[1, 2], [3, 4]]) == m # True
SparseMatrix([[1, 2], [3, 4]]) == m # False

@sidhu1012
Copy link
Contributor Author

sidhu1012 commented Oct 19, 2020

@sylee957 @oscarbenjamin I have removed the decorator and used _sympify instead .
@oscarbenjamin was right #20175 (comment) , the decorator would make Dense Matrix == Dense only and same goes to sparse, earlier it was working because changes weren't symmetric.

@sidhu1012 sidhu1012 closed this Oct 20, 2020
@sidhu1012 sidhu1012 reopened this Oct 20, 2020
@sidhu1012 sidhu1012 closed this Oct 20, 2020
@sidhu1012 sidhu1012 reopened this Oct 20, 2020
@oscarbenjamin
Copy link
Collaborator

@sidhu1012 we are having problems with CI (#20289). The tests are unlikely to pass for these PRs until that is resolved. I cancelled the previous run of the tests because because they were slowing down the tests for #20297

@sidhu1012
Copy link
Contributor Author

@oscarbenjamin Okay , please review this PR though

@sidhu1012
Copy link
Contributor Author

@oscarbenjamin @sylee957 Please review

@sylee957 sylee957 merged commit 5b2eabb into sympy:master Oct 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Comparing Matrix with object() raises
5 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy