Skip to content

Commit

Permalink
Always use np.intp for indices.
Browse files Browse the repository at this point in the history
  • Loading branch information
hameerabbasi committed Jan 18, 2024
1 parent c57fed2 commit f2e43eb
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 @@ -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)

Check warning on line 114 in sparse/_utils.py

View check run for this annotation

Codecov / codecov/patch

sparse/_utils.py#L113-L114

Added lines #L113 - L114 were not covered by tests
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)

Check warning on line 118 in sparse/_utils.py

View check run for this annotation

Codecov / codecov/patch

sparse/_utils.py#L118

Added line #L118 was not covered by tests
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)

Check warning on line 125 in sparse/_utils.py

View check run for this annotation

Codecov / codecov/patch

sparse/_utils.py#L125

Added line #L125 was not covered by tests
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)

Check warning on line 172 in sparse/_utils.py

View check run for this annotation

Codecov / codecov/patch

sparse/_utils.py#L170-L172

Added lines #L170 - L172 were not covered by tests
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())

Check warning on line 189 in sparse/_utils.py

View check run for this annotation

Codecov / codecov/patch

sparse/_utils.py#L189

Added line #L189 was not covered by tests
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)

Check warning on line 204 in sparse/_utils.py

View check run for this annotation

Codecov / codecov/patch

sparse/_utils.py#L203-L204

Added lines #L203 - L204 were not covered by tests
j = 0
k = 0
for i in range(N):
Expand Down

0 comments on commit f2e43eb

Please sign in to comment.