Skip to content

Commit

Permalink
Add dim check to matrix_space (#1683)
Browse files Browse the repository at this point in the history
* Add dim check to `matrix_space`

* Add test
  • Loading branch information
lgoettgens authored Apr 25, 2024
1 parent 86dba7a commit cba2be0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/generic/Matrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ end
function matrix_space(R::AbstractAlgebra.NCRing, r::Int, c::Int; cached::Bool = true)
# TODO: the 'cached' argument is ignored and mainly here for backwards compatibility
# (and perhaps future compatibility, in case we need it again)
(r < 0 || c < 0) && error("Dimensions must be non-negative")
T = elem_type(R)
return MatSpace{T}(R, r, c)
end
Expand Down
4 changes: 4 additions & 0 deletions test/generic/Matrix-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ end
@testset "Generic.Mat.constructors" begin
R, t = polynomial_ring(QQ, "t")

@test_throws ErrorException matrix_space(R, -1, 5)
@test_throws ErrorException matrix_space(R, 0, -2)
@test_throws ErrorException matrix_space(R, -3, -4)

S = matrix_space(R, 3, 3)

@test S === matrix_space(R, 3, 3)
Expand Down

0 comments on commit cba2be0

Please sign in to comment.