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

Add dim check to matrix_space #1683

Merged
merged 2 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading