code: def compute_unary_terms_ref(codebooks, x):
      codebooks_t = np.swapaxes(codebooks, 1, 2)  # [M, d, K]
      unaries = -2 * x.dot(codebooks_t)  # [n, M, K]
      code_norms = np.sum(codebooks * codebooks, axis=2)  # [M, K]
      unaries += code_norms
      unaries = np.swapaxes(unaries, 0, 1)  # [M, n, K]
  
      return unaries
  
imports: import numpy
  import faiss
  import unittest
  from faiss.contrib import datasets
label_desc: Use image node_id 4 for calling a global function with example usage: compute_unary_terms_ref(codebooks, x) and returns: unaries