code: def test_masked_tucker():
      """Test for the masked Tucker decomposition.
      This checks that a mask of 1's is identical to the unmasked case.
      """
      rng = tl.check_random_state(1234)
      tensor = tl.tensor(rng.random_sample((3, 3, 3)))
      mask = tl.tensor(np.ones((3, 3, 3)))
  
      mask_fact = tucker(tensor, rank=(2, 2, 2), mask=mask)
      fact = tucker(tensor, rank=(2, 2, 2))
      diff = tucker_to_tensor(mask_fact) - tucker_to_tensor(fact)
      assert_(
          tl.norm(diff) < 0.001,
          "norm 2 of reconstruction higher than 0.001",
      )
  
      # Mask an outlier value, and check that the decomposition ignores it
      tensor = random_tucker(
          (5, 5, 5), (1, 1, 1), full=True, random_state=1234
      )
      mask = tl.tensor(np.ones((5, 5, 5)))
  
      mask_tensor = tl.tensor(tensor)
      mask_tensor = tl.index_update(mask_tensor, tl.index[0, 0, 0], 1.0)
      mask = tl.index_update(mask, tl.index[0, 0, 0], 0)
  
      # We won't use the SVD decomposition, but check that it at least runs successfully
      mask_fact = tucker(
          mask_tensor, rank=(1, 1, 1), mask=mask, init="svd"
      )
      mask_fact = tucker(
          mask_tensor,
          rank=(1, 1, 1),
          mask=mask,
          init="random",
          random_state=1234,
      )
      mask_err = tl.norm(tucker_to_tensor(mask_fact) - tensor)
  
      assert_(
          mask_err < 0.001, "norm 2 of reconstruction higher than 0.001"
      )
  
file_path: tensorly/tensorly/decomposition/tests/test_tucker.py
imports: import pytest
  import numpy
  import tensorly
  from .._tucker import tucker, partial_tucker, non_negative_tucker, non_negative_tucker_hals, Tucker, Tucker_NN, Tucker_NN_HALS
  from ...tucker_tensor import tucker_to_tensor
  from ...tenalg import multi_mode_dot
  from ...random import random_tucker
  from ...testing import assert_equal, assert_, assert_array_equal, assert_class_wrapper_correctly_passes_arguments
label_desc: Use image node_id 3 for calling a global function with example usage: test_masked_tucker() without return types