From ff380af9a189115965cca8f60f03f3a07790f226 Mon Sep 17 00:00:00 2001 From: Marc Mezzarobba Date: Sun, 2 Jul 2023 13:42:33 +0200 Subject: [PATCH 1/3] missing include in t-NTL-interface --- src/interfaces/test/t-NTL-interface.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/interfaces/test/t-NTL-interface.cpp b/src/interfaces/test/t-NTL-interface.cpp index 98119de3d5..a4dc325fb2 100644 --- a/src/interfaces/test/t-NTL-interface.cpp +++ b/src/interfaces/test/t-NTL-interface.cpp @@ -18,6 +18,7 @@ #include #include "flint.h" #include "fmpz.h" +#include "fmpz_mod.h" #include "fmpz_poly.h" #include "fmpz_mod_poly.h" #include "ulong_extras.h" From e78c89a164b72733e4ad24e1c083719341c25215 Mon Sep 17 00:00:00 2001 From: Marc Mezzarobba Date: Sun, 2 Jul 2023 13:43:16 +0200 Subject: [PATCH 2/3] actually build the NTL interface when asked for it --- Makefile.in | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Makefile.in b/Makefile.in index 1c7b55da80..6a7c976ddc 100644 --- a/Makefile.in +++ b/Makefile.in @@ -82,6 +82,9 @@ CPPFLAGS2:=-L$(FLINT_DIR) $(CPPFLAGS) LIB_CPPFLAGS:=@LIB_CPPFLAGS@ CXXFLAGS:=@CXXFLAGS@ LIBS:=@LIBS@ +ifneq ($(WANT_NTL), 0) +LIBS += -lstdc++ -lntl +endif LIBS2:=$(LIBS) -lflint PIC_FLAG:=@PIC_FLAG@ @@ -305,10 +308,6 @@ define xxx_LOBJS $(1)_LOBJS := $(patsubst $(SRC_DIR)/%.c,$(BUILD_DIR)/%.lo,$($(1)_SOURCES)) endef $(foreach dir, $(DIRS), $(eval $(call xxx_LOBJS,$(dir)))) -LOBJS := $(foreach dir, $(DIRS), $($(dir)_LOBJS)) -ifneq ($(WANT_NTL), 0) -LOBJS += $(BUILD_DIR)/interfaces/NTL-interface.lo -endif endif ################################################################################ @@ -375,6 +374,9 @@ $(BUILD_DIR)/$(1)_merged.lo: $($(1)_LOBJS) | $(BUILD_DIR) endef $(foreach dir, $(DIRS), $(eval $(call xxx_merged_lobj_rule,$(dir)))) MERGED_LOBJS:=$(foreach dir, $(DIRS),$(BUILD_DIR)/$(dir)_merged.lo) +ifneq ($(WANT_NTL), 0) +MERGED_LOBJS += $(BUILD_DIR)/interfaces/NTL-interface.lo +endif $(FLINT_DIR)/$(FLINT_LIB_FULL): $(MERGED_LOBJS) $(CC) $(CFLAGS) -shared $(EXTRA_SHARED_FLAGS) $(MERGED_LOBJS) -o $(FLINT_LIB_FULL) $(LDFLAGS) $(LIBS) @@ -527,7 +529,7 @@ endef $(foreach dir, $(DIRS), $(eval $(call xxx_OBJS_rule,$(dir)))) ifneq ($(WANT_NTL), 0) -$(BUILD_DIR)/interfaces/NTL-interface.o: $(SRC_DIR)/interfaces/test/t-NTL-interface.cpp | $(BUILD_DIR)/interfaces +$(BUILD_DIR)/interfaces/NTL-interface.o: $(SRC_DIR)/interfaces/NTL-interface.cpp | $(BUILD_DIR)/interfaces @echo " CXX $(@:$(BUILD_DIR)/%=%)" @$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(LIB_CPPFLAGS) -c $< -o $@ -MMD -MF $(@:%=%.d) endif @@ -547,7 +549,7 @@ endef $(foreach dir, $(DIRS), $(eval $(call xxx_LOBJS_rule,$(dir)))) ifneq ($(WANT_NTL), 0) -$(BUILD_DIR)/interfaces/NTL-interface.lo: $(SRC_DIR)/interfaces/test/t-NTL-interface.cpp | $(BUILD_DIR)/interfaces +$(BUILD_DIR)/interfaces/NTL-interface.lo: $(SRC_DIR)/interfaces/NTL-interface.cpp | $(BUILD_DIR)/interfaces @echo " CXX $(@:$(BUILD_DIR)/%=%)" @$(CXX) $(PIC_FLAG) $(CXXFLAGS) $(CPPFLAGS) $(LIB_CPPFLAGS) -c $< -o $@ -MMD -MF $(@:%=.d) endif From 14bceec34145a20e767b41ccc24bb4a40cfa957d Mon Sep 17 00:00:00 2001 From: Marc Mezzarobba Date: Tue, 10 Oct 2023 17:03:34 +0200 Subject: [PATCH 3/3] make the NTL interface header-only --- Makefile.in | 31 +- configure.ac | 6 +- src/NTL-interface.h | 425 ++++++++++++++++++++++++++-- src/interfaces/NTL-interface.cpp | 454 ------------------------------ src/interfaces/doc/interfaces.txt | 5 +- 5 files changed, 402 insertions(+), 519 deletions(-) delete mode 100644 src/interfaces/NTL-interface.cpp diff --git a/Makefile.in b/Makefile.in index 6a7c976ddc..21f7f0640b 100644 --- a/Makefile.in +++ b/Makefile.in @@ -230,10 +230,8 @@ SINGLE_HEADERS := \ fq_types.h fq_nmod_types.h \ fq_zech_types.h \ arf_types.h acf_types.h \ - arb_types.h acb_types.h -ifneq ($(WANT_NTL), 0) -SINGLE_HEADERS += NTL-interface.h -endif + arb_types.h acb_types.h \ + NTL-interface.h HEADERS := $(patsubst %,$(SRC_DIR)/%, \ $(patsubst %,%,$(SINGLE_HEADERS)) \ @@ -250,11 +248,6 @@ $(1)_SOURCES := $(wildcard $(SRC_DIR)/$(1)/*.c) endef $(foreach dir, $(DIRS), $(eval $(call xxx_SOURCES,$(dir)))) SOURCES := $(foreach dir,$(DIRS),$($(dir)_SOURCES)) -# NOTE: We do not add CPP files to C files in SOURCES in order to not screw up -# the `patsubst' in the object files. -ifneq ($(WANT_NTL), 0) -interfaces_SOURCES := $(SRC_DIR)/interfaces/NTL-interface.cpp -endif define xxx_PROF_SOURCES $(1)_PROF_SOURCES := $(wildcard $(SRC_DIR)/$(1)/profile/*.c) @@ -271,6 +264,8 @@ endef _TEST_SOURCES := $(wildcard $(SRC_DIR)/test/*.c) $(foreach dir, $(DIRS), $(eval $(call xxx_TEST_SOURCES,$(dir)))) TEST_SOURCES := $(foreach dir,$(DIRS),$($(dir)_TEST_SOURCES)) $(_TEST_SOURCES) $(fq_zech_vec_TEST_SOURCES) +# NOTE: We do not add CPP files to C files in SOURCES in order to not screw up +# the `patsubst' in the object files. ifneq ($(WANT_NTL), 0) interfaces_TEST_SOURCES := $(SRC_DIR)/interfaces/test/t-NTL-interface.cpp endif @@ -294,9 +289,6 @@ $(1)_OBJS := $(patsubst $(SRC_DIR)/%.c,$(BUILD_DIR)/%.o,$($(1)_SOURCES)) endef $(foreach dir, $(DIRS), $(eval $(call xxx_OBJS,$(dir)))) OBJS := $(foreach dir, $(DIRS), $($(dir)_OBJS)) -ifneq ($(WANT_NTL), 0) -OBJS += $(BUILD_DIR)/interfaces/NTL-interface.o -endif endif ################################################################################ @@ -374,9 +366,6 @@ $(BUILD_DIR)/$(1)_merged.lo: $($(1)_LOBJS) | $(BUILD_DIR) endef $(foreach dir, $(DIRS), $(eval $(call xxx_merged_lobj_rule,$(dir)))) MERGED_LOBJS:=$(foreach dir, $(DIRS),$(BUILD_DIR)/$(dir)_merged.lo) -ifneq ($(WANT_NTL), 0) -MERGED_LOBJS += $(BUILD_DIR)/interfaces/NTL-interface.lo -endif $(FLINT_DIR)/$(FLINT_LIB_FULL): $(MERGED_LOBJS) $(CC) $(CFLAGS) -shared $(EXTRA_SHARED_FLAGS) $(MERGED_LOBJS) -o $(FLINT_LIB_FULL) $(LDFLAGS) $(LIBS) @@ -527,12 +516,6 @@ $(BUILD_DIR)/$(1)/%.o: $(SRC_DIR)/$(1)/%.c | $(BUILD_DIR)/$(1) endef $(foreach dir, $(DIRS), $(eval $(call xxx_OBJS_rule,$(dir)))) - -ifneq ($(WANT_NTL), 0) -$(BUILD_DIR)/interfaces/NTL-interface.o: $(SRC_DIR)/interfaces/NTL-interface.cpp | $(BUILD_DIR)/interfaces - @echo " CXX $(@:$(BUILD_DIR)/%=%)" - @$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(LIB_CPPFLAGS) -c $< -o $@ -MMD -MF $(@:%=%.d) -endif endif ################################################################################ @@ -547,12 +530,6 @@ $(BUILD_DIR)/$(1)/%.lo: $(SRC_DIR)/$(1)/%.c | $(BUILD_DIR)/$(1) endef $(foreach dir, $(DIRS), $(eval $(call xxx_LOBJS_rule,$(dir)))) - -ifneq ($(WANT_NTL), 0) -$(BUILD_DIR)/interfaces/NTL-interface.lo: $(SRC_DIR)/interfaces/NTL-interface.cpp | $(BUILD_DIR)/interfaces - @echo " CXX $(@:$(BUILD_DIR)/%=%)" - @$(CXX) $(PIC_FLAG) $(CXXFLAGS) $(CPPFLAGS) $(LIB_CPPFLAGS) -c $< -o $@ -MMD -MF $(@:%=.d) -endif endif ################################################################################ diff --git a/configure.ac b/configure.ac index 70702306b6..0e829fa504 100644 --- a/configure.ac +++ b/configure.ac @@ -411,19 +411,19 @@ then fi AC_ARG_WITH(ntl_include, -[AS_HELP_STRING([--with-ntl-include=DIR],[Use NTL and specify its include directory])], +[AS_HELP_STRING([--with-ntl-include=DIR],[Use NTL (in tests) and specify its include directory])], CPPFLAGS="$CPPFLAGS -I$withval" ntl_include_path="$withval" ) AC_ARG_WITH(ntl_lib, -[AS_HELP_STRING([--with-ntl-lib=DIR],[Use NTL and specify its library directory])], +[AS_HELP_STRING([--with-ntl-lib=DIR],[Use NTL (in tests) and specify its library directory])], LDFLAGS="$LDFLAGS -L$withval" ntl_lib_path="$withval" ) AC_ARG_WITH(ntl, -[AS_HELP_STRING([--with-ntl[[=DIR]]],[Use NTL and optionally specify its install directory])], +[AS_HELP_STRING([--with-ntl[[=DIR]]],[Use NTL (in tests) and optionally specify its install directory])], if test "$with_ntl" = "yes"; then : diff --git a/src/NTL-interface.h b/src/NTL-interface.h index 3de7c4d50a..d4acb3618d 100644 --- a/src/NTL-interface.h +++ b/src/NTL-interface.h @@ -35,120 +35,483 @@ #include "fq.h" #include "fq_poly.h" -#ifdef __cplusplus -extern "C" { -#endif +NTL_CLIENT /* Converts an NTL ZZ to an fmpz_t. Assumes the fmpz_t has already been allocated to have sufficient space. */ -void fmpz_set_ZZ(fmpz_t rop, const NTL_NNS ZZ& op); +inline void fmpz_set_ZZ(fmpz_t rop, const ZZ& op) +{ + const _ntl_gbigint x = op.rep; + + if (!x) + fmpz_zero(rop); + else + { + const mp_size_t lw = op.size(); + const mp_limb_t *xp = ((mp_limb_t *) (((slong *) (x)) + 2)); + + if (lw == 0) + fmpz_zero(rop); + else if (lw == 1) + fmpz_set_ui(rop, xp[0]); + else + { + __mpz_struct *mf = _fmpz_promote(rop); + + mpz_import(mf, lw, -1, sizeof(mp_limb_t), 0, 0, xp); + } + + if (op < WORD(0)) + fmpz_neg(rop, rop); + } +} /* Converts an fmpz_t to an NTL ZZ. Allocation is automatically handled. */ -void fmpz_get_ZZ(NTL_NNS ZZ& rop, const fmpz_t op); - +inline void fmpz_get_ZZ(NTL_NNS ZZ& rop, const fmpz_t op) +{ + mp_limb_t *xp; + _ntl_gbigint *x = &rop.rep; + slong lw = fmpz_size(op); + fmpz c = *op; + + if (lw == 0) + { + if (*x) ((slong *)(*x))[1] = 0; // size + return; + } + + _ntl_gsetlength(x, lw); + xp = ((mp_limb_t *) (((slong *) (*x)) + 2)); // data + + if (COEFF_IS_MPZ(c)) + { + __mpz_struct * m = COEFF_TO_PTR(c); + mpn_copyi(xp, m->_mp_d, lw); + } else + { + if (c < WORD(0)) + xp[0] = -c; + else + xp[0] = c; + } + + if (fmpz_sgn(op) < 0) ((slong *)(*x))[1] = -lw; + else ((slong *)(*x))[1] = lw; +} /* Converts an NTL ZZ_p to an fmpz_t. Assumes the fmpz_t has already been allocated to have sufficient space. */ -void fmpz_set_ZZ_p(fmpz_t rop, const NTL_NNS ZZ_p& op); +inline void fmpz_set_ZZ_p(fmpz_t rop, const NTL_NNS ZZ_p& op) +{ + fmpz_set_ZZ(rop, rep(op)); +} /* Converts an fmpz_t to an NTL ZZ_p. Allocation is automatically handled. */ -void fmpz_get_ZZ_p(NTL_NNS ZZ_p& rop, const fmpz_t op); +inline void fmpz_get_ZZ_p(NTL_NNS ZZ_p& rop, const fmpz_t op) +{ + ZZ a; + fmpz_get_ZZ(a, op); + conv(rop, a); +} /* Converts an NTL zz_p to an fmpz_t. */ -void fmpz_set_zz_p(fmpz_t rop, const NTL_NNS zz_p& op); +inline void fmpz_set_zz_p(fmpz_t rop, const NTL_NNS zz_p& op) +{ + fmpz_set_si(rop, rep(op)); +} /* Converts an fmpz_t to an NTL zz_p. */ -void fmpz_get_zz_p(NTL_NNS zz_p& rop, const fmpz_t op); +void fmpz_get_zz_p(NTL_NNS zz_p& rop, const fmpz_t op) +{ + conv(rop, fmpz_get_si(op)); +} /* Converts an fmpz_poly_t to an NTL ZZX. */ -void fmpz_poly_get_ZZX(NTL_NNS ZZX& rop, const fmpz_poly_t op); +inline void fmpz_poly_get_ZZX(NTL_NNS ZZX& rop, const fmpz_poly_t op) +{ + const slong len = op->length; + + if (len == 0) + { + rop = 0; + } + else + { + slong i; + ZZ *ap; + + rop.rep.SetLength(len); + + for (i = 0, ap = rop.rep.elts(); i < len; i++, ap++) + { + fmpz_get_ZZ(*ap, op->coeffs + i); + } + } +} /* Converts an NTL ZZX to an fmpz_poly_t. */ -void fmpz_poly_set_ZZX(fmpz_poly_t rop, const NTL_NNS ZZX& op); - +inline void fmpz_poly_set_ZZX(fmpz_poly_t rop, const NTL_NNS ZZX& op) +{ + const slong len = deg(op) + 1; + + if (len == 0) + { + fmpz_poly_zero(rop); + } + else + { + slong i; + const ZZ *ap; + + fmpz_poly_fit_length(rop, len); + _fmpz_poly_set_length(rop, len); + + for (i = 0, ap = op.rep.elts(); i < len; i++, ap++) + { + fmpz_set_ZZ(rop->coeffs + i, *ap); + } + } +} /* Converts an fmpz_mod_poly_t to an NTL ZZ_pX. */ -void fmpz_mod_poly_get_ZZ_pX(NTL_NNS ZZ_pX& rop, const fmpz_mod_poly_t op, const fmpz_mod_ctx_t ctx); +inline void fmpz_mod_poly_get_ZZ_pX(NTL_NNS ZZ_pX& rop, + const fmpz_mod_poly_t op, const fmpz_mod_ctx_t ctx) +{ + const slong len = op->length; + + if (len == 0) + { + rop = 0; + } + else + { + slong i; + ZZ_p *ap; + + rop.rep.SetLength(len); + + for (i = 0, ap = rop.rep.elts(); i < len; i++, ap++) + { + fmpz_get_ZZ_p(*ap, op->coeffs + i); + } + } +} /* Converts an NTL ZZ_pX to an fmpz_poly_t. */ -void fmpz_mod_poly_set_ZZ_pX(fmpz_mod_poly_t rop, const NTL_NNS ZZ_pX& op, const fmpz_mod_ctx_t ctx); +inline void fmpz_mod_poly_set_ZZ_pX(fmpz_mod_poly_t rop, + const NTL_NNS ZZ_pX& op, const fmpz_mod_ctx_t ctx) +{ + const slong len = deg(op) + 1; + + if (len == 0) + { + fmpz_mod_poly_zero(rop, ctx); + } + else + { + slong i; + const ZZ_p *ap; + + fmpz_mod_poly_fit_length(rop, len, ctx); + _fmpz_mod_poly_set_length(rop, len); + + for (i = 0, ap = op.rep.elts(); i < len; i++, ap++) + { + fmpz_set_ZZ_p(rop->coeffs + i, *ap); + } + } +} /* Converts an fq_t to an NTL ZZ_pE. */ -void fq_get_ZZ_pE(NTL_NNS ZZ_pE& rop, const fq_t op, const fq_ctx_t ctx); +inline void fq_get_ZZ_pE(NTL_NNS ZZ_pE& rop, const fq_t op, const fq_ctx_t ctx) +{ + ZZ_pX p; + + const slong len = op->length; + + if (len == 0) + { + rop = 0; + } + else + { + slong i; + ZZ_p *ap; + + p.rep.SetLength(len); + + for (i = 0, ap = p.rep.elts(); i < len; i++, ap++) + { + fmpz_get_ZZ_p(*ap, op->coeffs + i); + } + conv(rop, p); + } +} /* Converts an NTL ZZ_pE to an fq_t. */ -void fq_set_ZZ_pE(fq_t rop, const NTL_NNS ZZ_pE& op, const fq_ctx_t ctx); - +inline void fq_set_ZZ_pE(fq_t rop, const NTL_NNS ZZ_pE& op, const fq_ctx_t ctx) +{ + const slong len = deg(rep(op)) + 1; + + if (len == 0) + { + fq_zero(rop, ctx); + } + else + { + slong i; + const ZZ_p *ap; + + fmpz_poly_fit_length(rop, len); + _fmpz_poly_set_length(rop, len); + + for (i = 0, ap = rep(op).rep.elts(); i < len; i++, ap++) + { + fmpz_set_ZZ_p(rop->coeffs + i, *ap); + } + _fmpz_poly_normalise(rop); + } +} /* Converts an fq_poly_t to an NTL ZZ_pEX. */ -void fq_poly_get_ZZ_pEX(NTL_NNS ZZ_pEX& rop, const fq_poly_t op, const fq_ctx_t ctx); +inline void fq_poly_get_ZZ_pEX(NTL_NNS ZZ_pEX& rop, const fq_poly_t op, + const fq_ctx_t ctx) +{ + const slong len = op->length; + + if (len == 0) + { + rop = 0; + } + else + { + slong i; + ZZ_pE *ap; + + rop.rep.SetLength(len); + + for (i = 0, ap = rop.rep.elts(); i < len; i++, ap++) + { + fq_get_ZZ_pE(*ap, op->coeffs + i, ctx); + } + } +} /* Converts an NTL ZZ_pEX to an fq_poly_t. */ -void fq_poly_set_ZZ_pEX(fq_poly_t rop, const NTL_NNS ZZ_pEX& op, const fq_ctx_t ctx); +inline void fq_poly_set_ZZ_pEX(fq_poly_t rop, const NTL_NNS ZZ_pEX& op, + const fq_ctx_t ctx) +{ + const slong len = deg(op) + 1; + + if (len == 0) + { + fq_poly_zero(rop, ctx); + } + else + { + slong i; + const ZZ_pE *ap; + + fq_poly_fit_length(rop, len, ctx); + _fq_poly_set_length(rop, len, ctx); + + for (i = 0, ap = op.rep.elts(); i < len; i++, ap++) + { + fq_set_ZZ_pE(rop->coeffs + i, *ap, ctx); + } + _fq_poly_normalise(rop, ctx); + } +} /* Converts an fmpz_mod_poly_t to an NTL zz_pX. */ -void fmpz_mod_poly_get_zz_pX(NTL_NNS zz_pX& rop, const fmpz_mod_poly_t op, const fmpz_mod_ctx_t ctx); +inline void fmpz_mod_poly_get_zz_pX(NTL_NNS zz_pX& rop, + const fmpz_mod_poly_t op, const fmpz_mod_ctx_t ctx) +{ + const slong len = op->length; + + if (len == 0) + { + rop = 0; + } + else + { + slong i; + zz_p *ap; + + rop.rep.SetLength(len); + + for (i = 0, ap = rop.rep.elts(); i < len; i++, ap++) + { + fmpz_get_zz_p(*ap, op->coeffs + i); + } + } +} /* Converts an NTL zz_pX to an fmpz_poly_t. */ -void fmpz_mod_poly_set_zz_pX(fmpz_mod_poly_t rop, const NTL_NNS zz_pX& op, const fmpz_mod_ctx_t ctx); +inline void fmpz_mod_poly_set_zz_pX(fmpz_mod_poly_t rop, + const NTL_NNS zz_pX& op, const fmpz_mod_ctx_t ctx) +{ + const slong len = deg(op) + 1; + + if (len == 0) + { + fmpz_mod_poly_zero(rop, ctx); + } + else + { + slong i; + const zz_p *ap; + + fmpz_mod_poly_fit_length(rop, len, ctx); + _fmpz_mod_poly_set_length(rop, len); + + for (i = 0, ap = op.rep.elts(); i < len; i++, ap++) + { + fmpz_set_zz_p(rop->coeffs + i, *ap); + } + } +} /* Converts an fq_t to an NTL zz_pE. */ -void fq_get_zz_pE(NTL_NNS zz_pE& rop, const fq_t op, const fq_ctx_t ctx); +inline void fq_get_zz_pE(NTL_NNS zz_pE& rop, const fq_t op, const fq_ctx_t ctx) +{ + zz_pX p; + + const slong len = op->length; + + if (len == 0) + { + rop = 0; + } + else + { + slong i; + zz_p *ap; + + p.rep.SetLength(len); + + for (i = 0, ap = p.rep.elts(); i < len; i++, ap++) + { + fmpz_get_zz_p(*ap, op->coeffs + i); + } + conv(rop, p); + } +} /* Converts an NTL zz_pE to an fq_t. */ -void fq_set_zz_pE(fq_t rop, const NTL_NNS zz_pE& op, const fq_ctx_t ctx); - +inline void fq_set_zz_pE(fq_t rop, const NTL_NNS zz_pE& op, const fq_ctx_t ctx) +{ + const slong len = deg(rep(op)) + 1; + + if (len == 0) + { + fq_zero(rop, ctx); + } + else + { + slong i; + const zz_p *ap; + + fmpz_poly_fit_length(rop, len); + _fmpz_poly_set_length(rop, len); + + for (i = 0, ap = rep(op).rep.elts(); i < len; i++, ap++) + { + fmpz_set_zz_p(rop->coeffs + i, *ap); + } + _fmpz_poly_normalise(rop); + } +} /* Converts an fq_poly_t to an NTL zz_pEX. */ -void fq_poly_get_zz_pEX(NTL_NNS zz_pEX& rop, const fq_poly_t op, const fq_ctx_t ctx); +inline void fq_poly_get_zz_pEX(NTL_NNS zz_pEX& rop, const fq_poly_t op, + const fq_ctx_t ctx) +{ + const slong len = op->length; + + if (len == 0) + { + rop = 0; + } + else + { + slong i; + zz_pE *ap; + + rop.rep.SetLength(len); + + for (i = 0, ap = rop.rep.elts(); i < len; i++, ap++) + { + fq_get_zz_pE(*ap, op->coeffs + i, ctx); + } + } +} /* Converts an NTL zz_pEX to an fq_poly_t. */ -void fq_poly_set_zz_pEX(fq_poly_t rop, const NTL_NNS zz_pEX& op, const fq_ctx_t ctx); - -#ifdef __cplusplus +inline void fq_poly_set_zz_pEX(fq_poly_t rop, const NTL_NNS zz_pEX& op, + const fq_ctx_t ctx) +{ + const slong len = deg(op) + 1; + + if (len == 0) + { + fq_poly_zero(rop, ctx); + } + else + { + slong i; + const zz_pE *ap; + + fq_poly_fit_length(rop, len, ctx); + _fq_poly_set_length(rop, len, ctx); + + for (i = 0, ap = op.rep.elts(); i < len; i++, ap++) + { + fq_set_zz_pE(rop->coeffs + i, *ap, ctx); + } + _fq_poly_normalise(rop, ctx); + } } -#endif #endif - diff --git a/src/interfaces/NTL-interface.cpp b/src/interfaces/NTL-interface.cpp deleted file mode 100644 index 17180c3343..0000000000 --- a/src/interfaces/NTL-interface.cpp +++ /dev/null @@ -1,454 +0,0 @@ -/* - Copyright (C) 2007 William Hart - Copyright (C) 2011 Sebastian Pancratz - Copyright (C) 2013 Mike Hansen - - This file is part of FLINT. - - FLINT is free software: you can redistribute it and/or modify it under - the terms of the GNU Lesser General Public License (LGPL) as published - by the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. See . -*/ - -#include - -#include -#include -#include -#include -#include - -#include "flint.h" -#include "fmpz.h" -#include "fmpz_poly.h" -#include "NTL-interface.h" - -#define ZZ_SIZE(p) (((slong *) (p))[1]) -#define ZZ_DATA(p) ((mp_limb_t *) (((slong *) (p)) + 2)) - -NTL_CLIENT - -static void fmpz_set_limbs(fmpz_t f, mp_srcptr x, mp_size_t limbs) -{ - if (limbs == 0) - fmpz_zero(f); - else if (limbs == 1) - fmpz_set_ui(f, x[0]); - else - { - __mpz_struct *mf = _fmpz_promote(f); - - mpz_import(mf, limbs, -1, sizeof(mp_limb_t), 0, 0, x); - } -} - -void fmpz_set_ZZ(fmpz_t rop, const ZZ& op) -{ - const _ntl_gbigint x = op.rep; - - if (!x) - fmpz_zero(rop); - else - { - const mp_size_t lw = op.size(); - const mp_limb_t *xp = ZZ_DATA(x); - - fmpz_set_limbs(rop, xp, lw); - - if (op < WORD(0)) - fmpz_neg(rop, rop); - } -} - -void fmpz_set_ZZ_p(fmpz_t rop, const ZZ_p& op) -{ - fmpz_set_ZZ(rop, rep(op)); -} - -void fmpz_set_zz_p(fmpz_t rop, const zz_p& op) -{ - fmpz_set_si(rop, rep(op)); -} - -void fmpz_get_ZZ(ZZ& rop, const fmpz_t op) -{ - mp_limb_t *xp; - _ntl_gbigint *x = &rop.rep; - slong lw = fmpz_size(op); - fmpz c = *op; - - if (lw == 0) - { - if (*x) ZZ_SIZE(*x) = 0; - return; - } - - _ntl_gsetlength(x, lw); - xp = ZZ_DATA(*x); - - if (COEFF_IS_MPZ(c)) - { - __mpz_struct * m = COEFF_TO_PTR(c); - mpn_copyi(xp, m->_mp_d, lw); - } else - { - if (c < WORD(0)) - xp[0] = -c; - else - xp[0] = c; - } - - if (fmpz_sgn(op) < 0) ZZ_SIZE(*x) = -lw; - else ZZ_SIZE(*x) = lw; -} - -void fmpz_get_ZZ_p(ZZ_p& rop, const fmpz_t op) -{ - ZZ a; - fmpz_get_ZZ(a, op); - conv(rop, a); -} - -void fmpz_get_zz_p(zz_p& rop, const fmpz_t op) -{ - conv(rop, fmpz_get_si(op)); -} - -void fmpz_poly_get_ZZX(ZZX& rop, const fmpz_poly_t op) -{ - const slong len = op->length; - - if (len == 0) - { - rop = 0; - } - else - { - slong i; - ZZ *ap; - - rop.rep.SetLength(len); - - for (i = 0, ap = rop.rep.elts(); i < len; i++, ap++) - { - fmpz_get_ZZ(*ap, op->coeffs + i); - } - } -} - -void fmpz_poly_set_ZZX(fmpz_poly_t rop, const ZZX& op) -{ - const slong len = deg(op) + 1; - - if (len == 0) - { - fmpz_poly_zero(rop); - } - else - { - slong i; - const ZZ *ap; - - fmpz_poly_fit_length(rop, len); - _fmpz_poly_set_length(rop, len); - - for (i = 0, ap = op.rep.elts(); i < len; i++, ap++) - { - fmpz_set_ZZ(rop->coeffs + i, *ap); - } - } -} - - -void fmpz_mod_poly_get_ZZ_pX(ZZ_pX& rop, const fmpz_mod_poly_t op, - const fmpz_mod_ctx_t ctx) -{ - const slong len = op->length; - - if (len == 0) - { - rop = 0; - } - else - { - slong i; - ZZ_p *ap; - - rop.rep.SetLength(len); - - for (i = 0, ap = rop.rep.elts(); i < len; i++, ap++) - { - fmpz_get_ZZ_p(*ap, op->coeffs + i); - } - } -} - -void fmpz_mod_poly_set_ZZ_pX(fmpz_mod_poly_t rop, const ZZ_pX& op, - const fmpz_mod_ctx_t ctx) -{ - const slong len = deg(op) + 1; - - if (len == 0) - { - fmpz_mod_poly_zero(rop, ctx); - } - else - { - slong i; - const ZZ_p *ap; - - fmpz_mod_poly_fit_length(rop, len, ctx); - _fmpz_mod_poly_set_length(rop, len); - - for (i = 0, ap = op.rep.elts(); i < len; i++, ap++) - { - fmpz_set_ZZ_p(rop->coeffs + i, *ap); - } - } -} - -void fmpz_mod_poly_get_zz_pX(zz_pX& rop, const fmpz_mod_poly_t op, - const fmpz_mod_ctx_t ctx) -{ - const slong len = op->length; - - if (len == 0) - { - rop = 0; - } - else - { - slong i; - zz_p *ap; - - rop.rep.SetLength(len); - - for (i = 0, ap = rop.rep.elts(); i < len; i++, ap++) - { - fmpz_get_zz_p(*ap, op->coeffs + i); - } - } -} - -void fmpz_mod_poly_set_zz_pX(fmpz_mod_poly_t rop, const zz_pX& op, - const fmpz_mod_ctx_t ctx) -{ - const slong len = deg(op) + 1; - - if (len == 0) - { - fmpz_mod_poly_zero(rop, ctx); - } - else - { - slong i; - const zz_p *ap; - - fmpz_mod_poly_fit_length(rop, len, ctx); - _fmpz_mod_poly_set_length(rop, len); - - for (i = 0, ap = op.rep.elts(); i < len; i++, ap++) - { - fmpz_set_zz_p(rop->coeffs + i, *ap); - } - } -} - -void fq_get_ZZ_pE(ZZ_pE& rop, const fq_t op, const fq_ctx_t ctx) -{ - ZZ_pX p; - - const slong len = op->length; - - if (len == 0) - { - rop = 0; - } - else - { - slong i; - ZZ_p *ap; - - p.rep.SetLength(len); - - for (i = 0, ap = p.rep.elts(); i < len; i++, ap++) - { - fmpz_get_ZZ_p(*ap, op->coeffs + i); - } - conv(rop, p); - } -} - -void fq_set_ZZ_pE(fq_t rop, const ZZ_pE& op, const fq_ctx_t ctx) -{ - const slong len = deg(rep(op)) + 1; - - if (len == 0) - { - fq_zero(rop, ctx); - } - else - { - slong i; - const ZZ_p *ap; - - fmpz_poly_fit_length(rop, len); - _fmpz_poly_set_length(rop, len); - - for (i = 0, ap = rep(op).rep.elts(); i < len; i++, ap++) - { - fmpz_set_ZZ_p(rop->coeffs + i, *ap); - } - _fmpz_poly_normalise(rop); - } -} - - -void fq_poly_get_ZZ_pEX(ZZ_pEX& rop, const fq_poly_t op, const fq_ctx_t ctx) -{ - const slong len = op->length; - - if (len == 0) - { - rop = 0; - } - else - { - slong i; - ZZ_pE *ap; - - rop.rep.SetLength(len); - - for (i = 0, ap = rop.rep.elts(); i < len; i++, ap++) - { - fq_get_ZZ_pE(*ap, op->coeffs + i, ctx); - } - } -} - -void fq_poly_set_ZZ_pEX(fq_poly_t rop, const ZZ_pEX& op, const fq_ctx_t ctx) -{ - const slong len = deg(op) + 1; - - if (len == 0) - { - fq_poly_zero(rop, ctx); - } - else - { - slong i; - const ZZ_pE *ap; - - fq_poly_fit_length(rop, len, ctx); - _fq_poly_set_length(rop, len, ctx); - - for (i = 0, ap = op.rep.elts(); i < len; i++, ap++) - { - fq_set_ZZ_pE(rop->coeffs + i, *ap, ctx); - } - _fq_poly_normalise(rop, ctx); - } -} - -/* ----------------------------------------- */ -void fq_get_zz_pE(zz_pE& rop, const fq_t op, const fq_ctx_t ctx) -{ - zz_pX p; - - const slong len = op->length; - - if (len == 0) - { - rop = 0; - } - else - { - slong i; - zz_p *ap; - - p.rep.SetLength(len); - - for (i = 0, ap = p.rep.elts(); i < len; i++, ap++) - { - fmpz_get_zz_p(*ap, op->coeffs + i); - } - conv(rop, p); - } -} - -void fq_set_zz_pE(fq_t rop, const zz_pE& op, const fq_ctx_t ctx) -{ - const slong len = deg(rep(op)) + 1; - - if (len == 0) - { - fq_zero(rop, ctx); - } - else - { - slong i; - const zz_p *ap; - - fmpz_poly_fit_length(rop, len); - _fmpz_poly_set_length(rop, len); - - for (i = 0, ap = rep(op).rep.elts(); i < len; i++, ap++) - { - fmpz_set_zz_p(rop->coeffs + i, *ap); - } - _fmpz_poly_normalise(rop); - } -} - - -void fq_poly_get_zz_pEX(zz_pEX& rop, const fq_poly_t op, const fq_ctx_t ctx) -{ - const slong len = op->length; - - if (len == 0) - { - rop = 0; - } - else - { - slong i; - zz_pE *ap; - - rop.rep.SetLength(len); - - for (i = 0, ap = rop.rep.elts(); i < len; i++, ap++) - { - fq_get_zz_pE(*ap, op->coeffs + i, ctx); - } - } -} - -void fq_poly_set_zz_pEX(fq_poly_t rop, const zz_pEX& op, const fq_ctx_t ctx) -{ - const slong len = deg(op) + 1; - - if (len == 0) - { - fq_poly_zero(rop, ctx); - } - else - { - slong i; - const zz_pE *ap; - - fq_poly_fit_length(rop, len, ctx); - _fq_poly_set_length(rop, len, ctx); - - for (i = 0, ap = op.rep.elts(); i < len; i++, ap++) - { - fq_set_zz_pE(rop->coeffs + i, *ap, ctx); - } - _fq_poly_normalise(rop, ctx); - } -} - - -#undef ZZ_SIZE -#undef ZZ_DATA - diff --git a/src/interfaces/doc/interfaces.txt b/src/interfaces/doc/interfaces.txt index a98cefd3e1..1500b9cdb7 100644 --- a/src/interfaces/doc/interfaces.txt +++ b/src/interfaces/doc/interfaces.txt @@ -16,10 +16,7 @@ NTL Interface The NTL interface allows conversion between NTL objects and FLINT objects - and vice versa. The interface is built using C$++$ and is not built as a - part of the FLINT library library by default. To build the NTL interface - one must specify the location of NTL with the \code{--with-ntl=path} option - to configure. NTL version 5.5.2 or later is required. + and vice versa. NTL version 5.5.2 or later is required. *******************************************************************************