Skip to content

Commit e6f192f

Browse files
committed
Always use np.intp for indices.
1 parent 9cf10a3 commit e6f192f

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

Diff for: sparse/_compressed/indexing.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ def get_slicing_selection(arr_data, arr_indices, indptr, starts, ends, col): #
231231
col_count += 1
232232
ind_list.extend(inds)
233233
indptr[i + 1] = indptr[i] + len(inds)
234-
ind_list = np.array(ind_list, dtype=np.int64)
234+
ind_list = np.array(ind_list, dtype=np.intp)
235235
indices = np.array(indices, dtype=indptr.dtype)
236236
data = arr_data[ind_list]
237237
return (data, indices, indptr)
@@ -260,7 +260,7 @@ def get_array_selection(arr_data, arr_indices, indptr, starts, ends, col): # pr
260260
indices.append(c)
261261
ind_list.extend(inds)
262262
indptr[i + 1] = indptr[i] + len(inds)
263-
ind_list = np.array(ind_list, dtype=np.int64)
263+
ind_list = np.array(ind_list, dtype=np.intp)
264264
indices = np.array(indices, dtype=indptr.dtype)
265265
data = arr_data[ind_list]
266266
return (data, indices, indptr)

Diff for: sparse/_umath.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import itertools
2+
import operator
3+
from functools import reduce
24
from itertools import zip_longest
35

46
import numba
@@ -256,7 +258,7 @@ def _get_expanded_coords_data(coords, data, params, broadcast_shape):
256258
expanded_data = data[all_idx[first_dim]]
257259
else:
258260
expanded_coords = all_idx if len(data) else np.empty((0, all_idx.shape[1]), dtype=np.intp)
259-
expanded_data = np.repeat(data, np.prod(broadcast_shape, dtype=np.int64))
261+
expanded_data = np.repeat(data, reduce(operator.mul, broadcast_shape, 1))
260262
return np.asarray(expanded_coords), np.asarray(expanded_data)
261263

262264
for d, p in zip(range(len(broadcast_shape)), params):

Diff for: sparse/_utils.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -110,19 +110,19 @@ def algD(n, N, random_state):
110110
N = size of system (elements)
111111
random_state = seed for random number generation
112112
"""
113-
n = np.int64(n + 1)
114-
N = np.int64(N)
113+
n = np.intp(n + 1)
114+
N = np.intp(N)
115115
qu1 = N - n + 1
116116
Vprime = np.exp(np.log(random_state.random()) / n)
117117
i = 0
118-
arr = np.zeros(n - 1, dtype=np.int64)
118+
arr = np.zeros(n - 1, dtype=np.intp)
119119
arr[-1] = -1
120120
while n > 1:
121121
nmin1inv = 1 / (n - 1)
122122
while True:
123123
while True:
124124
X = N * (1 - Vprime)
125-
S = np.int64(X)
125+
S = np.intp(X)
126126
if qu1 > S:
127127
break
128128
Vprime = np.exp(np.log(random_state.random()) / n)
@@ -167,9 +167,9 @@ def algA(n, N, random_state):
167167
N = size of system (elements)
168168
random_state = seed for random number generation
169169
"""
170-
n = np.int64(n)
171-
N = np.int64(N)
172-
arr = np.zeros(n, dtype=np.int64)
170+
n = np.intp(n)
171+
N = np.intp(N)
172+
arr = np.zeros(n, dtype=np.intp)
173173
arr[-1] = -1
174174
i = 0
175175
top = N - n
@@ -186,7 +186,7 @@ def algA(n, N, random_state):
186186
i += 1
187187
N -= 1
188188
n -= 1
189-
S = np.int64(N * random_state.random())
189+
S = np.intp(N * random_state.random())
190190
arr[i] = arr[i - 1] + S + 1
191191
i += 1
192192
return arr
@@ -197,11 +197,11 @@ def reverse(inv, N):
197197
"""
198198
If density of random matrix is greater than .5, it is faster to sample states not included
199199
Parameters:
200-
arr = np.array(np.int64) of indices to be excluded from sample
200+
arr = np.array(np.intp) of indices to be excluded from sample
201201
N = size of the system (elements)
202202
"""
203-
N = np.int64(N)
204-
a = np.zeros(np.int64(N - len(inv)), dtype=np.int64)
203+
N = np.intp(N)
204+
a = np.zeros(np.intp(N - len(inv)), dtype=np.intp)
205205
j = 0
206206
k = 0
207207
for i in range(N):

0 commit comments

Comments
 (0)