Skip to content

Commit

Permalink
add accessor for internal context object of fq_default_ctx
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrik-johansson committed Feb 2, 2024
1 parent a711576 commit c264915
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 14 deletions.
5 changes: 5 additions & 0 deletions doc/source/fq_default.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ Context Management
Returns `1` if the context contains an ``fq_zech`` context, `2` if it
contains an ``fq_mod`` context and `3` if it contains an ``fq`` context.

.. function:: void * fq_default_ctx_inner(const fq_default_ctx_t ctx)

Returns a pointer to the internal context object of type
``fq_ctx_t``, ``fq_zech_ctx_t``, ``fmpz_mod_ctx_t``, etc.

.. function:: slong fq_default_ctx_degree(const fq_default_ctx_t ctx)

Returns the degree of the field extension
Expand Down
8 changes: 8 additions & 0 deletions src/fq_default.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,14 @@ FQ_DEFAULT_INLINE void fq_default_ctx_init(fq_default_ctx_t ctx,
fq_default_ctx_init_type(ctx, p, d, var, 0);
}

FQ_DEFAULT_INLINE void * fq_default_ctx_inner(const fq_default_ctx_t ctx)
{
if (_FQ_DEFAULT_TYPE(ctx) == _FQ_DEFAULT_NMOD)
return (void *) &FQ_DEFAULT_CTX_NMOD(ctx);
else
return (void *) GR_CTX_DATA_AS_PTR(ctx);
}

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
48 changes: 34 additions & 14 deletions src/fq_default/test/t-init.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,43 +23,63 @@ TEST_FUNCTION_START(fq_default_init, state)
fmpz_t p;

fmpz_init(p);

fmpz_set_ui(p, 3);

fq_default_ctx_init(ctx, p, 3, "x");

fq_default_init(fq, ctx);

fq_default_clear(fq, ctx);

fq_default_randtest(fq, state, ctx);

fq_default_ctx_clear(ctx);

fq_default_ctx_init(ctx, p, 16, "x");

fq_default_init(fq, ctx);

fq_default_randtest(fq, state, ctx);

fq_default_clear(fq, ctx);

fq_default_ctx_clear(ctx);

fmpz_set_str(p, "73786976294838206473", 10);

fq_default_ctx_init(ctx, p, 1, "x");

fq_default_init(fq, ctx);

fq_default_randtest(fq, state, ctx);

fq_default_clear(fq, ctx);

fq_default_ctx_clear(ctx);

fmpz_clear(p);
}

for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
fmpz_t p;
fq_default_ctx_t ctx;
fq_default_t x, y;
int type = 1 + n_randint(state, 5);

fmpz_init(p);
fmpz_set_ui(p, 7);
fq_default_ctx_init_type(ctx, p, 1, "x", type);
FLINT_TEST(fq_default_ctx_type(ctx) == type);
fq_default_init(x, ctx);
fq_default_init(y, ctx);
fq_default_randtest(x, state, ctx);
fq_default_sqr(y, x, ctx);

if (type == FQ_DEFAULT_FQ)
fq_sqr((fq_struct *) x, (const fq_struct *) x, (const fq_ctx_struct *) fq_default_ctx_inner(ctx));
else if (type == FQ_DEFAULT_FQ_NMOD)
fq_nmod_sqr((fq_nmod_struct *) x, (const fq_nmod_struct *) x, (const fq_nmod_ctx_struct *) fq_default_ctx_inner(ctx));
else if (type == FQ_DEFAULT_FQ_ZECH)
fq_zech_sqr((fq_zech_struct *) x, (const fq_zech_struct *) x, (const fq_zech_ctx_struct *) fq_default_ctx_inner(ctx));
else if (type == FQ_DEFAULT_FMPZ_MOD)
fmpz_mod_mul((fmpz *) x, (const fmpz *) x, (const fmpz *) x, (const fmpz_mod_ctx_struct *) fq_default_ctx_inner(ctx));
else
((ulong *) x)[0] = nmod_mul(((ulong *) x)[0], ((ulong *) x)[0], *((const nmod_t *) fq_default_ctx_inner(ctx)));

FLINT_TEST(fq_default_equal(x, y, ctx));
fq_default_clear(x, ctx);
fq_default_clear(y, ctx);
fq_default_ctx_clear(ctx);
fmpz_clear(p);
}

TEST_FUNCTION_END(state);
}

0 comments on commit c264915

Please sign in to comment.