code: def test_constrained_parafac_unimodality():
      """Test for the CANDECOMP-PARAFAC decomposition with ADMM under unimodality constraints"""
      rng = T.check_random_state(1234)
      rank = 3
      init = "random"
      tensor_init = initialize_constrained_parafac(
          T.zeros([6, 8, 4]), rank, unimodality=True, init=init
      )
      tensor = cp_to_tensor(tensor_init)
      _, factors = constrained_parafac(
          tensor,
          unimodality=True,
          rank=rank,
          init=tensor_init,
          n_iter_max=2,
          random_state=rng,
      )
      for factor in factors:
          max_location = T.argmax(factor[:, 0])
          assert_(
              np.all(
                  np.diff(
                      T.to_numpy(factor)[: int(max_location), 0], axis=0
                  )
                  >= 0
              )
          )
          assert_(
              np.all(
                  np.diff(
                      T.to_numpy(factor)[int(max_location) :, 0], axis=0
                  )
                  <= 0
              )
          )
  
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 9 for calling a global function with example usage: test_constrained_parafac_unimodality() without return types