code: def test_calculate_loss_simple(use_gpu):
      if use_gpu:
          calculate_loss = implicit.gpu.als.calculate_loss
  
      else:
          calculate_loss = implicit.cpu.als.calculate_loss
  
      # the only user has liked item 0, but not interacted with item 1
      n_users, n_items = 1, 2
      ratings = coo_matrix(
          ([1.0], ([0], [0])), shape=(n_users, n_items)
      ).tocsr()
  
      # factors are designed to be perfectly wrong, to test loss function
      item_factors = np.array([[0.0], [1.0]], dtype="float32")
      user_factors = np.array([[1.0]], dtype="float32")
  
      loss = calculate_loss(
          ratings, user_factors, item_factors, regularization=0
      )
      assert loss == pytest.approx(1.0)
  
      loss = calculate_loss(
          ratings, user_factors, item_factors, regularization=1.0
      )
      assert loss == pytest.approx(2.0)
  
imports: import pickle
  import unittest
  import numpy
  import pytest
  from numpy.testing import assert_array_equal
  from recommender_base_test import RecommenderBaseTestMixin, get_checker_board
  from scipy.sparse import coo_matrix, csr_matrix, random
  import implicit
  from implicit.als import AlternatingLeastSquares
  from implicit.gpu import HAS_CUDA
label_desc: Use image node_id 10 for calling a global function with example usage: test_calculate_loss_simple(use_gpu) without return types