@@ -174,6 +174,48 @@ def test_consistent_with_pure_implicit(
174174 actual_scores = actual_reco .loc [actual_reco [Columns .User ] == user_id , Columns .Score ].values
175175 np .testing .assert_equal (actual_internal_ids , expected_ids )
176176 np .testing .assert_allclose (actual_scores , expected_scores , atol = 0.01 )
177+
178+
179+
180+ @pytest .mark .parametrize ("fit_features_together" , (False , True ))
181+ @pytest .mark .parametrize ("init_model_before_fit" , (False , True ))
182+ def test_gpu_ranking_consistent_with_pure_implicit (
183+ self , dataset : Dataset , fit_features_together : bool , use_gpu : bool , init_model_before_fit : bool
184+ ) -> None :
185+ base_model = AlternatingLeastSquares (factors = 10 , num_threads = 2 , iterations = 30 , use_gpu = False , random_state = 32 )
186+ if init_model_before_fit :
187+ self ._init_model_factors_inplace (base_model , dataset )
188+ users = np .array ([10 , 20 , 30 , 40 ])
189+
190+
191+ ui_csr = dataset .get_user_item_matrix (include_weights = True )
192+ base_model .fit (ui_csr )
193+ gpu_model = base_model .to_gpu ()
194+
195+ wrapped_model = ImplicitALSWrapperModel (model = gpu_model , fit_features_together = fit_features_together , recommend_use_gpu_ranking = True )
196+ wrapped_model .is_fitted = True
197+ wrapped_model .model = wrapped_model ._model
198+
199+ actual_reco = wrapped_model .recommend (
200+ users = users ,
201+ dataset = dataset ,
202+ k = 3 ,
203+ filter_viewed = False ,
204+ )
205+
206+ for user_id in users :
207+ internal_id = dataset .user_id_map .convert_to_internal ([user_id ])[0 ]
208+ expected_ids , expected_scores = gpu_model .recommend (
209+ userid = internal_id ,
210+ user_items = ui_csr [internal_id ],
211+ N = 3 ,
212+ filter_already_liked_items = False ,
213+ )
214+ actual_ids = actual_reco .loc [actual_reco [Columns .User ] == user_id , Columns .Item ].values
215+ actual_internal_ids = dataset .item_id_map .convert_to_internal (actual_ids )
216+ actual_scores = actual_reco .loc [actual_reco [Columns .User ] == user_id , Columns .Score ].values
217+ np .testing .assert_equal (actual_internal_ids , expected_ids )
218+ np .testing .assert_allclose (actual_scores , expected_scores , atol = 0.00001 )
177219
178220 @pytest .mark .parametrize (
179221 "filter_viewed,expected" ,
0 commit comments