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

Support method dispatch based on tags (see the manual section "Tag Based Operations") #5344

Merged
merged 7 commits into from
Feb 13, 2023

Conversation

ThomasBreuer
Copy link
Contributor

@ThomasBreuer ThomasBreuer commented Jan 26, 2023

In calls to operations such as DiagonalMatrix, CompanionMatrix, etc., one wants to specify the internal representation of the result via a filter (such as IsPlistMatrixRep) as the first argument. In order to be able to install individual methods depending on this filter, one does not really want to declare the operations as constructors because the result shall have exactly the given filter (and not perhaps something better), and also because one wants to be able to install a default method. (See the discussion of #4398 for details.)

The changes proposed here provide an implementation (see commit 949cbc4) and documentation (see commit 9aaf40f) for this feature. Note that the operations in question are still GAP operations, the tag based mechanism is called only in the situation that the first argument is a filter.

The rest of the pull request applies the new mechanism to the operation DiagonalMatrix:

  • added a new operation DiagonalMatrix, and added its documentation to the Reference Manual
  • added a new filter IsRowVectorOrVectorObj, analogous to IsMatrixOrMatrixObj, in order to simplify some method installations
  • moved the declarations of DefaultVectorRepForBaseDomain and DefaultMatrixRepForBaseDomain from lib/matobj.gi to lib/matobj2.gd
  • added a CompatibleVectorFilter method for IsMatrix objects
  • added NewZeroMatrix and NewIdentityMatrix methods for IsPlistRep
  • added preliminary tests for DiagonalMatrix
  • removed some comment lines

As soon as we agree on the details, the same changes can be applied to PermutationMatrix, ReflectionMatrix, RandomMatrix, see issue #4367.

Here are the perhaps controversial pieces of the changes:

  • We could decide that DiagonalMatrix( list ) behaves like the global function DiagonalMat( list ), and then DiagonalMat could become deprecated.
  • It is not clear to me to which extent we want IsPlistRep matrices to be supported w.r.t. functionality for matrix objects. Thus perhaps the "auxiliary" NewZeroMatrix and NewIdentityMatrix methods for IsPlistRep and the CompatibleVectorFilter method for IsMatrix objects are not what we want.

@ThomasBreuer ThomasBreuer added kind: enhancement Label for issues suggesting enhancements; and for pull requests implementing enhancements topic: library release notes: not needed PRs introducing changes that are wholly irrelevant to the release notes labels Jan 26, 2023
@fingolfin

This comment was marked as resolved.

@fingolfin

This comment was marked as resolved.

@ChrisJefferson

This comment was marked as resolved.

@fingolfin
Copy link
Member

@ChrisJefferson that's what I did and how I got the backtrace above. It unfortunately doesn't tell us much. I could easily break at it in gdb, I guess. But then what?

@ChrisJefferson

This comment was marked as resolved.

lib/methsel.g Outdated Show resolved Hide resolved
Copy link
Member

@fingolfin fingolfin left a comment

Choose a reason for hiding this comment

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

This looks good to me, just needs to be rebased. Perhaps some more people could look at the docs to see if they make sense.

lib/methsel.g Outdated
##
#F NewKeyBasedOperation( <name>, <requirements> )
#F DeclareKeyBasedOperation( <name>, <requirements> )
#F InstallKeyBasedMethod( <oper>[, <key>], <meth> )
Copy link
Member

Choose a reason for hiding this comment

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

I am slightly concerned that people will confuse this with KeyDependentOperation resp. confuse one with the other. So if someone has a good idea for an alternate name...

- added a new operation `DiagonalMatrix`,
  and added its documentation to the Reference Manual
- added a new filter `IsRowVectorOrVectorObj`, analogous to
  `IsMatrixOrMatrixObj`, in order to simplify some method installations
- moved the declarations of `DefaultVectorRepForBaseDomain` and
  `DefaultMatrixRepForBaseDomain` from `lib/matobj.gi` to `lib/matobj2.gd`
- added a `CompatibleVectorFilter` method for `IsMatrix` object
- added `NewZeroMatrix` and `NewIdentityMatrix` methods for `IsPlistRep`
- added preliminary tests for `DiagonalMatrix`
- removed some comment lines
as proposed in the discussion of gap-system#4398:

- introduced `DeclareKeyBasedOperation`, `InstallKeyBasedMethod`
  (and `NewKeyBasedOperation`, in order to be able to write tests for
  them that can be run more than once in a session)
- added a testfile
- changed the code for `DiagonalMatrix` to use the setup given by the
  new functions
  (we could install methods depending on the representation but the main
  idea behind the change was that we do not have to do this)

(Official documentation is still missing.)
@ChrisJefferson
Copy link
Contributor

I'm generally happy with this PR. If you were looking for an alternative name to "Key", then I've often seen this kind of thing called "Tag".

@ThomasBreuer
Copy link
Contributor Author

ThomasBreuer commented Feb 10, 2023

O.k., I will replace "key" by "tag".
Thanks, @ChrisJefferson.

@ThomasBreuer ThomasBreuer changed the title new operation DiagonalMatrix Support method dispatch based on tags (see the manual section "Tag Based Operations") Feb 13, 2023
@ThomasBreuer ThomasBreuer added release notes: use title For PRs: the title of this PR is suitable for direct use in the release notes and removed release notes: not needed PRs introducing changes that are wholly irrelevant to the release notes labels Feb 13, 2023
@ThomasBreuer ThomasBreuer merged commit 9bf678e into gap-system:master Feb 13, 2023
@ThomasBreuer ThomasBreuer deleted the TB_DiagonalMat branch February 13, 2023 11:08
ThomasBreuer added a commit to ThomasBreuer/gap that referenced this pull request Mar 7, 2023
This is a follow-up of gap-system#5344, according to a comment in gap-system#4398.
fingolfin pushed a commit that referenced this pull request Mar 13, 2023
This is a follow-up of #5344, according to a comment in #4398.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: enhancement Label for issues suggesting enhancements; and for pull requests implementing enhancements kind: new feature release notes: use title For PRs: the title of this PR is suitable for direct use in the release notes topic: library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants