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

Implemented Givens rotation #24535

Merged
merged 18 commits into from
Jan 18, 2023
Merged

Implemented Givens rotation #24535

merged 18 commits into from
Jan 18, 2023

Conversation

evbernardes
Copy link
Contributor

@evbernardes evbernardes commented Jan 16, 2023

References to other Issues or PRs

As discussed in #24529.

Brief description of what is fixed or changed

Implemented a method giving the Givens rotation, a generalization of rotation matrices in any number of dimensions.

Replace implementation in other rotation matrix methods by calls to this generalized function.

Release Notes

  • matrices
    • Implemented rot_givens to compute givens rotation matrix.

@sympy-bot
Copy link

sympy-bot commented Jan 16, 2023

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

Click here to see the pull request description that was parsed.
#### References to other Issues or PRs
As discussed in #24529.

#### Brief description of what is fixed or changed
Implemented a method giving the Givens rotation, a generalization of rotation matrices in any number of dimensions.

Replace implementation in other rotation matrix methods by calls to this generalized function.

#### Release Notes

<!-- BEGIN RELEASE NOTES -->
* matrices
  * Implemented `rot_givens` to compute givens rotation matrix.
<!-- END RELEASE NOTES -->

Update

The release notes on the wiki have been updated.

@evbernardes evbernardes marked this pull request as ready for review January 16, 2023 21:16
@evbernardes
Copy link
Contributor Author

evbernardes commented Jan 16, 2023

@sylee957 Added the cross-references, implemented rot_givens and reimplemented the other ones as calls to rot_givens.

Not sure which other tests to implement, but there were already some tests before that I had introduced (comparing to the results of Quaternion.to_rotation_matrix) and they are still passing, so at least for 3D rotations they work as expected (with negated angle for rot_axis2, as expected from the article on Wikipedia.

Comment on lines 287 to 290
M[i-1, i-1] = c
M[j-1, j-1] = c
M[i-1, j-1] = s
M[j-1, i-1] = -s
Copy link
Member

@sylee957 sylee957 Jan 16, 2023

Choose a reason for hiding this comment

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

I think that 0 to n-1 indexing is more preferable because of having less complicated formula for indexing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright, I can change that tomorrow.

Isn't it better to keep it consistent with axis1, axis2 and axis3 though?

Copy link
Member

Choose a reason for hiding this comment

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

No, those methods are pretty much nominal, they have only a finite numbers of names, so they can be left as is.
However a program that generates infinite numbers of notations is more general and can be difficult to change in the future.
It is better to be consistent with python indexing, or sympy matrix indexing itself, or there would be other counter arguments.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fair, just changed it!

M = eye(dim)
if i < j:
i, j = j, i
theta = -theta
Copy link
Member

Choose a reason for hiding this comment

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

Is it necessary to calculate this formula?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the article they said "for i > j", which is why I put it.

But now that I think about it, I think this has no effect indeed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed it and then the calls for rot_givens had to be changed.

It all still works, but I'm not sure which is the correct convention, should be better understood before merging in order not to create something that we can't change later on...

Copy link
Member

Choose a reason for hiding this comment

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

I think that the previous implementation can be wrong because you attempt to change theta but values of s = sin(theta) is already computed above and ignored.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops you're right!

Comment on lines 307 to 311
R = \begin{bmatrix}
\cos(\theta) & \sin(\theta) & 0\\
-\sin(\theta) & \cos(\theta) & 0\\
0 & 0 & 1
\end{bmatrix}
Copy link
Member

Choose a reason for hiding this comment

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

Math formula should also better be aligned for indentation
and have constant spacing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried align all of the &, tell me if it's okay!

@evbernardes
Copy link
Contributor Author

bin/test_sphinx.sh and make html are running locally, but it fails in one of the tests here.

Does anyone know why?

@oscarbenjamin
Copy link
Collaborator

bin/test_sphinx.sh and make html are running locally, but it fails in one of the tests here.

I've restarted it to see if is passes

@sylee957
Copy link
Member

I think that the sphinx errors in https://github.com/sympy/sympy/actions/runs/3938511339/jobs/6737742971 should be fixed in some way though.

@evbernardes
Copy link
Contributor Author

I think that the sphinx errors in https://github.com/sympy/sympy/actions/runs/3938511339/jobs/6737742971 should be fixed in some way though.

Agreed, I'll try to investigate it. Do you have any idea of what might be causing it?

@evbernardes

This comment was marked as resolved.

@sylee957
Copy link
Member

sylee957 commented Jan 18, 2023

It looks like align may have some problems. I don't think that it had been used by other parts of sympy, so although it can be a bug in sphinx, I'd not recommend using it and find other alternatives to typeset.

@github-actions
Copy link

github-actions bot commented Jan 18, 2023

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
     [41d90958]       [3450b757]
     <sympy-1.11.1^0>                 
-     1.14±0.01ms          723±7μs     0.63  solve.TimeSparseSystem.time_linear_eq_to_matrix(10)
-     3.40±0.06ms      1.36±0.03ms     0.40  solve.TimeSparseSystem.time_linear_eq_to_matrix(20)
-      6.75±0.1ms      1.98±0.06ms     0.29  solve.TimeSparseSystem.time_linear_eq_to_matrix(30)

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

@evbernardes
Copy link
Contributor Author

It looks like align may have some problems. I don't think that it had been used by other parts of sympy, so although it can be a bug in sphinx, I'd not recommend using it and find other alternatives to typeset.

Apparently you were right! All checks are passing now.

sympy/matrices/dense.py Outdated Show resolved Hide resolved
Co-authored-by: (Lazard) S.Y. Lee  <[email protected]>
@sylee957 sylee957 merged commit 8c8ad9d into sympy:master Jan 18, 2023
@evbernardes evbernardes deleted the rot_givens branch January 18, 2023 20:03
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