Skip to content

Commit 8c97648

Browse files
authored
Merge pull request bashtage#110 from bashtage/clang-format
CLN: Reformat source files in interface
2 parents 09186fe + ffed636 commit 8c97648

22 files changed

+444
-522
lines changed

randomstate/distributions.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1495,7 +1495,7 @@ uint32_t random_buffered_bounded_uint32(aug_state *state, uint32_t off, uint32_t
14951495
return bounded_uint32(state, off, rng, mask);
14961496
}
14971497

1498-
static NPY_INLINE buffered_bounded_uint16(aug_state *state, uint16_t off, uint16_t rng, uint16_t mask, int *bcnt, uint32_t *buf)
1498+
static NPY_INLINE uint16_t buffered_bounded_uint16(aug_state *state, uint16_t off, uint16_t rng, uint16_t mask, int *bcnt, uint32_t *buf)
14991499
{
15001500
uint16_t val;
15011501
if (rng == 0)
Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,37 @@
11
#include "dSFMT-shim.h"
22
#include "dSFMT-poly.h"
33

4-
extern inline uint32_t random_uint32(aug_state* state);
4+
extern NPY_INLINE uint32_t random_uint32(aug_state *state);
55

6-
extern inline uint64_t random_uint64(aug_state* state);
6+
extern NPY_INLINE uint64_t random_uint64(aug_state *state);
77

8-
extern inline double random_double(aug_state* state);
8+
extern NPY_INLINE double random_double(aug_state *state);
99

10-
extern inline uint64_t random_raw_values(aug_state* state);
10+
extern NPY_INLINE uint64_t random_raw_values(aug_state *state);
1111

12-
void reset_buffer(aug_state* state)
13-
{
14-
int i = 0;
15-
for (i = 0; i < (2 * DSFMT_N); i++)
16-
{
17-
state->buffered_uniforms[i] = 0.0;
18-
}
19-
state->buffer_loc = 2 * DSFMT_N;
12+
void reset_buffer(aug_state *state) {
13+
int i = 0;
14+
for (i = 0; i < (2 * DSFMT_N); i++) {
15+
state->buffered_uniforms[i] = 0.0;
16+
}
17+
state->buffer_loc = 2 * DSFMT_N;
2018
}
2119

22-
extern void set_seed_by_array(aug_state* state, uint32_t init_key[], int key_length)
23-
{
24-
reset_buffer(state);
25-
dsfmt_init_by_array(state->rng, init_key, key_length);
20+
extern void set_seed_by_array(aug_state *state, uint32_t init_key[],
21+
int key_length) {
22+
reset_buffer(state);
23+
dsfmt_init_by_array(state->rng, init_key, key_length);
2624
}
2725

28-
void set_seed(aug_state* state, uint32_t seed)
29-
{
30-
reset_buffer(state);
31-
dsfmt_init_gen_rand(state->rng, seed);
26+
void set_seed(aug_state *state, uint32_t seed) {
27+
reset_buffer(state);
28+
dsfmt_init_gen_rand(state->rng, seed);
3229
}
3330

34-
void entropy_init(aug_state* state)
35-
{
36-
uint32_t seeds[1];
37-
entropy_fill((void*) seeds, sizeof(seeds));
38-
set_seed(state, seeds[0]);
31+
void entropy_init(aug_state *state) {
32+
uint32_t seeds[1];
33+
entropy_fill((void *)seeds, sizeof(seeds));
34+
set_seed(state, seeds[0]);
3935
}
4036

41-
void jump_state(aug_state* state)
42-
{
43-
dSFMT_jump(state->rng, poly_128);
44-
}
37+
void jump_state(aug_state *state) { dSFMT_jump(state->rng, poly_128); }
Lines changed: 52 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,81 @@
11
#ifdef _WIN32
22
#include "../../src/common/stdint.h"
3-
#define inline __forceinline
43
#else
54
#include <stdint.h>
65
#endif
76

7+
#include "Python.h"
8+
#include "numpy/npy_common.h"
9+
810
#include "../../src/common/binomial.h"
911
#include "../../src/common/entropy.h"
1012
#include "../../src/dSFMT/dSFMT-jump.h"
1113
#include "../../src/dSFMT/dSFMT.h"
1214

13-
1415
typedef struct s_aug_state {
15-
dsfmt_t *rng;
16-
binomial_t *binomial;
16+
dsfmt_t *rng;
17+
binomial_t *binomial;
1718

18-
int has_gauss, has_gauss_float, shift_zig_random_int, has_uint32;
19-
float gauss_float;
20-
double gauss;
21-
uint32_t uinteger;
22-
uint64_t zig_random_int;
19+
int has_gauss, has_gauss_float, shift_zig_random_int, has_uint32;
20+
float gauss_float;
21+
double gauss;
22+
uint32_t uinteger;
23+
uint64_t zig_random_int;
2324

24-
double *buffered_uniforms;
25-
int buffer_loc;
25+
double *buffered_uniforms;
26+
int buffer_loc;
2627
} aug_state;
2728

28-
static inline double random_double_from_buffer(aug_state *state)
29-
{
30-
double out;
31-
if (state->buffer_loc >= (2 * DSFMT_N))
32-
{
33-
state->buffer_loc = 0;
34-
dsfmt_fill_array_close1_open2(state->rng, state->buffered_uniforms, 2 * DSFMT_N);
35-
}
36-
out = state->buffered_uniforms[state->buffer_loc];
37-
state->buffer_loc++;
38-
return out;
29+
static NPY_INLINE double random_double_from_buffer(aug_state *state) {
30+
double out;
31+
if (state->buffer_loc >= (2 * DSFMT_N)) {
32+
state->buffer_loc = 0;
33+
dsfmt_fill_array_close1_open2(state->rng, state->buffered_uniforms,
34+
2 * DSFMT_N);
35+
}
36+
out = state->buffered_uniforms[state->buffer_loc];
37+
state->buffer_loc++;
38+
return out;
3939
}
4040

41-
static inline uint32_t random_uint32(aug_state* state)
42-
{
43-
/* TODO: This can be improved to use upper bits */
44-
double d = random_double_from_buffer(state);//dsfmt_genrand_close1_open2(state->rng);
45-
uint64_t *out = (uint64_t *)&d;
46-
return (uint32_t)(*out & 0xffffffff);
41+
static NPY_INLINE uint32_t random_uint32(aug_state *state) {
42+
/* TODO: This can be improved to use upper bits */
43+
double d = random_double_from_buffer(
44+
state); // dsfmt_genrand_close1_open2(state->rng);
45+
uint64_t *out = (uint64_t *)&d;
46+
return (uint32_t)(*out & 0xffffffff);
4747
}
4848

49-
static inline uint64_t random_uint64(aug_state* state)
50-
{
51-
/* TODO: This can be improved to use upper bits */
52-
double d = random_double_from_buffer(state); //dsfmt_genrand_close1_open2(state->rng);
53-
uint64_t out;
54-
uint64_t *tmp;
55-
tmp = (uint64_t *)&d;
56-
out = *tmp << 32;
57-
d = random_double_from_buffer(state);//dsfmt_genrand_close1_open2(state->rng);
58-
tmp = (uint64_t *)&d;
59-
out |= *tmp & 0xffffffff;
60-
return out;
49+
static NPY_INLINE uint64_t random_uint64(aug_state *state) {
50+
/* TODO: This can be improved to use upper bits */
51+
double d = random_double_from_buffer(
52+
state); // dsfmt_genrand_close1_open2(state->rng);
53+
uint64_t out;
54+
uint64_t *tmp;
55+
tmp = (uint64_t *)&d;
56+
out = *tmp << 32;
57+
d = random_double_from_buffer(
58+
state); // dsfmt_genrand_close1_open2(state->rng);
59+
tmp = (uint64_t *)&d;
60+
out |= *tmp & 0xffffffff;
61+
return out;
6162
}
6263

63-
static inline double random_double(aug_state* state)
64-
{
65-
return random_double_from_buffer(state) - 1.0;
66-
// return dsfmt_genrand_close1_open2(state->rng) - 1.0;
64+
static NPY_INLINE double random_double(aug_state *state) {
65+
return random_double_from_buffer(state) - 1.0;
66+
// return dsfmt_genrand_close1_open2(state->rng) - 1.0;
6767
}
6868

69-
70-
static inline uint64_t random_raw_values(aug_state* state)
71-
{
72-
double d = random_double_from_buffer(state);
73-
return *((uint64_t *)&d);
69+
static NPY_INLINE uint64_t random_raw_values(aug_state *state) {
70+
double d = random_double_from_buffer(state);
71+
return *((uint64_t *)&d);
7472
}
7573

74+
extern void entropy_init(aug_state *state);
7675

77-
extern void entropy_init(aug_state* state);
78-
79-
extern void set_seed_by_array(aug_state* state, uint32_t init_key[], int key_length);
76+
extern void set_seed_by_array(aug_state *state, uint32_t init_key[],
77+
int key_length);
8078

81-
extern void set_seed(aug_state* state, uint32_t seed);
79+
extern void set_seed(aug_state *state, uint32_t seed);
8280

83-
extern void jump_state(aug_state* state);
81+
extern void jump_state(aug_state *state);
Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,21 @@
11
#include "mlfg-1279-861-shim.h"
22

3-
extern inline uint32_t random_uint32(aug_state* state);
3+
extern NPY_INLINE uint32_t random_uint32(aug_state *state);
44

5-
extern inline uint64_t random_uint64(aug_state* state);
5+
extern NPY_INLINE uint64_t random_uint64(aug_state *state);
66

7-
extern inline double random_double(aug_state* state);
7+
extern NPY_INLINE double random_double(aug_state *state);
88

9-
extern inline uint64_t random_raw_values(aug_state* state);
9+
extern NPY_INLINE uint64_t random_raw_values(aug_state *state);
1010

11-
void set_seed(aug_state* state, uint64_t val)
12-
{
13-
mlfg_seed(state->rng, val);
14-
}
11+
void set_seed(aug_state *state, uint64_t val) { mlfg_seed(state->rng, val); }
1512

16-
void set_seed_by_array(aug_state* state, uint64_t *vals, int count)
17-
{
18-
mlfg_seed_by_array(state->rng, vals, count);
13+
void set_seed_by_array(aug_state *state, uint64_t *vals, int count) {
14+
mlfg_seed_by_array(state->rng, vals, count);
1915
}
2016

21-
void entropy_init(aug_state* state)
22-
{
23-
uint64_t seeds[1];
24-
entropy_fill((void*) seeds, sizeof(seeds));
25-
mlfg_seed(state->rng, seeds[0]);
17+
void entropy_init(aug_state *state) {
18+
uint64_t seeds[1];
19+
entropy_fill((void *)seeds, sizeof(seeds));
20+
mlfg_seed(state->rng, seeds[0]);
2621
}
Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,51 @@
11

22
#ifdef _WIN32
33
#include "../../src/common/stdint.h"
4-
#define inline __forceinline
54
#else
65
#include <stdint.h>
76
#endif
87

9-
#include "../../src/common/entropy.h"
8+
#include "Python.h"
9+
#include "numpy/npy_common.h"
10+
1011
#include "../../src/common/binomial.h"
12+
#include "../../src/common/entropy.h"
1113
#include "../../src/mlfg-1279-861/mlfg-1279-861.h"
1214

15+
1316
typedef struct s_aug_state {
14-
mlfg_state *rng;
15-
binomial_t *binomial;
16-
17-
int has_gauss, has_gauss_float, shift_zig_random_int, has_uint32;
18-
float gauss_float;
19-
double gauss;
20-
uint32_t uinteger;
21-
uint64_t zig_random_int;
17+
mlfg_state *rng;
18+
binomial_t *binomial;
19+
20+
int has_gauss, has_gauss_float, shift_zig_random_int, has_uint32;
21+
float gauss_float;
22+
double gauss;
23+
uint32_t uinteger;
24+
uint64_t zig_random_int;
2225
} aug_state;
2326

24-
inline uint32_t random_uint32(aug_state* state)
25-
{
26-
return (uint32_t)(mlfg_next(state->rng) >> 32);
27+
NPY_INLINE uint32_t random_uint32(aug_state *state) {
28+
return (uint32_t)(mlfg_next(state->rng) >> 32);
2729
}
2830

29-
inline uint64_t random_uint64(aug_state* state)
30-
{
31-
uint64_t out = mlfg_next(state->rng) & 0xffffffff00000000ULL;
32-
out |= mlfg_next(state->rng) >> 32;
33-
return out;
31+
NPY_INLINE uint64_t random_uint64(aug_state *state) {
32+
uint64_t out = mlfg_next(state->rng) & 0xffffffff00000000ULL;
33+
out |= mlfg_next(state->rng) >> 32;
34+
return out;
3435
}
3536

36-
inline uint64_t random_raw_values(aug_state* state)
37-
{
38-
return mlfg_next(state->rng) >> 1;
37+
NPY_INLINE uint64_t random_raw_values(aug_state *state) {
38+
return mlfg_next(state->rng) >> 1;
3939
}
4040

41-
inline double random_double(aug_state* state)
42-
{
43-
uint64_t rn;
44-
rn = mlfg_next(state->rng);
45-
return (rn >> 11) * (1.0 / 9007199254740992.0);
41+
NPY_INLINE double random_double(aug_state *state) {
42+
uint64_t rn;
43+
rn = mlfg_next(state->rng);
44+
return (rn >> 11) * (1.0 / 9007199254740992.0);
4645
}
4746

48-
extern void set_seed(aug_state* state, uint64_t seed);
47+
extern void set_seed(aug_state *state, uint64_t seed);
4948

50-
extern void set_seed_by_array(aug_state* state, uint64_t *vals, int count);
49+
extern void set_seed_by_array(aug_state *state, uint64_t *vals, int count);
5150

52-
extern void entropy_init(aug_state* state);
51+
extern void entropy_init(aug_state *state);

0 commit comments

Comments
 (0)