Skip to content

Conversation

oscargus
Copy link
Contributor

@oscargus oscargus commented Jul 5, 2022

References to other Issues or PRs

A small step towards #23609 for matrices.

Brief description of what is fixed or changed

Other comments

I should add some tests.

Release Notes

  • matrices
    • Better support for computing adjoint, re, and im for Identity, OneMatrix, and ZeroMatrix.

@sympy-bot
Copy link

sympy-bot commented Jul 5, 2022

Hi, I am the SymPy bot (v167). 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
    • Better support for computing adjoint, re, and im for Identity, OneMatrix, and ZeroMatrix. (#23724 by @oscargus)

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

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

A small step towards #23609 for matrices.

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


#### Other comments

I should add some tests.

#### Release Notes

<!-- Write the release notes for this release below between the BEGIN and END
statements. The basic format is a bulleted list with the name of the subpackage
and the release note for this PR. For example:

* solvers
  * Added a new solver for logarithmic equations.

* functions
  * Fixed a bug with log of integers.

or if no release note(s) should be included use:

NO ENTRY

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
   * Better support for computing `adjoint`, `re`, and `im` for `Identity`, `OneMatrix`, and `ZeroMatrix`.
<!-- END RELEASE NOTES -->

Update

The release notes on the wiki have been updated.

@github-actions
Copy link

github-actions bot commented Jul 5, 2022

Benchmark results from GitHub Actions

Lower numbers are good, higher numbers are bad. A ratio less than 1
means a speed up and greater than 1 means a slowdown. Green lines
beginning with + are slowdowns (the PR is slower then master or
master is slower than the previous release). Red lines beginning
with - are speedups.

Significantly changed benchmark results (PR vs master)

Significantly changed benchmark results (master vs previous release)

       before           after         ratio
     [77f1d79c]       [edf24253]
     <sympy-1.10.1^0>                 
+      99.3±0.8ms        180±0.5ms     1.81  sum.TimeSum.time_doit

Full benchmark results can be found as artifacts in GitHub Actions
(click on checks at the top of the PR).

@@ -179,6 +179,9 @@ def _eval_conjugate(self):
return Adjoint(Transpose(self))

def as_real_imag(self, deep=True, **hints):
return self._eval_as_real_imag()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't this method be deleted?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, not yet. As _eval_as_real_imag is not really supported, except for here. But it will simplify things once we support it throughout the code base.

@asmeurer
Copy link
Member

asmeurer commented Jul 5, 2022

Interesting that the matrices already use _eval_as_real_imag, although it looks like the current implementation in master is wrong (see the XXX comment in common.py).

We might want to figure out for #23609 in general how we want to handle deprecation. It's hard to just switch from method to _eval_method because user subclasses that redefine method will break, because it will use that version instead of the base class version that calls _eval_method.

So we need to either deprecate redefining method, or else somehow make it so it still works. But I'm not sure if that's possible. I'm not even sure if we can issue a warning for redefining method, unless we put some logic in the metaclass.

@oscargus
Copy link
Contributor Author

oscargus commented Jul 6, 2022

Interesting that the matrices already use _eval_as_real_imag, although it looks like the current implementation in master is wrong (see the XXX comment in common.py).

Indeed! I was a bit confused about the status at first... Yes, I noted the comment but though that I take the simple way out for now and do not touch anything else.

We might want to figure out for #23609 in general how we want to handle deprecation. It's hard to just switch from method to _eval_method because user subclasses that redefine method will break, because it will use that version instead of the base class version that calls _eval_method.

I guess that ideally, it shouldn't break anything but I can see many cases where it indeed may do it.

This is really a case where it would be nice to have code coverage... Right now, I modify things and hope that they are tested so that I do not break anything...

@oscargus oscargus force-pushed the matrixfixes branch 4 times, most recently from ae1ee25 to 14cd895 Compare July 10, 2022 14:38
@oscargus
Copy link
Contributor Author

I'd be a bit tempted to get this in 1.11 as well... But feel free to remove.

@oscargus oscargus added this to the SymPy 1.11 milestone Jul 12, 2022
@oscargus
Copy link
Contributor Author

The benefit is that in the added test, in current master e.g. re(X) becomes
image

while here it becomes
image

So basically more things involving re, im and adjoint evaluates to something more sensible.

@oscarbenjamin
Copy link
Collaborator

Looks good.

@oscarbenjamin oscarbenjamin merged commit 0bfd0c8 into sympy:master Jul 12, 2022
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.

4 participants