From b66d72cd8e0923ac7fbfd4cb4c41241aceae6763 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Wed, 20 Nov 2024 00:01:21 +0100 Subject: [PATCH] Change similar() to use UndefInitializer constructors This is incompatible with older Nemo versions. --- src/Matrix.jl | 2 +- src/generic/Matrix.jl | 4 ++++ test/generic/Matrix-test.jl | 4 +++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Matrix.jl b/src/Matrix.jl index 132f61d04..0367d1051 100644 --- a/src/Matrix.jl +++ b/src/Matrix.jl @@ -395,7 +395,7 @@ end Create an uninitialized matrix over the given ring and dimensions, with defaults based upon the given source matrix `x`. """ -similar(x::MatElem, R::NCRing, r::Int, c::Int) = zero_matrix(R, r, c) +similar(x::MatElem, R::NCRing, r::Int, c::Int) = dense_matrix_type(R)(R, undef, r, c) similar(x::MatElem, R::NCRing) = similar(x, R, nrows(x), ncols(x)) diff --git a/src/generic/Matrix.jl b/src/generic/Matrix.jl index 2cce12a66..af292e25a 100644 --- a/src/generic/Matrix.jl +++ b/src/generic/Matrix.jl @@ -25,6 +25,10 @@ parent(a::MatElem) = matrix_space(base_ring(a), nrows(a), ncols(a)) Return the type of matrices with coefficients of type `T` respectively `elem_type(S)`. + +Implementations of the ring interface only need to provide a method +for the argument a subtype of `NCRingElement`; the other variants are +implemented by calling that method. """ dense_matrix_type(::T) where T <: NCRing = dense_matrix_type(elem_type(T)) dense_matrix_type(::T) where T <: NCRingElement = dense_matrix_type(T) diff --git a/test/generic/Matrix-test.jl b/test/generic/Matrix-test.jl index e181b7321..bd561bdaa 100644 --- a/test/generic/Matrix-test.jl +++ b/test/generic/Matrix-test.jl @@ -73,11 +73,13 @@ struct F2Matrix <: AbstractAlgebra.MatElem{F2Elem} m::Generic.MatSpaceElem{F2Elem} end +F2Matrix(::F2, ::UndefInitializer, r::Int, c::Int) = F2Matrix(Generic.MatSpaceElem{F2Elem}(F2(), undef, r, c)) + AbstractAlgebra.elem_type(::Type{F2MatSpace}) = F2Matrix AbstractAlgebra.parent_type(::Type{F2Matrix}) = F2MatSpace AbstractAlgebra.base_ring(::F2MatSpace) = F2() -AbstractAlgebra.dense_matrix_type(::Type{F2}) = F2Matrix +AbstractAlgebra.dense_matrix_type(::Type{F2Elem}) = F2Matrix AbstractAlgebra.matrix_space(::F2, r::Int, c::Int) = F2MatSpace(F2(), r, c) AbstractAlgebra.number_of_rows(a::F2Matrix) = nrows(a.m)