code: def test_als_binpickle(tmp_path):
      "Test saving ALS with BinPickle"
  
      original = als.BiasedMF(20, iterations=5, method="lu")
      ratings = lktu.ml_test.ratings
      original.fit(ratings)
  
      assert original.bias.mean_ == approx(ratings.rating.mean())
  
      file = tmp_path / "als.bpk"
      binpickle.dump(original, file)
  
      with binpickle.BinPickleFile(file) as bpf:
          # the pickle data should be small
          _log.info(
              "serialized to %d pickle bytes",
              bpf.entries[-1].dec_length,
          )
          pickle_dis(bpf._read_buffer(bpf.entries[-1]))
          assert bpf.entries[-1].dec_length < 2048
  
          algo = bpf.load()
  
          assert algo.bias.mean_ == original.bias.mean_
          assert np.all(
              algo.bias.user_offsets_ == original.bias.user_offsets_
          )
          assert np.all(
              algo.bias.item_offsets_ == original.bias.item_offsets_
          )
          assert np.all(algo.user_features_ == original.user_features_)
          assert np.all(algo.item_features_ == original.item_features_)
          assert np.all(algo.item_index_ == original.item_index_)
          assert np.all(algo.user_index_ == original.user_index_)
  
          # make sure it still works
          preds = algo.predict_for_user(
              10, np.arange(0, 50, dtype="i8")
          )
          assert len(preds) == 50
  
imports: import logging
  import pickle
  from pickletools import dis
  from lenskit.algorithms import als
  from lenskit import util
  import pandas
  import numpy
  from seedbank import numpy_rng
  from pytest import approx, mark
  from lenskit.util import Stopwatch
  import lenskit.util.test
label_desc: Use image node_id 12 for calling a global function with example usage: test_als_binpickle(tmp_path) without return types