Skip to content

Commit

Permalink
Merge pull request #2050 from GiacomoPope/fq_default_ctx_randtest
Browse files Browse the repository at this point in the history
Introduce `fq_default_ctx_init_randtest()`
  • Loading branch information
fredrik-johansson authored Sep 5, 2024
2 parents 3311717 + 009a93f commit decd504
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 3 deletions.
6 changes: 3 additions & 3 deletions doc/source/fq_default.rst
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ 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)

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 using one of the five internal representations.
Assumes that ``fq_default_ctx_init`` has not been called on ``ctx`` already.

.. 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);

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

Expand Down
40 changes: 40 additions & 0 deletions src/fq_default/ctx.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,43 @@ 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);
}
}

/* Create a random fq_default_ctx picked from the five internal representations */
void fq_default_ctx_init_randtest(fq_default_ctx_t ctx, flint_rand_t state)
{
fmpz_t prime;
slong deg;

/* Select a context type [1,...,5] */
int ctx_type = 1 + n_randint(state, 5);
switch (ctx_type)
{
/* Create GF(p^d) for FQ_ZECH context */
case FQ_DEFAULT_FQ_ZECH:
fmpz_randprime(prime, state, 2 + n_randint(state, 3), 1);
deg = 1 + n_randint(state, 3);
break;
/* Create GF(p^d) for FQ_NMOD context */
case FQ_DEFAULT_FQ_NMOD:
fmpz_randprime(prime, state, 2 + n_randint(state, 29), 1);
deg = 1 + n_randint(state, 15);
break;
/* Create GF(p^d) for FQ context */
case FQ_DEFAULT_FQ:
fmpz_randprime(prime, state, 2 + n_randint(state, 62), 1);
deg = 1 + n_randint(state, 7);
break;
/* Create GF(p) for NMOD context */
case FQ_DEFAULT_NMOD:
fmpz_randprime(prime, state, 2 + n_randint(state, 29), 1);
deg = 1;
break;
/* Create GF(p) for FMPZ_MOD context */
case FQ_DEFAULT_FMPZ_MOD:
fmpz_randprime(prime, state, 2 + n_randint(state, 62), 1);
deg = 1;
break;
default: FLINT_UNREACHABLE;
}
fq_default_ctx_init_type(ctx, prime, deg, "a", ctx_type);
}
12 changes: 12 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,17 @@ 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;

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

TEST_FUNCTION_END(state);
}

0 comments on commit decd504

Please sign in to comment.