@@ -91,7 +91,7 @@ def dcg_score(gt_pos, pd_rank, k=-1):
9191 else :
9292 truncated_pd_rank = pd_rank
9393
94- ranked_scores = np .in1d (truncated_pd_rank , gt_pos ).astype (int )
94+ ranked_scores = np .isin (truncated_pd_rank , gt_pos ).astype (int )
9595 gain = 2 ** ranked_scores - 1
9696 discounts = np .log2 (np .arange (len (ranked_scores )) + 2 )
9797
@@ -162,7 +162,7 @@ def compute(self, gt_pos, pd_rank, **kwargs):
162162 truncated_pd_rank = pd_rank
163163
164164 # Compute CRR
165- rec_rank = np .where (np .in1d (truncated_pd_rank , gt_pos ))[0 ]
165+ rec_rank = np .where (np .isin (truncated_pd_rank , gt_pos ))[0 ]
166166 if len (rec_rank ) == 0 :
167167 return 0.0
168168 rec_rank = rec_rank + 1 # +1 because indices starts from 0 in python
@@ -210,7 +210,7 @@ def compute(self, gt_pos, pd_rank, **kwargs):
210210 Mean Reciprocal Rank score.
211211
212212 """
213- matched_items = np .nonzero (np .in1d (pd_rank , gt_pos ))[0 ]
213+ matched_items = np .nonzero (np .isin (pd_rank , gt_pos ))[0 ]
214214
215215 if len (matched_items ) == 0 :
216216 raise ValueError (
@@ -267,7 +267,7 @@ def compute(self, gt_pos, pd_rank, **kwargs):
267267 else :
268268 truncated_pd_rank = pd_rank
269269
270- tp = np .sum (np .in1d (truncated_pd_rank , gt_pos ))
270+ tp = np .sum (np .isin (truncated_pd_rank , gt_pos ))
271271 tp_fn = len (gt_pos )
272272 tp_fp = self .k if self .k > 0 else len (truncated_pd_rank )
273273
@@ -470,11 +470,11 @@ def compute(self, item_indices, pd_scores, gt_pos, gt_neg=None, **kwargs):
470470
471471 """
472472
473- gt_pos_mask = np .in1d (item_indices , gt_pos )
473+ gt_pos_mask = np .isin (item_indices , gt_pos )
474474 gt_neg_mask = (
475475 np .logical_not (gt_pos_mask )
476476 if gt_neg is None
477- else np .in1d (item_indices , gt_neg )
477+ else np .isin (item_indices , gt_neg )
478478 )
479479
480480 pos_scores = pd_scores [gt_pos_mask ]
@@ -519,7 +519,7 @@ def compute(self, item_indices, pd_scores, gt_pos, **kwargs):
519519 AP score.
520520
521521 """
522- relevant = np .in1d (item_indices , gt_pos )
522+ relevant = np .isin (item_indices , gt_pos )
523523 rank = rankdata (- pd_scores , "max" )[relevant ]
524524 L = rankdata (- pd_scores [relevant ], "max" )
525525 ans = (L / rank ).mean ()
0 commit comments