Skip to content

Examples of Vector objects and Matrix objects#6339

Open
cdwensley wants to merge 19 commits intomasterfrom
matrix-examples
Open

Examples of Vector objects and Matrix objects#6339
cdwensley wants to merge 19 commits intomasterfrom
matrix-examples

Conversation

@cdwensley
Copy link
Copy Markdown
Contributor

It was agreed by @fingolfin in PR#6320 that Chapter 26, Vector and Matrix Objects, needs lots of usage examples.
This is just an attempt to get this process started.
Newcomers to vector and matrix objects who start by reading this manual chapter (as opposed to those accessing a section by asking a question during a GAP session) need some examples early on, so this first commit adds a new section 26.2 doing just that.
Comments by one and all will be most welcome as further examples are added.
It was interesting to find that IsPlist{Vector/Matrix}Rep allow lists of type IsRangeRep as well as IsPlistRep.

@fingolfin fingolfin added the topic: documentation Issues and PRs related to documentation label Apr 20, 2026
@fingolfin fingolfin requested a review from ThomasBreuer April 20, 2026 22:42
Comment thread doc/ref/matobj.xml Outdated
and a matrix in these new forms.
The elements should all belong to a semiring <M>R</M>
(the <C>BaseDomain</C>).
It is also necessary to specify their <E>type</E>, or <E>filter</E>.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Actually these can be omitted if one uses Matrix and Vector instead of NewMatrix and NewVector -- in that case default are chosen, based on the base domain.

My feeling is that we should generally advocate the use of the function variants without the New; the ones with New are constructors, and are the ones that people implementing MatrixObj ought to implement. Though I might be missing some nuance here, @ThomasBreuer ? I really should read up on what we wrote in the docs ...

But in any case, this is exactly the kind of thing that must be made clear in the manual, of course

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

My point of view is that the starting point is the semiring R, in the sense that we want to do many computations with vectors and matrices over a given R.

Once we have fixed R, the functions Vector( R, list ) and Matrix( R, list ) (or Matrix( R, list, ncols )) give us vector and matrix objects in some representation that fits to R.

And once we have such a vector v or matrix M, new vectors and matrices that fit to them can be created with Vector( list, v ) and Matrix( list, M ).

This is the easy case.
If we do not want to rely on the default representation for R, we can look at some list of available representations (filters), and specify explicitly which one we choose.

Where is this useful or even necessary?
For example, suppose we need the matrix group GL( 4, GF(2) ), but we know already that later on this will be regarded as a subgroup of GL( 4, GF(2^10) ).
It may happen that the default representations for matrix objects over GF(2) and GF(2^10) differ.

In this situation, we should create GL( 4, GF(2) ) in such a way that the generators are written in a representation that is suitable also for matrices over GF(2^10).

Currently I see no easier way to achieve this than to create a matrix object over GF(2^10), to ask for its ConstructingFilter, and to specify this filter in the construction of the group GL( 4, GF(2) ).

Copy link
Copy Markdown
Contributor

@ThomasBreuer ThomasBreuer left a comment

Choose a reason for hiding this comment

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

Two suggestions, which should fix the test failure (one more instance of the annoying setup described in #6274).

And one general remark, I agree with @fingolfin that Matrix and Vector are more important for users than NewMatrix and NewVector.

Comment thread doc/ref/matobj.xml Outdated
Comment thread doc/ref/matobj.xml Outdated
@fingolfin fingolfin changed the title Examples of Vector objects and Matrix oblects Examples of Vector objects and Matrix objects Apr 21, 2026
cdwensley and others added 10 commits April 22, 2026 12:37
Co-authored-by: Thomas Breuer <sam@math.rwth-aachen.de>
Co-authored-by: Thomas Breuer <sam@math.rwth-aachen.de>
Bumps [actions/upload-pages-artifact](https://github.com/actions/upload-pages-artifact) from 4 to 5.
- [Release notes](https://github.com/actions/upload-pages-artifact/releases)
- [Commits](actions/upload-pages-artifact@v4...v5)

---
updated-dependencies:
- dependency-name: actions/upload-pages-artifact
  dependency-version: '5'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [julia-actions/setup-julia](https://github.com/julia-actions/setup-julia) from 2 to 3.
- [Release notes](https://github.com/julia-actions/setup-julia/releases)
- [Commits](julia-actions/setup-julia@v2...v3)

---
updated-dependencies:
- dependency-name: julia-actions/setup-julia
  dependency-version: '3'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Codex wrote most of this and I edited it.

Co-authored-by: Codex <codex@openai.com>
So far adding an integer to a range produced a plain list.
Add a kernel method to ensure this again produces a range,
if possible. If not, fall back to the current behavior.

AI-assisted with Codex for the kernel change and tests.

Co-authored-by: Codex <codex@openai.com>
Switch Codecov to manual notifications and send them once after
the coverage-uploading test matrix finishes. This avoids noisy
intermediate PR comments and temporary dropped-coverage reports
while uploads are still in flight.

Co-authored-by: Codex <codex@openai.com>
…6329)

... by avoiding some method dispatch, providing optimized methods
using `{...}` syntax, and turning ExtractSubVector, CopySubVector,
ExtractSubMatrix, and CopySubMatrix into kernel ops.

Then run some benchmarks via `benchmark/matobj/bench-submat.g` and
the new `benchmark/matobj/bench-subvec.g`.

Before:

    +----------------------------------------------------------------+
    | Testing submatrix extraction for integer matrix: list of lists |
    +----------------------------------------------------------------+
    Testing m{}{}:
      129 µs per iteration; 7749 iterations per second; (200 iterations)
    Testing ExtractSubMatrix:
      720 µs per iteration; 1388 iterations per second; (200 iterations)
    ...now testing submatrix copying...
    Testing m{}{}:=n{}{}:
      342 µs per iteration; 2921 iterations per second; (200 iterations)
    Testing CopySubMatrix:
      1032 µs per iteration; 969 iterations per second; (200 iterations)

    +------------------------------------------------+
    | Testing submatrix extraction for GF(2) rowlist |
    +------------------------------------------------+
    Testing m{}{}:
      167 µs per iteration; 5999 iterations per second; (200 iterations)
    Testing ExtractSubMatrix:
      3288 µs per iteration; 304 iterations per second; (92 iterations)
    ...now testing submatrix copying...
    Testing m{}{}:=n{}{}:
      1992 µs per iteration; 502 iterations per second; (151 iterations)
    Testing CopySubMatrix:
      2606 µs per iteration; 384 iterations per second; (116 iterations)

    +-------------------------------------------------------------+
    | Testing subvector extraction for integer vector: plain list |
    +-------------------------------------------------------------+
    Testing x{}:=v{}:
      393 µs per iteration; 2542 iterations per second; (200 iterations)
    Testing CopySubVector:
      2324 µs per iteration; 430 iterations per second; (130 iterations)

    +---------------------------------------------------+
    | Testing subvector extraction for GF(2) row vector |
    +---------------------------------------------------+
    Testing x{}:=v{}:
      441 µs per iteration; 2266 iterations per second; (200 iterations)
    Testing CopySubVector:
      2458 µs per iteration; 407 iterations per second; (123 iterations)

After:

    +----------------------------------------------------------------+
    | Testing submatrix extraction for integer matrix: list of lists |
    +----------------------------------------------------------------+
    Testing m{}{}:
      136 µs per iteration; 7355 iterations per second; (200 iterations)
    Testing ExtractSubMatrix:
      140 µs per iteration; 7135 iterations per second; (200 iterations)
    ...now testing submatrix copying...
    Testing m{}{}:=n{}{}:
      301 µs per iteration; 3319 iterations per second; (200 iterations)
    Testing CopySubMatrix:
      299 µs per iteration; 3347 iterations per second; (200 iterations)

    +------------------------------------------------+
    | Testing submatrix extraction for GF(2) rowlist |
    +------------------------------------------------+
    Testing m{}{}:
      154 µs per iteration; 6490 iterations per second; (200 iterations)
    Testing ExtractSubMatrix:
      146 µs per iteration; 6854 iterations per second; (200 iterations)
    ...now testing submatrix copying...
    Testing m{}{}:=n{}{}:
      1895 µs per iteration; 528 iterations per second; (159 iterations)
    Testing CopySubMatrix:
      1935 µs per iteration; 517 iterations per second; (156 iterations)

    +-------------------------------------------------------------+
    | Testing subvector extraction for integer vector: plain list |
    +-------------------------------------------------------------+
    Testing x{}:=v{}:
      428 µs per iteration; 2336 iterations per second; (200 iterations)
    Testing CopySubVector:
      453 µs per iteration; 2209 iterations per second; (200 iterations)

    +---------------------------------------------------+
    | Testing subvector extraction for GF(2) row vector |
    +---------------------------------------------------+
    Testing x{}:=v{}:
      427 µs per iteration; 2344 iterations per second; (200 iterations)
    Testing CopySubVector:
      460 µs per iteration; 2172 iterations per second; (200 iterations)

So overall the Copy/Extract methods are now more or less on par
with the code using `{...}` syntax.

But actually this `ExtractSubMatrix` for a GF(2) rowlist is now *faster*
than the optimized one for a compressed GF(2) matrix:

    +----------------------------------------------------------+
    | Testing submatrix extraction for GF(2) compressed matrix |
    +----------------------------------------------------------+
    Testing m{}{}:
      1057 µs per iteration; 946 iterations per second; (200 iterations)
    Testing ExtractSubMatrix:
      1618 µs per iteration; 618 iterations per second; (186 iterations)

A substantial part of that is due to the the `ExtractSubMatrix`
method for `IsGF2MatrixRep` calling `ConvertToMatrixRepNC(mm,2)`;
after removing that, it went down from 1618 to 392 µs (which is still
worse).

---

AI assistance: Codex implemented the kernel plumbing,
method cleanup, and test updates. It also created
`benchmark/matobj/bench-subvec.g`.

Co-authored-by: Codex <codex@openai.com>
@cdwensley
Copy link
Copy Markdown
Contributor Author

I have started to follow the suggestions of @fingolfin and @ThomasBreuer, but using GitHub in collaboration like this, and with GAPdev, is getting me in rather a tangle, so advice needed.
(1) the latest gapdev changes downloaded today result in errors when running GAP, so make_doc does not run:
("Error, Variable: 'EXTRACT_SUB_VECTOR' must have a value")
so is there a version of makedoc.g which will just produce the reference manual from within a GAP session?
(2) if I apply some of your suggestions within this PR, should I then "git pull upstream matrix-examples" before making any other changes locally? That did not seem to work well earlier today.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 22, 2026

Codecov Report

❌ Patch coverage is 93.26923% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.62%. Comparing base (edf6baf) to head (7971547).
⚠️ Report is 10 commits behind head on master.

Files with missing lines Patch % Lines
grp/simple.gi 44.44% 5 Missing ⚠️
src/range.c 92.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6339      +/-   ##
==========================================
+ Coverage   78.61%   78.62%   +0.01%     
==========================================
  Files         684      684              
  Lines      292638   292701      +63     
  Branches     8654     8658       +4     
==========================================
+ Hits       230045   230147     +102     
+ Misses      60785    60743      -42     
- Partials     1808     1811       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@cdwensley
Copy link
Copy Markdown
Contributor Author

NewMatrix(filt, R, ncols, list) & Matrix(filt, R, list, ncols) .... this confusing change of order will not do!

mvanhorn and others added 8 commits April 28, 2026 16:30
The GAPDoc description for IrreducibleModules claimed the second
entry was 'a list of all irreducible modules of G over the field F
in dimension dim'. The actual behaviour is to return all
irreducible constituents of dimension at most dim, matching:

Updated the description to match this, and also added a one-line
note that passing 0 imposes no bound (already the implementation
behavior, previously only discoverable by reading the code).

Co-authored-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
Co-authored-by: Claude (Anthropic AI) <noreply@anthropic.com>
Return the empty partition from PartitionsGreatestLE(0, m) for
every nonnegative m. Also clarify the documentation.

Co-authored-by: Codex <codex@openai.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic: documentation Issues and PRs related to documentation

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

4 participants