Skip to content

Commit fc543ad

Browse files
committed
Minor fixes
1 parent dcb21ee commit fc543ad

5 files changed

Lines changed: 12 additions & 10 deletions

File tree

illico/utils/ranking.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
@njit(nogil=True, cache=False, fastmath=True)
88
def _accumulate_group_ranksums_from_argsort(
99
arr: np.ndarray, idx: np.ndarray, groups: np.ndarray, ranksums: np.ndarray, zero_values_offset: int = 0
10-
) -> tuple[np.ndarray, int]:
10+
) -> tuple[float, int]:
1111
"""From a given array of values, indices of sorted values (result of np.argsort) and groups, accumulate group rank
1212
sums in the placegolder `ranksums`.
1313
@@ -21,7 +21,7 @@ def _accumulate_group_ranksums_from_argsort(
2121
on non zero values.
2222
2323
Returns:
24-
np.ndarray: tie sums
24+
float: tie sums
2525
int: position of zeros in the sorted array (if zero_values_offset > 0)
2626
2727
Author: Rémy Dubois
@@ -93,7 +93,7 @@ def rank_sum_and_ties_from_sorted(A: np.ndarray, B: np.ndarray, zero_values_offs
9393
k = 0 # number of items processed so far (0-based)
9494
zero_pos = -1 # Default setting
9595

96-
sum_ranks_B = 0
96+
sum_ranks_B = 0.0
9797
tie_sum = 0.0
9898

9999
# main sweep

src/dense_ovr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub fn dense_ovr_kernel<D: SparseFloat>(
3333
let mut tie_sums = Array1::zeros(chunk_ub - chunk_lb);
3434
for j in 0..chunk.dim().1 {
3535
let sorted_indices = argsort(chunk.column(j));
36-
_ = accumulate_rank_and_tie_sums_from_argsort(
36+
accumulate_rank_and_tie_sums_from_argsort(
3737
chunk.column(j),
3838
sorted_indices,
3939
grpc.encoded_groups,

src/ranking.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ pub fn rank_sum_and_ties<D: SparseFloat>(
157157
while j < n_tgt {
158158
let v = tgt[j];
159159

160-
if (v.to_f64() > 0.) & (zero_values_offset > 0) {
160+
if (v.to_f64() > 0.) && (zero_values_offset > 0) {
161161
zero_pos = k as isize;
162162
k += zero_values_offset;
163163
zero_values_offset = 0;
@@ -184,7 +184,7 @@ pub fn rank_sum_and_ties<D: SparseFloat>(
184184
k += count_tgt;
185185
}
186186

187-
if (zero_pos == -1) & (zero_values_offset > 0) {
187+
if (zero_pos == -1) && (zero_values_offset > 0) {
188188
zero_pos = k as isize;
189189
}
190190

@@ -250,7 +250,7 @@ pub fn accumulate_rank_and_tie_sums_from_argsort<D: SparseFloat>(
250250
while i < n_values {
251251
// Find tie block
252252
let mut j = i + 1;
253-
if (zero_values_offset > 0) & (x[sorted_indices[i]].to_f64() > 0.) {
253+
if (zero_values_offset > 0) && (x[sorted_indices[i]].to_f64() > 0.) {
254254
zero_pos = i as isize;
255255
rank += zero_values_offset;
256256
zero_values_offset = 0;
@@ -278,7 +278,7 @@ pub fn accumulate_rank_and_tie_sums_from_argsort<D: SparseFloat>(
278278
i = j;
279279
}
280280

281-
if (zero_pos == -1) & (zero_values_offset > 0) {
281+
if (zero_pos == -1) && (zero_values_offset > 0) {
282282
zero_pos = n_values as isize;
283283
}
284284

tests/conftest.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,12 @@ def rand_adata(request, tmp_path):
102102
groups = rng.randint(0, n_groups, size=n_cells) # Add one ref group
103103

104104
# Now cover all possible negative value scenarios: some with all negative values, some with a mix of both
105-
# By defaults dense_counts only contains positive values
105+
# By default dense_counts only contains positive values
106106
dense_counts[:, 0] *= -1.0 # all negative in the first column
107107
dense_counts[groups == 0, 1] *= -1.0 # First group all negative, rest all positives in the second column
108108
dense_counts[np.isin(groups, [0, 1]), 2] *= -1.0 # Two groups all negative, rest all positives in the third column
109+
dense_counts[groups == 0, 3][::2] *= -1.0 # Ref is both pos and neg in the fourth column
110+
dense_counts[groups == 1, 4][::2] *= -1.0 # Target is both pos and neg in the fifth column
109111

110112
fmt, lazy = request.param
111113
if fmt == "dense":

tests/utils/test_ranking.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def test_rank_sum_and_ties_from_sorted(format):
3030
n_zeros_A = (A == 0).sum()
3131
n_zeros_B = (B == 0).sum()
3232
n_zeros = n_zeros_A + n_zeros_B
33-
A, B = A[A != 0], B[B != 0] # Keep only positive values to have ties
33+
A, B = A[A != 0], B[B != 0] # Keep only non-null values to have ties
3434
else:
3535
n_zeros_A = n_zeros_B = n_zeros = 0
3636
A.sort()

0 commit comments

Comments
 (0)