diff --git a/src/arb/ArbTypes.jl b/src/arb/ArbTypes.jl index 225292497..c089a9a34 100644 --- a/src/arb/ArbTypes.jl +++ b/src/arb/ArbTypes.jl @@ -796,6 +796,9 @@ mutable struct RealMatrix <: MatElem{RealFieldElem} rows::Ptr{Nothing} #base_ring::ArbField + # MatElem interface + RealMatrix(::RealField, r::Int, c::Int) = RealMatrix(r, c) + function RealMatrix(r::Int, c::Int) z = new() ccall((:arb_mat_init, libflint), Nothing, (Ref{RealMatrix}, Int, Int), z, r, c) @@ -884,6 +887,13 @@ mutable struct ArbMatrix <: MatElem{ArbFieldElem} rows::Ptr{Nothing} base_ring::ArbField + # MatElem interface + function ArbMatrix(R::ArbField, r::Int, c::Int) + z = ArbMatrix(r, c) + z.base_ring = R + return z + end + function ArbMatrix(r::Int, c::Int) z = new() ccall((:arb_mat_init, libflint), Nothing, (Ref{ArbMatrix}, Int, Int), z, r, c) @@ -976,6 +986,9 @@ mutable struct ComplexMatrix <: MatElem{ComplexFieldElem} rows::Ptr{Nothing} #base_ring::AcbField + # MatElem interface + ComplexMatrix(::ComplexField, r::Int, c::Int) = ComplexMatrix(r, c) + function ComplexMatrix(r::Int, c::Int) z = new() ccall((:acb_mat_init, libflint), Nothing, (Ref{ComplexMatrix}, Int, Int), z, r, c) @@ -1166,6 +1179,13 @@ mutable struct AcbMatrix <: MatElem{AcbFieldElem} rows::Ptr{Nothing} base_ring::AcbField + # MatElem interface + function AcbMatrix(R::AcbField, r::Int, c::Int) + z = AcbMatrix(r, c) + z.base_ring = R + return z + end + function AcbMatrix(r::Int, c::Int) z = new() ccall((:acb_mat_init, libflint), Nothing, (Ref{AcbMatrix}, Int, Int), z, r, c) diff --git a/src/arb/acb_mat.jl b/src/arb/acb_mat.jl index 47fbaf416..d16beaf9b 100644 --- a/src/arb/acb_mat.jl +++ b/src/arb/acb_mat.jl @@ -11,8 +11,7 @@ ############################################################################### function similar(::AcbMatrix, R::AcbField, r::Int, c::Int) - z = AcbMatrix(r, c) - z.base_ring = R + z = AcbMatrix(R, r, c) return z end @@ -744,8 +743,7 @@ end ############################################################################### function (x::AcbMatrixSpace)() - z = AcbMatrix(nrows(x), ncols(x)) - z.base_ring = x.base_ring + z = AcbMatrix(base_ring(x), nrows(x), ncols(x)) return z end @@ -890,8 +888,7 @@ function zero_matrix(R::AcbField, r::Int, c::Int) if r < 0 || c < 0 error("dimensions must not be negative") end - z = AcbMatrix(r, c) - z.base_ring = R + z = AcbMatrix(R, r, c) return z end @@ -905,9 +902,8 @@ function identity_matrix(R::AcbField, n::Int) if n < 0 error("dimension must not be negative") end - z = AcbMatrix(n, n) + z = AcbMatrix(R, n, n) ccall((:acb_mat_one, libflint), Nothing, (Ref{AcbMatrix}, ), z) - z.base_ring = R return z end diff --git a/src/arb/arb_mat.jl b/src/arb/arb_mat.jl index aed33f313..adea8c0e8 100644 --- a/src/arb/arb_mat.jl +++ b/src/arb/arb_mat.jl @@ -11,8 +11,7 @@ ############################################################################### function similar(::ArbMatrix, R::ArbField, r::Int, c::Int) - z = ArbMatrix(r, c) - z.base_ring = R + z = ArbMatrix(R, r, c) return z end @@ -81,9 +80,8 @@ number_of_rows(a::ArbMatrix) = a.r number_of_columns(a::ArbMatrix) = a.c function deepcopy_internal(x::ArbMatrix, dict::IdDict) - z = ArbMatrix(nrows(x), ncols(x)) + z = ArbMatrix(base_ring(x), nrows(x), ncols(x)) ccall((:arb_mat_set, libflint), Nothing, (Ref{ArbMatrix}, Ref{ArbMatrix}), z, x) - z.base_ring = x.base_ring return z end @@ -711,8 +709,7 @@ end ############################################################################### function (x::ArbMatrixSpace)() - z = ArbMatrix(nrows(x), ncols(x)) - z.base_ring = x.base_ring + z = ArbMatrix(base_ring(x), nrows(x), ncols(x)) return z end @@ -787,8 +784,7 @@ function zero_matrix(R::ArbField, r::Int, c::Int) if r < 0 || c < 0 error("dimensions must not be negative") end - z = ArbMatrix(r, c) - z.base_ring = R + z = ArbMatrix(R, r, c) return z end @@ -802,9 +798,8 @@ function identity_matrix(R::ArbField, n::Int) if n < 0 error("dimension must not be negative") end - z = ArbMatrix(n, n) + z = ArbMatrix(R, n, n) ccall((:arb_mat_one, libflint), Nothing, (Ref{ArbMatrix}, ), z) - z.base_ring = R return z end diff --git a/src/flint/FlintTypes.jl b/src/flint/FlintTypes.jl index dfed74ad5..2beb36ac6 100644 --- a/src/flint/FlintTypes.jl +++ b/src/flint/FlintTypes.jl @@ -4697,7 +4697,10 @@ mutable struct QQMatrix <: MatElem{QQFieldElem} rows::Ptr{Ptr{QQFieldElem}} view_parent - # used by windows, not finalised!! + # MatElem interface + QQMatrix(::QQField, r::Int, c::Int) = QQMatrix(r, c) + + # Used by view, not finalised!! function QQMatrix() return new() end @@ -4740,6 +4743,9 @@ mutable struct ZZMatrix <: MatElem{ZZRingElem} rows::Ptr{Ptr{ZZRingElem}} view_parent + # MatElem interface + ZZMatrix(::ZZRing, r::Int, c::Int) = ZZMatrix(r, c) + # Used by view, not finalised!! function ZZMatrix() return new() @@ -4785,10 +4791,16 @@ mutable struct zzModMatrix <: MatElem{zzModRingElem} base_ring::zzModRing view_parent + # MatElem interface + function zzModMatrix(R::zzModRing, r::Int, c::Int) + z = zzModMatrix(r, c, R.n) + z.base_ring = R + return z + end + # Used by view, not finalised!! function zzModMatrix() - z = new() - return z + return new() end function zzModMatrix(r::Int, c::Int, n::UInt) @@ -4929,10 +4941,16 @@ mutable struct ZZModMatrix <: MatElem{ZZModRingElem} base_ring::ZZModRing view_parent + # MatElem interface + function ZZModMatrix(R::ZZModRing, r::Int, c::Int) + z = ZZModMatrix(r, c, R.ninv) + z.base_ring = R + return z + end + # Used by view, not finalised!! function ZZModMatrix() - z = new() - return z + return new() end function ZZModMatrix(r::Int, c::Int, ctx::fmpz_mod_ctx_struct) @@ -5087,10 +5105,16 @@ mutable struct FpMatrix <: MatElem{FpFieldElem} base_ring::FpField view_parent + # MatElem interface + function FpMatrix(R::FpField, r::Int, c::Int) + z = FpMatrix(r, c, R.ninv) + z.base_ring = R + return z + end + # Used by view, not finalised!! function FpMatrix() - z = new() - return z + return new() end function FpMatrix(r::Int, c::Int, ctx::fmpz_mod_ctx_struct) @@ -5197,10 +5221,16 @@ mutable struct fpMatrix <: MatElem{fpFieldElem} base_ring::fpField view_parent + # MatElem interface + function fpMatrix(R::fpField, r::Int, c::Int) + z = fpMatrix(r, c, R.n) + z.base_ring = R + return z + end + # Used by view, not finalised!! function fpMatrix() - z = new() - return z + return new() end function fpMatrix(r::Int, c::Int, n::UInt) @@ -5775,7 +5805,12 @@ mutable struct FqMatrix <: MatElem{FqFieldElem} base_ring::FqField view_parent - # used by windows, not finalised!! + # MatElem interface + function FqMatrix(R::FqField, r::Int, c::Int) + return FqMatrix(r, c, R) + end + + # Used by view, not finalised!! function FqMatrix() return new() end @@ -5941,7 +5976,12 @@ mutable struct FqPolyRepMatrix <: MatElem{FqPolyRepFieldElem} base_ring::FqPolyRepField view_parent - # used by windows, not finalised!! + # MatElem interface + function FqPolyRepMatrix(R::FqPolyRepField, r::Int, c::Int) + return FqPolyRepMatrix(r, c, R) + end + + # Used by view, not finalised!! function FqPolyRepMatrix() return new() end @@ -6074,7 +6114,12 @@ mutable struct fqPolyRepMatrix <: MatElem{fqPolyRepFieldElem} base_ring::fqPolyRepField view_parent - # used by windows, not finalised!! + # MatElem interface + function fqPolyRepMatrix(R::fqPolyRepField, r::Int, c::Int) + return fqPolyRepMatrix(r, c, R) + end + + # Used by view, not finalised!! function fqPolyRepMatrix() return new() end diff --git a/src/flint/fmpz_mod_mat.jl b/src/flint/fmpz_mod_mat.jl index 7cbf83abb..e9c62cbe6 100644 --- a/src/flint/fmpz_mod_mat.jl +++ b/src/flint/fmpz_mod_mat.jl @@ -19,8 +19,7 @@ dense_matrix_type(::Type{ZZModRingElem}) = ZZModMatrix ############################################################################### function similar(::MatElem, R::ZZModRing, r::Int, c::Int) - z = ZZModMatrix(r, c, R.ninv) - z.base_ring = R + z = ZZModMatrix(R, r, c) return z end @@ -753,8 +752,7 @@ promote_rule(::Type{ZZModMatrix}, ::Type{ZZRingElem}) = ZZModMatrix ################################################################################ function (a::ZZModMatrixSpace)() - z = ZZModMatrix(nrows(a), ncols(a), base_ring(a).ninv) - z.base_ring = a.base_ring + z = ZZModMatrix(base_ring(a), nrows(a), ncols(a)) return z end @@ -818,11 +816,10 @@ end function (a::ZZModMatrixSpace)(b::ZZMatrix) (ncols(a) != b.c || nrows(a) != b.r) && error("Dimensions do not fit") - z = ZZModMatrix(b.r, b.c, base_ring(a).ninv) + z = ZZModMatrix(base_ring(a), b.r, b.c) ccall((:fmpz_mod_mat_set_fmpz_mat, libflint), Nothing, (Ref{ZZModMatrix}, Ref{ZZMatrix}, Ref{fmpz_mod_ctx_struct}), z, b, base_ring(a).ninv) - z.base_ring = a.base_ring return z end @@ -855,8 +852,7 @@ function zero_matrix(R::ZZModRing, r::Int, c::Int) if r < 0 || c < 0 error("dimensions must not be negative") end - z = ZZModMatrix(r, c, R.ninv) - z.base_ring = R + z = ZZModMatrix(R, r, c) return z end diff --git a/src/flint/gfp_fmpz_mat.jl b/src/flint/gfp_fmpz_mat.jl index 0c706dca3..f0edfaac5 100644 --- a/src/flint/gfp_fmpz_mat.jl +++ b/src/flint/gfp_fmpz_mat.jl @@ -19,8 +19,7 @@ dense_matrix_type(::Type{FpFieldElem}) = FpMatrix ############################################################################### function similar(::MatElem, R::FpField, r::Int, c::Int) - z = FpMatrix(r, c, R.ninv) - z.base_ring = R + z = FpMatrix(R, r, c) return z end @@ -227,8 +226,7 @@ end ################################################################################ function (a::FpMatrixSpace)() - z = FpMatrix(nrows(a), ncols(a), base_ring(a).ninv) - z.base_ring = a.base_ring + z = FpMatrix(base_ring(a), nrows(a), ncols(a)) return z end @@ -328,8 +326,7 @@ function zero_matrix(R::FpField, r::Int, c::Int) if r < 0 || c < 0 error("dimensions must not be negative") end - z = FpMatrix(r, c, R.ninv) - z.base_ring = R + z = FpMatrix(R, r, c) return z end