code: def test_masked_parafac(linesearch):
      """Test for the masked CANDECOMP-PARAFAC decomposition.
      This checks that a mask of 1's is identical to the unmasked case.
      """
      tensor = random_cp((4, 4, 4), rank=1, full=True)
      mask = np.ones((4, 4, 4))
      mask[1, :, 3] = 0
      mask[:, 2, 3] = 0
      mask = tl.tensor(mask)
      tensor_mask = tensor * mask - 10000.0 * (1 - mask)
  
      fac = parafac(
          tensor_mask,
          svd_mask_repeats=0,
          mask=mask,
          n_iter_max=0,
          rank=1,
          init="svd",
      )
      fac_resvd = parafac(
          tensor_mask,
          svd_mask_repeats=10,
          mask=mask,
          n_iter_max=0,
          rank=1,
          init="svd",
      )
      err = tl.norm(tl.cp_to_tensor(fac) - tensor, 2)
      err_resvd = tl.norm(tl.cp_to_tensor(fac_resvd) - tensor, 2)
      assert_(err_resvd < err, "restarting SVD did not help")
  
      # Check that we get roughly the same answer with the full tensor and masking
      mask_fact = parafac(
          tensor,
          rank=1,
          mask=mask,
          init="random",
          random_state=1234,
          linesearch=linesearch,
      )
      fact = parafac(tensor, rank=1)
      diff = cp_to_tensor(mask_fact) - cp_to_tensor(fact)
      assert_(
          T.norm(diff) < 0.001,
          "norm 2 of reconstruction higher than 0.001",
      )
  
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 2 for calling a global function with example usage: test_masked_parafac(linesearch) without return types