Skip to content

Commit 948f55f

Browse files
committed
Always use np.intp for indices. (#634)
1 parent e530ed9 commit 948f55f

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

sparse/_compressed/indexing.py

Lines changed: 2 additions & 2 deletions
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)

sparse/_umath.py

Lines changed: 3 additions & 1 deletion
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
@@ -257,7 +259,7 @@ def _get_expanded_coords_data(coords, data, params, broadcast_shape):
257259
expanded_data = data[all_idx[first_dim]]
258260
else:
259261
expanded_coords = all_idx if len(data) else np.empty((0, all_idx.shape[1]), dtype=np.intp)
260-
expanded_data = np.repeat(data, np.prod(broadcast_shape, dtype=np.int64))
262+
expanded_data = np.repeat(data, reduce(operator.mul, broadcast_shape, 1))
261263
return np.asarray(expanded_coords), np.asarray(expanded_data)
262264

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

sparse/_utils.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -111,19 +111,19 @@ def algD(n, N, random_state):
111111
N = size of system (elements)
112112
random_state = seed for random number generation
113113
"""
114-
n = np.int64(n + 1)
115-
N = np.int64(N)
114+
n = np.intp(n + 1)
115+
N = np.intp(N)
116116
qu1 = N - n + 1
117117
Vprime = np.exp(np.log(random_state.random()) / n)
118118
i = 0
119-
arr = np.zeros(n - 1, dtype=np.int64)
119+
arr = np.zeros(n - 1, dtype=np.intp)
120120
arr[-1] = -1
121121
while n > 1:
122122
nmin1inv = 1 / (n - 1)
123123
while True:
124124
while True:
125125
X = N * (1 - Vprime)
126-
S = np.int64(X)
126+
S = np.intp(X)
127127
if qu1 > S:
128128
break
129129
Vprime = np.exp(np.log(random_state.random()) / n)
@@ -168,9 +168,9 @@ def algA(n, N, random_state):
168168
N = size of system (elements)
169169
random_state = seed for random number generation
170170
"""
171-
n = np.int64(n)
172-
N = np.int64(N)
173-
arr = np.zeros(n, dtype=np.int64)
171+
n = np.intp(n)
172+
N = np.intp(N)
173+
arr = np.zeros(n, dtype=np.intp)
174174
arr[-1] = -1
175175
i = 0
176176
top = N - n
@@ -187,7 +187,7 @@ def algA(n, N, random_state):
187187
i += 1
188188
N -= 1
189189
n -= 1
190-
S = np.int64(N * random_state.random())
190+
S = np.intp(N * random_state.random())
191191
arr[i] = arr[i - 1] + S + 1
192192
i += 1
193193
return arr
@@ -198,11 +198,11 @@ def reverse(inv, N):
198198
"""
199199
If density of random matrix is greater than .5, it is faster to sample states not included
200200
Parameters:
201-
arr = np.array(np.int64) of indices to be excluded from sample
201+
arr = np.array(np.intp) of indices to be excluded from sample
202202
N = size of the system (elements)
203203
"""
204-
N = np.int64(N)
205-
a = np.zeros(np.int64(N - len(inv)), dtype=np.int64)
204+
N = np.intp(N)
205+
a = np.zeros(np.intp(N - len(inv)), dtype=np.intp)
206206
j = 0
207207
k = 0
208208
for i in range(N):

0 commit comments

Comments
 (0)