Skip to content

Commit

Permalink
introduce fq_default_ctx_init_randtest
Browse files Browse the repository at this point in the history
  • Loading branch information
GiacomoPope committed Aug 19, 2024
1 parent 05340d2 commit 3f54490
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
9 changes: 6 additions & 3 deletions doc/source/fq_default.rst
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,13 @@ Context Management

Prints the context information to ``stdout``.

.. function:: void fq_default_ctx_randtest(fq_default_ctx_t ctx)
.. function:: void fq_default_ctx_init_randtest(fq_default_ctx_t ctx, flint_rand_t state, int type)

Initializes ``ctx`` to a random finite field. Assumes that
``fq_default_ctx_init`` has not been called on ``ctx`` already.
Initializes ``ctx`` to a random finite field where the prime and degree is
set according to ``type``.
Assumes that ``fq_default_ctx_init`` has not been called on ``ctx`` already.
To see what prime and degrees may be output, see
``type`` in :func:`_nmod_poly_conway_rand`.

.. function:: void fq_default_get_coeff_fmpz(fmpz_t c, fq_default_t op, slong n, const fq_default_ctx_t ctx)

Expand Down
1 change: 1 addition & 0 deletions src/fq_default.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ int fq_default_ctx_fprint(FILE * file, const fq_default_ctx_t ctx);
#endif

void fq_default_ctx_print(const fq_default_ctx_t ctx);
void fq_default_ctx_init_randtest(fq_default_ctx_t ctx, flint_rand_t state, int type);

/* Memory management *********************************************************/

Expand Down
19 changes: 19 additions & 0 deletions src/fq_default/ctx.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,22 @@ void fq_default_ctx_modulus(fmpz_mod_poly_t p, const fq_default_ctx_t ctx)
fmpz_mod_poly_set(p, FQ_DEFAULT_CTX_FQ(ctx)->modulus, mod);
}
}

/* FIXME: fq_ctx_init_randtest only tests nmod sized primes, so that's
all we'll do here too? */
void fq_default_ctx_init_randtest(fq_default_ctx_t ctx, flint_rand_t state, int type)
{
ulong prime;
slong degree;
fmpz_t p;

/* select a prime and degree to create the finite field */
prime = _nmod_poly_conway_rand(&degree, state, type);

/* fq_default initialisation wants an fmpz_t for the prime */
fmpz_init(p);
fmpz_set_ui(p, prime);

/* Initialise the context using the prime and degree selected above */
fq_default_ctx_init(ctx, p, degree, "x");
}
16 changes: 16 additions & 0 deletions src/fq_default/test/t-init.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,21 @@ TEST_FUNCTION_START(fq_default_init, state)
fmpz_clear(p);
}

for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
fq_default_ctx_t ctx;
fq_default_t fq;

/* Sets the type used internally for prime selection.
See _nmod_poly_conway_rand for more info. */
int type = n_randint(state, 4);

fq_default_ctx_init_randtest(ctx, state, type);
fq_default_init(fq, ctx);
fq_default_clear(fq, ctx);
fq_default_randtest(fq, state, ctx);
fq_default_ctx_clear(ctx);
}

TEST_FUNCTION_END(state);
}

0 comments on commit 3f54490

Please sign in to comment.