Skip to content

Commit 94c5ce0

Browse files
Sheppard, KevinSheppard, Kevin
authored andcommitted
CLN: Code formatting for py/c/h files
Improve format of all file types
1 parent 741d99c commit 94c5ce0

File tree

10 files changed

+190
-196
lines changed

10 files changed

+190
-196
lines changed

randomstate/distributions.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1377,7 +1377,7 @@ void random_gauss_zig_julia_fill(aug_state *state, int count, double *out) {
13771377
xx = -ziggurat_nor_inv_r*log(random_double(state));
13781378
yy = -log(random_double(state));
13791379
} while (yy+yy <= xx*xx);
1380-
1380+
13811381
out[i] = ((rabs >> 8) & 0x1) ? -(ziggurat_nor_r+xx) : ziggurat_nor_r+xx;
13821382
break;
13831383
}

randomstate/performance.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import struct
21
import os
2+
import struct
33
import timeit
44

55
import pandas as pd
66
from numpy.random import RandomState
7+
78
rs = RandomState()
89

910
SETUP = '''
@@ -19,7 +20,8 @@
1920
else:
2021
scale_64 = 2
2122

22-
RNGS = ['mlfg_1279_861', 'mrg32k3a', 'pcg64', 'pcg32', 'mt19937', 'xorshift128', 'xorshift1024', 'random']
23+
RNGS = ['mlfg_1279_861', 'mrg32k3a', 'pcg64', 'pcg32', 'mt19937', 'xorshift128', 'xorshift1024',
24+
'random']
2325

2426

2527
def timer(code, setup):
@@ -71,11 +73,6 @@ def timer_uniform():
7173
def timer_32bit():
7274
command = 'rs.{dist}(1000000, bits=32)'
7375
command_numpy = 'rs.tomaxint({scale} * 1000000)'.format(scale=scale_32)
74-
print('32 bit commands')
75-
print(command)
76-
print(command_numpy)
77-
print('Typical values')
78-
print(rs.tomaxint(5))
7976
dist = 'random_uintegers'
8077
run_timer(dist, command, command_numpy, SETUP, '32-bit unsigned integers')
8178

@@ -84,9 +81,6 @@ def timer_64bit():
8481
dist = 'random_uintegers'
8582
command = 'rs.{dist}(1000000, bits=64)'
8683
command_numpy = 'rs.tomaxint({scale} * 1000000)'.format(scale=scale_64)
87-
print('64 bit commands')
88-
print(command)
89-
print(command_numpy)
9084
run_timer(dist, command, command_numpy, SETUP, '64-bit unsigned integers')
9185

9286

@@ -96,6 +90,7 @@ def timer_normal():
9690
dist = 'standard_normal'
9791
run_timer(dist, command, command_numpy, SETUP, 'Standard normals')
9892

93+
9994
def timer_normal_zig():
10095
command = 'rs.{dist}(1000000, method="zig")'
10196
command_numpy = 'rs.{dist}(1000000)'
@@ -109,4 +104,3 @@ def timer_normal_zig():
109104
timer_64bit()
110105
timer_normal()
111106
timer_normal_zig()
112-

randomstate/setup-single-rng.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import os
12
import sys
23
from distutils.core import setup
34
from distutils.extension import Extension
4-
import os
55
from os import getcwd, name
66
from os.path import join
77

@@ -28,12 +28,12 @@
2828
defs = [('XORSHIFT128_RNG', '1')]
2929

3030
include_dirs = [pwd] + [numpy.get_include()]
31-
if os.name == 'nt' and sys.version_info < (3,5):
32-
include_dirs += [join(pwd, 'src','common')]
31+
if os.name == 'nt' and sys.version_info < (3, 5):
32+
include_dirs += [join(pwd, 'src', 'common')]
3333
include_dirs += [join(pwd, 'src', 'xorshift128')]
3434

3535
extra_link_args = ['Advapi32.lib'] if name == 'nt' else []
36-
extra_compile_args= [] if name == 'nt' else ['-std=c99']
36+
extra_compile_args = [] if name == 'nt' else ['-std=c99']
3737

3838
setup(ext_modules=cythonize([Extension("core_rng",
3939
sources=sources,

randomstate/src/mlfg-1279-861/mlfg-1279-861.h

100644100755
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010

1111
typedef struct s_mlfg_state
1212
{
13-
uint64_t lags[K];
14-
int pos;
15-
int lag_pos;
13+
uint64_t lags[K];
14+
int pos;
15+
int lag_pos;
1616
} mlfg_state;
1717

1818
void mlfg_seed(mlfg_state* state, uint64_t seed);
@@ -30,13 +30,13 @@ void mlfg_init_state(mlfg_state *state, uint64_t seeds[K]);
3030
*/
3131
inline uint64_t mlfg_next(mlfg_state* state)
3232
{
33-
state->pos++;
34-
state->lag_pos++;
35-
if (state->pos >= K)
36-
state->pos = 0;
37-
else if (state->lag_pos >= K)
38-
state->lag_pos = 0;
39-
state->lags[state->pos] = state->lags[state->lag_pos] * state->lags[state->pos];
40-
return state->lags[state->pos];
33+
state->pos++;
34+
state->lag_pos++;
35+
if (state->pos >= K)
36+
state->pos = 0;
37+
else if (state->lag_pos >= K)
38+
state->lag_pos = 0;
39+
state->lags[state->pos] = state->lags[state->lag_pos] * state->lags[state->pos];
40+
return state->lags[state->pos];
4141
}
4242

randomstate/src/pcg/pcg32.c

100644100755
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
extern inline void pcg_setseq_64_step_r(pcg_state_setseq_64* rng);
44
extern inline uint32_t pcg_output_xsl_rr_64_32(uint64_t state);
55
extern inline void pcg_setseq_64_srandom_r(pcg_state_setseq_64* rng,
6-
uint64_t initstate, uint64_t initseq);
6+
uint64_t initstate, uint64_t initseq);
77
extern inline uint32_t
88
pcg_setseq_64_xsl_rr_32_random_r(pcg_state_setseq_64* rng);
99
extern inline uint32_t
1010
pcg_setseq_64_xsl_rr_32_boundedrand_r(pcg_state_setseq_64* rng,
1111
uint32_t bound);
1212
extern inline void pcg_setseq_64_advance_r(pcg_state_setseq_64* rng,
13-
uint64_t delta);
13+
uint64_t delta);
1414

1515
uint64_t pcg_advance_lcg_64(uint64_t state, uint64_t delta, uint64_t cur_mult,
1616
uint64_t cur_plus)

randomstate/src/pcg/pcg32.h

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#endif
77

88
#if __GNUC_GNU_INLINE__ && !defined(__cplusplus)
9-
#error Nonstandard GNU inlining semantics. Compile with -std=c99 or better.
9+
#error Nonstandard GNU inlining semantics. Compile with -std=c99 or better.
1010
#endif
1111

1212
typedef struct {

randomstate/src/pcg64-compat/pcg64.c

100644100755
Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@
2727
extern inline void pcg_setseq_128_step_r(pcg_state_setseq_128* rng);
2828
extern inline uint64_t pcg_output_xsl_rr_128_64(pcg128_t state);
2929
extern inline void pcg_setseq_128_srandom_r(pcg_state_setseq_128* rng,
30-
pcg128_t initstate, pcg128_t initseq);
30+
pcg128_t initstate, pcg128_t initseq);
3131
extern inline uint64_t
3232
pcg_setseq_128_xsl_rr_64_random_r(pcg_state_setseq_128* rng);
3333
extern inline uint64_t
3434
pcg_setseq_128_xsl_rr_64_boundedrand_r(pcg_state_setseq_128* rng,
35-
uint64_t bound);
35+
uint64_t bound);
3636
extern inline void pcg_setseq_128_advance_r(pcg_state_setseq_128* rng, pcg128_t delta);
3737

3838
/* Multi-step advance functions (jump-ahead, jump-back)
@@ -49,41 +49,41 @@ extern inline void pcg_setseq_128_advance_r(pcg_state_setseq_128* rng, pcg128_t
4949
#ifndef PCG_EMULATED_128BIT_MATH
5050

5151
pcg128_t pcg_advance_lcg_128(pcg128_t state, pcg128_t delta, pcg128_t cur_mult,
52-
pcg128_t cur_plus)
52+
pcg128_t cur_plus)
5353
{
54-
pcg128_t acc_mult = 1u;
55-
pcg128_t acc_plus = 0u;
56-
while (delta > 0) {
57-
if (delta & 1) {
58-
acc_mult *= cur_mult;
59-
acc_plus = acc_plus * cur_mult + cur_plus;
60-
}
61-
cur_plus = (cur_mult + 1) * cur_plus;
62-
cur_mult *= cur_mult;
63-
delta /= 2;
64-
}
65-
return acc_mult * state + acc_plus;
54+
pcg128_t acc_mult = 1u;
55+
pcg128_t acc_plus = 0u;
56+
while (delta > 0) {
57+
if (delta & 1) {
58+
acc_mult *= cur_mult;
59+
acc_plus = acc_plus * cur_mult + cur_plus;
60+
}
61+
cur_plus = (cur_mult + 1) * cur_plus;
62+
cur_mult *= cur_mult;
63+
delta /= 2;
64+
}
65+
return acc_mult * state + acc_plus;
6666
}
6767

6868
#else
6969

7070
pcg128_t pcg_advance_lcg_128(pcg128_t state, pcg128_t delta, pcg128_t cur_mult,
71-
pcg128_t cur_plus)
71+
pcg128_t cur_plus)
7272
{
73-
pcg128_t acc_mult = PCG_128BIT_CONSTANT(0u, 1u);
74-
pcg128_t acc_plus = PCG_128BIT_CONSTANT(0u, 0u);
75-
while ((delta.high > 0) || (delta.low > 0)) {
76-
if (delta.low & 1) {
77-
acc_mult = _pcg128_mult(acc_mult, cur_mult);
78-
acc_plus = _pcg128_add(_pcg128_mult(acc_plus, cur_mult), cur_plus);
79-
}
80-
cur_plus = _pcg128_mult(_pcg128_add(cur_mult, PCG_128BIT_CONSTANT(0u, 1u)), cur_plus);
81-
cur_mult = _pcg128_mult(cur_mult, cur_mult);
82-
delta.low >>= 1;
83-
delta.low += delta.high & 1;
84-
delta.high >>= 1;
85-
}
86-
return _pcg128_add(_pcg128_mult(acc_mult, state), acc_plus);
73+
pcg128_t acc_mult = PCG_128BIT_CONSTANT(0u, 1u);
74+
pcg128_t acc_plus = PCG_128BIT_CONSTANT(0u, 0u);
75+
while ((delta.high > 0) || (delta.low > 0)) {
76+
if (delta.low & 1) {
77+
acc_mult = _pcg128_mult(acc_mult, cur_mult);
78+
acc_plus = _pcg128_add(_pcg128_mult(acc_plus, cur_mult), cur_plus);
79+
}
80+
cur_plus = _pcg128_mult(_pcg128_add(cur_mult, PCG_128BIT_CONSTANT(0u, 1u)), cur_plus);
81+
cur_mult = _pcg128_mult(cur_mult, cur_mult);
82+
delta.low >>= 1;
83+
delta.low += delta.high & 1;
84+
delta.high >>= 1;
85+
}
86+
return _pcg128_add(_pcg128_mult(acc_mult, state), acc_plus);
8787
}
8888

8989
#endif

0 commit comments

Comments
 (0)