Skip to content

Add support for BMat8#48

Merged
james-d-mitchell merged 7 commits intolibsemigroups:mainfrom
james-d-mitchell:bmat8
Mar 6, 2026
Merged

Add support for BMat8#48
james-d-mitchell merged 7 commits intolibsemigroups:mainfrom
james-d-mitchell:bmat8

Conversation

@james-d-mitchell
Copy link
Member

No description provided.

@james-d-mitchell james-d-mitchell marked this pull request as draft February 21, 2026 19:48
@james-d-mitchell
Copy link
Member Author

I think all the functionality is there, I just have to finish adding the documentation.

@jswent
Copy link
Member

jswent commented Feb 22, 2026

@james-d-mitchell I think your fork is behind since the tests are out of sync with main. Just merged in, everything should pass now.

EDIT: Nevermind, hadn't seen that you modified transf. Will do a full review later.

@codecov-commenter
Copy link

codecov-commenter commented Feb 22, 2026

Codecov Report

❌ Patch coverage is 76.47059% with 12 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@4cf738b). Learn more about missing BASE report.

Files with missing lines Patch % Lines
src/elements/bmat8.jl 76.47% 12 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main      #48   +/-   ##
=======================================
  Coverage        ?   65.33%           
=======================================
  Files           ?       10           
  Lines           ?      450           
  Branches        ?        0           
=======================================
  Hits            ?      294           
  Misses          ?      156           
  Partials        ?        0           

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

@james-d-mitchell
Copy link
Member Author

I just need to add tests and this should be good to go (note everything is tested in the docs, so it's just a matter of extracting the code examples and putting them in a test file).

@james-d-mitchell
Copy link
Member Author

@jswent Any idea why the docs are failing?

@jswent
Copy link
Member

jswent commented Feb 24, 2026

@jswent Any idea why the docs are failing?

not sure, haven't seen a segfault before. just tested on a throwaway PR and got the same result, which was passing before. will look into it later.

@jswent
Copy link
Member

jswent commented Feb 24, 2026

@james-d-mitchell should be fixed, appears to be a problem with the latest version of julia so I pinned a stable version to the CI checks

@james-d-mitchell
Copy link
Member Author

Thanks @jswent!

@james-d-mitchell james-d-mitchell marked this pull request as ready for review February 25, 2026 10:39
@james-d-mitchell
Copy link
Member Author

This is now good to go

@james-d-mitchell james-d-mitchell force-pushed the bmat8 branch 2 times, most recently from 9ef5e1c to f91e6d9 Compare February 25, 2026 15:16
@james-d-mitchell
Copy link
Member Author

Thanks for the comments @jswent, I've updated the PR accordingly, please let me know if have any further suggestions.

Copy link
Member

@jswent jswent left a comment

Choose a reason for hiding this comment

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

just a few more notes then should be good to go. tests failing is something different (increase_degree_by upstream changes), so I'll fix that

Copy link
Member

Choose a reason for hiding this comment

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

this needs to revert back to using Base.one()

Comment on lines +127 to +129
function Base.getindex(x::BMat8, r::Int64, c::Int64)::Bool
return @wrap_libsemigroups_call LibSemigroups.at(x, UInt(r - 1), UInt(c - 1))
end
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 it would be better to keep the index conversion in the C++ bindings layer to maintain consistency. Thoughts?

Copy link
Member Author

Choose a reason for hiding this comment

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

It might be better to keep everything in LibSemigroups as close to the original C++ as possible, for the purposes of resolving bugs. Not sure though. I've also been generating the bindings for Forest and it requires a fairly large amount of wrangling the parameters, which more or less cannot be done directly in the C++ code, which provides a further rationale for keeping this here.

Comment on lines +195 to +209
function BMat8(rows::Vector{Vector{T}})::BMat8 where {T<:Union{Bool,Int64}}
result = BMat8(0)
n = length(rows[1])
for (i, row) in enumerate(rows)
if length(row) != n
throw(
LibsemigroupsError(
"the entries of the argument (rows) must all be the same length $n, found length $(length(row)) for row with index $i",
),
)
end
result[i] = row
end
return result
end
Copy link
Member

Choose a reason for hiding this comment

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

Possibly worth adding some extra validation here based on what we discussed yesterday (BMat8 iterates and writes rows one-by-one) as currently behaves like:

julia> x = BMat8(0)
julia> for i in 1:9; x[i] = [1, 1]; end
# ERROR: LibsemigroupsError("...the 1st argument (row index) must be < 8, found 8")

julia> x  # rows 1-8 were already written
BMat8([[1, 1, 0, 0, 0, 0, 0, 0],
       [1, 1, 0, 0, 0, 0, 0, 0],
       [1, 1, 0, 0, 0, 0, 0, 0],
       [1, 1, 0, 0, 0, 0, 0, 0],
       [1, 1, 0, 0, 0, 0, 0, 0],
       [1, 1, 0, 0, 0, 0, 0, 0],
       [1, 1, 0, 0, 0, 0, 0, 0],
       [1, 1, 0, 0, 0, 0, 0, 0]])

possibly something like

Suggested change
function BMat8(rows::Vector{Vector{T}})::BMat8 where {T<:Union{Bool,Int64}}
result = BMat8(0)
n = length(rows[1])
for (i, row) in enumerate(rows)
if length(row) != n
throw(
LibsemigroupsError(
"the entries of the argument (rows) must all be the same length $n, found length $(length(row)) for row with index $i",
),
)
end
result[i] = row
end
return result
end
function BMat8(rows::Vector{Vector{T}})::BMat8 where {T<:Union{Bool,Int64}}
if length(rows) > 8
throw(LibsemigroupsError(
"expected the argument (rows) to have at most 8 rows, found $(length(rows))"))
end
result = BMat8(0)
n = length(rows[1])
if n > 8
throw(LibsemigroupsError(
"expected rows in the argument (rows) to have length at most 8, found $n"))
end
for (i, row) in enumerate(rows)
if length(row) != n
throw(
LibsemigroupsError(
"the entries of the argument (rows) must all be the same length $n, found length $(length(row)) for row with index $i",
),
)
end
result[i] = row
end
return result
end

not sure how you would feel about this?

Copy link
Member

Choose a reason for hiding this comment

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

probably better to apply these changes yourself since i wrote this in the browser (not sure if formatting is correct)

Copy link
Member Author

Choose a reason for hiding this comment

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

Possibly worth adding some extra validation here based on what we discussed yesterday (BMat8 iterates and writes rows one-by-one) as currently behaves like:

julia> x = BMat8(0)
julia> for i in 1:9; x[i] = [1, 1]; end

ERROR: LibsemigroupsError("...the 1st argument (row index) must be < 8, found 8")

julia> x # rows 1-8 were already written
BMat8([[1, 1, 0, 0, 0, 0, 0, 0],
[1, 1, 0, 0, 0, 0, 0, 0],
[1, 1, 0, 0, 0, 0, 0, 0],
[1, 1, 0, 0, 0, 0, 0, 0],
[1, 1, 0, 0, 0, 0, 0, 0],
[1, 1, 0, 0, 0, 0, 0, 0],
[1, 1, 0, 0, 0, 0, 0, 0],
[1, 1, 0, 0, 0, 0, 0, 0]])

As far as I can tell this does exactly as I'd expect, the error only occurs when i = 9 so the output is as expected. I think I added the correct amount of argument checking, everything else is checked in libsemigroups. If more argument checks are required we should add them in libsemigroups itself and not here. Which makes me think I should add the checks here to libsemigroups too (if they're not there already).

end

function Base.setindex!(x::BMat8, row::Vector{T}, r::Int64) where {T<:Union{Bool,Int64}}
@wrap_libsemigroups_call setindex!(x, Vector{UInt8}(row), r)
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 the same problem as the constructor would happen here, where setting a row with >8 elements writes columns 1-8 successfully and then errors out

- `rows::Vector{Vector{T}} where {T<:Union{Bool,Int64}}`: the rows of the matrix.

# Throws
- `MethodError`: if `rows` has `0` rows.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
- `MethodError`: if `rows` has `0` rows.
- `BoundsError`: if `rows` has `0` rows.

Copy link
Member Author

Choose a reason for hiding this comment

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

This throws a MethodError for me:

julia> BMat8([])
ERROR: MethodError: no method matching BMat8(::Vector{Any})
The type `BMat8` exists, but no method is defined for this combination of argument types when trying to construct it.

Closest candidates are:
  BMat8()
   @ Semigroups none:0
  BMat8(::Integer)
   @ Semigroups none:0
  BMat8(::Array{Vector{T}, 1}) where T<:Union{Bool, Int64}
   @ Semigroups ~/git/Semigroups.jl/src/elements/bmat8.jl:195

Stacktrace:
 [1] top-level scope
   @ REPL[1]:1

@jswent
Copy link
Member

jswent commented Feb 26, 2026

@james-d-mitchell tests should pass now if you rebase main

james-d-mitchell and others added 2 commits March 3, 2026 12:06
Co-authored-by: Jake Swent <94636565+jswent@users.noreply.github.com>
Co-authored-by: Jake Swent <94636565+jswent@users.noreply.github.com>
Co-authored-by: Jake Swent <94636565+jswent@users.noreply.github.com>
@james-d-mitchell james-d-mitchell merged commit fdbba42 into libsemigroups:main Mar 6, 2026
11 checks passed
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