Skip to content

Always use np.intp for indices. #634

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -256,7 +258,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 @@ -110,19 +110,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 @@ -167,9 +167,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 @@ -186,7 +186,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 @@ -197,11 +197,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