code: def test_constrained_parafac_l1():
      """Test for the CANDECOMP-PARAFAC decomposition with ADMM and l1 regularization"""
      rng = T.check_random_state(1234)
      tol_norm_2 = 0.5
      tol_max_abs = 0.5
      rank = 3
      init = "random"
      weights_init, factors_init = initialize_constrained_parafac(
          T.zeros([6, 8, 4]), rank, l1_reg=1e-3, init=init
      )
      tensor = cp_to_tensor((weights_init, factors_init))
      for i in range(len(factors_init)):
          factors_init[i] += T.tensor(
              0.1 * rng.random_sample(T.shape(factors_init[i])),
              **T.context(factors_init[i]),
          )
      tensor_init = CPTensor((weights_init, factors_init))
      res, errors = constrained_parafac(
          tensor,
          l1_reg=1e-3,
          rank=rank,
          init=tensor_init,
          random_state=rng,
          return_errors=True,
          tol_outer=1e-16,
          n_iter_max=1000,
      )
      res = cp_to_tensor(res)
      error = T.norm(res - tensor, 2)
      error /= T.norm(tensor, 2)
      assert_(
          error < tol_norm_2,
          f"norm 2 of reconstruction higher = {error} than tolerance={tol_norm_2}",
      )
      # Test the max abs difference between the reconstruction and the tensor
      assert_(
          T.max(T.abs(res - tensor)) < tol_max_abs,
          f"abs norm of reconstruction error = {T.max(T.abs(res - tensor))} higher than tolerance={tol_max_abs}",
      )
  
file_path: tensorly/tensorly/decomposition/tests/test_constrained_parafac.py
imports: import numpy
  from ...cp_tensor import cp_to_tensor, CPTensor
  from .._constrained_cp import constrained_parafac, initialize_constrained_parafac, ConstrainedCP
  from ...None import backend
  from ...testing import assert_, assert_array_almost_equal, assert_class_wrapper_correctly_passes_arguments
  from ...random import random_cp
label_desc: Use image node_id 2 for calling a global function with example usage: test_constrained_parafac_l1() without return types