Skip to content

Commit 489c615

Browse files
bashtageSheppard, Kevin
authored andcommitted
CLN: Fix small type mismatches on variables
1 parent 1dce278 commit 489c615

File tree

5 files changed

+57
-46
lines changed

5 files changed

+57
-46
lines changed

randomstate/array_utilities.pxi

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ ctypedef uint32_t (* random_uint_1_i_32)(aug_state* state, uint32_t a) nogil
1616
ctypedef int32_t (* random_int_2_i_32)(aug_state* state, int32_t a, int32_t b) nogil
1717
ctypedef int64_t (* random_int_2_i)(aug_state* state, int64_t a, int64_t b) nogil
1818

19-
ctypedef void (* random_double_fill)(aug_state* state, int count, double *out) nogil
19+
ctypedef void (* random_double_fill)(aug_state* state, np.npy_intp count, double *out) nogil
2020

2121
cdef Py_ssize_t compute_numel(size):
2222
cdef Py_ssize_t i, n = 1
@@ -104,25 +104,28 @@ cdef object cont_broadcast_1(aug_state* state, void* func, object size, object l
104104
object a, object a_name, constraint_type a_constraint):
105105

106106
cdef np.ndarray a_arr, randoms
107+
cdef double *randoms_data
107108
cdef np.broadcast it
108109
cdef random_double_1 f = (<random_double_1>func)
110+
cdef np.npy_intp i, n
109111

110112
a_arr = <np.ndarray>np.PyArray_FROM_OTF(a, np.NPY_DOUBLE, np.NPY_ALIGNED)
111113
if a_constraint != CONS_NONE:
112114
check_array_constraint(a_arr, a_name, a_constraint)
113115

114116
if size is not None:
115-
randoms = np.empty(size, np.double)
117+
randoms = <np.ndarray>np.empty(size, np.double)
116118
else:
117-
#randoms = np.empty(np.shape(a_arr), np.double)
118119
randoms = np.PyArray_SimpleNew(np.PyArray_NDIM(a_arr), np.PyArray_DIMS(a_arr), np.NPY_DOUBLE)
119120

120-
121+
randoms_data = <double *>np.PyArray_DATA(randoms)
122+
n = np.PyArray_SIZE(randoms)
121123
it = np.broadcast(randoms, a_arr)
124+
122125
with lock, nogil:
123-
while np.PyArray_MultiIter_NOTDONE(it):
126+
for i in range(n):
124127
a_val = (<double*>np.PyArray_MultiIter_DATA(it, 1))[0]
125-
(<double*>np.PyArray_MultiIter_DATA(it, 0))[0] = f(state, a_val)
128+
randoms_data[i] = f(state, a_val)
126129

127130
np.PyArray_MultiIter_NEXT(it)
128131

@@ -132,8 +135,10 @@ cdef object cont_broadcast_2(aug_state* state, void* func, object size, object l
132135
object a, object a_name, constraint_type a_constraint,
133136
object b, object b_name, constraint_type b_constraint):
134137
cdef np.ndarray a_arr, b_arr, randoms
138+
cdef double *randoms_data
135139
cdef np.broadcast it
136140
cdef random_double_2 f = (<random_double_2>func)
141+
cdef np.npy_intp i, n
137142

138143
a_arr = <np.ndarray>np.PyArray_FROM_OTF(a, np.NPY_DOUBLE, np.NPY_ALIGNED)
139144
if a_constraint != CONS_NONE:
@@ -144,18 +149,22 @@ cdef object cont_broadcast_2(aug_state* state, void* func, object size, object l
144149
check_array_constraint(b_arr, b_name, b_constraint)
145150

146151
if size is not None:
147-
randoms = np.empty(size, np.double)
152+
randoms = <np.ndarray>np.empty(size, np.double)
148153
else:
149154
it = np.PyArray_MultiIterNew2(a_arr, b_arr)
150-
randoms = np.empty(it.shape, np.double)
155+
randoms = <np.ndarray>np.empty(it.shape, np.double)
151156
#randoms = np.PyArray_SimpleNew(it.nd, np.PyArray_DIMS(it), np.NPY_DOUBLE)
157+
# TODO: These are needed when using a for loop
158+
159+
randoms_data = <double *>np.PyArray_DATA(randoms)
160+
n = np.PyArray_SIZE(randoms)
152161

153162
it = np.PyArray_MultiIterNew3(randoms, a_arr, b_arr)
154163
with lock, nogil:
155-
while np.PyArray_MultiIter_NOTDONE(it):
164+
for i in range(n):
156165
a_val = (<double*>np.PyArray_MultiIter_DATA(it, 1))[0]
157166
b_val = (<double*>np.PyArray_MultiIter_DATA(it, 2))[0]
158-
(<double*>np.PyArray_MultiIter_DATA(it, 0))[0] = f(state, a_val, b_val)
167+
randoms_data[i] = f(state, a_val, b_val)
159168

160169
np.PyArray_MultiIter_NEXT(it)
161170

randomstate/bounded_integers.pxi

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ cdef object _rand_int64(low, high, size, aug_state *state, lock):
1313
cdef uint64_t off, rng, buf
1414
cdef uint64_t *out
1515
cdef np.ndarray array
16-
cdef int cnt
16+
cdef np.npy_intp cnt
1717

1818
rng = <uint64_t>(high - low)
1919
off = <uint64_t>(<int64_t>low)
@@ -68,7 +68,7 @@ cdef object _rand_int32(low, high, size, aug_state *state, lock):
6868
cdef uint32_t off, rng, buf
6969
cdef uint32_t *out
7070
cdef np.ndarray array
71-
cdef int cnt
71+
cdef np.npy_intp cnt
7272

7373
rng = <uint32_t>(high - low)
7474
off = <uint32_t>(<int32_t>low)
@@ -88,7 +88,7 @@ cdef object _rand_int16(low, high, size, aug_state *state, lock):
8888
cdef uint16_t off, rng, buf
8989
cdef uint16_t *out
9090
cdef np.ndarray array
91-
cdef int cnt
91+
cdef np.npy_intp cnt
9292

9393
rng = <uint16_t>(high - low)
9494
off = <uint16_t>(<int16_t>low)
@@ -108,7 +108,7 @@ cdef object _rand_int8(low, high, size, aug_state *state, lock):
108108
cdef uint8_t off, rng, buf
109109
cdef uint8_t *out
110110
cdef np.ndarray array
111-
cdef int cnt
111+
cdef np.npy_intp cnt
112112

113113
rng = <uint8_t>(high - low)
114114
off = <uint8_t>(<int8_t>low)
@@ -131,7 +131,7 @@ cdef object _rand_uint64(low, high, size, aug_state *state, lock):
131131
cdef uint64_t off, rng, buf
132132
cdef uint64_t *out
133133
cdef np.ndarray array
134-
cdef int cnt
134+
cdef np.npy_intp cnt
135135

136136
rng = <uint64_t>(high - low)
137137
off = <uint64_t>low
@@ -151,7 +151,7 @@ cdef object _rand_uint32(low, high, size, aug_state *state, lock):
151151
cdef uint32_t off, rng, buf
152152
cdef uint32_t *out
153153
cdef np.ndarray array
154-
cdef int cnt
154+
cdef np.npy_intp cnt
155155

156156
rng = <uint32_t>(high - low)
157157
off = <uint32_t>low
@@ -171,7 +171,7 @@ cdef object _rand_uint16(low, high, size, aug_state *state, lock):
171171
cdef uint16_t off, rng, buf
172172
cdef uint16_t *out
173173
cdef np.ndarray array
174-
cdef int cnt
174+
cdef np.npy_intp cnt
175175

176176
rng = <uint16_t>(high - low)
177177
off = <uint16_t>low
@@ -191,7 +191,7 @@ cdef object _rand_uint8(low, high, size, aug_state *state, lock):
191191
cdef uint8_t off, rng, buf
192192
cdef uint8_t *out
193193
cdef np.ndarray array
194-
cdef int cnt
194+
cdef np.npy_intp cnt
195195

196196
rng = <uint8_t>(high - low)
197197
off = <uint8_t>low
@@ -212,7 +212,7 @@ cdef object _rand_bool(low, high, size, aug_state *state, lock):
212212
cdef int8_t off, rng, buf
213213
cdef int8_t *out
214214
cdef np.ndarray array
215-
cdef int cnt
215+
cdef np.npy_intp cnt
216216

217217
rng = <uint8_t>(high - low)
218218
off = <uint8_t>low

randomstate/distributions.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ double random_standard_uniform(aug_state* state)
3636
}
3737

3838

39-
void random_uniform_fill(aug_state* state, int count, double *out)
39+
void random_uniform_fill(aug_state* state, intptr_t count, double *out)
4040
{
4141
int i;
4242
for (i=0; i < count; i++) {
@@ -50,7 +50,7 @@ double random_standard_exponential(aug_state* state)
5050
return -log(1.0 - random_double(state));
5151
}
5252

53-
void random_standard_exponential_fill(aug_state* state, int count, double *out)
53+
void random_standard_exponential_fill(aug_state* state, intptr_t count, double *out)
5454
{
5555
int i;
5656
for (i=0; i < count; i++) {
@@ -87,7 +87,7 @@ double random_gauss(aug_state* state) {
8787
}
8888
}
8989

90-
void random_gauss_fill(aug_state* state, int count, double *out) {
90+
void random_gauss_fill(aug_state* state, intptr_t count, double *out) {
9191
int i;
9292
double f, x1, x2, r2;
9393
for (i = 0; i< count; i++) {
@@ -1354,7 +1354,7 @@ double random_gauss_zig_julia(aug_state *state) {
13541354
}
13551355

13561356

1357-
void random_gauss_zig_julia_fill(aug_state *state, int count, double *out) {
1357+
void random_gauss_zig_julia_fill(aug_state *state, intptr_t count, double *out) {
13581358
uint64_t r;
13591359
int64_t rabs;
13601360
int idx, i;
@@ -1444,7 +1444,7 @@ static inline uint64_t gen_mask(uint64_t max)
14441444
* Fills an array with cnt random npy_uint64 between off and off + rng
14451445
* inclusive. The numbers wrap if rng is sufficiently large.
14461446
*/
1447-
void random_bounded_uint64_fill(aug_state *state, uint64_t off, uint64_t rng, int cnt, uint64_t *out)
1447+
void random_bounded_uint64_fill(aug_state *state, uint64_t off, uint64_t rng, intptr_t cnt, uint64_t *out)
14481448
{
14491449
uint64_t val, mask;
14501450
int i;
@@ -1478,7 +1478,7 @@ void random_bounded_uint64_fill(aug_state *state, uint64_t off, uint64_t rng, in
14781478
* Fills an array with cnt random npy_uint32 between off and off + rng
14791479
* inclusive. The numbers wrap if rng is sufficiently large.
14801480
*/
1481-
void random_bounded_uint32_fill(aug_state *state, uint32_t off, uint32_t rng, int cnt, uint32_t *out)
1481+
void random_bounded_uint32_fill(aug_state *state, uint32_t off, uint32_t rng, intptr_t cnt, uint32_t *out)
14821482
{
14831483
uint32_t val, mask = rng;
14841484
int i;
@@ -1504,7 +1504,7 @@ void random_bounded_uint32_fill(aug_state *state, uint32_t off, uint32_t rng, in
15041504
* Fills an array with cnt random npy_uint16 between off and off + rng
15051505
* inclusive. The numbers wrap if rng is sufficiently large.
15061506
*/
1507-
void random_bounded_uint16_fill(aug_state *state, uint16_t off, uint16_t rng, int cnt, uint16_t *out)
1507+
void random_bounded_uint16_fill(aug_state *state, uint16_t off, uint16_t rng, intptr_t cnt, uint16_t *out)
15081508
{
15091509
uint16_t val, mask;
15101510
int i;
@@ -1541,7 +1541,7 @@ void random_bounded_uint16_fill(aug_state *state, uint16_t off, uint16_t rng, in
15411541
* Fills an array with cnt random npy_uint8 between off and off + rng
15421542
* inclusive. The numbers wrap if rng is sufficiently large.
15431543
*/
1544-
void random_bounded_uint8_fill(aug_state *state, uint8_t off, uint8_t rng, int cnt, uint8_t *out)
1544+
void random_bounded_uint8_fill(aug_state *state, uint8_t off, uint8_t rng, intptr_t cnt, uint8_t *out)
15451545
{
15461546
uint8_t val, mask = rng;
15471547
int i;
@@ -1580,7 +1580,7 @@ void random_bounded_uint8_fill(aug_state *state, uint8_t off, uint8_t rng, int c
15801580
* inclusive.
15811581
*/
15821582
/* TODO: This needs to use bools. See original */
1583-
void random_bool_fill(aug_state *state, int8_t off, int8_t rng, int cnt, int8_t *out)
1583+
void random_bool_fill(aug_state *state, int8_t off, int8_t rng, intptr_t cnt, int8_t *out)
15841584
{
15851585
int i;
15861586
uint32_t buf = 0;

randomstate/distributions.h

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
#include <stdlib.h>
33

44
#ifdef _WIN32
5+
#include "src/common/stdint.h"
56
typedef int bool;
67
#define false 0
78
#define true 1
89
#else
10+
#include <stdint.h>
911
#endif
1012

1113
#ifndef min
@@ -121,20 +123,20 @@ extern unsigned long random_uint(aug_state* state);
121123

122124
extern unsigned long random_interval(aug_state* state, unsigned long max);
123125

124-
extern void random_bounded_uint64_fill(aug_state *state, uint64_t off, uint64_t rng, int cnt, uint64_t *out);
126+
extern void random_bounded_uint64_fill(aug_state *state, uint64_t off, uint64_t rng, intptr_t cnt, uint64_t *out);
125127

126-
extern void random_bounded_uint32_fill(aug_state *state, uint32_t off, uint32_t rng, int cnt,uint32_t *out);
128+
extern void random_bounded_uint32_fill(aug_state *state, uint32_t off, uint32_t rng, intptr_t cnt, uint32_t *out);
127129

128-
extern void random_bounded_uint16_fill(aug_state *state, uint16_t off, uint16_t rng, int cnt, uint16_t *out);
130+
extern void random_bounded_uint16_fill(aug_state *state, uint16_t off, uint16_t rng, intptr_t cnt, uint16_t *out);
129131

130-
extern void random_bounded_uint8_fill(aug_state *state, uint8_t off, uint8_t rng, int cnt, uint8_t *out);
132+
extern void random_bounded_uint8_fill(aug_state *state, uint8_t off, uint8_t rng, intptr_t cnt, uint8_t *out);
131133

132-
extern void random_bool_fill(aug_state *state, int8_t off, int8_t rng, int cnt, int8_t *out);
134+
extern void random_bool_fill(aug_state *state, int8_t off, int8_t rng, intptr_t cnt, int8_t *out);
133135

134-
extern void random_uniform_fill(aug_state* state, int count, double *out);
136+
extern void random_uniform_fill(aug_state* state, intptr_t count, double *out);
135137

136-
extern void random_standard_exponential_fill(aug_state* state, int count, double *out);
138+
extern void random_standard_exponential_fill(aug_state* state, intptr_t count, double *out);
137139

138-
extern void random_gauss_fill(aug_state* state, int count, double *out);
140+
extern void random_gauss_fill(aug_state* state, intptr_t count, double *out);
139141

140-
extern void random_gauss_zig_julia_fill(aug_state *state, int count, double *out);
142+
extern void random_gauss_zig_julia_fill(aug_state *state, intptr_t count, double *out);

randomstate/interface.pyx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,15 @@ cdef extern from "distributions.h":
102102
cdef long random_zipf(aug_state *state, double a) nogil
103103
cdef long random_hypergeometric(aug_state *state, long good, long bad, long sample) nogil
104104

105-
cdef void random_bounded_uint64_fill(aug_state *state, uint64_t off, uint64_t rng, int cnt, uint64_t *out) nogil
106-
cdef void random_bounded_uint32_fill(aug_state *state, uint32_t off, uint32_t rng, int cnt,uint32_t *out) nogil
107-
cdef void random_bounded_uint16_fill(aug_state *state, uint16_t off, uint16_t rng, int cnt, uint16_t *out) nogil
108-
cdef void random_bounded_uint8_fill(aug_state *state, uint8_t off, uint8_t rng, int cnt, uint8_t *out) nogil
109-
cdef void random_bool_fill(aug_state *state, int8_t off, int8_t rng, int cnt, int8_t *out) nogil
110-
cdef void random_uniform_fill(aug_state *state, int cnt, double *out) nogil
111-
cdef void random_standard_exponential_fill(aug_state* state, int count, double *out) nogil
112-
cdef void random_gauss_fill(aug_state* state, int count, double *out) nogil
113-
cdef void random_gauss_zig_julia_fill(aug_state* state, int count, double *out) nogil
105+
cdef void random_bounded_uint64_fill(aug_state *state, uint64_t off, uint64_t rng, intptr_t cnt, uint64_t *out) nogil
106+
cdef void random_bounded_uint32_fill(aug_state *state, uint32_t off, uint32_t rng, intptr_t cnt,uint32_t *out) nogil
107+
cdef void random_bounded_uint16_fill(aug_state *state, uint16_t off, uint16_t rng, intptr_t cnt, uint16_t *out) nogil
108+
cdef void random_bounded_uint8_fill(aug_state *state, uint8_t off, uint8_t rng, intptr_t cnt, uint8_t *out) nogil
109+
cdef void random_bool_fill(aug_state *state, int8_t off, int8_t rng, intptr_t cnt, int8_t *out) nogil
110+
cdef void random_uniform_fill(aug_state *state, intptr_t cnt, double *out) nogil
111+
cdef void random_standard_exponential_fill(aug_state* state, intptr_t count, double *out) nogil
112+
cdef void random_gauss_fill(aug_state* state, intptr_t count, double *out) nogil
113+
cdef void random_gauss_zig_julia_fill(aug_state* state, intptr_t count, double *out) nogil
114114

115115
include "array_utilities.pxi"
116116
include "bounded_integers.pxi"

0 commit comments

Comments
 (0)