code: def test_validate_parafac2_tensor(true_shape, true_rank):
      weights, factors, projections = ivy.random_parafac2(
          true_shape, true_rank
      )
  
      # Check shape and rank returned
      shape, rank = ivy.Parafac2Tensor.validate_parafac2_tensor(
          (weights, factors, projections)
      )
      np.testing.assert_equal(
          true_shape,
          shape,
          err_msg=f"Returned incorrect shape (got {shape}, expected {true_shape})",
      )
      np.testing.assert_equal(
          true_rank,
          rank,
          err_msg=f"Returned incorrect rank (got {rank}, expected {true_rank})",
      )
  
      # One of the factors has the wrong rank
      for mode in range(3):
          false_shape = (ivy.shape(factors[mode])[0], true_rank + 1)
          factors[mode], copy = (
              ivy.random_uniform(shape=false_shape),
              factors[mode],
          )
          with np.testing.assert_raises(ValueError):
              ivy.Parafac2Tensor.validate_parafac2_tensor(
                  (weights, factors, projections)
              )
  
          factors[mode] = copy
  
      # Not three factor matrices
      with np.testing.assert_raises(ValueError):
          ivy.Parafac2Tensor.validate_parafac2_tensor(
              (weights, factors[1:], projections)
          )
  
      # Not enough projections
      with np.testing.assert_raises(ValueError):
          ivy.Parafac2Tensor.validate_parafac2_tensor(
              (weights, factors, projections[1:])
          )
  
      # Wrong number of weights
      with np.testing.assert_raises(ValueError):
          ivy.Parafac2Tensor.validate_parafac2_tensor(
              (weights[1:], factors, projections)
          )
  
      # The projections aren't orthogonal
      false_projections = [
          ivy.random_uniform(shape=ivy.shape(P)) for P in projections
      ]
      with np.testing.assert_raises(ValueError):
          ivy.Parafac2Tensor.validate_parafac2_tensor(
              (weights, factors, false_projections)
          )
  
file_path: ivy/ivy_tests/test_ivy/test_misc/test_factorized_tensor/test_parafac2_tensor.py
imports: import ivy
  import numpy
  import pytest
label_desc: Use image node_id 7 for calling a global function with example usage: test_validate_parafac2_tensor(true_shape, true_rank) without return types