Skip to content

Commit

Permalink
Remove unused rng c code
Browse files Browse the repository at this point in the history
  • Loading branch information
eivindjahren committed Aug 8, 2024
1 parent 71375b6 commit 9a97b2d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 70 deletions.
10 changes: 0 additions & 10 deletions lib/include/ert/util/rng.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,7 @@ void rng_free(rng_type *rng);
void rng_free(rng_type *rng);
unsigned int rng_forward(rng_type *rng);
double rng_get_double(rng_type *rng);
void rng_rng_init(rng_type *rng, rng_type *seed_src);
void rng_init(rng_type *rng, rng_init_mode init_mode);
rng_alg_type rng_get_type(const rng_type *rng);
void rng_fprintf_state(rng_type *rng, FILE *stream);
void rng_fscanf_state(rng_type *rng, FILE *stream);
int rng_state_size(const rng_type *rng);
void rng_save_state(rng_type *rng, const char *filename);
void rng_load_state(rng_type *rng, const char *filename);
Expand All @@ -52,12 +48,6 @@ double rng_get_double(rng_type *rng);
int rng_get_int(rng_type *rng, int max_value);
unsigned int rng_get_max_int(const rng_type *rng);

double rng_std_normal(rng_type *rng);
void rng_shuffle_int(rng_type *rng, int *data, size_t num_elements);
void rng_shuffle(rng_type *rng, char *data, size_t element_size,
size_t num_elements);
void rng_free__(void *arg);

UTIL_SAFE_CAST_HEADER(rng);

#ifdef __cplusplus
Expand Down
62 changes: 2 additions & 60 deletions lib/util/rng.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,28 +114,6 @@ void rng_init(rng_type *rng, rng_init_mode init_mode) {
}
}

void rng_rng_init(rng_type *rng, rng_type *seed_src) {
{
int byte_size = rng->state_size;
int int_size = rng->state_size / 4;
unsigned int *seed_buffer;

if (int_size * 4 < byte_size)
int_size += 1;

seed_buffer =
(unsigned int *)util_calloc(int_size, sizeof *seed_buffer);
{
int i;
for (i = 0; i < int_size; i++)
seed_buffer[i] = rng_forward(seed_src);
}
rng->set_state(rng->state, (char *)seed_buffer);

free(seed_buffer);
}
}

rng_type *rng_alloc(rng_alg_type type, rng_init_mode init_mode) {
rng_type *rng;
switch (type) {
Expand Down Expand Up @@ -169,16 +147,11 @@ void rng_free(rng_type *rng) {
free(rng);
}

void rng_free__(void *arg) {
rng_type *rng = rng_safe_cast(arg);
rng_free(rng);
}

void rng_fprintf_state(rng_type *rng, FILE *stream) {
static void rng_fprintf_state(rng_type *rng, FILE *stream) {
rng->fprintf_state(rng->state, stream);
}

void rng_fscanf_state(rng_type *rng, FILE *stream) {
static void rng_fscanf_state(rng_type *rng, FILE *stream) {
rng->fscanf_state(rng->state, stream);
}

Expand All @@ -205,8 +178,6 @@ int rng_get_int(rng_type *rng, int max_value) {
return rng->forward(rng->state) % max_value;
}

rng_alg_type rng_get_type(const rng_type *rng) { return rng->type; }

unsigned int rng_get_max_int(const rng_type *rng) {
unsigned int MAX = -1;
if (rng->max_value < MAX) {
Expand All @@ -216,35 +187,6 @@ unsigned int rng_get_max_int(const rng_type *rng) {
}
}

void rng_shuffle(rng_type *rng, char *data, size_t element_size,
size_t num_elements) {
void *tmp = util_malloc(element_size);
size_t index1;
for (index1 = 0; index1 < num_elements; index1++) {
int index2 = rng_get_int(rng, num_elements);

size_t offset1 = index1 * element_size;
size_t offset2 = index2 * element_size;

memcpy(tmp, &data[offset1], element_size);
memcpy(&data[offset1], &data[offset2], element_size);
memcpy(&data[offset2], tmp, element_size);
}
free(tmp);
}

void rng_shuffle_int(rng_type *rng, int *data, size_t num_elements) {
rng_shuffle(rng, (char *)data, sizeof *data, num_elements);
}

double rng_std_normal(rng_type *rng) {
const double pi = 3.141592653589;
double R1 = rng_get_double(rng);
double R2 = rng_get_double(rng);

return sqrt(-2.0 * log(R1)) * cos(2.0 * pi * R2);
}

#ifdef __cplusplus
}
#endif

0 comments on commit 9a97b2d

Please sign in to comment.