code: def test_non_negative_parafac_hals_one_unconstrained():
      """Test for non-negative PARAFAC HALS
      TODO: more rigorous test
      """
      rng = tl.check_random_state(1234)
      t_shape = (8, 9, 10)
      rank = 3
      weights = T.tensor(rng.uniform(size=rank))
      A = T.tensor(rng.uniform(size=(t_shape[0], rank)))
      B = T.tensor(rng.standard_normal(size=(t_shape[1], rank)))
      C = T.tensor(rng.uniform(0.1, 1.1, size=(t_shape[2], rank)))
      cp_tensor = (weights, (A, B, C))
      X = cp_to_tensor(cp_tensor)
  
      nn_estimate, errs = non_negative_parafac_hals(
          X,
          rank=3,
          n_iter_max=100,
          tol=0,
          init="svd",
          nn_modes={0, 2},
          return_errors=True,
      )
      X_hat = cp_to_tensor(nn_estimate)
      assert_(
          tl.norm(
              X - X_hat,
          )
          < 1e-3,
          "Error was too high",
      )
  
      assert_(
          congruence_coefficient(
              A, nn_estimate[1][0], absolute_value=True
          )[0]
          > 0.99,
          "Factor recovery not high enough",
      )
      assert_(
          congruence_coefficient(
              B, nn_estimate[1][1], absolute_value=True
          )[0]
          > 0.99,
          "Factor recovery not high enough",
      )
      assert_(
          congruence_coefficient(
              C, nn_estimate[1][2], absolute_value=True
          )[0]
          > 0.99,
          "Factor recovery not high enough",
      )
  
      assert_(T.all(nn_estimate[1][0] > -1e-10))
      assert_(T.all(nn_estimate[1][2] > -1e-10))
  
imports: import numpy
  import pytest
  import tensorly
  from .._cp import parafac, initialize_cp, sample_khatri_rao, randomised_parafac, CP, RandomizedCP, CPTensor
  from .._nn_cp import non_negative_parafac, non_negative_parafac_hals, CP_NN, CP_NN_HALS
  from ...cp_tensor import cp_to_tensor
  from ...cp_tensor import cp_to_tensor
  from ...random import random_cp
  from ...tenalg import khatri_rao
  from ...None import backend
  from ...testing import assert_array_equal, assert_, assert_class_wrapper_correctly_passes_arguments, assert_array_almost_equal
  from ...metrics.factors import congruence_coefficient
label_desc: Use image node_id 6 for calling a global function with example usage: test_non_negative_parafac_hals_one_unconstrained() without return types