Add support for BMat8#48
Conversation
|
I think all the functionality is there, I just have to finish adding the documentation. |
|
@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. |
15955b6 to
f29327f
Compare
Codecov Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
f29327f to
d94bd2c
Compare
|
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). |
|
@jswent Any idea why the docs are failing? |
d94bd2c to
eada35e
Compare
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. |
|
@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 |
|
Thanks @jswent! |
e55711d to
4a9d1d3
Compare
|
This is now good to go |
9ef5e1c to
f91e6d9
Compare
f91e6d9 to
95c950d
Compare
|
Thanks for the comments @jswent, I've updated the PR accordingly, please let me know if have any further suggestions. |
95c950d to
cfee39a
Compare
jswent
left a comment
There was a problem hiding this comment.
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
There was a problem hiding this comment.
this needs to revert back to using Base.one()
| function Base.getindex(x::BMat8, r::Int64, c::Int64)::Bool | ||
| return @wrap_libsemigroups_call LibSemigroups.at(x, UInt(r - 1), UInt(c - 1)) | ||
| end |
There was a problem hiding this comment.
I think it would be better to keep the index conversion in the C++ bindings layer to maintain consistency. Thoughts?
There was a problem hiding this comment.
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.
| 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 |
There was a problem hiding this comment.
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
| 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?
There was a problem hiding this comment.
probably better to apply these changes yourself since i wrote this in the browser (not sure if formatting is correct)
There was a problem hiding this comment.
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]; endERROR: 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) |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
| - `MethodError`: if `rows` has `0` rows. | |
| - `BoundsError`: if `rows` has `0` rows. |
There was a problem hiding this comment.
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
|
@james-d-mitchell tests should pass now if you rebase main |
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>
No description provided.