Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor FLINT randstate #1964

Merged
merged 1 commit into from
May 13, 2024
Merged

Conversation

albinahlback
Copy link
Collaborator

  • Rename flint_rand_s to flint_rand_struct,

  • Replace fields gmp_state and gmp_init in flint_rand_s by void * __gmp_state,

  • Rename the following functions:

    flint_randinit     -> flint_rand_init      (different content)
    flint_randclear    -> flint_rand_clear     (different content)
    flint_randseed     -> flint_rand_set_seed
    flint_get_randseed -> flint_rand_get_seed
    
  • Remove _flint_rand_init_gmp and replace with the two new functions _flint_rand_init_gmp_state and _flint_rand_clear_gmp_state.

    NOTE: The new init-function for the GMP-state assumes that __gmp_state is not initialized, and the new clear-function assumes that __gmp_state is initialized. To help with this, a new macro FLINT_RAND_GMP_STATE_IS_INITIALISED(state) can be utilized to check whether the GMP-state is initialized in state, assuming that state has been initialized via flint_rand_init.

  • Typedef ulong and slong to proper primitive C type instead of relying on GMP's mp_limb_t and mp_limb_signed_t.

@fredrik-johansson
Copy link
Collaborator

There should be macros for flint_randinit and flint_randclear for backward compatibility.

@albinahlback
Copy link
Collaborator Author

There should be macros for flint_randinit and flint_randclear for backward compatibility.

Yes, agreed!

@albinahlback
Copy link
Collaborator Author

I should also mention that I added clears of the random state in two embed.c files for finite fields. Looks like they haven't shown up on Valgrind yet, but they cause leaks.

@fredrik-johansson
Copy link
Collaborator

This looks fine to me. The missing underscore in flint_rand_init has been annoying for a long time.

* Rename flint_rand_s to flint_rand_struct,

* Replace fields `gmp_state` and `gmp_init` in `flint_rand_s` by
  `void * __gmp_state`,

* Rename the following functions:
  flint_randinit     -> flint_rand_init      (different content)
  flint_randclear    -> flint_rand_clear     (different content)
  flint_randseed     -> flint_rand_set_seed
  flint_get_randseed -> flint_rand_get_seed

  but keep the old names, marked as deprecated with the new keyword
  FLINT_DEPRECATED, to preserve backwards-compatibility.

* Deprecate _flint_rand_init_gmp and replace with the two new functions
  _flint_rand_init_gmp_state and _flint_rand_clear_gmp_state.

  NOTE: The new init-function for the GMP-state assumes that __gmp_state
  *is not* initialized, and the new clear-function assumes that
  __gmp_state *is* initialized. To help with this, a new macro
  `FLINT_RAND_GMP_STATE_IS_INITIALISED(state)` can be utilized to check
  whether the GMP-state is initialized in `state`, assuming that `state`
  has been initialized via `flint_rand_init`.

* Deprecate flint_rand_alloc and flint_rand_free.

* Typedef `ulong` and `slong` to proper primitive C type instead of
  relying on GMP's `mp_limb_t` and `mp_limb_signed_t`.
@albinahlback
Copy link
Collaborator Author

Nemo still needs a fix, but I will push that soon.

@albinahlback albinahlback merged commit 5166eb3 into flintlib:main May 13, 2024
12 of 13 checks passed
@albinahlback albinahlback deleted the declude_gmp branch May 13, 2024 08:17
@fredrik-johansson
Copy link
Collaborator

CI fails on Cygwin.

@albinahlback
Copy link
Collaborator Author

Yes, I saw that. Will fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants