Skip to content

Commit ba35a12

Browse files
committed
Add set! methods for QQ/ZZMPolyRingElem
1 parent f143dcb commit ba35a12

File tree

3 files changed

+66
-45
lines changed

3 files changed

+66
-45
lines changed

src/flint/FlintTypes.jl

Lines changed: 6 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,25 +1158,8 @@ mutable struct ZZMPolyRingElem <: MPolyRingElem{ZZRingElem}
11581158
return z
11591159
end
11601160

1161-
function ZZMPolyRingElem(ctx::ZZMPolyRing, a::ZZRingElem)
1162-
z = ZZMPolyRingElem(ctx)
1163-
@ccall libflint.fmpz_mpoly_set_fmpz(z::Ref{ZZMPolyRingElem}, a::Ref{ZZRingElem}, ctx::Ref{ZZMPolyRing})::Nothing
1164-
return z
1165-
end
1166-
1167-
function ZZMPolyRingElem(ctx::ZZMPolyRing, a::Int)
1168-
z = ZZMPolyRingElem(ctx)
1169-
@ccall libflint.fmpz_mpoly_set_si(z::Ref{ZZMPolyRingElem}, a::Int, ctx::Ref{ZZMPolyRing})::Nothing
1170-
return z
1171-
end
1172-
1173-
function ZZMPolyRingElem(ctx::ZZMPolyRing, a::UInt)
1174-
z = ZZMPolyRingElem(ctx)
1175-
@ccall libflint.fmpz_mpoly_set_ui(z::Ref{ZZMPolyRingElem}, a::UInt, ctx::Ref{ZZMPolyRing})::Nothing
1176-
return z
1177-
end
1178-
1179-
ZZMPolyRingElem(ctx::ZZMPolyRing, a::Integer) = ZZMPolyRingElem(ctx, flintify(a))
1161+
ZZMPolyRingElem(ctx::ZZMPolyRing, a::ZZRingElem) = set!(ZZMPolyRingElem(ctx), a)
1162+
ZZMPolyRingElem(ctx::ZZMPolyRing, a::Integer) = set!(ZZMPolyRingElem(ctx), a)
11801163
end
11811164

11821165
function _fmpz_mpoly_clear_fn(a::ZZMPolyRingElem)
@@ -1316,29 +1299,11 @@ mutable struct QQMPolyRingElem <: MPolyRingElem{QQFieldElem}
13161299
return z
13171300
end
13181301

1319-
function QQMPolyRingElem(ctx::QQMPolyRing, a::ZZRingElem)
1320-
z = QQMPolyRingElem(ctx)
1321-
@ccall libflint.fmpq_mpoly_set_fmpz(z::Ref{QQMPolyRingElem}, a::Ref{ZZRingElem}, ctx::Ref{QQMPolyRing})::Nothing
1322-
return z
1323-
end
1302+
QQMPolyRingElem(ctx::QQMPolyRing, a::ZZRingElem) = set!(QQMPolyRingElem(ctx), a)
1303+
QQMPolyRingElem(ctx::QQMPolyRing, a::QQFieldElem) = set!(QQMPolyRingElem(ctx), a)
1304+
QQMPolyRingElem(ctx::QQMPolyRing, a::Integer) = set!(QQMPolyRingElem(ctx), a)
1305+
QQMPolyRingElem(ctx::QQMPolyRing, a::Rational) = set!(QQMPolyRingElem(ctx), a)
13241306

1325-
function QQMPolyRingElem(ctx::QQMPolyRing, a::QQFieldElem)
1326-
z = QQMPolyRingElem(ctx)
1327-
@ccall libflint.fmpq_mpoly_set_fmpq(z::Ref{QQMPolyRingElem}, a::Ref{QQFieldElem}, ctx::Ref{QQMPolyRing})::Nothing
1328-
return z
1329-
end
1330-
1331-
function QQMPolyRingElem(ctx::QQMPolyRing, a::Int)
1332-
z = QQMPolyRingElem(ctx)
1333-
@ccall libflint.fmpq_mpoly_set_si(z::Ref{QQMPolyRingElem}, a::Int, ctx::Ref{QQMPolyRing})::Nothing
1334-
return z
1335-
end
1336-
1337-
function QQMPolyRingElem(ctx::QQMPolyRing, a::UInt)
1338-
z = QQMPolyRingElem(ctx)
1339-
@ccall libflint.fmpq_mpoly_set_ui(z::Ref{QQMPolyRingElem}, a::UInt, ctx::Ref{QQMPolyRing})::Nothing
1340-
return z
1341-
end
13421307
end
13431308

13441309
function _fmpq_mpoly_clear_fn(a::QQMPolyRingElem)

src/flint/fmpq_mpoly.jl

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ end
6565

6666
function deepcopy_internal(a::QQMPolyRingElem, dict::IdDict)
6767
z = parent(a)()
68-
@ccall libflint.fmpq_mpoly_set(z::Ref{QQMPolyRingElem}, a::Ref{QQMPolyRingElem}, a.parent::Ref{QQMPolyRing})::Nothing
69-
return z
68+
return set!(z, a)
7069
end
7170

7271
function length(a::QQMPolyRingElem)
@@ -673,6 +672,37 @@ function neg!(a::QQMPolyRingElem, b::QQMPolyRingElem)
673672
return a
674673
end
675674

675+
#
676+
677+
function set!(z::QQMPolyRingElem, a::QQMPolyRingElem)
678+
@ccall libflint.fmpq_mpoly_set(z::Ref{QQMPolyRingElem}, a::Ref{QQMPolyRingElem}, parent(a)::Ref{QQMPolyRing})::Nothing
679+
return z
680+
end
681+
682+
function set!(z::QQMPolyRingElem, a::QQFieldElemOrPtr)
683+
@ccall libflint.fmpq_mpoly_set_fmpq(z::Ref{QQMPolyRingElem}, a::Ref{QQFieldElem}, parent(z)::Ref{QQMPolyRing})::Nothing
684+
return z
685+
end
686+
687+
function set!(z::QQMPolyRingElem, a::ZZRingElemOrPtr)
688+
@ccall libflint.fmpq_mpoly_set_fmpz(z::Ref{QQMPolyRingElem}, a::Ref{ZZRingElem}, parent(z)::Ref{QQMPolyRing})::Nothing
689+
return z
690+
end
691+
692+
function set!(z::QQMPolyRingElem, a::Int)
693+
@ccall libflint.fmpq_mpoly_set_si(z::Ref{QQMPolyRingElem}, a::Int, parent(z)::Ref{QQMPolyRing})::Nothing
694+
return z
695+
end
696+
697+
function set!(z::QQMPolyRingElem, a::UInt)
698+
@ccall libflint.fmpq_mpoly_set_ui(z::Ref{QQMPolyRingElem}, a::UInt, parent(z)::Ref{QQMPolyRing})::Nothing
699+
return z
700+
end
701+
702+
set!(z::QQMPolyRingElem, a::Union{Integer, Rational}) = set!(z, flintify(a))
703+
704+
#
705+
676706
function add!(a::QQMPolyRingElem, b::QQMPolyRingElem, c::QQMPolyRingElem)
677707
@ccall libflint.fmpq_mpoly_add(a::Ref{QQMPolyRingElem}, b::Ref{QQMPolyRingElem}, c::Ref{QQMPolyRingElem}, a.parent::Ref{QQMPolyRing})::Nothing
678708
return a

src/flint/fmpz_mpoly.jl

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ end
6464

6565
function deepcopy_internal(a::ZZMPolyRingElem, dict::IdDict)
6666
z = parent(a)()
67-
@ccall libflint.fmpz_mpoly_set(z::Ref{ZZMPolyRingElem}, a::Ref{ZZMPolyRingElem}, a.parent::Ref{ZZMPolyRing})::Nothing
68-
return z
67+
return set!(z, a)
6968
end
7069

7170
function length(a::ZZMPolyRingElem)
@@ -636,6 +635,33 @@ function neg!(z::ZZMPolyRingElem, a::ZZMPolyRingElem)
636635
return z
637636
end
638637

638+
#
639+
640+
function set!(z::ZZMPolyRingElem, a::ZZMPolyRingElem)
641+
@ccall libflint.fmpz_mpoly_set(z::Ref{ZZMPolyRingElem}, a::Ref{ZZMPolyRingElem}, parent(a)::Ref{ZZMPolyRing})::Nothing
642+
return z
643+
end
644+
645+
function set!(z::ZZMPolyRingElem, a::ZZRingElemOrPtr)
646+
@ccall libflint.fmpz_mpoly_set_fmpz(z::Ref{ZZMPolyRingElem}, a::Ref{ZZRingElem}, parent(z)::Ref{ZZMPolyRing})::Nothing
647+
return z
648+
end
649+
650+
function set!(z::ZZMPolyRingElem, a::Int)
651+
@ccall libflint.fmpz_mpoly_set_si(z::Ref{ZZMPolyRingElem}, a::Int, parent(z)::Ref{ZZMPolyRing})::Nothing
652+
return z
653+
end
654+
655+
function set!(z::ZZMPolyRingElem, a::UInt)
656+
@ccall libflint.fmpz_mpoly_set_ui(z::Ref{ZZMPolyRingElem}, a::UInt, parent(z)::Ref{ZZMPolyRing})::Nothing
657+
return z
658+
end
659+
660+
set!(z::ZZMPolyRingElem, a::Union{Integer, Rational}) = set!(z, flintify(a))
661+
662+
#
663+
664+
639665
function add!(z::ZZMPolyRingElem, a::ZZMPolyRingElem, b::ZZMPolyRingElem)
640666
@ccall libflint.fmpz_mpoly_add(z::Ref{ZZMPolyRingElem}, a::Ref{ZZMPolyRingElem}, b::Ref{ZZMPolyRingElem}, a.parent::Ref{ZZMPolyRing})::Nothing
641667
return z

0 commit comments

Comments
 (0)