Skip to content

Commit

Permalink
Ensure MatElem subtypes T have T(R::Ring, r::Int, c::Int) constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
fingolfin committed Oct 8, 2024
1 parent ef20920 commit 8aacd64
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 44 deletions.
20 changes: 20 additions & 0 deletions src/arb/ArbTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Check warning on line 800 in src/arb/ArbTypes.jl

View check run for this annotation

Codecov / codecov/patch

src/arb/ArbTypes.jl#L800

Added line #L800 was not covered by tests

function RealMatrix(r::Int, c::Int)
z = new()
ccall((:arb_mat_init, libflint), Nothing, (Ref{RealMatrix}, Int, Int), z, r, c)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Check warning on line 990 in src/arb/ArbTypes.jl

View check run for this annotation

Codecov / codecov/patch

src/arb/ArbTypes.jl#L990

Added line #L990 was not covered by tests

function ComplexMatrix(r::Int, c::Int)
z = new()
ccall((:acb_mat_init, libflint), Nothing, (Ref{ComplexMatrix}, Int, Int), z, r, c)
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 4 additions & 8 deletions src/arb/acb_mat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand All @@ -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

Expand Down
15 changes: 5 additions & 10 deletions src/arb/arb_mat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand All @@ -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

Expand Down
69 changes: 57 additions & 12 deletions src/flint/FlintTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Check warning on line 4701 in src/flint/FlintTypes.jl

View check run for this annotation

Codecov / codecov/patch

src/flint/FlintTypes.jl#L4701

Added line #L4701 was not covered by tests

# Used by view, not finalised!!
function QQMatrix()
return new()
end
Expand Down Expand Up @@ -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)

Check warning on line 4747 in src/flint/FlintTypes.jl

View check run for this annotation

Codecov / codecov/patch

src/flint/FlintTypes.jl#L4747

Added line #L4747 was not covered by tests

# Used by view, not finalised!!
function ZZMatrix()
return new()
Expand Down Expand Up @@ -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

Check warning on line 4798 in src/flint/FlintTypes.jl

View check run for this annotation

Codecov / codecov/patch

src/flint/FlintTypes.jl#L4795-L4798

Added lines #L4795 - L4798 were not covered by tests
end

# Used by view, not finalised!!
function zzModMatrix()
z = new()
return z
return new()
end

function zzModMatrix(r::Int, c::Int, n::UInt)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

Check warning on line 5228 in src/flint/FlintTypes.jl

View check run for this annotation

Codecov / codecov/patch

src/flint/FlintTypes.jl#L5225-L5228

Added lines #L5225 - L5228 were not covered by tests
end

# Used by view, not finalised!!
function fpMatrix()
z = new()
return z
return new()
end

function fpMatrix(r::Int, c::Int, n::UInt)
Expand Down Expand Up @@ -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)

Check warning on line 5810 in src/flint/FlintTypes.jl

View check run for this annotation

Codecov / codecov/patch

src/flint/FlintTypes.jl#L5809-L5810

Added lines #L5809 - L5810 were not covered by tests
end

# Used by view, not finalised!!
function FqMatrix()
return new()
end
Expand Down Expand Up @@ -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)

Check warning on line 5981 in src/flint/FlintTypes.jl

View check run for this annotation

Codecov / codecov/patch

src/flint/FlintTypes.jl#L5980-L5981

Added lines #L5980 - L5981 were not covered by tests
end

# Used by view, not finalised!!
function FqPolyRepMatrix()
return new()
end
Expand Down Expand Up @@ -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)

Check warning on line 6119 in src/flint/FlintTypes.jl

View check run for this annotation

Codecov / codecov/patch

src/flint/FlintTypes.jl#L6118-L6119

Added lines #L6118 - L6119 were not covered by tests
end

# Used by view, not finalised!!
function fqPolyRepMatrix()
return new()
end
Expand Down
12 changes: 4 additions & 8 deletions src/flint/fmpz_mod_mat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
9 changes: 3 additions & 6 deletions src/flint/gfp_fmpz_mat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 8aacd64

Please sign in to comment.