Skip to content
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

Fix Attribute error in matrix and polynomial multiplication #18159

Merged
merged 7 commits into from
Dec 30, 2019

Conversation

Smit-create
Copy link
Member

Fix Attribute error in matrix and polynomial multiplication

References to other Issues or PRs

Fixes #17988

Brief description of what is fixed or changed

Other comments

Release Notes

  • polys
    • Changes in Poly.__new__() to make it handle simplified Matrix

@sympy-bot
Copy link

sympy-bot commented Dec 28, 2019

Hi, I am the SymPy bot (v149). 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:

  • polys

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

Note: This comment will be updated with the latest check if you edit the pull request. You need to reload the page to see it.

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. -->
Fix Attribute error in matrix and polynomial multiplication
#### 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://github.com/blog/1506-closing-issues-via-pull-requests . Please also
write a comment on that issue linking back to this pull request once it is
open. -->
Fixes #17988

#### Brief description of what is fixed or changed


#### 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 -->
* polys
  * Changes in `Poly.__new__()` to make it handle simplified Matrix
<!-- END RELEASE NOTES -->

Update

The release notes on the wiki have been updated.

@jksuom
Copy link
Member

jksuom commented Dec 29, 2019

It looks like changing _sympify_it may create errors. Perhaps this would work: No change in decorators but a direct check in Poly.__mul__ as follows

--- a/sympy/polys/polytools.py
+++ b/sympy/polys/polytools.py
@@ -4037,6 +4037,8 @@ def __rsub__(f, g):
 
     @_sympifyit('g', NotImplemented)
     def __mul__(f, g):
+        if not isinstance(g, Expr):
+            return NotImplemented
         if not g.is_Poly:
             try:
                 g = f.__class__(g, *f.gens)
            except PolynomialError:
                return f.as_expr()*g

That should not raise new errors. I think that the changes in Poly.__new__ are good and should be preserved.

@codecov
Copy link

codecov bot commented Dec 29, 2019

Codecov Report

Merging #18159 into master will decrease coverage by 0.029%.
The diff coverage is 100%.

@@             Coverage Diff              @@
##            master    #18159      +/-   ##
============================================
- Coverage   74.953%   74.924%   -0.03%     
============================================
  Files          642       642              
  Lines       166973    166978       +5     
  Branches     39283     39285       +2     
============================================
- Hits        125152    125107      -45     
- Misses       36300     36338      +38     
- Partials      5521      5533      +12

@Smit-create
Copy link
Member Author

It looks like changing _sympify_it may create errors. Perhaps this would work: No change in decorators but a direct check in Poly.__mul__ as follows

--- a/sympy/polys/polytools.py
+++ b/sympy/polys/polytools.py
@@ -4037,6 +4037,8 @@ def __rsub__(f, g):
 
     @_sympifyit('g', NotImplemented)
     def __mul__(f, g):
+        if not isinstance(g, Expr):
+            return NotImplemented
         if not g.is_Poly:
             try:
                 g = f.__class__(g, *f.gens)
            except PolynomialError:
                return f.as_expr()*g

That should not raise new errors. I think that the changes in Poly.__new__ are good and should be preserved.

Yes, It worked. Thanks for your help and reviewing it.

@jksuom
Copy link
Member

jksuom commented Dec 30, 2019

Thanks for your contribution.

@jksuom jksuom merged commit f927ca6 into sympy:master Dec 30, 2019
@Smit-create Smit-create deleted the 17988 branch January 3, 2020 06:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unexpected AttributeError when multiplying a matrix with a polynomial
4 participants