Skip to content

Commit

Permalink
Add gr-impl.h
Browse files Browse the repository at this point in the history
  • Loading branch information
albinahlback committed Nov 5, 2024
1 parent 16d98f1 commit e5e3f75
Show file tree
Hide file tree
Showing 13 changed files with 86 additions and 67 deletions.
11 changes: 1 addition & 10 deletions src/fq_default/ctx.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*/

#include "fq_default.h"
#include "gr-impl.h"

void fq_default_ctx_init_type(fq_default_ctx_t ctx,
const fmpz_t p, slong d, const char *var, int type)
Expand Down Expand Up @@ -42,16 +43,6 @@ void fq_default_ctx_init_type(fq_default_ctx_t ctx,
}
}

int gr_ctx_init_fq_zech_modulus_nmod_poly(gr_ctx_t ctx, const nmod_poly_t modulus, const char * var);
int gr_ctx_init_fq_zech_modulus_fmpz_mod_poly(gr_ctx_t ctx, const fmpz_mod_poly_t modulus, fmpz_mod_ctx_t mod_ctx, const char * var);

int gr_ctx_init_fq_nmod_modulus_nmod_poly(gr_ctx_t ctx, const nmod_poly_t modulus, const char * var);
int gr_ctx_init_fq_nmod_modulus_fmpz_mod_poly(gr_ctx_t ctx, const fmpz_mod_poly_t modulus, fmpz_mod_ctx_t mod_ctx, const char * var);

int gr_ctx_init_fq_modulus_nmod_poly(gr_ctx_t ctx, const nmod_poly_t modulus, const char * var);
int gr_ctx_init_fq_modulus_fmpz_mod_poly(gr_ctx_t ctx, const fmpz_mod_poly_t modulus, fmpz_mod_ctx_t mod_ctx, const char * var);


void fq_default_ctx_init_modulus_type(fq_default_ctx_t ctx,
const fmpz_mod_poly_t modulus, fmpz_mod_ctx_t mod_ctx,
const char * var, int type)
Expand Down
56 changes: 56 additions & 0 deletions src/gr-impl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
Copyright (C) 2024 Albin Ahlbäck
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 3 of the License, or
(at your option) any later version. See <https://www.gnu.org/licenses/>.
*/

#ifndef GR_IMPL_H
#define GR_IMPL_H

#include "fmpz_types.h"
#include "qqbar.h"
#include "gr_types.h"

#ifdef __cplusplus
extern "C" {
#endif

/* todo: move */
void qqbar_set_fmpzi(qqbar_t res, const fmpzi_t x);

int _gr_arf_cmpabs(int * res, const arf_t x, const arf_t y, const gr_ctx_t ctx);

int _gr_arf_get_ui(ulong * res, const arf_t x, const gr_ctx_t ctx);
int _gr_arf_get_si(slong * res, const arf_t x, const gr_ctx_t ctx);
int _gr_arf_get_fmpz(fmpz_t res, const arf_t x, const gr_ctx_t ctx);

int _gr_arb_cmpabs(int * res, const arb_t x, const arb_t y, const gr_ctx_t ctx);

/* hidden feature: also works with arb ctx */
int _gr_acb_poly_roots(gr_vec_t roots, gr_vec_t mult, const gr_poly_t poly, int flags, gr_ctx_t ctx);

int _gr_ca_get_arb_with_prec(arb_t res, gr_srcptr x, gr_ctx_t x_ctx, slong prec);
int _gr_ca_get_acb_with_prec(acb_t res, gr_srcptr x, gr_ctx_t x_ctx, slong prec);

int gr_ctx_init_fq_modulus_fmpz_mod_poly(gr_ctx_t ctx, const fmpz_mod_poly_t modulus, fmpz_mod_ctx_t mod_ctx, const char * var);
int gr_ctx_init_fq_modulus_nmod_poly(gr_ctx_t ctx, const nmod_poly_t modulus, const char * var);

int gr_ctx_init_fq_nmod_modulus_nmod_poly(gr_ctx_t ctx, const nmod_poly_t modulus, const char * var);
int gr_ctx_init_fq_nmod_modulus_fmpz_mod_poly(gr_ctx_t ctx, const fmpz_mod_poly_t modulus, fmpz_mod_ctx_t mod_ctx, const char * var);

int gr_ctx_init_fq_zech_modulus_nmod_poly(gr_ctx_t ctx, const nmod_poly_t modulus, const char * var);
int gr_ctx_init_fq_zech_modulus_fmpz_mod_poly(gr_ctx_t ctx, const fmpz_mod_poly_t modulus, fmpz_mod_ctx_t mod_ctx, const char * var);

void _gr_fmpz_mpoly_ctx_clear(gr_ctx_t ctx);
int _gr_fmpz_mpoly_ctx_set_gen_names(gr_ctx_t ctx, const char ** s);

#ifdef __cplusplus
}
#endif

#endif /* GR_IMPL_H */
14 changes: 2 additions & 12 deletions src/gr/acb.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "acf.h"
#include "qqbar.h"
#include "gr.h"
#include "gr-impl.h"
#include "gr_generic.h"
#include "gr_vec.h"
#include "gr_poly.h"
Expand Down Expand Up @@ -227,9 +228,6 @@ _gr_acb_set_d(acb_t res, double x, const gr_ctx_t ctx)
return GR_SUCCESS;
}

int
_gr_ca_get_acb_with_prec(acb_t res, gr_srcptr x, gr_ctx_t x_ctx, slong prec);

static int
_gr_acb_set_other(acb_t res, gr_srcptr x, gr_ctx_t x_ctx, gr_ctx_t ctx)
{
Expand Down Expand Up @@ -324,11 +322,6 @@ _gr_acb_set_interval_mid_rad(acb_t res, const acb_t m, const acb_t r, const gr_c
return GR_SUCCESS;
}

/* xxx: assumes that ctx are not read */
int _gr_arf_get_fmpz(fmpz_t res, const arf_t x, const gr_ctx_t ctx);
int _gr_arf_get_si(slong * res, const arf_t x, const gr_ctx_t ctx);
int _gr_arf_get_ui(ulong * res, const arf_t x, const gr_ctx_t ctx);

static int
_gr_acb_get_fmpz(fmpz_t res, const acb_t x, const gr_ctx_t FLINT_UNUSED(ctx))
{
Expand Down Expand Up @@ -988,9 +981,6 @@ _gr_acb_cmp(int * res, const acb_t x, const acb_t y, const gr_ctx_t FLINT_UNUSED
}
}

int
_gr_arb_cmpabs(int * res, const arb_t x, const arb_t y, const gr_ctx_t ctx);

static int
_gr_acb_cmpabs(int * res, const acb_t x, const acb_t y, const gr_ctx_t ctx)
{
Expand Down Expand Up @@ -1992,7 +1982,7 @@ roots_accurate(acb_ptr roots, slong len, slong prec)
}

/* hidden feature: also works with arb ctx */
static int
int
_gr_acb_poly_roots(gr_vec_t roots, gr_vec_t mult, const gr_poly_t poly, int FLINT_UNUSED(flags), gr_ctx_t ctx)
{
slong prec, initial_prec, target_prec, isolated, maxiter, maxprec, deg, i;
Expand Down
15 changes: 2 additions & 13 deletions src/gr/arb.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "fmpzi.h"
#include "qqbar.h"
#include "gr.h"
#include "gr-impl.h"
#include "gr_generic.h"
#include "gr_vec.h"
#include "gr_poly.h"
Expand Down Expand Up @@ -243,9 +244,6 @@ _gr_arb_set_d(arb_t res, double x, const gr_ctx_t ctx)
return GR_SUCCESS;
}

int
_gr_ca_get_arb_with_prec(arb_t res, gr_srcptr x, gr_ctx_t x_ctx, slong prec);

static int
_gr_arb_set_other(arb_t res, gr_srcptr x, gr_ctx_t x_ctx, gr_ctx_t ctx)
{
Expand Down Expand Up @@ -352,11 +350,6 @@ _gr_arb_set_interval_mid_rad(arb_t res, const arb_t m, const arb_t r, const gr_c
return GR_SUCCESS;
}

/* xxx: assumes that ctx are not read */
int _gr_arf_get_fmpz(fmpz_t res, const arf_t x, const gr_ctx_t ctx);
int _gr_arf_get_si(slong * res, const arf_t x, const gr_ctx_t ctx);
int _gr_arf_get_ui(ulong * res, const arf_t x, const gr_ctx_t ctx);

static int
_gr_arb_get_fmpz(fmpz_t res, const arb_t x, const gr_ctx_t FLINT_UNUSED(ctx))
{
Expand Down Expand Up @@ -878,7 +871,7 @@ _gr_arb_cmp(int * res, const arb_t x, const arb_t y, const gr_ctx_t FLINT_UNUSED
}
}

static int
int
_gr_arb_cmpabs(int * res, const arb_t x, const arb_t y, const gr_ctx_t ctx)
{
arb_t t, u;
Expand Down Expand Up @@ -1589,10 +1582,6 @@ _gr_arb_poly_mullow(arb_ptr res,
return GR_SUCCESS;
}

/* hidden feature: also works with arb ctx */
int
_gr_acb_poly_roots(gr_vec_t roots, gr_vec_t mult, const gr_poly_t poly, int flags, gr_ctx_t ctx);

static int
_gr_arb_poly_roots(gr_vec_t roots, gr_vec_t mult, const gr_poly_t poly, int flags, gr_ctx_t ctx)
{
Expand Down
9 changes: 5 additions & 4 deletions src/gr/arf.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "acb_poly.h"
#include "arb_fmpz_poly.h"
#include "gr.h"
#include "gr-impl.h"
#include "gr_vec.h"
#include "gr_mat.h"
#include "gr_poly.h"
Expand Down Expand Up @@ -229,7 +230,7 @@ _gr_arf_set_other(arf_t res, gr_srcptr x, gr_ctx_t x_ctx, const gr_ctx_t ctx)
}
}

static int
int
_gr_arf_get_fmpz(fmpz_t res, const arf_t x, const gr_ctx_t FLINT_UNUSED(ctx))
{
if (!arf_is_int(x))
Expand All @@ -243,7 +244,7 @@ _gr_arf_get_fmpz(fmpz_t res, const arf_t x, const gr_ctx_t FLINT_UNUSED(ctx))
return GR_SUCCESS;
}

static int
int
_gr_arf_get_si(slong * res, const arf_t x, const gr_ctx_t FLINT_UNUSED(ctx))
{ fmpz_t t;

Expand All @@ -260,7 +261,7 @@ _gr_arf_get_si(slong * res, const arf_t x, const gr_ctx_t FLINT_UNUSED(ctx))
return GR_SUCCESS;
}

static int
int
_gr_arf_get_ui(ulong * res, const arf_t x, const gr_ctx_t FLINT_UNUSED(ctx))
{
fmpz_t t;
Expand Down Expand Up @@ -638,7 +639,7 @@ _gr_arf_cmp(int * res, const arf_t x, const arf_t y, const gr_ctx_t FLINT_UNUSED
return GR_SUCCESS;
}

static int
int
_gr_arf_cmpabs(int * res, const arf_t x, const arf_t y, const gr_ctx_t FLINT_UNUSED(ctx))
{
*res = arf_cmpabs(x, y);
Expand Down
7 changes: 3 additions & 4 deletions src/gr/ca.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "ca_poly.h"
#include "fexpr.h"
#include "gr.h"
#include "gr-impl.h"
#include "gr_generic.h"
#include "gr_vec.h"
#include "gr_poly.h"
Expand Down Expand Up @@ -364,7 +365,7 @@ _gr_ca_set_other(ca_t res, gr_srcptr x, gr_ctx_t x_ctx, gr_ctx_t ctx)
return gr_generic_set_other(res, x, x_ctx, ctx);
}

static int
int
_gr_ca_get_arb_with_prec(arb_t res, gr_srcptr x, gr_ctx_t x_ctx, slong prec)
{
int status = GR_UNABLE;
Expand Down Expand Up @@ -398,8 +399,7 @@ _gr_ca_get_arb_with_prec(arb_t res, gr_srcptr x, gr_ctx_t x_ctx, slong prec)
return status;
}

#if 0
static int
int
_gr_ca_get_acb_with_prec(acb_t res, gr_srcptr x, gr_ctx_t x_ctx, slong prec)
{
if (x_ctx->which_ring == GR_CTX_COMPLEX_EXTENDED_CA)
Expand All @@ -417,7 +417,6 @@ _gr_ca_get_acb_with_prec(acb_t res, gr_srcptr x, gr_ctx_t x_ctx, slong prec)
acb_set_round(res, res, prec);
return GR_SUCCESS;
}
#endif

static int
_gr_ca_get_fmpz(fmpz_t res, const ca_t x, gr_ctx_t ctx)
Expand Down
5 changes: 3 additions & 2 deletions src/gr/fmpz_mpoly.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "fmpz.h"
#include "fmpz_mpoly_factor.h"
#include "gr.h"
#include "gr-impl.h"
#include "gr_vec.h"
#include "gr_generic.h"

Expand Down Expand Up @@ -41,7 +42,7 @@ static int _gr_fmpz_mpoly_ctx_write(gr_stream_t out, gr_ctx_t ctx)
return GR_SUCCESS;
}

static void
void
_gr_fmpz_mpoly_ctx_clear(gr_ctx_t ctx)
{
if (MPOLYNOMIAL_CTX(ctx)->vars != NULL)
Expand All @@ -56,7 +57,7 @@ _gr_fmpz_mpoly_ctx_clear(gr_ctx_t ctx)
flint_free(GR_CTX_DATA_AS_PTR(ctx));
}

static int
int
_gr_fmpz_mpoly_ctx_set_gen_names(gr_ctx_t ctx, const char ** s)
{
slong i, nvars, len;
Expand Down
5 changes: 1 addition & 4 deletions src/gr/fmpz_mpoly_q.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "fmpq.h"
#include "fmpz_mpoly_q.h"
#include "gr.h"
#include "gr-impl.h"
#include "gr_vec.h"
#include "gr_generic.h"

Expand Down Expand Up @@ -40,10 +41,6 @@ static int _gr_fmpz_mpoly_q_ctx_write(gr_stream_t out, gr_ctx_t ctx)
return GR_SUCCESS;
}

/* Some methods are identical to their fmpz_mpoly counterparts */
void _gr_fmpz_mpoly_ctx_clear(gr_ctx_t ctx);
int _gr_fmpz_mpoly_ctx_set_gen_names(gr_ctx_t ctx, const char ** s);

#define _gr_fmpz_mpoly_q_ctx_clear _gr_fmpz_mpoly_ctx_clear
#define _gr_fmpz_mpoly_q_ctx_set_gen_names _gr_fmpz_mpoly_ctx_set_gen_names

Expand Down
4 changes: 1 addition & 3 deletions src/gr/fmpzi.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "qqbar.h"
#include "fmpzi.h"
#include "gr.h"
#include "gr-impl.h"
#include "gr_generic.h"

static int
Expand Down Expand Up @@ -260,9 +261,6 @@ _gr_fmpzi_get_fmpq(fmpq_t res, const fmpzi_t x, const gr_ctx_t FLINT_UNUSED(ctx)
return GR_SUCCESS;
}

/* todo: qqbar should call an fmpzi method rather than vice versa */
void qqbar_set_fmpzi(qqbar_t res, const fmpzi_t x);

static int
_gr_fmpzi_get_fexpr(fexpr_t res, const fmpzi_t x, const gr_ctx_t FLINT_UNUSED(ctx))
{
Expand Down
9 changes: 4 additions & 5 deletions src/gr/fq.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
#include "fmpz_poly.h"
#include "fmpz_mod.h"
#include "fmpz_mod_poly.h"
#include "gr.h"
#include "fq.h"
#include "fq_poly.h"
#include "fq_mat.h"
#include "fq_poly_factor.h"
#include "gr.h"
#include "gr-impl.h"
#include "gr_vec.h"
#include "gr_generic.h"

Expand Down Expand Up @@ -787,8 +788,7 @@ gr_ctx_init_fq(gr_ctx_t ctx, const fmpz_t p, slong d, const char * var)
_gr_ctx_init_fq_from_ref(ctx, fq_ctx);
}

#if 0
static int gr_ctx_init_fq_modulus_fmpz_mod_poly(gr_ctx_t ctx, const fmpz_mod_poly_t modulus, fmpz_mod_ctx_t mod_ctx, const char * var)
int gr_ctx_init_fq_modulus_fmpz_mod_poly(gr_ctx_t ctx, const fmpz_mod_poly_t modulus, fmpz_mod_ctx_t mod_ctx, const char * var)
{
fq_ctx_struct * fq_ctx;
fq_ctx = flint_malloc(sizeof(fq_ctx_struct));
Expand All @@ -797,7 +797,7 @@ static int gr_ctx_init_fq_modulus_fmpz_mod_poly(gr_ctx_t ctx, const fmpz_mod_pol
return GR_SUCCESS;
}

static int gr_ctx_init_fq_modulus_nmod_poly(gr_ctx_t ctx, const nmod_poly_t modulus, const char * var)
int gr_ctx_init_fq_modulus_nmod_poly(gr_ctx_t ctx, const nmod_poly_t modulus, const char * var)
{
fmpz_mod_ctx_t fmod_ctx;
fmpz_mod_poly_t fmod;
Expand All @@ -813,4 +813,3 @@ static int gr_ctx_init_fq_modulus_nmod_poly(gr_ctx_t ctx, const nmod_poly_t modu
fmpz_clear(p);
return status;
}
#endif
7 changes: 3 additions & 4 deletions src/gr/fq_nmod.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "fq_nmod_poly_factor.h"
#include "fmpz_mod_poly.h"
#include "gr.h"
#include "gr-impl.h"
#include "gr_vec.h"
#include "gr_poly.h"
#include "gr_generic.h"
Expand Down Expand Up @@ -739,8 +740,7 @@ gr_ctx_init_fq_nmod(gr_ctx_t ctx, ulong p, slong d, const char * var)
_gr_ctx_init_fq_nmod_from_ref(ctx, fq_nmod_ctx);
}

#if 0
static int gr_ctx_init_fq_nmod_modulus_nmod_poly(gr_ctx_t ctx, const nmod_poly_t modulus, const char * var)
int gr_ctx_init_fq_nmod_modulus_nmod_poly(gr_ctx_t ctx, const nmod_poly_t modulus, const char * var)
{
fq_nmod_ctx_struct * fq_nmod_ctx;
fq_nmod_ctx = flint_malloc(sizeof(fq_nmod_ctx_struct));
Expand All @@ -749,7 +749,7 @@ static int gr_ctx_init_fq_nmod_modulus_nmod_poly(gr_ctx_t ctx, const nmod_poly_t
return GR_SUCCESS;
}

static int
int
gr_ctx_init_fq_nmod_modulus_fmpz_mod_poly(gr_ctx_t ctx, const fmpz_mod_poly_t modulus, fmpz_mod_ctx_t mod_ctx, const char * var)
{
nmod_poly_t nmodulus;
Expand All @@ -764,4 +764,3 @@ gr_ctx_init_fq_nmod_modulus_fmpz_mod_poly(gr_ctx_t ctx, const fmpz_mod_poly_t mo
nmod_poly_clear(nmodulus);
return status;
}
#endif
Loading

0 comments on commit e5e3f75

Please sign in to comment.