Skip to content

transpose degree n matrices #1217

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

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

Alex-Jordan
Copy link
Contributor

This builds on #1216 (which builds on #1215). If #1216 is updated following feedback, I will update here too. Once #1216 is merged, this diff should be more manageable.

In addition to changes from #1216, this has:

  • a slice method for a Matrix object. This produces a degree (n-1) Matrix from a degree n Matrix. You specify an index and a value for that index, and it produces the degree (n-1) Matrix that is thereby defined. This is currently only used as a helper for the update to transpose. It is similar to row and column methods, but more general. And always produces something of the next lower degree.
  • to transpose a degree n Matrix, the word "transpose" is perhaps a misnomer. Instead you have some permutation of the index dimensions in mind. For the usual transpose of a degree 2 matrix, this is just the permutation (12). For a degree n matrix, you might want to permute the indices in a different way. Doing this once can make it more efficient to repeatedly access data in the Matrix, depending on the scenario. So now you can transpose a degree n Matrix. If you don't specify a permutation, the default is to just swap the last two indices. This will look like a regular transposition on each of the degree 2 matrices in the frontal slice. Otherwise, for the permutation you may specify a cycle in the form of an array reference, or a product of cycles in the form of an array reference of array references.

This is the last of the updates I wanted to do before adding new methods for setting elements, removing columns and rows and a submatrix that @pstaabp has in #1076. We should make sure new tools work with degree n Matrix objects as we add them. Unless it is for sure only appropriate for degree 2 matrices.

@Alex-Jordan Alex-Jordan changed the title Matrices 3 transpose degree n matrices Mar 25, 2025
@pstaabp
Copy link
Member

pstaabp commented Mar 25, 2025

Looks good, but we should bring the test suite in soon. There was one in my branch that probably works for a lot of this, but should be update.

Although I'm guessing you have a number of problems that you've been testing with, it's more efficient to have the test suite.

I can get it working with this branch and put in a PR to this if you'd like.

Copy link
Member

@drgrice1 drgrice1 left a comment

Choose a reason for hiding this comment

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

I haven't tested this at all yet, but I see some code changes that are needed. Some things that perlcritic pointed out.

Copy link
Member

@drgrice1 drgrice1 left a comment

Choose a reason for hiding this comment

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

I think this generally looks good aside from the comments I made.

Comment on lines 842 to 843
Produce the degree (n-1) Matrix defined by a given index and value for that index. If n is 1,
this produces a Real/Complex/Fraction.
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 this could use some clarification as to what this really means. What do index and value mean in this context?

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 to do better here. I will push and you can see. Imagine a 5x7x9 matrix. Entry positions are defined by three indices i,j,k. The first index, second index, and third index. So "index" here would be 1, 2, or 3. Say it is 3. Then a value for that index can be 1, 2, ..., or 9. Take a look and see if what I changed to is OK or can be improved upon.

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 what you changed it to is better. What you said here really is what really worked for me though. Perhaps adding an example like that to the POD would better. Terminology with these "tensor" things can get confusing!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, I put something like that in the POD.

Take the transpose of a matrix.
Apply this to a degree n Matrix, passing (m, k), and produce the degree (n-1) Matrix defined by
taking all entries whose position has mth index with value k. For example if C<$M> is a 4x5x6
Matrix, then m can be 1, 2, or 3. If m is 2, then k can be 1, 2, 3, 4, or 5. C<$M-<gt>slice(2,3)>
Copy link
Member

Choose a reason for hiding this comment

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

The code at the end of this can be made with C<<$M->slice(2,3)>>, a bit easier than the notation.

Copy link
Member

Choose a reason for hiding this comment

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

That actually needs to be C<< $M->slice(2, 3) >>. There must be spaces after << and before >>.

Copy link
Member

Choose a reason for hiding this comment

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

Good point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants