Skip to content

Commit

Permalink
Always use np.intp for indices. (#634)
Browse files Browse the repository at this point in the history
  • Loading branch information
hameerabbasi committed May 17, 2024
1 parent e530ed9 commit 948f55f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
4 changes: 2 additions & 2 deletions sparse/_compressed/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def get_slicing_selection(arr_data, arr_indices, indptr, starts, ends, col): #
col_count += 1
ind_list.extend(inds)
indptr[i + 1] = indptr[i] + len(inds)
ind_list = np.array(ind_list, dtype=np.int64)
ind_list = np.array(ind_list, dtype=np.intp)
indices = np.array(indices, dtype=indptr.dtype)
data = arr_data[ind_list]
return (data, indices, indptr)
Expand Down Expand Up @@ -260,7 +260,7 @@ def get_array_selection(arr_data, arr_indices, indptr, starts, ends, col): # pr
indices.append(c)
ind_list.extend(inds)
indptr[i + 1] = indptr[i] + len(inds)
ind_list = np.array(ind_list, dtype=np.int64)
ind_list = np.array(ind_list, dtype=np.intp)
indices = np.array(indices, dtype=indptr.dtype)
data = arr_data[ind_list]
return (data, indices, indptr)
Expand Down
4 changes: 3 additions & 1 deletion sparse/_umath.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import itertools
import operator
from functools import reduce
from itertools import zip_longest

import numba
Expand Down Expand Up @@ -257,7 +259,7 @@ def _get_expanded_coords_data(coords, data, params, broadcast_shape):
expanded_data = data[all_idx[first_dim]]
else:
expanded_coords = all_idx if len(data) else np.empty((0, all_idx.shape[1]), dtype=np.intp)
expanded_data = np.repeat(data, np.prod(broadcast_shape, dtype=np.int64))
expanded_data = np.repeat(data, reduce(operator.mul, broadcast_shape, 1))
return np.asarray(expanded_coords), np.asarray(expanded_data)

for d, p in zip(range(len(broadcast_shape)), params):
Expand Down
22 changes: 11 additions & 11 deletions sparse/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,19 +111,19 @@ def algD(n, N, random_state):
N = size of system (elements)
random_state = seed for random number generation
"""
n = np.int64(n + 1)
N = np.int64(N)
n = np.intp(n + 1)
N = np.intp(N)
qu1 = N - n + 1
Vprime = np.exp(np.log(random_state.random()) / n)
i = 0
arr = np.zeros(n - 1, dtype=np.int64)
arr = np.zeros(n - 1, dtype=np.intp)
arr[-1] = -1
while n > 1:
nmin1inv = 1 / (n - 1)
while True:
while True:
X = N * (1 - Vprime)
S = np.int64(X)
S = np.intp(X)
if qu1 > S:
break
Vprime = np.exp(np.log(random_state.random()) / n)
Expand Down Expand Up @@ -168,9 +168,9 @@ def algA(n, N, random_state):
N = size of system (elements)
random_state = seed for random number generation
"""
n = np.int64(n)
N = np.int64(N)
arr = np.zeros(n, dtype=np.int64)
n = np.intp(n)
N = np.intp(N)
arr = np.zeros(n, dtype=np.intp)
arr[-1] = -1
i = 0
top = N - n
Expand All @@ -187,7 +187,7 @@ def algA(n, N, random_state):
i += 1
N -= 1
n -= 1
S = np.int64(N * random_state.random())
S = np.intp(N * random_state.random())
arr[i] = arr[i - 1] + S + 1
i += 1
return arr
Expand All @@ -198,11 +198,11 @@ def reverse(inv, N):
"""
If density of random matrix is greater than .5, it is faster to sample states not included
Parameters:
arr = np.array(np.int64) of indices to be excluded from sample
arr = np.array(np.intp) of indices to be excluded from sample
N = size of the system (elements)
"""
N = np.int64(N)
a = np.zeros(np.int64(N - len(inv)), dtype=np.int64)
N = np.intp(N)
a = np.zeros(np.intp(N - len(inv)), dtype=np.intp)
j = 0
k = 0
for i in range(N):
Expand Down

0 comments on commit 948f55f

Please sign in to comment.