code: def test_constrained_parafac_soft_sparsity():
      """Test for the CANDECOMP-PARAFAC decomposition with ADMM under soft_sparsity constraints"""
      rng = T.check_random_state(1234)
      rank = 3
      init = "random"
      weights_init, factors_init = initialize_constrained_parafac(
          T.zeros([6, 8, 4]), rank, soft_sparsity=[1, 1, 1], 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 = constrained_parafac(
          tensor,
          soft_sparsity=[1, 1, 1],
          rank=rank,
          init=tensor_init,
          random_state=rng,
      )
      # Check if factors have l1 norm smaller than threshold
      for i in range(len(factors_init)):
          assert_(
              np.all(T.to_numpy(T.norm(res.factors[i], 1, axis=0))) <= 1
          )
  
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 8 for calling a global function with example usage: test_constrained_parafac_soft_sparsity() without return types