code: def test_check_shared():
      n_subjects = 2
      n_sessions = 2
      input_shapes = np.zeros((n_subjects, n_sessions, 2))
      input_shapes[0, 0, 0] = 10
      input_shapes[0, 0, 1] = 3
      input_shapes[0, 1, 0] = 10
      input_shapes[0, 1, 1] = 2
      input_shapes[1, 0, 0] = 10
      input_shapes[1, 0, 1] = 3
      input_shapes[1, 1, 0] = 10
      input_shapes[1, 1, 1] = 2
  
      shared_list_list = [
          [
              np.array([[1, 2, 3], [4, 5, 6]]),
              np.array([[1, 2], [4, 5]]),
          ],
          [
              np.array([[2, 3, 4], [5, 6, 7]]),
              np.array([[2, 3], [5, 6]]),
          ],
      ]
  
      shared_list_subjects = [
          np.array([[1, 2, 3, 1, 2], [4, 5, 6, 4, 5]]),
          np.array([[2, 3, 4, 2, 3], [5, 6, 7, 5, 6]]),
      ]
  
      shared_list_sessions = [
          np.array([[1.5, 2.5, 3.5], [4.5, 5.5, 6.5]]),
          np.array([[1.5, 2.5], [4.5, 5.5]]),
      ]
  
      shared_array = np.array(
          [[1.5, 2.5, 3.5, 1.5, 2.5], [4.5, 5.5, 6.5, 4.5, 5.5]]
      )
  
      with pytest.raises(
          ValueError,
          match=(
              r"shared_response should be either a list or an "
              "array but is of type <class 'str'>"
          ),
      ):
          check_shared_response("bla")
  
      with pytest.raises(
          ValueError,
          match=(
              r"shared_response is a list but shared_response\[0\] "
              "is neither a list or an array. This is invalid."
          ),
      ):
          check_shared_response(["bla", "bli"])
  
      with pytest.raises(
          ValueError,
          match=(
              r"shared_response\[0\] is a list but shared_response\[1\] "
              "is not a list this is incompatible"
          ),
      ):
          check_shared_response(
              [[np.random.rand(2, 2)], np.array([1])], aggregate=None
          )
  
      with pytest.raises(
          ValueError,
          match=(
              r"shared_response\[1\] has len 1 whereas "
              r"shared_response\[0\] has len 2. They should "
              "have same len"
          ),
      ):
          check_shared_response(
              [
                  [np.random.rand(2, 2), np.random.rand(2, 2)],
                  [np.random.rand(2, 2)],
              ],
              aggregate=None,
          )
  
      with pytest.raises(
          ValueError,
          match=(
              "Number of timeframes in input images during session 0 "
              "does not match the number of timeframes during session "
              r"0 of shared_response \(2 != 3\)"
          ),
      ):
          check_shared_response(
              [np.random.rand(2, 2), np.random.rand(2, 2)],
              aggregate="mean",
              input_shapes=input_shapes,
          )
  
      with pytest.raises(
          ValueError,
          match=(
              "Number of components in shared_response "
              "during session 0 is different than "
              "the number of components of the "
              r"model \(2 != 4\)"
          ),
      ):
          check_shared_response(np.random.rand(2, 10), n_components=4)
  
      with pytest.raises(
          ValueError,
          match=(
              "self.aggregate has value 'mean' but shared "
              "response is a list of list. "
              "This is incompatible"
          ),
      ):
          added_session, reshaped_shared = check_shared_response(
              shared_list_list,
              aggregate="mean",
              n_components=2,
              input_shapes=input_shapes,
          )
  
      added_session, reshaped_shared = check_shared_response(
          shared_list_subjects,
          aggregate=None,
          n_components=2,
          input_shapes=input_shapes,
      )
      assert added_session
      assert_array_almost_equal(
          np.array(reshaped_shared), shared_array.reshape(1, 2, 5)
      )
  
      added_session, reshaped_shared = check_shared_response(
          shared_list_sessions,
          aggregate="mean",
          n_components=2,
          input_shapes=input_shapes,
      )
      assert not added_session
      for j in range(len(reshaped_shared)):
          assert_array_almost_equal(
              reshaped_shared[j], shared_list_sessions[j]
          )
  
      added_session, reshaped_shared = check_shared_response(
          shared_array,
          aggregate="mean",
          n_components=2,
          input_shapes=input_shapes,
      )
      assert added_session
      assert_array_almost_equal(
          np.array(reshaped_shared), shared_array.reshape(1, 2, 5)
      )
  
imports: import os
  import tempfile
  import numpy
  import pytest
  from numpy.testing import assert_array_almost_equal
  from sklearn.exceptions import NotFittedError
  from brainiak.funcalign.fastsrm import FastSRM, _compute_and_save_corr_mat, _compute_and_save_subject_basis, _compute_basis_subject_online, _reduced_space_compute_shared_response, check_atlas, check_imgs, check_shared_response, create_temp_dir, fast_srm, reduce_data, safe_load
  from brainiak.funcalign.srm import DetSRM
label_desc: Use image node_id 7 for calling a global function with example usage: test_check_shared() without return types